Home | History | Annotate | Download | only in photoeditor
      1 /*
      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 
     17 package com.android.gallery3d.photoeditor;
     18 
     19 import android.app.Dialog;
     20 import android.content.Context;
     21 import android.content.DialogInterface;
     22 import android.view.MotionEvent;
     23 import android.view.View;
     24 import android.view.ViewGroup.LayoutParams;
     25 import android.widget.ProgressBar;
     26 
     27 import com.android.gallery3d.R;
     28 
     29 import java.util.ArrayList;
     30 import java.util.List;
     31 
     32 /**
     33  * Spinner model progress dialog that disables all tools for user interaction after it shows up and
     34  * and re-enables them after it dismisses.
     35  */
     36 public class SpinnerProgressDialog extends Dialog {
     37 
     38     /**
     39      * Listener of touch events.
     40      */
     41     public interface OnTouchListener {
     42 
     43         public boolean onTouch(DialogInterface dialog, MotionEvent event);
     44     }
     45 
     46     private final List<View> enabledTools = new ArrayList<View>();
     47     private final OnTouchListener listener;
     48 
     49     public SpinnerProgressDialog(Context context, List<View> tools, OnTouchListener listener) {
     50         super(context, R.style.SpinnerProgressDialog);
     51         addContentView(new ProgressBar(context), new LayoutParams(
     52                 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
     53         setCancelable(false);
     54 
     55         for (View view : tools) {
     56             if (view.isEnabled()) {
     57                 enabledTools.add(view);
     58             }
     59         }
     60         this.listener = listener;
     61     }
     62 
     63     @Override
     64     public void show() {
     65         super.show();
     66         // Disable enabled tools when showing spinner progress dialog.
     67         for (View view : enabledTools) {
     68             view.setEnabled(false);
     69         }
     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         }
     79     }
     80 
     81     @Override
     82     public boolean onTouchEvent(MotionEvent event) {
     83         return listener.onTouch(this, event);
     84     }
     85 }
     86