Defensively copy potentially mutable text in Cue constructor

Without this the Cue isn't deeply immutable, which can be a bit
surprising.

PiperOrigin-RevId: 375477571
This commit is contained in:
ibaker 2021-05-24 16:11:06 +01:00 committed by Oliver Woodman
parent 2081f4b466
commit 926df59081

View file

@ -20,6 +20,8 @@ import android.graphics.Color;
import android.os.Bundle;
import android.text.Layout;
import android.text.Layout.Alignment;
import android.text.Spanned;
import android.text.SpannedString;
import android.text.TextUtils;
import androidx.annotation.ColorInt;
import androidx.annotation.IntDef;
@ -453,7 +455,13 @@ public final class Cue implements Bundleable {
} else {
Assertions.checkArgument(bitmap == null);
}
this.text = text;
if (text instanceof Spanned) {
this.text = SpannedString.valueOf(text);
} else if (text != null) {
this.text = text.toString();
} else {
this.text = null;
}
this.textAlignment = textAlignment;
this.multiRowAlignment = multiRowAlignment;
this.bitmap = bitmap;