diff --git a/res/values/strings.xml b/res/values/strings.xml index fe7c8f59fe2..7b6768ad7f0 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5256,10 +5256,18 @@ Tap items on your screen to hear them read aloud Caption preferences + + About caption preferences + + Learn more about caption preferences Magnification Magnification shortcut + + About magnification + + Learn more about magnification Magnification type @@ -5410,6 +5418,12 @@ Accessibility button Accessibility button & gesture + + About accessibility button + + About accessibility button & gesture + + Learn more about accessibility button & gesture Using the accessibility button. The gesture isn\u2019t available with 3-button navigation. @@ -5471,6 +5485,10 @@ 2 minutes Time to take action (Accessibility timeout) + + About time to take action (Accessibility timeout) + + Learn more about time to take action (Accessibility timeout) Time to take action @@ -5497,6 +5515,10 @@ Autoclick (dwell timing) + + About autoclick (dwell timing) + + Learn more about autoclick (dwell timing) Autoclick works with a connected mouse. You can set the mouse cursor to click automatically when the cursor stops moving for a certain amount of time. @@ -5537,6 +5559,14 @@ Use color correction Color correction shortcut + + About color correction + + Learn more about color correction + + About color inversion + + Learn more about color inversion Show captions @@ -5618,6 +5648,8 @@ Make screen extra dim Extra dim shortcut + + About extra dim Dim screen beyond your phone\u2019s minimum brightness diff --git a/src/com/android/settings/accessibility/AccessibilityButtonFooterPreferenceController.java b/src/com/android/settings/accessibility/AccessibilityButtonFooterPreferenceController.java index de90374c393..044c9d7ba00 100644 --- a/src/com/android/settings/accessibility/AccessibilityButtonFooterPreferenceController.java +++ b/src/com/android/settings/accessibility/AccessibilityButtonFooterPreferenceController.java @@ -33,8 +33,14 @@ public class AccessibilityButtonFooterPreferenceController extends } @Override - protected String getLabelName() { - return mContext.getString(R.string.accessibility_button_title); + protected String getLearnMoreContentDescription() { + return mContext.getString( + R.string.accessibility_button_gesture_footer_learn_more_content_description); + } + + @Override + protected String getIntroductionTitle() { + return mContext.getString(R.string.accessibility_button_about_title); } @Override diff --git a/src/com/android/settings/accessibility/AccessibilityControlTimeoutFooterPreferenceController.java b/src/com/android/settings/accessibility/AccessibilityControlTimeoutFooterPreferenceController.java index 0e65ac5b827..498b767a6dd 100644 --- a/src/com/android/settings/accessibility/AccessibilityControlTimeoutFooterPreferenceController.java +++ b/src/com/android/settings/accessibility/AccessibilityControlTimeoutFooterPreferenceController.java @@ -31,8 +31,14 @@ public class AccessibilityControlTimeoutFooterPreferenceController extends } @Override - protected String getLabelName() { - return mContext.getString(R.string.accessibility_setting_item_control_timeout_title); + protected String getLearnMoreContentDescription() { + return mContext.getString( + R.string.accessibility_control_timeout_footer_learn_more_content_description); + } + + @Override + protected String getIntroductionTitle() { + return mContext.getString(R.string.accessibility_control_timeout_about_title); } @Override diff --git a/src/com/android/settings/accessibility/AccessibilityFooterPreferenceController.java b/src/com/android/settings/accessibility/AccessibilityFooterPreferenceController.java index e3422e43fbd..08e5906105e 100644 --- a/src/com/android/settings/accessibility/AccessibilityFooterPreferenceController.java +++ b/src/com/android/settings/accessibility/AccessibilityFooterPreferenceController.java @@ -21,14 +21,18 @@ import android.content.Intent; import androidx.preference.PreferenceScreen; -import com.android.settings.R; import com.android.settings.core.BasePreferenceController; import com.android.settingslib.HelpUtils; /** - * Base class for accessibility preference footer. + * Preference controller that controls the help link and customizes the preference title in {@link + * AccessibilityFooterPreference}. */ -public abstract class AccessibilityFooterPreferenceController extends BasePreferenceController { +public class AccessibilityFooterPreferenceController extends BasePreferenceController { + + private int mHelpResource; + private String mLearnMoreContentDescription; + private String mIntroductionTitle; public AccessibilityFooterPreferenceController(Context context, String key) { super(context, key); @@ -49,23 +53,55 @@ public abstract class AccessibilityFooterPreferenceController extends BasePrefer } /** - * Override this if showing a help item in the footer bar, by returning the resource id. + * Setups a help item in the {@link AccessibilityFooterPreference} with specific content + * description. + */ + public void setupHelpLink(int helpResource, String learnMoreContentDescription) { + mHelpResource = helpResource; + mLearnMoreContentDescription = learnMoreContentDescription; + } + + /** + * Overrides this if showing a help item in the {@link AccessibilityFooterPreference}, by + * returning the resource id. * * @return the resource id for the help url */ protected int getHelpResource() { - return 0; + return mHelpResource; } - /** Returns the accessibility feature name. */ - protected abstract String getLabelName(); + /** + * Overrides this if showing a help item in the {@link AccessibilityFooterPreference} with + * specific content description. + * + * @return the content description for the help url + */ + protected String getLearnMoreContentDescription() { + return mLearnMoreContentDescription; + } + + /** + * Sets the announcement the specific features introduction in the {@link + * AccessibilityFooterPreference}. + */ + public void setIntroductionTitle(String introductionTitle) { + mIntroductionTitle = introductionTitle; + } + + /** + * Overrides this if announcement the specific features introduction in the {@link + * AccessibilityFooterPreference}. + * + * @return the extended content description for specific features introduction + */ + protected String getIntroductionTitle() { + return mIntroductionTitle; + } private void updateFooterPreferences(AccessibilityFooterPreference footerPreference) { final StringBuffer sb = new StringBuffer(); - sb.append(mContext.getString( - R.string.accessibility_introduction_title, getLabelName())) - .append("\n\n") - .append(footerPreference.getTitle()); + sb.append(getIntroductionTitle()).append("\n\n").append(footerPreference.getTitle()); footerPreference.setContentDescription(sb); if (getHelpResource() != 0) { @@ -75,10 +111,10 @@ public abstract class AccessibilityFooterPreferenceController extends BasePrefer mContext.getClass().getName()); view.startActivityForResult(helpIntent, 0); }); - - final String learnMoreContentDescription = mContext.getString( - R.string.footer_learn_more_content_description, getLabelName()); - footerPreference.setLearnMoreContentDescription(learnMoreContentDescription); + footerPreference.setLearnMoreContentDescription(getLearnMoreContentDescription()); + footerPreference.setLinkEnabled(true); + } else { + footerPreference.setLinkEnabled(false); } } } diff --git a/src/com/android/settings/accessibility/CaptionFooterPreferenceController.java b/src/com/android/settings/accessibility/CaptionFooterPreferenceController.java index 4e50b899d61..495d3951bac 100644 --- a/src/com/android/settings/accessibility/CaptionFooterPreferenceController.java +++ b/src/com/android/settings/accessibility/CaptionFooterPreferenceController.java @@ -30,12 +30,18 @@ public class CaptionFooterPreferenceController extends AccessibilityFooterPrefer } @Override - protected String getLabelName() { - return mContext.getString(R.string.accessibility_captioning_title); + protected String getLearnMoreContentDescription() { + return mContext.getString( + R.string.accessibility_captioning_footer_learn_more_content_description); } @Override - protected int getHelpResource() { + protected String getIntroductionTitle() { + return mContext.getString(R.string.accessibility_captioning_about_title); + } + + @Override + protected int getHelpResource() { return R.string.help_url_caption; } } diff --git a/src/com/android/settings/accessibility/ToggleAutoclickFooterPreferenceController.java b/src/com/android/settings/accessibility/ToggleAutoclickFooterPreferenceController.java index 053fa9dc18e..962ffece229 100644 --- a/src/com/android/settings/accessibility/ToggleAutoclickFooterPreferenceController.java +++ b/src/com/android/settings/accessibility/ToggleAutoclickFooterPreferenceController.java @@ -31,8 +31,14 @@ public class ToggleAutoclickFooterPreferenceController extends } @Override - protected String getLabelName() { - return mContext.getString(R.string.accessibility_autoclick_preference_title); + protected String getLearnMoreContentDescription() { + return mContext.getString( + R.string.accessibility_autoclick_footer_learn_more_content_description); + } + + @Override + protected String getIntroductionTitle() { + return mContext.getString(R.string.accessibility_autoclick_about_title); } @Override diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java index e06078558b7..419514f4ed4 100644 --- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java @@ -38,8 +38,7 @@ import java.util.ArrayList; import java.util.List; /** Settings page for color inversion. */ -public class ToggleColorInversionPreferenceFragment extends - ToggleFeaturePreferenceFragment { +public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePreferenceFragment { private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED; private final Handler mHandler = new Handler(); @@ -95,7 +94,20 @@ public class ToggleColorInversionPreferenceFragment extends updateSwitchBarToggleSwitch(); } }; - return super.onCreateView(inflater, container, savedInstanceState); + + final View view = super.onCreateView(inflater, container, savedInstanceState); + updateFooterPreference(); + return view; + } + + private void updateFooterPreference() { + final String title = getPrefContext().getString( + R.string.accessibility_color_inversion_about_title); + final String learnMoreContentDescription = getPrefContext().getString( + R.string.accessibility_color_inversion_footer_learn_more_content_description); + mFooterPreferenceController.setIntroductionTitle(title); + mFooterPreferenceController.setupHelpLink(getHelpResource(), learnMoreContentDescription); + mFooterPreferenceController.displayPreference(getPreferenceScreen()); } @Override diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java index 7cf57b9ab77..c9449d24109 100644 --- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java @@ -92,12 +92,20 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe updateSwitchBarToggleSwitch(); } }; - return super.onCreateView(inflater, container, savedInstanceState); + + final View view = super.onCreateView(inflater, container, savedInstanceState); + updateFooterPreference(); + return view; } - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); + private void updateFooterPreference() { + final String title = getPrefContext() + .getString(R.string.accessibility_daltonizer_about_title); + final String learnMoreContentDescription = getPrefContext() + .getString(R.string.accessibility_daltonizer_footer_learn_more_content_description); + mFooterPreferenceController.setIntroductionTitle(title); + mFooterPreferenceController.setupHelpLink(getHelpResource(), learnMoreContentDescription); + mFooterPreferenceController.displayPreference(getPreferenceScreen()); } /** Customizes the order by preference key. */ diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java index 1c807eb463f..7cefcedff28 100644 --- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java @@ -57,7 +57,6 @@ import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType; import com.android.settings.utils.LocaleUtils; import com.android.settings.widget.SettingsMainSwitchBar; import com.android.settings.widget.SettingsMainSwitchPreference; -import com.android.settingslib.HelpUtils; import com.android.settingslib.accessibility.AccessibilityUtils; import com.android.settingslib.widget.IllustrationPreference; import com.android.settingslib.widget.OnMainSwitchChangeListener; @@ -78,6 +77,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference protected SettingsMainSwitchPreference mToggleServiceSwitchPreference; protected ShortcutPreference mShortcutPreference; protected Preference mSettingsPreference; + protected AccessibilityFooterPreferenceController mFooterPreferenceController; protected String mPreferenceKey; protected CharSequence mSettingsTitle; @@ -469,33 +469,19 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference final PreferenceScreen screen = getPreferenceScreen(); final CharSequence htmlDescription = Html.fromHtml(mHtmlDescription.toString(), Html.FROM_HTML_MODE_COMPACT, mImageGetter, /* tagHandler= */ null); - final String iconContentDescription = - getString(R.string.accessibility_introduction_title, mPackageName); final AccessibilityFooterPreference htmlFooterPreference = new AccessibilityFooterPreference(screen.getContext()); htmlFooterPreference.setKey(KEY_HTML_DESCRIPTION_PREFERENCE); htmlFooterPreference.setSummary(htmlDescription); - htmlFooterPreference.setContentDescription( - generateFooterContentDescription(htmlDescription)); - - // Only framework tools support help link - if (getHelpResource() != 0) { - htmlFooterPreference.setLearnMoreAction(view -> { - final Intent helpIntent = HelpUtils.getHelpIntent( - getContext(), getContext().getString(getHelpResource()), - getContext().getClass().getName()); - view.startActivityForResult(helpIntent, 0); - }); - - final String learnMoreContentDescription = getPrefContext().getString( - R.string.footer_learn_more_content_description, mPackageName); - htmlFooterPreference.setLearnMoreContentDescription(learnMoreContentDescription); - htmlFooterPreference.setLinkEnabled(true); - } else { - htmlFooterPreference.setLinkEnabled(false); - } screen.addPreference(htmlFooterPreference); + + // TODO(b/171272809): Migrate to DashboardFragment. + final String title = getString(R.string.accessibility_introduction_title, mPackageName); + mFooterPreferenceController = new AccessibilityFooterPreferenceController( + screen.getContext(), htmlFooterPreference.getKey()); + mFooterPreferenceController.setIntroductionTitle(title); + mFooterPreferenceController.displayPreference(screen); } private void initFooterPreference() { @@ -518,41 +504,22 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference * * @param screen The preference screen to add the footer preference * @param summary The summary of the preference summary. - * @param iconContentDescription The content description of icon in the footer. + * @param introductionTitle The title of introduction in the footer. */ @VisibleForTesting void createFooterPreference(PreferenceScreen screen, CharSequence summary, - String iconContentDescription) { + String introductionTitle) { final AccessibilityFooterPreference footerPreference = new AccessibilityFooterPreference(screen.getContext()); footerPreference.setSummary(summary); - footerPreference.setContentDescription( - generateFooterContentDescription(summary)); - - // Only framework tools support help link - if (getHelpResource() != 0) { - footerPreference.setLearnMoreAction(view -> { - final Intent helpIntent = HelpUtils.getHelpIntent( - getContext(), getContext().getString(getHelpResource()), - getContext().getClass().getName()); - view.startActivityForResult(helpIntent, 0); - }); - - final String learnMoreContentDescription = getPrefContext().getString( - R.string.footer_learn_more_content_description, mPackageName); - footerPreference.setLearnMoreContentDescription(learnMoreContentDescription); - } screen.addPreference(footerPreference); + + mFooterPreferenceController = new AccessibilityFooterPreferenceController( + screen.getContext(), footerPreference.getKey()); + mFooterPreferenceController.setIntroductionTitle(introductionTitle); + mFooterPreferenceController.displayPreference(screen); } - private CharSequence generateFooterContentDescription(CharSequence footerContent) { - final StringBuffer sb = new StringBuffer(); - sb.append(getPrefContext().getString( - R.string.accessibility_introduction_title, mPackageName)) - .append("\n\n") - .append(footerContent); - return sb; - } @VisibleForTesting void setupEditShortcutDialog(Dialog dialog) { final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut); diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java index 6fd2e1d81d0..81bd45a0541 100644 --- a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java @@ -86,6 +86,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre // Parent sets the title when creating the view, so set it after calling super mToggleServiceSwitchPreference.setTitle(R.string.reduce_bright_colors_switch_title); updateGeneralCategoryOrder(); + updateFooterPreference(); return view; } @@ -101,6 +102,12 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre generalCategory.addPreference(persist); } + private void updateFooterPreference() { + final String title = getPrefContext().getString(R.string.reduce_bright_colors_about_title); + mFooterPreferenceController.setIntroductionTitle(title); + mFooterPreferenceController.displayPreference(getPreferenceScreen()); + } + @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -135,7 +142,6 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre return R.xml.reduce_bright_colors_settings; } - @Override protected void onPreferenceToggled(String preferenceKey, boolean enabled) { AccessibilityStatsLogUtils.logAccessibilityServiceEnabled(mComponentName, enabled); diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java index 6b02f04154c..4f25430e8d2 100644 --- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java @@ -95,7 +95,20 @@ public class ToggleScreenMagnificationPreferenceFragment extends removeDialog(DialogEnums.EDIT_SHORTCUT); mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext())); }; - return super.onCreateView(inflater, container, savedInstanceState); + + final View view = super.onCreateView(inflater, container, savedInstanceState); + updateFooterPreference(); + return view; + } + + private void updateFooterPreference() { + final String title = getPrefContext().getString( + R.string.accessibility_screen_magnification_about_title); + final String learnMoreContentDescription = getPrefContext().getString( + R.string.accessibility_screen_magnification_footer_learn_more_content_description); + mFooterPreferenceController.setIntroductionTitle(title); + mFooterPreferenceController.setupHelpLink(getHelpResource(), learnMoreContentDescription); + mFooterPreferenceController.displayPreference(getPreferenceScreen()); } @Override diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceControllerTest.java new file mode 100644 index 00000000000..d6c8d996a16 --- /dev/null +++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceControllerTest.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.accessibility; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import androidx.preference.PreferenceScreen; +import androidx.preference.PreferenceViewHolder; +import androidx.test.core.app.ApplicationProvider; + +import com.android.settings.R; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.robolectric.RobolectricTestRunner; + +/** + * Tests for {@link AccessibilityFooterPreferenceController}. + */ +@RunWith(RobolectricTestRunner.class) +public class AccessibilityFooterPreferenceControllerTest { + + private static final String TEST_KEY = "test_pref_key"; + private static final String TEST_TITLE = "test_title"; + private static final String TEST_INTRODUCTION_TITLE = "test_introduction_title"; + private static final String TEST_CONTENT_DESCRIPTION = "test_content_description"; + private static final int TEST_HELP_ID = 12345; + + @Rule + public final MockitoRule mockito = MockitoJUnit.rule(); + + @Spy + private final Context mContext = ApplicationProvider.getApplicationContext(); + @Mock + private PreferenceScreen mScreen; + private AccessibilityFooterPreferenceController mController; + private AccessibilityFooterPreference mPreference; + private PreferenceViewHolder mPreferenceViewHolder; + + @Before + public void setUp() { + mController = new AccessibilityFooterPreferenceController(mContext, TEST_KEY); + mPreference = new AccessibilityFooterPreference(mContext); + mPreference.setKey(TEST_KEY); + mPreference.setTitle(TEST_TITLE); + + final LayoutInflater inflater = LayoutInflater.from(mContext); + final View view = inflater.inflate(R.layout.preference_footer, null); + mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(view); + mPreference.onBindViewHolder(mPreferenceViewHolder); + + when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); + } + + @Test + public void setIntroductionTitle_setCorrectIntroductionTitle() { + mController.setIntroductionTitle(TEST_INTRODUCTION_TITLE); + + assertThat(mController.getIntroductionTitle()).isEqualTo(TEST_INTRODUCTION_TITLE); + } + + @Test + public void onBindViewHolder_setIntroductionTitle_setCorrectIntroductionTitle() { + mController.setIntroductionTitle(TEST_INTRODUCTION_TITLE); + mController.displayPreference(mScreen); + + mPreference.onBindViewHolder(mPreferenceViewHolder); + + final TextView summaryView = (TextView) mPreferenceViewHolder + .findViewById(android.R.id.title); + assertThat(summaryView.getContentDescription().toString()) + .contains(TEST_INTRODUCTION_TITLE); + } + + @Test + public void setupHelpLink_setCorrectHelpLinkAndContentDescription() { + mController.setupHelpLink(TEST_HELP_ID, TEST_CONTENT_DESCRIPTION); + + assertThat(mController.getHelpResource()).isEqualTo(TEST_HELP_ID); + assertThat(mController.getLearnMoreContentDescription()) + .isEqualTo(TEST_CONTENT_DESCRIPTION); + } + + @Test + public void onBindViewHolder_setupHelpLink_setCorrectHelpLinkAndContentDescription() { + mController.setupHelpLink(TEST_HELP_ID, TEST_CONTENT_DESCRIPTION); + mController.displayPreference(mScreen); + + mPreference.onBindViewHolder(mPreferenceViewHolder); + + final TextView learnMoreView = (TextView) mPreferenceViewHolder + .findViewById(com.android.settingslib.R.id.settingslib_learn_more); + assertThat(learnMoreView.getContentDescription().toString()) + .contains(TEST_CONTENT_DESCRIPTION); + assertThat(mPreference.isLinkEnabled()).isTrue(); + } +}