samsung: doze: Clean up ambient display pref dependencies
authorZhao Wei Liew <zhaoweiliew@gmail.com>
Thu, 13 Oct 2016 10:33:52 +0000 (18:33 +0800)
committerJan Altensen <info@stricted.net>
Fri, 20 Mar 2020 13:56:38 +0000 (14:56 +0100)
 * Use SecureSettingSwitchPreference for Ambient Display
 * Use the XML preference dependency attribute

Change-Id: I3480af71e334110aed834a53f49b33a853f16316

doze/res/xml/gesture_panel.xml
doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java

index f9113785387ae986959b2236a360f36c24617056..47ff26e392fec2af0960bc1ac983ab34db45b518 100644 (file)
@@ -20,8 +20,8 @@
         android:key="ambient_display_key"
         android:title="@string/ambient_display_title">
 
-        <SwitchPreference
-            android:key="ambient_display_enable"
+        <cyanogenmod.preference.SecureSettingSwitchPreference
+            android:key="doze_enabled"
             android:defaultValue="true"
             android:title="@string/ambient_display_enable_title"
             android:summary="@string/ambient_display_enable_summary" />
             android:key="gesture_hand_wave"
             android:defaultValue="false"
             android:title="@string/hand_wave_gesture_title"
-            android:summary="@string/hand_wave_gesture_summary" />
+            android:summary="@string/hand_wave_gesture_summary"
+            android:dependency="doze_enabled" />
 
         <SwitchPreference
             android:key="gesture_pocket"
             android:defaultValue="false"
             android:title="@string/pocket_gesture_title"
-            android:summary="@string/pocket_gesture_summary" />
+            android:summary="@string/pocket_gesture_summary"
+            android:dependency="doze_enabled" />
     </PreferenceCategory>
 
     <PreferenceCategory
index c9ffce0ae2712f2cac40b5ed8082c4ba2abf03e0..9256afe43825cdc909630ddce3ea192be3a3d784 100644 (file)
@@ -26,32 +26,19 @@ import org.cyanogenmod.internal.util.ScreenType;
 
 public class TouchscreenGestureSettings extends PreferenceFragment {
 
-    private static final String KEY_AMBIENT_DISPLAY_ENABLE = "ambient_display_enable";
     private static final String KEY_HAND_WAVE = "gesture_hand_wave";
-    private static final String KEY_GESTURE_POCKET = "gesture_pocket";
     private static final String KEY_PROXIMITY_WAKE = "proximity_wake_enable";
 
-    private SwitchPreference mAmbientDisplayPreference;
     private SwitchPreference mHandwavePreference;
-    private SwitchPreference mPocketPreference;
     private SwitchPreference mProximityWakePreference;
 
     @Override
     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
         addPreferencesFromResource(R.xml.gesture_panel);
-        boolean dozeEnabled = isDozeEnabled();
-        mAmbientDisplayPreference =
-            (SwitchPreference) findPreference(KEY_AMBIENT_DISPLAY_ENABLE);
-        // Read from DOZE_ENABLED secure setting
-        mAmbientDisplayPreference.setChecked(dozeEnabled);
-        mAmbientDisplayPreference.setOnPreferenceChangeListener(mAmbientDisplayPrefListener);
+
         mHandwavePreference =
             (SwitchPreference) findPreference(KEY_HAND_WAVE);
-        mHandwavePreference.setEnabled(dozeEnabled);
         mHandwavePreference.setOnPreferenceChangeListener(mProximityListener);
-        mPocketPreference =
-            (SwitchPreference) findPreference(KEY_GESTURE_POCKET);
-        mPocketPreference.setEnabled(dozeEnabled);
         mProximityWakePreference =
             (SwitchPreference) findPreference(KEY_PROXIMITY_WAKE);
         mProximityWakePreference.setOnPreferenceChangeListener(mProximityListener);
@@ -67,30 +54,6 @@ public class TouchscreenGestureSettings extends PreferenceFragment {
         }
     }
 
-    private boolean enableDoze(boolean enable) {
-        return Settings.Secure.putInt(getContext().getContentResolver(),
-                Settings.Secure.DOZE_ENABLED, enable ? 1 : 0);
-    }
-
-    private boolean isDozeEnabled() {
-        return Settings.Secure.getInt(getContext().getContentResolver(),
-                Settings.Secure.DOZE_ENABLED, 1) != 0;
-    }
-
-    private Preference.OnPreferenceChangeListener mAmbientDisplayPrefListener =
-        new Preference.OnPreferenceChangeListener() {
-        @Override
-        public boolean onPreferenceChange(Preference preference, Object newValue) {
-            boolean enable = (boolean) newValue;
-            boolean ret = enableDoze(enable);
-            if (ret) {
-                mHandwavePreference.setEnabled(enable);
-                mPocketPreference.setEnabled(enable);
-            }
-            return ret;
-        }
-    };
-
     private Preference.OnPreferenceChangeListener mProximityListener =
         new Preference.OnPreferenceChangeListener() {
         @Override