From f10bc37831ca72dafc7ccf451ea82f7f83da3e24 Mon Sep 17 00:00:00 2001 From: ibaker Date: Tue, 17 Dec 2019 12:44:15 +0000 Subject: [PATCH] Migrate usages of Cue's bitmap constructor to Cue.Builder PiperOrigin-RevId: 285956436 --- .../google/android/exoplayer2/text/Cue.java | 44 ------------------- .../exoplayer2/text/dvb/DvbParser.java | 23 +++++++--- .../exoplayer2/text/pgs/PgsDecoder.java | 17 +++---- .../exoplayer2/text/ttml/TtmlNode.java | 17 +++---- 4 files changed, 35 insertions(+), 66 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/text/Cue.java b/library/core/src/main/java/com/google/android/exoplayer2/text/Cue.java index 25b71d9410..1aecc09385 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/text/Cue.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/text/Cue.java @@ -227,50 +227,6 @@ public final class Cue { */ public final float textSize; - /** - * Creates an image cue. - * - * @param bitmap See {@link #bitmap}. - * @param horizontalPosition The position of the horizontal anchor within the viewport, expressed - * as a fraction of the viewport width. - * @param horizontalPositionAnchor The horizontal anchor. One of {@link #ANCHOR_TYPE_START}, - * {@link #ANCHOR_TYPE_MIDDLE}, {@link #ANCHOR_TYPE_END} and {@link #TYPE_UNSET}. - * @param verticalPosition The position of the vertical anchor within the viewport, expressed as a - * fraction of the viewport height. - * @param verticalPositionAnchor The vertical anchor. One of {@link #ANCHOR_TYPE_START}, {@link - * #ANCHOR_TYPE_MIDDLE}, {@link #ANCHOR_TYPE_END} and {@link #TYPE_UNSET}. - * @param width The width of the cue as a fraction of the viewport width. - * @param height The height of the cue as a fraction of the viewport height, or {@link - * #DIMEN_UNSET} if the bitmap should be displayed at its natural height for the specified - * {@code width}. - * @deprecated Use {@link Builder}. - */ - @Deprecated - public Cue( - Bitmap bitmap, - float horizontalPosition, - @AnchorType int horizontalPositionAnchor, - float verticalPosition, - @AnchorType int verticalPositionAnchor, - float width, - float height) { - this( - /* text= */ null, - /* textAlignment= */ null, - bitmap, - verticalPosition, - /* lineType= */ LINE_TYPE_FRACTION, - verticalPositionAnchor, - horizontalPosition, - horizontalPositionAnchor, - /* textSizeType= */ TYPE_UNSET, - /* textSize= */ DIMEN_UNSET, - width, - height, - /* windowColorSet= */ false, - /* windowColor= */ Color.BLACK); - } - /** * Creates a text cue whose {@link #textAlignment} is null, whose type parameters are set to * {@link #TYPE_UNSET} and whose dimension parameters are set to {@link #DIMEN_UNSET}. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/text/dvb/DvbParser.java b/library/core/src/main/java/com/google/android/exoplayer2/text/dvb/DvbParser.java index e1cde75532..228973ce0c 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/text/dvb/DvbParser.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/text/dvb/DvbParser.java @@ -208,12 +208,23 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; fillRegionPaint); } - Bitmap cueBitmap = Bitmap.createBitmap(bitmap, baseHorizontalAddress, baseVerticalAddress, - regionComposition.width, regionComposition.height); - cues.add(new Cue(cueBitmap, (float) baseHorizontalAddress / displayDefinition.width, - Cue.ANCHOR_TYPE_START, (float) baseVerticalAddress / displayDefinition.height, - Cue.ANCHOR_TYPE_START, (float) regionComposition.width / displayDefinition.width, - (float) regionComposition.height / displayDefinition.height)); + cues.add( + new Cue.Builder() + .setBitmap( + Bitmap.createBitmap( + bitmap, + baseHorizontalAddress, + baseVerticalAddress, + regionComposition.width, + regionComposition.height)) + .setPosition((float) baseHorizontalAddress / displayDefinition.width) + .setPositionAnchor(Cue.ANCHOR_TYPE_START) + .setLine( + (float) baseVerticalAddress / displayDefinition.height, Cue.LINE_TYPE_FRACTION) + .setLineAnchor(Cue.ANCHOR_TYPE_START) + .setSize((float) regionComposition.width / displayDefinition.width) + .setBitmapHeight((float) regionComposition.height / displayDefinition.height) + .build()); canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); // Restore clean clipping state. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/text/pgs/PgsDecoder.java b/library/core/src/main/java/com/google/android/exoplayer2/text/pgs/PgsDecoder.java index 9ef3556c8f..fe8bf12d47 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/text/pgs/PgsDecoder.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/text/pgs/PgsDecoder.java @@ -235,14 +235,15 @@ public final class PgsDecoder extends SimpleSubtitleDecoder { Bitmap bitmap = Bitmap.createBitmap(argbBitmapData, bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888); // Build the cue. - return new Cue( - bitmap, - (float) bitmapX / planeWidth, - Cue.ANCHOR_TYPE_START, - (float) bitmapY / planeHeight, - Cue.ANCHOR_TYPE_START, - (float) bitmapWidth / planeWidth, - (float) bitmapHeight / planeHeight); + return new Cue.Builder() + .setBitmap(bitmap) + .setPosition((float) bitmapX / planeWidth) + .setPositionAnchor(Cue.ANCHOR_TYPE_START) + .setLine((float) bitmapY / planeHeight, Cue.LINE_TYPE_FRACTION) + .setLineAnchor(Cue.ANCHOR_TYPE_START) + .setSize((float) bitmapWidth / planeWidth) + .setBitmapHeight((float) bitmapHeight / planeHeight) + .build(); } public void reset() { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/text/ttml/TtmlNode.java b/library/core/src/main/java/com/google/android/exoplayer2/text/ttml/TtmlNode.java index 3365749e1a..b025a4e139 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/text/ttml/TtmlNode.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/text/ttml/TtmlNode.java @@ -228,14 +228,15 @@ import java.util.TreeSet; TtmlRegion region = regionMap.get(regionImagePair.first); cues.add( - new Cue( - bitmap, - region.position, - Cue.ANCHOR_TYPE_START, - region.line, - region.lineAnchor, - region.width, - region.height)); + new Cue.Builder() + .setBitmap(bitmap) + .setPosition(region.position) + .setPositionAnchor(Cue.ANCHOR_TYPE_START) + .setLine(region.line, Cue.LINE_TYPE_FRACTION) + .setLineAnchor(region.lineAnchor) + .setSize(region.width) + .setBitmapHeight(region.height) + .build()); } // Create text based cues.