summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorDave Kessler <activethrasher00@gmail.com>2014-12-19 17:29:40 -0500
committerAdnan Begovic <adnan@cyngn.com>2015-10-29 17:36:27 -0700
commit2ea9a80502df3cd28c4255b7250cd257755e9e2f (patch)
tree17dca8fcbbd2398cffdc16e20d78c045dff8f2ea /src/com/android
parent3f0f7d02181b960a6bd6c9724b07fced6bdcb119 (diff)
downloadpackages_apps_Settings-2ea9a80502df3cd28c4255b7250cd257755e9e2f.zip
packages_apps_Settings-2ea9a80502df3cd28c4255b7250cd257755e9e2f.tar.gz
packages_apps_Settings-2ea9a80502df3cd28c4255b7250cd257755e9e2f.tar.bz2
Power menu customizations [2/2]
power reboot screenshot profile switcher airplane mode user switcher bug reports [mikeioannina]: Modify for CyanogenMod Change-Id: Iadb41a661770f8b71eef4e12b1d8f04d0ba3e6be
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/settings/ButtonSettings.java1
-rw-r--r--src/com/android/settings/cyanogenmod/PowerMenuActions.java316
-rw-r--r--src/com/android/settings/profiles/ProfilesSettings.java1
3 files changed, 317 insertions, 1 deletions
diff --git a/src/com/android/settings/ButtonSettings.java b/src/com/android/settings/ButtonSettings.java
index f8f0562..5ddfab1 100644
--- a/src/com/android/settings/ButtonSettings.java
+++ b/src/com/android/settings/ButtonSettings.java
@@ -207,7 +207,6 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
if (!Utils.isVoiceCapable(getActivity())) {
powerCategory.removePreference(mPowerEndCall);
mPowerEndCall = null;
- prefScreen.removePreference(powerCategory);
}
} else {
prefScreen.removePreference(powerCategory);
diff --git a/src/com/android/settings/cyanogenmod/PowerMenuActions.java b/src/com/android/settings/cyanogenmod/PowerMenuActions.java
new file mode 100644
index 0000000..b43fdfa
--- /dev/null
+++ b/src/com/android/settings/cyanogenmod/PowerMenuActions.java
@@ -0,0 +1,316 @@
+/*
+ * Copyright (C) 2014-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.android.settings.cyanogenmod;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.UserInfo;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
+import android.preference.ListPreference;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.provider.Settings;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.internal.util.cm.PowerMenuConstants;
+
+import static com.android.internal.util.cm.PowerMenuConstants.*;
+
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
+
+public class PowerMenuActions extends SettingsPreferenceFragment {
+ final static String TAG = "PowerMenuActions";
+
+ private CheckBoxPreference mPowerPref;
+ private CheckBoxPreference mRebootPref;
+ private CheckBoxPreference mScreenshotPref;
+ private CheckBoxPreference mProfilePref;
+ private CheckBoxPreference mAirplanePref;
+ private CheckBoxPreference mUsersPref;
+ private CheckBoxPreference mSettingsPref;
+ private CheckBoxPreference mLockdownPref;
+ private CheckBoxPreference mBugReportPref;
+ private CheckBoxPreference mSilentPref;
+
+ Context mContext;
+ private ArrayList<String> mLocalUserConfig = new ArrayList<String>();
+ private String[] mAvailableActions;
+ private String[] mAllActions;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ addPreferencesFromResource(R.xml.power_menu_settings);
+ mContext = getActivity().getApplicationContext();
+
+ mAvailableActions = getActivity().getResources().getStringArray(
+ R.array.power_menu_actions_array);
+ mAllActions = PowerMenuConstants.getAllActions();
+
+ for (String action : mAllActions) {
+ // Remove preferences not present in the overlay
+ if (!isActionAllowed(action)) {
+ getPreferenceScreen().removePreference(findPreference(action));
+ continue;
+ }
+
+ if (action.equals(GLOBAL_ACTION_KEY_POWER)) {
+ mPowerPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_POWER);
+ } else if (action.equals(GLOBAL_ACTION_KEY_REBOOT)) {
+ mRebootPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_REBOOT);
+ } else if (action.equals(GLOBAL_ACTION_KEY_SCREENSHOT)) {
+ mScreenshotPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_SCREENSHOT);
+ } else if (action.equals(GLOBAL_ACTION_KEY_PROFILE)) {
+ mProfilePref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_PROFILE);
+ } else if (action.equals(GLOBAL_ACTION_KEY_AIRPLANE)) {
+ mAirplanePref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_AIRPLANE);
+ } else if (action.equals(GLOBAL_ACTION_KEY_USERS)) {
+ mUsersPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_USERS);
+ } else if (action.equals(GLOBAL_ACTION_KEY_SETTINGS)) {
+ mSettingsPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_SETTINGS);
+ } else if (action.equals(GLOBAL_ACTION_KEY_LOCKDOWN)) {
+ mLockdownPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_LOCKDOWN);
+ } else if (action.equals(GLOBAL_ACTION_KEY_BUGREPORT)) {
+ mBugReportPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_BUGREPORT);
+ } else if (action.equals(GLOBAL_ACTION_KEY_SILENT)) {
+ mSilentPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_SILENT);
+ }
+ }
+
+ getUserConfig();
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ if (mPowerPref != null) {
+ mPowerPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_POWER));
+ }
+
+ if (mRebootPref != null) {
+ mRebootPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_REBOOT));
+ }
+
+ if (mScreenshotPref != null) {
+ mScreenshotPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_SCREENSHOT));
+ }
+
+ if (mProfilePref != null) {
+ mProfilePref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_PROFILE));
+ }
+
+ if (mAirplanePref != null) {
+ mAirplanePref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_AIRPLANE));
+ }
+
+ if (mUsersPref != null) {
+ if (!UserHandle.MU_ENABLED || !UserManager.supportsMultipleUsers()) {
+ getPreferenceScreen().removePreference(findPreference(GLOBAL_ACTION_KEY_USERS));
+ } else {
+ List<UserInfo> users = ((UserManager) mContext.getSystemService(
+ Context.USER_SERVICE)).getUsers();
+ boolean enabled = (users.size() > 1);
+ mUsersPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_USERS) && enabled);
+ mUsersPref.setEnabled(enabled);
+ }
+ }
+
+ if (mSettingsPref != null) {
+ mSettingsPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_SETTINGS));
+ }
+
+ if (mLockdownPref != null) {
+ mLockdownPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_LOCKDOWN));
+ }
+
+ if (mBugReportPref != null) {
+ mBugReportPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_BUGREPORT));
+ }
+
+ if (mSilentPref != null) {
+ mSilentPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_SILENT));
+ }
+
+ updatePreferences();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ updatePreferences();
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+ boolean value;
+
+ if (preference == mPowerPref) {
+ value = mPowerPref.isChecked();
+ updateUserConfig(value, GLOBAL_ACTION_KEY_POWER);
+
+ } else if (preference == mRebootPref) {
+ value = mRebootPref.isChecked();
+ updateUserConfig(value, GLOBAL_ACTION_KEY_REBOOT);
+
+ } else if (preference == mScreenshotPref) {
+ value = mScreenshotPref.isChecked();
+ updateUserConfig(value, GLOBAL_ACTION_KEY_SCREENSHOT);
+
+ } else if (preference == mProfilePref) {
+ value = mProfilePref.isChecked();
+ updateUserConfig(value, GLOBAL_ACTION_KEY_PROFILE);
+
+ } else if (preference == mAirplanePref) {
+ value = mAirplanePref.isChecked();
+ updateUserConfig(value, GLOBAL_ACTION_KEY_AIRPLANE);
+
+ } else if (preference == mUsersPref) {
+ value = mUsersPref.isChecked();
+ updateUserConfig(value, GLOBAL_ACTION_KEY_USERS);
+
+ } else if (preference == mSettingsPref) {
+ value = mSettingsPref.isChecked();
+ updateUserConfig(value, GLOBAL_ACTION_KEY_SETTINGS);
+
+ } else if (preference == mLockdownPref) {
+ value = mLockdownPref.isChecked();
+ updateUserConfig(value, GLOBAL_ACTION_KEY_LOCKDOWN);
+
+ } else if (preference == mBugReportPref) {
+ value = mBugReportPref.isChecked();
+ updateUserConfig(value, GLOBAL_ACTION_KEY_BUGREPORT);
+
+ } else if (preference == mSilentPref) {
+ value = mSilentPref.isChecked();
+ updateUserConfig(value, GLOBAL_ACTION_KEY_SILENT);
+
+ } else {
+ return super.onPreferenceTreeClick(preferenceScreen, preference);
+ }
+ return true;
+ }
+
+ private boolean settingsArrayContains(String preference) {
+ return mLocalUserConfig.contains(preference);
+ }
+
+ private boolean isActionAllowed(String action) {
+ if (Arrays.asList(mAvailableActions).contains(action)) {
+ return true;
+ }
+ return false;
+ }
+
+ private void updateUserConfig(boolean enabled, String action) {
+ if (enabled) {
+ if (!settingsArrayContains(action)) {
+ mLocalUserConfig.add(action);
+ }
+ } else {
+ if (settingsArrayContains(action)) {
+ mLocalUserConfig.remove(action);
+ }
+ }
+ saveUserConfig();
+ }
+
+ private void updatePreferences() {
+ boolean bugreport = Settings.Secure.getInt(getContentResolver(),
+ Settings.Secure.BUGREPORT_IN_POWER_MENU, 0) != 0;
+ boolean profiles = Settings.System.getInt(getContentResolver(),
+ Settings.System.SYSTEM_PROFILES_ENABLED, 1) != 0;
+
+ if (mProfilePref != null) {
+ mProfilePref.setEnabled(profiles);
+ if (profiles) {
+ mProfilePref.setSummary(null);
+ } else {
+ mProfilePref.setSummary(R.string.power_menu_profiles_disabled);
+ }
+ }
+
+ if (mBugReportPref != null) {
+ mBugReportPref.setEnabled(bugreport);
+ if (bugreport) {
+ mBugReportPref.setSummary(null);
+ } else {
+ mBugReportPref.setSummary(R.string.power_menu_bug_report_disabled);
+ }
+ }
+ }
+
+ private void getUserConfig() {
+ mLocalUserConfig.clear();
+ String[] defaultActions;
+ String savedActions = Settings.Global.getStringForUser(mContext.getContentResolver(),
+ Settings.Global.POWER_MENU_ACTIONS, UserHandle.USER_CURRENT);
+
+ if (savedActions == null) {
+ defaultActions = mContext.getResources().getStringArray(
+ com.android.internal.R.array.config_globalActionsList);
+ for (String action : defaultActions) {
+ mLocalUserConfig.add(action);
+ }
+ } else {
+ for (String action : savedActions.split("\\|")) {
+ mLocalUserConfig.add(action);
+ }
+ }
+ }
+
+ private void saveUserConfig() {
+ StringBuilder s = new StringBuilder();
+
+ // TODO: Use DragSortListView
+ ArrayList<String> setactions = new ArrayList<String>();
+ for (String action : mAllActions) {
+ if (settingsArrayContains(action) && isActionAllowed(action)) {
+ setactions.add(action);
+ } else {
+ continue;
+ }
+ }
+
+ for (int i = 0; i < setactions.size(); i++) {
+ s.append(setactions.get(i).toString());
+ if (i != setactions.size() - 1) {
+ s.append("|");
+ }
+ }
+
+ Settings.Global.putStringForUser(getContentResolver(),
+ Settings.Global.POWER_MENU_ACTIONS, s.toString(), UserHandle.USER_CURRENT);
+ updatePowerMenuDialog();
+ }
+
+ private void updatePowerMenuDialog() {
+ Intent u = new Intent();
+ u.setAction(Intent.UPDATE_POWER_MENU);
+ mContext.sendBroadcastAsUser(u, UserHandle.ALL);
+ }
+}
diff --git a/src/com/android/settings/profiles/ProfilesSettings.java b/src/com/android/settings/profiles/ProfilesSettings.java
index ed12663..59078ae 100644
--- a/src/com/android/settings/profiles/ProfilesSettings.java
+++ b/src/com/android/settings/profiles/ProfilesSettings.java
@@ -27,6 +27,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
+import android.os.UserHandle;
import android.provider.Settings;
import android.support.v4.view.ViewPager;
import android.support.v13.app.FragmentStatePagerAdapter;