From 12cbc0984310035f98c2440d974f31ceaf149a00 Mon Sep 17 00:00:00 2001 From: Yuli Huang Date: Mon, 14 Nov 2011 22:38:16 +0800 Subject: Fix b/5517002 by dismissing running progress dialog in onPause(). Change-Id: I524f876e53776c38bc850120a2d7b7e6381ca33a --- .../android/gallery3d/photoeditor/EffectsBar.java | 5 +- .../android/gallery3d/photoeditor/PhotoEditor.java | 20 ++++---- .../photoeditor/SpinnerProgressDialog.java | 59 ++++++++++++---------- 3 files changed, 44 insertions(+), 40 deletions(-) (limited to 'src/com/android/gallery3d/photoeditor') diff --git a/src/com/android/gallery3d/photoeditor/EffectsBar.java b/src/com/android/gallery3d/photoeditor/EffectsBar.java index b4857e60d..40754040c 100644 --- a/src/com/android/gallery3d/photoeditor/EffectsBar.java +++ b/src/com/android/gallery3d/photoeditor/EffectsBar.java @@ -128,13 +128,12 @@ public class EffectsBar extends LinearLayout { private boolean exitActiveEffect(final Runnable runnableOnDone) { if (activeEffect != null) { - final SpinnerProgressDialog progressDialog = SpinnerProgressDialog.show( - (ViewGroup) getRootView().findViewById(R.id.toolbar)); + SpinnerProgressDialog.showDialog(); activeEffect.end(new Runnable() { @Override public void run() { - progressDialog.dismiss(); + SpinnerProgressDialog.dismissDialog(); View fullscreenTool = getRootView().findViewById(R.id.fullscreen_effect_tool); if (fullscreenTool != null) { ((ViewGroup) fullscreenTool.getParent()).removeView(fullscreenTool); diff --git a/src/com/android/gallery3d/photoeditor/PhotoEditor.java b/src/com/android/gallery3d/photoeditor/PhotoEditor.java index dba7e6258..8f3990b5e 100644 --- a/src/com/android/gallery3d/photoeditor/PhotoEditor.java +++ b/src/com/android/gallery3d/photoeditor/PhotoEditor.java @@ -42,6 +42,7 @@ public class PhotoEditor extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.photoeditor_main); + SpinnerProgressDialog.initialize((ViewGroup) findViewById(R.id.toolbar)); Intent intent = getIntent(); if (Intent.ACTION_EDIT.equalsIgnoreCase(intent.getAction())) { @@ -74,12 +75,8 @@ public class PhotoEditor extends Activity { actionBar.setClickRunnable(R.id.action_bar_back, createBackRunnable()); } - private SpinnerProgressDialog createProgressDialog() { - return SpinnerProgressDialog.show((ViewGroup) findViewById(R.id.toolbar)); - } - private void openPhoto() { - final SpinnerProgressDialog progressDialog = createProgressDialog(); + SpinnerProgressDialog.showDialog(); LoadScreennailTask.Callback callback = new LoadScreennailTask.Callback() { @Override @@ -88,7 +85,7 @@ public class PhotoEditor extends Activity { @Override public void onDone() { - progressDialog.dismiss(); + SpinnerProgressDialog.dismissDialog(); effectsBar.setEnabled(result != null); } }); @@ -106,12 +103,12 @@ public class PhotoEditor extends Activity { @Override public void run() { - final SpinnerProgressDialog progressDialog = createProgressDialog(); + SpinnerProgressDialog.showDialog(); OnDoneCallback callback = new OnDoneCallback() { @Override public void onDone() { - progressDialog.dismiss(); + SpinnerProgressDialog.dismissDialog(); } }; if (undo) { @@ -134,7 +131,7 @@ public class PhotoEditor extends Activity { @Override public void run() { - final SpinnerProgressDialog progressDialog = createProgressDialog(); + SpinnerProgressDialog.showDialog(); filterStack.getOutputBitmap(new OnDoneBitmapCallback() { @Override @@ -143,7 +140,7 @@ public class PhotoEditor extends Activity { @Override public void onComplete(Uri result) { - progressDialog.dismiss(); + SpinnerProgressDialog.dismissDialog(); saveUri = result; actionBar.updateSave(saveUri == null); } @@ -223,9 +220,10 @@ public class PhotoEditor extends Activity { @Override protected void onPause() { - // TODO: Close running progress dialogs as all pending operations will be paused. super.onPause(); filterStack.onPause(); + // Dismiss any running progress dialog as all operations are paused. + SpinnerProgressDialog.dismissDialog(); } @Override 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 enabledTools = new ArrayList(); - 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); -- cgit v1.2.3