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

Commit 4389434c authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Make ProgressDialog a little less lame.

Change-Id: Ic3f1dd8ba32dd02d422ee6f05fff5541e54bb8a1
parent 6014527c
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -34830,6 +34830,32 @@
<parameter name="d" type="android.graphics.drawable.Drawable">
</parameter>
</method>
<method name="setProgressNumberFormat"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="format" type="java.lang.String">
</parameter>
</method>
<method name="setProgressPercentFormat"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="format" type="java.text.NumberFormat">
</parameter>
</method>
<method name="setProgressStyle"
 return="void"
 abstract="false"
+45 −16
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.app;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -75,10 +74,18 @@ public class ProgressDialog extends AlertDialog {
    
    public ProgressDialog(Context context) {
        super(context);
        initFormats();
    }

    public ProgressDialog(Context context, int theme) {
        super(context, theme);
        initFormats();
    }

    private void initFormats() {
        mProgressNumberFormat = "%1d/%2d";
        mProgressPercentFormat = NumberFormat.getPercentInstance();
        mProgressPercentFormat.setMaximumFractionDigits(0);
    }
    
    public static ProgressDialog show(Context context, CharSequence title,
@@ -125,22 +132,27 @@ public class ProgressDialog extends AlertDialog {
                    /* Update the number and percent */
                    int progress = mProgress.getProgress();
                    int max = mProgress.getMax();
                    double percent = (double) progress / (double) max;
                    if (mProgressNumberFormat != null) {
                        String format = mProgressNumberFormat;
                        mProgressNumber.setText(String.format(format, progress, max));
                    } else {
                        mProgressNumber.setText("");
                    }
                    if (mProgressPercentFormat != null) {
                        double percent = (double) progress / (double) max;
                        SpannableString tmp = new SpannableString(mProgressPercentFormat.format(percent));
                        tmp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),
                                0, tmp.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                        mProgressPercent.setText(tmp);
                    } else {
                        mProgressPercent.setText("");
                    }
                }
            };
            View view = inflater.inflate(R.layout.alert_dialog_progress, null);
            mProgress = (ProgressBar) view.findViewById(R.id.progress);
            mProgressNumber = (TextView) view.findViewById(R.id.progress_number);
            mProgressNumberFormat = "%d/%d";
            mProgressPercent = (TextView) view.findViewById(R.id.progress_percent);
            mProgressPercentFormat = NumberFormat.getPercentInstance();
            mProgressPercentFormat.setMaximumFractionDigits(0);
            setView(view);
        } else {
            View view = inflater.inflate(R.layout.progress_dialog, null);
@@ -304,19 +316,36 @@ public class ProgressDialog extends AlertDialog {
    }

    /**
     * Change the format of Progress Number. The default is "current/max".
     * Change the format of the small text showing current and maximum units
     * of progress.  The default is "%1d/%2d".
     * Should not be called during the number is progressing.
     * @param format Should contain two "%d". The first is used for current number
     * and the second is used for the maximum.
     * @hide
     * @param format A string passed to {@link String#format String.format()};
     * use "%1d" for the current number and "%2d" for the maximum.  If null,
     * nothing will be shown.
     */
    public void setProgressNumberFormat(String format) {
        mProgressNumberFormat = format;
        onProgressChanged();
    }

    /**
     * Change the format of the small text showing the percentage of progress.
     * The default is
     * {@link NumberFormat#getPercentInstance() NumberFormat.getPercentageInstnace().}
     * Should not be called during the number is progressing.
     * @param format An instance of a {@link NumberFormat} to generate the
     * percentage text.  If null, nothing will be shown.
     */
    public void setProgressPercentFormat(NumberFormat format) {
        mProgressPercentFormat = format;
        onProgressChanged();
    }
    
    private void onProgressChanged() {
        if (mProgressStyle == STYLE_HORIZONTAL) {
            if (!mViewUpdateHandler.hasMessages(0)) {
                mViewUpdateHandler.sendEmptyMessage(0);
            }
        }
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -40,9 +40,9 @@
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="12dip"
            android:layout_marginLeft="50dip"
            android:layout_marginRight="15dip"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_alignParentRight="true"
            android:layout_below="@id/progress"
        />
</RelativeLayout>