From 9a527bab46bae5d4aea2ebd070e49dd390d94f30 Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Tue, 8 Jan 2019 14:56:52 +0100 Subject: [PATCH] samsung: doze: Move Utils.checkDozeService in an handler * There's no need to manually write to the gestures prefs as long we are sure the handler is run after we return true in the onPreferenceChangeListner Change-Id: I090c0c6c91267aff69c45365b95b5f5e26d07b07 --- .../org/lineageos/settings/doze/SamsungDozeSettings.java | 7 ++++--- doze/src/org/lineageos/settings/doze/Utils.java | 5 ----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java b/doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java index 546fec18..7ee7cab6 100644 --- a/doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java +++ b/doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java @@ -19,6 +19,7 @@ package org.lineageos.settings.doze; import android.app.ActionBar; import android.os.Bundle; +import android.os.Handler; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -43,6 +44,8 @@ public class SamsungDozeSettings extends PreferenceFragment private SwitchPreference mHandwavePreference; private SwitchPreference mPocketPreference; + private Handler mHandler = new Handler(); + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.gesture_panel); @@ -117,11 +120,9 @@ public class SamsungDozeSettings extends PreferenceFragment public boolean onPreferenceChange(Preference preference, Object newValue) { if (Utils.ALWAYS_ON_DISPLAY.equals(preference.getKey())) { Utils.enableAlwaysOn(getActivity(), (Boolean) newValue); - } else { - Utils.enableGesture(getActivity(), preference.getKey(), (Boolean) newValue); } - Utils.checkDozeService(getActivity()); + mHandler.post(() -> Utils.checkDozeService(getActivity())); return true; } diff --git a/doze/src/org/lineageos/settings/doze/Utils.java b/doze/src/org/lineageos/settings/doze/Utils.java index c8746900..d6ff02ac 100644 --- a/doze/src/org/lineageos/settings/doze/Utils.java +++ b/doze/src/org/lineageos/settings/doze/Utils.java @@ -84,11 +84,6 @@ public final class Utils { DOZE_ENABLED, enable ? 1 : 0); } - protected static void enableGesture(Context context, String gesture, boolean enable) { - PreferenceManager.getDefaultSharedPreferences(context).edit() - .putBoolean(gesture, enable).apply(); - } - protected static boolean isAnyGestureEnabled(Context context) { return isHandwaveGestureEnabled(context) || isPocketGestureEnabled(context); }