aboutsummaryrefslogtreecommitdiff
path: root/doze/src
diff options
context:
space:
mode:
Diffstat (limited to 'doze/src')
-rw-r--r--doze/src/com/cyanogenmod/settings/doze/BootCompletedReceiver.java2
-rw-r--r--doze/src/com/cyanogenmod/settings/doze/DozeReceiver.java54
-rw-r--r--doze/src/com/cyanogenmod/settings/doze/DozeService.java6
-rw-r--r--doze/src/com/cyanogenmod/settings/doze/DozeSettings.java152
-rw-r--r--doze/src/com/cyanogenmod/settings/doze/DozeSettingsFragment.java197
-rw-r--r--doze/src/com/cyanogenmod/settings/doze/Utils.java28
6 files changed, 276 insertions, 163 deletions
diff --git a/doze/src/com/cyanogenmod/settings/doze/BootCompletedReceiver.java b/doze/src/com/cyanogenmod/settings/doze/BootCompletedReceiver.java
index e1b2b50..2283575 100644
--- a/doze/src/com/cyanogenmod/settings/doze/BootCompletedReceiver.java
+++ b/doze/src/com/cyanogenmod/settings/doze/BootCompletedReceiver.java
@@ -24,7 +24,7 @@ import android.util.Log;
public class BootCompletedReceiver extends BroadcastReceiver {
private static final boolean DEBUG = false;
- private static final String TAG = "ZukDoze";
+ private static final String TAG = "OneplusDoze";
@Override
public void onReceive(final Context context, Intent intent) {
diff --git a/doze/src/com/cyanogenmod/settings/doze/DozeReceiver.java b/doze/src/com/cyanogenmod/settings/doze/DozeReceiver.java
new file mode 100644
index 0000000..6ab3e0d
--- /dev/null
+++ b/doze/src/com/cyanogenmod/settings/doze/DozeReceiver.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.cyanogenmod.settings.doze;
+
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+import cyanogenmod.preference.RemotePreferenceUpdater;
+
+public class DozeReceiver extends RemotePreferenceUpdater {
+
+ private static final boolean DEBUG = false;
+ private static final String TAG = "OneplusDoze";
+
+ private static final String DOZE_CATEGORY_KEY = "doze_device_settings";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ super.onReceive(context, intent);
+
+ if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
+ if (Utils.isDozeEnabled(context) && Utils.sensorsEnabled(context)) {
+ if (DEBUG) Log.d(TAG, "Starting service");
+ Utils.startService(context);
+ }
+ }
+ }
+
+ @Override
+ public String getSummary(Context context, String key) {
+ if (DOZE_CATEGORY_KEY.equals(key)) {
+ return DozeSettingsFragment.getDozeSummary(context);
+ }
+ return null;
+ }
+
+ static void notifyChanged(Context context) {
+ notifyChanged(context, DOZE_CATEGORY_KEY);
+ }
+}
diff --git a/doze/src/com/cyanogenmod/settings/doze/DozeService.java b/doze/src/com/cyanogenmod/settings/doze/DozeService.java
index 354d97f..2ee79bf 100644
--- a/doze/src/com/cyanogenmod/settings/doze/DozeService.java
+++ b/doze/src/com/cyanogenmod/settings/doze/DozeService.java
@@ -75,11 +75,11 @@ public class DozeService extends Service {
private void onDisplayOff() {
if (DEBUG) Log.d(TAG, "Display off");
- if (Utils.pickUpEnabled(this) && Utils.tiltAlwaysEnabled(this)) {
+ if (Utils.pickUpEnabled(this)) {
mTiltSensor.enable();
}
- if (Utils.proximityAlwaysEnabled(this) && (Utils.handwaveGestureEnabled(this) ||
- Utils.pocketGestureEnabled(this))) {
+ if (Utils.handwaveGestureEnabled(this) ||
+ Utils.pocketGestureEnabled(this)) {
mProximitySensor.enable();
}
}
diff --git a/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java b/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java
index d2c408a..76ac5fe 100644
--- a/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java
+++ b/doze/src/com/cyanogenmod/settings/doze/DozeSettings.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 The CyanogenMod Project
+ * Copyright (C) 2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,88 +13,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.cyanogenmod.settings.doze;
-import android.app.ActionBar;
import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.DialogFragment;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.SharedPreferences;
import android.os.Bundle;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
-import android.preference.PreferenceActivity;
-import android.preference.PreferenceScreen;
-import android.preference.SwitchPreference;
-import android.provider.Settings;
-import android.view.Menu;
import android.view.MenuItem;
-public class DozeSettings extends PreferenceActivity implements OnPreferenceChangeListener {
+import com.android.settingslib.drawer.SettingsDrawerActivity;
+
+/**
+ * Created by shade on 10/14/16.
+ */
- private Context mContext;
- private SharedPreferences mPreferences;
+public class DozeSettings extends SettingsDrawerActivity {
- private SwitchPreference mAmbientDisplayPreference;
- private SwitchPreference mPickUpPreference;
- private SwitchPreference mTiltAlwaysPreference;
- private SwitchPreference mHandwavePreference;
- private SwitchPreference mPocketPreference;
- private SwitchPreference mProximityAlwaysPreference;
+ private static final String TAG_DOZE = "doze";
@Override
- public void onCreate(Bundle savedInstanceState) {
+ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.doze_settings);
- mContext = getApplicationContext();
- boolean dozeEnabled = Utils.isDozeEnabled(mContext);
-
- // get shared preference
- mPreferences = mContext.getSharedPreferences("doze_settings", Activity.MODE_PRIVATE);
- if (savedInstanceState == null && !mPreferences.getBoolean("first_help_shown", false)) {
- showHelp();
- }
-
- mAmbientDisplayPreference =
- (SwitchPreference) findPreference(Utils.AMBIENT_DISPLAY_KEY);
- // Read from DOZE_ENABLED secure setting
- mAmbientDisplayPreference.setChecked(dozeEnabled);
- mAmbientDisplayPreference.setOnPreferenceChangeListener(this);
-
- mTiltAlwaysPreference =
- (SwitchPreference) findPreference(Utils.TILT_ALWAYS_KEY);
- mTiltAlwaysPreference.setOnPreferenceChangeListener(this);
-
- mPickUpPreference =
- (SwitchPreference) findPreference(Utils.PICK_UP_KEY);
- mPickUpPreference.setOnPreferenceChangeListener(this);
-
- mHandwavePreference =
- (SwitchPreference) findPreference(Utils.GESTURE_HAND_WAVE_KEY);
- mHandwavePreference.setOnPreferenceChangeListener(this);
- mPocketPreference =
- (SwitchPreference) findPreference(Utils.GESTURE_POCKET_KEY);
- mPocketPreference.setOnPreferenceChangeListener(this);
+ setContentView(R.layout.doze);
- mProximityAlwaysPreference =
- (SwitchPreference) findPreference(Utils.PROXIMITY_ALWAYS_KEY);
- mProximityAlwaysPreference.setOnPreferenceChangeListener(this);
-
- final ActionBar actionBar = getActionBar();
- actionBar.setDisplayHomeAsUpEnabled(true);
-
- updateAlwaysEnabledPreference();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- updateAlwaysEnabledPreference();
+ getFragmentManager().beginTransaction().replace(R.id.content_frame,
+ new DozeSettingsFragment(), TAG_DOZE).commit();
}
@Override
@@ -105,74 +47,4 @@ public class DozeSettings extends PreferenceActivity implements OnPreferenceChan
}
return false;
}
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final String key = preference.getKey();
- final boolean value = (Boolean) newValue;
- if (Utils.AMBIENT_DISPLAY_KEY.equals(key)) {
- mAmbientDisplayPreference.setChecked(value);
- Utils.enableDoze(value, mContext);
- return true;
- } else if (Utils.PICK_UP_KEY.equals(key)) {
- mPickUpPreference.setChecked(value);
- updateAlwaysEnabledPreference();
- Utils.startService(mContext);
- return true;
- } else if (Utils.TILT_ALWAYS_KEY.equals(key)) {
- mTiltAlwaysPreference.setChecked(value);
- return true;
- } else if (Utils.GESTURE_HAND_WAVE_KEY.equals(key)) {
- mHandwavePreference.setChecked(value);
- updateAlwaysEnabledPreference();
- Utils.startService(mContext);
- return true;
- } else if (Utils.GESTURE_POCKET_KEY.equals(key)) {
- mPocketPreference.setChecked(value);
- updateAlwaysEnabledPreference();
- Utils.startService(mContext);
- return true;
- } else if (Utils.PROXIMITY_ALWAYS_KEY.equals(key)) {
- mProximityAlwaysPreference.setChecked(value);
- return true;
- }
- return false;
- }
-
- public static class HelpDialogFragment extends DialogFragment {
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- return new AlertDialog.Builder(getActivity())
- .setTitle(R.string.doze_settings_help_title)
- .setMessage(R.string.doze_settings_help_text)
- .setNegativeButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- }
- })
- .create();
- }
-
- @Override
- public void onCancel(DialogInterface dialog) {
- getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE)
- .edit()
- .putBoolean("first_help_shown", true)
- .commit();
- }
- }
-
- private void showHelp() {
- HelpDialogFragment fragment = new HelpDialogFragment();
- fragment.show(getFragmentManager(), "help_dialog");
- }
-
- private void updateAlwaysEnabledPreference() {
- boolean tiltEnabled = Utils.pickUpEnabled(mContext);
- boolean proximityEnabled = Utils.handwaveGestureEnabled(mContext)
- || Utils.pocketGestureEnabled(mContext);
- mTiltAlwaysPreference.setEnabled(tiltEnabled);
- mProximityAlwaysPreference.setEnabled(proximityEnabled);
- }
}
diff --git a/doze/src/com/cyanogenmod/settings/doze/DozeSettingsFragment.java b/doze/src/com/cyanogenmod/settings/doze/DozeSettingsFragment.java
new file mode 100644
index 0000000..ec1c9d8
--- /dev/null
+++ b/doze/src/com/cyanogenmod/settings/doze/DozeSettingsFragment.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2015 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.cyanogenmod.settings.doze;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.SharedPreferences;
+import android.database.ContentObserver;
+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;
+import android.support.v7.preference.Preference.OnPreferenceChangeListener;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.CompoundButton;
+import android.widget.Switch;
+
+public class DozeSettingsFragment extends PreferenceFragment implements OnPreferenceChangeListener,
+ CompoundButton.OnCheckedChangeListener {
+
+ private SharedPreferences mPreferences;
+
+ private Switch mSwitch;
+
+ private SwitchPreference mPickUpPreference;
+ private SwitchPreference mHandwavePreference;
+ private SwitchPreference mPocketPreference;
+
+ private ContentObserver mDozeObserver = new ContentObserver(new Handler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+
+ boolean enabled = Utils.isDozeEnabled(getActivity());
+
+ updateSwitches(Utils.isDozeEnabled(getActivity()));
+ DozeReceiver.notifyChanged(getActivity());
+ }
+ };
+
+ static String getDozeSummary(Context context) {
+ if (Utils.isDozeEnabled(context)) {
+ return context.getString(R.string.ambient_display_summary_on);
+ }
+ return context.getString(R.string.ambient_display_summary_off);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ final View view = LayoutInflater.from(getContext()).inflate(R.layout.doze, container, false);
+ ((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState));
+ return view;
+ }
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ addPreferencesFromResource(R.xml.doze_settings);
+
+ // get shared preference
+ mPreferences = getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE);
+
+ if (savedInstanceState == null && !mPreferences.getBoolean("first_help_shown", false)) {
+ showHelp();
+ }
+
+ mPickUpPreference =
+ (SwitchPreference) findPreference(Utils.PICK_UP_KEY);
+ mPickUpPreference.setOnPreferenceChangeListener(this);
+
+ mHandwavePreference =
+ (SwitchPreference) findPreference(Utils.GESTURE_HAND_WAVE_KEY);
+ mHandwavePreference.setOnPreferenceChangeListener(this);
+
+ mPocketPreference =
+ (SwitchPreference) findPreference(Utils.GESTURE_POCKET_KEY);
+ mPocketPreference.setOnPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ getActivity().getContentResolver().registerContentObserver(
+ Utils.DOZE_ENABLED_URI, false, mDozeObserver);
+ updateSwitches(Utils.isDozeEnabled(getActivity()));
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ getActivity().getContentResolver().unregisterContentObserver(mDozeObserver);
+ }
+
+ private void updateSwitches(boolean enabled) {
+ mPickUpPreference.setEnabled(enabled);
+ mHandwavePreference.setEnabled(enabled);
+ mPocketPreference.setEnabled(enabled);
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+
+ View switchBar = view.findViewById(R.id.switch_bar);
+ mSwitch = (Switch) switchBar.findViewById(android.R.id.switch_widget);
+ mSwitch.setChecked(Utils.isDozeEnabled(getActivity()));
+ mSwitch.setOnCheckedChangeListener(this);
+
+ switchBar.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mSwitch.setChecked(!mSwitch.isChecked());
+ }
+ });
+ }
+
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final String key = preference.getKey();
+ final boolean value = (Boolean) newValue;
+ if (Utils.PICK_UP_KEY.equals(key)) {
+ mPickUpPreference.setChecked(value);
+ } else if (Utils.GESTURE_HAND_WAVE_KEY.equals(key)) {
+ mHandwavePreference.setChecked(value);
+ } else if (Utils.GESTURE_POCKET_KEY.equals(key)) {
+ mPocketPreference.setChecked(value);
+ } else {
+ return false;
+ }
+
+ Utils.startService(getActivity());
+ return true;
+ }
+
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+ Utils.enableDoze(b, getActivity());
+ }
+
+ public static class HelpDialogFragment extends DialogFragment {
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ return new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.doze_settings_help_title)
+ .setMessage(R.string.doze_settings_help_text)
+ .setNegativeButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ })
+ .create();
+ }
+
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE)
+ .edit()
+ .putBoolean("first_help_shown", true)
+ .commit();
+ }
+ }
+
+ private void showHelp() {
+ HelpDialogFragment fragment = new HelpDialogFragment();
+ fragment.show(getFragmentManager(), "help_dialog");
+ }
+}
diff --git a/doze/src/com/cyanogenmod/settings/doze/Utils.java b/doze/src/com/cyanogenmod/settings/doze/Utils.java
index bdc696b..585ccbf 100644
--- a/doze/src/com/cyanogenmod/settings/doze/Utils.java
+++ b/doze/src/com/cyanogenmod/settings/doze/Utils.java
@@ -16,16 +16,16 @@
package com.cyanogenmod.settings.doze;
-import android.app.ActivityManager;
-import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
+import android.net.Uri;
import android.os.UserHandle;
-import android.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;
+import static android.provider.Settings.Secure.DOZE_ENABLED;
+
public final class Utils {
private static final String TAG = "DozeUtils";
@@ -33,12 +33,12 @@ public final class Utils {
private static final String DOZE_INTENT = "com.android.systemui.doze.pulse";
- protected static final String AMBIENT_DISPLAY_KEY = "ambient_display";
+ protected static final String AMBIENT_DISPLAY_KEY = "doze_enabled";
protected static final String PICK_UP_KEY = "pick_up";
- protected static final String TILT_ALWAYS_KEY = "tilt_always";
protected static final String GESTURE_HAND_WAVE_KEY = "gesture_hand_wave";
protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
- protected static final String PROXIMITY_ALWAYS_KEY = "proximity_always";
+
+ public static final Uri DOZE_ENABLED_URI = Settings.Secure.getUriFor(DOZE_ENABLED);
protected static void startService(Context context) {
if (DEBUG) Log.d(TAG, "Starting service");
@@ -52,12 +52,12 @@ public final class Utils {
protected static boolean isDozeEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(),
- Settings.Secure.DOZE_ENABLED, 1) != 0;
+ DOZE_ENABLED, 1) != 0;
}
protected static boolean enableDoze(boolean enable, Context context) {
boolean dozeEnabled = Settings.Secure.putInt(context.getContentResolver(),
- Settings.Secure.DOZE_ENABLED, enable ? 1 : 0);
+ DOZE_ENABLED, enable ? 1 : 0);
if (enable) {
startService(context);
} else {
@@ -77,11 +77,6 @@ public final class Utils {
.getBoolean(PICK_UP_KEY, false);
}
- protected static boolean tiltAlwaysEnabled(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context)
- .getBoolean(TILT_ALWAYS_KEY, false);
- }
-
protected static boolean handwaveGestureEnabled(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(GESTURE_HAND_WAVE_KEY, false);
@@ -92,11 +87,6 @@ public final class Utils {
.getBoolean(GESTURE_POCKET_KEY, false);
}
- protected static boolean proximityAlwaysEnabled(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context)
- .getBoolean(PROXIMITY_ALWAYS_KEY, false);
- }
-
protected static boolean sensorsEnabled(Context context) {
return pickUpEnabled(context) || handwaveGestureEnabled(context)
|| pocketGestureEnabled(context);