DO NOT MERGE - Merge Pie Bonito/Sargo into master.

Bug: 131756210
Change-Id: Ia6aaf3bc9301d914668a11345bc39a25a1f14871
This commit is contained in:
Xin Li 2019-05-09 09:27:04 -07:00
commit 2494de82e3
5 changed files with 82 additions and 7 deletions

View File

@ -19,5 +19,5 @@
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="suw_next_button_label" msgid="7269625133873553978">"आगे बढ़ें"</string>
<string name="suw_back_button_label" msgid="1460929053642711025">"पीछे"</string>
<string name="suw_more_button_label" msgid="7769076059705546563">"ज़्यादा"</string>
<string name="suw_more_button_label" msgid="7769076059705546563">"अधिक"</string>
</resources>

View File

@ -17,7 +17,7 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="suw_next_button_label" msgid="7269625133873553978">"पुढे जा"</string>
<string name="suw_next_button_label" msgid="7269625133873553978">"पुढील"</string>
<string name="suw_back_button_label" msgid="1460929053642711025">"मागे"</string>
<string name="suw_more_button_label" msgid="7769076059705546563">"अधिक"</string>
</resources>

View File

@ -65,6 +65,8 @@ public class IllustrationVideoView extends TextureView implements Animatable,
@VisibleForTesting Surface mSurface;
protected int mWindowVisibility;
public IllustrationVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
final TypedArray a = context.obtainStyledAttributes(attrs,
@ -125,7 +127,7 @@ public class IllustrationVideoView extends TextureView implements Animatable,
* Creates a media player for the current URI. The media player will be started immediately if
* the view's window is visible. If there is an existing media player, it will be released.
*/
private void createMediaPlayer() {
protected void createMediaPlayer() {
if (mMediaPlayer != null) {
mMediaPlayer.release();
}
@ -150,11 +152,35 @@ public class IllustrationVideoView extends TextureView implements Animatable,
} else {
Log.wtf(TAG, "Unable to initialize media player for video view");
}
if (getWindowVisibility() == View.VISIBLE) {
if (mWindowVisibility == View.VISIBLE) {
start();
}
}
protected void createSurface() {
if (mSurface != null) {
mSurface.release();
mSurface = null;
}
// Reattach only if it has been previously released
SurfaceTexture surfaceTexture = getSurfaceTexture();
if (surfaceTexture != null) {
setVisibility(View.INVISIBLE);
mSurface = new Surface(surfaceTexture);
}
}
@Override
protected void onWindowVisibilityChanged(int visibility) {
super.onWindowVisibilityChanged(visibility);
mWindowVisibility = visibility;
if (visibility == View.VISIBLE) {
reattach();
} else {
release();
}
}
/**
* Whether the media player should play the video in a continuous loop. The default value is
* true.
@ -179,14 +205,34 @@ public class IllustrationVideoView extends TextureView implements Animatable,
}
}
private void reattach() {
if (mSurface == null) {
initVideo();
}
}
private void initVideo() {
if (mWindowVisibility != View.VISIBLE) {
return;
}
createSurface();
if (mSurface != null) {
createMediaPlayer();
} else {
Log.w("IllustrationVideoView", "Surface creation failed");
}
}
protected void onRenderingStart() {
}
/* SurfaceTextureListener methods */
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
// Keep the view hidden until video starts
setVisibility(View.INVISIBLE);
mSurface = new Surface(surfaceTexture);
createMediaPlayer();
initVideo();
}
@Override
@ -231,6 +277,7 @@ public class IllustrationVideoView extends TextureView implements Animatable,
if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
// Video available, show view now
setVisibility(View.VISIBLE);
onRenderingStart();
}
return false;
}

View File

@ -16,6 +16,8 @@
package com.android.setupwizardlib.view;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@ -30,6 +32,7 @@ import android.graphics.SurfaceTexture;
import android.media.MediaPlayer;
import android.os.Build.VERSION_CODES;
import android.view.Surface;
import android.view.View;
import androidx.annotation.RawRes;
@ -91,6 +94,30 @@ public class IllustrationVideoViewTest {
}
}
@Test
public void onVisibilityChanged_notVisible_shouldRelease() {
createDefaultView();
mView.onWindowVisibilityChanged(View.GONE);
verify(ShadowMockMediaPlayer.sMediaPlayer).release();
assertThat(mView.mSurface).isNull();
assertThat(mView.mMediaPlayer).isNull();
}
@Test
public void onVisibilityChanged_visible_shouldPlay() {
createDefaultView();
mView.onWindowVisibilityChanged(View.GONE);
assertThat(mView.mSurface).isNull();
assertThat(mView.mMediaPlayer).isNull();
mView.onWindowVisibilityChanged(View.VISIBLE);
assertThat(mView.mSurface).isNotNull();
assertThat(mView.mMediaPlayer).isNotNull();
}
@Test
public void testPausedWhenWindowFocusLost() {
createDefaultView();
@ -149,6 +176,7 @@ public class IllustrationVideoViewTest {
// Any resource attribute should work, since the media player is mocked
.addAttribute(R.attr.suwVideo, "@android:color/white")
.build());
mView.setSurfaceTexture(mock(SurfaceTexture.class));
mView.onSurfaceTextureAvailable(mSurfaceTexture, 500, 500);
}

View File

@ -2,5 +2,5 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="setup_wizard_next_button_label" msgid="6681282266022780599">"Seuraava"</string>
<string name="setup_wizard_back_button_label" msgid="2863826823307023546">"Takaisin"</string>
<string name="setup_wizard_back_button_label" msgid="2863826823307023546">"Edellinen"</string>
</resources>