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.photoeditor; 18 19 import android.app.Dialog; 20 import android.view.MotionEvent; 21 import android.view.ViewGroup; 22 import android.view.ViewGroup.LayoutParams; 23 import android.widget.ProgressBar; 24 25 /** 26 * Spinner model progress dialog that disables all tools for user interaction after it shows up and 27 * and re-enables them after it dismisses. 28 */ 29 public class SpinnerProgressDialog extends Dialog { 30 31 private final ViewGroup tools; 32 show(ViewGroup tools)33 public static SpinnerProgressDialog show(ViewGroup tools) { 34 SpinnerProgressDialog dialog = new SpinnerProgressDialog(tools); 35 dialog.show(); 36 return dialog; 37 } 38 SpinnerProgressDialog(ViewGroup tools)39 private SpinnerProgressDialog(ViewGroup tools) { 40 super(tools.getContext(), R.style.SpinnerProgressDialog); 41 42 addContentView(new ProgressBar(tools.getContext()), new LayoutParams( 43 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 44 45 this.tools = tools; 46 enableTools(false); 47 } 48 49 @Override dismiss()50 public void dismiss() { 51 super.dismiss(); 52 53 enableTools(true); 54 } 55 56 @Override onTouchEvent(MotionEvent event)57 public boolean onTouchEvent(MotionEvent event) { 58 super.onTouchEvent(event); 59 60 // Pass touch events to tools for killing idle even when the progress dialog is shown. 61 return tools.onInterceptTouchEvent(event); 62 } 63 enableTools(boolean enabled)64 private void enableTools(boolean enabled) { 65 for (int i = 0; i < tools.getChildCount(); i++) { 66 tools.getChildAt(i).setEnabled(enabled); 67 } 68 } 69 } 70