Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21da32d9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Pull out PreferenceControllers from AccessibilitySettings"

parents 174c9b7f d37618c8
Loading
Loading
Loading
Loading
+74 −70
Original line number Diff line number Diff line
@@ -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,13 +63,15 @@
        <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"
+10 −46
Original line number Diff line number Diff line
@@ -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() {

+80 −0
Original line number Diff line number Diff line
/*
 * 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);
        }
    }
}
+48 −0
Original line number Diff line number Diff line
/*
 * 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);
    }
}