From fcd3f34dc62572cb8dff8ae6e2578b5eb86aac6e Mon Sep 17 00:00:00 2001 From: "Christopher R. Palmer" Date: Sat, 23 May 2015 11:42:49 -0700 Subject: [PATCH] samsung: doze: Consolidate doze settings * 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 | 5 ++ doze/res/xml/gesture_panel.xml | 36 +++++++++----- .../device/TouchscreenGestureSettings.java | 47 +++++++++++++++++++ 3 files changed, 77 insertions(+), 11 deletions(-) diff --git a/doze/res/values/strings.xml b/doze/res/values/strings.xml index 2b54bfb..273a211 100644 --- a/doze/res/values/strings.xml +++ b/doze/res/values/strings.xml @@ -17,6 +17,11 @@ Gestures Use gestures to perform actions + Ambient display + + Ambient display + Wake screen when you receive notifications + Hand wave Pulse notifications on hand wave diff --git a/doze/res/xml/gesture_panel.xml b/doze/res/xml/gesture_panel.xml index 61d639b..ba48f9d 100644 --- a/doze/res/xml/gesture_panel.xml +++ b/doze/res/xml/gesture_panel.xml @@ -1,10 +1,13 @@ - + + + + + - + + - + \ No newline at end of file diff --git a/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java b/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java index bb40546..e685c7e 100644 --- a/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java +++ b/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java @@ -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; + } + }; } -- 2.20.1