aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressTask.java
diff options
context:
space:
mode:
Diffstat (limited to 'sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressTask.java')
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressTask.java49
1 files changed, 39 insertions, 10 deletions
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressTask.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressTask.java
index 42d5558..2563a5f 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressTask.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressTask.java
@@ -27,21 +27,48 @@ import org.eclipse.swt.widgets.Shell;
*/
public final class ProgressTask extends TaskMonitorImpl {
+ private final String mTitle;
private final ProgressTaskDialog mDialog;
- private boolean mAutomaticallyCloseOnTaskCompletion = true;
+ private volatile boolean mAutoClose = true;
/**
* Creates a new {@link ProgressTask} with the given title.
- * The given task will execute in a separate thread (not the UI thread).
- *
- * This blocks till the thread ends.
+ * This does NOT start the task. The caller must invoke {@link #start(ITask)}.
*/
- public ProgressTask(Shell parent, String title, ITask task) {
+ public ProgressTask(Shell parent, String title) {
super(new ProgressTaskDialog(parent));
+ mTitle = title;
mDialog = (ProgressTaskDialog) getUiProvider();
- mDialog.setText(title);
- mDialog.open(createTaskThread(title, task));
+ mDialog.setText(mTitle);
+ }
+
+ /**
+ * Execute the given task in a separate thread (not the UI thread).
+ * This blocks till the thread ends.
+ * <p/>
+ * The {@link ProgressTask} must not be reused after this call.
+ */
+ public void start(ITask task) {
+ assert mDialog != null;
+ mDialog.open(createTaskThread(mTitle, task));
+ }
+
+ /**
+ * Changes the auto-close behavior of the dialog on task completion.
+ *
+ * @param autoClose True if the dialog should be closed automatically when the task
+ * has completed.
+ */
+ public void setAutoClose(boolean autoClose) {
+ if (autoClose != mAutoClose) {
+ if (autoClose) {
+ mDialog.setAutoCloseRequested();
+ } else {
+ mDialog.setManualCloseRequested();
+ }
+ mAutoClose = autoClose;
+ }
}
/**
@@ -56,7 +83,7 @@ public final class ProgressTask extends TaskMonitorImpl {
@Override
public void run() {
task.run(ProgressTask.this);
- if (mAutomaticallyCloseOnTaskCompletion) {
+ if (mAutoClose) {
mDialog.setAutoCloseRequested();
} else {
mDialog.setManualCloseRequested();
@@ -68,12 +95,14 @@ public final class ProgressTask extends TaskMonitorImpl {
}
/**
- * Sets the dialog to not auto-close since we want the user to see the error.
* {@inheritDoc}
+ * <p/>
+ * Sets the dialog to not auto-close since we want the user to see the error
+ * (this is equivalent to calling {@code setAutoClose(false)}).
*/
@Override
public void logError(String format, Object...args) {
- mAutomaticallyCloseOnTaskCompletion = false;
+ setAutoClose(false);
super.logError(format, args);
}
}