Merge "Automatically play the gesture video when the setting is launched."
This commit is contained in:
committed by
Android (Google) Code Review
commit
ade7f5b531
@@ -17,6 +17,8 @@
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
@@ -27,14 +29,20 @@ import com.android.settings.widget.VideoPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
||||
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
public abstract class GesturePreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
LifecycleObserver, OnStart, OnStop, OnCreate, OnSaveInstanceState {
|
||||
|
||||
@VisibleForTesting
|
||||
static final String KEY_VIDEO_PAUSED = "key_video_paused";
|
||||
|
||||
private VideoPreference mVideoPreference;
|
||||
private boolean mVideoPaused;
|
||||
|
||||
public GesturePreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context);
|
||||
@@ -66,6 +74,21 @@ public abstract class GesturePreferenceController extends AbstractPreferenceCont
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
if (savedInstanceState != null) {
|
||||
mVideoPaused = savedInstanceState.getBoolean(KEY_VIDEO_PAUSED, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
if (mVideoPreference != null) {
|
||||
mVideoPaused = mVideoPreference.isVideoPaused();
|
||||
}
|
||||
outState.putBoolean(KEY_VIDEO_PAUSED, mVideoPaused);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mVideoPreference != null) {
|
||||
@@ -76,7 +99,7 @@ public abstract class GesturePreferenceController extends AbstractPreferenceCont
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mVideoPreference != null) {
|
||||
mVideoPreference.onViewVisible();
|
||||
mVideoPreference.onViewVisible(mVideoPaused);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -45,6 +45,7 @@ public class VideoPreference extends Preference {
|
||||
private MediaPlayer mMediaPlayer;
|
||||
private boolean mAnimationAvailable;
|
||||
private boolean mVideoReady;
|
||||
private boolean mVideoPaused;
|
||||
private int mPreviewResource;
|
||||
|
||||
public VideoPreference(Context context, AttributeSet attrs) {
|
||||
@@ -100,9 +101,11 @@ public class VideoPreference extends Preference {
|
||||
if (mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.pause();
|
||||
playButton.setVisibility(View.VISIBLE);
|
||||
mVideoPaused = true;
|
||||
} else {
|
||||
mMediaPlayer.start();
|
||||
playButton.setVisibility(View.GONE);
|
||||
mVideoPaused = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -133,6 +136,10 @@ public class VideoPreference extends Preference {
|
||||
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
|
||||
if (mVideoReady && imageView.getVisibility() == View.VISIBLE) {
|
||||
imageView.setVisibility(View.GONE);
|
||||
if (!mVideoPaused && mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.start();
|
||||
playButton.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
if (mMediaPlayer != null && !mMediaPlayer.isPlaying() &&
|
||||
playButton.getVisibility() != View.VISIBLE) {
|
||||
@@ -152,7 +159,8 @@ public class VideoPreference extends Preference {
|
||||
super.onDetached();
|
||||
}
|
||||
|
||||
public void onViewVisible() {
|
||||
public void onViewVisible(boolean videoPaused) {
|
||||
mVideoPaused = videoPaused;
|
||||
if (mVideoReady && mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.seekTo(0);
|
||||
}
|
||||
@@ -163,4 +171,9 @@ public class VideoPreference extends Preference {
|
||||
mMediaPlayer.pause();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVideoPaused() {
|
||||
return mVideoPaused;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user