1 /* 2 * Copyright (C) 2006 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.server.am; 18 19 import com.android.internal.R; 20 21 import android.app.AlertDialog; 22 import android.content.Context; 23 import android.os.Handler; 24 import android.os.Message; 25 import android.view.KeyEvent; 26 import android.view.WindowManager; 27 import android.widget.Button; 28 29 class BaseErrorDialog extends AlertDialog { 30 public BaseErrorDialog(Context context) { 31 super(context, com.android.internal.R.style.Theme_Dialog_AppError); 32 33 getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); 34 getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 35 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 36 getWindow().setTitle("Error Dialog"); 37 setIcon(R.drawable.ic_dialog_alert); 38 } 39 40 public void onStart() { 41 super.onStart(); 42 setEnabled(false); 43 mHandler.sendMessageDelayed(mHandler.obtainMessage(0), 1000); 44 } 45 46 public boolean dispatchKeyEvent(KeyEvent event) { 47 if (mConsuming) { 48 //Slog.i(TAG, "Consuming: " + event); 49 return true; 50 } 51 //Slog.i(TAG, "Dispatching: " + event); 52 return super.dispatchKeyEvent(event); 53 } 54 55 private void setEnabled(boolean enabled) { 56 Button b = (Button)findViewById(R.id.button1); 57 if (b != null) { 58 b.setEnabled(enabled); 59 } 60 b = (Button)findViewById(R.id.button2); 61 if (b != null) { 62 b.setEnabled(enabled); 63 } 64 b = (Button)findViewById(R.id.button3); 65 if (b != null) { 66 b.setEnabled(enabled); 67 } 68 } 69 70 private Handler mHandler = new Handler() { 71 public void handleMessage(Message msg) { 72 if (msg.what == 0) { 73 mConsuming = false; 74 setEnabled(true); 75 } 76 } 77 }; 78 79 private boolean mConsuming = true; 80 } 81