From 939e909cc937f20b762c22cdb67c55f84a3d0ffd Mon Sep 17 00:00:00 2001 From: Yuli Huang Date: Thu, 10 Nov 2011 16:50:31 +0800 Subject: Fix b/5518211 by disabling effects when photo cannot be loaded. Change-Id: I9e5ae9cfaf9bee52cd63a0e77a3b083e47b59335 --- .../photoeditor/SpinnerProgressDialog.java | 42 ++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java') diff --git a/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java b/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java index 9a3d8499a..207c2d142 100644 --- a/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java +++ b/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java @@ -18,55 +18,61 @@ package com.android.gallery3d.photoeditor; import android.app.Dialog; import android.view.MotionEvent; +import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.widget.ProgressBar; import com.android.gallery3d.R; +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. */ public class SpinnerProgressDialog extends Dialog { - private final ViewGroup tools; + private final ViewGroup toolbar; + private final ArrayList enabledTools = new ArrayList(); - public static SpinnerProgressDialog show(ViewGroup tools) { - SpinnerProgressDialog dialog = new SpinnerProgressDialog(tools); + public static SpinnerProgressDialog show(ViewGroup toolbar) { + SpinnerProgressDialog dialog = new SpinnerProgressDialog(toolbar); dialog.setCancelable(false); dialog.show(); return dialog; } - private SpinnerProgressDialog(ViewGroup tools) { - super(tools.getContext(), R.style.SpinnerProgressDialog); + private SpinnerProgressDialog(ViewGroup toolbar) { + super(toolbar.getContext(), R.style.SpinnerProgressDialog); - addContentView(new ProgressBar(tools.getContext()), new LayoutParams( + addContentView(new ProgressBar(toolbar.getContext()), new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); - this.tools = tools; - enableTools(false); + // 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); + } + } + this.toolbar = toolbar; } @Override public void dismiss() { super.dismiss(); - - enableTools(true); + // Enable tools that were disabled by this spinner progress dialog. + for (View view : enabledTools) { + view.setEnabled(true); + } } @Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); - // Pass touch events to tools for killing idle even when the progress dialog is shown. - return tools.dispatchTouchEvent(event); - } - - private void enableTools(boolean enabled) { - for (int i = 0; i < tools.getChildCount(); i++) { - tools.getChildAt(i).setEnabled(enabled); - } + return toolbar.dispatchTouchEvent(event); } } -- cgit v1.2.3