Add magnification switch shortcut dialog.
* show dialog when triple-tap users want to use magnify window mode Bug: 146473544 Test: manual Change-Id: I6915c165e8da59c6ec7557147192c7a1e9e19cf3
This commit is contained in:
55
res/layout/accessibility_edit_magnification_shortcut.xml
Normal file
55
res/layout/accessibility_edit_magnification_shortcut.xml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?><!--
|
||||||
|
Copyright (C) 2020 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
|
||||||
|
-->
|
||||||
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/container_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scrollbarStyle="outsideOverlay">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="24dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/accessibility_magnification_switch_shortcut_message"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
android:layout_marginBottom="24dp"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/switch_shortcut_positive_button"
|
||||||
|
style="@style/AccessibilityDialogButton"
|
||||||
|
android:gravity="center|end"
|
||||||
|
android:text="@string/accessibility_magnification_switch_shortcut_positive_button"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/switch_shortcut_negative_button"
|
||||||
|
style="@style/AccessibilityDialogButton"
|
||||||
|
android:gravity="center|end"
|
||||||
|
android:text="@string/accessibility_magnification_switch_shortcut_negative_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
@@ -4913,6 +4913,14 @@
|
|||||||
<string name="accessibility_magnification_area_settings_full_screen">Magnify entire screen</string>
|
<string name="accessibility_magnification_area_settings_full_screen">Magnify entire screen</string>
|
||||||
<!-- Message for the accessibility preference screen to edit part of screen. [CHAR LIMIT=none] -->
|
<!-- Message for the accessibility preference screen to edit part of screen. [CHAR LIMIT=none] -->
|
||||||
<string name="accessibility_magnification_area_settings_window_screen">Magnify part of screen</string>
|
<string name="accessibility_magnification_area_settings_window_screen">Magnify part of screen</string>
|
||||||
|
<!-- Title for the accessibility magnification switch shortcut dialog. [CHAR LIMIT=48] -->
|
||||||
|
<string name="accessibility_magnification_switch_shortcut_title">Switch to accessibility button?</string>
|
||||||
|
<!-- Message for the accessibility magnification switch shortcut dialog. [CHAR LIMIT=none] -->
|
||||||
|
<string name="accessibility_magnification_switch_shortcut_message">Using triple tap to magnify part of the screen will cause typing and other actions to be delayed.\n\nDo you want to switch to using accessibility button to magnify?</string>
|
||||||
|
<!-- Title for the switch shortcut button in accessibility switch shortcut dialog to change the config shortcut value. [CHAR LIMIT=45] -->
|
||||||
|
<string name="accessibility_magnification_switch_shortcut_positive_button">Switch to accessibility button</string>
|
||||||
|
<!-- Title for the cancel button in accessibility switch shortcut dialog to keep the config shortcut value. [CHAR LIMIT=54] -->
|
||||||
|
<string name="accessibility_magnification_switch_shortcut_negative_button">Keep triple tap to magnify</string>
|
||||||
<!-- Title for the accessibility preference screen to enable screen magnification settings. [CHAR LIMIT=35] -->
|
<!-- Title for the accessibility preference screen to enable screen magnification settings. [CHAR LIMIT=35] -->
|
||||||
<string name="accessibility_magnification_service_settings_title">Magnification settings</string>
|
<string name="accessibility_magnification_service_settings_title">Magnification settings</string>
|
||||||
<!-- Title for the accessibility preference screen to enable triple-tap gesture screen magnification. [CHAR LIMIT=35] -->
|
<!-- Title for the accessibility preference screen to enable triple-tap gesture screen magnification. [CHAR LIMIT=35] -->
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
@@ -26,6 +27,7 @@ import android.text.TextUtils;
|
|||||||
import android.text.style.ImageSpan;
|
import android.text.style.ImageSpan;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@@ -56,12 +58,14 @@ public class AccessibilityEditDialogUtils {
|
|||||||
DialogType.EDIT_SHORTCUT_GENERIC,
|
DialogType.EDIT_SHORTCUT_GENERIC,
|
||||||
DialogType.EDIT_SHORTCUT_MAGNIFICATION,
|
DialogType.EDIT_SHORTCUT_MAGNIFICATION,
|
||||||
DialogType.EDIT_MAGNIFICATION_MODE,
|
DialogType.EDIT_MAGNIFICATION_MODE,
|
||||||
|
DialogType.EDIT_MAGNIFICATION_SWITCH_SHORTCUT,
|
||||||
})
|
})
|
||||||
|
|
||||||
private @interface DialogType {
|
private @interface DialogType {
|
||||||
int EDIT_SHORTCUT_GENERIC = 0;
|
int EDIT_SHORTCUT_GENERIC = 0;
|
||||||
int EDIT_SHORTCUT_MAGNIFICATION = 1;
|
int EDIT_SHORTCUT_MAGNIFICATION = 1;
|
||||||
int EDIT_MAGNIFICATION_MODE = 2;
|
int EDIT_MAGNIFICATION_MODE = 2;
|
||||||
|
int EDIT_MAGNIFICATION_SWITCH_SHORTCUT = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,6 +119,26 @@ public class AccessibilityEditDialogUtils {
|
|||||||
return alertDialog;
|
return alertDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to show the magnification edit shortcut dialog in Magnification.
|
||||||
|
*
|
||||||
|
* @param context A valid context
|
||||||
|
* @param dialogTitle The title of magnify edit shortcut dialog
|
||||||
|
* @param listener The listener to determine the action of magnify edit shortcut dialog
|
||||||
|
* @return A magnification edit shortcut dialog in Magnification
|
||||||
|
*/
|
||||||
|
public static Dialog showMagnificationSwitchShortcutDialog(Context context,
|
||||||
|
CharSequence dialogTitle, View.OnClickListener listener) {
|
||||||
|
final AlertDialog alertDialog = new AlertDialog.Builder(context)
|
||||||
|
.setView(createSwitchShortcutDialogContentView(context))
|
||||||
|
.setTitle(dialogTitle)
|
||||||
|
.create();
|
||||||
|
alertDialog.show();
|
||||||
|
setEditShortcutButtonsListener(alertDialog, listener);
|
||||||
|
setScrollIndicators(alertDialog);
|
||||||
|
return alertDialog;
|
||||||
|
}
|
||||||
|
|
||||||
private static AlertDialog createDialog(Context context, int dialogType,
|
private static AlertDialog createDialog(Context context, int dialogType,
|
||||||
CharSequence dialogTitle, DialogInterface.OnClickListener listener) {
|
CharSequence dialogTitle, DialogInterface.OnClickListener listener) {
|
||||||
|
|
||||||
@@ -140,6 +164,22 @@ public class AccessibilityEditDialogUtils {
|
|||||||
View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_BOTTOM);
|
View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_BOTTOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setEditShortcutButtonsListener(AlertDialog dialog,
|
||||||
|
View.OnClickListener listener) {
|
||||||
|
final View contentView = dialog.findViewById(R.id.container_layout);
|
||||||
|
final Button positiveButton = contentView.findViewById(
|
||||||
|
R.id.switch_shortcut_positive_button);
|
||||||
|
final Button negativeButton = contentView.findViewById(
|
||||||
|
R.id.switch_shortcut_negative_button);
|
||||||
|
|
||||||
|
positiveButton.setOnClickListener(listener);
|
||||||
|
negativeButton.setOnClickListener(v -> dialog.dismiss());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static View createSwitchShortcutDialogContentView(Context context) {
|
||||||
|
return createEditDialogContentView(context, DialogType.EDIT_MAGNIFICATION_SWITCH_SHORTCUT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a content View for the edit shortcut dialog.
|
* Get a content View for the edit shortcut dialog.
|
||||||
*
|
*
|
||||||
@@ -174,6 +214,10 @@ public class AccessibilityEditDialogUtils {
|
|||||||
initMagnifyFullScreen(context, contentView);
|
initMagnifyFullScreen(context, contentView);
|
||||||
initMagnifyWindowScreen(context, contentView);
|
initMagnifyWindowScreen(context, contentView);
|
||||||
break;
|
break;
|
||||||
|
case DialogType.EDIT_MAGNIFICATION_SWITCH_SHORTCUT:
|
||||||
|
contentView = inflater.inflate(
|
||||||
|
R.layout.accessibility_edit_magnification_shortcut, null);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
@@ -16,17 +16,21 @@
|
|||||||
|
|
||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
|
import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
|
||||||
|
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||||
|
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -36,6 +40,8 @@ import com.android.settingslib.search.SearchIndexable;
|
|||||||
|
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
|
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
/** Settings page for magnification. */
|
/** Settings page for magnification. */
|
||||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||||
public class MagnificationSettingsFragment extends DashboardFragment {
|
public class MagnificationSettingsFragment extends DashboardFragment {
|
||||||
@@ -45,12 +51,15 @@ public class MagnificationSettingsFragment extends DashboardFragment {
|
|||||||
private static final String KEY_CAPABILITY =
|
private static final String KEY_CAPABILITY =
|
||||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_CAPABILITY;
|
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_CAPABILITY;
|
||||||
private static final int DIALOG_MAGNIFICATION_CAPABILITY = 1;
|
private static final int DIALOG_MAGNIFICATION_CAPABILITY = 1;
|
||||||
|
private static final int DIALOG_MAGNIFICATION_SWITCH_SHORTCUT = 2;
|
||||||
private static final String EXTRA_CAPABILITY = "capability";
|
private static final String EXTRA_CAPABILITY = "capability";
|
||||||
private static final int NONE = 0;
|
private static final int NONE = 0;
|
||||||
|
private static final char COMPONENT_NAME_SEPARATOR = ':';
|
||||||
private Preference mModePreference;
|
private Preference mModePreference;
|
||||||
private int mCapabilities = NONE;
|
private int mCapabilities = NONE;
|
||||||
private CheckBox mMagnifyFullScreenCheckBox;
|
private CheckBox mMagnifyFullScreenCheckBox;
|
||||||
private CheckBox mMagnifyWindowCheckBox;
|
private CheckBox mMagnifyWindowCheckBox;
|
||||||
|
private Dialog mDialog;
|
||||||
|
|
||||||
static String getMagnificationCapabilitiesSummary(Context context) {
|
static String getMagnificationCapabilitiesSummary(Context context) {
|
||||||
final String[] magnificationModeSummaries = context.getResources().getStringArray(
|
final String[] magnificationModeSummaries = context.getResources().getStringArray(
|
||||||
@@ -102,6 +111,8 @@ public class MagnificationSettingsFragment extends DashboardFragment {
|
|||||||
switch (dialogId) {
|
switch (dialogId) {
|
||||||
case DIALOG_MAGNIFICATION_CAPABILITY:
|
case DIALOG_MAGNIFICATION_CAPABILITY:
|
||||||
return SettingsEnums.DIALOG_MAGNIFICATION_CAPABILITY;
|
return SettingsEnums.DIALOG_MAGNIFICATION_CAPABILITY;
|
||||||
|
case DIALOG_MAGNIFICATION_SWITCH_SHORTCUT:
|
||||||
|
return SettingsEnums.DIALOG_MAGNIFICATION_SWITCH_SHORTCUT;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -130,15 +141,23 @@ public class MagnificationSettingsFragment extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(int dialogId) {
|
public Dialog onCreateDialog(int dialogId) {
|
||||||
if (dialogId == DIALOG_MAGNIFICATION_CAPABILITY) {
|
final CharSequence title;
|
||||||
final String title = getPrefContext().getString(
|
switch (dialogId) {
|
||||||
R.string.accessibility_magnification_mode_title);
|
case DIALOG_MAGNIFICATION_CAPABILITY:
|
||||||
AlertDialog alertDialog = AccessibilityEditDialogUtils
|
title = getPrefContext().getString(
|
||||||
.showMagnificationModeDialog(getPrefContext(), title,
|
R.string.accessibility_magnification_mode_title);
|
||||||
this::callOnAlertDialogCheckboxClicked);
|
mDialog = AccessibilityEditDialogUtils.showMagnificationModeDialog(getPrefContext(),
|
||||||
initializeDialogCheckBox(alertDialog);
|
title, this::callOnAlertDialogCheckboxClicked);
|
||||||
return alertDialog;
|
initializeDialogCheckBox(mDialog);
|
||||||
|
return mDialog;
|
||||||
|
case DIALOG_MAGNIFICATION_SWITCH_SHORTCUT:
|
||||||
|
title = getPrefContext().getString(
|
||||||
|
R.string.accessibility_magnification_switch_shortcut_title);
|
||||||
|
mDialog = AccessibilityEditDialogUtils.showMagnificationSwitchShortcutDialog(
|
||||||
|
getPrefContext(), title, this::onSwitchShortcutDialogPositiveButtonClicked);
|
||||||
|
return mDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
|
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +167,40 @@ public class MagnificationSettingsFragment extends DashboardFragment {
|
|||||||
getMagnificationCapabilitiesSummary(getPrefContext()));
|
getMagnificationCapabilitiesSummary(getPrefContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeDialogCheckBox(AlertDialog dialog) {
|
private void onSwitchShortcutDialogPositiveButtonClicked(View view) {
|
||||||
|
//TODO(b/147990389): Merge this function into util until magnification change format to
|
||||||
|
// Component.
|
||||||
|
optOutMagnificationFromTripleTap();
|
||||||
|
optInMagnificationToAccessibilityButton();
|
||||||
|
|
||||||
|
mDialog.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void optOutMagnificationFromTripleTap() {
|
||||||
|
Settings.Secure.putInt(getPrefContext().getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void optInMagnificationToAccessibilityButton() {
|
||||||
|
final String targetKey = Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
|
||||||
|
final String targetString = Settings.Secure.getString(getPrefContext().getContentResolver(),
|
||||||
|
targetKey);
|
||||||
|
if (targetString.contains(MAGNIFICATION_CONTROLLER_NAME)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(targetString)) {
|
||||||
|
joiner.add(targetString);
|
||||||
|
}
|
||||||
|
joiner.add(MAGNIFICATION_CONTROLLER_NAME);
|
||||||
|
|
||||||
|
Settings.Secure.putString(getPrefContext().getContentResolver(), targetKey,
|
||||||
|
joiner.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeDialogCheckBox(Dialog dialog) {
|
||||||
final View dialogFullScreenView = dialog.findViewById(R.id.magnify_full_screen);
|
final View dialogFullScreenView = dialog.findViewById(R.id.magnify_full_screen);
|
||||||
final View dialogFullScreenTextArea = dialogFullScreenView.findViewById(R.id.container);
|
final View dialogFullScreenTextArea = dialogFullScreenView.findViewById(R.id.container);
|
||||||
mMagnifyFullScreenCheckBox = dialogFullScreenView.findViewById(R.id.checkbox);
|
mMagnifyFullScreenCheckBox = dialogFullScreenView.findViewById(R.id.checkbox);
|
||||||
@@ -176,6 +228,10 @@ public class MagnificationSettingsFragment extends DashboardFragment {
|
|||||||
windowCheckBox.toggle();
|
windowCheckBox.toggle();
|
||||||
updateCapabilities(false);
|
updateCapabilities(false);
|
||||||
updateAlertDialogEnableState(fullScreenTextArea, windowTextArea);
|
updateAlertDialogEnableState(fullScreenTextArea, windowTextArea);
|
||||||
|
|
||||||
|
if (isTripleTapEnabled() && windowCheckBox.isChecked()) {
|
||||||
|
showDialog(DIALOG_MAGNIFICATION_SWITCH_SHORTCUT);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,6 +289,11 @@ public class MagnificationSettingsFragment extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTripleTapEnabled() {
|
||||||
|
return Settings.Secure.getInt(getPrefContext().getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF) == ON;
|
||||||
|
}
|
||||||
|
|
||||||
private void setSecureIntValue(String key, int value) {
|
private void setSecureIntValue(String key, int value) {
|
||||||
Settings.Secure.putIntForUser(getPrefContext().getContentResolver(),
|
Settings.Secure.putIntForUser(getPrefContext().getContentResolver(),
|
||||||
key, value, getPrefContext().getContentResolver().getUserId());
|
key, value, getPrefContext().getContentResolver().getUserId());
|
||||||
|
Reference in New Issue
Block a user