From 6f0b4d8143858e41cede1f935230e2a430b9fd2d Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Thu, 26 May 2011 16:45:43 -0700 Subject: [PATCH] Accessibility service specific settings. This is the settings part of the change for adding support for accessibility service specific settings. 1. Added the first cut of a SettingsCheckBoxPreference that is a CheckBoxPreference that optionally takes an intent to be lauched as settings of the item represented by the preference. 2. Updated the AccessibilitySettigns to use the SettingsCheckBoxPreference. Change-Id: If44262b8965c65620c6b8c252f8ef356eb0d95cf --- res/drawable-hdpi/ic_sysbar_quicksettings.png | Bin 0 -> 773 bytes res/drawable-mdpi/ic_sysbar_quicksettings.png | Bin 0 -> 653 bytes .../preference_settings_checkbox_widget.xml | 50 ++++++++++ res/values/strings.xml | 3 + .../settings/AccessibilitySettings.java | 42 +++++--- .../settings/SettingsCheckBoxPreference.java | 91 ++++++++++++++++++ 6 files changed, 172 insertions(+), 14 deletions(-) create mode 100644 res/drawable-hdpi/ic_sysbar_quicksettings.png create mode 100644 res/drawable-mdpi/ic_sysbar_quicksettings.png create mode 100644 res/layout/preference_settings_checkbox_widget.xml create mode 100644 src/com/android/settings/SettingsCheckBoxPreference.java diff --git a/res/drawable-hdpi/ic_sysbar_quicksettings.png b/res/drawable-hdpi/ic_sysbar_quicksettings.png new file mode 100644 index 0000000000000000000000000000000000000000..47b4ba23f7a547b327d6a0dd592b7e188ebbc28e GIT binary patch literal 773 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}a}trX+877l!}s{b%+Ad7K3vk;M!Q z+(IDCcKfnz$52J2-w_pT?Lfr0U*r;B4q#NoHoPX`_f5NX@bofvVVP4GC| z7KW@1jXALwn8FenZ#8jm-_Dr5fFbul;X$XE1g7Jzaw>}7C$hM=KfM3s+}YZ{&tvw< zJXo@ST9&bAdhu_K7G5TSYkj;{vbuiJS~njh@HuF=aOdrOGB@2WU}0i+nPLz}a@-6d z;SCSkmS%RxX*1U*9GhYqea&a)(ppom;svvRzGO^ZaJ)ey`}N&7PM0q89y-L`FL1SY z@-G2VS&efxwk$f|f4NzmJO95mL}r12+a4peq8ufjh{AKrE^KGKCn3nlJT2z)%-FkS zo_Pz-G%{$f+v6Ov&$RYIS5n8P8nMYbYyS8xWjCF>+F+B#g_Db`{&D4U{rw%(yKbf5 zG{HqRjyE6rs+w9~Eh5bxg@rR91+HDcsW|5jSajsdJ zWn{}#v%H|c{9-pVAM;J@cJ#6_vSo@>AX=TBoO^Xy-av zuhcT*-E?u8XKYGR;K5&Y0&jpaUk|Qae)ixiCFWee(un8e~8=1m~xflqVLYGB~E>C#5R5WfrBD=NDxcD>w(67H)lP Q22{u3>FVdQ&MBb@03|y(X#fBK literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/ic_sysbar_quicksettings.png b/res/drawable-mdpi/ic_sysbar_quicksettings.png new file mode 100644 index 0000000000000000000000000000000000000000..792810427f92d8521d94cdb350b6c2db23830bb9 GIT binary patch literal 653 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE0wix1Z>k4UOiAAEE)4(M`_JqL@;D1TB8wRq zxP?HN@zUM8KOn)f0>^Y9tpLXDzvj$kU|=ltba4#vIR5miVcr!73DyVsYGF!>LSY@; z46?kpnyP;YTnM}za5ssN_o#(9XM_QF;bw==?JKXo=N^(=!({Aw}ua>UW zP)z+%$=j6j@D7vq`86$8ye1i+=CBJV985d#;Y8wOmF&)_R)xwZyIW0|Je%a>cCuX; z+gI5%b$M7*Na^~>>c=Zqd}-tkpL^rt)a!CyX4iHW$Mc@EIp%+UxygeB_Gz~LcdtC? z&s~1_m{{oKC4W{--p0+HJ&{PDEQg`{J89$4U6s{l{r&cH=E6pJ@x$Yn+6k`H$8ux z^QGGBcfyOGf8R9kd;b5qoy4`f-y9nc{;|8k%+yynarrK8hwE~?HTwVc{x-gmntbAc zzTw2%`wEveF9F7aXo+h?iE~kEVo7Fxo&k%&R6z<-5=&C8 zl0m9c8H@}J4Rs9+bqy^-3@xop%&iPfbqy@63=F!Tb$mt9kei>9nO2Eg!>`>2o + + + + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 064700ffed7..3a0968545e1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2609,6 +2609,9 @@ found in the list of installed applications. During a call, pressing Power ends call instead of turning off screen + + Settings + Touchscreen gestures diff --git a/src/com/android/settings/AccessibilitySettings.java b/src/com/android/settings/AccessibilitySettings.java index 826410d2788..9a0db5d7774 100644 --- a/src/com/android/settings/AccessibilitySettings.java +++ b/src/com/android/settings/AccessibilitySettings.java @@ -16,6 +16,7 @@ package com.android.settings; +import android.accessibilityservice.AccessibilityServiceInfo; import android.app.AlertDialog; import android.app.Dialog; import android.app.Service; @@ -78,7 +79,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements private CheckBoxPreference mToggleAccessibilityCheckBox; private CheckBoxPreference mToggleScriptInjectionCheckBox; - private CheckBoxPreference mToggleAccessibilityServiceCheckBox; + private SettingsCheckBoxPreference mToggleAccessibilityServiceCheckBox; private PreferenceCategory mPowerButtonCategory; private CheckBoxPreference mPowerButtonEndsCallCheckBox; @@ -87,8 +88,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements private ListPreference mLongPressTimeoutListPreference; - private Map mAccessibilityServices = - new LinkedHashMap(); + private Map mAccessibilityServices = + new LinkedHashMap(); private TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':'); @@ -157,7 +158,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements } } - Map accessibilityServices = mAccessibilityServices; + Map accessibilityServices = mAccessibilityServices; for (String key : accessibilityServices.keySet()) { CheckBoxPreference preference = (CheckBoxPreference) findPreference(key); @@ -230,9 +231,9 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements throw new IllegalArgumentException( KEY_TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX + " must be mapped to an instance of a " - + CheckBoxPreference.class.getName()); + + SettingsCheckBoxPreference.class.getName()); } - mToggleAccessibilityServiceCheckBox = (CheckBoxPreference) preference; + mToggleAccessibilityServiceCheckBox = (SettingsCheckBoxPreference) preference; } } @@ -274,7 +275,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements } else if (TOGGLE_ACCESSIBILITY_SCRIPT_INJECTION_CHECKBOX.equals(key)) { handleToggleAccessibilityScriptInjection((CheckBoxPreference) preference); } else if (preference instanceof CheckBoxPreference) { - handleEnableAccessibilityServiceStateChange((CheckBoxPreference) preference); + handleEnableAccessibilityServiceStateChange((SettingsCheckBoxPreference) preference); } return super.onPreferenceTreeClick(preferenceScreen, preference); @@ -318,7 +319,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements * * @param preference The preference. */ - private void handleEnableAccessibilityServiceStateChange(CheckBoxPreference preference) { + private void handleEnableAccessibilityServiceStateChange( + SettingsCheckBoxPreference preference) { if (preference.isChecked()) { mToggleAccessibilityServiceCheckBox = preference; // set right enabled state since the user may press back @@ -357,7 +359,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements AccessibilityManager accessibilityManager = (AccessibilityManager) getSystemService(Service.ACCESSIBILITY_SERVICE); - List installedServices = accessibilityManager.getAccessibilityServiceList(); + List installedServices = + accessibilityManager.getInstalledAccessibilityServiceList(); if (installedServices.isEmpty()) { getPreferenceScreen().removePreference(mAccessibilityServicesCategory); @@ -367,12 +370,22 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements getPreferenceScreen().addPreference(mAccessibilityServicesCategory); for (int i = 0, count = installedServices.size(); i < count; ++i) { - ServiceInfo serviceInfo = installedServices.get(i); - String key = serviceInfo.packageName + "/" + serviceInfo.name; + AccessibilityServiceInfo accessibilityServiceInfo = installedServices.get(i); + String key = accessibilityServiceInfo.getId(); - if (mAccessibilityServices.put(key, serviceInfo) == null) { - CheckBoxPreference preference = new CheckBoxPreference(getActivity()); + if (mAccessibilityServices.put(key, accessibilityServiceInfo) == null) { + String settingsActivityName = accessibilityServiceInfo.getSettingsActivityName(); + Intent settingsIntent = null; + if (!TextUtils.isEmpty(settingsActivityName)) { + String packageName = accessibilityServiceInfo.getResolveInfo() + .serviceInfo.packageName; + settingsIntent = new Intent(Intent.ACTION_MAIN); + settingsIntent.setClassName(packageName, settingsActivityName); + } + SettingsCheckBoxPreference preference = new SettingsCheckBoxPreference( + getActivity(), settingsIntent); preference.setKey(key); + ServiceInfo serviceInfo = accessibilityServiceInfo.getResolveInfo().serviceInfo; preference.setTitle(serviceInfo.loadLabel(getActivity().getPackageManager())); mAccessibilityServicesCategory.addPreference(preference); } @@ -424,7 +437,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements .setMessage(getResources().getString( R.string.accessibility_service_security_warning, mAccessibilityServices.get(mToggleAccessibilityServiceCheckBox.getKey()) - .applicationInfo.loadLabel(getActivity().getPackageManager()))) + .getResolveInfo().serviceInfo.applicationInfo.loadLabel( + getActivity().getPackageManager()))) .setCancelable(true) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { diff --git a/src/com/android/settings/SettingsCheckBoxPreference.java b/src/com/android/settings/SettingsCheckBoxPreference.java new file mode 100644 index 00000000000..6acdfe8df56 --- /dev/null +++ b/src/com/android/settings/SettingsCheckBoxPreference.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2011 The Android Open Source 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; + +import android.content.Context; +import android.content.Intent; +import android.preference.CheckBoxPreference; +import android.util.TypedValue; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.CheckBox; +import android.widget.ImageView; + +/** + * CheckBox preference that optionally shows an icon for launching a settings + * {@link android.app.Activity}. The settings activity, if intent for launching + * it was provided, can be stared only if the CheckBox in is checked. + */ +public class SettingsCheckBoxPreference extends CheckBoxPreference { + + // Integer.MIN_VALUE means not initalized + private static int sDimAlpha = Integer.MIN_VALUE; + + private final Intent mSettingsIntent; + + /** + * Creates a new instance. + * + * @param context Context for accessing resources. + * @param settingsIntent Intent to use as settings for the item represented by + * this preference. Pass null if there is no associated + * settings activity. + */ + public SettingsCheckBoxPreference(Context context, Intent settingsIntent) { + super(context); + + if (sDimAlpha == Integer.MIN_VALUE) { + TypedValue outValue = new TypedValue(); + context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true); + sDimAlpha = (int) (outValue.getFloat() * 255); + } + + mSettingsIntent = settingsIntent; + setWidgetLayoutResource(R.layout.preference_settings_checkbox_widget); + } + + @Override + protected void onBindView(View view) { + super.onBindView(view); + + ImageView settingsButton = (ImageView) view.findViewById(R.id.settings_button); + if (settingsButton == null) { + return; + } + if (mSettingsIntent != null) { + CheckBox checkbox = (CheckBox) view.findViewById(com.android.internal.R.id.checkbox); + if (checkbox == null) { + return; + } + if (checkbox.isChecked()) { + settingsButton.setOnClickListener(new OnClickListener() { + public void onClick(View view) { + getContext().startActivity(mSettingsIntent); + } + }); + } + settingsButton.setVisibility(View.VISIBLE); + if (checkbox.isChecked() && isEnabled()) { + settingsButton.setAlpha(255); + } else { + settingsButton.setAlpha(sDimAlpha); + } + } else { + settingsButton.setVisibility(View.GONE); + } + } +}