summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjt1134 <jt1134@gmail.com>2012-12-11 00:05:05 -0600
committerjt1134 <jt1134@gmail.com>2012-12-11 00:12:26 -0600
commitb8f026b7b054a874d28f799d6d663e557a540610 (patch)
tree43f0197d4ee81d1ea9fbb2c925068dce2ca6ab44
parent607bdaefa337b73aed8d2ad7ac9439009a5522d1 (diff)
downloadpackages_apps_settings-b8f026b7b054a874d28f799d6d663e557a540610.zip
packages_apps_settings-b8f026b7b054a874d28f799d6d663e557a540610.tar.gz
packages_apps_settings-b8f026b7b054a874d28f799d6d663e557a540610.tar.bz2
LockScreen: allow long-press actions from hardware keys (2/2)
Allow following actions with button long-presses on lockscreen: - toggle flashlight (if available) - play/pause/next/previous track selection - toggle silent mode Allow customizing of back, menu, and home buttons. Search button events are completely ignored on the lockscreen. Auto-detect hardware keys, only show appropriate menu options based on the actual hardware keys available on the device (or completely hide if there are no hardware keys). Based largely on Danny Baumann's work from gingerbread. Ported from CM10 Change-Id: I36ea5eb7e93d68de872536dc6d7e93f99ba1621f
-rw-r--r--AndroidManifest.xml2
-rw-r--r--res/values/arrays.xml16
-rw-r--r--res/values/strings.xml12
-rw-r--r--res/xml/lockscreen_buttons_settings.xml38
-rw-r--r--res/xml/lockscreen_interface_settings.xml6
-rw-r--r--src/com/android/settings/cyanogenmod/LockscreenButtons.java168
-rw-r--r--src/com/android/settings/cyanogenmod/LockscreenInterface.java9
7 files changed, 251 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index b22c96b..5cc2a48 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1481,6 +1481,8 @@
<activity android:name=".cyanogenmod.LockscreenInterface" />
+ <activity android:name=".cyanogenmod.LockscreenButtons" />
+
<activity android:name=".cyanogenmod.PowerMenu" />
<activity android:name=".profiles.NFCProfile"
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 607d76b..2a8ca1c 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1181,5 +1181,21 @@
<item>5</item>
</string-array>
+ <string-array name="lockscreen_long_key_press_entries" translatable="false">
+ <item>@string/lockscreen_buttons_no_action</item>
+ <item>@string/lockscreen_buttons_next</item>
+ <item>@string/lockscreen_buttons_previous</item>
+ <item>@string/lockscreen_buttons_playpause</item>
+ <item>@string/lockscreen_buttons_toggle_sound</item>
+ </string-array>
+
+ <string-array name="lockscreen_long_key_press_values" translatable="false">
+ <item></item>
+ <item>NEXT</item>
+ <item>PREVIOUS</item>
+ <item>PLAYPAUSE</item>
+ <item>SOUND</item>
+ </string-array>
+
<!-- **** CYANOGENMOD EDITS END **** -->
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0809434..3e65286 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4983,5 +4983,17 @@
<!-- Warning for Adb over Network -->
<string name="adb_over_network_warning">WARNING: When ADB over network is enabled, your phone is open for intrusions on all connected networks, including GSM data network!\n\nOnly use this feature when you are connected on trusted networks.\n\nDo you really want to enable this function?</string>
+ <string name="lockscreen_buttons_title">Button actions</string>
+ <string name="lockscreen_buttons_summary">View or change lock screen button actions</string>
+ <string name="lockscreen_long_press_back_title">Long press Back button</string>
+ <string name="lockscreen_long_press_home_title">Long press Home button</string>
+ <string name="lockscreen_long_press_menu_title">Long press Menu button</string>
+ <string name="lockscreen_buttons_no_action">No action</string>
+ <string name="lockscreen_buttons_flashlight">Flashlight</string>
+ <string name="lockscreen_buttons_next">Next song</string>
+ <string name="lockscreen_buttons_previous">Previous song</string>
+ <string name="lockscreen_buttons_playpause">Play/Pause music</string>
+ <string name="lockscreen_buttons_toggle_sound">Toggle sound</string>
+
<!-- **** CYANOGENMOD ADDITIONS END **** -->
</resources>
diff --git a/res/xml/lockscreen_buttons_settings.xml b/res/xml/lockscreen_buttons_settings.xml
new file mode 100644
index 0000000..3fa2548
--- /dev/null
+++ b/res/xml/lockscreen_buttons_settings.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
+ android:title="@string/lockscreen_buttons_title" >
+
+ <ListPreference android:key="lockscreen_long_press_back"
+ android:title="@string/lockscreen_long_press_back_title"
+ android:persistent="false"
+ android:entries="@array/lockscreen_long_key_press_entries"
+ android:entryValues="@array/lockscreen_long_key_press_values"/>
+
+ <ListPreference android:key="lockscreen_long_press_home"
+ android:title="@string/lockscreen_long_press_home_title"
+ android:persistent="false"
+ android:entries="@array/lockscreen_long_key_press_entries"
+ android:entryValues="@array/lockscreen_long_key_press_values"/>
+
+ <ListPreference android:key="lockscreen_long_press_menu"
+ android:title="@string/lockscreen_long_press_menu_title"
+ android:persistent="false"
+ android:entries="@array/lockscreen_long_key_press_entries"
+ android:entryValues="@array/lockscreen_long_key_press_values"/>
+
+</PreferenceScreen>
diff --git a/res/xml/lockscreen_interface_settings.xml b/res/xml/lockscreen_interface_settings.xml
index 6d6c7a2..a4f5365 100644
--- a/res/xml/lockscreen_interface_settings.xml
+++ b/res/xml/lockscreen_interface_settings.xml
@@ -31,4 +31,10 @@
android:summary="@string/lockscreen_target_summary"
android:title="@string/lockscreen_target_title" />
+ <PreferenceScreen
+ android:fragment="com.android.settings.cyanogenmod.LockscreenButtons"
+ android:key="lockscreen_buttons"
+ android:title="@string/lockscreen_buttons_title"
+ android:summary="@string/lockscreen_buttons_summary" />
+
</PreferenceScreen>
diff --git a/src/com/android/settings/cyanogenmod/LockscreenButtons.java b/src/com/android/settings/cyanogenmod/LockscreenButtons.java
new file mode 100644
index 0000000..3f840f8
--- /dev/null
+++ b/src/com/android/settings/cyanogenmod/LockscreenButtons.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2012 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 java.util.*;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceScreen;
+import android.provider.Settings;
+import android.text.TextUtils;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
+
+/**
+ * Lockscreen Buttons Settings
+ */
+public class LockscreenButtons extends SettingsPreferenceFragment
+ implements Preference.OnPreferenceChangeListener {
+
+ private static final String TAG = "LockscreenButtons";
+
+ private static final String LONG_PRESS_BACK = "lockscreen_long_press_back";
+ private static final String LONG_PRESS_HOME = "lockscreen_long_press_home";
+ private static final String LONG_PRESS_MENU = "lockscreen_long_press_menu";
+
+ // Masks for checking presence of hardware keys.
+ // Must match values in frameworks/base/core/res/res/values/config.xml
+ private static final int KEY_MASK_HOME = 0x01;
+ private static final int KEY_MASK_BACK = 0x02;
+ private static final int KEY_MASK_MENU = 0x04;
+
+ private ListPreference mLongBackAction;
+ private ListPreference mLongHomeAction;
+ private ListPreference mLongMenuAction;
+ private ListPreference[] mActions;
+
+ private boolean torchSupported() {
+ return getResources().getBoolean(R.bool.has_led_flash);
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final int deviceKeys = getResources().getInteger(
+ com.android.internal.R.integer.config_deviceHardwareKeys);
+ final boolean hasHomeKey = (deviceKeys & KEY_MASK_HOME) != 0;
+ final boolean hasBackKey = (deviceKeys & KEY_MASK_BACK) != 0;
+ final boolean hasMenuKey = (deviceKeys & KEY_MASK_MENU) != 0;
+
+ addPreferencesFromResource(R.xml.lockscreen_buttons_settings);
+
+ PreferenceScreen prefSet = getPreferenceScreen();
+
+ mLongBackAction = (ListPreference) prefSet.findPreference(LONG_PRESS_BACK);
+ if (hasBackKey) {
+ mLongBackAction.setKey(Settings.System.LOCKSCREEN_LONG_BACK_ACTION);
+ } else {
+ getPreferenceScreen().removePreference(mLongBackAction);
+ }
+
+ mLongHomeAction = (ListPreference) prefSet.findPreference(LONG_PRESS_HOME);
+ if (hasHomeKey) {
+ mLongHomeAction.setKey(Settings.System.LOCKSCREEN_LONG_HOME_ACTION);
+ } else {
+ getPreferenceScreen().removePreference(mLongHomeAction);
+ }
+
+ mLongMenuAction = (ListPreference) prefSet.findPreference(LONG_PRESS_MENU);
+ if (hasMenuKey) {
+ mLongMenuAction.setKey(Settings.System.LOCKSCREEN_LONG_MENU_ACTION);
+ } else {
+ getPreferenceScreen().removePreference(mLongMenuAction);
+ }
+
+ mActions = new ListPreference[] {
+ mLongBackAction, mLongHomeAction, mLongMenuAction
+ };
+ for (ListPreference pref : mActions) {
+ if (torchSupported()) {
+ final CharSequence[] oldEntries = pref.getEntries();
+ final CharSequence[] oldValues = pref.getEntryValues();
+ ArrayList<CharSequence> newEntries = new ArrayList<CharSequence>();
+ ArrayList<CharSequence> newValues = new ArrayList<CharSequence>();
+ for (int i = 0; i < oldEntries.length; i++) {
+ newEntries.add(oldEntries[i].toString());
+ newValues.add(oldValues[i].toString());
+ }
+ newEntries.add(getString(R.string.lockscreen_buttons_flashlight));
+ newValues.add("FLASHLIGHT");
+ pref.setEntries(
+ newEntries.toArray(new CharSequence[newEntries.size()]));
+ pref.setEntryValues(
+ newValues.toArray(new CharSequence[newValues.size()]));
+ }
+ pref.setOnPreferenceChangeListener(this);
+ }
+ }
+
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ for (ListPreference pref : mActions) {
+ updateEntry(pref);
+ }
+ }
+
+ private void updateEntry(ListPreference pref) {
+ String value = Settings.System.getString(getContentResolver(), pref.getKey());
+ if (value == null) {
+ value = "";
+ }
+
+ CharSequence entry = findEntryForValue(pref, value);
+ if (entry != null) {
+ pref.setValue(value);
+ pref.setSummary(entry);
+ return;
+ }
+ }
+
+ private CharSequence findEntryForValue(ListPreference pref, CharSequence value) {
+ CharSequence[] entries = pref.getEntryValues();
+ for (int i = 0; i < entries.length; i++) {
+ if (TextUtils.equals(entries[i], value)) {
+ return pref.getEntries()[i];
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference pref, Object newValue) {
+ /* we only have ListPreferences, so know newValue is a string */
+ ListPreference list = (ListPreference) pref;
+ String value = (String) newValue;
+
+ if (Settings.System.putString(getContentResolver(), list.getKey(), value)) {
+ pref.setSummary(findEntryForValue(list, value));
+ }
+
+ return true;
+ }
+
+}
diff --git a/src/com/android/settings/cyanogenmod/LockscreenInterface.java b/src/com/android/settings/cyanogenmod/LockscreenInterface.java
index 1a13e04..7df8699 100644
--- a/src/com/android/settings/cyanogenmod/LockscreenInterface.java
+++ b/src/com/android/settings/cyanogenmod/LockscreenInterface.java
@@ -25,6 +25,10 @@ import com.android.settings.SettingsPreferenceFragment;
public class LockscreenInterface extends SettingsPreferenceFragment {
private static final String TAG = "LockscreenInterface";
+ private static final String KEY_LOCKSCREEN_BUTTONS = "lockscreen_buttons";
+
+ private PreferenceScreen mLockscreenButtons;
+
public boolean hasButtons() {
return !getResources().getBoolean(com.android.internal.R.bool.config_showNavigationBar);
}
@@ -34,6 +38,11 @@ public class LockscreenInterface extends SettingsPreferenceFragment {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.lockscreen_interface_settings);
+
+ mLockscreenButtons = (PreferenceScreen) findPreference(KEY_LOCKSCREEN_BUTTONS);
+ if (!hasButtons()) {
+ getPreferenceScreen().removePreference(mLockscreenButtons);
+ }
}
@Override