aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doze/Android.mk20
-rw-r--r--doze/AndroidManifest.xml21
-rw-r--r--doze/proguard.flags5
-rw-r--r--doze/res/drawable/switchbar_background.xml21
-rw-r--r--doze/res/layout/doze.xml28
-rw-r--r--doze/res/layout/switch_bar.xml48
-rw-r--r--doze/res/values/colors.xml23
-rw-r--r--doze/res/values/strings.xml10
-rw-r--r--doze/res/values/styles.xml34
-rw-r--r--doze/res/xml/doze_settings.xml18
-rw-r--r--doze/src/com/cyanogenmod/settings/doze/DozeReceiver.java54
-rw-r--r--doze/src/com/cyanogenmod/settings/doze/DozeSettings.java122
-rw-r--r--doze/src/com/cyanogenmod/settings/doze/DozeSettingsFragment.java197
-rw-r--r--doze/src/com/cyanogenmod/settings/doze/Utils.java16
14 files changed, 477 insertions, 140 deletions
diff --git a/doze/Android.mk b/doze/Android.mk
index de136ea..f94a662 100644
--- a/doze/Android.mk
+++ b/doze/Android.mk
@@ -8,9 +8,29 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := ZukDoze
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
+LOCAL_STATIC_JAVA_LIBRARIES := \
+ android-support-v4 \
+ android-support-v13 \
+ android-support-v7-recyclerview \
+ android-support-v7-preference \
+ android-support-v7-appcompat \
+ android-support-v14-preference \
+ org.cyanogenmod.platform.internal
+
+LOCAL_RESOURCE_DIR := \
+ $(LOCAL_PATH)/res \
+ frameworks/support/v7/preference/res \
+ frameworks/support/v14/preference/res \
+ frameworks/support/v7/appcompat/res \
+ frameworks/support/v7/recyclerview/res
+
+LOCAL_AAPT_FLAGS := --auto-add-overlay \
+ --extra-packages android.support.v7.preference:android.support.v14.preference:android.support.v17.preference:android.support.v7.appcompat:android.support.v7.recyclerview
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+include frameworks/base/packages/SettingsLib/common.mk
+
include $(BUILD_PACKAGE)
include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/doze/AndroidManifest.xml b/doze/AndroidManifest.xml
index 54783eb..1fcb05e 100644
--- a/doze/AndroidManifest.xml
+++ b/doze/AndroidManifest.xml
@@ -7,18 +7,20 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
+ <uses-permission android:name="cyanogenmod.permission.MANAGE_REMOTE_PREFERENCES" />
<uses-sdk
- android:minSdkVersion="21"
- android:targetSdkVersion="21"/>
+ android:minSdkVersion="24"
+ android:targetSdkVersion="24"/>
<application
android:label="ZukDoze"
android:persistent="true">
- <receiver android:name="com.cyanogenmod.settings.doze.BootCompletedReceiver">
+ <receiver android:name="com.cyanogenmod.settings.doze.DozeReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
+ <action android:name="cyanogenmod.intent.action.UPDATE_PREFERENCE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
@@ -30,16 +32,17 @@
<activity
android:name=".DozeSettings"
android:label="@string/ambient_display_title"
- android:theme="@android:style/Theme.Material.Settings">
+ android:theme="@style/DozeSettings">
<intent-filter>
- <action android:name="com.android.settings.action.EXTRA_SETTINGS" />
+ <action android:name="org.cyanogenmod.settings.device.DOZE_SETTINGS" />
+ <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
- android:name="com.android.settings.category"
- android:value="com.android.settings.category.device" />
+ android:name="org.cyanogenmod.settings.summary.receiver"
+ android:value="com.cyanogenmod.settings.doze.DozeReceiver" />
<meta-data
- android:name="com.android.settings.icon"
- android:resource="@drawable/ic_settings_doze" />
+ android:name="org.cyanogenmod.settings.summary.key"
+ android:value="doze_device_settings" />
</activity>
</application>
diff --git a/doze/proguard.flags b/doze/proguard.flags
index a21e62f..7f3d4c7 100644
--- a/doze/proguard.flags
+++ b/doze/proguard.flags
@@ -1,3 +1,8 @@
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keep class ** extends android.support.v14.preference.PreferenceFragment
-keep class com.cyanogenmod.settings.doze.* {
*;
}
diff --git a/doze/res/drawable/switchbar_background.xml b/doze/res/drawable/switchbar_background.xml
new file mode 100644
index 0000000..45f1578
--- /dev/null
+++ b/doze/res/drawable/switchbar_background.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 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.
+-->
+
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="?android:attr/colorControlHighlight">
+ <item android:drawable="@color/switch_bar_background" />
+</ripple>
+
diff --git a/doze/res/layout/doze.xml b/doze/res/layout/doze.xml
new file mode 100644
index 0000000..941cdf6
--- /dev/null
+++ b/doze/res/layout/doze.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2014, 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.
+*/
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent">
+
+ <include layout="@layout/switch_bar" />
+
+</LinearLayout>
+
diff --git a/doze/res/layout/switch_bar.xml b/doze/res/layout/switch_bar.xml
new file mode 100644
index 0000000..f98de96
--- /dev/null
+++ b/doze/res/layout/switch_bar.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/switch_bar"
+ android:layout_width="match_parent"
+ android:layout_height="?android:attr/actionBarSize"
+ android:background="@drawable/switchbar_background"
+ android:paddingStart="16dp"
+ android:paddingEnd="16dp"
+ android:clickable="true"
+ android:gravity="center">
+
+ <TextView android:id="@+id/switch_text"
+ android:layout_height="wrap_content"
+ android:layout_width="0dp"
+ android:layout_weight="1"
+ android:layout_gravity="center_vertical"
+ android:paddingStart="48dp"
+ android:maxLines="2"
+ android:ellipsize="end"
+ android:textAppearance="@android:style/TextAppearance.Material.Title"
+ android:textColor="?android:attr/textColorPrimaryInverse"
+ android:textAlignment="viewStart"
+ android:text="@string/switch_bar_on" />
+
+ <Switch
+ android:id="@android:id/switch_widget"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:background="@null"
+ android:theme="@style/ThemeOverlay.SwitchBar" />
+
+</LinearLayout>
diff --git a/doze/res/values/colors.xml b/doze/res/values/colors.xml
new file mode 100644
index 0000000..d598598
--- /dev/null
+++ b/doze/res/values/colors.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright 2010, 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.
+ */
+-->
+<resources>
+ <color name="switch_bar_background">#ff37474f</color>
+ <color name="switch_accent_color">#ff7fcac3</color>
+ <color name="system_secondary_color">#ff37474F</color>
+</resources>
diff --git a/doze/res/values/strings.xml b/doze/res/values/strings.xml
index 63146cb..fed5b05 100644
--- a/doze/res/values/strings.xml
+++ b/doze/res/values/strings.xml
@@ -13,8 +13,16 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Label for feature switch [CHAR LIMIT=30] -->
+ <string name="switch_bar_on">On</string>
+
+ <!-- Label for feature switch [CHAR LIMIT=30] -->
+ <string name="switch_bar_off">Off</string>
+
<string name="ambient_display_title">Ambient display</string>
<string name="ambient_display_summary">Wake screen when you receive notifications</string>
+ <string name="ambient_display_summary_on">Screen will wake when you receive notifications</string>
+ <string name="ambient_display_summary_off">Screen will not wake when you receive notifications</string>
<!-- Tilt sensor -->
<string name="tilt_sensor_title">Tilt sensor</string>
@@ -31,5 +39,5 @@
<!-- Help text -->
<string name="dlg_ok">OK</string>
<string name="doze_settings_help_title">Help</string>
- <string name="doze_settings_help_text">These features use sensor events to launch a doze notification pulse. The chosen sensor is only enabled when the device receives a notification, this helps to reduce battery usage. There is also an option to enable the chosen sensor as soon as the screen turns off, this will cause higher battery usage.</string>
+ <string name="doze_settings_help_text">These features use sensor events to launch a doze notification pulse, this will cause higher battery usage.</string>
</resources>
diff --git a/doze/res/values/styles.xml b/doze/res/values/styles.xml
new file mode 100644
index 0000000..78d2d59
--- /dev/null
+++ b/doze/res/values/styles.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <style name="DozeSettings" parent="@android:style/Theme.Material.Settings">
+ <item name="android:windowActionBar">false</item>
+ <item name="preferenceTheme">@style/DozePreferenceTheme</item>
+ </style>
+
+ <style name="DozePreferenceTheme" parent="@android:style/Theme.Material.Settings">
+ <item name="dropdownPreferenceStyle">@style/Preference.DropDown.Material</item>
+ </style>
+
+ <style name="ThemeOverlay.SwitchBar" parent="@android:style/ThemeOverlay">
+ <item name="android:colorAccent">@color/switch_accent_color</item>
+ </style>
+
+ <style name="ThemeOverlay.SwitchBar.Secondary" parent="@android:style/ThemeOverlay">
+ <item name="android:colorAccent">@color/system_secondary_color</item>
+ </style>
+
+</resources>
diff --git a/doze/res/xml/doze_settings.xml b/doze/res/xml/doze_settings.xml
index dfa608b..acc19d2 100644
--- a/doze/res/xml/doze_settings.xml
+++ b/doze/res/xml/doze_settings.xml
@@ -14,13 +14,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
-
- <SwitchPreference
- android:key="ambient_display"
- android:defaultValue="true"
- android:title="@string/ambient_display_title"
- android:summary="@string/ambient_display_summary" />
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:cm="http://schemas.android.com/apk/res/cyanogenmod.platform">
<PreferenceCategory
android:key="tilt_sensor"
@@ -30,8 +25,7 @@
android:key="pick_up"
android:defaultValue="false"
android:title="@string/pick_up_title"
- android:summary="@string/pick_up_summary"
- android:dependency="ambient_display" />
+ android:summary="@string/pick_up_summary" />
</PreferenceCategory>
@@ -43,15 +37,13 @@
android:key="gesture_hand_wave"
android:defaultValue="false"
android:title="@string/hand_wave_gesture_title"
- android:summary="@string/hand_wave_gesture_summary"
- android:dependency="ambient_display" />
+ 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"
- android:dependency="ambient_display" />
+ android:summary="@string/pocket_gesture_summary" />
</PreferenceCategory>
diff --git a/doze/src/com/cyanogenmod/settings/doze/DozeReceiver.java b/doze/src/com/cyanogenmod/settings/doze/DozeReceiver.java
new file mode 100644
index 0000000..6ab3e0d
--- /dev/null
+++ b/doze/src/com/cyanogenmod/settings/doze/DozeReceiver.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.cyanogenmod.settings.doze;
+
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+import cyanogenmod.preference.RemotePreferenceUpdater;
+
+public class DozeReceiver extends RemotePreferenceUpdater {
+
+ private static final boolean DEBUG = false;
+ private static final String TAG = "OneplusDoze";
+
+ private static final String DOZE_CATEGORY_KEY = "doze_device_settings";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ super.onReceive(context, intent);
+
+ if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
+ if (Utils.isDozeEnabled(context) && Utils.sensorsEnabled(context)) {
+ if (DEBUG) Log.d(TAG, "Starting service");
+ Utils.startService(context);
+ }
+ }
+ }
+
+ @Override
+ public String getSummary(Context context, String key) {
+ if (DOZE_CATEGORY_KEY.equals(key)) {
+ return DozeSettingsFragment.getDozeSummary(context);
+ }
+ return null;
+ }
+
+ static void notifyChanged(Context context) {
+ notifyChanged(context, DOZE_CATEGORY_KEY);
+ }
+}
diff --git a/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java b/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java
index 2e179bc..76ac5fe 100644
--- a/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java
+++ b/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 The CyanogenMod Project
+ * Copyright (C) 2016 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.
@@ -13,75 +13,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.cyanogenmod.settings.doze;
-import android.app.ActionBar;
import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.DialogFragment;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.SharedPreferences;
import android.os.Bundle;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
-import android.preference.PreferenceActivity;
-import android.preference.PreferenceScreen;
-import android.preference.SwitchPreference;
-import android.provider.Settings;
-import android.view.Menu;
import android.view.MenuItem;
-public class DozeSettings extends PreferenceActivity implements OnPreferenceChangeListener {
+import com.android.settingslib.drawer.SettingsDrawerActivity;
+
+/**
+ * Created by shade on 10/14/16.
+ */
- private Context mContext;
- private SharedPreferences mPreferences;
+public class DozeSettings extends SettingsDrawerActivity {
- private SwitchPreference mAmbientDisplayPreference;
- private SwitchPreference mPickUpPreference;
- private SwitchPreference mHandwavePreference;
- private SwitchPreference mPocketPreference;
+ private static final String TAG_DOZE = "doze";
@Override
- public void onCreate(Bundle savedInstanceState) {
+ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.doze_settings);
- mContext = getApplicationContext();
- boolean dozeEnabled = Utils.isDozeEnabled(mContext);
-
- // get shared preference
- mPreferences = mContext.getSharedPreferences("doze_settings", Activity.MODE_PRIVATE);
- if (savedInstanceState == null && !mPreferences.getBoolean("first_help_shown", false)) {
- showHelp();
- }
-
- mAmbientDisplayPreference =
- (SwitchPreference) findPreference(Utils.AMBIENT_DISPLAY_KEY);
- // Read from DOZE_ENABLED secure setting
- mAmbientDisplayPreference.setChecked(dozeEnabled);
- mAmbientDisplayPreference.setOnPreferenceChangeListener(this);
-
- mPickUpPreference =
- (SwitchPreference) findPreference(Utils.PICK_UP_KEY);
- mPickUpPreference.setOnPreferenceChangeListener(this);
- mHandwavePreference =
- (SwitchPreference) findPreference(Utils.GESTURE_HAND_WAVE_KEY);
- mHandwavePreference.setOnPreferenceChangeListener(this);
+ setContentView(R.layout.doze);
- mPocketPreference =
- (SwitchPreference) findPreference(Utils.GESTURE_POCKET_KEY);
- mPocketPreference.setOnPreferenceChangeListener(this);
-
- final ActionBar actionBar = getActionBar();
- actionBar.setDisplayHomeAsUpEnabled(true);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
+ getFragmentManager().beginTransaction().replace(R.id.content_frame,
+ new DozeSettingsFragment(), TAG_DOZE).commit();
}
@Override
@@ -92,57 +47,4 @@ public class DozeSettings extends PreferenceActivity implements OnPreferenceChan
}
return false;
}
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final String key = preference.getKey();
- final boolean value = (Boolean) newValue;
- if (Utils.AMBIENT_DISPLAY_KEY.equals(key)) {
- mAmbientDisplayPreference.setChecked(value);
- Utils.enableDoze(value, mContext);
- return true;
- } else if (Utils.PICK_UP_KEY.equals(key)) {
- mPickUpPreference.setChecked(value);
- Utils.startService(mContext);
- return true;
- } else if (Utils.GESTURE_HAND_WAVE_KEY.equals(key)) {
- mHandwavePreference.setChecked(value);
- Utils.startService(mContext);
- return true;
- } else if (Utils.GESTURE_POCKET_KEY.equals(key)) {
- mPocketPreference.setChecked(value);
- Utils.startService(mContext);
- return true;
- }
- return false;
- }
-
- public static class HelpDialogFragment extends DialogFragment {
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- return new AlertDialog.Builder(getActivity())
- .setTitle(R.string.doze_settings_help_title)
- .setMessage(R.string.doze_settings_help_text)
- .setNegativeButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- }
- })
- .create();
- }
-
- @Override
- public void onCancel(DialogInterface dialog) {
- getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE)
- .edit()
- .putBoolean("first_help_shown", true)
- .commit();
- }
- }
-
- private void showHelp() {
- HelpDialogFragment fragment = new HelpDialogFragment();
- fragment.show(getFragmentManager(), "help_dialog");
- }
}
diff --git a/doze/src/com/cyanogenmod/settings/doze/DozeSettingsFragment.java b/doze/src/com/cyanogenmod/settings/doze/DozeSettingsFragment.java
new file mode 100644
index 0000000..ec1c9d8
--- /dev/null
+++ b/doze/src/com/cyanogenmod/settings/doze/DozeSettingsFragment.java
@@ -0,0 +1,197 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.cyanogenmod.settings.doze;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.SharedPreferences;
+import android.database.ContentObserver;
+import android.os.Bundle;
+import android.os.Handler;
+import android.support.v14.preference.PreferenceFragment;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.Preference.OnPreferenceChangeListener;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.CompoundButton;
+import android.widget.Switch;
+
+public class DozeSettingsFragment extends PreferenceFragment implements OnPreferenceChangeListener,
+ CompoundButton.OnCheckedChangeListener {
+
+ private SharedPreferences mPreferences;
+
+ private Switch mSwitch;
+
+ private SwitchPreference mPickUpPreference;
+ private SwitchPreference mHandwavePreference;
+ private SwitchPreference mPocketPreference;
+
+ private ContentObserver mDozeObserver = new ContentObserver(new Handler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+
+ boolean enabled = Utils.isDozeEnabled(getActivity());
+
+ updateSwitches(Utils.isDozeEnabled(getActivity()));
+ DozeReceiver.notifyChanged(getActivity());
+ }
+ };
+
+ static String getDozeSummary(Context context) {
+ if (Utils.isDozeEnabled(context)) {
+ return context.getString(R.string.ambient_display_summary_on);
+ }
+ return context.getString(R.string.ambient_display_summary_off);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ final View view = LayoutInflater.from(getContext()).inflate(R.layout.doze, container, false);
+ ((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState));
+ return view;
+ }
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ addPreferencesFromResource(R.xml.doze_settings);
+
+ // get shared preference
+ mPreferences = getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE);
+
+ if (savedInstanceState == null && !mPreferences.getBoolean("first_help_shown", false)) {
+ showHelp();
+ }
+
+ mPickUpPreference =
+ (SwitchPreference) findPreference(Utils.PICK_UP_KEY);
+ mPickUpPreference.setOnPreferenceChangeListener(this);
+
+ mHandwavePreference =
+ (SwitchPreference) findPreference(Utils.GESTURE_HAND_WAVE_KEY);
+ mHandwavePreference.setOnPreferenceChangeListener(this);
+
+ mPocketPreference =
+ (SwitchPreference) findPreference(Utils.GESTURE_POCKET_KEY);
+ mPocketPreference.setOnPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ getActivity().getContentResolver().registerContentObserver(
+ Utils.DOZE_ENABLED_URI, false, mDozeObserver);
+ updateSwitches(Utils.isDozeEnabled(getActivity()));
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ getActivity().getContentResolver().unregisterContentObserver(mDozeObserver);
+ }
+
+ private void updateSwitches(boolean enabled) {
+ mPickUpPreference.setEnabled(enabled);
+ mHandwavePreference.setEnabled(enabled);
+ mPocketPreference.setEnabled(enabled);
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+
+ View switchBar = view.findViewById(R.id.switch_bar);
+ mSwitch = (Switch) switchBar.findViewById(android.R.id.switch_widget);
+ mSwitch.setChecked(Utils.isDozeEnabled(getActivity()));
+ mSwitch.setOnCheckedChangeListener(this);
+
+ switchBar.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mSwitch.setChecked(!mSwitch.isChecked());
+ }
+ });
+ }
+
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final String key = preference.getKey();
+ final boolean value = (Boolean) newValue;
+ if (Utils.PICK_UP_KEY.equals(key)) {
+ mPickUpPreference.setChecked(value);
+ } else if (Utils.GESTURE_HAND_WAVE_KEY.equals(key)) {
+ mHandwavePreference.setChecked(value);
+ } else if (Utils.GESTURE_POCKET_KEY.equals(key)) {
+ mPocketPreference.setChecked(value);
+ } else {
+ return false;
+ }
+
+ Utils.startService(getActivity());
+ return true;
+ }
+
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+ Utils.enableDoze(b, getActivity());
+ }
+
+ public static class HelpDialogFragment extends DialogFragment {
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ return new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.doze_settings_help_title)
+ .setMessage(R.string.doze_settings_help_text)
+ .setNegativeButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ })
+ .create();
+ }
+
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE)
+ .edit()
+ .putBoolean("first_help_shown", true)
+ .commit();
+ }
+ }
+
+ private void showHelp() {
+ HelpDialogFragment fragment = new HelpDialogFragment();
+ fragment.show(getFragmentManager(), "help_dialog");
+ }
+}
diff --git a/doze/src/com/cyanogenmod/settings/doze/Utils.java b/doze/src/com/cyanogenmod/settings/doze/Utils.java
index 767cd96..9dc2703 100644
--- a/doze/src/com/cyanogenmod/settings/doze/Utils.java
+++ b/doze/src/com/cyanogenmod/settings/doze/Utils.java
@@ -16,16 +16,16 @@
package com.cyanogenmod.settings.doze;
-import android.app.ActivityManager;
-import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
+import android.net.Uri;
import android.os.UserHandle;
-import android.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;
+import static android.provider.Settings.Secure.DOZE_ENABLED;
+
public final class Utils {
private static final String TAG = "DozeUtils";
@@ -33,11 +33,13 @@ public final class Utils {
private static final String DOZE_INTENT = "com.android.systemui.doze.pulse";
- protected static final String AMBIENT_DISPLAY_KEY = "ambient_display";
+ protected static final String AMBIENT_DISPLAY_KEY = "doze_enabled";
protected static final String PICK_UP_KEY = "pick_up";
protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
+ public static final Uri DOZE_ENABLED_URI = Settings.Secure.getUriFor(DOZE_ENABLED);
+
protected static void startService(Context context) {
if (DEBUG) Log.d(TAG, "Starting service");
context.startService(new Intent(context, DozeService.class));
@@ -50,12 +52,12 @@ public final class Utils {
protected static boolean isDozeEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(),
- Settings.Secure.DOZE_ENABLED, 1) != 0;
+ DOZE_ENABLED, 1) != 0;
}
protected static boolean enableDoze(boolean enable, Context context) {
boolean dozeEnabled = Settings.Secure.putInt(context.getContentResolver(),
- Settings.Secure.DOZE_ENABLED, enable ? 1 : 0);
+ DOZE_ENABLED, enable ? 1 : 0);
if (enable) {
startService(context);
} else {