Skip to content
Snippets Groups Projects
Commit 353628a7 authored by YK Hung's avatar YK Hung Committed by Android (Google) Code Review
Browse files

Merge "Allow the bottom summary to have its own content description" into main

parents 5b6a560c a6477319
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment