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
This commit is contained in:
BIN
res/drawable-hdpi/ic_sysbar_quicksettings.png
Normal file
BIN
res/drawable-hdpi/ic_sysbar_quicksettings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 773 B |
BIN
res/drawable-mdpi/ic_sysbar_quicksettings.png
Normal file
BIN
res/drawable-mdpi/ic_sysbar_quicksettings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 653 B |
50
res/layout/preference_settings_checkbox_widget.xml
Normal file
50
res/layout/preference_settings_checkbox_widget.xml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 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.
|
||||||
|
-->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingRight="?android:attr/scrollbarSize">
|
||||||
|
|
||||||
|
<!-- Settings button -->
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/settings_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:padding="8dip"
|
||||||
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
android:src="@drawable/ic_sysbar_quicksettings"
|
||||||
|
android:contentDescription="@string/settings_button" />
|
||||||
|
|
||||||
|
<!-- Divider -->
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/divider"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:src="@drawable/nav_divider" />
|
||||||
|
|
||||||
|
<!-- CheckBox -->
|
||||||
|
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+android:id/checkbox"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:focusable="false"
|
||||||
|
android:clickable="false" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@@ -2609,6 +2609,9 @@ found in the list of installed applications.</string>
|
|||||||
<!-- Accessibility settings: power button behavior summary text -->
|
<!-- Accessibility settings: power button behavior summary text -->
|
||||||
<string name="accessibility_power_button_ends_call_summary">During a call, pressing Power ends call instead of turning off screen</string>
|
<string name="accessibility_power_button_ends_call_summary">During a call, pressing Power ends call instead of turning off screen</string>
|
||||||
|
|
||||||
|
<!-- Accessibility settings: button for lauching settings for an accessibility service -->
|
||||||
|
<string name="settings_button">Settings</string>
|
||||||
|
|
||||||
<!-- Setting interaction category [CHAR LIMIT=35] -->
|
<!-- Setting interaction category [CHAR LIMIT=35] -->
|
||||||
<string name="touchscreen_gestures_category">Touchscreen gestures</string>
|
<string name="touchscreen_gestures_category">Touchscreen gestures</string>
|
||||||
<!-- Title for setting the long-press timeout [CHAR LIMIT=35] -->
|
<!-- Title for setting the long-press timeout [CHAR LIMIT=35] -->
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
@@ -78,7 +79,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
private CheckBoxPreference mToggleAccessibilityCheckBox;
|
private CheckBoxPreference mToggleAccessibilityCheckBox;
|
||||||
private CheckBoxPreference mToggleScriptInjectionCheckBox;
|
private CheckBoxPreference mToggleScriptInjectionCheckBox;
|
||||||
private CheckBoxPreference mToggleAccessibilityServiceCheckBox;
|
private SettingsCheckBoxPreference mToggleAccessibilityServiceCheckBox;
|
||||||
|
|
||||||
private PreferenceCategory mPowerButtonCategory;
|
private PreferenceCategory mPowerButtonCategory;
|
||||||
private CheckBoxPreference mPowerButtonEndsCallCheckBox;
|
private CheckBoxPreference mPowerButtonEndsCallCheckBox;
|
||||||
@@ -87,8 +88,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
private ListPreference mLongPressTimeoutListPreference;
|
private ListPreference mLongPressTimeoutListPreference;
|
||||||
|
|
||||||
private Map<String, ServiceInfo> mAccessibilityServices =
|
private Map<String, AccessibilityServiceInfo> mAccessibilityServices =
|
||||||
new LinkedHashMap<String, ServiceInfo>();
|
new LinkedHashMap<String, AccessibilityServiceInfo>();
|
||||||
|
|
||||||
private TextUtils.SimpleStringSplitter mStringColonSplitter =
|
private TextUtils.SimpleStringSplitter mStringColonSplitter =
|
||||||
new TextUtils.SimpleStringSplitter(':');
|
new TextUtils.SimpleStringSplitter(':');
|
||||||
@@ -157,7 +158,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, ServiceInfo> accessibilityServices = mAccessibilityServices;
|
Map<String, AccessibilityServiceInfo> accessibilityServices = mAccessibilityServices;
|
||||||
|
|
||||||
for (String key : accessibilityServices.keySet()) {
|
for (String key : accessibilityServices.keySet()) {
|
||||||
CheckBoxPreference preference = (CheckBoxPreference) findPreference(key);
|
CheckBoxPreference preference = (CheckBoxPreference) findPreference(key);
|
||||||
@@ -230,9 +231,9 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
KEY_TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX
|
KEY_TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX
|
||||||
+ " must be mapped to an instance of a "
|
+ " 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)) {
|
} else if (TOGGLE_ACCESSIBILITY_SCRIPT_INJECTION_CHECKBOX.equals(key)) {
|
||||||
handleToggleAccessibilityScriptInjection((CheckBoxPreference) preference);
|
handleToggleAccessibilityScriptInjection((CheckBoxPreference) preference);
|
||||||
} else if (preference instanceof CheckBoxPreference) {
|
} else if (preference instanceof CheckBoxPreference) {
|
||||||
handleEnableAccessibilityServiceStateChange((CheckBoxPreference) preference);
|
handleEnableAccessibilityServiceStateChange((SettingsCheckBoxPreference) preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||||
@@ -318,7 +319,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
*
|
*
|
||||||
* @param preference The preference.
|
* @param preference The preference.
|
||||||
*/
|
*/
|
||||||
private void handleEnableAccessibilityServiceStateChange(CheckBoxPreference preference) {
|
private void handleEnableAccessibilityServiceStateChange(
|
||||||
|
SettingsCheckBoxPreference preference) {
|
||||||
if (preference.isChecked()) {
|
if (preference.isChecked()) {
|
||||||
mToggleAccessibilityServiceCheckBox = preference;
|
mToggleAccessibilityServiceCheckBox = preference;
|
||||||
// set right enabled state since the user may press back
|
// set right enabled state since the user may press back
|
||||||
@@ -357,7 +359,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
AccessibilityManager accessibilityManager =
|
AccessibilityManager accessibilityManager =
|
||||||
(AccessibilityManager) getSystemService(Service.ACCESSIBILITY_SERVICE);
|
(AccessibilityManager) getSystemService(Service.ACCESSIBILITY_SERVICE);
|
||||||
|
|
||||||
List<ServiceInfo> installedServices = accessibilityManager.getAccessibilityServiceList();
|
List<AccessibilityServiceInfo> installedServices =
|
||||||
|
accessibilityManager.getInstalledAccessibilityServiceList();
|
||||||
|
|
||||||
if (installedServices.isEmpty()) {
|
if (installedServices.isEmpty()) {
|
||||||
getPreferenceScreen().removePreference(mAccessibilityServicesCategory);
|
getPreferenceScreen().removePreference(mAccessibilityServicesCategory);
|
||||||
@@ -367,12 +370,22 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
getPreferenceScreen().addPreference(mAccessibilityServicesCategory);
|
getPreferenceScreen().addPreference(mAccessibilityServicesCategory);
|
||||||
|
|
||||||
for (int i = 0, count = installedServices.size(); i < count; ++i) {
|
for (int i = 0, count = installedServices.size(); i < count; ++i) {
|
||||||
ServiceInfo serviceInfo = installedServices.get(i);
|
AccessibilityServiceInfo accessibilityServiceInfo = installedServices.get(i);
|
||||||
String key = serviceInfo.packageName + "/" + serviceInfo.name;
|
String key = accessibilityServiceInfo.getId();
|
||||||
|
|
||||||
if (mAccessibilityServices.put(key, serviceInfo) == null) {
|
if (mAccessibilityServices.put(key, accessibilityServiceInfo) == null) {
|
||||||
CheckBoxPreference preference = new CheckBoxPreference(getActivity());
|
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);
|
preference.setKey(key);
|
||||||
|
ServiceInfo serviceInfo = accessibilityServiceInfo.getResolveInfo().serviceInfo;
|
||||||
preference.setTitle(serviceInfo.loadLabel(getActivity().getPackageManager()));
|
preference.setTitle(serviceInfo.loadLabel(getActivity().getPackageManager()));
|
||||||
mAccessibilityServicesCategory.addPreference(preference);
|
mAccessibilityServicesCategory.addPreference(preference);
|
||||||
}
|
}
|
||||||
@@ -424,7 +437,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
.setMessage(getResources().getString(
|
.setMessage(getResources().getString(
|
||||||
R.string.accessibility_service_security_warning,
|
R.string.accessibility_service_security_warning,
|
||||||
mAccessibilityServices.get(mToggleAccessibilityServiceCheckBox.getKey())
|
mAccessibilityServices.get(mToggleAccessibilityServiceCheckBox.getKey())
|
||||||
.applicationInfo.loadLabel(getActivity().getPackageManager())))
|
.getResolveInfo().serviceInfo.applicationInfo.loadLabel(
|
||||||
|
getActivity().getPackageManager())))
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton(android.R.string.ok,
|
.setPositiveButton(android.R.string.ok,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
|
91
src/com/android/settings/SettingsCheckBoxPreference.java
Normal file
91
src/com/android/settings/SettingsCheckBoxPreference.java
Normal file
@@ -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 <code>null</code> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user