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
tirimbino
Luca Stefani 6 years ago committed by Bruno Martins
parent f69e8a5140
commit 9a527bab46
  1. 7
      doze/src/org/lineageos/settings/doze/SamsungDozeSettings.java
  2. 5
      doze/src/org/lineageos/settings/doze/Utils.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;
}

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

Loading…
Cancel
Save