diff options
author | Fedor917 <cryscript@gmail.com> | 2016-11-10 15:53:00 +0700 |
---|---|---|
committer | Fedor917 <cryscript@gmail.com> | 2016-11-10 15:53:00 +0700 |
commit | f7102b858dc849cc94255bc96f95b880dfd93452 (patch) | |
tree | 3e6164b0b02bb62f7093ddc44bbbaebaf44aacf8 /doze | |
parent | cc834f0c4bb0ce51baddc42d11935438bf63394a (diff) |
Initialising brunch based on davidevinavil device tree (CM14.0 branch)
Diffstat (limited to 'doze')
21 files changed, 485 insertions, 227 deletions
diff --git a/doze/Android.mk b/doze/Android.mk index de136ea..9c397b5 100644 --- a/doze/Android.mk +++ b/doze/Android.mk @@ -5,12 +5,32 @@ LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-java-files-under, src) -LOCAL_PACKAGE_NAME := ZukDoze +LOCAL_PACKAGE_NAME := CmDoze 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..d44a1b2 100644 --- a/doze/AndroidManifest.xml +++ b/doze/AndroidManifest.xml @@ -7,39 +7,42 @@ <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:label="CmDoze" 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> <service android:name="com.cyanogenmod.settings.doze.DozeService" - android:permission="ZukDozeService"> + android:permission="OneplusDozeService"> </service> <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-gl-rES/strings.xml b/doze/res/values-gl-rES/strings.xml index 809934c..c023c08 100644 --- a/doze/res/values-gl-rES/strings.xml +++ b/doze/res/values-gl-rES/strings.xml @@ -13,22 +13,7 @@ limitations under the License. --> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> - <string name="ambient_display_title">Visualización ambiente</string> - <string name="ambient_display_summary">Activar a pantalla ao recibir notificacións</string> - <string name="always_enabled_title">Sempre activo</string> - <string name="always_enabled_summary">Atender ao eventos do sensor así que se apague a pantalla</string> <!-- Tilt sensor --> - <string name="tilt_sensor_title">Sensor de inclinación</string> - <string name="pick_up_title">Coller</string> - <string name="pick_up_summary">Amosar notificacións ao coller o dispositivo</string> <!-- Proximity sensor --> - <string name="priximity_sensor_title">Sensor de proximidade</string> - <string name="hand_wave_gesture_title">Pasar a man</string> - <string name="hand_wave_gesture_summary">Amosar notificacións ao pasar a man</string> - <string name="pocket_gesture_title">Peto</string> - <string name="pocket_gesture_summary">Amosar notificacións ao sacar do peto</string> <!-- Help text --> - <string name="dlg_ok">ACEPTAR</string> - <string name="doze_settings_help_title">Axuda</string> - <string name="doze_settings_help_text">Estas características usan eventos do sensor para amosar unha notificación latente. O sensor seleccionado habilitarase só cando reciba unha notificación axudando a reducir o consumo da batería. Tamén existe unha opción para activar o sensor así que se apague a pantalla, pero isto causará un maior uso da batería.</string> </resources> diff --git a/doze/res/values-iw/strings.xml b/doze/res/values-iw/strings.xml index b3ba98f..caff68b 100644 --- a/doze/res/values-iw/strings.xml +++ b/doze/res/values-iw/strings.xml @@ -27,5 +27,4 @@ <!-- Help text --> <string name="dlg_ok">אישור</string> <string name="doze_settings_help_title">עזרה</string> - <string name="doze_settings_help_text">התכונות נעזרות בחיישני אירועים כדי להפעיל הדגשת התראות עם Doze. החיישן הנבחר מופעל רק כאשר המכשיר מקבל התראה, מה שעוזר להקטין את השימוש בסוללה. בנוסף, יש אפשרות להפעיל את החיישן הנבחר ברגע שהמסך נכבה, מה שעלול לגרום לשימוש רב יותר בסוללה.</string> </resources> diff --git a/doze/res/values-nl/strings.xml b/doze/res/values-nl/strings.xml index b803eeb..a9db278 100644 --- a/doze/res/values-nl/strings.xml +++ b/doze/res/values-nl/strings.xml @@ -30,5 +30,5 @@ <!-- Help text --> <string name="dlg_ok">OK</string> <string name="doze_settings_help_title">Help</string> - <string name="doze_settings_help_text">Deze functies gebruiken sensoren om een Doze-puls te versturen. De gekozen sensor is alleen ingeschakeld als het apparaat een melding ontvangt. Dit helpt het accugebruik te verminderen. Er is ook een optie om de sensor te activeren zodra het scherm uitschakelt, maar dit leidt tot hoger accugebruik.</string> + <string name="doze_settings_help_text">Deze functies gebruiken sensoren om een Doze-puls te versturen. De gekozen sensor is alleen ingeschakeld als het apparaat een melding ontvangt. Dit helpt het batterijgebruik te verminderen. Er is ook een optie om de sensor te activeren zodra het scherm uitschakelt, maar dit leidt tot hoger batterijgebruik.</string> </resources> diff --git a/doze/res/values-pl/strings.xml b/doze/res/values-pl/strings.xml index ec0b8c6..aa010bf 100644 --- a/doze/res/values-pl/strings.xml +++ b/doze/res/values-pl/strings.xml @@ -15,7 +15,6 @@ <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <string name="ambient_display_title">Aktywny wyświetlacz</string> <string name="ambient_display_summary">Wybudź ekran po odebraniu powiadomienia</string> - <string name="always_enabled_title">Zawsze włączone</string> <string name="always_enabled_summary">Nasłuchiwanie zdarzeń z czujników zaraz po wyłączeniu ekranu</string> <!-- Tilt sensor --> <string name="tilt_sensor_title">Czujnik pochylenia</string> @@ -29,5 +28,4 @@ <!-- Help text --> <string name="dlg_ok">OK</string> <string name="doze_settings_help_title">Pomoc</string> - <string name="doze_settings_help_text">Te funkcje używają czujników, aby pokazywać powiadomienia tylko w odpowiednim momencie. Czujniki są wykorzystywane, kiedy telefon odbierze powiadomienie. Pozwala to w oszczędzaniu baterii. Istnieje również możliwość, aby włączyć wybrany czujnik zaraz po wyłączeniu ekranu, spowoduje to większe zużycie baterii.</string> </resources> diff --git a/doze/res/values-sv/strings.xml b/doze/res/values-sv/strings.xml index 225a2b8..030a831 100644 --- a/doze/res/values-sv/strings.xml +++ b/doze/res/values-sv/strings.xml @@ -15,10 +15,8 @@ <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- Tilt sensor --> <string name="pick_up_title">Plocka upp</string> - <string name="pick_up_summary">Pulsera aviseringarna när enheten plockas upp</string> <!-- Proximity sensor --> <string name="priximity_sensor_title">Närhetscensor</string> - <string name="pocket_gesture_summary">Pulsera aviseringar när telefonen tas upp ur fickan</string> <!-- Help text --> <string name="dlg_ok">OK</string> <string name="doze_settings_help_title">Hjälp</string> 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 9643190..fed5b05 100644 --- a/doze/res/values/strings.xml +++ b/doze/res/values/strings.xml @@ -13,11 +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="always_enabled_title">Always enable</string> - <string name="always_enabled_summary">Listen for sensor events as soon as the screen turns off</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> @@ -34,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 09e27b5..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,15 +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" /> - - <SwitchPreference - android:key="tilt_always" - android:defaultValue="false" - android:title="@string/always_enabled_title" - android:summary="@string/always_enabled_summary" - android:dependency="ambient_display" /> + android:summary="@string/pick_up_summary" /> </PreferenceCategory> @@ -50,22 +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" /> - - <SwitchPreference - android:key="proximity_always" - android:defaultValue="false" - android:title="@string/always_enabled_title" - android:summary="@string/always_enabled_summary" - android:dependency="ambient_display" /> + android:summary="@string/pocket_gesture_summary" /> </PreferenceCategory> diff --git a/doze/src/com/cyanogenmod/settings/doze/BootCompletedReceiver.java b/doze/src/com/cyanogenmod/settings/doze/BootCompletedReceiver.java index e1b2b50..2283575 100644 --- a/doze/src/com/cyanogenmod/settings/doze/BootCompletedReceiver.java +++ b/doze/src/com/cyanogenmod/settings/doze/BootCompletedReceiver.java @@ -24,7 +24,7 @@ import android.util.Log; public class BootCompletedReceiver extends BroadcastReceiver { private static final boolean DEBUG = false; - private static final String TAG = "ZukDoze"; + private static final String TAG = "OneplusDoze"; @Override public void onReceive(final Context context, Intent intent) { 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/DozeService.java b/doze/src/com/cyanogenmod/settings/doze/DozeService.java index 354d97f..2ee79bf 100644 --- a/doze/src/com/cyanogenmod/settings/doze/DozeService.java +++ b/doze/src/com/cyanogenmod/settings/doze/DozeService.java @@ -75,11 +75,11 @@ public class DozeService extends Service { private void onDisplayOff() { if (DEBUG) Log.d(TAG, "Display off"); - if (Utils.pickUpEnabled(this) && Utils.tiltAlwaysEnabled(this)) { + if (Utils.pickUpEnabled(this)) { mTiltSensor.enable(); } - if (Utils.proximityAlwaysEnabled(this) && (Utils.handwaveGestureEnabled(this) || - Utils.pocketGestureEnabled(this))) { + if (Utils.handwaveGestureEnabled(this) || + Utils.pocketGestureEnabled(this)) { mProximitySensor.enable(); } } diff --git a/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java b/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java index d2c408a..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,88 +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 mTiltAlwaysPreference; - private SwitchPreference mHandwavePreference; - private SwitchPreference mPocketPreference; - private SwitchPreference mProximityAlwaysPreference; + 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); - - mTiltAlwaysPreference = - (SwitchPreference) findPreference(Utils.TILT_ALWAYS_KEY); - mTiltAlwaysPreference.setOnPreferenceChangeListener(this); - - 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); + setContentView(R.layout.doze); - mProximityAlwaysPreference = - (SwitchPreference) findPreference(Utils.PROXIMITY_ALWAYS_KEY); - mProximityAlwaysPreference.setOnPreferenceChangeListener(this); - - final ActionBar actionBar = getActionBar(); - actionBar.setDisplayHomeAsUpEnabled(true); - - updateAlwaysEnabledPreference(); - } - - @Override - protected void onResume() { - super.onResume(); - updateAlwaysEnabledPreference(); + getFragmentManager().beginTransaction().replace(R.id.content_frame, + new DozeSettingsFragment(), TAG_DOZE).commit(); } @Override @@ -105,74 +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); - updateAlwaysEnabledPreference(); - Utils.startService(mContext); - return true; - } else if (Utils.TILT_ALWAYS_KEY.equals(key)) { - mTiltAlwaysPreference.setChecked(value); - return true; - } else if (Utils.GESTURE_HAND_WAVE_KEY.equals(key)) { - mHandwavePreference.setChecked(value); - updateAlwaysEnabledPreference(); - Utils.startService(mContext); - return true; - } else if (Utils.GESTURE_POCKET_KEY.equals(key)) { - mPocketPreference.setChecked(value); - updateAlwaysEnabledPreference(); - Utils.startService(mContext); - return true; - } else if (Utils.PROXIMITY_ALWAYS_KEY.equals(key)) { - mProximityAlwaysPreference.setChecked(value); - 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"); - } - - private void updateAlwaysEnabledPreference() { - boolean tiltEnabled = Utils.pickUpEnabled(mContext); - boolean proximityEnabled = Utils.handwaveGestureEnabled(mContext) - || Utils.pocketGestureEnabled(mContext); - mTiltAlwaysPreference.setEnabled(tiltEnabled); - mProximityAlwaysPreference.setEnabled(proximityEnabled); - } } 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 bdc696b..585ccbf 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,12 +33,12 @@ 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 TILT_ALWAYS_KEY = "tilt_always"; protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave"; protected static final String GESTURE_POCKET_KEY = "gesture_pocket"; - protected static final String PROXIMITY_ALWAYS_KEY = "proximity_always"; + + 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"); @@ -52,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 { @@ -77,11 +77,6 @@ public final class Utils { .getBoolean(PICK_UP_KEY, false); } - protected static boolean tiltAlwaysEnabled(Context context) { - return PreferenceManager.getDefaultSharedPreferences(context) - .getBoolean(TILT_ALWAYS_KEY, false); - } - protected static boolean handwaveGestureEnabled(Context context) { return PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(GESTURE_HAND_WAVE_KEY, false); @@ -92,11 +87,6 @@ public final class Utils { .getBoolean(GESTURE_POCKET_KEY, false); } - protected static boolean proximityAlwaysEnabled(Context context) { - return PreferenceManager.getDefaultSharedPreferences(context) - .getBoolean(PROXIMITY_ALWAYS_KEY, false); - } - protected static boolean sensorsEnabled(Context context) { return pickUpEnabled(context) || handwaveGestureEnabled(context) || pocketGestureEnabled(context); |