sdm845-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
5736ed5e06
commit
f67403199e
2 changed files with 5 additions and 8 deletions
|
@ -26,6 +26,7 @@ import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.support.v14.preference.PreferenceFragment;
|
import android.support.v14.preference.PreferenceFragment;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
@ -50,6 +51,8 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||||
private SwitchPreference mPickUpPreference;
|
private SwitchPreference mPickUpPreference;
|
||||||
private SwitchPreference mPocketPreference;
|
private SwitchPreference mPocketPreference;
|
||||||
|
|
||||||
|
private Handler mHandler = new Handler();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
addPreferencesFromResource(R.xml.doze_settings);
|
addPreferencesFromResource(R.xml.doze_settings);
|
||||||
|
@ -124,10 +127,9 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
if (Utils.ALWAYS_ON_DISPLAY.equals(preference.getKey())) {
|
if (Utils.ALWAYS_ON_DISPLAY.equals(preference.getKey())) {
|
||||||
Utils.enableAlwaysOn(getActivity(), (Boolean) newValue);
|
Utils.enableAlwaysOn(getActivity(), (Boolean) newValue);
|
||||||
} else {
|
|
||||||
Utils.enableGesture(getActivity(), preference.getKey(), (Boolean) newValue);
|
|
||||||
}
|
}
|
||||||
Utils.checkDozeService(getActivity());
|
|
||||||
|
mHandler.post(() -> Utils.checkDozeService(getActivity()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,11 +96,6 @@ public final class Utils {
|
||||||
return new AmbientDisplayConfiguration(context).alwaysOnAvailable();
|
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) {
|
protected static boolean isGestureEnabled(Context context, String gesture) {
|
||||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
.getBoolean(gesture, false);
|
.getBoolean(gesture, false);
|
||||||
|
|
Loading…
Reference in a new issue