2828 * Class to hold the timed text's metadata, including:
2929 * <ul>
3030 * <li> The characters for rendering</li>
31- * <li> The rendering postion for the timed text</li>
31+ * <li> The rendering position for the timed text</li>
3232 * </ul>
3333 *
3434 * <p> To render the timed text, applications need to do the following:
@@ -86,7 +86,6 @@ public final class TimedText
8686
8787 private static final String TAG = "TimedText" ;
8888
89- private Parcel mParcel = Parcel .obtain ();
9089 private final HashMap <Integer , Object > mKeyObjectMap =
9190 new HashMap <Integer , Object >();
9291
@@ -356,10 +355,8 @@ public HyperText(int startChar, int endChar, String url, String alt) {
356355 * @throws IllegalArgumentExcept if parseParcel() fails.
357356 * {@hide}
358357 */
359- public TimedText (byte [] obj ) {
360- mParcel .unmarshall (obj , 0 , obj .length );
361-
362- if (!parseParcel ()) {
358+ public TimedText (Parcel parcel ) {
359+ if (!parseParcel (parcel )) {
363360 mKeyObjectMap .clear ();
364361 throw new IllegalArgumentException ("parseParcel() fails" );
365362 }
@@ -393,28 +390,28 @@ public Rect getBounds() {
393390 * Parcel. These are stored in mKeyObjectMap for application to retrieve.
394391 * @return false if an error occurred during parsing. Otherwise, true.
395392 */
396- private boolean parseParcel () {
397- mParcel .setDataPosition (0 );
398- if (mParcel .dataAvail () == 0 ) {
393+ private boolean parseParcel (Parcel parcel ) {
394+ parcel .setDataPosition (0 );
395+ if (parcel .dataAvail () == 0 ) {
399396 return false ;
400397 }
401398
402- int type = mParcel .readInt ();
399+ int type = parcel .readInt ();
403400 if (type == KEY_LOCAL_SETTING ) {
404- type = mParcel .readInt ();
401+ type = parcel .readInt ();
405402 if (type != KEY_START_TIME ) {
406403 return false ;
407404 }
408- int mStartTimeMs = mParcel .readInt ();
405+ int mStartTimeMs = parcel .readInt ();
409406 mKeyObjectMap .put (type , mStartTimeMs );
410407
411- type = mParcel .readInt ();
408+ type = parcel .readInt ();
412409 if (type != KEY_STRUCT_TEXT ) {
413410 return false ;
414411 }
415412
416- int textLen = mParcel .readInt ();
417- byte [] text = mParcel .createByteArray ();
413+ int textLen = parcel .readInt ();
414+ byte [] text = parcel .createByteArray ();
418415 if (text == null || text .length == 0 ) {
419416 mTextChars = null ;
420417 } else {
@@ -426,8 +423,8 @@ private boolean parseParcel() {
426423 return false ;
427424 }
428425
429- while (mParcel .dataAvail () > 0 ) {
430- int key = mParcel .readInt ();
426+ while (parcel .dataAvail () > 0 ) {
427+ int key = parcel .readInt ();
431428 if (!isValidKey (key )) {
432429 Log .w (TAG , "Invalid timed text key found: " + key );
433430 return false ;
@@ -437,77 +434,77 @@ private boolean parseParcel() {
437434
438435 switch (key ) {
439436 case KEY_STRUCT_STYLE_LIST : {
440- readStyle ();
437+ readStyle (parcel );
441438 object = mStyleList ;
442439 break ;
443440 }
444441 case KEY_STRUCT_FONT_LIST : {
445- readFont ();
442+ readFont (parcel );
446443 object = mFontList ;
447444 break ;
448445 }
449446 case KEY_STRUCT_HIGHLIGHT_LIST : {
450- readHighlight ();
447+ readHighlight (parcel );
451448 object = mHighlightPosList ;
452449 break ;
453450 }
454451 case KEY_STRUCT_KARAOKE_LIST : {
455- readKaraoke ();
452+ readKaraoke (parcel );
456453 object = mKaraokeList ;
457454 break ;
458455 }
459456 case KEY_STRUCT_HYPER_TEXT_LIST : {
460- readHyperText ();
457+ readHyperText (parcel );
461458 object = mHyperTextList ;
462459
463460 break ;
464461 }
465462 case KEY_STRUCT_BLINKING_TEXT_LIST : {
466- readBlinkingText ();
463+ readBlinkingText (parcel );
467464 object = mBlinkingPosList ;
468465
469466 break ;
470467 }
471468 case KEY_WRAP_TEXT : {
472- mWrapText = mParcel .readInt ();
469+ mWrapText = parcel .readInt ();
473470 object = mWrapText ;
474471 break ;
475472 }
476473 case KEY_HIGHLIGHT_COLOR_RGBA : {
477- mHighlightColorRGBA = mParcel .readInt ();
474+ mHighlightColorRGBA = parcel .readInt ();
478475 object = mHighlightColorRGBA ;
479476 break ;
480477 }
481478 case KEY_DISPLAY_FLAGS : {
482- mDisplayFlags = mParcel .readInt ();
479+ mDisplayFlags = parcel .readInt ();
483480 object = mDisplayFlags ;
484481 break ;
485482 }
486483 case KEY_STRUCT_JUSTIFICATION : {
487484
488- int horizontal = mParcel .readInt ();
489- int vertical = mParcel .readInt ();
485+ int horizontal = parcel .readInt ();
486+ int vertical = parcel .readInt ();
490487 mJustification = new Justification (horizontal , vertical );
491488
492489 object = mJustification ;
493490 break ;
494491 }
495492 case KEY_BACKGROUND_COLOR_RGBA : {
496- mBackgroundColorRGBA = mParcel .readInt ();
493+ mBackgroundColorRGBA = parcel .readInt ();
497494 object = mBackgroundColorRGBA ;
498495 break ;
499496 }
500497 case KEY_STRUCT_TEXT_POS : {
501- int top = mParcel .readInt ();
502- int left = mParcel .readInt ();
503- int bottom = mParcel .readInt ();
504- int right = mParcel .readInt ();
498+ int top = parcel .readInt ();
499+ int left = parcel .readInt ();
500+ int bottom = parcel .readInt ();
501+ int right = parcel .readInt ();
505502 mTextBounds = new Rect (left , top , right , bottom );
506503
507504 break ;
508505 }
509506 case KEY_SCROLL_DELAY : {
510- mScrollDelay = mParcel .readInt ();
507+ mScrollDelay = parcel .readInt ();
511508 object = mScrollDelay ;
512509 break ;
513510 }
@@ -520,18 +517,18 @@ private boolean parseParcel() {
520517 if (mKeyObjectMap .containsKey (key )) {
521518 mKeyObjectMap .remove (key );
522519 }
520+ // Previous mapping will be replaced with the new object, if there was one.
523521 mKeyObjectMap .put (key , object );
524522 }
525523 }
526524
527- mParcel .recycle ();
528525 return true ;
529526 }
530527
531528 /*
532529 * To parse and store the Style list.
533530 */
534- private void readStyle () {
531+ private void readStyle (Parcel parcel ) {
535532 boolean endOfStyle = false ;
536533 int startChar = -1 ;
537534 int endChar = -1 ;
@@ -541,23 +538,23 @@ private void readStyle() {
541538 boolean isUnderlined = false ;
542539 int fontSize = -1 ;
543540 int colorRGBA = -1 ;
544- while (!endOfStyle && (mParcel .dataAvail () > 0 )) {
545- int key = mParcel .readInt ();
541+ while (!endOfStyle && (parcel .dataAvail () > 0 )) {
542+ int key = parcel .readInt ();
546543 switch (key ) {
547544 case KEY_START_CHAR : {
548- startChar = mParcel .readInt ();
545+ startChar = parcel .readInt ();
549546 break ;
550547 }
551548 case KEY_END_CHAR : {
552- endChar = mParcel .readInt ();
549+ endChar = parcel .readInt ();
553550 break ;
554551 }
555552 case KEY_FONT_ID : {
556- fontId = mParcel .readInt ();
553+ fontId = parcel .readInt ();
557554 break ;
558555 }
559556 case KEY_STYLE_FLAGS : {
560- int flags = mParcel .readInt ();
557+ int flags = parcel .readInt ();
561558 // In the absence of any bits set in flags, the text
562559 // is plain. Otherwise, 1: bold, 2: italic, 4: underline
563560 isBold = ((flags % 2 ) == 1 );
@@ -566,17 +563,17 @@ private void readStyle() {
566563 break ;
567564 }
568565 case KEY_FONT_SIZE : {
569- fontSize = mParcel .readInt ();
566+ fontSize = parcel .readInt ();
570567 break ;
571568 }
572569 case KEY_TEXT_COLOR_RGBA : {
573- colorRGBA = mParcel .readInt ();
570+ colorRGBA = parcel .readInt ();
574571 break ;
575572 }
576573 default : {
577574 // End of the Style parsing. Reset the data position back
578- // to the position before the last mParcel .readInt() call.
579- mParcel .setDataPosition (mParcel .dataPosition () - 4 );
575+ // to the position before the last parcel .readInt() call.
576+ parcel .setDataPosition (parcel .dataPosition () - 4 );
580577 endOfStyle = true ;
581578 break ;
582579 }
@@ -594,14 +591,14 @@ private void readStyle() {
594591 /*
595592 * To parse and store the Font list
596593 */
597- private void readFont () {
598- int entryCount = mParcel .readInt ();
594+ private void readFont (Parcel parcel ) {
595+ int entryCount = parcel .readInt ();
599596
600597 for (int i = 0 ; i < entryCount ; i ++) {
601- int id = mParcel .readInt ();
602- int nameLen = mParcel .readInt ();
598+ int id = parcel .readInt ();
599+ int nameLen = parcel .readInt ();
603600
604- byte [] text = mParcel .createByteArray ();
601+ byte [] text = parcel .createByteArray ();
605602 final String name = new String (text , 0 , nameLen );
606603
607604 Font font = new Font (id , name );
@@ -616,9 +613,9 @@ private void readFont() {
616613 /*
617614 * To parse and store the Highlight list
618615 */
619- private void readHighlight () {
620- int startChar = mParcel .readInt ();
621- int endChar = mParcel .readInt ();
616+ private void readHighlight (Parcel parcel ) {
617+ int startChar = parcel .readInt ();
618+ int endChar = parcel .readInt ();
622619 CharPos pos = new CharPos (startChar , endChar );
623620
624621 if (mHighlightPosList == null ) {
@@ -630,14 +627,14 @@ private void readHighlight() {
630627 /*
631628 * To parse and store the Karaoke list
632629 */
633- private void readKaraoke () {
634- int entryCount = mParcel .readInt ();
630+ private void readKaraoke (Parcel parcel ) {
631+ int entryCount = parcel .readInt ();
635632
636633 for (int i = 0 ; i < entryCount ; i ++) {
637- int startTimeMs = mParcel .readInt ();
638- int endTimeMs = mParcel .readInt ();
639- int startChar = mParcel .readInt ();
640- int endChar = mParcel .readInt ();
634+ int startTimeMs = parcel .readInt ();
635+ int endTimeMs = parcel .readInt ();
636+ int startChar = parcel .readInt ();
637+ int endChar = parcel .readInt ();
641638 Karaoke kara = new Karaoke (startTimeMs , endTimeMs ,
642639 startChar , endChar );
643640
@@ -651,16 +648,16 @@ private void readKaraoke() {
651648 /*
652649 * To parse and store HyperText list
653650 */
654- private void readHyperText () {
655- int startChar = mParcel .readInt ();
656- int endChar = mParcel .readInt ();
651+ private void readHyperText (Parcel parcel ) {
652+ int startChar = parcel .readInt ();
653+ int endChar = parcel .readInt ();
657654
658- int len = mParcel .readInt ();
659- byte [] url = mParcel .createByteArray ();
655+ int len = parcel .readInt ();
656+ byte [] url = parcel .createByteArray ();
660657 final String urlString = new String (url , 0 , len );
661658
662- len = mParcel .readInt ();
663- byte [] alt = mParcel .createByteArray ();
659+ len = parcel .readInt ();
660+ byte [] alt = parcel .createByteArray ();
664661 final String altString = new String (alt , 0 , len );
665662 HyperText hyperText = new HyperText (startChar , endChar , urlString , altString );
666663
@@ -674,9 +671,9 @@ private void readHyperText() {
674671 /*
675672 * To parse and store blinking text list
676673 */
677- private void readBlinkingText () {
678- int startChar = mParcel .readInt ();
679- int endChar = mParcel .readInt ();
674+ private void readBlinkingText (Parcel parcel ) {
675+ int startChar = parcel .readInt ();
676+ int endChar = parcel .readInt ();
680677 CharPos blinkingPos = new CharPos (startChar , endChar );
681678
682679 if (mBlinkingPosList == null ) {
0 commit comments