summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicole Huang <nicolehuang@google.com>2018-06-28 17:40:00 +0800
committerNicole Huang <nicolehuang@google.com>2018-07-03 10:24:38 +0800
commite2b863a8f3416e694b7bcccec589dcf46c1d0d84 (patch)
tree7210404b4490e4a373e05aa5c1862f28a818d0ca
parente4d2a1d06a1aac5c71729f51834f5a9952120b3f (diff)
downloadsetupwizard-e2b863a8f3416e694b7bcccec589dcf46c1d0d84.tar.gz
[Overlay resource] Support video from overlay package
support video from overlay package. bug: 110588815 Test: Manually tested and verified Change-Id: Ia5acc27602309ed7a0a081ef5a9629186f77fb8d
-rw-r--r--library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java34
-rw-r--r--library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java67
2 files changed, 92 insertions, 9 deletions
diff --git a/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java b/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java
index 608c32b..3c188e8 100644
--- a/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java
+++ b/library/main/src/com/android/setupwizardlib/view/IllustrationVideoView.java
@@ -72,6 +72,8 @@ public class IllustrationVideoView extends TextureView implements Animatable,
private @RawRes int mVideoResId = 0;
+ private String mVideoResPackageName;
+
@VisibleForTesting Surface mSurface;
private boolean mPrepared;
@@ -80,8 +82,9 @@ public class IllustrationVideoView extends TextureView implements Animatable,
super(context, attrs);
final TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.SuwIllustrationVideoView);
- mVideoResId = a.getResourceId(R.styleable.SuwIllustrationVideoView_suwVideo, 0);
+ final int videoResId = a.getResourceId(R.styleable.SuwIllustrationVideoView_suwVideo, 0);
a.recycle();
+ setVideoResource(videoResId);
// By default the video scales without interpolation, resulting in jagged edges in the
// video. This works around it by making the view go through scaling, which will apply
@@ -110,16 +113,30 @@ public class IllustrationVideoView extends TextureView implements Animatable,
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
+
+ /**
+ * Set the video and video package name to be played by this view.
+ *
+ * @param videoResId Resource ID of the video, typically an MP4 under res/raw.
+ * @param videoResPackageName The package name of videoResId.
+ */
+ public void setVideoResource(@RawRes int videoResId, String videoResPackageName) {
+ if (videoResId != mVideoResId
+ || (videoResPackageName != null && !videoResPackageName.equals(
+ mVideoResPackageName))) {
+ mVideoResId = videoResId;
+ mVideoResPackageName = videoResPackageName;
+ createMediaPlayer();
+ }
+ }
+
/**
* Set the video to be played by this view.
*
* @param resId Resource ID of the video, typically an MP4 under res/raw.
*/
public void setVideoResource(@RawRes int resId) {
- if (resId != mVideoResId) {
- mVideoResId = resId;
- createMediaPlayer();
- }
+ setVideoResource(resId, getContext().getPackageName());
}
@Override
@@ -152,12 +169,11 @@ public class IllustrationVideoView extends TextureView implements Animatable,
mMediaPlayer.setOnInfoListener(this);
mMediaPlayer.setOnErrorListener(this);
- setVideoResourceInternal(mVideoResId);
+ setVideoResourceInternal(mVideoResId, mVideoResPackageName);
}
- private void setVideoResourceInternal(@RawRes int videoRes) {
- Uri uri =
- Uri.parse("android.resource://" + getContext().getPackageName() + "/" + videoRes);
+ private void setVideoResourceInternal(@RawRes int videoRes, String videoResPackageName) {
+ Uri uri = Uri.parse("android.resource://" + videoResPackageName + "/" + videoRes);
try {
mMediaPlayer.setDataSource(getContext(), uri);
mMediaPlayer.prepareAsync();
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 a39ffb9..a6c1808 100644
--- a/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java
+++ b/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java
@@ -190,6 +190,64 @@ public class IllustrationVideoViewTest {
assertThat(aspectRatio).isEqualTo(0.0f);
}
+ @Test
+ public void setVideoResId_resetDiffVideoResFromDiffPackage_videoResShouldBeSet() {
+ // VideoRes default set as android.R.color.white with
+ // default package(com.android.setupwizardlib)
+ createDefaultView();
+
+ // reset different videoRes from different package
+ String newPackageName = "com.android.fakepackage";
+ @RawRes int black = android.R.color.black;
+ addMediaInfo(black, newPackageName);
+ mView.setVideoResource(black, newPackageName);
+
+ // should be reset to black with the new package
+ mShadowMediaPlayer = (ShadowMediaPlayer) Shadows.shadowOf(mView.mMediaPlayer);
+ assertThat(mShadowMediaPlayer.getSourceUri().toString())
+ .isEqualTo("android.resource://" + newPackageName + "/"
+ + android.R.color.black);
+ }
+
+ @Test
+ public void setVideoResId_resetDiffVideoResFromSamePackage_videoResShouldBeSet() {
+ // VideoRes default set as android.R.color.white with
+ // default package(com.android.setupwizardlib)
+ createDefaultView();
+
+ // reset different videoRes from the same package(default package)
+ String defaultPackageName = "com.android.setupwizardlib";
+ @RawRes int black = android.R.color.black;
+ addMediaInfo(black);
+ mView.setVideoResource(black, defaultPackageName);
+
+ // should be reset to black with the same package(default package)
+ mShadowMediaPlayer = (ShadowMediaPlayer) Shadows.shadowOf(mView.mMediaPlayer);
+ assertThat(mShadowMediaPlayer.getSourceUri().toString())
+ .isEqualTo("android.resource://" + defaultPackageName + "/"
+ + android.R.color.black);
+ }
+
+ @Test
+ public void setVideoResId_resetSameVideoResFromDifferentPackage_videoResShouldBeSet() {
+ // VideoRes default set as android.R.color.white with
+ // default package(com.android.setupwizardlib)
+ createDefaultView();
+
+
+ // reset same videoRes from different package
+ @RawRes int white = android.R.color.white;
+ String newPackageName = "com.android.fakepackage";
+ addMediaInfo(white, newPackageName);
+ mView.setVideoResource(white, newPackageName);
+
+ // should be white with the new package
+ mShadowMediaPlayer = (ShadowMediaPlayer) Shadows.shadowOf(mView.mMediaPlayer);
+ assertThat(mShadowMediaPlayer.getSourceUri().toString())
+ .isEqualTo("android.resource://" + newPackageName + "/"
+ + android.R.color.white);
+ }
+
private void createDefaultView() {
mView = new IllustrationVideoView(
application,
@@ -227,6 +285,15 @@ public class IllustrationVideoViewTest {
new MediaInfo(5000, 1));
}
+ private void addMediaInfo(@RawRes int res, String packageName) {
+ ShadowMediaPlayer.addMediaInfo(
+ DataSource.toDataSource(
+ application,
+ Uri.parse("android.resource://" + packageName + "/" + res),
+ null),
+ new MediaInfo(5000, 1));
+ }
+
@Implements(Surface.class)
@TargetApi(VERSION_CODES.HONEYCOMB)
public static class ShadowSurface extends org.robolectric.shadows.ShadowSurface {