Create a method to allow child classes to define it's main switch toggle's pref key
We'd like to make the main switch toggle's preference searchable. Since we construct the preference programmatically, this would allow the preference to be automatically scrolled to when the user is brought to this page from a search result. Bug: 372171003 Flag: EXEMPT refactor Test: manual Test: atest ToggleColorInversionPreferenceFragmentTest atest ToggleDaltonizerPreferenceFragmentTest atest ToggleFeaturePreferenceFragmentTest Change-Id: I6eed7598ad296a758573318cf4bde5de30c7005c
This commit is contained in:
@@ -67,7 +67,7 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
|
|||||||
initLaunchPreference();
|
initLaunchPreference();
|
||||||
|
|
||||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
removePreference(KEY_USE_SERVICE_PREFERENCE);
|
removePreference(getUseServicePreferenceKey());
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -106,7 +106,7 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF
|
|||||||
final List<String> lists = new ArrayList<>();
|
final List<String> lists = new ArrayList<>();
|
||||||
lists.add(KEY_TOP_INTRO_PREFERENCE);
|
lists.add(KEY_TOP_INTRO_PREFERENCE);
|
||||||
lists.add(KEY_PREVIEW);
|
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.
|
// Putting saturation level close to the preview so users can see what is changing.
|
||||||
lists.add(KEY_SATURATION);
|
lists.add(KEY_SATURATION);
|
||||||
lists.add(KEY_DEUTERANOMALY);
|
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_GENERAL_CATEGORY = "general_categories";
|
||||||
public static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
|
public static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
|
||||||
protected static final String KEY_TOP_INTRO_PREFERENCE = "top_intro";
|
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_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_RESHOW = "qs_tooltip_reshow";
|
||||||
protected static final String KEY_SAVED_QS_TOOLTIP_TYPE = "qs_tooltip_type";
|
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);
|
switchPreference.setTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getUseServicePreferenceKey() {
|
||||||
|
return "use_service";
|
||||||
|
}
|
||||||
|
|
||||||
protected CharSequence getShortcutTitle() {
|
protected CharSequence getShortcutTitle() {
|
||||||
return getString(R.string.accessibility_shortcut_title, mPackageName);
|
return getString(R.string.accessibility_shortcut_title, mPackageName);
|
||||||
}
|
}
|
||||||
@@ -411,7 +414,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
|
|||||||
final List<String> lists = new ArrayList<>();
|
final List<String> lists = new ArrayList<>();
|
||||||
lists.add(KEY_TOP_INTRO_PREFERENCE);
|
lists.add(KEY_TOP_INTRO_PREFERENCE);
|
||||||
lists.add(KEY_ANIMATED_IMAGE);
|
lists.add(KEY_ANIMATED_IMAGE);
|
||||||
lists.add(KEY_USE_SERVICE_PREFERENCE);
|
lists.add(getUseServicePreferenceKey());
|
||||||
lists.add(KEY_GENERAL_CATEGORY);
|
lists.add(KEY_GENERAL_CATEGORY);
|
||||||
lists.add(KEY_HTML_DESCRIPTION_PREFERENCE);
|
lists.add(KEY_HTML_DESCRIPTION_PREFERENCE);
|
||||||
return lists;
|
return lists;
|
||||||
@@ -476,7 +479,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
|
|||||||
|
|
||||||
private void initToggleServiceSwitchPreference() {
|
private void initToggleServiceSwitchPreference() {
|
||||||
mToggleServiceSwitchPreference = new SettingsMainSwitchPreference(getPrefContext());
|
mToggleServiceSwitchPreference = new SettingsMainSwitchPreference(getPrefContext());
|
||||||
mToggleServiceSwitchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);
|
mToggleServiceSwitchPreference.setKey(getUseServicePreferenceKey());
|
||||||
if (getArguments().containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
|
if (getArguments().containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
|
||||||
final boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED);
|
final boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED);
|
||||||
mToggleServiceSwitchPreference.setChecked(enabled);
|
mToggleServiceSwitchPreference.setChecked(enabled);
|
||||||
|
@@ -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.OFF;
|
||||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||||
import static com.android.settings.accessibility.ToggleColorInversionPreferenceFragment.KEY_USE_SERVICE_PREFERENCE;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -93,10 +92,10 @@ public class ToggleColorInversionPreferenceFragmentTest {
|
|||||||
when(mActivity.getContentResolver()).thenReturn(mContext.getContentResolver());
|
when(mActivity.getContentResolver()).thenReturn(mContext.getContentResolver());
|
||||||
|
|
||||||
mScreen = spy(new PreferenceScreen(mContext, /* attrs= */ null));
|
mScreen = spy(new PreferenceScreen(mContext, /* attrs= */ null));
|
||||||
when(mScreen.findPreference(KEY_USE_SERVICE_PREFERENCE))
|
when(mScreen.findPreference(mFragment.getUseServicePreferenceKey()))
|
||||||
.thenReturn(mFragment.mToggleServiceSwitchPreference);
|
.thenReturn(mFragment.mToggleServiceSwitchPreference);
|
||||||
doReturn(mScreen).when(mFragment).getPreferenceScreen();
|
doReturn(mScreen).when(mFragment).getPreferenceScreen();
|
||||||
mSwitchPreference = mScreen.findPreference(KEY_USE_SERVICE_PREFERENCE);
|
mSwitchPreference = mScreen.findPreference(mFragment.getUseServicePreferenceKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -220,7 +219,7 @@ public class ToggleColorInversionPreferenceFragmentTest {
|
|||||||
mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
||||||
final SettingsMainSwitchPreference switchPreference =
|
final SettingsMainSwitchPreference switchPreference =
|
||||||
new SettingsMainSwitchPreference(context);
|
new SettingsMainSwitchPreference(context);
|
||||||
switchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);
|
switchPreference.setKey(getUseServicePreferenceKey());
|
||||||
mToggleServiceSwitchPreference = switchPreference;
|
mToggleServiceSwitchPreference = switchPreference;
|
||||||
setArguments(new Bundle());
|
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.OFF;
|
||||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
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;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -189,6 +188,6 @@ public class ToggleDaltonizerPreferenceFragmentTest {
|
|||||||
|
|
||||||
private SettingsMainSwitchPreference getMainFeatureToggle(
|
private SettingsMainSwitchPreference getMainFeatureToggle(
|
||||||
ToggleDaltonizerPreferenceFragment fragment) {
|
ToggleDaltonizerPreferenceFragment fragment) {
|
||||||
return fragment.findPreference(KEY_USE_SERVICE_PREFERENCE);
|
return fragment.findPreference(fragment.getUseServicePreferenceKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -235,8 +235,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public void onPreferenceToggledOnDisabledService_notShowTooltipView() {
|
public void onPreferenceToggledOnDisabledService_notShowTooltipView() {
|
||||||
mFragment.onPreferenceToggled(
|
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ false);
|
||||||
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ false);
|
|
||||||
|
|
||||||
assertThat(getLatestPopupWindow()).isNull();
|
assertThat(getLatestPopupWindow()).isNull();
|
||||||
}
|
}
|
||||||
@@ -245,8 +244,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public void onPreferenceToggledOnEnabledService_showTooltipView() {
|
public void onPreferenceToggledOnEnabledService_showTooltipView() {
|
||||||
mFragment.onPreferenceToggled(
|
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ true);
|
||||||
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
|
|
||||||
|
|
||||||
assertThat(getLatestPopupWindow().isShowing()).isTrue();
|
assertThat(getLatestPopupWindow().isShowing()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -258,8 +256,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
suwIntent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true);
|
suwIntent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true);
|
||||||
when(mActivity.getIntent()).thenReturn(suwIntent);
|
when(mActivity.getIntent()).thenReturn(suwIntent);
|
||||||
|
|
||||||
mFragment.onPreferenceToggled(
|
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ true);
|
||||||
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
|
|
||||||
|
|
||||||
assertThat(getLatestPopupWindow()).isNull();
|
assertThat(getLatestPopupWindow()).isNull();
|
||||||
}
|
}
|
||||||
@@ -268,12 +265,10 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public void onPreferenceToggledOnEnabledService_tooltipViewShown_notShowTooltipView() {
|
public void onPreferenceToggledOnEnabledService_tooltipViewShown_notShowTooltipView() {
|
||||||
mFragment.onPreferenceToggled(
|
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ true);
|
||||||
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
|
|
||||||
getLatestPopupWindow().dismiss();
|
getLatestPopupWindow().dismiss();
|
||||||
|
|
||||||
mFragment.onPreferenceToggled(
|
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ true);
|
||||||
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
|
|
||||||
|
|
||||||
assertThat(getLatestPopupWindow().isShowing()).isFalse();
|
assertThat(getLatestPopupWindow().isShowing()).isFalse();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user