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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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(
|
||||
@@ -73,9 +78,9 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
mHtmlDescription = getText(R.string.accessibility_display_inversion_preference_subtitle);
|
||||
mTopIntroTitle = getText(R.string.accessibility_display_inversion_preference_intro_text);
|
||||
mImageUri = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
|
||||
.authority(getPrefContext().getPackageName())
|
||||
.appendPath(String.valueOf(R.raw.a11y_color_inversion_banner))
|
||||
.build();
|
||||
.authority(getPrefContext().getPackageName())
|
||||
.appendPath(String.valueOf(R.raw.a11y_color_inversion_banner))
|
||||
.build();
|
||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
updateFooterPreference();
|
||||
return view;
|
||||
@@ -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);
|
||||
@@ -165,7 +175,7 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
@Override
|
||||
int getUserShortcutTypes() {
|
||||
return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
|
||||
mComponentName);
|
||||
mComponentName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -176,8 +186,8 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
@Override
|
||||
CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
|
||||
return getText(type == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? R.string.accessibility_color_inversion_qs_tooltip_content
|
||||
: R.string.accessibility_color_inversion_auto_added_qs_tooltip_content);
|
||||
? R.string.accessibility_color_inversion_qs_tooltip_content
|
||||
: R.string.accessibility_color_inversion_auto_added_qs_tooltip_content);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -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);
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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());
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@ 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.ToggleDaltonizerPreferenceFragment.KEY_USE_SERVICE_PREFERENCE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -189,6 +188,6 @@ public class ToggleDaltonizerPreferenceFragmentTest {
|
||||
|
||||
private SettingsMainSwitchPreference getMainFeatureToggle(
|
||||
ToggleDaltonizerPreferenceFragment fragment) {
|
||||
return fragment.findPreference(KEY_USE_SERVICE_PREFERENCE);
|
||||
return fragment.findPreference(fragment.getUseServicePreferenceKey());
|
||||
}
|
||||
}
|
||||
|
@@ -235,8 +235,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
@Test
|
||||
@Config(shadows = ShadowFragment.class)
|
||||
public void onPreferenceToggledOnDisabledService_notShowTooltipView() {
|
||||
mFragment.onPreferenceToggled(
|
||||
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ false);
|
||||
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ false);
|
||||
|
||||
assertThat(getLatestPopupWindow()).isNull();
|
||||
}
|
||||
@@ -245,8 +244,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
@Config(shadows = ShadowFragment.class)
|
||||
public void onPreferenceToggledOnEnabledService_showTooltipView() {
|
||||
mFragment.onPreferenceToggled(
|
||||
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
|
||||
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ true);
|
||||
|
||||
assertThat(getLatestPopupWindow().isShowing()).isTrue();
|
||||
}
|
||||
@@ -258,8 +256,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
suwIntent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true);
|
||||
when(mActivity.getIntent()).thenReturn(suwIntent);
|
||||
|
||||
mFragment.onPreferenceToggled(
|
||||
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
|
||||
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ true);
|
||||
|
||||
assertThat(getLatestPopupWindow()).isNull();
|
||||
}
|
||||
@@ -268,12 +265,10 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
@Config(shadows = ShadowFragment.class)
|
||||
public void onPreferenceToggledOnEnabledService_tooltipViewShown_notShowTooltipView() {
|
||||
mFragment.onPreferenceToggled(
|
||||
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
|
||||
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ true);
|
||||
getLatestPopupWindow().dismiss();
|
||||
|
||||
mFragment.onPreferenceToggled(
|
||||
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
|
||||
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ true);
|
||||
|
||||
assertThat(getLatestPopupWindow().isShowing()).isFalse();
|
||||
}
|
||||
|
Reference in New Issue
Block a user