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

Commit 685f6669 authored by Jean Chen's avatar Jean Chen Committed by Android (Google) Code Review
Browse files

Merge changes Iad13fbe1,I6eed7598 into main

* changes:
  Makes Use Color inversion searchable.
  Create a method to allow child classes to define it's main switch toggle's pref key
parents f4a3bd14 806b9141
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
        initLaunchPreference();

        final View view = super.onCreateView(inflater, container, savedInstanceState);
        removePreference(KEY_USE_SERVICE_PREFERENCE);
        removePreference(getUseServicePreferenceKey());
        return view;
    }

+29 −9
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.VisibleForTesting;

import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -52,7 +54,10 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
    private static final String TAG = "ToggleColorInversionPreferenceFragment";
    private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED;

    private static final String KEY_SHORTCUT_PREFERENCE = "color_inversion_shortcut_key";
    @VisibleForTesting
    static final String KEY_SHORTCUT_PREFERENCE = "color_inversion_shortcut_key";
    @VisibleForTesting
    static final String KEY_SWITCH_PREFERENCE = "color_inversion_switch_preference_key";

    @Override
    protected void registerKeysToObserverCallback(
@@ -131,6 +136,11 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
        switchPreference.setTitle(R.string.accessibility_display_inversion_switch_title);
    }

    @Override
    protected String getUseServicePreferenceKey() {
        return KEY_SWITCH_PREFERENCE;
    }

    @Override
    protected CharSequence getShortcutTitle() {
        return getText(R.string.accessibility_display_inversion_shortcut_title);
@@ -194,12 +204,22 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
                @Override
                public List<SearchIndexableRaw> getRawDataToIndex(Context context,
                        boolean enabled) {
                    final List<SearchIndexableRaw> rawData = new ArrayList<>();
                    final List<SearchIndexableRaw> rawData =
                            super.getRawDataToIndex(context, enabled);

                    SearchIndexableRaw raw = new SearchIndexableRaw(context);
                    raw.key = KEY_SHORTCUT_PREFERENCE;
                    raw.title = context.getString(
                            R.string.accessibility_display_inversion_shortcut_title);
                    rawData.add(raw);

                    if (Flags.fixA11ySettingsSearch()) {
                        SearchIndexableRaw mainPreferenceRaw = new SearchIndexableRaw(context);
                        mainPreferenceRaw.key = KEY_SWITCH_PREFERENCE;
                        mainPreferenceRaw.title = context.getString(
                                R.string.accessibility_display_inversion_switch_title);
                        rawData.add(mainPreferenceRaw);
                    }
                    return rawData;
                }
            };
+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF
        final List<String> lists = new ArrayList<>();
        lists.add(KEY_TOP_INTRO_PREFERENCE);
        lists.add(KEY_PREVIEW);
        lists.add(KEY_USE_SERVICE_PREFERENCE);
        lists.add(getUseServicePreferenceKey());
        // Putting saturation level close to the preview so users can see what is changing.
        lists.add(KEY_SATURATION);
        lists.add(KEY_DEUTERANOMALY);
+6 −3
Original line number Diff line number Diff line
@@ -83,7 +83,6 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
    public static final String KEY_GENERAL_CATEGORY = "general_categories";
    public static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
    protected static final String KEY_TOP_INTRO_PREFERENCE = "top_intro";
    protected static final String KEY_USE_SERVICE_PREFERENCE = "use_service";
    protected static final String KEY_HTML_DESCRIPTION_PREFERENCE = "html_description";
    protected static final String KEY_SAVED_QS_TOOLTIP_RESHOW = "qs_tooltip_reshow";
    protected static final String KEY_SAVED_QS_TOOLTIP_TYPE = "qs_tooltip_type";
@@ -325,6 +324,10 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
        switchPreference.setTitle(title);
    }

    protected String getUseServicePreferenceKey() {
        return "use_service";
    }

    protected CharSequence getShortcutTitle() {
        return getString(R.string.accessibility_shortcut_title, mPackageName);
    }
@@ -411,7 +414,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
        final List<String> lists = new ArrayList<>();
        lists.add(KEY_TOP_INTRO_PREFERENCE);
        lists.add(KEY_ANIMATED_IMAGE);
        lists.add(KEY_USE_SERVICE_PREFERENCE);
        lists.add(getUseServicePreferenceKey());
        lists.add(KEY_GENERAL_CATEGORY);
        lists.add(KEY_HTML_DESCRIPTION_PREFERENCE);
        return lists;
@@ -476,7 +479,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment

    private void initToggleServiceSwitchPreference() {
        mToggleServiceSwitchPreference = new SettingsMainSwitchPreference(getPrefContext());
        mToggleServiceSwitchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);
        mToggleServiceSwitchPreference.setKey(getUseServicePreferenceKey());
        if (getArguments().containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
            final boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED);
            mToggleServiceSwitchPreference.setChecked(enabled);
