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:
@@ -37,8 +37,9 @@
|
||||
|
||||
<Preference
|
||||
android:key="tts_settings_preference"
|
||||
android:fragment="com.android.settings.tts.TextToSpeechSettings"
|
||||
android:title="@string/tts_settings_title"
|
||||
android:fragment="com.android.settings.tts.TextToSpeechSettings"
|
||||
settings:controller="com.android.settings.language.TtsPreferenceController"
|
||||
settings:searchable="false"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
@@ -47,9 +48,10 @@
|
||||
android:title="@string/display_category_title">
|
||||
|
||||
<Preference
|
||||
android:fragment="com.android.settings.display.ToggleFontSizePreferenceFragment"
|
||||
android:key="font_size_preference_screen"
|
||||
android:title="@string/title_font_size"
|
||||
android:fragment="com.android.settings.display.ToggleFontSizePreferenceFragment"
|
||||
settings:controller="com.android.settings.display.FontSizePreferenceController"
|
||||
settings:searchable="false"/>
|
||||
|
||||
<com.android.settings.display.ScreenZoomPreference
|
||||
@@ -61,21 +63,23 @@
|
||||
<SwitchPreference
|
||||
android:key="dark_ui_mode_accessibility"
|
||||
android:title="@string/dark_ui_mode"
|
||||
settings:controller="com.android.settings.display.DarkUIPreferenceController"
|
||||
settings:searchable="false"/>
|
||||
|
||||
<Preference
|
||||
android:fragment="com.android.settings.accessibility.MagnificationPreferenceFragment"
|
||||
android:key="magnification_preference_screen"
|
||||
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
|
||||
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
|
||||
android:key="toggle_disable_animations"
|
||||
android:title="@string/accessibility_disable_animations" />
|
||||
android:title="@string/accessibility_disable_animations"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
@@ -111,12 +115,12 @@
|
||||
android:fragment="com.android.settings.accessibility.AccessibilityControlTimeoutPreferenceFragment"
|
||||
android:key="accessibility_control_timeout_preference_fragment"
|
||||
android:title="@string/accessibility_setting_item_control_timeout_title"
|
||||
android:persistent="false" />
|
||||
android:persistent="false"/>
|
||||
|
||||
<Preference
|
||||
android:fragment="com.android.settings.accessibility.VibrationSettings"
|
||||
android:key="vibration_preference_screen"
|
||||
android:title="@string/accessibility_vibration_settings_title" />
|
||||
android:title="@string/accessibility_vibration_settings_title"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
@@ -138,7 +142,7 @@
|
||||
|
||||
<com.android.settings.accessibility.BalanceSeekBarPreference
|
||||
android:key="seekbar_master_balance"
|
||||
android:title="@string/accessibility_toggle_master_balance_title" />
|
||||
android:title="@string/accessibility_toggle_master_balance_title"/>
|
||||
|
||||
<Preference
|
||||
android:key="hearing_aid_preference"
|
||||
@@ -148,7 +152,7 @@
|
||||
<Preference
|
||||
android:fragment="com.android.settings.accessibility.CaptionPropertiesFragment"
|
||||
android:key="captioning_preference_screen"
|
||||
android:title="@string/accessibility_captioning_title" />
|
||||
android:title="@string/accessibility_captioning_title"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
@@ -157,7 +161,7 @@
|
||||
|
||||
<SwitchPreference
|
||||
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
|
||||
android:fragment="com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment"
|
||||
|
@@ -59,6 +59,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.display.DarkUIPreferenceController;
|
||||
import com.android.settings.display.FontSizePreferenceController;
|
||||
import com.android.settings.display.ToggleFontSizePreferenceFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
@@ -241,6 +242,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
private LiveCaptionPreferenceController mLiveCaptionPreferenceController;
|
||||
|
||||
private LockScreenRotationPreferenceController mLockScreenRotationPreferenceController;
|
||||
private FontSizePreferenceController mFontSizePreferenceController;
|
||||
private MagnificationPreferenceController mMagnificationPreferenceController;
|
||||
|
||||
private int mLongPressTimeoutDefault;
|
||||
|
||||
@@ -489,10 +492,14 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
// Display magnification.
|
||||
mDisplayMagnificationPreferenceScreen = findPreference(
|
||||
DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN);
|
||||
configureMagnificationPreferenceIfNeeded(mDisplayMagnificationPreferenceScreen);
|
||||
mMagnificationPreferenceController = new MagnificationPreferenceController(getContext(),
|
||||
DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN);
|
||||
mMagnificationPreferenceController.displayPreference(getPreferenceScreen());
|
||||
|
||||
// Font size.
|
||||
mFontSizePreferenceScreen = findPreference(FONT_SIZE_PREFERENCE_SCREEN);
|
||||
mFontSizePreferenceController = new FontSizePreferenceController(getContext(),
|
||||
FONT_SIZE_PREFERENCE_SCREEN);
|
||||
|
||||
// Autoclick after pointer stops.
|
||||
mAutoclickPreferenceScreen = findPreference(AUTOCLICK_PREFERENCE_SCREEN);
|
||||
@@ -770,9 +777,9 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
updateFeatureSummary(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
||||
mDisplayDaltonizerPreferenceScreen);
|
||||
|
||||
updateMagnificationSummary(mDisplayMagnificationPreferenceScreen);
|
||||
mMagnificationPreferenceController.updateState(mDisplayMagnificationPreferenceScreen);
|
||||
|
||||
updateFontSizeSummary(mFontSizePreferenceScreen);
|
||||
mFontSizePreferenceController.updateState(mFontSizePreferenceScreen);
|
||||
|
||||
updateAutoclickSummary(mAutoclickPreferenceScreen);
|
||||
|
||||
@@ -795,25 +802,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
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) {
|
||||
final boolean enabled = Settings.Secure.getInt(getContentResolver(), prefKey, 0) == 1;
|
||||
pref.setSummary(enabled ? R.string.accessibility_feature_state_on
|
||||
@@ -834,17 +822,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
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
|
||||
void updateVibrationSummary(Preference pref) {
|
||||
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 =
|
||||
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