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:
parent
26f4f08a36
commit
6fcbd7f597
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue