Migrate to DashboardFragment in ToggleFeaturePreferenceFragment

Root Cause: ToggleFeaturePrefreferenceFragment becomes heavy when more and more features come in.

Solution: Mirgrate to DashboardFragment, a plugin-style preference controllers, can help us separate the preference and its logic into its own controller.

* This is the first step for the whole migration. Change to extend DashboardFragment and fill up the missing override functions.
* Reorder fields and functions to the recommended general approach.

Bug: 171272809
Test: make RunSettingsRoboTests
ROBOTEST_FILTER=com.android.settings.accessibility

Change-Id: I852091700a4b3b3c7bbdbc82f0b5dc47c087d61c
This commit is contained in:
jasonwshsu
2022-07-10 11:59:04 +08:00
parent 95726e0bad
commit 8145631ab8
9 changed files with 249 additions and 238 deletions

View File

@@ -49,9 +49,11 @@ import java.util.List;
/** Fragment for providing open activity button. */ /** Fragment for providing open activity button. */
public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeaturePreferenceFragment { public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeaturePreferenceFragment {
private static final String TAG = "LaunchA11yActivity";
private static final String TAG = "LaunchAccessibilityActivityPreferenceFragment";
private static final String EMPTY_STRING = ""; private static final String EMPTY_STRING = "";
protected static final String KEY_LAUNCH_PREFERENCE = "launch_preference"; protected static final String KEY_LAUNCH_PREFERENCE = "launch_preference";
private ComponentName mTileComponentName; private ComponentName mTileComponentName;
@Override @Override
@@ -70,10 +72,10 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
final View view = super.onCreateView(inflater, container, savedInstanceState);
// Init new preference to replace the switch preference instead. // Init new preference to replace the switch preference instead.
initLaunchPreference(); initLaunchPreference();
final View view = super.onCreateView(inflater, container, savedInstanceState);
removePreference(KEY_USE_SERVICE_PREFERENCE); removePreference(KEY_USE_SERVICE_PREFERENCE);
return view; return view;
} }
@@ -173,6 +175,7 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
/** Customizes the order by preference key. */ /** Customizes the order by preference key. */
protected List<String> getPreferenceOrderList() { protected List<String> getPreferenceOrderList() {
final List<String> lists = new ArrayList<>(); final List<String> lists = new ArrayList<>();
lists.add(KEY_TOP_INTRO_PREFERENCE);
lists.add(KEY_ANIMATED_IMAGE); lists.add(KEY_ANIMATED_IMAGE);
lists.add(KEY_LAUNCH_PREFERENCE); lists.add(KEY_LAUNCH_PREFERENCE);
lists.add(KEY_GENERAL_CATEGORY); lists.add(KEY_GENERAL_CATEGORY);
@@ -230,4 +233,15 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
return settingsIntent; return settingsIntent;
} }
@Override
protected int getPreferenceScreenResId() {
// TODO(b/171272809): Add back when controllers move to static type
return 0;
}
@Override
protected String getLogTag() {
return TAG;
}
} }

View File

