summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYuli Huang <yuli@google.com>2012-03-12 16:34:41 +0800
committerYuli Huang <yuli@google.com>2012-03-13 15:37:02 +0800
commit68c98d3213cc762673797b2ed1c061e2c3e63742 (patch)
treec170afe3ed303603c9b6944930081e1fbfa23119 /src
parent0778565d10d9c7ee903d8cb869be24278cf0ef09 (diff)
downloadandroid_packages_apps_Snap-68c98d3213cc762673797b2ed1c061e2c3e63742.tar.gz
android_packages_apps_Snap-68c98d3213cc762673797b2ed1c061e2c3e63742.tar.bz2
android_packages_apps_Snap-68c98d3213cc762673797b2ed1c061e2c3e63742.zip
Simplify PhotoEditor code.
1. Encapsulate spinner usages inside Toolbar. 2. Remove unnecessary static variable usages. Change-Id: Iaec614c5322a50c1e2c0cfa9cec1971b85e32f8a
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java53
1 files changed, 24 insertions, 29 deletions
diff --git a/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java b/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java
index 108c17d50..5bc544f9f 100644
--- a/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java
+++ b/src/com/android/gallery3d/photoeditor/SpinnerProgressDialog.java
@@ -17,6 +17,8 @@
package com.android.gallery3d.photoeditor;
import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
@@ -25,50 +27,45 @@ import android.widget.ProgressBar;
import com.android.gallery3d.R;
import java.util.ArrayList;
+import java.util.List;
/**
* Spinner model progress dialog that disables all tools for user interaction after it shows up and
- * 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.
+ * and re-enables them after it dismisses.
*/
public class SpinnerProgressDialog extends Dialog {
- private static SpinnerProgressDialog dialog;
- private final Toolbar toolbar;
- private final ArrayList<View> enabledTools = new ArrayList<View>();
+ /**
+ * Listener of touch events.
+ */
+ public interface OnTouchListener {
- public static void showDialog(Toolbar toolbar) {
- // There should be only one progress dialog running at a time.
- if (dialog == null) {
- dialog = new SpinnerProgressDialog(toolbar);
- dialog.show();
- }
+ public boolean onTouch(DialogInterface dialog, MotionEvent event);
}
- public static void dismissDialog() {
- if (dialog != null) {
- dialog.dismiss();
- dialog = null;
- }
- }
+ private final List<View> enabledTools = new ArrayList<View>();
+ private final OnTouchListener listener;
- private SpinnerProgressDialog(Toolbar toolbar) {
- super(toolbar.getContext(), R.style.SpinnerProgressDialog);
- addContentView(new ProgressBar(toolbar.getContext()), new LayoutParams(
+ public SpinnerProgressDialog(Context context, List<View> tools, OnTouchListener listener) {
+ super(context, R.style.SpinnerProgressDialog);
+ addContentView(new ProgressBar(context), new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
setCancelable(false);
- this.toolbar = toolbar;
+
+ for (View view : tools) {
+ if (view.isEnabled()) {
+ enabledTools.add(view);
+ }
+ }
+ this.listener = listener;
}
@Override
public void show() {
super.show();
// Disable enabled tools when showing spinner progress dialog.
- for (View view : toolbar.getTools()) {
- if (view.isEnabled()) {
- enabledTools.add(view);
- view.setEnabled(false);
- }
+ for (View view : enabledTools) {
+ view.setEnabled(false);
}
}
@@ -83,8 +80,6 @@ public class SpinnerProgressDialog extends Dialog {
@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 toolbar.dispatchTouchEvent(event);
+ return listener.onTouch(this, event);
}
}