Accessibility framework & Settings to support the Android accessibility intro & footer

- Implements a TopIntroPreference into the Accessibility Settings base fragment.
- Creates a protected API or variable to provide content to support if needed.

Bug: 218407398
Test: make RunSettingsRoboTests ROBOTEST_FILTER=ToggleFeaturePreferenceFragmentTest
Change-Id: Id0f7700bb8f62960951913db8bd034fce1b15a90
This commit is contained in:
menghanli
2022-02-08 14:06:24 +08:00
parent d920ad507c
commit 426e781f19
2 changed files with 35 additions and 0 deletions

View File

@@ -63,6 +63,7 @@ import com.android.settings.widget.SettingsMainSwitchPreference;
import com.android.settingslib.accessibility.AccessibilityUtils; import com.android.settingslib.accessibility.AccessibilityUtils;
import com.android.settingslib.widget.IllustrationPreference; import com.android.settingslib.widget.IllustrationPreference;
import com.android.settingslib.widget.OnMainSwitchChangeListener; import com.android.settingslib.widget.OnMainSwitchChangeListener;
import com.android.settingslib.widget.TopIntroPreference;
import com.google.android.setupcompat.util.WizardManagerHelper; import com.google.android.setupcompat.util.WizardManagerHelper;
@@ -92,8 +93,10 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
protected Uri mImageUri; protected Uri mImageUri;
private CharSequence mDescription; private CharSequence mDescription;
protected CharSequence mHtmlDescription; protected CharSequence mHtmlDescription;
protected CharSequence mTopIntroTitle;
private static final String DRAWABLE_FOLDER = "drawable"; private static final String DRAWABLE_FOLDER = "drawable";
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_USE_SERVICE_PREFERENCE = "use_service";
public static final String KEY_GENERAL_CATEGORY = "general_categories"; public static final String KEY_GENERAL_CATEGORY = "general_categories";
protected static final String KEY_HTML_DESCRIPTION_PREFERENCE = "html_description"; protected static final String KEY_HTML_DESCRIPTION_PREFERENCE = "html_description";
@@ -182,6 +185,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
// Need to be called as early as possible. Protected variables will be assigned here. // Need to be called as early as possible. Protected variables will be assigned here.
onProcessArguments(getArguments()); onProcessArguments(getArguments());
initTopIntroPreference();
initAnimatedImagePreference(); initAnimatedImagePreference();
initToggleServiceSwitchPreference(); initToggleServiceSwitchPreference();
initGeneralCategory(); initGeneralCategory();
@@ -393,6 +397,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
/** 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_USE_SERVICE_PREFERENCE); lists.add(KEY_USE_SERVICE_PREFERENCE);
lists.add(KEY_GENERAL_CATEGORY); lists.add(KEY_GENERAL_CATEGORY);
@@ -461,6 +466,17 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
getPreferenceScreen().addPreference(illustrationPreference); getPreferenceScreen().addPreference(illustrationPreference);
} }
@VisibleForTesting
void initTopIntroPreference() {
if (TextUtils.isEmpty(mTopIntroTitle)) {
return;
}
final TopIntroPreference topIntroPreference = new TopIntroPreference(getPrefContext());
topIntroPreference.setKey(KEY_TOP_INTRO_PREFERENCE);
topIntroPreference.setTitle(mTopIntroTitle);
getPreferenceScreen().addPreference(topIntroPreference);
}
private void initToggleServiceSwitchPreference() { private void initToggleServiceSwitchPreference() {
mToggleServiceSwitchPreference = new SettingsMainSwitchPreference(getPrefContext()); mToggleServiceSwitchPreference = new SettingsMainSwitchPreference(getPrefContext());
mToggleServiceSwitchPreference.setKey(KEY_USE_SERVICE_PREFERENCE); mToggleServiceSwitchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);

View File

@@ -51,6 +51,7 @@ import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType; import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType;
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType; import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.testutils.shadow.ShadowFragment; import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settingslib.widget.TopIntroPreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -81,6 +82,7 @@ public class ToggleFeaturePreferenceFragmentTest {
private static final String PLACEHOLDER_DIALOG_TITLE = "title"; private static final String PLACEHOLDER_DIALOG_TITLE = "title";
private static final String DEFAULT_SUMMARY = "default summary"; private static final String DEFAULT_SUMMARY = "default summary";
private static final String DEFAULT_DESCRIPTION = "default description"; private static final String DEFAULT_DESCRIPTION = "default description";
private static final String DEFAULT_TOP_INTRO = "default top intro";
private static final String SOFTWARE_SHORTCUT_KEY = private static final String SOFTWARE_SHORTCUT_KEY =
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS; Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
@@ -293,6 +295,23 @@ public class ToggleFeaturePreferenceFragmentTest {
assertThat(getLatestPopupWindow().isShowing()).isTrue(); assertThat(getLatestPopupWindow().isShowing()).isTrue();
} }
@Test
public void initTopIntroPreference_hasTopIntroTitle_shouldSetAsExpectedValue() {
mFragment.mTopIntroTitle = DEFAULT_TOP_INTRO;
mFragment.initTopIntroPreference();
TopIntroPreference topIntroPreference =
(TopIntroPreference) mFragment.getPreferenceScreen().getPreference(/* index= */ 0);
assertThat(topIntroPreference.getTitle().toString()).isEqualTo(DEFAULT_TOP_INTRO);
}
@Test
public void initTopIntroPreference_topIntroTitleIsNull_shouldNotAdded() {
mFragment.initTopIntroPreference();
assertThat(mFragment.getPreferenceScreen().getPreferenceCount()).isEqualTo(0);
}
@Test @Test
public void createFooterPreference_shouldSetAsExpectedValue() { public void createFooterPreference_shouldSetAsExpectedValue() {
mFragment.createFooterPreference(mFragment.getPreferenceScreen(), mFragment.createFooterPreference(mFragment.getPreferenceScreen(),