Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6477319 authored by Yiling Chuang's avatar Yiling Chuang
Browse files

Allow the bottom summary to have its own content description

Bug: 343616480
Test: rebuild and manual test
Change-Id: Ie7422b9b40edae4086355fdb5f9691fdebdf5d78
parent 0bd33674
Loading
Loading
Loading
Loading
+32 −18
Original line number Diff line number Diff line
@@ -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 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,8 +70,8 @@ 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 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) {
@@ -114,6 +115,14 @@ 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) {
@@ -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);
@@ -206,8 +217,11 @@ 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);
            spannableSummary.setSpan(
                    new AbsoluteSizeSpan(64, true /* dip */),
                    matcher.start(),
                    matcher.end(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            return spannableSummary;
        }
        return summary;