Fields Summary |
---|
public static final int | STYLE_SPINNERCreates a ProgressDialog with a ciruclar, spinning progress
bar. This is the default. |
public static final int | STYLE_HORIZONTALCreates a ProgressDialog with a horizontal progress bar. |
private android.widget.ProgressBar | mProgress |
private android.widget.TextView | mMessageView |
private int | mProgressStyle |
private android.widget.TextView | mProgressNumber |
private String | mProgressNumberFormat |
private android.widget.TextView | mProgressPercent |
private NumberFormat | mProgressPercentFormat |
private int | mMax |
private int | mProgressVal |
private int | mSecondaryProgressVal |
private int | mIncrementBy |
private int | mIncrementSecondaryBy |
private android.graphics.drawable.Drawable | mProgressDrawable |
private android.graphics.drawable.Drawable | mIndeterminateDrawable |
private CharSequence | mMessage |
private boolean | mIndeterminate |
private boolean | mHasStarted |
private android.os.Handler | mViewUpdateHandler |
Methods Summary |
---|
public int | getMax()
if (mProgress != null) {
return mProgress.getMax();
}
return mMax;
|
public int | getProgress()
if (mProgress != null) {
return mProgress.getProgress();
}
return mProgressVal;
|
public int | getSecondaryProgress()
if (mProgress != null) {
return mProgress.getSecondaryProgress();
}
return mSecondaryProgressVal;
|
public void | incrementProgressBy(int diff)
if (mProgress != null) {
mProgress.incrementProgressBy(diff);
onProgressChanged();
} else {
mIncrementBy += diff;
}
|
public void | incrementSecondaryProgressBy(int diff)
if (mProgress != null) {
mProgress.incrementSecondaryProgressBy(diff);
onProgressChanged();
} else {
mIncrementSecondaryBy += diff;
}
|
public boolean | isIndeterminate()
if (mProgress != null) {
return mProgress.isIndeterminate();
}
return mIndeterminate;
|
protected void | onCreate(android.os.Bundle savedInstanceState)
LayoutInflater inflater = LayoutInflater.from(mContext);
if (mProgressStyle == STYLE_HORIZONTAL) {
/* Use a separate handler to update the text views as they
* must be updated on the same thread that created them.
*/
mViewUpdateHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
/* Update the number and percent */
int progress = mProgress.getProgress();
int max = mProgress.getMax();
double percent = (double) progress / (double) max;
String format = mProgressNumberFormat;
mProgressNumber.setText(String.format(format, progress, 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);
}
};
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);
mProgress = (ProgressBar) view.findViewById(R.id.progress);
mMessageView = (TextView) view.findViewById(R.id.message);
setView(view);
}
if (mMax > 0) {
setMax(mMax);
}
if (mProgressVal > 0) {
setProgress(mProgressVal);
}
if (mSecondaryProgressVal > 0) {
setSecondaryProgress(mSecondaryProgressVal);
}
if (mIncrementBy > 0) {
incrementProgressBy(mIncrementBy);
}
if (mIncrementSecondaryBy > 0) {
incrementSecondaryProgressBy(mIncrementSecondaryBy);
}
if (mProgressDrawable != null) {
setProgressDrawable(mProgressDrawable);
}
if (mIndeterminateDrawable != null) {
setIndeterminateDrawable(mIndeterminateDrawable);
}
if (mMessage != null) {
setMessage(mMessage);
}
setIndeterminate(mIndeterminate);
onProgressChanged();
super.onCreate(savedInstanceState);
|
private void | onProgressChanged()
if (mProgressStyle == STYLE_HORIZONTAL) {
mViewUpdateHandler.sendEmptyMessage(0);
}
|
public void | onStart()
super.onStart();
mHasStarted = true;
|
protected void | onStop()
super.onStop();
mHasStarted = false;
|
public void | setIndeterminate(boolean indeterminate)
if (mProgress != null) {
mProgress.setIndeterminate(indeterminate);
} else {
mIndeterminate = indeterminate;
}
|
public void | setIndeterminateDrawable(android.graphics.drawable.Drawable d)
if (mProgress != null) {
mProgress.setIndeterminateDrawable(d);
} else {
mIndeterminateDrawable = d;
}
|
public void | setMax(int max)
if (mProgress != null) {
mProgress.setMax(max);
onProgressChanged();
} else {
mMax = max;
}
|
public void | setMessage(java.lang.CharSequence message)
if (mProgress != null) {
if (mProgressStyle == STYLE_HORIZONTAL) {
super.setMessage(message);
} else {
mMessageView.setText(message);
}
} else {
mMessage = message;
}
|
public void | setProgress(int value)
if (mHasStarted) {
mProgress.setProgress(value);
onProgressChanged();
} else {
mProgressVal = value;
}
|
public void | setProgressDrawable(android.graphics.drawable.Drawable d)
if (mProgress != null) {
mProgress.setProgressDrawable(d);
} else {
mProgressDrawable = d;
}
|
public void | setProgressNumberFormat(java.lang.String format)Change the format of Progress Number. The default is "current/max".
Should not be called during the number is progressing.
mProgressNumberFormat = format;
|
public void | setProgressStyle(int style)
mProgressStyle = style;
|
public void | setSecondaryProgress(int secondaryProgress)
if (mProgress != null) {
mProgress.setSecondaryProgress(secondaryProgress);
onProgressChanged();
} else {
mSecondaryProgressVal = secondaryProgress;
}
|
public static android.app.ProgressDialog | show(android.content.Context context, java.lang.CharSequence title, java.lang.CharSequence message)
return show(context, title, message, false);
|
public static android.app.ProgressDialog | show(android.content.Context context, java.lang.CharSequence title, java.lang.CharSequence message, boolean indeterminate)
return show(context, title, message, indeterminate, false, null);
|
public static android.app.ProgressDialog | show(android.content.Context context, java.lang.CharSequence title, java.lang.CharSequence message, boolean indeterminate, boolean cancelable)
return show(context, title, message, indeterminate, cancelable, null);
|
public static android.app.ProgressDialog | show(android.content.Context context, java.lang.CharSequence title, java.lang.CharSequence message, boolean indeterminate, boolean cancelable, OnCancelListener cancelListener)
ProgressDialog dialog = new ProgressDialog(context);
dialog.setTitle(title);
dialog.setMessage(message);
dialog.setIndeterminate(indeterminate);
dialog.setCancelable(cancelable);
dialog.setOnCancelListener(cancelListener);
dialog.show();
return dialog;
|