Update the rich content UI to meet the UX design version 2.

1. Using the footerPreference component for the interface
android:desription.
2. Remove the redundant and unused codes.
3. Remove the ripple effect for AnimatedImagePreference.

Bug: 142532186
Test: manual test
Change-Id: I547ed7611b40d8b7bee4c4350b00bd4987768950
This commit is contained in:
Peter_Liang
2020-02-04 19:03:50 +08:00
parent 64a941f8ad
commit 68d701db97
5 changed files with 32 additions and 63 deletions

View File

@@ -33,7 +33,6 @@ import com.android.settings.R;
*/
public class AnimatedImagePreference extends Preference {
private boolean mDividerAllowedAbove = false;
private Uri mImageUri;
AnimatedImagePreference(Context context) {
@@ -44,7 +43,6 @@ public class AnimatedImagePreference extends Preference {
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
holder.setDividerAllowedAbove(mDividerAllowedAbove);
final ImageView imageView = holder.itemView.findViewById(R.id.animated_img);
if (imageView != null && mImageUri != null) {
@@ -59,18 +57,6 @@ public class AnimatedImagePreference extends Preference {
}
}
/**
* Sets divider whether to show in preference above.
*
* @param allowed true will be drawn on above this item
*/
public void setDividerAllowedAbove(boolean allowed) {
if (allowed != mDividerAllowedAbove) {
mDividerAllowedAbove = allowed;
notifyChanged();
}
}
/**
* Set image uri to display image in {@link ImageView}
*

View File

@@ -32,7 +32,6 @@ import java.util.regex.Pattern;
*/
public final class HtmlTextPreference extends StaticTextPreference {
private boolean mDividerAllowedAbove = false;
private int mFlag = Html.FROM_HTML_MODE_COMPACT;
private Html.ImageGetter mImageGetter;
private Html.TagHandler mTagHandler;
@@ -45,7 +44,6 @@ public final class HtmlTextPreference extends StaticTextPreference {
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
holder.setDividerAllowedAbove(mDividerAllowedAbove);
final TextView summaryView = holder.itemView.findViewById(android.R.id.summary);
if (summaryView != null && !TextUtils.isEmpty(getSummary())) {
@@ -54,18 +52,6 @@ public final class HtmlTextPreference extends StaticTextPreference {
}
}
/**
* Sets divider whether to show in preference above.
*
* @param allowed true will be drawn on above this item
*/
public void setDividerAllowedAbove(boolean allowed) {
if (allowed != mDividerAllowedAbove) {
mDividerAllowedAbove = allowed;
notifyChanged();
}
}
/**
* Sets the flag to which text format to be applied.
*

View File

@@ -47,6 +47,7 @@ import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.widget.FooterPreference;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -75,7 +76,6 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
protected ComponentName mComponentName;
protected CharSequence mPackageName;
protected Uri mImageUri;
protected CharSequence mStaticDescription;
protected CharSequence mHtmlDescription;
private static final String ANCHOR_TAG = "a";
private static final String DRAWABLE_FOLDER = "drawable";
@@ -141,7 +141,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
final AnimatedImagePreference animatedImagePreference = new AnimatedImagePreference(
getPrefContext());
animatedImagePreference.setImageUri(mImageUri);
animatedImagePreference.setDividerAllowedAbove(true);
animatedImagePreference.setSelectable(false);
preferenceScreen.addPreference(animatedImagePreference);
}
@@ -172,34 +172,24 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
groupCategory.addPreference(mSettingsPreference);
}
if (mStaticDescription != null || mHtmlDescription != null) {
final PreferenceCategory footerCategory = new PreferenceCategory(getPrefContext());
final CharSequence title = getString(R.string.accessibility_footer_title, mPackageName);
footerCategory.setTitle(title);
preferenceScreen.addPreference(footerCategory);
if (mHtmlDescription != null) {
final PreferenceCategory introductionCategory = new PreferenceCategory(
getPrefContext());
final CharSequence title = getString(R.string.accessibility_introduction_title,
mPackageName);
introductionCategory.setTitle(title);
preferenceScreen.addPreference(introductionCategory);
if (mStaticDescription != null) {
final StaticTextPreference staticTextPreference = new StaticTextPreference(
getPrefContext());
staticTextPreference.setSummary(mStaticDescription);
staticTextPreference.setSelectable(/* selectable= */ false);
footerCategory.addPreference(staticTextPreference);
}
// For accessibility service, avoid malicious links made by third party developer.
final List<String> unsupportedTagList = new ArrayList<>();
unsupportedTagList.add(ANCHOR_TAG);
if (mHtmlDescription != null) {
// For accessibility service, avoid malicious links made by third party developer.
final List<String> unsupportedTagList = new ArrayList<>();
unsupportedTagList.add(ANCHOR_TAG);
final HtmlTextPreference htmlTextPreference = new HtmlTextPreference(
getPrefContext());
htmlTextPreference.setSummary(mHtmlDescription);
htmlTextPreference.setImageGetter(mImageGetter);
htmlTextPreference.setUnsupportedTagList(unsupportedTagList);
htmlTextPreference.setDividerAllowedAbove(true);
htmlTextPreference.setSelectable(/* selectable= */ false);
footerCategory.addPreference(htmlTextPreference);
}
final HtmlTextPreference htmlTextPreference = new HtmlTextPreference(getPrefContext());
htmlTextPreference.setSummary(mHtmlDescription);
htmlTextPreference.setImageGetter(mImageGetter);
htmlTextPreference.setUnsupportedTagList(unsupportedTagList);
htmlTextPreference.setSelectable(false);
introductionCategory.addPreference(htmlTextPreference);
}
}
@@ -362,11 +352,11 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
// Summary.
if (arguments.containsKey(AccessibilitySettings.EXTRA_SUMMARY_RES)) {
final int summary = arguments.getInt(AccessibilitySettings.EXTRA_SUMMARY_RES);
mStaticDescription = getText(summary);
createFooterPreference(getText(summary));
} else if (arguments.containsKey(AccessibilitySettings.EXTRA_SUMMARY)) {
final CharSequence summary = arguments.getCharSequence(
AccessibilitySettings.EXTRA_SUMMARY);
mStaticDescription = summary;
createFooterPreference(summary);
}
}
@@ -635,4 +625,10 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
public void onSettingsClicked(ShortcutPreference preference) {
mUserShortcutTypeCache = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
}
private void createFooterPreference(CharSequence title) {
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.addPreference(new FooterPreference.Builder(getActivity()).setTitle(
title).build());
}
}