Merge "Fix the link text "Learn more" in the accessibility pages with help links could not convey the link's purpose clearly" into sc-dev
This commit is contained in:
@@ -17,29 +17,19 @@
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.utils.AnnotationSpan;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
/**
|
||||
* A custom preference acting as footer of a page. It has a field for icon and text. It is added
|
||||
* to screen as the last preference and groups of icon and text content in accessibility-focusable
|
||||
* {@link android.view.accessibility.AccessibilityNodeInfo} for TalkBack to use.
|
||||
* A custom preference acting as footer of a page. Disables the movement method by default.
|
||||
*/
|
||||
public final class AccessibilityFooterPreference extends FooterPreference {
|
||||
|
||||
private CharSequence mIconContentDescription;
|
||||
private boolean mLinkEnabled;
|
||||
|
||||
public AccessibilityFooterPreference(Context context, AttributeSet attrs) {
|
||||
@@ -65,33 +55,6 @@ public final class AccessibilityFooterPreference extends FooterPreference {
|
||||
} else {
|
||||
title.setMovementMethod(/* movement= */ null);
|
||||
}
|
||||
|
||||
final LinearLayout infoFrame = holder.itemView.findViewById(R.id.icon_frame);
|
||||
if (!TextUtils.isEmpty(mIconContentDescription)) {
|
||||
// Groups related content.
|
||||
infoFrame.setContentDescription(mIconContentDescription);
|
||||
title.setFocusable(false);
|
||||
} else {
|
||||
infoFrame.setContentDescription(null);
|
||||
title.setFocusable(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content description of the icon.
|
||||
*/
|
||||
public void setIconContentDescription(CharSequence iconContentDescription) {
|
||||
if (!TextUtils.equals(iconContentDescription, mIconContentDescription)) {
|
||||
mIconContentDescription = iconContentDescription;
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content description of the icon.
|
||||
*/
|
||||
public CharSequence getIconContentDescription() {
|
||||
return mIconContentDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,23 +73,4 @@ public final class AccessibilityFooterPreference extends FooterPreference {
|
||||
public boolean isLinkEnabled() {
|
||||
return mLinkEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends {@link AnnotationSpan} with learn more link apart from the other text.
|
||||
*
|
||||
* @param helpLinkRes The Help Uri Resource key
|
||||
*/
|
||||
public void appendHelpLink(int helpLinkRes) {
|
||||
final SpannableStringBuilder sb = new SpannableStringBuilder();
|
||||
sb.append(getTitle()).append("\n\n").append(getLearnMoreLink(getContext(), helpLinkRes));
|
||||
setTitle(sb);
|
||||
}
|
||||
|
||||
private CharSequence getLearnMoreLink(Context context, int helpLinkRes) {
|
||||
final Intent helpIntent = HelpUtils.getHelpIntent(
|
||||
context, context.getString(helpLinkRes), context.getClass().getName());
|
||||
final AnnotationSpan.LinkInfo linkInfo = new AnnotationSpan.LinkInfo(
|
||||
context, AnnotationSpan.LinkInfo.DEFAULT_ANNOTATION, helpIntent);
|
||||
return AnnotationSpan.linkify(context.getText(R.string.footer_learn_more), linkInfo);
|
||||
}
|
||||
}
|
||||
|
@@ -17,11 +17,13 @@
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
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.
|
||||
@@ -59,13 +61,24 @@ public abstract class AccessibilityFooterPreferenceController extends BasePrefer
|
||||
protected abstract String getLabelName();
|
||||
|
||||
private void updateFooterPreferences(AccessibilityFooterPreference footerPreference) {
|
||||
final String iconContentDescription = mContext.getString(
|
||||
R.string.accessibility_introduction_title, getLabelName());
|
||||
footerPreference.setIconContentDescription(iconContentDescription);
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
sb.append(mContext.getString(
|
||||
R.string.accessibility_introduction_title, getLabelName()))
|
||||
.append("\n\n")
|
||||
.append(footerPreference.getTitle());
|
||||
footerPreference.setContentDescription(sb);
|
||||
|
||||
if (getHelpResource() != 0) {
|
||||
footerPreference.appendHelpLink(getHelpResource());
|
||||
footerPreference.setLinkEnabled(true);
|
||||
footerPreference.setLearnMoreAction(view -> {
|
||||
final Intent helpIntent = HelpUtils.getHelpIntent(
|
||||
mContext, mContext.getString(getHelpResource()),
|
||||
mContext.getClass().getName());
|
||||
view.startActivityForResult(helpIntent, 0);
|
||||
});
|
||||
|
||||
final String learnMoreContentDescription = mContext.getString(
|
||||
R.string.footer_learn_more_content_description, getLabelName());
|
||||
footerPreference.setLearnMoreContentDescription(learnMoreContentDescription);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -55,6 +55,7 @@ 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.OnMainSwitchChangeListener;
|
||||
|
||||
@@ -520,14 +521,25 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
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.appendHelpLink(getHelpResource());
|
||||
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);
|
||||
}
|
||||
htmlFooterPreference.setIconContentDescription(iconContentDescription);
|
||||
screen.addPreference(htmlFooterPreference);
|
||||
}
|
||||
|
||||
@@ -559,14 +571,33 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
final AccessibilityFooterPreference footerPreference =
|
||||
new AccessibilityFooterPreference(screen.getContext());
|
||||
footerPreference.setSummary(summary);
|
||||
footerPreference.setIconContentDescription(iconContentDescription);
|
||||
footerPreference.setContentDescription(
|
||||
generateFooterContentDescription(summary));
|
||||
|
||||
// Only framework tools support help link
|
||||
if (getHelpResource() != 0) {
|
||||
footerPreference.appendHelpLink(getHelpResource());
|
||||
footerPreference.setLinkEnabled(true);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
Reference in New Issue
Block a user