@@ -61,9 +61,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
private static final String TAG = "ToggleAccessibilityServicePreferenceFragment"; private static final String TAG = "ToggleAccessibilityServicePreferenceFragment";
private static final String KEY_HAS_LOGGED = "has_logged"; private static final String KEY_HAS_LOGGED = "has_logged";
private AtomicBoolean mIsDialogShown = new AtomicBoolean(/* initialValue= */ false); private final AtomicBoolean mIsDialogShown = new AtomicBoolean(/* initialValue= */ false);
private static final String EMPTY_STRING = "";
private Dialog mWarningDialog; private Dialog mWarningDialog;
private ComponentName mTileComponentName; private ComponentName mTileComponentName;
@@ -85,7 +83,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
} }
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater infalter) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Do not call super. We don't want to see the "Help & feedback" option on this page so as // Do not call super. We don't want to see the "Help & feedback" option on this page so as
// not to confuse users who think they might be able to send feedback about a specific // not to confuse users who think they might be able to send feedback about a specific
// accessibility service from this page. // accessibility service from this page.
@@ -125,11 +123,6 @@ public class ToggleAccessibilityServicePreferenceFragment extends
updateSwitchBarToggleSwitch(); updateSwitchBarToggleSwitch();
} }
@Override
public void onPause() {
super.onPause();
}
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
if (mStartTimeMillsForLogging > 0) { if (mStartTimeMillsForLogging > 0) {
@@ -148,10 +141,8 @@ public class ToggleAccessibilityServicePreferenceFragment extends
AccessibilityUtils.setAccessibilityServiceState(getPrefContext(), toggledService, enabled); AccessibilityUtils.setAccessibilityServiceState(getPrefContext(), toggledService, enabled);
} }
// IMPORTANT: Refresh the info since there are dynamically changing // IMPORTANT: Refresh the info since there are dynamically changing capabilities. For
// capabilities. For // example, before JellyBean MR2 the user was granting the explore by touch one.
// example, before JellyBean MR2 the user was granting the explore by touch
// one.
@Nullable @Nullable
AccessibilityServiceInfo getAccessibilityServiceInfo() { AccessibilityServiceInfo getAccessibilityServiceInfo() {
final List<AccessibilityServiceInfo> infos = AccessibilityManager.getInstance( final List<AccessibilityServiceInfo> infos = AccessibilityManager.getInstance(
@@ -454,6 +445,17 @@ public class ToggleAccessibilityServicePreferenceFragment extends
unregisterPackageRemoveReceiver(); unregisterPackageRemoveReceiver();
} }
@Override
protected int getPreferenceScreenResId() {
// TODO(b/171272809): Add back when controllers move to static type
return 0;
}
@Override
protected String getLogTag() {
return TAG;
}
private void onAllowButtonFromEnableToggleClicked() { private void onAllowButtonFromEnableToggleClicked() {
handleConfirmServiceEnabled(/* confirmed= */ true); handleConfirmServiceEnabled(/* confirmed= */ true);
if (isServiceSupportAccessibilityButton()) { if (isServiceSupportAccessibilityButton()) {

View File

@@ -42,11 +42,39 @@ import java.util.List;
/** Settings page for color inversion. */ /** Settings page for color inversion. */
public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePreferenceFragment { public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePreferenceFragment {
private static final String TAG = "ToggleColorInversionPreferenceFragment";
private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED; private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED;
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { protected void registerKeysToObserverCallback(
super.onActivityCreated(savedInstanceState); AccessibilitySettingsContentObserver contentObserver) {
super.registerKeysToObserverCallback(contentObserver);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(ENABLED);
contentObserver.registerKeysToObserverCallback(enableServiceFeatureKeys,
key -> updateSwitchBarToggleSwitch());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mComponentName = COLOR_INVERSION_COMPONENT_NAME;
mPackageName = getText(R.string.accessibility_display_inversion_preference_title);
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.accessibility_color_inversion_banner))
.build();
final View view = super.onCreateView(inflater, container, savedInstanceState);
updateFooterPreference();
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final View rootView = getActivity().getWindow().peekDecorView(); final View rootView = getActivity().getWindow().peekDecorView();
if (rootView != null) { if (rootView != null) {
rootView.setAccessibilityPaneTitle(getString( rootView.setAccessibilityPaneTitle(getString(
@@ -78,6 +106,11 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
return R.xml.accessibility_color_inversion_settings; return R.xml.accessibility_color_inversion_settings;
} }
@Override
protected String getLogTag() {
return TAG;
}
@Override @Override
protected void onRemoveSwitchPreferenceToggleSwitch() { protected void onRemoveSwitchPreferenceToggleSwitch() {
super.onRemoveSwitchPreferenceToggleSwitch(); super.onRemoveSwitchPreferenceToggleSwitch();
@@ -94,33 +127,6 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
return getText(R.string.accessibility_display_inversion_shortcut_title); return getText(R.string.accessibility_display_inversion_shortcut_title);
} }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mComponentName = COLOR_INVERSION_COMPONENT_NAME;
mPackageName = getText(R.string.accessibility_display_inversion_preference_title);
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.accessibility_color_inversion_banner))
.build();
final View view = super.onCreateView(inflater, container, savedInstanceState);
updateFooterPreference();
return view;
}
@Override
protected void registerKeysToObserverCallback(
AccessibilitySettingsContentObserver contentObserver) {
super.registerKeysToObserverCallback(contentObserver);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(ENABLED);
contentObserver.registerKeysToObserverCallback(enableServiceFeatureKeys,
key -> updateSwitchBarToggleSwitch());
}
private void updateFooterPreference() { private void updateFooterPreference() {
final String title = getPrefContext().getString( final String title = getPrefContext().getString(
R.string.accessibility_color_inversion_about_title); R.string.accessibility_color_inversion_about_title);

View File

@@ -51,6 +51,7 @@ import java.util.List;
public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceFragment public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceFragment
implements DaltonizerRadioButtonPreferenceController.OnChangeListener { implements DaltonizerRadioButtonPreferenceController.OnChangeListener {
private static final String TAG = "ToggleDaltonizerPreferenceFragment";
private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED; private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED;
private static final String KEY_PREVIEW = "daltonizer_preview"; private static final String KEY_PREVIEW = "daltonizer_preview";
@VisibleForTesting @VisibleForTesting
@@ -70,29 +71,24 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF
final String[] daltonizerKeys = resources.getStringArray( final String[] daltonizerKeys = resources.getStringArray(
R.array.daltonizer_mode_keys); R.array.daltonizer_mode_keys);
for (int i = 0; i < daltonizerKeys.length; i++) { for (String daltonizerKey : daltonizerKeys) {
sControllers.add(new DaltonizerRadioButtonPreferenceController( sControllers.add(new DaltonizerRadioButtonPreferenceController(
context, lifecycle, daltonizerKeys[i])); context, lifecycle, daltonizerKey));
} }
} }
return sControllers; return sControllers;
} }
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final View rootView = getActivity().getWindow().peekDecorView();
if (rootView != null) {
rootView.setAccessibilityPaneTitle(getString(
R.string.accessibility_display_daltonizer_preference_title));
}
}
@Override @Override
public void onCheckedChanged(Preference preference) { protected void registerKeysToObserverCallback(
for (AbstractPreferenceController controller : sControllers) { AccessibilitySettingsContentObserver contentObserver) {
controller.updateState(preference); super.registerKeysToObserverCallback(contentObserver);
}
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(ENABLED);
contentObserver.registerKeysToObserverCallback(enableServiceFeatureKeys,
key -> updateSwitchBarToggleSwitch());
} }
@Override @Override
@@ -108,14 +104,20 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF
} }
@Override @Override
protected void registerKeysToObserverCallback( public void onViewCreated(View view, Bundle savedInstanceState) {
AccessibilitySettingsContentObserver contentObserver) { super.onViewCreated(view, savedInstanceState);
super.registerKeysToObserverCallback(contentObserver); final View rootView = getActivity().getWindow().peekDecorView();
if (rootView != null) {
rootView.setAccessibilityPaneTitle(getString(
R.string.accessibility_display_daltonizer_preference_title));
}
}
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1); @Override
enableServiceFeatureKeys.add(ENABLED); public void onCheckedChanged(Preference preference) {
contentObserver.registerKeysToObserverCallback(enableServiceFeatureKeys, for (AbstractPreferenceController controller : sControllers) {
key -> updateSwitchBarToggleSwitch()); controller.updateState(preference);
}
} }
private void updateFooterPreference() { private void updateFooterPreference() {
@@ -179,6 +181,11 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF
return R.xml.accessibility_daltonizer_settings; return R.xml.accessibility_daltonizer_settings;
} }
@Override
protected String getLogTag() {
return TAG;
}
@Override @Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) { protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
final boolean isEnabled = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON; final boolean isEnabled = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON;

View File

@@ -54,10 +54,10 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType; import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType; import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.utils.LocaleUtils; import com.android.settings.utils.LocaleUtils;
import com.android.settings.widget.SettingsMainSwitchBar; import com.android.settings.widget.SettingsMainSwitchBar;
import com.android.settings.widget.SettingsMainSwitchPreference; import com.android.settings.widget.SettingsMainSwitchPreference;
@@ -76,9 +76,24 @@ import java.util.Locale;
* Base class for accessibility fragments with toggle, shortcut, some helper functions * Base class for accessibility fragments with toggle, shortcut, some helper functions
* and dialog management. * and dialog management.
*/ */
public abstract class ToggleFeaturePreferenceFragment extends SettingsPreferenceFragment public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
implements ShortcutPreference.OnClickCallback, OnMainSwitchChangeListener { implements ShortcutPreference.OnClickCallback, OnMainSwitchChangeListener {
public static final String KEY_GENERAL_CATEGORY = "general_categories";
public static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
public static final int NOT_SET = -1;
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_USER_SHORTCUT_TYPE = "shortcut_type";
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_ANIMATED_IMAGE = "animated_image";
// For html description of accessibility service, must follow the rule, such as
// <img src="R.drawable.fileName"/>, a11y settings will get the resources successfully.
private static final String IMG_PREFIX = "R.drawable.";
private static final String DRAWABLE_FOLDER = "drawable";
protected TopIntroPreference mTopIntroPreference; protected TopIntroPreference mTopIntroPreference;
protected SettingsMainSwitchPreference mToggleServiceSwitchPreference; protected SettingsMainSwitchPreference mToggleServiceSwitchPreference;
protected ShortcutPreference mShortcutPreference; protected ShortcutPreference mShortcutPreference;
@@ -86,28 +101,17 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
protected AccessibilityFooterPreferenceController mFooterPreferenceController; protected AccessibilityFooterPreferenceController mFooterPreferenceController;
protected String mPreferenceKey; protected String mPreferenceKey;
protected Dialog mDialog; protected Dialog mDialog;
protected CharSequence mSettingsTitle; protected CharSequence mSettingsTitle;
protected Intent mSettingsIntent; protected Intent mSettingsIntent;
// The mComponentName maybe null, such as Magnify // The mComponentName maybe null, such as Magnify
protected ComponentName mComponentName; protected ComponentName mComponentName;
protected CharSequence mPackageName; protected CharSequence mPackageName;
protected Uri mImageUri; protected Uri mImageUri;
private CharSequence mDescription;
protected CharSequence mHtmlDescription; protected CharSequence mHtmlDescription;
protected CharSequence mTopIntroTitle; protected CharSequence mTopIntroTitle;
// Save user's shortcutType value when savedInstance has value (e.g. device rotated).
private static final String DRAWABLE_FOLDER = "drawable"; protected int mSavedCheckBoxValue = NOT_SET;
protected static final String KEY_TOP_INTRO_PREFERENCE = "top_intro"; private CharSequence mDescription;
protected static final String KEY_USE_SERVICE_PREFERENCE = "use_service";
public static final String KEY_GENERAL_CATEGORY = "general_categories";
protected static final String KEY_HTML_DESCRIPTION_PREFERENCE = "html_description";
public static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
protected static final String KEY_SAVED_USER_SHORTCUT_TYPE = "shortcut_type";
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_ANIMATED_IMAGE = "animated_image";
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener; private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
private AccessibilitySettingsContentObserver mSettingsContentObserver; private AccessibilitySettingsContentObserver mSettingsContentObserver;
@@ -117,18 +121,8 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
private AccessibilityQuickSettingsTooltipWindow mTooltipWindow; private AccessibilityQuickSettingsTooltipWindow mTooltipWindow;
private boolean mNeedsQSTooltipReshow = false; private boolean mNeedsQSTooltipReshow = false;
private int mNeedsQSTooltipType = QuickSettingsTooltipType.GUIDE_TO_EDIT; private int mNeedsQSTooltipType = QuickSettingsTooltipType.GUIDE_TO_EDIT;
public static final int NOT_SET = -1;
// Save user's shortcutType value when savedInstance has value (e.g. device rotated).
protected int mSavedCheckBoxValue = NOT_SET;
private boolean mSavedAccessibilityFloatingMenuEnabled; private boolean mSavedAccessibilityFloatingMenuEnabled;
// For html description of accessibility service, must follow the rule, such as
// <img src="R.drawable.fileName"/>, a11y settings will get the resources successfully.
private static final String IMG_PREFIX = "R.drawable.";
private ImageView mImageGetterCacheView; private ImageView mImageGetterCacheView;
private final Html.ImageGetter mImageGetter = (String str) -> { private final Html.ImageGetter mImageGetter = (String str) -> {
if (str != null && str.startsWith(IMG_PREFIX)) { if (str != null && str.startsWith(IMG_PREFIX)) {
final String fileName = str.substring(IMG_PREFIX.length()); final String fileName = str.substring(IMG_PREFIX.length());
@@ -211,6 +205,28 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
return super.onCreateView(inflater, container, savedInstanceState); return super.onCreateView(inflater, container, savedInstanceState);
} }
@Override
public Dialog onCreateDialog(int dialogId) {
switch (dialogId) {
case DialogEnums.EDIT_SHORTCUT:
final int dialogType = WizardManagerHelper.isAnySetupWizard(getIntent())
? DialogType.EDIT_SHORTCUT_GENERIC_SUW : DialogType.EDIT_SHORTCUT_GENERIC;
mDialog = AccessibilityDialogUtils.showEditShortcutDialog(
getPrefContext(), dialogType, getShortcutTitle(),
this::callOnAlertDialogCheckboxClicked);
setupEditShortcutDialog(mDialog);
return mDialog;
case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
mDialog = AccessibilityGestureNavigationTutorial
.createAccessibilityTutorialDialog(getPrefContext(),
getUserShortcutTypes(), this::callOnTutorialDialogButtonClicked);
mDialog.setCanceledOnTouchOutside(false);
return mDialog;
default:
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
}
}
@Override @Override
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
@@ -268,25 +284,9 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
} }
@Override @Override
public Dialog onCreateDialog(int dialogId) { public void onDestroyView() {
switch (dialogId) { super.onDestroyView();
case DialogEnums.EDIT_SHORTCUT: removeActionBarToggleSwitch();
final int dialogType = WizardManagerHelper.isAnySetupWizard(getIntent())
? DialogType.EDIT_SHORTCUT_GENERIC_SUW : DialogType.EDIT_SHORTCUT_GENERIC;
mDialog = AccessibilityDialogUtils.showEditShortcutDialog(
getPrefContext(), dialogType, getShortcutTitle(),
this::callOnAlertDialogCheckboxClicked);
setupEditShortcutDialog(mDialog);
return mDialog;
case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
mDialog = AccessibilityGestureNavigationTutorial
.createAccessibilityTutorialDialog(getPrefContext(),
getUserShortcutTypes(), this::callOnTutorialDialogButtonClicked);
mDialog.setCanceledOnTouchOutside(false);
return mDialog;
default:
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
}
} }
@Override @Override
@@ -311,12 +311,6 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
return 0; return 0;
} }
@Override
public void onDestroyView() {
super.onDestroyView();
removeActionBarToggleSwitch();
}
@Override @Override
public void onSwitchChanged(Switch switchView, boolean isChecked) { public void onSwitchChanged(Switch switchView, boolean isChecked) {
onPreferenceToggled(mPreferenceKey, isChecked); onPreferenceToggled(mPreferenceKey, isChecked);
@@ -335,7 +329,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) { protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
final CharSequence title = final CharSequence title =
getString(R.string.accessibility_service_primary_switch_title, mPackageName); getString(R.string.accessibility_service_primary_switch_title, mPackageName);
switchPreference.setTitle(title); switchPreference.setTitle(title);
} }
@@ -363,15 +357,6 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
// Implement this to update the state of switch. // Implement this to update the state of switch.
} }
private void installActionBarToggleSwitch() {
onInstallSwitchPreferenceToggleSwitch();
}
private void removeActionBarToggleSwitch() {
mToggleServiceSwitchPreference.setOnPreferenceClickListener(null);
onRemoveSwitchPreferenceToggleSwitch();
}
public void setTitle(String title) { public void setTitle(String title) {
getActivity().setTitle(title); getActivity().setTitle(title);
} }
@@ -405,15 +390,13 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
} }
} }
/** Customizes the order by preference key. */ private void installActionBarToggleSwitch() {
protected List<String> getPreferenceOrderList() { onInstallSwitchPreferenceToggleSwitch();
final List<String> lists = new ArrayList<>(); }
lists.add(KEY_TOP_INTRO_PREFERENCE);
lists.add(KEY_ANIMATED_IMAGE); private void removeActionBarToggleSwitch() {
lists.add(KEY_USE_SERVICE_PREFERENCE); mToggleServiceSwitchPreference.setOnPreferenceClickListener(null);
lists.add(KEY_GENERAL_CATEGORY); onRemoveSwitchPreferenceToggleSwitch();
lists.add(KEY_HTML_DESCRIPTION_PREFERENCE);
return lists;
} }
private void updatePreferenceOrder() { private void updatePreferenceOrder() {
@@ -431,6 +414,17 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
} }
} }
/** Customizes the order by preference key. */
protected List<String> getPreferenceOrderList() {
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(KEY_GENERAL_CATEGORY);
lists.add(KEY_HTML_DESCRIPTION_PREFERENCE);
return lists;
}
private Drawable getDrawableFromUri(Uri imageUri) { private Drawable getDrawableFromUri(Uri imageUri) {
if (mImageGetterCacheView == null) { if (mImageGetterCacheView == null) {
mImageGetterCacheView = new ImageView(getPrefContext()); mImageGetterCacheView = new ImageView(getPrefContext());
@@ -551,7 +545,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
// TODO(b/171272809): Migrate to DashboardFragment. // TODO(b/171272809): Migrate to DashboardFragment.
final String title = getString(R.string.accessibility_introduction_title, mPackageName); final String title = getString(R.string.accessibility_introduction_title, mPackageName);
mFooterPreferenceController = new AccessibilityFooterPreferenceController( mFooterPreferenceController = new AccessibilityFooterPreferenceController(
screen.getContext(), htmlFooterPreference.getKey()); screen.getContext(), htmlFooterPreference.getKey());
mFooterPreferenceController.setIntroductionTitle(title); mFooterPreferenceController.setIntroductionTitle(title);
mFooterPreferenceController.displayPreference(screen); mFooterPreferenceController.displayPreference(screen);
} }
@@ -568,8 +562,8 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
* Creates {@link AccessibilityFooterPreference} and append into {@link PreferenceScreen} * Creates {@link AccessibilityFooterPreference} and append into {@link PreferenceScreen}
* *
* @param screen The preference screen to add the footer preference * @param screen The preference screen to add the footer preference
* @param summary The summary of the preference summary. * @param summary The summary of the preference summary
* @param introductionTitle The title of introduction in the footer. * @param introductionTitle The title of introduction in the footer
*/ */
@VisibleForTesting @VisibleForTesting
void createFooterPreference(PreferenceScreen screen, CharSequence summary, void createFooterPreference(PreferenceScreen screen, CharSequence summary,
@@ -580,7 +574,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
screen.addPreference(footerPreference); screen.addPreference(footerPreference);
mFooterPreferenceController = new AccessibilityFooterPreferenceController( mFooterPreferenceController = new AccessibilityFooterPreferenceController(
screen.getContext(), footerPreference.getKey()); screen.getContext(), footerPreference.getKey());
mFooterPreferenceController.setIntroductionTitle(introductionTitle); mFooterPreferenceController.setIntroductionTitle(introductionTitle);
mFooterPreferenceController.displayPreference(screen); mFooterPreferenceController.displayPreference(screen);
} }
@@ -649,18 +643,6 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
return value; return value;
} }
private static CharSequence getSoftwareShortcutTypeSummary(Context context) {
int resId;
if (AccessibilityUtil.isFloatingMenuEnabled(context)) {
resId = R.string.accessibility_shortcut_edit_summary_software;
} else if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
resId = R.string.accessibility_shortcut_edit_summary_software_gesture;
} else {
resId = R.string.accessibility_shortcut_edit_summary_software;
}
return context.getText(resId);
}
protected CharSequence getShortcutTypeSummary(Context context) { protected CharSequence getShortcutTypeSummary(Context context) {
if (!mShortcutPreference.isSettingsEditable()) { if (!mShortcutPreference.isSettingsEditable()) {
return context.getText(R.string.accessibility_shortcut_edit_dialog_title_hardware); return context.getText(R.string.accessibility_shortcut_edit_dialog_title_hardware);
@@ -692,6 +674,18 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
null, LocaleUtils.getConcatenatedString(list)); null, LocaleUtils.getConcatenatedString(list));
} }
private static CharSequence getSoftwareShortcutTypeSummary(Context context) {
int resId;
if (AccessibilityUtil.isFloatingMenuEnabled(context)) {
resId = R.string.accessibility_shortcut_edit_summary_software;
} else if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
resId = R.string.accessibility_shortcut_edit_summary_software_gesture;
} else {
resId = R.string.accessibility_shortcut_edit_summary_software;
}
return context.getText(resId);
}
/** /**
* This method will be invoked when a button in the tutorial dialog is clicked. * This method will be invoked when a button in the tutorial dialog is clicked.
* *

View File

@@ -49,19 +49,30 @@ import java.util.List;
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePreferenceFragment { public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePreferenceFragment {
private static final String REDUCE_BRIGHT_COLORS_ACTIVATED_KEY = private static final String TAG = "ToggleReduceBrightColorsPreferenceFragment";
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED;
private static final String KEY_INTENSITY = "rbc_intensity"; private static final String KEY_INTENSITY = "rbc_intensity";
private static final String KEY_PERSIST = "rbc_persist"; private static final String KEY_PERSIST = "rbc_persist";
private static final String REDUCE_BRIGHT_COLORS_ACTIVATED_KEY =
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED;
private ReduceBrightColorsIntensityPreferenceController mRbcIntensityPreferenceController; private ReduceBrightColorsIntensityPreferenceController mRbcIntensityPreferenceController;
private ReduceBrightColorsPersistencePreferenceController mRbcPersistencePreferenceController; private ReduceBrightColorsPersistencePreferenceController mRbcPersistencePreferenceController;
private ColorDisplayManager mColorDisplayManager; private ColorDisplayManager mColorDisplayManager;
@Override
protected void registerKeysToObserverCallback(
AccessibilitySettingsContentObserver contentObserver) {
super.registerKeysToObserverCallback(contentObserver);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(REDUCE_BRIGHT_COLORS_ACTIVATED_KEY);
contentObserver.registerKeysToObserverCallback(enableServiceFeatureKeys,
key -> updateSwitchBarToggleSwitch());
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
mImageUri = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) mImageUri = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
.authority(getPrefContext().getPackageName()) .authority(getPrefContext().getPackageName())
.appendPath(String.valueOf(R.raw.extra_dim_banner)) .appendPath(String.valueOf(R.raw.extra_dim_banner))
@@ -85,17 +96,6 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
return view; return view;
} }
@Override
protected void registerKeysToObserverCallback(
AccessibilitySettingsContentObserver contentObserver) {
super.registerKeysToObserverCallback(contentObserver);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(REDUCE_BRIGHT_COLORS_ACTIVATED_KEY);
contentObserver.registerKeysToObserverCallback(enableServiceFeatureKeys,
key -> updateSwitchBarToggleSwitch());
}
private void updateGeneralCategoryOrder() { private void updateGeneralCategoryOrder() {
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY); final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
final SeekBarPreference intensity = findPreference(KEY_INTENSITY); final SeekBarPreference intensity = findPreference(KEY_INTENSITY);
@@ -114,22 +114,12 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
mFooterPreferenceController.displayPreference(getPreferenceScreen()); mFooterPreferenceController.displayPreference(getPreferenceScreen());
} }
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
updateSwitchBarToggleSwitch(); updateSwitchBarToggleSwitch();
} }
@Override
public void onPause() {
super.onPause();
}
@Override @Override
public int getMetricsCategory() { public int getMetricsCategory() {
return SettingsEnums.REDUCE_BRIGHT_COLORS_SETTINGS; return SettingsEnums.REDUCE_BRIGHT_COLORS_SETTINGS;
@@ -137,7 +127,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
@Override @Override
public int getHelpResource() { public int getHelpResource() {
// TODO(170973645): Link to help support page // TODO(b/170973645): Link to help support page
return 0; return 0;
} }
@@ -146,6 +136,11 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
return R.xml.reduce_bright_colors_settings; return R.xml.reduce_bright_colors_settings;
} }
@Override
protected String getLogTag() {
return TAG;
}
@Override @Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) { protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
if (enabled) { if (enabled) {
@@ -186,8 +181,8 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
@Override @Override
CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) { CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
return getText(type == QuickSettingsTooltipType.GUIDE_TO_EDIT return getText(type == QuickSettingsTooltipType.GUIDE_TO_EDIT
? R.string.accessibility_reduce_bright_colors_qs_tooltip_content ? R.string.accessibility_reduce_bright_colors_qs_tooltip_content
: R.string.accessibility_reduce_bright_colors_auto_added_qs_tooltip_content); : R.string.accessibility_reduce_bright_colors_auto_added_qs_tooltip_content);
} }
@Override @Override

View File

@@ -66,22 +66,22 @@ import java.util.StringJoiner;
public class ToggleScreenMagnificationPreferenceFragment extends public class ToggleScreenMagnificationPreferenceFragment extends
ToggleFeaturePreferenceFragment implements ToggleFeaturePreferenceFragment implements
MagnificationModePreferenceController.DialogHelper { MagnificationModePreferenceController.DialogHelper {
// TODO(b/147021230): Move duplicated functions with android/internal/accessibility into util.
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox;
private CheckBox mTripleTapTypeCheckBox;
private static final String TAG = "ToggleScreenMagnificationPreferenceFragment";
private static final char COMPONENT_NAME_SEPARATOR = ':'; private static final char COMPONENT_NAME_SEPARATOR = ':';
private static final TextUtils.SimpleStringSplitter sStringColonSplitter = private static final TextUtils.SimpleStringSplitter sStringColonSplitter =
new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR); new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR);
protected SwitchPreference mFollowingTypingSwitchPreference;
// TODO(b/147021230): Move duplicated functions with android/internal/accessibility into util.
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox;
private CheckBox mTripleTapTypeCheckBox;
private DialogCreatable mDialogDelegate; private DialogCreatable mDialogDelegate;
private MagnificationFollowTypingPreferenceController mFollowTypingPreferenceController; private MagnificationFollowTypingPreferenceController mFollowTypingPreferenceController;
protected SwitchPreference mFollowingTypingSwitchPreference;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@@ -125,6 +125,17 @@ public class ToggleScreenMagnificationPreferenceFragment extends
am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener); am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
} }
@Override
protected int getPreferenceScreenResId() {
// TODO(b/171272809): Add back when controllers move to static type
return 0;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override @Override
public void onPause() { public void onPause() {
final AccessibilityManager am = getPrefContext().getSystemService( final AccessibilityManager am = getPrefContext().getSystemService(
@@ -623,15 +634,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return false; return false;
} }
private boolean isWindowMagnification(Context context) {
final int mode = Settings.Secure.getIntForUser(
context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE,
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN,
context.getContentResolver().getUserId());
return mode == Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW;
}
private static int getUserShortcutTypeFromSettings(Context context) { private static int getUserShortcutTypeFromSettings(Context context) {
int shortcutTypes = UserShortcutType.EMPTY; int shortcutTypes = UserShortcutType.EMPTY;
if (hasMagnificationValuesInSettings(context, UserShortcutType.SOFTWARE)) { if (hasMagnificationValuesInSettings(context, UserShortcutType.SOFTWARE)) {

View File

@@ -16,7 +16,6 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import static com.android.settings.accessibility.ToggleFeaturePreferenceFragment.KEY_SAVED_QS_TOOLTIP_RESHOW;
import static com.android.settings.accessibility.ToggleFeaturePreferenceFragment.KEY_SAVED_USER_SHORTCUT_TYPE; import static com.android.settings.accessibility.ToggleFeaturePreferenceFragment.KEY_SAVED_USER_SHORTCUT_TYPE;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -41,7 +40,6 @@ import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import androidx.annotation.XmlRes;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@@ -115,15 +113,15 @@ public class ToggleFeaturePreferenceFragmentTest {
final PreferenceScreen screen = spy(new PreferenceScreen(mContext, null)); final PreferenceScreen screen = spy(new PreferenceScreen(mContext, null));
when(screen.getPreferenceManager()).thenReturn(mPreferenceManager); when(screen.getPreferenceManager()).thenReturn(mPreferenceManager);
doReturn(screen).when(mFragment).getPreferenceScreen(); doReturn(screen).when(mFragment).getPreferenceScreen();
mContext.setTheme(R.style.Theme_AppCompat);
} }
@Test @Test
public void createFragment_shouldOnlyAddPreferencesOnce() { public void setupFragment_getExpectedPreferenceScreenResId() {
FragmentController.setupFragment(mFragment, FragmentActivity.class, FragmentController.setupFragment(mFragment, FragmentActivity.class,
/* containerViewId= */ 0, /* bundle= */ null); /* containerViewId= */ 0, Bundle.EMPTY);
// execute exactly once assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(R.xml.placeholder_prefs);
verify(mFragment).addPreferencesFromResource(R.xml.placeholder_prefs);
} }
@Test @Test
@@ -186,7 +184,6 @@ public class ToggleFeaturePreferenceFragmentTest {
@Test @Test
public void dialogCheckboxClicked_hardwareType_skipTimeoutRestriction() { public void dialogCheckboxClicked_hardwareType_skipTimeoutRestriction() {
mContext.setTheme(R.style.Theme_AppCompat);
final ShortcutPreference shortcutPreference = new ShortcutPreference(mContext, /* attrs= */ final ShortcutPreference shortcutPreference = new ShortcutPreference(mContext, /* attrs= */
null); null);
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME; mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
@@ -208,7 +205,6 @@ public class ToggleFeaturePreferenceFragmentTest {
@Test @Test
public void setupEditShortcutDialog_shortcutPreferenceOff_checkboxIsEmptyValue() { public void setupEditShortcutDialog_shortcutPreferenceOff_checkboxIsEmptyValue() {
mContext.setTheme(R.style.Theme_AppCompat);
final AlertDialog dialog = AccessibilityDialogUtils.showEditShortcutDialog( final AlertDialog dialog = AccessibilityDialogUtils.showEditShortcutDialog(
mContext, DialogType.EDIT_SHORTCUT_GENERIC, PLACEHOLDER_DIALOG_TITLE, mContext, DialogType.EDIT_SHORTCUT_GENERIC, PLACEHOLDER_DIALOG_TITLE,
this::callEmptyOnClicked); this::callEmptyOnClicked);
@@ -226,7 +222,6 @@ public class ToggleFeaturePreferenceFragmentTest {
@Test @Test
public void setupEditShortcutDialog_shortcutPreferenceOn_checkboxIsSavedValue() { public void setupEditShortcutDialog_shortcutPreferenceOn_checkboxIsSavedValue() {
mContext.setTheme(R.style.Theme_AppCompat);
final AlertDialog dialog = AccessibilityDialogUtils.showEditShortcutDialog( final AlertDialog dialog = AccessibilityDialogUtils.showEditShortcutDialog(
mContext, DialogType.EDIT_SHORTCUT_GENERIC, PLACEHOLDER_DIALOG_TITLE, mContext, DialogType.EDIT_SHORTCUT_GENERIC, PLACEHOLDER_DIALOG_TITLE,
this::callEmptyOnClicked); this::callEmptyOnClicked);
@@ -248,7 +243,6 @@ public class ToggleFeaturePreferenceFragmentTest {
@Test @Test
@Config(shadows = ShadowFragment.class) @Config(shadows = ShadowFragment.class)
public void restoreValueFromSavedInstanceState_assignShortcutTypeToVariable() { public void restoreValueFromSavedInstanceState_assignShortcutTypeToVariable() {
mContext.setTheme(R.style.Theme_AppCompat);
final AlertDialog dialog = AccessibilityDialogUtils.showEditShortcutDialog( final AlertDialog dialog = AccessibilityDialogUtils.showEditShortcutDialog(
mContext, DialogType.EDIT_SHORTCUT_GENERIC, PLACEHOLDER_DIALOG_TITLE, mContext, DialogType.EDIT_SHORTCUT_GENERIC, PLACEHOLDER_DIALOG_TITLE,
this::callEmptyOnClicked); this::callEmptyOnClicked);
@@ -273,9 +267,8 @@ public class ToggleFeaturePreferenceFragmentTest {
@Test @Test
@Config(shadows = ShadowFragment.class) @Config(shadows = ShadowFragment.class)
public void onPreferenceToggledOnDisabledService_notShowTooltipView() { public void onPreferenceToggledOnDisabledService_notShowTooltipView() {
mContext.setTheme(R.style.Theme_AppCompat); mFragment.onPreferenceToggled(
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ false);
mFragment.onPreferenceToggled(mFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ false);
assertThat(getLatestPopupWindow()).isNull(); assertThat(getLatestPopupWindow()).isNull();
} }
@@ -283,9 +276,8 @@ public class ToggleFeaturePreferenceFragmentTest {
@Test @Test
@Config(shadows = ShadowFragment.class) @Config(shadows = ShadowFragment.class)
public void onPreferenceToggledOnEnabledService_showTooltipView() { public void onPreferenceToggledOnEnabledService_showTooltipView() {
mContext.setTheme(R.style.Theme_AppCompat); mFragment.onPreferenceToggled(
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
mFragment.onPreferenceToggled(mFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
assertThat(getLatestPopupWindow().isShowing()).isTrue(); assertThat(getLatestPopupWindow().isShowing()).isTrue();
} }
@@ -293,32 +285,16 @@ public class ToggleFeaturePreferenceFragmentTest {
@Test @Test
@Config(shadows = ShadowFragment.class) @Config(shadows = ShadowFragment.class)
public void onPreferenceToggledOnEnabledService_tooltipViewShown_notShowTooltipView() { public void onPreferenceToggledOnEnabledService_tooltipViewShown_notShowTooltipView() {
mContext.setTheme(R.style.Theme_AppCompat); mFragment.onPreferenceToggled(
mFragment.onPreferenceToggled(mFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true); ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
getLatestPopupWindow().dismiss(); getLatestPopupWindow().dismiss();
mFragment.onPreferenceToggled(mFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true); mFragment.onPreferenceToggled(
ToggleFeaturePreferenceFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
assertThat(getLatestPopupWindow().isShowing()).isFalse(); assertThat(getLatestPopupWindow().isShowing()).isFalse();
} }
@Test
@Config(shadows = ShadowFragment.class)
public void restoreValueFromSavedInstanceState_showTooltipView() {
mContext.setTheme(R.style.Theme_AppCompat);
mFragment.onPreferenceToggled(mFragment.KEY_USE_SERVICE_PREFERENCE, /* enabled= */ true);
assertThat(getLatestPopupWindow().isShowing()).isTrue();
final Bundle savedInstanceState = new Bundle();
savedInstanceState.putBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW, /* value= */ true);
mFragment.onCreate(savedInstanceState);
mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
mFragment.onViewCreated(mFragment.getView(), savedInstanceState);
mFragment.onAttach(mContext);
assertThat(getLatestPopupWindow().isShowing()).isTrue();
}
@Test @Test
public void initTopIntroPreference_hasTopIntroTitle_shouldSetAsExpectedValue() { public void initTopIntroPreference_hasTopIntroTitle_shouldSetAsExpectedValue() {
mFragment.mTopIntroTitle = DEFAULT_TOP_INTRO; mFragment.mTopIntroTitle = DEFAULT_TOP_INTRO;
@@ -394,6 +370,21 @@ public class ToggleFeaturePreferenceFragmentTest {
return R.xml.placeholder_prefs; return R.xml.placeholder_prefs;
} }
@Override
protected String getLogTag() {
return null;
}
@Override
protected void onProcessArguments(Bundle arguments) {
// do nothing
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
// do nothing
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@@ -410,11 +401,6 @@ public class ToggleFeaturePreferenceFragmentTest {
// do nothing // do nothing
} }
@Override
public void addPreferencesFromResource(@XmlRes int preferencesResId) {
// do nothing
}
@Override @Override
protected void updateShortcutPreference() { protected void updateShortcutPreference() {
// UI related function, do nothing in tests // UI related function, do nothing in tests

View File

@@ -468,6 +468,11 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
return mPreferenceManager; return mPreferenceManager;
} }
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
// do nothing
}
@Override @Override
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
// do nothing // do nothing