diff options
author | masiullah <masiullah@gmail.com> | 2012-07-14 19:17:57 +0530 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2015-10-29 17:36:30 -0700 |
commit | 376cb194f5ecb8e26e80aa93d02236941d7aa369 (patch) | |
tree | f8094c3ff809b43919fc3d13fd4005491820cb7b | |
parent | 23ba4b7a4d7f852533c451e1cfbd9edca27477af (diff) | |
download | packages_apps_Settings-376cb194f5ecb8e26e80aa93d02236941d7aa369.zip packages_apps_Settings-376cb194f5ecb8e26e80aa93d02236941d7aa369.tar.gz packages_apps_Settings-376cb194f5ecb8e26e80aa93d02236941d7aa369.tar.bz2 |
Stylus gestures features (2/2)
*Forward-port to CM-12.0
Change-Id: I0ab78f1129d2d04b0af21e9b38da027dfe3d1295
-rw-r--r-- | res/values/cm_arrays.xml | 19 | ||||
-rw-r--r-- | res/values/cm_strings.xml | 25 | ||||
-rw-r--r-- | res/xml/gestures_prefs.xml | 74 | ||||
-rw-r--r-- | res/xml/language_settings.xml | 17 | ||||
-rw-r--r-- | src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java | 7 | ||||
-rw-r--r-- | src/com/android/settings/inputmethod/StylusGestures.java | 201 |
6 files changed, 337 insertions, 6 deletions
diff --git a/res/values/cm_arrays.xml b/res/values/cm_arrays.xml index 80b4ace..b6402a2 100644 --- a/res/values/cm_arrays.xml +++ b/res/values/cm_arrays.xml @@ -268,4 +268,23 @@ <item>Vivid</item> <item>Custom</item> </string-array> + + <!-- Stylus Gestures --> + <string-array name="gestures_entries" translatable="false"> + <item>@string/gestures_action_empty</item> + <item>@string/gestures_action_home</item> + <item>@string/gestures_action_back</item> + <item>@string/gestures_action_menu</item> + <item>@string/gestures_action_search</item> + <item>@string/gestures_action_recent</item> + </string-array> + + <string-array name="gestures_values" translatable="false"> + <item>1000</item> + <item>1001</item> + <item>1002</item> + <item>1003</item> + <item>1004</item> + <item>1005</item> + </string-array> </resources> diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index b982fd1..40e6d73 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -510,4 +510,29 @@ <!-- High touch sensitivity --> <string name="high_touch_sensitivity_title">High touch sensitivity</string> <string name="high_touch_sensitivity_summary">Increase touchscreen sensitivity so it can be used while wearing gloves</string> + + <!-- Stylus Gestures --> + <string name="gestures_settings_title">Stylus gestures</string> + <string name="category_spen_title">Stylus gestures</string> + <string name="enable_subcat_title">Stylus</string> + <string name="enable_spen_title_head">Enable gestures</string> + <string name="enable_spen_summary_head">Use swipe gestures by holding down the stylus button</string> + <string name="gestures_subcat_title">Gestures</string> + <string name="gestures_left_spen_title_head">Left swipe</string> + <string name="gestures_right_spen_title_head">Right swipe</string> + <string name="gestures_up_spen_title_head">Up swipe</string> + <string name="gestures_down_spen_title_head">Down swipe</string> + <string name="gestures_long_spen_title_head">Long press</string> + <string name="gestures_double_spen_title_head">Double tap</string> + + <!-- Gestures Options --> + <string name="gestures_action_empty">No action</string> + <string name="gestures_action_home">Home</string> + <string name="gestures_action_back">Back</string> + <string name="gestures_action_menu">Menu</string> + <string name="gestures_action_search">Invoke search</string> + <string name="gestures_action_recent">Recent apps</string> + + <!-- Stylus gestures --> + <string name="stylus_app_not_installed">%s is not installed</string> </resources> diff --git a/res/xml/gestures_prefs.xml b/res/xml/gestures_prefs.xml new file mode 100644 index 0000000..11c9441 --- /dev/null +++ b/res/xml/gestures_prefs.xml @@ -0,0 +1,74 @@ +<?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" > + + <PreferenceCategory android:title="@string/enable_subcat_title" > + + <!-- Enable --> + <com.android.settings.cyanogenmod.SystemSettingSwitchPreference + android:key="enable_stylus_gestures" + android:summary="@string/enable_spen_summary_head" + android:title="@string/enable_spen_title_head" /> + + </PreferenceCategory> + + <!-- Gesture Actions --> + <PreferenceCategory android:title="@string/gestures_subcat_title" > + <ListPreference + android:dependency="enable_stylus_gestures" + android:entries="@array/gestures_entries" + android:entryValues="@array/gestures_values" + android:key="gestures_left" + android:persistent="false" + android:title="@string/gestures_left_spen_title_head" /> + <ListPreference + android:dependency="enable_stylus_gestures" + android:entries="@array/gestures_entries" + android:entryValues="@array/gestures_values" + android:key="gestures_right" + android:persistent="false" + android:title="@string/gestures_right_spen_title_head" /> + <ListPreference + android:dependency="enable_stylus_gestures" + android:entries="@array/gestures_entries" + android:entryValues="@array/gestures_values" + android:key="gestures_up" + android:persistent="false" + android:title="@string/gestures_up_spen_title_head" /> + <ListPreference + android:dependency="enable_stylus_gestures" + android:entries="@array/gestures_entries" + android:entryValues="@array/gestures_values" + android:key="gestures_down" + android:persistent="false" + android:title="@string/gestures_down_spen_title_head" /> + <ListPreference + android:dependency="enable_stylus_gestures" + android:entries="@array/gestures_entries" + android:entryValues="@array/gestures_values" + android:key="gestures_long" + android:persistent="false" + android:title="@string/gestures_long_spen_title_head" /> + <ListPreference + android:dependency="enable_stylus_gestures" + android:entries="@array/gestures_entries" + android:entryValues="@array/gestures_values" + android:key="gestures_double" + android:persistent="false" + android:title="@string/gestures_double_spen_title_head" /> + </PreferenceCategory> + +</PreferenceScreen> diff --git a/res/xml/language_settings.xml b/res/xml/language_settings.xml index 0e299b7..c5936f2 100644 --- a/res/xml/language_settings.xml +++ b/res/xml/language_settings.xml @@ -87,6 +87,17 @@ android:dialogTitle="@string/pointer_speed" /> + <PreferenceScreen + android:fragment="com.android.settings.inputmethod.StylusGestures" + android:key="stylus_gestures" + android:title="@string/gestures_settings_title" /> + + <SwitchPreference + android:key="high_touch_sensitivity" + android:title="@string/high_touch_sensitivity_title" + android:summary="@string/high_touch_sensitivity_summary" + android:defaultValue="false" /> + <!-- Gesture pad settings --> <Preference android:key="gesture_pad_settings"> @@ -95,12 +106,6 @@ android:targetPackage="com.cyanogenmod.settings.device" android:targetClass="com.cyanogenmod.settings.device.GesturePadSettings" /> </Preference> - - <SwitchPreference - android:key="high_touch_sensitivity" - android:title="@string/high_touch_sensitivity_title" - android:summary="@string/high_touch_sensitivity_summary" - android:defaultValue="false" /> </PreferenceCategory> <PreferenceCategory diff --git a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java index 1d31874..6288fb2 100644 --- a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java +++ b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java @@ -89,6 +89,7 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment private static final String KEY_PREVIOUSLY_ENABLED_SUBTYPES = "previously_enabled_subtypes"; private static final String KEY_TRACKPAD_SETTINGS = "gesture_pad_settings"; private static final String KEY_HIGH_TOUCH_SENSITIVITY = "high_touch_sensitivity"; + private static final String KEY_STYLUS_GESTURES = "stylus_gestures"; // false: on ICS or later private static final boolean SHOW_INPUT_METHOD_SWITCHER_SETTINGS = false; @@ -99,6 +100,7 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment private PreferenceCategory mHardKeyboardCategory; private PreferenceCategory mGameControllerCategory; private Preference mLanguagePref; + private PreferenceScreen mStylusGestures; private final ArrayList<InputMethodPreference> mInputMethodPreferenceList = new ArrayList<>(); private final ArrayList<PreferenceScreen> mHardKeyboardPreferenceList = new ArrayList<>(); private InputManager mIm; @@ -175,9 +177,14 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment PreferenceCategory pointerSettingsCategory = (PreferenceCategory) findPreference(KEY_POINTER_SETTINGS_CATEGORY); + mStylusGestures = (PreferenceScreen) findPreference(KEY_STYLUS_GESTURES); mHighTouchSensitivity = (SwitchPreference) findPreference(KEY_HIGH_TOUCH_SENSITIVITY); if (pointerSettingsCategory != null) { + if (!getResources().getBoolean(com.android.internal.R.bool.config_stylusGestures)) { + pointerSettingsCategory.removePreference(mStylusGestures); + } + if (!isHighTouchSensitivitySupported()) { pointerSettingsCategory.removePreference(mHighTouchSensitivity); mHighTouchSensitivity = null; diff --git a/src/com/android/settings/inputmethod/StylusGestures.java b/src/com/android/settings/inputmethod/StylusGestures.java new file mode 100644 index 0000000..5661adc --- /dev/null +++ b/src/com/android/settings/inputmethod/StylusGestures.java @@ -0,0 +1,201 @@ +/* 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.inputmethod; + +import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.ResolveInfo; +import android.content.res.Resources; +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.PreferenceScreen; +import android.provider.Settings; + +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; + +import java.util.Collections; +import java.util.List; + +public class StylusGestures extends SettingsPreferenceFragment implements + Preference.OnPreferenceChangeListener { + + public static final String TAG = "Stylus Gestures"; + public static final String KEY_SPEN_LEFT = "gestures_left"; + public static final String KEY_SPEN_RIGHT = "gestures_right"; + public static final String KEY_SPEN_UP = "gestures_up"; + public static final String KEY_SPEN_DOWN = "gestures_down"; + public static final String KEY_SPEN_LONG = "gestures_long"; + public static final String KEY_SPEN_DOUBLE = "gestures_double"; + public static final int KEY_NO_ACTION = 1000; + public static final String TEXT_NO_ACTION = "No Action"; + + private ListPreference mSwipeLeft; + private ListPreference mSwipeRight; + private ListPreference mSwipeUp; + private ListPreference mSwipeDown; + private ListPreference mSwipeLong; + private ListPreference mSwipeDouble; + + private Context mContext; + private ContentResolver mResolver; + + private String[] mActionNames; + private String[] mActionValues; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.gestures_prefs); + mContext = getActivity(); + mResolver = getContentResolver(); + + Resources resources = mContext.getResources(); + mActionNames = resources.getStringArray(R.array.gestures_entries); + mActionValues = resources.getStringArray(R.array.gestures_values); + + // Setup the gestures + mSwipeLeft = setupGesturePref(KEY_SPEN_LEFT, Settings.System.GESTURES_LEFT_SWIPE); + mSwipeRight = setupGesturePref(KEY_SPEN_RIGHT, Settings.System.GESTURES_RIGHT_SWIPE); + mSwipeUp = setupGesturePref(KEY_SPEN_UP, Settings.System.GESTURES_UP_SWIPE); + mSwipeDown = setupGesturePref(KEY_SPEN_DOWN, Settings.System.GESTURES_DOWN_SWIPE); + mSwipeLong = setupGesturePref(KEY_SPEN_LONG, Settings.System.GESTURES_LONG_PRESS); + mSwipeDouble = setupGesturePref(KEY_SPEN_DOUBLE, Settings.System.GESTURES_DOUBLE_TAP); + } + + private ListPreference setupGesturePref(String key, String settingName) { + ListPreference pref = (ListPreference) findPreference(key); + String setting = Settings.System.getString(mResolver, settingName); + addApplicationEntries(pref, setting); + pref.setOnPreferenceChangeListener(this); + return pref; + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + String settingName = null; + + if (preference == mSwipeLeft) { + settingName = Settings.System.GESTURES_LEFT_SWIPE; + } else if (preference == mSwipeRight) { + settingName = Settings.System.GESTURES_RIGHT_SWIPE; + } else if (preference == mSwipeUp) { + settingName = Settings.System.GESTURES_UP_SWIPE; + } else if (preference == mSwipeDown) { + settingName = Settings.System.GESTURES_DOWN_SWIPE; + } else if (preference == mSwipeLong) { + settingName = Settings.System.GESTURES_LONG_PRESS; + } else if (preference == mSwipeDouble) { + settingName = Settings.System.GESTURES_DOUBLE_TAP; + } else { + return false; + } + + String packageName = newValue.toString(); + Settings.System.putString(mResolver, settingName, packageName); + setPrefValue((ListPreference)preference, packageName); + return true; + } + + private String mapUpdateValue(String time) { + for (int i = 0; i < mActionValues.length; i++) { + if (mActionValues[i].equalsIgnoreCase(time)) { + return mActionNames[i]; + } + } + return null; + } + + private void setPrefValue(ListPreference pref, String packageName) { + if (packageName == null) { + packageName = String.valueOf(KEY_NO_ACTION); + } + + String text = mapUpdateValue(packageName); + if (text != null) { + pref.setValue(packageName); + pref.setSummary(text); + } else { + CharSequence appName = getAppName(packageName); + if (appName != null) { + pref.setValue(packageName); + pref.setSummary(appName); + } else { + pref.setSummary(mContext.getString(R.string.stylus_app_not_installed, + packageName)); + } + } + + } + + private void addApplicationEntries(ListPreference pref, String packageName) { + PackageManager pm = getPackageManager(); + + Intent intent = new Intent(Intent.ACTION_MAIN, null); + intent.addCategory(Intent.CATEGORY_LAUNCHER); + List<ResolveInfo> list = pm.queryIntentActivities(intent, + PackageManager.PERMISSION_GRANTED); + + Collections.sort(list, new ResolveInfo.DisplayNameComparator(pm)); + + int count = list.size() + mActionValues.length; + CharSequence[] entries = new CharSequence[count]; + CharSequence[] values = new CharSequence[count]; + + // Step 1: copy in predefined actions + for (int i = 0; i < mActionValues.length; i++) { + entries[i] = mActionNames[i]; + values[i] = mActionValues[i]; + } + + // Step 2: copy in resolved activities + for (int i = mActionValues.length; i < count; i++) { + ResolveInfo info = list.get(i - mActionValues.length); + CharSequence label = info.loadLabel(pm); + if (label == null) { + label = info.activityInfo.name; + } + + entries[i] = label; + values[i] = info.activityInfo.applicationInfo.packageName; + } + + pref.setEntries(entries); + pref.setEntryValues(values); + setPrefValue(pref, packageName); + } + + private CharSequence getAppName(String packageName) { + final PackageManager pm = mContext.getPackageManager(); + ApplicationInfo ai; + + try { + ai = pm.getApplicationInfo(packageName, 0); + } catch (final NameNotFoundException e) { + ai = null; + } + + if (ai != null) { + return pm.getApplicationLabel(ai); + } + return null; + } +} |