summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/cyanogenmod
diff options
context:
space:
mode:
authorcrizmess <jens.doll@gmail.com>2013-03-18 20:40:21 +0100
committerDvTonder <david.vantonder@gmail.com>2013-03-25 18:08:15 -0400
commite5bba18990fb2cbb4e777e6bd81a97254d909462 (patch)
treed7c296ee82aa03d406fb67f443975a5bec6e43b3 /src/com/android/settings/cyanogenmod
parent5814f08554e053081e76e7dcf6e8ff804ae5d713 (diff)
downloadpackages_apps_settings-e5bba18990fb2cbb4e777e6bd81a97254d909462.zip
packages_apps_settings-e5bba18990fb2cbb4e777e6bd81a97254d909462.tar.gz
packages_apps_settings-e5bba18990fb2cbb4e777e6bd81a97254d909462.tar.bz2
Bringing basic Pie controls to CyanogenMod. (2/2)
This is the settings part of the pie commit, for the real implementation look in frameworks/base. Patch Set 3: * CyanogenMod Code Style Patch Set 4: * Strings cleanup * Better integration into CyanogenMod system settings UX * Some related cleanup in SysteSettings.java Patch Set 5 and 6: * Rename feature to Quick controls to match AOSP terminology Patch Set 7: * Remove WIP Patch Set 8: * Revert name to Pie controls Patch Set 11: * Fix broken revert * Fix spelling of search Change-Id: I47599316273d8e46017f49ba62a02cc55a785678
Diffstat (limited to 'src/com/android/settings/cyanogenmod')
-rw-r--r--src/com/android/settings/cyanogenmod/PieControl.java135
-rw-r--r--src/com/android/settings/cyanogenmod/PieSizePreference.java148
-rw-r--r--src/com/android/settings/cyanogenmod/SystemSettings.java55
3 files changed, 319 insertions, 19 deletions
diff --git a/src/com/android/settings/cyanogenmod/PieControl.java b/src/com/android/settings/cyanogenmod/PieControl.java
new file mode 100644
index 0000000..b902fc7
--- /dev/null
+++ b/src/com/android/settings/cyanogenmod/PieControl.java
@@ -0,0 +1,135 @@
+package com.android.settings.cyanogenmod;
+
+import android.content.ContentResolver;
+import android.database.ContentObserver;
+import android.os.Bundle;
+import android.os.Handler;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
+import android.preference.SeekBarDialogPreference;
+import android.provider.Settings;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+public class PieControl extends SettingsPreferenceFragment
+ implements Preference.OnPreferenceChangeListener {
+
+ private static final int DEFAULT_POSITION = 1 << 1; // this equals Position.BOTTOM.FLAG
+
+ private static final String PIE_CONTROL = "pie_control_checkbox";
+ private static final String SEARCH_BUTTON = "pie_control_search";
+ private static final String PIE_SIZE = "pie_control_size";
+ private static final String[] TRIGGER = {
+ "pie_control_trigger_left",
+ "pie_control_trigger_bottom",
+ "pie_control_trigger_right",
+ "pie_control_trigger_top"
+ };
+
+ private CheckBoxPreference mPieControl;
+ private CheckBoxPreference mSearchButton;
+ private SeekBarDialogPreference mPieSize;
+ private CheckBoxPreference[] mTrigger = new CheckBoxPreference[4];
+
+ private ContentObserver mPieTriggerObserver = new ContentObserver(new Handler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ updatePieTriggers();
+ }
+ };
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ addPreferencesFromResource(R.xml.pie_control);
+
+ PreferenceScreen prefSet = getPreferenceScreen();
+ mPieControl = (CheckBoxPreference) prefSet.findPreference(PIE_CONTROL);
+ mPieControl.setOnPreferenceChangeListener(this);
+ mSearchButton = (CheckBoxPreference) prefSet.findPreference(SEARCH_BUTTON);
+ mSearchButton.setOnPreferenceChangeListener(this);
+ mPieSize = (SeekBarDialogPreference) prefSet.findPreference(PIE_SIZE);
+
+ for (int i = 0; i < TRIGGER.length; i++) {
+ mTrigger[i] = (CheckBoxPreference) prefSet.findPreference(TRIGGER[i]);
+ mTrigger[i].setOnPreferenceChangeListener(this);
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (preference == mPieControl) {
+ boolean newState = (Boolean) newValue;
+
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.PIE_CONTROLS, newState ? 1 : 0);
+ propagatePieControl(newState);
+
+ } else if (preference == mSearchButton) {
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.PIE_SEARCH, (Boolean) newValue ? 1 : 0);
+
+ } else {
+ int triggerSlots = 0;
+ for (int i = 0; i < mTrigger.length; i++) {
+ boolean checked = preference == mTrigger[i]
+ ? (Boolean) newValue : mTrigger[i].isChecked();
+ if (checked) {
+ triggerSlots |= 1 << i;
+ }
+ }
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.PIE_GRAVITY, triggerSlots);
+ }
+ return true;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ mPieControl.setChecked(Settings.System.getInt(getContentResolver(),
+ Settings.System.PIE_CONTROLS, 0) == 1);
+ propagatePieControl(mPieControl.isChecked());
+
+ mSearchButton.setChecked(Settings.System.getInt(getContentResolver(),
+ Settings.System.PIE_SEARCH, 0) == 1);
+
+ getContentResolver().registerContentObserver(
+ Settings.System.getUriFor(Settings.System.PIE_GRAVITY), true,
+ mPieTriggerObserver);
+
+ updatePieTriggers();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ getContentResolver().unregisterContentObserver(mPieTriggerObserver);
+ }
+
+ private void propagatePieControl(boolean value) {
+ mSearchButton.setEnabled(value);
+ for (int i = 0; i < mTrigger.length; i++) {
+ mTrigger[i].setEnabled(value);
+ }
+ mPieSize.setEnabled(value);
+ }
+
+ private void updatePieTriggers() {
+ int triggerSlots = Settings.System.getInt(getContentResolver(),
+ Settings.System.PIE_GRAVITY, DEFAULT_POSITION);
+
+ for (int i = 0; i < mTrigger.length; i++) {
+ if ((triggerSlots & (0x01 << i)) != 0) {
+ mTrigger[i].setChecked(true);
+ } else {
+ mTrigger[i].setChecked(false);
+ }
+ }
+ }
+
+}
diff --git a/src/com/android/settings/cyanogenmod/PieSizePreference.java b/src/com/android/settings/cyanogenmod/PieSizePreference.java
new file mode 100644
index 0000000..11394d6
--- /dev/null
+++ b/src/com/android/settings/cyanogenmod/PieSizePreference.java
@@ -0,0 +1,148 @@
+package com.android.settings.cyanogenmod;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.preference.SeekBarDialogPreference;
+import android.provider.Settings;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.SeekBar;
+
+public class PieSizePreference extends SeekBarDialogPreference
+ implements SeekBar.OnSeekBarChangeListener {
+
+ private SeekBar mSeekBar;
+
+ private float mOldSize;
+
+ private boolean mRestoredOldState = true;
+
+ private static final int SEEK_BAR_MIN = 500;
+ private static final int SEEK_BAR_MAX = 1500;
+
+ public PieSizePreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ protected void showDialog(Bundle state) {
+ super.showDialog(state);
+ mRestoredOldState = false;
+ }
+
+ @Override
+ protected void onBindDialogView(View view) {
+ super.onBindDialogView(view);
+
+ mSeekBar = getSeekBar(view);
+ mSeekBar.setMax(SEEK_BAR_MAX);
+ mOldSize = Settings.System.getFloat(getContext().getContentResolver(),
+ Settings.System.PIE_SIZE, 1.0f);
+
+ mSeekBar.setProgress((int) (mOldSize * 1000 - SEEK_BAR_MIN));
+ mSeekBar.setEnabled(true);
+ mSeekBar.setOnSeekBarChangeListener(this);
+ }
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
+ Settings.System.putFloat(getContext().getContentResolver(),
+ Settings.System.PIE_SIZE, (SEEK_BAR_MIN + progress) / 1000f);
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult) {
+ super.onDialogClosed(positiveResult);
+
+ if (positiveResult) {
+ onProgressChanged(mSeekBar, mSeekBar.getProgress(), true);
+ } else {
+ restoreOldState();
+ }
+ }
+
+ private void restoreOldState() {
+ if (mRestoredOldState) {
+ return;
+ }
+
+ Settings.System.putFloat(getContext().getContentResolver(),
+ Settings.System.PIE_SIZE, mOldSize);
+
+ mRestoredOldState = true;
+ }
+
+ @Override
+ protected Parcelable onSaveInstanceState() {
+ final Parcelable superState = super.onSaveInstanceState();
+ if (getDialog() == null || !getDialog().isShowing()) {
+ return superState;
+ }
+
+ // Save the dialog state
+ final SavedState myState = new SavedState(superState);
+ myState.oldSize = mOldSize;
+
+ // Restore the old state when the activity or dialog is being paused
+ restoreOldState();
+ return myState;
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Parcelable state) {
+ if (state == null || !state.getClass().equals(SavedState.class)) {
+ // Didn't save state for us in onSaveInstanceState
+ super.onRestoreInstanceState(state);
+ return;
+ }
+
+ SavedState myState = (SavedState) state;
+ super.onRestoreInstanceState(myState.getSuperState());
+ mOldSize = myState.oldSize;
+ }
+
+ private static class SavedState extends BaseSavedState {
+
+ float oldSize;
+
+ public SavedState(Parcel source) {
+ super(source);
+ oldSize = source.readFloat();
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ super.writeToParcel(dest, flags);
+ dest.writeFloat(oldSize);
+ }
+
+ public SavedState(Parcelable superState) {
+ super(superState);
+ }
+
+ public static final Parcelable.Creator<SavedState> CREATOR =
+ new Parcelable.Creator<SavedState>() {
+
+ public SavedState createFromParcel(Parcel in) {
+ return new SavedState(in);
+ }
+
+ public SavedState[] newArray(int size) {
+ return new SavedState[size];
+ }
+ };
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ // nothing to do
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ // nothing to do
+ }
+
+}
diff --git a/src/com/android/settings/cyanogenmod/SystemSettings.java b/src/com/android/settings/cyanogenmod/SystemSettings.java
index 1c07877..889dc04 100644
--- a/src/com/android/settings/cyanogenmod/SystemSettings.java
+++ b/src/com/android/settings/cyanogenmod/SystemSettings.java
@@ -48,9 +48,11 @@ public class SystemSettings extends SettingsPreferenceFragment {
private static final String KEY_QUICK_SETTINGS = "quick_settings_panel";
private static final String KEY_NOTIFICATION_DRAWER = "notification_drawer";
private static final String KEY_POWER_MENU = "power_menu";
+ private static final String KEY_PIE_CONTROL = "pie_control";
private PreferenceScreen mNotificationPulse;
private PreferenceScreen mBatteryPulse;
+ private PreferenceScreen mPieControl;
private boolean mIsPrimary;
@Override
@@ -70,8 +72,7 @@ public class SystemSettings extends SettingsPreferenceFragment {
if (getResources().getBoolean(
com.android.internal.R.bool.config_intrusiveBatteryLed) == false) {
prefScreen.removePreference(mBatteryPulse);
- } else {
- updateBatteryPulseDescription();
+ mBatteryPulse = null;
}
}
@@ -119,15 +120,40 @@ public class SystemSettings extends SettingsPreferenceFragment {
if (mNotificationPulse != null) {
if (!getResources().getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)) {
prefScreen.removePreference(mNotificationPulse);
- } else {
- updateLightPulseDescription();
+ mNotificationPulse = null;
}
}
+ // Pie controls
+ mPieControl = (PreferenceScreen) findPreference(KEY_PIE_CONTROL);
+
// Don't display the lock clock preference if its not installed
removePreferenceIfPackageNotInstalled(findPreference(KEY_LOCK_CLOCK));
}
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ // All users
+ if (mNotificationPulse != null) {
+ updateLightPulseDescription();
+ }
+ if (mPieControl != null) {
+ updatePieControlDescription();
+ }
+
+ // Primary user only
+ if (mIsPrimary && mBatteryPulse != null) {
+ updateBatteryPulseDescription();
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ }
+
private void updateLightPulseDescription() {
if (Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.NOTIFICATION_LIGHT_PULSE, 0) == 1) {
@@ -146,24 +172,15 @@ public class SystemSettings extends SettingsPreferenceFragment {
}
}
- @Override
- public void onResume() {
- super.onResume();
-
- // All users
- updateLightPulseDescription();
-
- // Primary user only
- if (mIsPrimary) {
- updateBatteryPulseDescription();
+ private void updatePieControlDescription() {
+ if (Settings.System.getInt(getActivity().getContentResolver(),
+ Settings.System.PIE_CONTROLS, 0) == 1) {
+ mPieControl.setSummary(getString(R.string.pie_control_enabled));
+ } else {
+ mPieControl.setSummary(getString(R.string.pie_control_disabled));
}
}
- @Override
- public void onPause() {
- super.onPause();
- }
-
private boolean removePreferenceIfPackageNotInstalled(Preference preference) {
String intentUri = ((PreferenceScreen) preference).getIntent().toUri(1);
Pattern pattern = Pattern.compile("component=([^/]+)/");