Add video to each gesture preference screen.
- Refactor GesturePreference to a generic VideoPreference. - The old video_preference.xml is only for magnification video, so renamed. - And use VideoPreference in gesture setting pages. - Refactor common logic into GesturePreferenceController. Bug: 32637613 Test: RunSettingsRoboTests Change-Id: I58580b01a32873cb32c5dc5bf2ec021d5b1400cc
This commit is contained in:
@@ -120,7 +120,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends ToggleFeaturePr
|
||||
mVideoPreference = new VideoPreference(getPrefContext());
|
||||
mVideoPreference.setSelectable(false);
|
||||
mVideoPreference.setPersistent(false);
|
||||
mVideoPreference.setLayoutResource(R.layout.video_preference);
|
||||
mVideoPreference.setLayoutResource(R.layout.magnification_video_preference);
|
||||
|
||||
final PreferenceScreen preferenceScreen = getPreferenceManager().getPreferenceScreen();
|
||||
preferenceScreen.setOrderingAsAdded(false);
|
||||
|
@@ -60,6 +60,13 @@ public abstract class ObservablePreferenceFragment extends PreferenceFragment {
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onStop() {
|
||||
mLifecycle.onStop();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
@@ -19,17 +19,16 @@ package com.android.settings.gestures;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
|
||||
public class DoubleTapPowerPreferenceController extends PreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
public class DoubleTapPowerPreferenceController extends GesturePreferenceController {
|
||||
|
||||
private static final String PREF_KEY_VIDEO = "gesture_double_tap_power_video";
|
||||
private static final String PREF_KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
|
||||
|
||||
public DoubleTapPowerPreferenceController(Context context) {
|
||||
super(context);
|
||||
public DoubleTapPowerPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,8 +38,8 @@ public class DoubleTapPowerPreferenceController extends PreferenceController
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
return false;
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_KEY_VIDEO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,20 +47,6 @@ public class DoubleTapPowerPreferenceController extends PreferenceController
|
||||
return PREF_KEY_DOUBLE_TAP_POWER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final boolean isEnabled = isDoubleTapEnabled();
|
||||
if (preference != null) {
|
||||
if (preference instanceof TwoStatePreference) {
|
||||
((TwoStatePreference) preference).setChecked(isEnabled);
|
||||
} else {
|
||||
preference.setSummary(isEnabled
|
||||
? com.android.settings.R.string.gesture_setting_on
|
||||
: com.android.settings.R.string.gesture_setting_off);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
boolean enabled = (boolean) newValue;
|
||||
@@ -70,7 +55,8 @@ public class DoubleTapPowerPreferenceController extends PreferenceController
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isDoubleTapEnabled() {
|
||||
@Override
|
||||
protected boolean isSwitchPrefEnabled() {
|
||||
final int cameraDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0);
|
||||
return cameraDisabled == 0;
|
||||
|
@@ -52,7 +52,7 @@ public class DoubleTapPowerSettings extends DashboardFragment {
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new DoubleTapPowerPreferenceController(context));
|
||||
controllers.add(new DoubleTapPowerPreferenceController(context, getLifecycle()));
|
||||
return controllers;
|
||||
}
|
||||
}
|
||||
|
@@ -20,23 +20,22 @@ import android.annotation.UserIdInt;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
|
||||
public class DoubleTapScreenPreferenceController extends PreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
public class DoubleTapScreenPreferenceController extends GesturePreferenceController {
|
||||
|
||||
private static final String PREF_KEY_VIDEO = "gesture_double_tap_screen_video";
|
||||
private static final String PREF_KEY_DOUBLE_TAP_SCREEN = "gesture_double_tap_screen";
|
||||
|
||||
private final AmbientDisplayConfiguration mAmbientConfig;
|
||||
@UserIdInt
|
||||
private final int mUserId;
|
||||
|
||||
public DoubleTapScreenPreferenceController(Context context, AmbientDisplayConfiguration config,
|
||||
@UserIdInt int userId) {
|
||||
super(context);
|
||||
public DoubleTapScreenPreferenceController(Context context, Lifecycle lifecycle,
|
||||
AmbientDisplayConfiguration config, @UserIdInt int userId) {
|
||||
super(context, lifecycle);
|
||||
mAmbientConfig = config;
|
||||
mUserId = userId;
|
||||
}
|
||||
@@ -46,25 +45,6 @@ public class DoubleTapScreenPreferenceController extends PreferenceController
|
||||
return mAmbientConfig.pulseOnDoubleTapAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final boolean isEnabled = mAmbientConfig.pulseOnDoubleTapEnabled(mUserId);
|
||||
if (preference != null) {
|
||||
if (preference instanceof TwoStatePreference) {
|
||||
((TwoStatePreference) preference).setChecked(isEnabled);
|
||||
} else {
|
||||
preference.setSummary(isEnabled
|
||||
? com.android.settings.R.string.gesture_setting_on
|
||||
: com.android.settings.R.string.gesture_setting_off);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return PREF_KEY_DOUBLE_TAP_SCREEN;
|
||||
@@ -77,4 +57,14 @@ public class DoubleTapScreenPreferenceController extends PreferenceController
|
||||
Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, enabled ? 1 : 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_KEY_VIDEO;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSwitchPrefEnabled() {
|
||||
return mAmbientConfig.pulseOnDoubleTapEnabled(mUserId);
|
||||
}
|
||||
}
|
||||
|
@@ -54,8 +54,8 @@ public class DoubleTapScreenSettings extends DashboardFragment {
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new DoubleTapScreenPreferenceController(
|
||||
context, new AmbientDisplayConfiguration(context), UserHandle.myUserId()));
|
||||
controllers.add(new DoubleTapScreenPreferenceController(context, getLifecycle(),
|
||||
new AmbientDisplayConfiguration(context), UserHandle.myUserId()));
|
||||
return controllers;
|
||||
}
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ public class DoubleTwistGestureSettings extends DashboardFragment {
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new DoubleTwistPreferenceController(context));
|
||||
controllers.add(new DoubleTwistPreferenceController(context, getLifecycle()));
|
||||
return controllers;
|
||||
}
|
||||
}
|
||||
|
@@ -22,19 +22,18 @@ import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
|
||||
public class DoubleTwistPreferenceController extends PreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
public class DoubleTwistPreferenceController extends GesturePreferenceController {
|
||||
|
||||
private static final String PREF_KEY_VIDEO = "gesture_double_twist_video";
|
||||
private static final String PREF_KEY_DOUBLE_TWIST = "gesture_double_twist";
|
||||
|
||||
public DoubleTwistPreferenceController(Context context) {
|
||||
super(context);
|
||||
public DoubleTwistPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,22 +43,8 @@ public class DoubleTwistPreferenceController extends PreferenceController
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final boolean isEnabled = isDoubleTwistEnabled();
|
||||
if (preference != null) {
|
||||
if (preference instanceof TwoStatePreference) {
|
||||
((TwoStatePreference) preference).setChecked(isEnabled);
|
||||
} else {
|
||||
preference.setSummary(isEnabled
|
||||
? com.android.settings.R.string.gesture_setting_on
|
||||
: com.android.settings.R.string.gesture_setting_off);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
return false;
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_KEY_VIDEO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,7 +52,16 @@ public class DoubleTwistPreferenceController extends PreferenceController
|
||||
return PREF_KEY_DOUBLE_TWIST;
|
||||
}
|
||||
|
||||
private boolean isDoubleTwistEnabled() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean enabled = (boolean) newValue;
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled ? 1 : 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSwitchPrefEnabled() {
|
||||
final int doubleTwistEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
|
||||
return doubleTwistEnabled != 0;
|
||||
@@ -88,12 +82,4 @@ public class DoubleTwistPreferenceController extends PreferenceController
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean enabled = (boolean) newValue;
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled ? 1 : 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
import com.android.settings.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settings.core.lifecycle.events.OnStart;
|
||||
import com.android.settings.core.lifecycle.events.OnStop;
|
||||
import com.android.settings.widget.VideoPreference;
|
||||
|
||||
public abstract class GesturePreferenceController extends PreferenceController
|
||||
implements Preference.OnPreferenceChangeListener, LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private VideoPreference mVideoPreference;
|
||||
|
||||
public GesturePreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context);
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
if (isAvailable()) {
|
||||
mVideoPreference = (VideoPreference) screen.findPreference(getVideoPrefKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final boolean isEnabled = isSwitchPrefEnabled();
|
||||
if (preference != null) {
|
||||
if (preference instanceof TwoStatePreference) {
|
||||
((TwoStatePreference) preference).setChecked(isEnabled);
|
||||
} else {
|
||||
preference.setSummary(isEnabled
|
||||
? R.string.gesture_setting_on
|
||||
: R.string.gesture_setting_off);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mVideoPreference != null) {
|
||||
mVideoPreference.onViewInvisible();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mVideoPreference != null) {
|
||||
mVideoPreference.onViewVisible();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String getVideoPrefKey();
|
||||
|
||||
protected abstract boolean isSwitchPrefEnabled();
|
||||
}
|
@@ -30,6 +30,7 @@ import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
@@ -56,13 +57,14 @@ public class GestureSettings extends DashboardFragment {
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final AmbientDisplayConfiguration ambientConfig = new AmbientDisplayConfiguration(context);
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new SwipeToNotificationPreferenceController(context));
|
||||
controllers.add(new DoubleTapPowerPreferenceController(context));
|
||||
controllers.add(new DoubleTwistPreferenceController(context));
|
||||
final Lifecycle lifecycle = getLifecycle();
|
||||
controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle));
|
||||
controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle));
|
||||
controllers.add(new DoubleTwistPreferenceController(context, lifecycle));
|
||||
controllers.add(new PickupGesturePreferenceController(
|
||||
context, ambientConfig, UserHandle.myUserId()));
|
||||
context, lifecycle, ambientConfig, UserHandle.myUserId()));
|
||||
controllers.add(new DoubleTapScreenPreferenceController(
|
||||
context, ambientConfig, UserHandle.myUserId()));
|
||||
context, lifecycle, ambientConfig, UserHandle.myUserId()));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@@ -167,17 +169,17 @@ public class GestureSettings extends DashboardFragment {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
AmbientDisplayConfiguration ambientConfig
|
||||
= new AmbientDisplayConfiguration(context);
|
||||
new DoubleTapPowerPreferenceController(context)
|
||||
new DoubleTapPowerPreferenceController(context, null /* lifecycle */)
|
||||
.updateNonIndexableKeys(result);
|
||||
new PickupGesturePreferenceController(
|
||||
context, ambientConfig, UserHandle.myUserId())
|
||||
context, null /* lifecycle */, ambientConfig, UserHandle.myUserId())
|
||||
.updateNonIndexableKeys(result);
|
||||
new DoubleTapScreenPreferenceController(
|
||||
context, ambientConfig, UserHandle.myUserId())
|
||||
context, null /* lifecycle */, ambientConfig, UserHandle.myUserId())
|
||||
.updateNonIndexableKeys(result);
|
||||
new SwipeToNotificationPreferenceController(context)
|
||||
new SwipeToNotificationPreferenceController(context, null /* lifecycle */)
|
||||
.updateNonIndexableKeys(result);
|
||||
new DoubleTwistPreferenceController(context)
|
||||
new DoubleTwistPreferenceController(context, null /* lifecycle */)
|
||||
.updateNonIndexableKeys(result);
|
||||
return result;
|
||||
}
|
||||
|
@@ -20,23 +20,22 @@ import android.annotation.UserIdInt;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
|
||||
public class PickupGesturePreferenceController extends PreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
public class PickupGesturePreferenceController extends GesturePreferenceController {
|
||||
|
||||
private static final String PREF_VIDEO_KEY = "gesture_pick_up_video";
|
||||
private static final String PREF_KEY_PICK_UP = "gesture_pick_up";
|
||||
|
||||
private final AmbientDisplayConfiguration mAmbientConfig;
|
||||
@UserIdInt
|
||||
private final int mUserId;
|
||||
|
||||
public PickupGesturePreferenceController(Context context, AmbientDisplayConfiguration config,
|
||||
@UserIdInt int userId) {
|
||||
super(context);
|
||||
public PickupGesturePreferenceController(Context context, Lifecycle lifecycle,
|
||||
AmbientDisplayConfiguration config, @UserIdInt int userId) {
|
||||
super(context, lifecycle);
|
||||
mAmbientConfig = config;
|
||||
mUserId = userId;
|
||||
}
|
||||
@@ -47,8 +46,13 @@ public class PickupGesturePreferenceController extends PreferenceController
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
return false;
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_VIDEO_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSwitchPrefEnabled() {
|
||||
return mAmbientConfig.pulseOnPickupEnabled(mUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,20 +60,6 @@ public class PickupGesturePreferenceController extends PreferenceController
|
||||
return PREF_KEY_PICK_UP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final boolean isEnabled = mAmbientConfig.pulseOnPickupEnabled(mUserId);
|
||||
if (preference != null) {
|
||||
if (preference instanceof TwoStatePreference) {
|
||||
((TwoStatePreference) preference).setChecked(isEnabled);
|
||||
} else {
|
||||
preference.setSummary(isEnabled
|
||||
? com.android.settings.R.string.gesture_setting_on
|
||||
: com.android.settings.R.string.gesture_setting_off);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean enabled = (boolean) newValue;
|
||||
|
@@ -54,8 +54,8 @@ public class PickupGestureSettings extends DashboardFragment {
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new PickupGesturePreferenceController(
|
||||
context, new AmbientDisplayConfiguration(context), UserHandle.myUserId()));
|
||||
controllers.add(new PickupGesturePreferenceController(context, getLifecycle(),
|
||||
new AmbientDisplayConfiguration(context), UserHandle.myUserId()));
|
||||
return controllers;
|
||||
}
|
||||
}
|
||||
|
@@ -19,18 +19,16 @@ package com.android.settings.gestures;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
|
||||
public class SwipeToNotificationPreferenceController extends PreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
public class SwipeToNotificationPreferenceController extends GesturePreferenceController {
|
||||
|
||||
private static final String PREF_KEY_VIDEO = "gesture_swipe_down_fingerprint_video";
|
||||
private static final String PREF_KEY_SWIPE_DOWN_FINGERPRINT = "gesture_swipe_down_fingerprint";
|
||||
|
||||
public SwipeToNotificationPreferenceController(Context context) {
|
||||
super(context);
|
||||
public SwipeToNotificationPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,18 +42,8 @@ public class SwipeToNotificationPreferenceController extends PreferenceControlle
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final boolean isEnabled = isSystemUINavigationEnabled();
|
||||
if (preference != null) {
|
||||
if (preference instanceof TwoStatePreference) {
|
||||
((TwoStatePreference) preference).setChecked(isEnabled);
|
||||
} else {
|
||||
preference.setSummary(isEnabled
|
||||
? R.string.gesture_setting_on
|
||||
: R.string.gesture_setting_off);
|
||||
}
|
||||
}
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_KEY_VIDEO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,16 +52,17 @@ public class SwipeToNotificationPreferenceController extends PreferenceControlle
|
||||
com.android.internal.R.bool.config_supportSystemNavigationKeys);
|
||||
}
|
||||
|
||||
private boolean isSystemUINavigationEnabled() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0)
|
||||
== 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, (boolean) newValue ? 1 : 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSwitchPrefEnabled() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0)
|
||||
== 1;
|
||||
}
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ public class SwipeToNotificationSettings extends DashboardFragment {
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new SwipeToNotificationPreferenceController(context));
|
||||
controllers.add(new SwipeToNotificationPreferenceController(context, getLifecycle()));
|
||||
return controllers;
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import android.support.annotation.VisibleForTesting;
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.gestures.DoubleTapPowerPreferenceController;
|
||||
import com.android.settings.gestures.DoubleTapScreenPreferenceController;
|
||||
@@ -62,6 +63,7 @@ public class InputAndGestureSettings extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final Lifecycle lifecycle = getLifecycle();
|
||||
final GameControllerPreferenceController gameControllerPreferenceController
|
||||
= new GameControllerPreferenceController(context);
|
||||
getLifecycle().addObserver(gameControllerPreferenceController);
|
||||
@@ -72,13 +74,14 @@ public class InputAndGestureSettings extends DashboardFragment {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(gameControllerPreferenceController);
|
||||
// Gestures
|
||||
controllers.add(new SwipeToNotificationPreferenceController(context));
|
||||
controllers.add(new DoubleTwistPreferenceController(context));
|
||||
controllers.add(new DoubleTapPowerPreferenceController(context));
|
||||
|
||||
controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle));
|
||||
controllers.add(new DoubleTwistPreferenceController(context, lifecycle));
|
||||
controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle));
|
||||
controllers.add(new PickupGesturePreferenceController(
|
||||
context, mAmbientDisplayConfig, UserHandle.myUserId()));
|
||||
context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId()));
|
||||
controllers.add(new DoubleTapScreenPreferenceController(
|
||||
context, mAmbientDisplayConfig, UserHandle.myUserId()));
|
||||
context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId()));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
@@ -62,7 +62,7 @@ public class ConfigureNotificationSettings extends DashboardFragment {
|
||||
mLockScreenNotificationController = new LockScreenNotificationPreferenceController(context);
|
||||
getLifecycle().addObserver(pulseController);
|
||||
getLifecycle().addObserver(mLockScreenNotificationController);
|
||||
controllers.add(new SwipeToNotificationPreferenceController(context));
|
||||
controllers.add(new SwipeToNotificationPreferenceController(context, getLifecycle()));
|
||||
controllers.add(pulseController);
|
||||
controllers.add(mLockScreenNotificationController);
|
||||
return controllers;
|
||||
|
163
src/com/android/settings/widget/VideoPreference.java
Normal file
163
src/com/android/settings/widget/VideoPreference.java
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.widget;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import android.view.TextureView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* A full width preference that hosts a MP4 video.
|
||||
*/
|
||||
public class VideoPreference extends Preference {
|
||||
|
||||
private static final String TAG = "VideoPreference";
|
||||
private final Context mContext;
|
||||
|
||||
private Uri mVideoPath;
|
||||
private MediaPlayer mMediaPlayer;
|
||||
private boolean mAnimationAvailable;
|
||||
private boolean mVideoReady;
|
||||
private int mPreviewResource;
|
||||
|
||||
public VideoPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mContext = context;
|
||||
TypedArray attributes = context.getTheme().obtainStyledAttributes(
|
||||
attrs,
|
||||
com.android.settings.R.styleable.VideoPreference,
|
||||
0, 0);
|
||||
try {
|
||||
int animation = attributes.getResourceId(R.styleable.VideoPreference_animation, 0);
|
||||
mVideoPath = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
|
||||
.authority(context.getPackageName())
|
||||
.appendPath(String.valueOf(animation))
|
||||
.build();
|
||||
mMediaPlayer = MediaPlayer.create(mContext, mVideoPath);
|
||||
if (mMediaPlayer != null && mMediaPlayer.getDuration() > 0) {
|
||||
setLayoutResource(R.layout.video_preference);
|
||||
|
||||
mPreviewResource = attributes.getResourceId(
|
||||
R.styleable.VideoPreference_preview, 0);
|
||||
|
||||
mMediaPlayer.setOnSeekCompleteListener(mp -> mVideoReady = true);
|
||||
|
||||
mMediaPlayer.setOnPreparedListener(mediaPlayer -> mediaPlayer.setLooping(true));
|
||||
mAnimationAvailable = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Animation resource not found. Will not show animation.");
|
||||
} finally {
|
||||
attributes.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
if (!mAnimationAvailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextureView video = (TextureView) holder.findViewById(R.id.video_texture_view);
|
||||
final ImageView imageView = (ImageView) holder.findViewById(R.id.video_preview_image);
|
||||
final ImageView playButton = (ImageView) holder.findViewById(R.id.video_play_button);
|
||||
imageView.setImageResource(mPreviewResource);
|
||||
|
||||
video.setOnClickListener(v -> {
|
||||
if (mMediaPlayer != null) {
|
||||
if (mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.pause();
|
||||
playButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mMediaPlayer.start();
|
||||
playButton.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
video.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
|
||||
@Override
|
||||
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width,
|
||||
int height) {
|
||||
if (mMediaPlayer != null) {
|
||||
mMediaPlayer.setSurface(new Surface(surfaceTexture));
|
||||
mVideoReady = false;
|
||||
mMediaPlayer.seekTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width,
|
||||
int height) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
|
||||
if (mVideoReady && imageView.getVisibility() == View.VISIBLE) {
|
||||
imageView.setVisibility(View.GONE);
|
||||
}
|
||||
if (mMediaPlayer != null && !mMediaPlayer.isPlaying() &&
|
||||
playButton.getVisibility() != View.VISIBLE) {
|
||||
playButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetached() {
|
||||
if (mMediaPlayer != null) {
|
||||
mMediaPlayer.stop();
|
||||
mMediaPlayer.reset();
|
||||
mMediaPlayer.release();
|
||||
}
|
||||
super.onDetached();
|
||||
}
|
||||
|
||||
public void onViewVisible() {
|
||||
if (mVideoReady && mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.seekTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void onViewInvisible() {
|
||||
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.pause();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user