blob: 5bc544f9f76c7db7d471dd52a4ef018c6dfc1093 [file] [log] [blame]
Yuli Huang6a12ad72011-09-12 22:25:30 +08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.gallery3d.photoeditor;
18
19import android.app.Dialog;
Yuli Huang5cac6d52012-03-12 16:34:41 +080020import android.content.Context;
21import android.content.DialogInterface;
Yuli Huang6a12ad72011-09-12 22:25:30 +080022import android.view.MotionEvent;
Yuli Huangf963bc22011-11-10 16:50:31 +080023import android.view.View;
Yuli Huang6a12ad72011-09-12 22:25:30 +080024import android.view.ViewGroup.LayoutParams;
25import android.widget.ProgressBar;
26
27import com.android.gallery3d.R;
28
Yuli Huangf963bc22011-11-10 16:50:31 +080029import java.util.ArrayList;
Yuli Huang5cac6d52012-03-12 16:34:41 +080030import java.util.List;
Yuli Huangf963bc22011-11-10 16:50:31 +080031
Yuli Huang6a12ad72011-09-12 22:25:30 +080032/**
33 * Spinner model progress dialog that disables all tools for user interaction after it shows up and
Yuli Huang5cac6d52012-03-12 16:34:41 +080034 * and re-enables them after it dismisses.
Yuli Huang6a12ad72011-09-12 22:25:30 +080035 */
36public class SpinnerProgressDialog extends Dialog {
37
Yuli Huang5cac6d52012-03-12 16:34:41 +080038 /**
39 * Listener of touch events.
40 */
41 public interface OnTouchListener {
Yuli Huang6a12ad72011-09-12 22:25:30 +080042
Yuli Huang5cac6d52012-03-12 16:34:41 +080043 public boolean onTouch(DialogInterface dialog, MotionEvent event);
Yuli Huang6a12ad72011-09-12 22:25:30 +080044 }
45
Yuli Huang5cac6d52012-03-12 16:34:41 +080046 private final List<View> enabledTools = new ArrayList<View>();
47 private final OnTouchListener listener;
Yuli Huang6a12ad72011-09-12 22:25:30 +080048
Yuli Huang5cac6d52012-03-12 16:34:41 +080049 public SpinnerProgressDialog(Context context, List<View> tools, OnTouchListener listener) {
50 super(context, R.style.SpinnerProgressDialog);
51 addContentView(new ProgressBar(context), new LayoutParams(
Yuli Huang3235a3e2011-11-14 22:38:16 +080052 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
Yuli Huangd67ec742012-03-07 01:18:08 +080053 setCancelable(false);
Yuli Huang5cac6d52012-03-12 16:34:41 +080054
55 for (View view : tools) {
56 if (view.isEnabled()) {
57 enabledTools.add(view);
58 }
59 }
60 this.listener = listener;
Yuli Huangd67ec742012-03-07 01:18:08 +080061 }
62
63 @Override
64 public void show() {
65 super.show();
66 // Disable enabled tools when showing spinner progress dialog.
Yuli Huang5cac6d52012-03-12 16:34:41 +080067 for (View view : enabledTools) {
68 view.setEnabled(false);
Yuli Huangd67ec742012-03-07 01:18:08 +080069 }
70 }
71
72 @Override
73 public void dismiss() {
74 super.dismiss();
75 // Enable tools that were disabled by this spinner progress dialog.
76 for (View view : enabledTools) {
77 view.setEnabled(true);
78 }
Yuli Huang3235a3e2011-11-14 22:38:16 +080079 }
80
Yuli Huang6a12ad72011-09-12 22:25:30 +080081 @Override
82 public boolean onTouchEvent(MotionEvent event) {
Yuli Huang5cac6d52012-03-12 16:34:41 +080083 return listener.onTouch(this, event);
Yuli Huang6a12ad72011-09-12 22:25:30 +080084 }
85}