Pull out PreferenceControllers from AccessibilitySettings
- clean up the format of accessibility_settings - To leverage the existing TtsPreferenceController and FontSizePreferenceController - pull out the logic of magnification from AccessibilitySettings Bug: 135056871 Test: manual, robotest Change-Id: I414fa7a04fd558d3a3a8b5e157469c198a772732
This commit is contained in:
@@ -15,41 +15,43 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
android:key="accessibility_settings_screen"
|
android:key="accessibility_settings_screen"
|
||||||
android:title="@string/accessibility_settings"
|
android:title="@string/accessibility_settings"
|
||||||
android:persistent="true">
|
android:persistent="true">
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="accessibility_shortcut_preference"
|
android:key="accessibility_shortcut_preference"
|
||||||
android:fragment="com.android.settings.accessibility.AccessibilityShortcutPreferenceFragment"
|
android:fragment="com.android.settings.accessibility.AccessibilityShortcutPreferenceFragment"
|
||||||
android:title="@string/accessibility_global_gesture_preference_title"/>
|
android:title="@string/accessibility_global_gesture_preference_title"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="user_installed_services_category"
|
android:key="user_installed_services_category"
|
||||||
android:title="@string/user_installed_services_category_title">
|
android:title="@string/user_installed_services_category_title">
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="screen_reader_category"
|
android:key="screen_reader_category"
|
||||||
android:title="@string/screen_reader_category_title">
|
android:title="@string/screen_reader_category_title">
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="tts_settings_preference"
|
android:key="tts_settings_preference"
|
||||||
android:fragment="com.android.settings.tts.TextToSpeechSettings"
|
android:title="@string/tts_settings_title"
|
||||||
android:title="@string/tts_settings_title"
|
android:fragment="com.android.settings.tts.TextToSpeechSettings"
|
||||||
settings:searchable="false"/>
|
settings:controller="com.android.settings.language.TtsPreferenceController"
|
||||||
|
settings:searchable="false"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="display_category"
|
android:key="display_category"
|
||||||
android:title="@string/display_category_title">
|
android:title="@string/display_category_title">
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:fragment="com.android.settings.display.ToggleFontSizePreferenceFragment"
|
|
||||||
android:key="font_size_preference_screen"
|
android:key="font_size_preference_screen"
|
||||||
android:title="@string/title_font_size"
|
android:title="@string/title_font_size"
|
||||||
|
android:fragment="com.android.settings.display.ToggleFontSizePreferenceFragment"
|
||||||
|
settings:controller="com.android.settings.display.FontSizePreferenceController"
|
||||||
settings:searchable="false"/>
|
settings:searchable="false"/>
|
||||||
|
|
||||||
<com.android.settings.display.ScreenZoomPreference
|
<com.android.settings.display.ScreenZoomPreference
|
||||||
@@ -61,68 +63,70 @@
|
|||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="dark_ui_mode_accessibility"
|
android:key="dark_ui_mode_accessibility"
|
||||||
android:title="@string/dark_ui_mode"
|
android:title="@string/dark_ui_mode"
|
||||||
|
settings:controller="com.android.settings.display.DarkUIPreferenceController"
|
||||||
settings:searchable="false"/>
|
settings:searchable="false"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:fragment="com.android.settings.accessibility.MagnificationPreferenceFragment"
|
|
||||||
android:key="magnification_preference_screen"
|
android:key="magnification_preference_screen"
|
||||||
android:title="@string/accessibility_screen_magnification_title"
|
android:title="@string/accessibility_screen_magnification_title"
|
||||||
android:icon="@drawable/ic_accessibility_magnification" />
|
android:icon="@drawable/ic_accessibility_magnification"
|
||||||
|
android:fragment="com.android.settings.accessibility.MagnificationPreferenceFragment"
|
||||||
|
settings:controller="com.android.settings.accessibility.MagnificationPreferenceController"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="toggle_large_pointer_icon"
|
android:key="toggle_large_pointer_icon"
|
||||||
android:title="@string/accessibility_toggle_large_pointer_icon_title" />
|
android:title="@string/accessibility_toggle_large_pointer_icon_title"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="toggle_disable_animations"
|
android:key="toggle_disable_animations"
|
||||||
android:title="@string/accessibility_disable_animations" />
|
android:title="@string/accessibility_disable_animations"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="interaction_control_category"
|
android:key="interaction_control_category"
|
||||||
android:title="@string/interaction_control_category_title">
|
android:title="@string/interaction_control_category_title">
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:fragment="com.android.settings.accessibility.ToggleAutoclickPreferenceFragment"
|
android:fragment="com.android.settings.accessibility.ToggleAutoclickPreferenceFragment"
|
||||||
android:key="autoclick_preference"
|
android:key="autoclick_preference"
|
||||||
android:title="@string/accessibility_autoclick_preference_title"
|
android:title="@string/accessibility_autoclick_preference_title"
|
||||||
settings:searchable="false"/>
|
settings:searchable="false"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="toggle_power_button_ends_call_preference"
|
android:key="toggle_power_button_ends_call_preference"
|
||||||
android:title="@string/accessibility_power_button_ends_call_prerefence_title"
|
android:title="@string/accessibility_power_button_ends_call_prerefence_title"
|
||||||
android:persistent="false"/>
|
android:persistent="false"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="toggle_lock_screen_rotation_preference"
|
android:key="toggle_lock_screen_rotation_preference"
|
||||||
android:title="@string/accelerometer_title"
|
android:title="@string/accelerometer_title"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
settings:controller="com.android.settings.accessibility.LockScreenRotationPreferenceController"/>
|
settings:controller="com.android.settings.accessibility.LockScreenRotationPreferenceController"/>
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="select_long_press_timeout_preference"
|
android:key="select_long_press_timeout_preference"
|
||||||
android:title="@string/accessibility_long_press_timeout_preference_title"
|
android:title="@string/accessibility_long_press_timeout_preference_title"
|
||||||
android:entries="@array/long_press_timeout_selector_titles"
|
android:entries="@array/long_press_timeout_selector_titles"
|
||||||
android:entryValues="@array/long_press_timeout_selector_values"
|
android:entryValues="@array/long_press_timeout_selector_values"
|
||||||
android:persistent="false"/>
|
android:persistent="false"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:fragment="com.android.settings.accessibility.AccessibilityControlTimeoutPreferenceFragment"
|
android:fragment="com.android.settings.accessibility.AccessibilityControlTimeoutPreferenceFragment"
|
||||||
android:key="accessibility_control_timeout_preference_fragment"
|
android:key="accessibility_control_timeout_preference_fragment"
|
||||||
android:title="@string/accessibility_setting_item_control_timeout_title"
|
android:title="@string/accessibility_setting_item_control_timeout_title"
|
||||||
android:persistent="false" />
|
android:persistent="false"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:fragment="com.android.settings.accessibility.VibrationSettings"
|
android:fragment="com.android.settings.accessibility.VibrationSettings"
|
||||||
android:key="vibration_preference_screen"
|
android:key="vibration_preference_screen"
|
||||||
android:title="@string/accessibility_vibration_settings_title" />
|
android:title="@string/accessibility_vibration_settings_title"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="audio_and_captions_category"
|
android:key="audio_and_captions_category"
|
||||||
android:title="@string/audio_and_captions_category_title">
|
android:title="@string/audio_and_captions_category_title">
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="live_caption"
|
android:key="live_caption"
|
||||||
@@ -131,14 +135,14 @@
|
|||||||
settings:controller="com.android.settings.accessibility.LiveCaptionPreferenceController"/>
|
settings:controller="com.android.settings.accessibility.LiveCaptionPreferenceController"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="toggle_master_mono"
|
android:key="toggle_master_mono"
|
||||||
android:title="@string/accessibility_toggle_master_mono_title"
|
android:title="@string/accessibility_toggle_master_mono_title"
|
||||||
android:summary="@string/accessibility_toggle_master_mono_summary"
|
android:summary="@string/accessibility_toggle_master_mono_summary"
|
||||||
android:persistent="false"/>
|
android:persistent="false"/>
|
||||||
|
|
||||||
<com.android.settings.accessibility.BalanceSeekBarPreference
|
<com.android.settings.accessibility.BalanceSeekBarPreference
|
||||||
android:key="seekbar_master_balance"
|
android:key="seekbar_master_balance"
|
||||||
android:title="@string/accessibility_toggle_master_balance_title" />
|
android:title="@string/accessibility_toggle_master_balance_title"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="hearing_aid_preference"
|
android:key="hearing_aid_preference"
|
||||||
@@ -146,32 +150,32 @@
|
|||||||
android:title="@string/accessibility_hearingaid_title"/>
|
android:title="@string/accessibility_hearingaid_title"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:fragment="com.android.settings.accessibility.CaptionPropertiesFragment"
|
android:fragment="com.android.settings.accessibility.CaptionPropertiesFragment"
|
||||||
android:key="captioning_preference_screen"
|
android:key="captioning_preference_screen"
|
||||||
android:title="@string/accessibility_captioning_title" />
|
android:title="@string/accessibility_captioning_title"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="experimental_category"
|
android:key="experimental_category"
|
||||||
android:title="@string/experimental_category_title">
|
android:title="@string/experimental_category_title">
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="toggle_high_text_contrast_preference"
|
android:key="toggle_high_text_contrast_preference"
|
||||||
android:title="@string/accessibility_toggle_high_text_contrast_preference_title" />
|
android:title="@string/accessibility_toggle_high_text_contrast_preference_title"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:fragment="com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment"
|
android:fragment="com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment"
|
||||||
android:key="daltonizer_preference"
|
android:key="daltonizer_preference"
|
||||||
android:title="@string/accessibility_display_daltonizer_preference_title"
|
android:title="@string/accessibility_display_daltonizer_preference_title"
|
||||||
android:icon="@drawable/ic_daltonizer"
|
android:icon="@drawable/ic_daltonizer"
|
||||||
settings:searchable="false"/>
|
settings:searchable="false"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="toggle_inversion_preference"
|
android:key="toggle_inversion_preference"
|
||||||
android:title="@string/accessibility_display_inversion_preference_title"
|
android:title="@string/accessibility_display_inversion_preference_title"
|
||||||
android:summary="@string/accessibility_display_inversion_preference_subtitle"
|
android:summary="@string/accessibility_display_inversion_preference_subtitle"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:icon="@drawable/ic_color_inversion"
|
android:icon="@drawable/ic_color_inversion"
|
||||||
settings:controller="com.android.settings.accessibility.ColorInversionPreferenceController"/>
|
settings:controller="com.android.settings.accessibility.ColorInversionPreferenceController"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -59,6 +59,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.display.DarkUIPreferenceController;
|
import com.android.settings.display.DarkUIPreferenceController;
|
||||||
|
import com.android.settings.display.FontSizePreferenceController;
|
||||||
import com.android.settings.display.ToggleFontSizePreferenceFragment;
|
import com.android.settings.display.ToggleFontSizePreferenceFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
@@ -241,6 +242,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
private LiveCaptionPreferenceController mLiveCaptionPreferenceController;
|
private LiveCaptionPreferenceController mLiveCaptionPreferenceController;
|
||||||
|
|
||||||
private LockScreenRotationPreferenceController mLockScreenRotationPreferenceController;
|
private LockScreenRotationPreferenceController mLockScreenRotationPreferenceController;
|
||||||
|
private FontSizePreferenceController mFontSizePreferenceController;
|
||||||
|
private MagnificationPreferenceController mMagnificationPreferenceController;
|
||||||
|
|
||||||
private int mLongPressTimeoutDefault;
|
private int mLongPressTimeoutDefault;
|
||||||
|
|
||||||
@@ -489,10 +492,14 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
// Display magnification.
|
// Display magnification.
|
||||||
mDisplayMagnificationPreferenceScreen = findPreference(
|
mDisplayMagnificationPreferenceScreen = findPreference(
|
||||||
DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN);
|
DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN);
|
||||||
configureMagnificationPreferenceIfNeeded(mDisplayMagnificationPreferenceScreen);
|
mMagnificationPreferenceController = new MagnificationPreferenceController(getContext(),
|
||||||
|
DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN);
|
||||||
|
mMagnificationPreferenceController.displayPreference(getPreferenceScreen());
|
||||||
|
|
||||||
// Font size.
|
// Font size.
|
||||||
mFontSizePreferenceScreen = findPreference(FONT_SIZE_PREFERENCE_SCREEN);
|
mFontSizePreferenceScreen = findPreference(FONT_SIZE_PREFERENCE_SCREEN);
|
||||||
|
mFontSizePreferenceController = new FontSizePreferenceController(getContext(),
|
||||||
|
FONT_SIZE_PREFERENCE_SCREEN);
|
||||||
|
|
||||||
// Autoclick after pointer stops.
|
// Autoclick after pointer stops.
|
||||||
mAutoclickPreferenceScreen = findPreference(AUTOCLICK_PREFERENCE_SCREEN);
|
mAutoclickPreferenceScreen = findPreference(AUTOCLICK_PREFERENCE_SCREEN);
|
||||||
@@ -770,9 +777,9 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
updateFeatureSummary(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
updateFeatureSummary(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
||||||
mDisplayDaltonizerPreferenceScreen);
|
mDisplayDaltonizerPreferenceScreen);
|
||||||
|
|
||||||
updateMagnificationSummary(mDisplayMagnificationPreferenceScreen);
|
mMagnificationPreferenceController.updateState(mDisplayMagnificationPreferenceScreen);
|
||||||
|
|
||||||
updateFontSizeSummary(mFontSizePreferenceScreen);
|
mFontSizePreferenceController.updateState(mFontSizePreferenceScreen);
|
||||||
|
|
||||||
updateAutoclickSummary(mAutoclickPreferenceScreen);
|
updateAutoclickSummary(mAutoclickPreferenceScreen);
|
||||||
|
|
||||||
@@ -795,25 +802,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
pref.setSummary(timeoutSummarys[idx == -1 ? 0 : idx]);
|
pref.setSummary(timeoutSummarys[idx == -1 ? 0 : idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMagnificationSummary(Preference pref) {
|
|
||||||
final boolean tripleTapEnabled = Settings.Secure.getInt(getContentResolver(),
|
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1;
|
|
||||||
final boolean buttonEnabled = Settings.Secure.getInt(getContentResolver(),
|
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0) == 1;
|
|
||||||
|
|
||||||
int summaryResId = 0;
|
|
||||||
if (!tripleTapEnabled && !buttonEnabled) {
|
|
||||||
summaryResId = R.string.accessibility_feature_state_off;
|
|
||||||
} else if (!tripleTapEnabled && buttonEnabled) {
|
|
||||||
summaryResId = R.string.accessibility_screen_magnification_navbar_title;
|
|
||||||
} else if (tripleTapEnabled && !buttonEnabled) {
|
|
||||||
summaryResId = R.string.accessibility_screen_magnification_gestures_title;
|
|
||||||
} else {
|
|
||||||
summaryResId = R.string.accessibility_screen_magnification_state_navbar_gesture;
|
|
||||||
}
|
|
||||||
pref.setSummary(summaryResId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateFeatureSummary(String prefKey, Preference pref) {
|
private void updateFeatureSummary(String prefKey, Preference pref) {
|
||||||
final boolean enabled = Settings.Secure.getInt(getContentResolver(), prefKey, 0) == 1;
|
final boolean enabled = Settings.Secure.getInt(getContentResolver(), prefKey, 0) == 1;
|
||||||
pref.setSummary(enabled ? R.string.accessibility_feature_state_on
|
pref.setSummary(enabled ? R.string.accessibility_feature_state_on
|
||||||
@@ -834,17 +822,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
getResources(), delay));
|
getResources(), delay));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFontSizeSummary(Preference pref) {
|
|
||||||
final float currentScale = Settings.System.getFloat(getContext().getContentResolver(),
|
|
||||||
Settings.System.FONT_SCALE, 1.0f);
|
|
||||||
final Resources res = getContext().getResources();
|
|
||||||
final String[] entries = res.getStringArray(R.array.entries_font_size);
|
|
||||||
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
|
|
||||||
final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(currentScale,
|
|
||||||
strEntryValues);
|
|
||||||
pref.setSummary(entries[index]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void updateVibrationSummary(Preference pref) {
|
void updateVibrationSummary(Preference pref) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
@@ -954,19 +931,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void configureMagnificationPreferenceIfNeeded(Preference preference) {
|
|
||||||
// Some devices support only a single magnification mode. In these cases, we redirect to
|
|
||||||
// the magnification mode's UI directly, rather than showing a PreferenceScreen with a
|
|
||||||
// single list item.
|
|
||||||
final Context context = preference.getContext();
|
|
||||||
if (!MagnificationPreferenceFragment.isApplicable(context.getResources())) {
|
|
||||||
preference.setFragment(ToggleScreenMagnificationPreferenceFragment.class.getName());
|
|
||||||
final Bundle extras = preference.getExtras();
|
|
||||||
MagnificationGesturesPreferenceController
|
|
||||||
.populateMagnificationGesturesPreferenceExtras(extras, context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider() {
|
new BaseSearchIndexProvider() {
|
||||||
|
|
||||||
|
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* 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.Bundle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
public class MagnificationPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
|
public MagnificationPreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
final boolean tripleTapEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1;
|
||||||
|
final boolean buttonEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0) == 1;
|
||||||
|
|
||||||
|
int summaryResId = 0;
|
||||||
|
if (!tripleTapEnabled && !buttonEnabled) {
|
||||||
|
summaryResId = R.string.accessibility_feature_state_off;
|
||||||
|
} else if (!tripleTapEnabled && buttonEnabled) {
|
||||||
|
summaryResId = R.string.accessibility_screen_magnification_navbar_title;
|
||||||
|
} else if (tripleTapEnabled && !buttonEnabled) {
|
||||||
|
summaryResId = R.string.accessibility_screen_magnification_gestures_title;
|
||||||
|
} else {
|
||||||
|
summaryResId = R.string.accessibility_screen_magnification_state_navbar_gesture;
|
||||||
|
}
|
||||||
|
return mContext.getResources().getText(summaryResId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
configureMagnificationPreferenceIfNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureMagnificationPreferenceIfNeeded() {
|
||||||
|
// Some devices support only a single magnification mode. In these cases, we redirect to
|
||||||
|
// the magnification mode's UI directly, rather than showing a PreferenceScreen with a
|
||||||
|
// single list item.
|
||||||
|
if (!MagnificationPreferenceFragment.isApplicable(mContext.getResources())) {
|
||||||
|
mPreference.setFragment(ToggleScreenMagnificationPreferenceFragment.class.getName());
|
||||||
|
final Bundle extras = mPreference.getExtras();
|
||||||
|
MagnificationGesturesPreferenceController
|
||||||
|
.populateMagnificationGesturesPreferenceExtras(extras, mContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
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 MagnificationPreferenceControllerTest {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private MagnificationPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mController = new MagnificationPreferenceController(mContext, "magnification");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_shouldReturnAvailable() {
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||||
|
BasePreferenceController.AVAILABLE);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user