summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/ButtonSettings.java
diff options
context:
space:
mode:
authorNextbit <contributions@nextbit.com>2015-01-28 13:46:52 -0800
committerAdnan Begovic <adnan@cyngn.com>2015-10-29 17:36:28 -0700
commit5f8bf98dc28d58becadf0bbbcd0ed8d359e68d39 (patch)
tree05b6250908c34ee0e776ace6d52f9695b8a4637a /src/com/android/settings/ButtonSettings.java
parent9cf9098e3f3a6d71ec600b862005452068db86b8 (diff)
downloadpackages_apps_Settings-5f8bf98dc28d58becadf0bbbcd0ed8d359e68d39.zip
packages_apps_Settings-5f8bf98dc28d58becadf0bbbcd0ed8d359e68d39.tar.gz
packages_apps_Settings-5f8bf98dc28d58becadf0bbbcd0ed8d359e68d39.tar.bz2
Settings: ButtonSettings: Introduce recents long press action
Add a new preference in Settings > Buttons > Recents long press action that controls the behavior of recents long press intent ACTION_RECENTS_LONG_PRESS. The user preference is saved in Settings.Secure.RECENTS_LONG_PRESS_ACTIVITY; if empty the default is the system's "switch to last app" behavior. Settings.Secure is used intentionally over Settings.System for permission reasons. Change-Id: Ifc61b5958a88360e32db31459f0205b6ba5306b3
Diffstat (limited to 'src/com/android/settings/ButtonSettings.java')
-rw-r--r--src/com/android/settings/ButtonSettings.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/com/android/settings/ButtonSettings.java b/src/com/android/settings/ButtonSettings.java
index 6cb6895..95bb3d9 100644
--- a/src/com/android/settings/ButtonSettings.java
+++ b/src/com/android/settings/ButtonSettings.java
@@ -16,8 +16,12 @@
package com.android.settings;
+import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
@@ -63,6 +67,7 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
private static final String KEY_SWAP_VOLUME_BUTTONS = "swap_volume_buttons";
private static final String DISABLE_NAV_KEYS = "disable_nav_keys";
private static final String KEY_NAVIGATION_BAR_LEFT = "navigation_bar_left";
+ private static final String KEY_NAVIGATION_RECENTS_LONG_PRESS = "navigation_recents_long_press";
private static final String KEY_POWER_END_CALL = "power_end_call";
private static final String KEY_HOME_ANSWER_CALL = "home_answer_call";
private static final String KEY_BLUETOOTH_INPUT_SETTINGS = "bluetooth_input_settings";
@@ -113,6 +118,7 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
private SwitchPreference mSwapVolumeButtons;
private SwitchPreference mDisableNavigationKeys;
private SwitchPreference mNavigationBarLeftPref;
+ private ListPreference mNavigationRecentsLongPressAction;
private SwitchPreference mPowerEndCall;
private SwitchPreference mHomeAnswerCall;
@@ -182,6 +188,9 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
// Navigation bar left
mNavigationBarLeftPref = (SwitchPreference) findPreference(KEY_NAVIGATION_BAR_LEFT);
+ // Navigation bar recents long press activity needs custom setup
+ mNavigationRecentsLongPressAction = initRecentsLongPressAction(KEY_NAVIGATION_RECENTS_LONG_PRESS);
+
// Only visible on devices that does not have a navigation bar already,
// and don't even try unless the existing keys can be disabled
boolean needsNavigationBar = false;
@@ -402,6 +411,68 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
return list;
}
+ private ListPreference initRecentsLongPressAction(String key) {
+ ListPreference list = (ListPreference) getPreferenceScreen().findPreference(key);
+ list.setOnPreferenceChangeListener(this);
+
+ // Read the componentName from Settings.Secure, this is the user's prefered setting
+ String componentString = Settings.Secure.getString(getContentResolver(),
+ Settings.Secure.RECENTS_LONG_PRESS_ACTIVITY);
+ ComponentName targetComponent = null;
+ if (componentString == null) {
+ list.setSummary(getString(R.string.hardware_keys_action_last_app));
+ } else {
+ targetComponent = ComponentName.unflattenFromString(componentString);
+ }
+
+ // Dyanamically generate the list array, query PackageManager for all Activites that are registered for
+ // ACTION_RECENTS_LONG_PRESS
+ PackageManager pm = getPackageManager();
+ Intent intent = new Intent(Intent.ACTION_RECENTS_LONG_PRESS);
+ List<ResolveInfo> recentsActivities = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
+ if (recentsActivities.size() == 0) {
+ // No entries available, disable
+ list.setSummary(getString(R.string.hardware_keys_action_last_app));
+ Settings.Secure.putString(getContentResolver(), Settings.Secure.RECENTS_LONG_PRESS_ACTIVITY, null);
+ list.setEnabled(false);
+ return list;
+ }
+
+ CharSequence[] entries = new CharSequence[recentsActivities.size() + 1];
+ CharSequence[] values = new CharSequence[recentsActivities.size() + 1];
+ // First entry is always default last app
+ entries[0] = getString(R.string.hardware_keys_action_last_app);
+ values[0] = "";
+ list.setValue(values[0].toString());
+ int i = 1;
+ for (ResolveInfo info : recentsActivities) {
+ try {
+ // Use pm.getApplicationInfo for the label, we cannot rely on ResolveInfo that comes back from
+ // queryIntentActivities.
+ entries[i] = pm.getApplicationInfo(info.activityInfo.packageName, 0).loadLabel(pm);
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Error package not found: " + info.activityInfo.packageName, e);
+ // Fallback to package name
+ entries[i] = info.activityInfo.packageName;
+ }
+
+ // Set the value to the ComponentName that will handle this intent
+ ComponentName entryComponent = new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
+ values[i] = entryComponent.flattenToString();
+ if (targetComponent != null) {
+ if (entryComponent.equals(targetComponent)) {
+ // Update the selected value and the preference summary
+ list.setSummary(entries[i]);
+ list.setValue(values[i].toString());
+ }
+ }
+ i++;
+ }
+ list.setEntries(entries);
+ list.setEntryValues(values);
+ return list;
+ }
+
private void handleActionListChange(ListPreference pref, Object newValue, String setting) {
String value = (String) newValue;
int index = pref.findIndexOfValue(value);
@@ -452,6 +523,19 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
handleActionListChange(mVolumeKeyCursorControl, newValue,
Settings.System.VOLUME_KEY_CURSOR_CONTROL);
return true;
+ } else if (preference == mNavigationRecentsLongPressAction) {
+ // RecentsLongPressAction is handled differently because it intentionally uses Settings.
+ // Settings.System.
+ String putString = (String) newValue;
+ int index = mNavigationRecentsLongPressAction.findIndexOfValue(putString);
+ CharSequence summary = mNavigationRecentsLongPressAction.getEntries()[index];
+ // Update the summary
+ mNavigationRecentsLongPressAction.setSummary(summary);
+ if (putString.length() == 0) {
+ putString = null;
+ }
+ Settings.Secure.putString(getContentResolver(), Settings.Secure.RECENTS_LONG_PRESS_ACTIVITY, putString);
+ return true;
}
return false;
}