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
This commit is contained in:
Luca Stefani 2019-01-08 14:56:52 +01:00 committed by luk1337
parent 26f4f08a36
commit 6fcbd7f597
2 changed files with 5 additions and 8 deletions

View File

@ -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;
}

View File

@ -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);