The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 36 | WindowManager.LayoutParams attrs = getWindow().getAttributes(); |
| 37 | attrs.setTitle("Error Dialog"); |
| 38 | getWindow().setAttributes(attrs); |
Adam Powell | 947f782 | 2011-01-07 22:30:48 -0800 | [diff] [blame] | 39 | setIconAttribute(R.attr.alertDialogIcon); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | public void onStart() { |
| 43 | super.onStart(); |
| 44 | setEnabled(false); |
| 45 | mHandler.sendMessageDelayed(mHandler.obtainMessage(0), 1000); |
| 46 | } |
| 47 | |
| 48 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 49 | if (mConsuming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 50 | //Slog.i(TAG, "Consuming: " + event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | return true; |
| 52 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 53 | //Slog.i(TAG, "Dispatching: " + event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | return super.dispatchKeyEvent(event); |
| 55 | } |
| 56 | |
| 57 | private void setEnabled(boolean enabled) { |
| 58 | Button b = (Button)findViewById(R.id.button1); |
| 59 | if (b != null) { |
| 60 | b.setEnabled(enabled); |
| 61 | } |
| 62 | b = (Button)findViewById(R.id.button2); |
| 63 | if (b != null) { |
| 64 | b.setEnabled(enabled); |
| 65 | } |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 66 | b = (Button)findViewById(R.id.button3); |
| 67 | if (b != null) { |
| 68 | b.setEnabled(enabled); |
| 69 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | private Handler mHandler = new Handler() { |
| 73 | public void handleMessage(Message msg) { |
| 74 | if (msg.what == 0) { |
| 75 | mConsuming = false; |
| 76 | setEnabled(true); |
| 77 | } |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | private boolean mConsuming = true; |
| 82 | } |