From 053dcc969f8d7b7bd3a20cadbd0b61a82f02aba0 Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Tue, 8 Jan 2019 14:56:52 +0100 Subject: sdm660-common: doze: Move DozeUtils.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 Signed-off-by: Harsh Shandilya Signed-off-by: Akhil Narang Signed-off-by: Anunay Maheshwari --- doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java | 6 ++++-- doze/src/org/lineageos/settings/doze/Utils.java | 5 ----- 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'doze') diff --git a/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java b/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java index d7db2dd..2af38a8 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.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -49,6 +50,8 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer private SwitchPreference mHandwavePreference; private SwitchPreference mPocketPreference; + private Handler mHandler = new Handler(); + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.doze_settings); @@ -115,8 +118,7 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - 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 7aa6884..8c333f2 100644 --- a/doze/src/org/lineageos/settings/doze/Utils.java +++ b/doze/src/org/lineageos/settings/doze/Utils.java @@ -87,11 +87,6 @@ public final class Utils { new UserHandle(UserHandle.USER_CURRENT)); } - 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); -- cgit v1.2.3