From 6fcbd7f597248e81bfa07cdef2aae581f590b350 Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Tue, 8 Jan 2019 14:56:52 +0100 Subject: [PATCH] sm8150-common: 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/DozeSettingsFragment.java | 8 +++++--- doze/src/org/lineageos/settings/doze/Utils.java | 5 ----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java b/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java index 0a03d3f4..517ecf6f 100644 --- a/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java +++ b/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java @@ -26,6 +26,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; 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; @@ -50,6 +51,8 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer private SwitchPreference mPickUpPreference; private SwitchPreference mPocketPreference; + private Handler mHandler = new Handler(); + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.doze_settings); @@ -124,10 +127,9 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer 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 10f6c459..c86ad83c 100644 --- a/doze/src/org/lineageos/settings/doze/Utils.java +++ b/doze/src/org/lineageos/settings/doze/Utils.java @@ -96,11 +96,6 @@ public final class Utils { return new AmbientDisplayConfiguration(context).alwaysOnAvailable(); } - protected static void enableGesture(Context context, String gesture, boolean enable) { - PreferenceManager.getDefaultSharedPreferences(context).edit() - .putBoolean(gesture, enable).apply(); - } - protected static boolean isGestureEnabled(Context context, String gesture) { return PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(gesture, false);