mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Remove SubtitlePainter from null-checking blacklist
PiperOrigin-RevId: 279107241
This commit is contained in:
parent
53283ecb52
commit
6286491621
1 changed files with 21 additions and 9 deletions
|
|
@ -35,10 +35,14 @@ import android.text.style.AbsoluteSizeSpan;
|
||||||
import android.text.style.BackgroundColorSpan;
|
import android.text.style.BackgroundColorSpan;
|
||||||
import android.text.style.RelativeSizeSpan;
|
import android.text.style.RelativeSizeSpan;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.text.CaptionStyleCompat;
|
import com.google.android.exoplayer2.text.CaptionStyleCompat;
|
||||||
import com.google.android.exoplayer2.text.Cue;
|
import com.google.android.exoplayer2.text.Cue;
|
||||||
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Log;
|
import com.google.android.exoplayer2.util.Log;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paints subtitle {@link Cue}s.
|
* Paints subtitle {@link Cue}s.
|
||||||
|
|
@ -63,9 +67,9 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
private final Paint paint;
|
private final Paint paint;
|
||||||
|
|
||||||
// Previous input variables.
|
// Previous input variables.
|
||||||
private CharSequence cueText;
|
@Nullable private CharSequence cueText;
|
||||||
private Alignment cueTextAlignment;
|
@Nullable private Alignment cueTextAlignment;
|
||||||
private Bitmap cueBitmap;
|
@Nullable private Bitmap cueBitmap;
|
||||||
private float cueLine;
|
private float cueLine;
|
||||||
@Cue.LineType
|
@Cue.LineType
|
||||||
private int cueLineType;
|
private int cueLineType;
|
||||||
|
|
@ -93,11 +97,11 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
private int parentBottom;
|
private int parentBottom;
|
||||||
|
|
||||||
// Derived drawing variables.
|
// Derived drawing variables.
|
||||||
private StaticLayout textLayout;
|
private @MonotonicNonNull StaticLayout textLayout;
|
||||||
private int textLeft;
|
private int textLeft;
|
||||||
private int textTop;
|
private int textTop;
|
||||||
private int textPaddingX;
|
private int textPaddingX;
|
||||||
private Rect bitmapRect;
|
private @MonotonicNonNull Rect bitmapRect;
|
||||||
|
|
||||||
@SuppressWarnings("ResourceType")
|
@SuppressWarnings("ResourceType")
|
||||||
public SubtitlePainter(Context context) {
|
public SubtitlePainter(Context context) {
|
||||||
|
|
@ -225,14 +229,18 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
this.parentBottom = cueBoxBottom;
|
this.parentBottom = cueBoxBottom;
|
||||||
|
|
||||||
if (isTextCue) {
|
if (isTextCue) {
|
||||||
|
Assertions.checkNotNull(cueText);
|
||||||
setupTextLayout();
|
setupTextLayout();
|
||||||
} else {
|
} else {
|
||||||
|
Assertions.checkNotNull(cueBitmap);
|
||||||
setupBitmapLayout();
|
setupBitmapLayout();
|
||||||
}
|
}
|
||||||
drawLayout(canvas, isTextCue);
|
drawLayout(canvas, isTextCue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresNonNull("cueText")
|
||||||
private void setupTextLayout() {
|
private void setupTextLayout() {
|
||||||
|
CharSequence cueText = this.cueText;
|
||||||
int parentWidth = parentRight - parentLeft;
|
int parentWidth = parentRight - parentLeft;
|
||||||
int parentHeight = parentBottom - parentTop;
|
int parentHeight = parentBottom - parentTop;
|
||||||
|
|
||||||
|
|
@ -248,7 +256,6 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CharSequence cueText = this.cueText;
|
|
||||||
// Remove embedded styling or font size if requested.
|
// Remove embedded styling or font size if requested.
|
||||||
if (!applyEmbeddedStyles) {
|
if (!applyEmbeddedStyles) {
|
||||||
cueText = cueText.toString(); // Equivalent to erasing all spans.
|
cueText = cueText.toString(); // Equivalent to erasing all spans.
|
||||||
|
|
@ -364,7 +371,9 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
this.textPaddingX = textPaddingX;
|
this.textPaddingX = textPaddingX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresNonNull("cueBitmap")
|
||||||
private void setupBitmapLayout() {
|
private void setupBitmapLayout() {
|
||||||
|
Bitmap cueBitmap = this.cueBitmap;
|
||||||
int parentWidth = parentRight - parentLeft;
|
int parentWidth = parentRight - parentLeft;
|
||||||
int parentHeight = parentBottom - parentTop;
|
int parentHeight = parentBottom - parentTop;
|
||||||
float anchorX = parentLeft + (parentWidth * cuePosition);
|
float anchorX = parentLeft + (parentWidth * cuePosition);
|
||||||
|
|
@ -389,6 +398,8 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
if (isTextCue) {
|
if (isTextCue) {
|
||||||
drawTextLayout(canvas);
|
drawTextLayout(canvas);
|
||||||
} else {
|
} else {
|
||||||
|
Assertions.checkNotNull(bitmapRect);
|
||||||
|
Assertions.checkNotNull(cueBitmap);
|
||||||
drawBitmapLayout(canvas);
|
drawBitmapLayout(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -438,8 +449,9 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
canvas.restoreToCount(saveCount);
|
canvas.restoreToCount(saveCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresNonNull({"cueBitmap", "bitmapRect"})
|
||||||
private void drawBitmapLayout(Canvas canvas) {
|
private void drawBitmapLayout(Canvas canvas) {
|
||||||
canvas.drawBitmap(cueBitmap, null, bitmapRect, null);
|
canvas.drawBitmap(cueBitmap, /* src= */ null, bitmapRect, /* paint= */ null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -448,10 +460,10 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
* may be embedded within the {@link CharSequence}s.
|
* may be embedded within the {@link CharSequence}s.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("UndefinedEquals")
|
@SuppressWarnings("UndefinedEquals")
|
||||||
private static boolean areCharSequencesEqual(CharSequence first, CharSequence second) {
|
private static boolean areCharSequencesEqual(
|
||||||
|
@Nullable CharSequence first, @Nullable CharSequence second) {
|
||||||
// Some CharSequence implementations don't perform a cheap referential equality check in their
|
// Some CharSequence implementations don't perform a cheap referential equality check in their
|
||||||
// equals methods, so we perform one explicitly here.
|
// equals methods, so we perform one explicitly here.
|
||||||
return first == second || (first != null && first.equals(second));
|
return first == second || (first != null && first.equals(second));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue