From f9f9c448c90ad039fcc94cd38ffed47d43faf516 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Wed, 6 Oct 2021 07:25:13 +0000 Subject: msm8996-common: doze: Adapt to S style * Use Theme.SubSettingsBase for theme * Replace PreferenceActivity with CollapsingToolbarBaseActivity * Add Titles to prefernce screen * Remove onOptionsItemSelected and where neccessary move to activity Change-Id: Ic879ce61d83a33da12829008a4336c8a23230d63 Signed-off-by: Davide Garberi --- doze/AndroidManifest.xml | 2 +- doze/res/layout/doze.xml | 28 ------ doze/res/xml/doze_settings.xml | 9 +- .../settings/doze/BootCompletedReceiver.java | 2 +- .../org/lineageos/settings/doze/DozeService.java | 17 ++-- .../settings/doze/DozeSettingsActivity.java | 10 +- .../settings/doze/DozeSettingsFragment.java | 83 ++++----------- .../src/org/lineageos/settings/doze/DozeUtils.java | 111 +++++++++++++++++++++ .../lineageos/settings/doze/ProximitySensor.java | 10 +- .../org/lineageos/settings/doze/TiltSensor.java | 6 +- doze/src/org/lineageos/settings/doze/Utils.java | 111 --------------------- 11 files changed, 162 insertions(+), 227 deletions(-) delete mode 100644 doze/res/layout/doze.xml create mode 100644 doze/src/org/lineageos/settings/doze/DozeUtils.java delete mode 100644 doze/src/org/lineageos/settings/doze/Utils.java (limited to 'doze') diff --git a/doze/AndroidManifest.xml b/doze/AndroidManifest.xml index 62d87f3..72581c2 100644 --- a/doze/AndroidManifest.xml +++ b/doze/AndroidManifest.xml @@ -48,7 +48,7 @@ + android:theme="@style/Theme.SubSettingsBase"> diff --git a/doze/res/layout/doze.xml b/doze/res/layout/doze.xml deleted file mode 100644 index 941cdf6..0000000 --- a/doze/res/layout/doze.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - diff --git a/doze/res/xml/doze_settings.xml b/doze/res/xml/doze_settings.xml index fe4fa0a..72823dc 100644 --- a/doze/res/xml/doze_settings.xml +++ b/doze/res/xml/doze_settings.xml @@ -15,7 +15,14 @@ See the License for the specific language governing permissions and limitations under the License. --> - + + + { - switchWidget.setChecked(!switchWidget.isChecked()); - mSwitchBar.setActivated(switchWidget.isChecked()); - }); - } - @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - mHandler.post(() -> Utils.checkDozeService(getActivity())); + mHandler.post(() -> DozeUtils.checkDozeService(getActivity())); return true; } @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { - Utils.enableDoze(getActivity(), isChecked); - Utils.checkDozeService(getActivity()); + public void onSwitchChanged(Switch switchView, boolean isChecked) { + DozeUtils.enableDoze(getActivity(), isChecked); + DozeUtils.checkDozeService(getActivity()); - mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off)); - mSwitchBar.setActivated(isChecked); + mSwitchBar.setChecked(isChecked); mPickUpPreference.setEnabled(isChecked); mHandwavePreference.setEnabled(isChecked); mPocketPreference.setEnabled(isChecked); } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - getActivity().onBackPressed(); - return true; - } - return false; - } - private static class HelpDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { diff --git a/doze/src/org/lineageos/settings/doze/DozeUtils.java b/doze/src/org/lineageos/settings/doze/DozeUtils.java new file mode 100644 index 0000000..62dce44 --- /dev/null +++ b/doze/src/org/lineageos/settings/doze/DozeUtils.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * 2017-2022 The LineageOS 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 org.lineageos.settings.doze; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.UserHandle; +import android.provider.Settings; +import android.util.Log; +import androidx.preference.PreferenceManager; + +import static android.provider.Settings.Secure.DOZE_ENABLED; + +public final class DozeUtils { + + private static final String TAG = "DozeUtils"; + private static final boolean DEBUG = false; + + private static final String DOZE_INTENT = "com.android.systemui.doze.pulse"; + + protected static final String CATEG_PROX_SENSOR = "proximity_sensor"; + + protected static final String GESTURE_PICK_UP_KEY = "gesture_pick_up"; + protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave"; + protected static final String GESTURE_POCKET_KEY = "gesture_pocket"; + + protected static void startService(Context context) { + if (DEBUG) Log.d(TAG, "Starting service"); + context.startServiceAsUser(new Intent(context, DozeService.class), + UserHandle.CURRENT); + } + + protected static void stopService(Context context) { + if (DEBUG) Log.d(TAG, "Stopping service"); + context.stopServiceAsUser(new Intent(context, DozeService.class), + UserHandle.CURRENT); + } + + protected static void checkDozeService(Context context) { + if (isDozeEnabled(context) && sensorsEnabled(context)) { + startService(context); + } else { + stopService(context); + } + } + + protected static boolean getProxCheckBeforePulse(Context context) { + try { + Context con = context.createPackageContext("com.android.systemui", 0); + int id = con.getResources().getIdentifier("doze_proximity_check_before_pulse", + "bool", "com.android.systemui"); + return con.getResources().getBoolean(id); + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + + protected static boolean isDozeEnabled(Context context) { + return Settings.Secure.getInt(context.getContentResolver(), + DOZE_ENABLED, 1) != 0; + } + + protected static boolean enableDoze(Context context, boolean enable) { + return Settings.Secure.putInt(context.getContentResolver(), + DOZE_ENABLED, enable ? 1 : 0); + } + + protected static void launchDozePulse(Context context) { + if (DEBUG) Log.d(TAG, "Launch doze pulse"); + context.sendBroadcastAsUser(new Intent(DOZE_INTENT), + new UserHandle(UserHandle.USER_CURRENT)); + } + + protected static boolean isGestureEnabled(Context context, String gesture) { + return PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(gesture, false); + } + + protected static boolean isPickUpEnabled(Context context) { + return isGestureEnabled(context, GESTURE_PICK_UP_KEY); + } + + protected static boolean isHandwaveGestureEnabled(Context context) { + return isGestureEnabled(context, GESTURE_HAND_WAVE_KEY); + } + + protected static boolean isPocketGestureEnabled(Context context) { + return isGestureEnabled(context, GESTURE_POCKET_KEY); + } + + protected static boolean sensorsEnabled(Context context) { + return isPickUpEnabled(context) || isHandwaveGestureEnabled(context) + || isPocketGestureEnabled(context); + } +} diff --git a/doze/src/org/lineageos/settings/doze/ProximitySensor.java b/doze/src/org/lineageos/settings/doze/ProximitySensor.java index 71594ff..b1de348 100644 --- a/doze/src/org/lineageos/settings/doze/ProximitySensor.java +++ b/doze/src/org/lineageos/settings/doze/ProximitySensor.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2015 The CyanogenMod Project - * 2017-2018 The LineageOS Project + * 2017-2018,2021 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,7 +63,7 @@ public class ProximitySensor implements SensorEventListener { boolean isNear = event.values[0] < mSensor.getMaximumRange(); if (mSawNear && !isNear) { if (shouldPulse(event.timestamp)) { - Utils.launchDozePulse(mContext); + DozeUtils.launchDozePulse(mContext); } } else { mInPocketTime = event.timestamp; @@ -74,11 +74,11 @@ public class ProximitySensor implements SensorEventListener { private boolean shouldPulse(long timestamp) { long delta = timestamp - mInPocketTime; - if (Utils.isHandwaveGestureEnabled(mContext) && Utils.isPocketGestureEnabled(mContext)) { + if (DozeUtils.isHandwaveGestureEnabled(mContext) && DozeUtils.isPocketGestureEnabled(mContext)) { return true; - } else if (Utils.isHandwaveGestureEnabled(mContext)) { + } else if (DozeUtils.isHandwaveGestureEnabled(mContext)) { return delta < HANDWAVE_MAX_DELTA_NS; - } else if (Utils.isPocketGestureEnabled(mContext)) { + } else if (DozeUtils.isPocketGestureEnabled(mContext)) { return delta >= POCKET_MIN_DELTA_NS; } return false; diff --git a/doze/src/org/lineageos/settings/doze/TiltSensor.java b/doze/src/org/lineageos/settings/doze/TiltSensor.java index 6598127..768eb92 100644 --- a/doze/src/org/lineageos/settings/doze/TiltSensor.java +++ b/doze/src/org/lineageos/settings/doze/TiltSensor.java @@ -1,6 +1,6 @@ /* - * Copyright (c) 2015 The CyanogenMod Project - * 2017-2018 The LineageOS Project + * Copyright (C) 2015 The CyanogenMod Project + * 2017-2018,2021 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,7 +67,7 @@ public class TiltSensor implements SensorEventListener { } if (event.values[0] == 1) { - Utils.launchDozePulse(mContext); + DozeUtils.launchDozePulse(mContext); } } diff --git a/doze/src/org/lineageos/settings/doze/Utils.java b/doze/src/org/lineageos/settings/doze/Utils.java deleted file mode 100644 index 987e06a..0000000 --- a/doze/src/org/lineageos/settings/doze/Utils.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2015 The CyanogenMod Project - * 2017-2019 The LineageOS 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 org.lineageos.settings.doze; - -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.os.UserHandle; -import android.provider.Settings; -import android.util.Log; -import androidx.preference.PreferenceManager; - -import static android.provider.Settings.Secure.DOZE_ENABLED; - -public final class Utils { - - private static final String TAG = "DozeUtils"; - private static final boolean DEBUG = false; - - private static final String DOZE_INTENT = "com.android.systemui.doze.pulse"; - - protected static final String CATEG_PROX_SENSOR = "proximity_sensor"; - - protected static final String GESTURE_PICK_UP_KEY = "gesture_pick_up"; - protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave"; - protected static final String GESTURE_POCKET_KEY = "gesture_pocket"; - - protected static void startService(Context context) { - if (DEBUG) Log.d(TAG, "Starting service"); - context.startServiceAsUser(new Intent(context, DozeService.class), - UserHandle.CURRENT); - } - - protected static void stopService(Context context) { - if (DEBUG) Log.d(TAG, "Stopping service"); - context.stopServiceAsUser(new Intent(context, DozeService.class), - UserHandle.CURRENT); - } - - protected static void checkDozeService(Context context) { - if (isDozeEnabled(context) && sensorsEnabled(context)) { - startService(context); - } else { - stopService(context); - } - } - - protected static boolean getProxCheckBeforePulse(Context context) { - try { - Context con = context.createPackageContext("com.android.systemui", 0); - int id = con.getResources().getIdentifier("doze_proximity_check_before_pulse", - "bool", "com.android.systemui"); - return con.getResources().getBoolean(id); - } catch (PackageManager.NameNotFoundException e) { - return false; - } - } - - protected static boolean isDozeEnabled(Context context) { - return Settings.Secure.getInt(context.getContentResolver(), - DOZE_ENABLED, 1) != 0; - } - - protected static boolean enableDoze(Context context, boolean enable) { - return Settings.Secure.putInt(context.getContentResolver(), - DOZE_ENABLED, enable ? 1 : 0); - } - - protected static void launchDozePulse(Context context) { - if (DEBUG) Log.d(TAG, "Launch doze pulse"); - context.sendBroadcastAsUser(new Intent(DOZE_INTENT), - new UserHandle(UserHandle.USER_CURRENT)); - } - - protected static boolean isGestureEnabled(Context context, String gesture) { - return PreferenceManager.getDefaultSharedPreferences(context) - .getBoolean(gesture, false); - } - - protected static boolean isPickUpEnabled(Context context) { - return isGestureEnabled(context, GESTURE_PICK_UP_KEY); - } - - protected static boolean isHandwaveGestureEnabled(Context context) { - return isGestureEnabled(context, GESTURE_HAND_WAVE_KEY); - } - - protected static boolean isPocketGestureEnabled(Context context) { - return isGestureEnabled(context, GESTURE_POCKET_KEY); - } - - protected static boolean sensorsEnabled(Context context) { - return isPickUpEnabled(context) || isHandwaveGestureEnabled(context) - || isPocketGestureEnabled(context); - } -} -- cgit v1.2.3