summaryrefslogtreecommitdiff
path: root/doze
diff options
context:
space:
mode:
Diffstat (limited to 'doze')
-rw-r--r--doze/src/org/lineageos/settings/doze/DozeService.java16
-rw-r--r--doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java16
-rw-r--r--doze/src/org/lineageos/settings/doze/ProximitySensor.java6
-rw-r--r--doze/src/org/lineageos/settings/doze/Utils.java33
4 files changed, 41 insertions, 30 deletions
diff --git a/doze/src/org/lineageos/settings/doze/DozeService.java b/doze/src/org/lineageos/settings/doze/DozeService.java
index 31c7c90..5b161e2 100644
--- a/doze/src/org/lineageos/settings/doze/DozeService.java
+++ b/doze/src/org/lineageos/settings/doze/DozeService.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2015 The CyanogenMod Project
- * 2017 The LineageOS Project
+ * Copyright (C) 2015 The CyanogenMod Project
+ * 2017-2018 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -65,22 +65,22 @@ public class DozeService extends Service {
private void onDisplayOn() {
if (DEBUG) Log.d(TAG, "Display on");
- if (Utils.pickUpEnabled(this)) {
+ if (Utils.isPickUpEnabled(this)) {
mTiltSensor.disable();
}
- if (Utils.handwaveGestureEnabled(this) ||
- Utils.pocketGestureEnabled(this)) {
+ if (Utils.isHandwaveGestureEnabled(this) ||
+ Utils.isPocketGestureEnabled(this)) {
mProximitySensor.disable();
}
}
private void onDisplayOff() {
if (DEBUG) Log.d(TAG, "Display off");
- if (Utils.pickUpEnabled(this)) {
+ if (Utils.isPickUpEnabled(this)) {
mTiltSensor.enable();
}
- if (Utils.handwaveGestureEnabled(this) ||
- Utils.pocketGestureEnabled(this)) {
+ if (Utils.isHandwaveGestureEnabled(this) ||
+ Utils.isPocketGestureEnabled(this)) {
mProximitySensor.enable();
}
}
diff --git a/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java b/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java
index 1798c10..3770b5e 100644
--- a/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java
+++ b/doze/src/org/lineageos/settings/doze/DozeSettingsFragment.java
@@ -67,12 +67,15 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
mPickUpPreference = (SwitchPreference) findPreference(Utils.GESTURE_PICK_UP_KEY);
mPickUpPreference.setEnabled(dozeEnabled);
+ mPickUpPreference.setOnPreferenceChangeListener(this);
mHandwavePreference = (SwitchPreference) findPreference(Utils.GESTURE_HAND_WAVE_KEY);
mHandwavePreference.setEnabled(dozeEnabled);
+ mHandwavePreference.setOnPreferenceChangeListener(this);
mPocketPreference = (SwitchPreference) findPreference(Utils.GESTURE_POCKET_KEY);
mPocketPreference.setEnabled(dozeEnabled);
+ mPocketPreference.setOnPreferenceChangeListener(this);
// Hide proximity sensor related features if the device doesn't support them
if (!Utils.getProxCheckBeforePulse(getActivity())) {
@@ -107,20 +110,21 @@ 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());
return true;
}
@Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
- Utils.enableDoze(b, getActivity());
+ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
+ Utils.enableDoze(getActivity(), isChecked);
Utils.checkDozeService(getActivity());
- mTextView.setText(getString(b ? R.string.switch_bar_on : R.string.switch_bar_off));
+ mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off));
- mPickUpPreference.setEnabled(b);
- mHandwavePreference.setEnabled(b);
- mPocketPreference.setEnabled(b);
+ mPickUpPreference.setEnabled(isChecked);
+ mHandwavePreference.setEnabled(isChecked);
+ mPocketPreference.setEnabled(isChecked);
}
@Override
diff --git a/doze/src/org/lineageos/settings/doze/ProximitySensor.java b/doze/src/org/lineageos/settings/doze/ProximitySensor.java
index 52b8e75..71594ff 100644
--- a/doze/src/org/lineageos/settings/doze/ProximitySensor.java
+++ b/doze/src/org/lineageos/settings/doze/ProximitySensor.java
@@ -74,11 +74,11 @@ public class ProximitySensor implements SensorEventListener {
private boolean shouldPulse(long timestamp) {
long delta = timestamp - mInPocketTime;
- if (Utils.handwaveGestureEnabled(mContext) && Utils.pocketGestureEnabled(mContext)) {
+ if (Utils.isHandwaveGestureEnabled(mContext) && Utils.isPocketGestureEnabled(mContext)) {
return true;
- } else if (Utils.handwaveGestureEnabled(mContext)) {
+ } else if (Utils.isHandwaveGestureEnabled(mContext)) {
return delta < HANDWAVE_MAX_DELTA_NS;
- } else if (Utils.pocketGestureEnabled(mContext)) {
+ } else if (Utils.isPocketGestureEnabled(mContext)) {
return delta >= POCKET_MIN_DELTA_NS;
}
return false;
diff --git a/doze/src/org/lineageos/settings/doze/Utils.java b/doze/src/org/lineageos/settings/doze/Utils.java
index 2abec57..9cd7fdd 100644
--- a/doze/src/org/lineageos/settings/doze/Utils.java
+++ b/doze/src/org/lineageos/settings/doze/Utils.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2015 The CyanogenMod Project
- * 2017 The LineageOS Project
+ * Copyright (C) 2015 The CyanogenMod Project
+ * 2017-2018 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,7 +76,7 @@ public final class Utils {
DOZE_ENABLED, 1) != 0;
}
- protected static boolean enableDoze(boolean enable, Context context) {
+ protected static boolean enableDoze(Context context, boolean enable) {
return Settings.Secure.putInt(context.getContentResolver(),
DOZE_ENABLED, enable ? 1 : 0);
}
@@ -87,23 +87,30 @@ public final class Utils {
new UserHandle(UserHandle.USER_CURRENT));
}
- protected static boolean pickUpEnabled(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context)
- .getBoolean(GESTURE_PICK_UP_KEY, false);
+ protected static void enableGesture(Context context, String gesture, boolean enable) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit()
+ .putBoolean(gesture, enable).apply();
}
- protected static boolean handwaveGestureEnabled(Context context) {
+ protected static boolean isGestureEnabled(Context context, String gesture) {
return PreferenceManager.getDefaultSharedPreferences(context)
- .getBoolean(GESTURE_HAND_WAVE_KEY, false);
+ .getBoolean(gesture, false);
}
- protected static boolean pocketGestureEnabled(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context)
- .getBoolean(GESTURE_POCKET_KEY, false);
+ protected static boolean isPickUpEnabled(Context context) {
+ return isGestureEnabled(context, GESTURE_PICK_UP_KEY);
+ }
+
+ protected static boolean isHandwaveGestureEnabled(Context context) {
+ return isGestureEnabled(context, GESTURE_HAND_WAVE_KEY);
+ }
+
+ protected static boolean isPocketGestureEnabled(Context context) {
+ return isGestureEnabled(context, GESTURE_POCKET_KEY);
}
protected static boolean sensorsEnabled(Context context) {
- return pickUpEnabled(context) || handwaveGestureEnabled(context)
- || pocketGestureEnabled(context);
+ return isPickUpEnabled(context) || isHandwaveGestureEnabled(context)
+ || isPocketGestureEnabled(context);
}
}