+44 −6
Original line number Diff line number Diff line
@@ -18,7 +18,8 @@ package com.android.settings.accessibility;

import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import static com.android.settings.accessibility.ToggleColorInversionPreferenceFragment.KEY_USE_SERVICE_PREFERENCE;
import static com.android.settings.accessibility.ToggleColorInversionPreferenceFragment.KEY_SHORTCUT_PREFERENCE;
import static com.android.settings.accessibility.ToggleColorInversionPreferenceFragment.KEY_SWITCH_PREFERENCE;

import static com.google.common.truth.Truth.assertThat;

@@ -32,12 +33,12 @@ import android.content.ComponentName;
import android.content.Context;
import android.os.Bundle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.Flags;
import android.widget.PopupWindow;

import androidx.fragment.app.FragmentActivity;
@@ -50,6 +51,7 @@ import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltip
import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.widget.SettingsMainSwitchPreference;
import com.android.settingslib.search.SearchIndexableRaw;

import org.junit.Before;
import org.junit.Rule;
@@ -63,6 +65,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowApplication;

import java.util.ArrayList;
import java.util.List;

/** Tests for {@link ToggleColorInversionPreferenceFragment} */
@@ -93,10 +96,10 @@ public class ToggleColorInversionPreferenceFragmentTest {
        when(mActivity.getContentResolver()).thenReturn(mContext.getContentResolver());

        mScreen = spy(new PreferenceScreen(mContext, /* attrs= */ null));
        when(mScreen.findPreference(KEY_USE_SERVICE_PREFERENCE))
        when(mScreen.findPreference(mFragment.getUseServicePreferenceKey()))
                .thenReturn(mFragment.mToggleServiceSwitchPreference);
        doReturn(mScreen).when(mFragment).getPreferenceScreen();
        mSwitchPreference = mScreen.findPreference(KEY_USE_SERVICE_PREFERENCE);
        mSwitchPreference = mScreen.findPreference(mFragment.getUseServicePreferenceKey());
    }

    @Test
@@ -137,7 +140,7 @@ public class ToggleColorInversionPreferenceFragmentTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
    @DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
    public void onPreferenceToggled_colorCorrectDisabled_shouldReturnTrueAndShowTooltipView() {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, OFF);
@@ -199,6 +202,41 @@ public class ToggleColorInversionPreferenceFragmentTest {
        assertThat(keys).containsAtLeastElementsIn(niks);
    }

    @Test
    @DisableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
    public void getRawDataToIndex_flagOff_returnShortcutIndexablePreferences() {
        List<SearchIndexableRaw> rawData = ToggleColorInversionPreferenceFragment
                .SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(mContext, /* enabled= */ true);

        assertThat(rawData).hasSize(1);
        assertThat(rawData.get(0).key).isEqualTo(KEY_SHORTCUT_PREFERENCE);
        assertThat(rawData.get(0).title).isEqualTo(mContext.getString(
                R.string.accessibility_display_inversion_shortcut_title));

    }

    @Test
    @EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
    public void getRawDataToIndex_flagOn_returnAllIndexablePreferences() {
        String[] expectedKeys = {KEY_SHORTCUT_PREFERENCE, KEY_SWITCH_PREFERENCE};
        String[] expectedTitles = {
                mContext.getString(R.string.accessibility_display_inversion_shortcut_title),
                mContext.getString(R.string.accessibility_display_inversion_switch_title)};
        List<String> keysResultList = new ArrayList<>();
        List<String> titlesResultList = new ArrayList<>();
        List<SearchIndexableRaw> rawData = ToggleColorInversionPreferenceFragment
                .SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(mContext, /* enabled= */ true);

        for (SearchIndexableRaw rawDataItem : rawData) {
            keysResultList.add(rawDataItem.key);
            titlesResultList.add(rawDataItem.title);
        }

        assertThat(rawData).hasSize(2);
        assertThat(keysResultList).containsExactly(expectedKeys);
        assertThat(titlesResultList).containsExactly(expectedTitles);
    }

    private static PopupWindow getLatestPopupWindow() {
        final ShadowApplication shadowApplication =
                Shadow.extract(ApplicationProvider.getApplicationContext());
@@ -220,7 +258,7 @@ public class ToggleColorInversionPreferenceFragmentTest {
            mComponentName = PLACEHOLDER_COMPONENT_NAME;
            final SettingsMainSwitchPreference switchPreference =
                    new SettingsMainSwitchPreference(context);
            switchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);
            switchPreference.setKey(getUseServicePreferenceKey());
            mToggleServiceSwitchPreference = switchPreference;
            setArguments(new Bundle());
        }
Loading