diff --git a/packages/SettingsLib/UsageProgressBarPreference/src/com/android/settingslib/widget/UsageProgressBarPreference.java b/packages/SettingsLib/UsageProgressBarPreference/src/com/android/settingslib/widget/UsageProgressBarPreference.java index ea3dbd925792f1ae7f3fe1c2c28c3a5409e103c2..0e71a1b127e7e3220d066e14fa5e24e3fe7bda97 100644 --- a/packages/SettingsLib/UsageProgressBarPreference/src/com/android/settingslib/widget/UsageProgressBarPreference.java +++ b/packages/SettingsLib/UsageProgressBarPreference/src/com/android/settingslib/widget/UsageProgressBarPreference.java @@ -38,8 +38,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * Progres bar preference with a usage summary and a total summary. - * This preference shows number in usage summary with enlarged font size. + * Progress bar preference with a usage summary and a total summary. + * + * <p>This preference shows number in usage summary with enlarged font size. */ public class UsageProgressBarPreference extends Preference { @@ -48,18 +49,18 @@ public class UsageProgressBarPreference extends Preference { private CharSequence mUsageSummary; private CharSequence mTotalSummary; private CharSequence mBottomSummary; + private CharSequence mBottomSummaryContentDescription; private ImageView mCustomImageView; private int mPercent = -1; /** * Perform inflation from XML and apply a class-specific base style. * - * @param context The {@link Context} this is associated with, through which it can - * access the current theme, resources, {@link SharedPreferences}, etc. - * @param attrs The attributes of the XML tag that is inflating the preference + * @param context The {@link Context} this is associated with, through which it can access the + * current theme, resources, {@link SharedPreferences}, etc. + * @param attrs The attributes of the XML tag that is inflating the preference * @param defStyle An attribute in the current theme that contains a reference to a style - * resource that supplies default values for the view. Can be 0 to not - * look for defaults. + * resource that supplies default values for the view. Can be 0 to not look for defaults. */ public UsageProgressBarPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); @@ -69,9 +70,9 @@ public class UsageProgressBarPreference extends Preference { /** * Perform inflation from XML and apply a class-specific base style. * - * @param context The {@link Context} this is associated with, through which it can - * access the current theme, resources, {@link SharedPreferences}, etc. - * @param attrs The attributes of the XML tag that is inflating the preference + * @param context The {@link Context} this is associated with, through which it can access the + * current theme, resources, {@link SharedPreferences}, etc. + * @param attrs The attributes of the XML tag that is inflating the preference */ public UsageProgressBarPreference(Context context, AttributeSet attrs) { super(context, attrs); @@ -114,9 +115,17 @@ public class UsageProgressBarPreference extends Preference { notifyChanged(); } + /** Set content description for the bottom summary. */ + public void setBottomSummaryContentDescription(CharSequence contentDescription) { + if (!TextUtils.equals(mBottomSummaryContentDescription, contentDescription)) { + mBottomSummaryContentDescription = contentDescription; + notifyChanged(); + } + } + /** Set percentage of the progress bar. */ public void setPercent(long usage, long total) { - if (usage > total) { + if (usage > total) { return; } if (total == 0L) { @@ -146,14 +155,13 @@ public class UsageProgressBarPreference extends Preference { /** * Binds the created View to the data for this preference. * - * <p>This is a good place to grab references to custom Views in the layout and set - * properties on them. + * <p>This is a good place to grab references to custom Views in the layout and set properties + * on them. * * <p>Make sure to call through to the superclass's implementation. * * @param holder The ViewHolder that provides references to the views to fill in. These views - * will be recycled, so you should not hold a reference to them after this method - * returns. + * will be recycled, so you should not hold a reference to them after this method returns. */ @Override public void onBindViewHolder(PreferenceViewHolder holder) { @@ -177,6 +185,9 @@ public class UsageProgressBarPreference extends Preference { bottomSummary.setVisibility(View.VISIBLE); bottomSummary.setMovementMethod(LinkMovementMethod.getInstance()); bottomSummary.setText(mBottomSummary); + if (!TextUtils.isEmpty(mBottomSummaryContentDescription)) { + bottomSummary.setContentDescription(mBottomSummaryContentDescription); + } } final ProgressBar progressBar = (ProgressBar) holder.findViewById(android.R.id.progress); @@ -205,9 +216,12 @@ public class UsageProgressBarPreference extends Preference { final Matcher matcher = mNumberPattern.matcher(summary); if (matcher.find()) { - final SpannableString spannableSummary = new SpannableString(summary); - spannableSummary.setSpan(new AbsoluteSizeSpan(64, true /* dip */), matcher.start(), - matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + final SpannableString spannableSummary = new SpannableString(summary); + spannableSummary.setSpan( + new AbsoluteSizeSpan(64, true /* dip */), + matcher.start(), + matcher.end(), + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableSummary; } return summary;