Accessibility shortcut primary action - implement launched type fragment.
Bug: 142531433 Test: make RunSettingsRoboTests Change-Id: I444bcc921b2a05483e508934c6f0b90b2cc53421
This commit is contained in:
@@ -4994,6 +4994,8 @@
|
|||||||
<string name="accessibility_touch_vibration_title">Touch feedback</string>
|
<string name="accessibility_touch_vibration_title">Touch feedback</string>
|
||||||
<!-- Used in the accessibility service settings to control turning on/off the service entirely -->
|
<!-- Used in the accessibility service settings to control turning on/off the service entirely -->
|
||||||
<string name="accessibility_service_master_switch_title">Use <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g></string>
|
<string name="accessibility_service_master_switch_title">Use <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g></string>
|
||||||
|
<!-- Used in the accessibility service settings to open the activity. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="accessibility_service_master_open_title">Open <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g></string>
|
||||||
<!-- Used in the Color correction settings screen to control turning on/off the feature entirely -->
|
<!-- Used in the Color correction settings screen to control turning on/off the feature entirely -->
|
||||||
<string name="accessibility_daltonizer_master_switch_title">Use color correction</string>
|
<string name="accessibility_daltonizer_master_switch_title">Use color correction</string>
|
||||||
<!-- Used in the Captions settings screen to control turning on/off the feature entirely -->
|
<!-- Used in the Captions settings screen to control turning on/off the feature entirely -->
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
@@ -29,11 +30,25 @@ public final class DividerSwitchPreference extends SwitchPreference {
|
|||||||
|
|
||||||
private Boolean mDividerAllowedAbove;
|
private Boolean mDividerAllowedAbove;
|
||||||
private Boolean mDividerAllowBelow;
|
private Boolean mDividerAllowBelow;
|
||||||
|
private int mSwitchVisibility;
|
||||||
|
|
||||||
public DividerSwitchPreference(Context context) {
|
public DividerSwitchPreference(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
mDividerAllowedAbove = true;
|
mDividerAllowedAbove = true;
|
||||||
mDividerAllowBelow = true;
|
mDividerAllowBelow = true;
|
||||||
|
mSwitchVisibility = View.VISIBLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
|
super.onBindViewHolder(holder);
|
||||||
|
holder.setDividerAllowedAbove(mDividerAllowedAbove);
|
||||||
|
holder.setDividerAllowedBelow(mDividerAllowBelow);
|
||||||
|
|
||||||
|
final View switchView = holder.itemView.findViewById(android.R.id.widget_frame);
|
||||||
|
if (switchView != null) {
|
||||||
|
switchView.setVisibility(mSwitchVisibility);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,10 +75,15 @@ public final class DividerSwitchPreference extends SwitchPreference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
* Sets the visibility state of Settings view.
|
||||||
super.onBindViewHolder(holder);
|
*
|
||||||
holder.setDividerAllowedAbove(mDividerAllowedAbove);
|
* @param visibility one of {@link View#VISIBLE}, {@link View#INVISIBLE}, or {@link View#GONE}.
|
||||||
holder.setDividerAllowedBelow(mDividerAllowBelow);
|
*/
|
||||||
|
public void setSwitchVisibility(@View.Visibility int visibility) {
|
||||||
|
if (mSwitchVisibility != visibility) {
|
||||||
|
mSwitchVisibility = visibility;
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,12 +16,119 @@
|
|||||||
|
|
||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
|
import android.accessibilityservice.AccessibilityShortcutInfo;
|
||||||
|
import android.app.ActivityOptions;
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** Fragment for providing open activity button. */
|
/** Fragment for providing open activity button. */
|
||||||
public class LaunchAccessibilityActivityPreferenceFragment extends
|
public class LaunchAccessibilityActivityPreferenceFragment extends
|
||||||
ToggleFeaturePreferenceFragment {
|
ToggleFeaturePreferenceFragment {
|
||||||
|
private static final String TAG = "LaunchA11yActivity";
|
||||||
|
private static final String EMPTY_STRING = "";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
mToggleServiceDividerSwitchPreference.setSwitchVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||||
// TODO(b/142531433): Added in next CL.
|
launchShortcutTargetActivity(getPrefContext().getDisplayId(), mComponentName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onInstallSwitchPreferenceToggleSwitch() {
|
||||||
|
super.onInstallSwitchPreferenceToggleSwitch();
|
||||||
|
mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener((preference) -> {
|
||||||
|
final boolean checked = ((DividerSwitchPreference) preference).isChecked();
|
||||||
|
onPreferenceToggled(mPreferenceKey, checked);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProcessArguments(Bundle arguments) {
|
||||||
|
super.onProcessArguments(arguments);
|
||||||
|
|
||||||
|
mComponentName = arguments.getParcelable(AccessibilitySettings.EXTRA_COMPONENT_NAME);
|
||||||
|
final ActivityInfo info = getAccessibilityShortcutInfo().getActivityInfo();
|
||||||
|
mPackageName = info.loadLabel(getPackageManager()).toString();
|
||||||
|
|
||||||
|
// Settings animated image.
|
||||||
|
final int animatedImageRes = arguments.getInt(
|
||||||
|
AccessibilitySettings.EXTRA_ANIMATED_IMAGE_RES);
|
||||||
|
mImageUri = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
|
||||||
|
.authority(mComponentName.getPackageName())
|
||||||
|
.appendPath(String.valueOf(animatedImageRes))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// Settings html description.
|
||||||
|
mHtmlDescription = arguments.getCharSequence(AccessibilitySettings.EXTRA_HTML_DESCRIPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSettingsClicked(ShortcutPreference preference) {
|
||||||
|
super.onSettingsClicked(preference);
|
||||||
|
showDialog(DialogEnums.EDIT_SHORTCUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
|
||||||
|
final AccessibilityShortcutInfo info = getAccessibilityShortcutInfo();
|
||||||
|
final String switchBarText = (info == null) ? EMPTY_STRING : getString(
|
||||||
|
R.string.accessibility_service_master_open_title,
|
||||||
|
info.getActivityInfo().loadLabel(getPackageManager()));
|
||||||
|
|
||||||
|
switchPreference.setTitle(switchBarText);
|
||||||
|
}
|
||||||
|
|
||||||
|
// IMPORTANT: Refresh the info since there are dynamically changing capabilities.
|
||||||
|
private AccessibilityShortcutInfo getAccessibilityShortcutInfo() {
|
||||||
|
final List<AccessibilityShortcutInfo> infos = AccessibilityManager.getInstance(
|
||||||
|
getPrefContext()).getInstalledAccessibilityShortcutListAsUser(getPrefContext(),
|
||||||
|
UserHandle.myUserId());
|
||||||
|
|
||||||
|
for (int i = 0, count = infos.size(); i < count; i++) {
|
||||||
|
AccessibilityShortcutInfo shortcutInfo = infos.get(i);
|
||||||
|
ActivityInfo activityInfo = shortcutInfo.getActivityInfo();
|
||||||
|
if (mComponentName.getPackageName().equals(activityInfo.packageName)
|
||||||
|
&& mComponentName.getClassName().equals(activityInfo.name)) {
|
||||||
|
return shortcutInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void launchShortcutTargetActivity(int displayId, ComponentName name) {
|
||||||
|
final Intent intent = new Intent();
|
||||||
|
final Bundle bundle = ActivityOptions.makeBasic().setLaunchDisplayId(displayId).toBundle();
|
||||||
|
|
||||||
|
intent.setComponent(name);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
try {
|
||||||
|
final int userId = UserHandle.myUserId();
|
||||||
|
getPrefContext().startActivityAsUser(intent, bundle, UserHandle.of(userId));
|
||||||
|
} catch (ActivityNotFoundException ignore) {
|
||||||
|
// ignore the exception
|
||||||
|
Log.w(TAG, "Target activity not found.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -59,6 +59,8 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
private LockPatternUtils mLockPatternUtils;
|
private LockPatternUtils mLockPatternUtils;
|
||||||
private AtomicBoolean mIsDialogShown = new AtomicBoolean(/* initialValue= */ false);
|
private AtomicBoolean mIsDialogShown = new AtomicBoolean(/* initialValue= */ false);
|
||||||
|
|
||||||
|
private static final String EMPTY_STRING = "";
|
||||||
|
|
||||||
private final SettingsContentObserver mSettingsContentObserver =
|
private final SettingsContentObserver mSettingsContentObserver =
|
||||||
new SettingsContentObserver(new Handler()) {
|
new SettingsContentObserver(new Handler()) {
|
||||||
@Override
|
@Override
|
||||||
@@ -84,7 +86,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mLockPatternUtils = new LockPatternUtils(getActivity());
|
mLockPatternUtils = new LockPatternUtils(getPrefContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -105,11 +107,11 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
// example, before JellyBean MR2 the user was granting the explore by touch
|
// example, before JellyBean MR2 the user was granting the explore by touch
|
||||||
// one.
|
// one.
|
||||||
private AccessibilityServiceInfo getAccessibilityServiceInfo() {
|
private AccessibilityServiceInfo getAccessibilityServiceInfo() {
|
||||||
List<AccessibilityServiceInfo> serviceInfos = AccessibilityManager.getInstance(
|
final List<AccessibilityServiceInfo> infos = AccessibilityManager.getInstance(
|
||||||
getActivity()).getInstalledAccessibilityServiceList();
|
getPrefContext()).getInstalledAccessibilityServiceList();
|
||||||
final int serviceInfoCount = serviceInfos.size();
|
|
||||||
for (int i = 0; i < serviceInfoCount; i++) {
|
for (int i = 0, count = infos.size(); i < count; i++) {
|
||||||
AccessibilityServiceInfo serviceInfo = serviceInfos.get(i);
|
AccessibilityServiceInfo serviceInfo = infos.get(i);
|
||||||
ResolveInfo resolveInfo = serviceInfo.getResolveInfo();
|
ResolveInfo resolveInfo = serviceInfo.getResolveInfo();
|
||||||
if (mComponentName.getPackageName().equals(resolveInfo.serviceInfo.packageName)
|
if (mComponentName.getPackageName().equals(resolveInfo.serviceInfo.packageName)
|
||||||
&& mComponentName.getClassName().equals(resolveInfo.serviceInfo.name)) {
|
&& mComponentName.getClassName().equals(resolveInfo.serviceInfo.name)) {
|
||||||
|
Reference in New Issue
Block a user