Commit 9e4315f4 by klhyun Committed by Oliver Woodman

Implement MediaController#getCurrentCues

It only covers MediaSession - MediaController
(Does not consider cases that either a legacy session or a legacy controller is involved)

Add PlayerInfo#Builder to clean it up.

PiperOrigin-RevId: 374785779
parent 65d8ff80
......@@ -20,11 +20,13 @@ import android.graphics.Color;
import android.os.Bundle;
import android.text.Layout;
import android.text.Layout.Alignment;
import android.text.TextUtils;
import androidx.annotation.ColorInt;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Bundleable;
import com.google.android.exoplayer2.util.Assertions;
import com.google.common.base.Objects;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
......@@ -474,6 +476,58 @@ public final class Cue implements Bundleable {
return new Cue.Builder(this);
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Cue that = (Cue) obj;
return TextUtils.equals(text, that.text)
&& textAlignment == that.textAlignment
&& multiRowAlignment == that.multiRowAlignment
&& (bitmap == null
? that.bitmap == null
: (that.bitmap != null && bitmap.sameAs(that.bitmap)))
&& line == that.line
&& lineType == that.lineType
&& lineAnchor == that.lineAnchor
&& position == that.position
&& positionAnchor == that.positionAnchor
&& size == that.size
&& bitmapHeight == that.bitmapHeight
&& windowColorSet == that.windowColorSet
&& windowColor == that.windowColor
&& textSizeType == that.textSizeType
&& textSize == that.textSize
&& verticalType == that.verticalType
&& shearDegrees == that.shearDegrees;
}
@Override
public int hashCode() {
return Objects.hashCode(
text,
textAlignment,
multiRowAlignment,
bitmap,
line,
lineType,
lineAnchor,
position,
positionAnchor,
size,
bitmapHeight,
windowColorSet,
windowColor,
textSizeType,
textSize,
verticalType,
shearDegrees);
}
/** A builder for {@link Cue} objects. */
public static final class Builder {
@Nullable private CharSequence text;
......@@ -911,7 +965,7 @@ public final class Cue implements Bundleable {
bundle.putCharSequence(keyForField(FIELD_TEXT), text);
bundle.putSerializable(keyForField(FIELD_TEXT_ALIGNMENT), textAlignment);
bundle.putSerializable(keyForField(FIELD_MULTI_ROW_ALIGNMENT), multiRowAlignment);
// TODO(b/187804381): Use Util.scaleDownBitmap when it's added
// TODO(b/187804381): Drop bitmap
bundle.putParcelable(keyForField(FIELD_BITMAP), bitmap);
bundle.putFloat(keyForField(FIELD_LINE), line);
bundle.putInt(keyForField(FIELD_LINE_TYPE), lineType);
......
......@@ -25,7 +25,6 @@ import android.os.Bundle;
import android.os.Parcel;
import android.text.Layout;
import android.text.SpannedString;
import android.text.TextUtils;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -128,22 +127,7 @@ public class CueTest {
.build();
Cue modifiedCue = parcelAndUnParcelCue(cue);
assertThat(TextUtils.equals(modifiedCue.text, cue.text)).isTrue();
assertThat(modifiedCue.textAlignment).isEqualTo(cue.textAlignment);
assertThat(modifiedCue.multiRowAlignment).isEqualTo(cue.multiRowAlignment);
assertThat(modifiedCue.bitmap).isNull();
assertThat(modifiedCue.bitmapHeight).isEqualTo(Cue.DIMEN_UNSET);
assertThat(modifiedCue.line).isEqualTo(cue.line);
assertThat(modifiedCue.lineType).isEqualTo(cue.lineType);
assertThat(modifiedCue.position).isEqualTo(cue.position);
assertThat(modifiedCue.positionAnchor).isEqualTo(cue.positionAnchor);
assertThat(modifiedCue.textSize).isEqualTo(cue.textSize);
assertThat(modifiedCue.textSizeType).isEqualTo(cue.textSizeType);
assertThat(modifiedCue.size).isEqualTo(cue.size);
assertThat(modifiedCue.windowColor).isEqualTo(cue.windowColor);
assertThat(modifiedCue.windowColorSet).isEqualTo(cue.windowColorSet);
assertThat(modifiedCue.verticalType).isEqualTo(cue.verticalType);
assertThat(modifiedCue.shearDegrees).isEqualTo(cue.shearDegrees);
assertThat(modifiedCue).isEqualTo(cue);
}
@Test
......@@ -152,8 +136,7 @@ public class CueTest {
new Cue.Builder().setBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)).build();
Cue modifiedCue = parcelAndUnParcelCue(cue);
assertThat(modifiedCue.bitmap.sameAs(cue.bitmap)).isTrue();
assertThat(modifiedCue.bitmapHeight).isEqualTo(cue.bitmapHeight);
assertThat(modifiedCue).isEqualTo(cue);
}
private static Cue parcelAndUnParcelCue(Cue cue) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment