samsung: doze: Consolidate doze settings
authorChristopher R. Palmer <crpalmer@gmail.com>
Sat, 23 May 2015 18:42:49 +0000 (11:42 -0700)
committerJan Altensen <info@stricted.net>
Fri, 20 Mar 2020 13:56:29 +0000 (14:56 +0100)
* Allow user to disable ambient display from gesture panel
* Disable/enable doze settings based on ambient display state

Change-Id: I0ff7686ccc04037b3ada9a8355384ba6746cf30c

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

index 2b54bfbc6f7f3faaa185265cb0ea771fe377769c..273a2116a1458ba62197d1ba8424538773c7f90e 100644 (file)
     <string name="screen_gestures_panel_title">Gestures</string>
     <string name="screen_gestures_panel_summary">Use gestures to perform actions</string>
 
+    <string name="ambient_display_title">Ambient display</string>
+
+    <string name="ambient_display_enable_title">Ambient display</string>
+    <string name="ambient_display_enable_summary">Wake screen when you receive notifications</string>
+
     <string name="hand_wave_gesture_title">Hand wave</string>
     <string name="hand_wave_gesture_summary">Pulse notifications on hand wave</string>
 
index 61d639bf4855ba371e58ab46ea5c729d892e26b3..ba48f9d4a20c77f5efc420bb2986098c086aee5e 100644 (file)
@@ -1,10 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
      Copyright (C) 2015 The CyanogenMod 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.
 -->
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
 
-    <SwitchPreference
-        android:key="gesture_hand_wave"
-        android:defaultValue="false"
-        android:title="@string/hand_wave_gesture_title"
-        android:summary="@string/hand_wave_gesture_summary" />
+    <PreferenceCategory
+        android:key="ambient_display_key"
+        android:title="@string/ambient_display_title" >
+
+        <SwitchPreference
+            android:key="ambient_display_enable"
+            android:defaultValue="true"
+            android:title="@string/ambient_display_enable_title"
+            android:summary="@string/ambient_display_enable_summary" />
+
+        <SwitchPreference
+            android:key="gesture_hand_wave"
+            android:defaultValue="false"
+            android:title="@string/hand_wave_gesture_title"
+            android:summary="@string/hand_wave_gesture_summary" />
 
-    <SwitchPreference
-        android:key="gesture_pocket"
-        android:defaultValue="false"
-        android:title="@string/pocket_gesture_title"
-        android:summary="@string/pocket_gesture_summary" />
+        <SwitchPreference
+            android:key="gesture_pocket"
+            android:defaultValue="false"
+            android:title="@string/pocket_gesture_title"
+            android:summary="@string/pocket_gesture_summary" />
+    </PreferenceCategory>
 
-</PreferenceScreen>
+</PreferenceScreen>
\ No newline at end of file
index bb4054660431614a1b5058b7f4f65351ca1b87c1..e685c7e98dc6fe8a1456b53c3b44a716a4b01f1c 100644 (file)
@@ -19,14 +19,37 @@ package com.cyanogenmod.settings.device;
 import com.android.internal.util.cm.ScreenType;
 
 import android.os.Bundle;
+import android.preference.Preference;
 import android.preference.PreferenceActivity;
+import android.preference.SwitchPreference;
+import android.provider.Settings;
 
 public class TouchscreenGestureSettings extends PreferenceActivity {
 
+    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 SwitchPreference mAmbientDisplayPreference;
+    private SwitchPreference mHandwavePreference;
+    private SwitchPreference mPocketPreference;
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         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);
+        mPocketPreference =
+            (SwitchPreference) findPreference(KEY_GESTURE_POCKET);
+        mPocketPreference.setEnabled(dozeEnabled);
     }
 
     @Override
@@ -38,4 +61,28 @@ public class TouchscreenGestureSettings extends PreferenceActivity {
             getListView().setPadding(0, 0, 0, 0);
         }
     }
+
+    private boolean enableDoze(boolean enable) {
+        return Settings.Secure.putInt(getContentResolver(),
+                Settings.Secure.DOZE_ENABLED, enable ? 1 : 0);
+    }
+
+    private boolean isDozeEnabled() {
+        return Settings.Secure.getInt(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;
+        }
+    };
 }