summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYuli Huang <yuli@google.com>2011-11-14 22:38:16 +0800
committerYuli Huang <yuli@google.com>2011-11-15 12:02:25 +0800
commitadf860cd9edec2bddb5ad0330c08a3a04c2b4bcc (patch)
treed72848a03d167a1846363359b8515073c574fb71 /src
parentae76c972d3735796663eff50fcb2a4fc7fcd6db0 (diff)
downloadandroid_packages_apps_Snap-adf860cd9edec2bddb5ad0330c08a3a04c2b4bcc.tar.gz
android_packages_apps_Snap-adf860cd9edec2bddb5ad0330c08a3a04c2b4bcc.tar.bz2
android_packages_apps_Snap-adf860cd9edec2bddb5ad0330c08a3a04c2b4bcc.zip
Fix b/5517002 by dismissing running progress dialog in onPause().
Change-Id: I524f876e53776c38bc850120a2d7b7e6381ca33a
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java59
1 files changed, 33 insertions, 26 deletions
diff --git a/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java b/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java
index 207c2d142..065075e52 100644
--- a/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java
+++ b/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java
@@ -29,46 +29,53 @@ import java.util.ArrayList;
/**
* Spinner model progress dialog that disables all tools for user interaction after it shows up and
- * and re-enables them after it dismisses.
+ * and re-enables them after it dismisses; this class along with all its methods should be accessed
+ * in only UI thread and allows only one instance at a time.
*/
public class SpinnerProgressDialog extends Dialog {
- private final ViewGroup toolbar;
+ private static ViewGroup toolbar;
+ private static SpinnerProgressDialog dialog;
private final ArrayList<View> enabledTools = new ArrayList<View>();
- public static SpinnerProgressDialog show(ViewGroup toolbar) {
- SpinnerProgressDialog dialog = new SpinnerProgressDialog(toolbar);
- dialog.setCancelable(false);
- dialog.show();
- return dialog;
+ public static void initialize(ViewGroup toolbar) {
+ SpinnerProgressDialog.toolbar = toolbar;
}
- private SpinnerProgressDialog(ViewGroup toolbar) {
- super(toolbar.getContext(), R.style.SpinnerProgressDialog);
-
- addContentView(new ProgressBar(toolbar.getContext()), new LayoutParams(
- LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
-
- // Disable enabled tools when showing spinner progress dialog.
- for (int i = 0; i < toolbar.getChildCount(); i++) {
- View view = toolbar.getChildAt(i);
- if (view.isEnabled()) {
- enabledTools.add(view);
- view.setEnabled(false);
+ public static void showDialog() {
+ // There should be only one progress dialog running at a time.
+ if (dialog == null) {
+ dialog = new SpinnerProgressDialog();
+ dialog.setCancelable(false);
+ dialog.show();
+ // Disable enabled tools when showing spinner progress dialog.
+ for (int i = 0; i < toolbar.getChildCount(); i++) {
+ View view = toolbar.getChildAt(i);
+ if (view.isEnabled()) {
+ dialog.enabledTools.add(view);
+ view.setEnabled(false);
+ }
}
}
- this.toolbar = toolbar;
}
- @Override
- public void dismiss() {
- super.dismiss();
- // Enable tools that were disabled by this spinner progress dialog.
- for (View view : enabledTools) {
- view.setEnabled(true);
+ public static void dismissDialog() {
+ if (dialog != null) {
+ dialog.dismiss();
+ // Enable tools that were disabled by this spinner progress dialog.
+ for (View view : dialog.enabledTools) {
+ view.setEnabled(true);
+ }
+ dialog = null;
}
}
+ private SpinnerProgressDialog() {
+ super(toolbar.getContext(), R.style.SpinnerProgressDialog);
+ addContentView(new ProgressBar(toolbar.getContext()), new LayoutParams(
+ LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+ }
+
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);