/** * Creates and shows an indeterminate progress dialog. Once the progress dialog is shown, it * will be shown for at least the minDisplayTime (in milliseconds), so that the progress dialog * does not flash in and out to quickly. */ public static IndeterminateProgressDialog show(FragmentManager fragmentManager, CharSequence title, CharSequence message, long minDisplayTime) { IndeterminateProgressDialog dialogFragment = new IndeterminateProgressDialog(); dialogFragment.mTitle = title; dialogFragment.mMessage = message; dialogFragment.mMinDisplayTime = minDisplayTime; dialogFragment.show(fragmentManager, TAG); dialogFragment.mShowTime = System.currentTimeMillis(); dialogFragment.setCancelable(false); return dialogFragment; }
/** * This tells the progress dialog to dismiss itself after guaranteeing to be shown for the * specified time in {@link #show(FragmentManager, CharSequence, CharSequence, long)}. */ @Override public void dismiss() { mAllowStateLoss = false; dismissWhenReady(); }
/** * Save the old dialog that is about to get destroyed in case this is due to a change * in device orientation. This will allow us to intercept the callback to * {@link #onDismiss(DialogInterface)} in case the callback happens after a new progress dialog * instance was created. */ @Override public void onDestroyView() { mOldDialog = getDialog(); super.onDestroyView(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); }
@Override public void onStart() { super.onStart(); mActivityReady = true; // Check if superDismiss() had been called before. This can happen if in a long // running operation, the user hits the home button and closes this fragment's activity. // Upon returning, we want to dismiss this progress dialog fragment. if (mCalledSuperDismiss) { superDismiss(); } }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Create the progress dialog and set its properties final ProgressDialog dialog = new ProgressDialog(getActivity()); dialog.setIndeterminate(true); dialog.setIndeterminateDrawable(null); dialog.setTitle(mTitle); dialog.setMessage(mMessage); return dialog; }
@Override public void onClick(DialogInterface dialog, int which) { if (!PermissionsUtil.hasContactsPermissions(context)) { return; } final IndeterminateProgressDialog progressDialog = IndeterminateProgressDialog.show( getFragmentManager(), getString(R.string.clearFrequentsProgress_title), null, 500); final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { resolver.delete(ContactsContract.DataUsageFeedback.DELETE_USAGE_URI, null, null); return null; } @Override protected void onPostExecute(Void result) { progressDialog.dismiss(); } }; task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } };
/** * This tells the progress dialog to dismiss itself (with state loss) after guaranteeing to be * shown for the specified time in * {@link #show(FragmentManager, CharSequence, CharSequence, long)}. */ @Override public void dismissAllowingStateLoss() { mAllowStateLoss = true; dismissWhenReady(); }