Methods Summary |
---|
private boolean | containsKey(int key)
if (isValidKey(key) && mKeyObjectMap.containsKey(key)) {
return true;
}
return false;
|
public android.graphics.Rect | getBounds()Get the rectangle area or region for rendering the timed text as specified
by a Rect object.
return mTextBounds;
|
private java.lang.Object | getObject(int key)
if (containsKey(key)) {
return mKeyObjectMap.get(key);
} else {
throw new IllegalArgumentException("Invalid key: " + key);
}
|
public java.lang.String | getText()Get the characters in the timed text.
return mTextChars;
|
private boolean | isValidKey(int key)
if (!((key >= FIRST_PUBLIC_KEY) && (key <= LAST_PUBLIC_KEY))
&& !((key >= FIRST_PRIVATE_KEY) && (key <= LAST_PRIVATE_KEY))) {
return false;
}
return true;
|
private java.util.Set | keySet()
return mKeyObjectMap.keySet();
|
private boolean | parseParcel(android.os.Parcel parcel)
parcel.setDataPosition(0);
if (parcel.dataAvail() == 0) {
return false;
}
int type = parcel.readInt();
if (type == KEY_LOCAL_SETTING) {
type = parcel.readInt();
if (type != KEY_START_TIME) {
return false;
}
int mStartTimeMs = parcel.readInt();
mKeyObjectMap.put(type, mStartTimeMs);
type = parcel.readInt();
if (type != KEY_STRUCT_TEXT) {
return false;
}
int textLen = parcel.readInt();
byte[] text = parcel.createByteArray();
if (text == null || text.length == 0) {
mTextChars = null;
} else {
mTextChars = new String(text);
}
} else if (type != KEY_GLOBAL_SETTING) {
Log.w(TAG, "Invalid timed text key found: " + type);
return false;
}
while (parcel.dataAvail() > 0) {
int key = parcel.readInt();
if (!isValidKey(key)) {
Log.w(TAG, "Invalid timed text key found: " + key);
return false;
}
Object object = null;
switch (key) {
case KEY_STRUCT_STYLE_LIST: {
readStyle(parcel);
object = mStyleList;
break;
}
case KEY_STRUCT_FONT_LIST: {
readFont(parcel);
object = mFontList;
break;
}
case KEY_STRUCT_HIGHLIGHT_LIST: {
readHighlight(parcel);
object = mHighlightPosList;
break;
}
case KEY_STRUCT_KARAOKE_LIST: {
readKaraoke(parcel);
object = mKaraokeList;
break;
}
case KEY_STRUCT_HYPER_TEXT_LIST: {
readHyperText(parcel);
object = mHyperTextList;
break;
}
case KEY_STRUCT_BLINKING_TEXT_LIST: {
readBlinkingText(parcel);
object = mBlinkingPosList;
break;
}
case KEY_WRAP_TEXT: {
mWrapText = parcel.readInt();
object = mWrapText;
break;
}
case KEY_HIGHLIGHT_COLOR_RGBA: {
mHighlightColorRGBA = parcel.readInt();
object = mHighlightColorRGBA;
break;
}
case KEY_DISPLAY_FLAGS: {
mDisplayFlags = parcel.readInt();
object = mDisplayFlags;
break;
}
case KEY_STRUCT_JUSTIFICATION: {
int horizontal = parcel.readInt();
int vertical = parcel.readInt();
mJustification = new Justification(horizontal, vertical);
object = mJustification;
break;
}
case KEY_BACKGROUND_COLOR_RGBA: {
mBackgroundColorRGBA = parcel.readInt();
object = mBackgroundColorRGBA;
break;
}
case KEY_STRUCT_TEXT_POS: {
int top = parcel.readInt();
int left = parcel.readInt();
int bottom = parcel.readInt();
int right = parcel.readInt();
mTextBounds = new Rect(left, top, right, bottom);
break;
}
case KEY_SCROLL_DELAY: {
mScrollDelay = parcel.readInt();
object = mScrollDelay;
break;
}
default: {
break;
}
}
if (object != null) {
if (mKeyObjectMap.containsKey(key)) {
mKeyObjectMap.remove(key);
}
// Previous mapping will be replaced with the new object, if there was one.
mKeyObjectMap.put(key, object);
}
}
return true;
|
private void | readBlinkingText(android.os.Parcel parcel)
int startChar = parcel.readInt();
int endChar = parcel.readInt();
CharPos blinkingPos = new CharPos(startChar, endChar);
if (mBlinkingPosList == null) {
mBlinkingPosList = new ArrayList<CharPos>();
}
mBlinkingPosList.add(blinkingPos);
|
private void | readFont(android.os.Parcel parcel)
int entryCount = parcel.readInt();
for (int i = 0; i < entryCount; i++) {
int id = parcel.readInt();
int nameLen = parcel.readInt();
byte[] text = parcel.createByteArray();
final String name = new String(text, 0, nameLen);
Font font = new Font(id, name);
if (mFontList == null) {
mFontList = new ArrayList<Font>();
}
mFontList.add(font);
}
|
private void | readHighlight(android.os.Parcel parcel)
int startChar = parcel.readInt();
int endChar = parcel.readInt();
CharPos pos = new CharPos(startChar, endChar);
if (mHighlightPosList == null) {
mHighlightPosList = new ArrayList<CharPos>();
}
mHighlightPosList.add(pos);
|
private void | readHyperText(android.os.Parcel parcel)
int startChar = parcel.readInt();
int endChar = parcel.readInt();
int len = parcel.readInt();
byte[] url = parcel.createByteArray();
final String urlString = new String(url, 0, len);
len = parcel.readInt();
byte[] alt = parcel.createByteArray();
final String altString = new String(alt, 0, len);
HyperText hyperText = new HyperText(startChar, endChar, urlString, altString);
if (mHyperTextList == null) {
mHyperTextList = new ArrayList<HyperText>();
}
mHyperTextList.add(hyperText);
|
private void | readKaraoke(android.os.Parcel parcel)
int entryCount = parcel.readInt();
for (int i = 0; i < entryCount; i++) {
int startTimeMs = parcel.readInt();
int endTimeMs = parcel.readInt();
int startChar = parcel.readInt();
int endChar = parcel.readInt();
Karaoke kara = new Karaoke(startTimeMs, endTimeMs,
startChar, endChar);
if (mKaraokeList == null) {
mKaraokeList = new ArrayList<Karaoke>();
}
mKaraokeList.add(kara);
}
|
private void | readStyle(android.os.Parcel parcel)
boolean endOfStyle = false;
int startChar = -1;
int endChar = -1;
int fontId = -1;
boolean isBold = false;
boolean isItalic = false;
boolean isUnderlined = false;
int fontSize = -1;
int colorRGBA = -1;
while (!endOfStyle && (parcel.dataAvail() > 0)) {
int key = parcel.readInt();
switch (key) {
case KEY_START_CHAR: {
startChar = parcel.readInt();
break;
}
case KEY_END_CHAR: {
endChar = parcel.readInt();
break;
}
case KEY_FONT_ID: {
fontId = parcel.readInt();
break;
}
case KEY_STYLE_FLAGS: {
int flags = parcel.readInt();
// In the absence of any bits set in flags, the text
// is plain. Otherwise, 1: bold, 2: italic, 4: underline
isBold = ((flags % 2) == 1);
isItalic = ((flags % 4) >= 2);
isUnderlined = ((flags / 4) == 1);
break;
}
case KEY_FONT_SIZE: {
fontSize = parcel.readInt();
break;
}
case KEY_TEXT_COLOR_RGBA: {
colorRGBA = parcel.readInt();
break;
}
default: {
// End of the Style parsing. Reset the data position back
// to the position before the last parcel.readInt() call.
parcel.setDataPosition(parcel.dataPosition() - 4);
endOfStyle = true;
break;
}
}
}
Style style = new Style(startChar, endChar, fontId, isBold,
isItalic, isUnderlined, fontSize, colorRGBA);
if (mStyleList == null) {
mStyleList = new ArrayList<Style>();
}
mStyleList.add(style);
|