Settings: Allow showing Ambient instead of fully waking [2/2]
* [joeyhuab] Adapt to A16; Remove MainSwitchPreference.updateStatus like 041bc113eb
Separate configs for st2w and lift to wake
Follow our convention in the rest of the switches in that page
Change-Id: Ibd82d808aca2caf3f9c4518eb0c2e5f60669759e
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
Signed-off-by: Edwiin Kusuma Jaya <kutemeikito0905@gmail.com>
This commit is contained in:
@@ -331,4 +331,10 @@
|
||||
<!-- HDR Display -->
|
||||
<string name="hdr_display_title">HDR Display</string>
|
||||
<string name="hdr_display_summary">Enable peak brightness for HDR content. This will increase battery usage</string>
|
||||
|
||||
<!-- Ambient wake toggles -->
|
||||
<string name="doze_gesture_ambient_title">Show Ambient</string>
|
||||
<string name="doze_gesture_ambient_summary">Show Ambient Display instead of fully waking the screen up</string>
|
||||
<string name="gesture_wake_ambient">Show Ambient</string>
|
||||
<string name="gesture_wake">Fully wake</string>
|
||||
</resources>
|
||||
|
||||
@@ -67,8 +67,8 @@
|
||||
android:fragment="com.android.settings.gestures.OneHandedSettings"
|
||||
settings:controller="com.android.settings.gestures.OneHandedEnablePreferenceController" />
|
||||
|
||||
<Preference
|
||||
android:key="gesture_tap_screen_input_summary"
|
||||
<com.android.settingslib.PrimarySwitchPreference
|
||||
android:key="gesture_tap"
|
||||
android:title="@string/ambient_display_tap_screen_title"
|
||||
android:fragment="com.android.settings.gestures.TapScreenGestureSettings"
|
||||
settings:searchable="false"
|
||||
@@ -88,7 +88,7 @@
|
||||
settings:controller="com.android.settings.gestures.DoubleTapAmbientSettingsPreferenceController"
|
||||
settings:userRestriction="no_ambient_display" />
|
||||
|
||||
<Preference
|
||||
<com.android.settingslib.PrimarySwitchPreference
|
||||
android:key="gesture_pick_up_input_summary"
|
||||
android:title="@string/ambient_display_pickup_title"
|
||||
android:fragment="com.android.settings.gestures.PickupGestureSettings"
|
||||
|
||||
@@ -26,12 +26,19 @@
|
||||
settings:searchable="false"
|
||||
app:lottie_rawRes="@raw/lottie_lift_to_check_phone"/>
|
||||
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
<com.android.settingslib.widget.MainSwitchPreference
|
||||
android:key="gesture_pick_up"
|
||||
android:title="@string/ambient_display_pickup_title"
|
||||
android:summary="@string/ambient_display_pickup_summary"
|
||||
app:keywords="@string/keywords_gesture"
|
||||
app:controller="com.android.settings.gestures.PickupGesturePreferenceController" />
|
||||
app:keywords="@string/keywords_gesture" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="ambient_display_pickup"
|
||||
android:title="@string/ambient_display_pickup_summary" />
|
||||
|
||||
<org.evolution.settings.preferences.SecureSettingSwitchPreference
|
||||
android:key="doze_pick_up_gesture_ambient"
|
||||
android:title="@string/doze_gesture_ambient_title"
|
||||
android:summary="@string/doze_gesture_ambient_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -117,8 +117,8 @@
|
||||
android:fragment="com.android.settings.display.AODSchedule"
|
||||
settings:controller="com.android.settings.display.AODSchedulePreferenceController" />
|
||||
|
||||
<Preference
|
||||
android:key="ambient_display_tap"
|
||||
<com.android.settingslib.PrimarySwitchPreference
|
||||
android:key="gesture_tap"
|
||||
android:title="@string/ambient_display_tap_screen_title"
|
||||
android:fragment="com.android.settings.gestures.TapScreenGestureSettings"
|
||||
settings:searchable="false"
|
||||
@@ -131,7 +131,7 @@
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.gestures.DoubleTapScreenPreferenceController" />
|
||||
|
||||
<Preference
|
||||
<com.android.settingslib.PrimarySwitchPreference
|
||||
android:key="ambient_display_pick_up"
|
||||
android:title="@string/ambient_display_pickup_title"
|
||||
android:fragment="com.android.settings.gestures.PickupGestureSettings"
|
||||
|
||||
@@ -26,11 +26,19 @@
|
||||
settings:searchable="false"
|
||||
app:lottie_rawRes="@raw/lottie_tap_to_check_phone"/>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
<com.android.settingslib.widget.MainSwitchPreference
|
||||
android:key="gesture_tap"
|
||||
android:title="@string/ambient_display_tap_screen_title"
|
||||
android:summary="@string/ambient_display_tap_screen_summary"
|
||||
app:keywords="@string/keywords_gesture"
|
||||
app:controller="com.android.settings.gestures.TapScreenGesturePreferenceController" />
|
||||
app:keywords="@string/keywords_gesture" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="gesture_tap_category"
|
||||
android:title="@string/ambient_display_tap_screen_summary" />
|
||||
|
||||
<org.evolution.settings.preferences.SecureSettingSwitchPreference
|
||||
android:key="doze_tap_gesture_ambient"
|
||||
android:title="@string/doze_gesture_ambient_title"
|
||||
android:summary="@string/doze_gesture_ambient_summary"
|
||||
android:defaultValue="true" />
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Yet Another AOSP 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.provider.Settings;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
|
||||
import org.evolution.settings.preferences.SecureSettingSwitchPreference;
|
||||
|
||||
public class PickupGestureInsidePreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, OnCheckedChangeListener {
|
||||
|
||||
private static final String KEY = "gesture_pick_up";
|
||||
private static final String AMBIENT_KEY = "doze_pick_up_gesture_ambient";
|
||||
|
||||
private final boolean mDefault;
|
||||
private final Context mContext;
|
||||
private MainSwitchPreference mSwitch;
|
||||
private SecureSettingSwitchPreference mAmbientPref;
|
||||
|
||||
public PickupGestureInsidePreferenceController(Context context) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
mDefault = context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_dozePickupGestureEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mAmbientPref = screen.findPreference(AMBIENT_KEY);
|
||||
mSwitch = screen.findPreference(getPreferenceKey());
|
||||
mSwitch.setOnPreferenceClickListener(preference -> {
|
||||
final boolean enabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DOZE_PICK_UP_GESTURE, mDefault ? 1 : 0) == 1;
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DOZE_PICK_UP_GESTURE,
|
||||
enabled ? 0 : 1);
|
||||
updateAmbientEnablement(!enabled);
|
||||
return true;
|
||||
});
|
||||
mSwitch.addOnSwitchChangeListener(this);
|
||||
updateState(mSwitch);
|
||||
}
|
||||
|
||||
public void setChecked(boolean isChecked) {
|
||||
if (mSwitch != null) {
|
||||
mSwitch.setChecked(isChecked);
|
||||
}
|
||||
updateAmbientEnablement(isChecked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final boolean enabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DOZE_PICK_UP_GESTURE, mDefault ? 1 : 0) == 1;
|
||||
setChecked(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DOZE_PICK_UP_GESTURE, isChecked ? 1 : 0);
|
||||
updateAmbientEnablement(isChecked);
|
||||
}
|
||||
|
||||
private void updateAmbientEnablement(boolean enabled) {
|
||||
if (mAmbientPref == null) return;
|
||||
mAmbientPref.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
@@ -19,31 +19,49 @@ package com.android.settings.gestures;
|
||||
import static android.provider.Settings.Secure.DOZE_PICK_UP_GESTURE;
|
||||
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.ContentObserver;
|
||||
import android.hardware.display.AmbientDisplayConfiguration;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class PickupGesturePreferenceController extends GesturePreferenceController {
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
import com.android.settingslib.PrimarySwitchPreference;
|
||||
|
||||
public class PickupGesturePreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private static final int ON = 1;
|
||||
private static final int OFF = 0;
|
||||
|
||||
private static final String PREF_KEY_VIDEO = "gesture_pick_up_video";
|
||||
private final String mPickUpPrefKey;
|
||||
|
||||
private final String SECURE_KEY = DOZE_PICK_UP_GESTURE;
|
||||
private static final String AMBIENT_SECURE_KEY = "doze_pick_up_gesture_ambient";
|
||||
|
||||
private AmbientDisplayConfiguration mAmbientConfig;
|
||||
@UserIdInt
|
||||
private final int mUserId;
|
||||
private final boolean mDefault;
|
||||
|
||||
private PrimarySwitchPreference mPreference;
|
||||
private SettingObserver mSettingObserver;
|
||||
|
||||
public PickupGesturePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mUserId = UserHandle.myUserId();
|
||||
mPickUpPrefKey = key;
|
||||
mDefault = context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_dozePickupGestureEnabled);
|
||||
}
|
||||
|
||||
public PickupGesturePreferenceController setConfig(AmbientDisplayConfiguration config) {
|
||||
@@ -67,6 +85,32 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
mSettingObserver = new SettingObserver(mPreference);
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final ContentResolver resolver = mContext.getContentResolver();
|
||||
final boolean enabled =
|
||||
Settings.Secure.getInt(resolver, SECURE_KEY, mDefault ? ON : OFF) == ON;
|
||||
String summary;
|
||||
if (enabled) {
|
||||
summary = mContext.getString(R.string.gesture_setting_on) + " ("
|
||||
+ (Settings.Secure.getInt(resolver, AMBIENT_SECURE_KEY, OFF) == ON
|
||||
? mContext.getString(R.string.gesture_wake_ambient)
|
||||
: mContext.getString(R.string.gesture_wake)) + ")";
|
||||
} else {
|
||||
summary = mContext.getString(R.string.gesture_setting_off);
|
||||
}
|
||||
preference.setSummary(summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return TextUtils.equals(getPreferenceKey(), "gesture_pick_up");
|
||||
@@ -77,21 +121,11 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_KEY_VIDEO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return getAmbientConfig().pickupGestureEnabled(mUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return mPickUpPrefKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
|
||||
@@ -105,4 +139,53 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
|
||||
|
||||
return mAmbientConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return NO_RES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mSettingObserver != null) {
|
||||
mSettingObserver.register(mContext.getContentResolver());
|
||||
mSettingObserver.onChange(false, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mSettingObserver != null) {
|
||||
mSettingObserver.unregister(mContext.getContentResolver());
|
||||
}
|
||||
}
|
||||
|
||||
private class SettingObserver extends ContentObserver {
|
||||
private final Uri mUri = Settings.Secure.getUriFor(SECURE_KEY);
|
||||
private final Uri mAmbientUri = Settings.Secure.getUriFor(AMBIENT_SECURE_KEY);
|
||||
|
||||
private final Preference mPreference;
|
||||
|
||||
SettingObserver(Preference preference) {
|
||||
super(Handler.getMain());
|
||||
mPreference = preference;
|
||||
}
|
||||
|
||||
public void register(ContentResolver cr) {
|
||||
cr.registerContentObserver(mUri, false, this);
|
||||
cr.registerContentObserver(mAmbientUri, false, this);
|
||||
}
|
||||
|
||||
public void unregister(ContentResolver cr) {
|
||||
cr.unregisterContentObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
super.onChange(selfChange, uri);
|
||||
if (uri == null || mUri.equals(uri) || mAmbientUri.equals(uri)) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,13 @@ import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable
|
||||
public class PickupGestureSettings extends DashboardFragment {
|
||||
|
||||
@@ -43,9 +48,18 @@ public class PickupGestureSettings extends DashboardFragment {
|
||||
FeatureFactory.getFeatureFactory().getSuggestionFeatureProvider();
|
||||
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
|
||||
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();
|
||||
}
|
||||
|
||||
use(PickupGesturePreferenceController.class)
|
||||
.setConfig(new AmbientDisplayConfiguration(context));
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context, getSettingsLifecycle());
|
||||
}
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new PickupGestureInsidePreferenceController(context));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
104
src/com/android/settings/gestures/TapPreferenceController.java
Normal file
104
src/com/android/settings/gestures/TapPreferenceController.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Yet Another AOSP 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.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
|
||||
import org.evolution.settings.preferences.SecureSettingSwitchPreference;
|
||||
|
||||
public class TapPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, OnCheckedChangeListener {
|
||||
|
||||
private static final String KEY = "gesture_tap";
|
||||
private static final String AMBIENT_KEY = "doze_tap_gesture_ambient";
|
||||
|
||||
private final Context mContext;
|
||||
private MainSwitchPreference mSwitch;
|
||||
private SecureSettingSwitchPreference mAmbientPref;
|
||||
|
||||
public TapPreferenceController(Context context) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mAmbientPref = screen.findPreference(AMBIENT_KEY);
|
||||
mSwitch = screen.findPreference(getPreferenceKey());
|
||||
mSwitch.setOnPreferenceClickListener(preference -> {
|
||||
final boolean enabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DOZE_TAP_SCREEN_GESTURE, 1) == 1;
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
|
||||
enabled ? 0 : 1);
|
||||
updateAmbientEnablement(!enabled);
|
||||
return true;
|
||||
});
|
||||
mSwitch.addOnSwitchChangeListener(this);
|
||||
updateState(mSwitch);
|
||||
}
|
||||
|
||||
public void setChecked(boolean isChecked) {
|
||||
if (mSwitch != null) {
|
||||
mSwitch.setChecked(isChecked);
|
||||
}
|
||||
updateAmbientEnablement(isChecked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final boolean enabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DOZE_TAP_SCREEN_GESTURE, 1) == 1;
|
||||
setChecked(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.DOZE_TAP_SCREEN_GESTURE, isChecked ? 1 : 0);
|
||||
SystemProperties.set("persist.sys.tap_gesture", isChecked ? "1" : "0");
|
||||
updateAmbientEnablement(isChecked);
|
||||
}
|
||||
|
||||
private void updateAmbientEnablement(boolean enabled) {
|
||||
if (mAmbientPref == null) return;
|
||||
mAmbientPref.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
@@ -19,28 +19,43 @@ package com.android.settings.gestures;
|
||||
import static android.provider.Settings.Secure.DOZE_TAP_SCREEN_GESTURE;
|
||||
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.hardware.display.AmbientDisplayConfiguration;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
public class TapScreenGesturePreferenceController extends GesturePreferenceController {
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
private static final String PREF_KEY_VIDEO = "gesture_tap_screen_video";
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
import com.android.settingslib.PrimarySwitchPreference;
|
||||
|
||||
public class TapScreenGesturePreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private static final String SECURE_KEY = DOZE_TAP_SCREEN_GESTURE;
|
||||
private static final String AMBIENT_SECURE_KEY = "doze_tap_gesture_ambient";
|
||||
|
||||
private AmbientDisplayConfiguration mAmbientConfig;
|
||||
@UserIdInt
|
||||
private final int mUserId;
|
||||
|
||||
private PrimarySwitchPreference mPreference;
|
||||
private SettingObserver mSettingObserver;
|
||||
|
||||
public TapScreenGesturePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mUserId = UserHandle.myUserId();
|
||||
}
|
||||
|
||||
public TapScreenGesturePreferenceController setConfig(AmbientDisplayConfiguration config) {
|
||||
mAmbientConfig = config;
|
||||
return this;
|
||||
mAmbientConfig = new AmbientDisplayConfiguration(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,13 +69,33 @@ public class TapScreenGesturePreferenceController extends GesturePreferenceContr
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPublicSlice() {
|
||||
return true;
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
mSettingObserver = new SettingObserver(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVideoPrefKey() {
|
||||
return PREF_KEY_VIDEO;
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final ContentResolver resolver = mContext.getContentResolver();
|
||||
final boolean enabled =
|
||||
Settings.Secure.getInt(resolver, SECURE_KEY, 1) == 1;
|
||||
String summary;
|
||||
if (enabled) {
|
||||
summary = mContext.getString(R.string.gesture_setting_on) + " ("
|
||||
+ (Settings.Secure.getInt(resolver, AMBIENT_SECURE_KEY, 0) == 1
|
||||
? mContext.getString(R.string.gesture_wake_ambient)
|
||||
: mContext.getString(R.string.gesture_wake)) + ")";
|
||||
} else {
|
||||
summary = mContext.getString(R.string.gesture_setting_off);
|
||||
}
|
||||
preference.setSummary(summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPublicSlice() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,7 +111,7 @@ public class TapScreenGesturePreferenceController extends GesturePreferenceContr
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
boolean success = Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
DOZE_TAP_SCREEN_GESTURE, isChecked ? 1 : 0);
|
||||
SECURE_KEY, isChecked ? 1 : 0);
|
||||
SystemProperties.set("persist.sys.tap_gesture", isChecked ? "1" : "0");
|
||||
return success;
|
||||
}
|
||||
@@ -87,4 +122,53 @@ public class TapScreenGesturePreferenceController extends GesturePreferenceContr
|
||||
}
|
||||
return mAmbientConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return NO_RES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mSettingObserver != null) {
|
||||
mSettingObserver.register(mContext.getContentResolver());
|
||||
mSettingObserver.onChange(false, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mSettingObserver != null) {
|
||||
mSettingObserver.unregister(mContext.getContentResolver());
|
||||
}
|
||||
}
|
||||
|
||||
private class SettingObserver extends ContentObserver {
|
||||
private final Uri mUri = Settings.Secure.getUriFor(SECURE_KEY);
|
||||
private final Uri mAmbientUri = Settings.Secure.getUriFor(AMBIENT_SECURE_KEY);
|
||||
|
||||
private final Preference mPreference;
|
||||
|
||||
SettingObserver(Preference preference) {
|
||||
super(Handler.getMain());
|
||||
mPreference = preference;
|
||||
}
|
||||
|
||||
public void register(ContentResolver cr) {
|
||||
cr.registerContentObserver(mUri, false, this);
|
||||
cr.registerContentObserver(mAmbientUri, false, this);
|
||||
}
|
||||
|
||||
public void unregister(ContentResolver cr) {
|
||||
cr.unregisterContentObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
super.onChange(selfChange, uri);
|
||||
if (uri == null || mUri.equals(uri) || mAmbientUri.equals(uri)) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,13 @@ import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable
|
||||
public class TapScreenGestureSettings extends DashboardFragment {
|
||||
private static final String TAG = "TapScreenGestureSettings";
|
||||
@@ -42,9 +47,18 @@ public class TapScreenGestureSettings extends DashboardFragment {
|
||||
FeatureFactory.getFeatureFactory().getSuggestionFeatureProvider();
|
||||
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
|
||||
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();
|
||||
}
|
||||
|
||||
use(TapScreenGesturePreferenceController.class)
|
||||
.setConfig(new AmbientDisplayConfiguration(context));
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context, getSettingsLifecycle());
|
||||
}
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new TapPreferenceController(context));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user