Skip to content

Add progress dialog#71

Merged
eltos merged 14 commits intomainfrom
dialog-progress
May 28, 2021
Merged

Add progress dialog#71
eltos merged 14 commits intomainfrom
dialog-progress

Conversation

@eltos
Copy link
Owner

@eltos eltos commented May 27, 2021

  • Indeterminate type
  • Bar and indeterminate circle
  • Annotations (percent, info)
  • Methods to update progress
  • Simple connection with AsyncTask
  • Test for compatibility with rotation changes

closes #69


Wiki page draft:

Progress dialog

extends CustomViewDialog

A dialog showing a progress

Building dialogs

The progress is indeterminate by default, but can be updated either before the dialog is shown or while it is being shown.
In addition, an AsyncTask can easily be connected to the dialog, such that the progress and state is automatically synced with the task.
By default, a cancel button is shown, but the dialog can not be dismissed by (accidentally) clicking outside it or via the back button. This button can be removed via .neut(null).
The dialog is meant to be dismissed by calling .dismiss(), but an auto-dismiss option exists.

Example

SimpleProgressDialog.bar()
                    .title(R.string.login)
                    .msg(R.string.creating_user_profile_wait)
                    .show(this, PROGRESS_DIALOG);
// use this to access the dialog after rotation changes
FragmentManager fm = getSupportFragmentManager();
SimpleProgressDialog dialog = (SimpleProgressDialog) 
    fm.findFragmentByTag(PROGRESS_DIALOG);

dialog.updateProgress(13, 100);
dialog.updateInfoText("Working…");
dialog.dismiss();

More examples can be found in the testApp

Available customizations

  • Type (bar/circle)
    SimpleProgressDialog.bar()
    SimpleProgressDialog.indeterminateCircle()
    .type(Type type)
    Please note that the circle type can only show an indeterminate progress
  • Percentage indicator "00%" below bar/inside circle (shown by default for bar type)
    .percentage(boolean visible)

See also CustomViewDialog

Updating the progress

These methods can be called either before the dialog is shown or afterwards.

Progress
.updateProgress(int progress)
.updateProgress(int progress, int max)
.updateMax(int max)
.updateSecondaryProgress(int progress)
.updateIndeterminate()
.updateFinished()

Text
.updateProgressText(String text) for a short text, e.g. 5% or 8MB (by default, this shows the progress unless manually set)
.updateInfoText(String text) for a longer text, e.g. "Loading data…" or "5 seconds left"

Working with AsyncTask

Derive a task from SimpleProgressTask.

static class MyProgressTask extends SimpleProgressTask<Void, Integer, Void> {
    @Override
    protected Void doInBackground(Void... voids) {
        publishProgress(10); // 10% progress
        publishProgress(100, 500);  // 100/500 = 20% progress
        publishProgress(20, 100, 40);  // 20% primary and 40% secondary progress
        // ...
    }
    // if required, the full spectra of `mDialog.updateXXX(...)` methods can be called from a custom `onProgressUpdate` implementation
}

and link it to the dialog:

MyTask task = new MyTask();
task.execute();

SimpleProgressDialog.bar()
        .title("...")
        .msg("...")
        .task(task, cancelable, autoDismiss) // optional cancel button and auto-dismiss functionality
        .show(this);

If cancelable is set and the cancel button is pressed, the task is canceled with mayInterruptIfRunning=false, so make sure to frequently check for ìsCancelled() in your tasks doInBackground method.
If autoDismiss is set, the dialog will be dismissed once the task is finished and the onResult method will be called with which=SimpleProgressDialog.COMPLETED.

Receiving results

See SimpleDialog

@eltos eltos self-assigned this May 27, 2021
@eltos eltos marked this pull request as ready for review May 27, 2021 20:09
@eltos eltos changed the title Add indeterminate progress dialog Add progress dialog May 27, 2021
@eltos eltos merged commit 3a51e73 into main May 28, 2021
@eltos eltos deleted the dialog-progress branch May 28, 2021 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request - a "SimpleProgressDialog" - progress bar (the indeterminate type)

1 participant