Create settings for window magnification (2/n)
Provide a setting for new Magnify area feature and joystick controller Bug: 146019459 Bug: 146473544 Test: make RunSettingsRoboTests ROBOTEST_FILTER=MagnificationModePreferenceControllerTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=MagnificationWindowControlPreferenceControllerTest Test: make RunSettingsRoboTests2 Change-Id: Ia32fa073c59ad304e9ef9eb530ba37dd24c2f2f6
This commit is contained in:
BIN
res/drawable/accessibility_magnification_full_screen.png
Normal file
BIN
res/drawable/accessibility_magnification_full_screen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
BIN
res/drawable/accessibility_magnification_window_screen.png
Normal file
BIN
res/drawable/accessibility_magnification_window_screen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
44
res/layout/accessibility_edit_magnification_mode.xml
Normal file
44
res/layout/accessibility_edit_magnification_mode.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2019 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: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:paddingEnd="24dp"
|
||||
android:paddingStart="24dp">
|
||||
|
||||
<TextView
|
||||
style="@style/AccessibilityDialogDescription"
|
||||
android:text="@string/accessibility_magnification_area_settings_message" />
|
||||
|
||||
<include
|
||||
android:id="@+id/magnify_full_screen"
|
||||
layout="@layout/accessibility_edit_shortcut_component" />
|
||||
|
||||
<include
|
||||
android:id="@+id/magnify_window_screen"
|
||||
layout="@layout/accessibility_edit_shortcut_component" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
@@ -19,12 +19,14 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:saveEnabled="false"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/summary"
|
||||
|
@@ -1014,8 +1014,25 @@
|
||||
<item>\?</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Summary for magnification adjustment modes for accessibility -->
|
||||
<string-array name="magnification_mode_summaries" translatable="false">
|
||||
<item>@string/accessibility_magnification_area_settings_full_screen_summary</item>
|
||||
<item>@string/accessibility_magnification_area_settings_window_screen_summary</item>
|
||||
<item>@string/accessibility_magnification_area_settings_all_summary</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Values for magnification adjustment modes for accessibility -->
|
||||
<integer-array name="magnification_mode_values" translatable="false">
|
||||
<!-- Full screen -->
|
||||
<item>1</item>
|
||||
<!-- Window screen -->
|
||||
<item>2</item>
|
||||
<!-- Full screen and window screen. -->
|
||||
<item>3</item>
|
||||
</integer-array>
|
||||
|
||||
<!-- Summary for color space adjustment modes for accessibility -->
|
||||
<string-array name="daltonizer_mode_summary" translatable="false">
|
||||
<string-array name="daltonizer_mode_summaries" translatable="false">
|
||||
<item>@string/daltonizer_mode_deuteranomaly</item>
|
||||
<item>@string/daltonizer_mode_protanomaly</item>
|
||||
<item>@string/daltonizer_mode_tritanomaly</item>
|
||||
|
@@ -4755,6 +4755,26 @@
|
||||
<string name="accessibility_captioning_title">Caption preferences</string>
|
||||
<!-- Title for the accessibility preference screen to enable screen magnification. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_screen_magnification_title">Magnification</string>
|
||||
<!-- Title for the accessibility preference screen to edit magnification area. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_magnification_mode_title">Magnification area</string>
|
||||
<!-- Message for the accessibility preference screen to edit magnification area dialog. [CHAR LIMIT=none] -->
|
||||
<string name="accessibility_magnification_area_settings_message">Choose the magnification area(s) you want to use when magnifying the screen</string>
|
||||
<!-- Summary for the accessibility preference screen to edit full screen. [CHAR LIMIT=none] -->
|
||||
<string name="accessibility_magnification_area_settings_full_screen_summary">Full screen</string>
|
||||
<!-- Summary for the accessibility preference screen to edit window screen. [CHAR LIMIT=none] -->
|
||||
<string name="accessibility_magnification_area_settings_window_screen_summary">Part of screen</string>
|
||||
<!-- Summary for the accessibility preference screen to edit entire screen. [CHAR LIMIT=none] -->
|
||||
<string name="accessibility_magnification_area_settings_all_summary">Full screen & part of screen</string>
|
||||
<!-- Message for the accessibility preference screen to edit entire screen. [CHAR LIMIT=none] -->
|
||||
<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] -->
|
||||
<string name="accessibility_magnification_area_settings_window_screen">Magnify part of screen</string>
|
||||
<!-- Title for the accessibility preference screen to show move controller. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_magnification_window_control_switch_title">Show move controller</string>
|
||||
<!-- Summary for the accessibility preference screen to show move controller. [CHAR LIMIT=none] -->
|
||||
<string name="accessibility_magnification_window_control_switch_summary">Show a joystick-like controller to move the magnification area</string>
|
||||
<!-- Title for the accessibility preference screen to enable screen magnification settings. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_magnification_service_settings_title">Magnify settings</string>
|
||||
<!-- Title for the accessibility preference screen to enable triple-tap gesture screen magnification. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_screen_magnification_gestures_title">Magnify with triple-tap</string>
|
||||
<!-- Title for the accessibility preference screen to enable navigation bar screen magnification. [CHAR LIMIT=35] -->
|
||||
|
36
res/xml/accessibility_magnification_service_settings.xml
Normal file
36
res/xml/accessibility_magnification_service_settings.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2019 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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:key="magnification_mode_screen"
|
||||
android:persistent="false"
|
||||
android:title="@string/accessibility_magnification_service_settings_title">
|
||||
|
||||
<Preference
|
||||
android:key="magnification_mode"
|
||||
android:persistent="false"
|
||||
android:title="@string/accessibility_magnification_mode_title"
|
||||
settings:controller="com.android.settings.accessibility.MagnificationModePreferenceController" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="magnification_window_control_switch"
|
||||
android:persistent="false"
|
||||
android:summary="@string/accessibility_magnification_window_control_switch_summary"
|
||||
android:title="@string/accessibility_magnification_window_control_switch_title"
|
||||
settings:controller="com.android.settings.accessibility.MagnificationWindowControlPreferenceController" />
|
||||
</PreferenceScreen>
|
@@ -24,6 +24,7 @@ import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -55,11 +56,13 @@ public class AccessibilityEditDialogUtils {
|
||||
@IntDef({
|
||||
DialogType.EDIT_SHORTCUT_GENERIC,
|
||||
DialogType.EDIT_SHORTCUT_MAGNIFICATION,
|
||||
DialogType.EDIT_MAGNIFICATION_MODE,
|
||||
})
|
||||
|
||||
private @interface DialogType {
|
||||
int EDIT_SHORTCUT_GENERIC = 0;
|
||||
int EDIT_SHORTCUT_MAGNIFICATION = 1;
|
||||
int EDIT_MAGNIFICATION_MODE = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,6 +99,23 @@ public class AccessibilityEditDialogUtils {
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to show the magnification mode dialog in Magnification.
|
||||
*
|
||||
* @param context A valid context
|
||||
* @param dialogTitle The title of magnify mode dialog
|
||||
* @param listener The listener to determine the action of magnify mode dialog
|
||||
* @return A magnification mode dialog in Magnification
|
||||
*/
|
||||
public static AlertDialog showMagnificationModeDialog(Context context,
|
||||
CharSequence dialogTitle, DialogInterface.OnClickListener listener) {
|
||||
final AlertDialog alertDialog = createDialog(context,
|
||||
DialogType.EDIT_MAGNIFICATION_MODE, dialogTitle, listener);
|
||||
alertDialog.show();
|
||||
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
private static AlertDialog createDialog(Context context, int dialogType,
|
||||
CharSequence dialogTitle, DialogInterface.OnClickListener listener) {
|
||||
|
||||
@@ -138,6 +158,12 @@ public class AccessibilityEditDialogUtils {
|
||||
initMagnifyShortcut(context, contentView);
|
||||
initAdvancedWidget(contentView);
|
||||
break;
|
||||
case DialogType.EDIT_MAGNIFICATION_MODE:
|
||||
contentView = inflater.inflate(
|
||||
R.layout.accessibility_edit_magnification_mode, null);
|
||||
initMagnifyFullScreen(context, contentView);
|
||||
initMagnifyWindowScreen(context, contentView);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
@@ -145,12 +171,37 @@ public class AccessibilityEditDialogUtils {
|
||||
return contentView;
|
||||
}
|
||||
|
||||
private static void initMagnifyFullScreen(Context context, View view) {
|
||||
final View dialogView = view.findViewById(R.id.magnify_full_screen);
|
||||
final String title = context.getString(
|
||||
R.string.accessibility_magnification_area_settings_full_screen);
|
||||
// TODO(b/146019459): Use vector drawable instead of temporal png file to avoid distorted.
|
||||
setupShortcutWidget(dialogView, title, R.drawable.accessibility_magnification_full_screen);
|
||||
}
|
||||
|
||||
private static void initMagnifyWindowScreen(Context context, View view) {
|
||||
final View dialogView = view.findViewById(R.id.magnify_window_screen);
|
||||
final String title = context.getString(
|
||||
R.string.accessibility_magnification_area_settings_window_screen);
|
||||
// TODO(b/146019459): Use vector drawable instead of temporal png file to avoid distorted.
|
||||
setupShortcutWidget(dialogView, title,
|
||||
R.drawable.accessibility_magnification_window_screen);
|
||||
}
|
||||
|
||||
private static void setupShortcutWidget(View view, CharSequence titleText, int imageResId) {
|
||||
setupShortcutWidget(view, titleText, null, imageResId);
|
||||
}
|
||||
|
||||
private static void setupShortcutWidget(View view, CharSequence titleText,
|
||||
CharSequence summaryText, int imageResId) {
|
||||
final CheckBox checkBox = view.findViewById(R.id.checkbox);
|
||||
checkBox.setText(titleText);
|
||||
final TextView summary = view.findViewById(R.id.summary);
|
||||
if (TextUtils.isEmpty(summaryText)) {
|
||||
summary.setVisibility(View.GONE);
|
||||
} else {
|
||||
summary.setText(summaryText);
|
||||
}
|
||||
final ImageView image = view.findViewById(R.id.image);
|
||||
image.setImageResource(imageResId);
|
||||
}
|
||||
|
@@ -42,15 +42,15 @@ public class DaltonizerPreferenceController extends BasePreferenceController {
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final String[] daltonizerSummarys = mContext.getResources().getStringArray(
|
||||
R.array.daltonizer_mode_summary);
|
||||
final String[] daltonizerSummaries = mContext.getResources().getStringArray(
|
||||
R.array.daltonizer_mode_summaries);
|
||||
final int[] daltonizerValues = mContext.getResources().getIntArray(
|
||||
R.array.daltonizer_type_values);
|
||||
final int timeoutValue =
|
||||
DaltonizerRadioButtonPreferenceController.getSecureAccessibilityDaltonizerValue(
|
||||
mContext.getContentResolver(), DALTONIZER_TYPE);
|
||||
final int idx = Ints.indexOf(daltonizerValues, timeoutValue);
|
||||
final String serviceSummary = daltonizerSummarys[idx == -1 ? 0 : idx];
|
||||
final String serviceSummary = daltonizerSummaries[idx == -1 ? 0 : idx];
|
||||
|
||||
final CharSequence serviceState = AccessibilityUtil.getSummary(mContext,
|
||||
DALTONIZER_ENABLED);
|
||||
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/** Controller that shows the magnification area mode summary. */
|
||||
public class MagnificationModePreferenceController extends BasePreferenceController {
|
||||
|
||||
public MagnificationModePreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return MagnificationSettingsFragment.getMagnificationCapabilitiesSummary(
|
||||
mContext);
|
||||
}
|
||||
}
|
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.accessibility;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/** Settings page for magnification. */
|
||||
@SearchIndexable
|
||||
public class MagnificationSettingsFragment extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "MagnificationSettingsFragment";
|
||||
private static final String PREF_KEY_MODE = "magnification_mode";
|
||||
// TODO(b/146019459): Use magnification_capability.
|
||||
private static final String KEY_CAPABILITY = Settings.System.MASTER_MONO;
|
||||
private static final int DIALOG_MAGNIFICATION_CAPABILITY = 1;
|
||||
private static final String EXTRA_CAPABILITY = "capability";
|
||||
private Preference mModePreference;
|
||||
private int mCapabilities = MagnifyMode.NONE;
|
||||
private CheckBox mMagnifyFullScreenCheckBox;
|
||||
private CheckBox mMagnifyWindowCheckBox;
|
||||
|
||||
static String getMagnificationCapabilitiesSummary(Context context) {
|
||||
final String[] magnificationModeSummaries = context.getResources().getStringArray(
|
||||
R.array.magnification_mode_summaries);
|
||||
final int[] magnificationModeValues = context.getResources().getIntArray(
|
||||
R.array.magnification_mode_values);
|
||||
final int capabilities = MagnificationSettingsFragment.getMagnificationCapabilities(
|
||||
context);
|
||||
|
||||
final int idx = Ints.indexOf(magnificationModeValues, capabilities);
|
||||
return magnificationModeSummaries[idx == -1 ? 0 : idx];
|
||||
}
|
||||
|
||||
private static int getMagnificationCapabilities(Context context) {
|
||||
return getSecureIntValue(context, KEY_CAPABILITY, MagnifyMode.FULLSCREEN);
|
||||
}
|
||||
|
||||
private static int getSecureIntValue(Context context, String key, int defaultValue) {
|
||||
return Settings.Secure.getIntForUser(
|
||||
context.getContentResolver(),
|
||||
key, defaultValue, context.getContentResolver().getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.ACCESSIBILITY_MAGNIFICATION_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt(EXTRA_CAPABILITY, mCapabilities);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
mCapabilities = savedInstanceState.getInt(EXTRA_CAPABILITY, MagnifyMode.NONE);
|
||||
}
|
||||
if (mCapabilities == MagnifyMode.NONE) {
|
||||
mCapabilities = getMagnificationCapabilities(getPrefContext());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDialogMetricsCategory(int dialogId) {
|
||||
switch (dialogId) {
|
||||
case DIALOG_MAGNIFICATION_CAPABILITY:
|
||||
return SettingsEnums.DIALOG_MAGNIFICATION_CAPABILITY;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
mModePreference = findPreference(PREF_KEY_MODE);
|
||||
mModePreference.setOnPreferenceClickListener(preference -> {
|
||||
mCapabilities = getMagnificationCapabilities(getPrefContext());
|
||||
showDialog(DIALOG_MAGNIFICATION_CAPABILITY);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.accessibility_magnification_service_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(int dialogId) {
|
||||
if (dialogId == DIALOG_MAGNIFICATION_CAPABILITY) {
|
||||
final String title = getPrefContext().getString(
|
||||
R.string.accessibility_magnification_mode_title);
|
||||
AlertDialog alertDialog = AccessibilityEditDialogUtils
|
||||
.showMagnificationModeDialog(getPrefContext(), title,
|
||||
this::callOnAlertDialogCheckboxClicked);
|
||||
initializeDialogCheckBox(alertDialog);
|
||||
return alertDialog;
|
||||
}
|
||||
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
|
||||
}
|
||||
|
||||
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
|
||||
updateCapabilities(true);
|
||||
mModePreference.setSummary(
|
||||
getMagnificationCapabilitiesSummary(getPrefContext()));
|
||||
}
|
||||
|
||||
private void initializeDialogCheckBox(AlertDialog dialog) {
|
||||
final View dialogFullScreenView = dialog.findViewById(R.id.magnify_full_screen);
|
||||
mMagnifyFullScreenCheckBox = dialogFullScreenView.findViewById(R.id.checkbox);
|
||||
|
||||
final View dialogWidowView = dialog.findViewById(R.id.magnify_window_screen);
|
||||
mMagnifyWindowCheckBox = dialogWidowView.findViewById(R.id.checkbox);
|
||||
|
||||
updateAlertDialogCheckState();
|
||||
updateAlertDialogEnableState();
|
||||
}
|
||||
|
||||
private void updateAlertDialogCheckState() {
|
||||
updateCheckStatus(mMagnifyWindowCheckBox, MagnifyMode.WINDOW);
|
||||
updateCheckStatus(mMagnifyFullScreenCheckBox, MagnifyMode.FULLSCREEN);
|
||||
|
||||
}
|
||||
|
||||
private void updateCheckStatus(CheckBox checkBox, int mode) {
|
||||
checkBox.setChecked((mode & mCapabilities) != 0);
|
||||
checkBox.setOnClickListener(v -> {
|
||||
updateCapabilities(false);
|
||||
updateAlertDialogEnableState();
|
||||
});
|
||||
}
|
||||
|
||||
private void updateAlertDialogEnableState() {
|
||||
if (mCapabilities != MagnifyMode.ALL) {
|
||||
disableEnabledMagnificationModePreference();
|
||||
} else {
|
||||
enableAllPreference();
|
||||
}
|
||||
}
|
||||
|
||||
private void enableAllPreference() {
|
||||
mMagnifyFullScreenCheckBox.setEnabled(true);
|
||||
mMagnifyWindowCheckBox.setEnabled(true);
|
||||
}
|
||||
|
||||
private void disableEnabledMagnificationModePreference() {
|
||||
if (!mMagnifyFullScreenCheckBox.isChecked()) {
|
||||
mMagnifyWindowCheckBox.setEnabled(false);
|
||||
} else if (!mMagnifyWindowCheckBox.isChecked()) {
|
||||
mMagnifyFullScreenCheckBox.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCapabilities(boolean saveToDB) {
|
||||
int capabilities = 0;
|
||||
capabilities |=
|
||||
mMagnifyFullScreenCheckBox.isChecked() ? MagnifyMode.FULLSCREEN : 0;
|
||||
capabilities |= mMagnifyWindowCheckBox.isChecked() ? MagnifyMode.WINDOW : 0;
|
||||
mCapabilities = capabilities;
|
||||
if (saveToDB) {
|
||||
setMagnificationCapabilities(capabilities);
|
||||
}
|
||||
}
|
||||
|
||||
private void setSecureIntValue(String key, int value) {
|
||||
Settings.Secure.putIntForUser(getPrefContext().getContentResolver(),
|
||||
key, value, getPrefContext().getContentResolver().getUserId());
|
||||
}
|
||||
|
||||
private void setMagnificationCapabilities(int capabilities) {
|
||||
setSecureIntValue(KEY_CAPABILITY, capabilities);
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({
|
||||
MagnifyMode.NONE,
|
||||
MagnifyMode.FULLSCREEN,
|
||||
MagnifyMode.WINDOW,
|
||||
MagnifyMode.ALL,
|
||||
})
|
||||
private @interface MagnifyMode {
|
||||
int NONE = 0;
|
||||
int FULLSCREEN = 1;
|
||||
int WINDOW = 2;
|
||||
int ALL = 3;
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.accessibility_magnification_service_settings);
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/** Controller that shows and updates the magnification window control switch. */
|
||||
public class MagnificationWindowControlPreferenceController extends TogglePreferenceController {
|
||||
|
||||
// TODO(b/146019459): Use magnification_window_control_enabled.
|
||||
private static final String KEY_CONTROL = Settings.System.MASTER_MONO;
|
||||
|
||||
public MagnificationWindowControlPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
KEY_CONTROL, State.OFF, UserHandle.USER_CURRENT) == State.ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.System.putIntForUser(mContext.getContentResolver(),
|
||||
KEY_CONTROL, isChecked ? State.ON : State.OFF, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
private @interface State {
|
||||
int OFF = 0;
|
||||
int ON = 1;
|
||||
}
|
||||
}
|
@@ -54,6 +54,7 @@ import com.android.settings.widget.SwitchBar;
|
||||
public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
ToggleFeaturePreferenceFragment implements SwitchBar.OnSwitchChangeListener {
|
||||
|
||||
private static final String SETTINGS_KEY = "screen_magnification_settings";
|
||||
private static final int DIALOG_ID_GESTURE_NAVIGATION_TUTORIAL = 1;
|
||||
private static final int DIALOG_ID_ACCESSIBILITY_BUTTON_TUTORIAL = 2;
|
||||
private static final int DIALOG_ID_EDIT_SHORTCUT = 3;
|
||||
@@ -170,6 +171,13 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
mVideoPreference.setPersistent(false);
|
||||
mVideoPreference.setLayoutResource(R.layout.magnification_video_preference);
|
||||
|
||||
final Preference settingsPreference = new Preference(getPrefContext());
|
||||
final String SettingsText = getString(R.string.settings_button);
|
||||
settingsPreference.setTitle(SettingsText);
|
||||
settingsPreference.setKey(SETTINGS_KEY);
|
||||
settingsPreference.setFragment(MagnificationSettingsFragment.class.getName());
|
||||
settingsPreference.setPersistent(false);
|
||||
|
||||
mConfigWarningPreference = new Preference(getPrefContext());
|
||||
mConfigWarningPreference.setSelectable(false);
|
||||
mConfigWarningPreference.setPersistent(false);
|
||||
@@ -179,8 +187,10 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
final PreferenceScreen preferenceScreen = getPreferenceManager().getPreferenceScreen();
|
||||
preferenceScreen.setOrderingAsAdded(false);
|
||||
mVideoPreference.setOrder(0);
|
||||
settingsPreference.setOrder(1);
|
||||
mConfigWarningPreference.setOrder(2);
|
||||
preferenceScreen.addPreference(mVideoPreference);
|
||||
preferenceScreen.addPreference(settingsPreference);
|
||||
preferenceScreen.addPreference(mConfigWarningPreference);
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MagnificationModePreferenceControllerTest {
|
||||
private static final String PREF_KEY = "screen_magnification_mode";
|
||||
// TODO(b/146019459): Use magnification_capability.
|
||||
private static final String KEY_CAPABILITY = Settings.System.MASTER_MONO;
|
||||
private static final int WINDOW_SCREEN_VALUE = 2;
|
||||
private static final int ALL_VALUE = 3;
|
||||
|
||||
private Context mContext;
|
||||
private MagnificationModePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new MagnificationModePreferenceController(mContext, PREF_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_saveWindowScreen_shouldReturnWindowScreenSummary() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
KEY_CAPABILITY, WINDOW_SCREEN_VALUE);
|
||||
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getString(
|
||||
R.string.accessibility_magnification_area_settings_window_screen_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_saveAll_shouldReturnAllSummary() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
KEY_CAPABILITY, ALL_VALUE);
|
||||
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getString(
|
||||
R.string.accessibility_magnification_area_settings_all_summary));
|
||||
}
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MagnificationWindowControlPreferenceControllerTest {
|
||||
private static final String PREF_KEY = "screen_magnification_window_control_switch";
|
||||
// TODO(b/146019459): Use magnification_window_control_enabled.
|
||||
private static final String KEY_CONTROL = Settings.System.MASTER_MONO;
|
||||
private Context mContext;
|
||||
private SwitchPreference mPreference;
|
||||
private MagnificationWindowControlPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mController = new MagnificationWindowControlPreferenceController(mContext, PREF_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_enabledWindowControl_shouldReturnTrue() {
|
||||
Settings.System.putIntForUser(mContext.getContentResolver(),
|
||||
KEY_CONTROL, State.ON, UserHandle.USER_CURRENT);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_disabledWindowControl_shouldReturnFalse() {
|
||||
Settings.System.putIntForUser(mContext.getContentResolver(),
|
||||
KEY_CONTROL, State.OFF, UserHandle.USER_CURRENT);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_setTrue_shouldEnableWindowControl() {
|
||||
mController.setChecked(true);
|
||||
|
||||
assertThat(Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
KEY_CONTROL, State.UNKNOWN, UserHandle.USER_CURRENT)).isEqualTo(State.ON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_setFalse_shouldDisableWindowControl() {
|
||||
mController.setChecked(false);
|
||||
|
||||
assertThat(Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
KEY_CONTROL, State.UNKNOWN, UserHandle.USER_CURRENT)).isEqualTo(State.OFF);
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
private @interface State {
|
||||
int UNKNOWN = -1;
|
||||
int OFF = 0;
|
||||
int ON = 1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user