summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
Diffstat (limited to 'library')
-rw-r--r--library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java12
-rw-r--r--library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowMediaPlayer.java31
-rw-r--r--library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java29
3 files changed, 69 insertions, 3 deletions
diff --git a/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java b/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java
index e5688b3..608c32b 100644
--- a/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java
+++ b/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java
@@ -294,9 +294,15 @@ public class IllustrationVideoView extends TextureView implements Animatable,
public void onPrepared(MediaPlayer mp) {
mPrepared = true;
mp.setLooping(shouldLoop());
- float aspectRatio =
- (float) mp.getVideoHeight() / mp.getVideoWidth();
- if (Float.compare(mAspectRatio, aspectRatio) == 0) {
+
+ float aspectRatio = 0.0f;
+ if (mp.getVideoWidth() > 0 && mp.getVideoHeight() > 0) {
+ aspectRatio = (float) mp.getVideoHeight() / mp.getVideoWidth();
+ } else {
+ Log.w(TAG, "Unexpected video size=" + mp.getVideoWidth() + "x"
+ + mp.getVideoHeight());
+ }
+ if (Float.compare(mAspectRatio, aspectRatio) != 0) {
mAspectRatio = aspectRatio;
requestLayout();
}
diff --git a/library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowMediaPlayer.java b/library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowMediaPlayer.java
index 2ef2b7d..7bcefd0 100644
--- a/library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowMediaPlayer.java
+++ b/library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowMediaPlayer.java
@@ -34,6 +34,15 @@ import java.util.Map;
@Implements(MediaPlayer.class)
public class ShadowMediaPlayer extends org.robolectric.shadows.ShadowMediaPlayer {
+ private int mVideoWidth;
+ private int mVideoHeight;
+
+ public ShadowMediaPlayer() {
+ super();
+ mVideoWidth = -1;
+ mVideoHeight = -1;
+ }
+
@Implementation
public void setDataSource(
@NonNull Context context,
@@ -48,4 +57,26 @@ public class ShadowMediaPlayer extends org.robolectric.shadows.ShadowMediaPlayer
public void seekTo(long msec, int mode) {
seekTo((int) msec);
}
+
+ public void setVideoSize(int width, int height) {
+ if (width < 0) {
+ throw new IllegalArgumentException("Unexpected negative width=" + width);
+ }
+ if (height < 0) {
+ throw new IllegalArgumentException("Unexpected negative height=" + height);
+ }
+
+ mVideoWidth = width;
+ mVideoHeight = height;
+ }
+
+ @Override
+ public int getVideoWidth() {
+ return mVideoWidth;
+ }
+
+ @Override
+ public int getVideoHeight() {
+ return mVideoHeight;
+ }
}
diff --git a/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java b/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java
index c09e22f..a39ffb9 100644
--- a/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java
+++ b/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java
@@ -161,6 +161,35 @@ public class IllustrationVideoViewTest {
+ android.R.color.black);
}
+ @Test
+ public void prepareVideo_shouldSetAspectRatio() {
+ createDefaultView();
+
+ mShadowMediaPlayer.setVideoSize(720, 1280);
+
+ Robolectric.flushForegroundThreadScheduler();
+ mView.start();
+
+ mView.measure(View.MeasureSpec.makeMeasureSpec(720, View.MeasureSpec.EXACTLY),
+ View.MeasureSpec.makeMeasureSpec(720, View.MeasureSpec.EXACTLY));
+
+ final float aspectRatio = (float) mView.getMeasuredHeight() / mView.getMeasuredWidth();
+ assertThat(aspectRatio).isWithin(0.001f).of(1280f / 720f);
+ }
+
+ @Test
+ public void prepareVideo_zeroHeight_shouldSetAspectRatioToZero() {
+ createDefaultView();
+
+ mShadowMediaPlayer.setVideoSize(720, 0);
+
+ Robolectric.flushForegroundThreadScheduler();
+ mView.start();
+
+ final float aspectRatio = (float) mView.getHeight() / mView.getWidth();
+ assertThat(aspectRatio).isEqualTo(0.0f);
+ }
+
private void createDefaultView() {
mView = new IllustrationVideoView(
application,