Migrate usages of Cue's bitmap constructor to Cue.Builder

PiperOrigin-RevId: 285956436
This commit is contained in:
ibaker 2019-12-17 12:44:15 +00:00 committed by Oliver Woodman
parent 04b1782a53
commit f10bc37831
4 changed files with 35 additions and 66 deletions

View File

@ -227,50 +227,6 @@ public final class Cue {
*/ */
public final float textSize; 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 * 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}. * {@link #TYPE_UNSET} and whose dimension parameters are set to {@link #DIMEN_UNSET}.

View File

@ -208,12 +208,23 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
fillRegionPaint); fillRegionPaint);
} }
Bitmap cueBitmap = Bitmap.createBitmap(bitmap, baseHorizontalAddress, baseVerticalAddress, cues.add(
regionComposition.width, regionComposition.height); new Cue.Builder()
cues.add(new Cue(cueBitmap, (float) baseHorizontalAddress / displayDefinition.width, .setBitmap(
Cue.ANCHOR_TYPE_START, (float) baseVerticalAddress / displayDefinition.height, Bitmap.createBitmap(
Cue.ANCHOR_TYPE_START, (float) regionComposition.width / displayDefinition.width, bitmap,
(float) regionComposition.height / displayDefinition.height)); 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); canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
// Restore clean clipping state. // Restore clean clipping state.

View File

@ -235,14 +235,15 @@ public final class PgsDecoder extends SimpleSubtitleDecoder {
Bitmap bitmap = Bitmap bitmap =
Bitmap.createBitmap(argbBitmapData, bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888); Bitmap.createBitmap(argbBitmapData, bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
// Build the cue. // Build the cue.
return new Cue( return new Cue.Builder()
bitmap, .setBitmap(bitmap)
(float) bitmapX / planeWidth, .setPosition((float) bitmapX / planeWidth)
Cue.ANCHOR_TYPE_START, .setPositionAnchor(Cue.ANCHOR_TYPE_START)
(float) bitmapY / planeHeight, .setLine((float) bitmapY / planeHeight, Cue.LINE_TYPE_FRACTION)
Cue.ANCHOR_TYPE_START, .setLineAnchor(Cue.ANCHOR_TYPE_START)
(float) bitmapWidth / planeWidth, .setSize((float) bitmapWidth / planeWidth)
(float) bitmapHeight / planeHeight); .setBitmapHeight((float) bitmapHeight / planeHeight)
.build();
} }
public void reset() { public void reset() {

View File

@ -228,14 +228,15 @@ import java.util.TreeSet;
TtmlRegion region = regionMap.get(regionImagePair.first); TtmlRegion region = regionMap.get(regionImagePair.first);
cues.add( cues.add(
new Cue( new Cue.Builder()
bitmap, .setBitmap(bitmap)
region.position, .setPosition(region.position)
Cue.ANCHOR_TYPE_START, .setPositionAnchor(Cue.ANCHOR_TYPE_START)
region.line, .setLine(region.line, Cue.LINE_TYPE_FRACTION)
region.lineAnchor, .setLineAnchor(region.lineAnchor)
region.width, .setSize(region.width)
region.height)); .setBitmapHeight(region.height)
.build());
} }
// Create text based cues. // Create text based cues.