diff options
author | crizmess <jens.doll@gmail.com> | 2013-03-18 20:40:21 +0100 |
---|---|---|
committer | DvTonder <david.vantonder@gmail.com> | 2013-03-25 18:08:15 -0400 |
commit | e5bba18990fb2cbb4e777e6bd81a97254d909462 (patch) | |
tree | d7c296ee82aa03d406fb67f443975a5bec6e43b3 /src/com/android/settings/cyanogenmod/PieControl.java | |
parent | 5814f08554e053081e76e7dcf6e8ff804ae5d713 (diff) | |
download | packages_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/PieControl.java')
-rw-r--r-- | src/com/android/settings/cyanogenmod/PieControl.java | 135 |
1 files changed, 135 insertions, 0 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); + } + } + } + +} |