blob: 5f7f67a8a5e8496504bd31cc4d7398afc93c17de [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server.am;
18
19import com.android.internal.R;
20
21import android.app.AlertDialog;
22import android.content.Context;
23import android.os.Handler;
24import android.os.Message;
25import android.view.KeyEvent;
26import android.view.WindowManager;
27import android.widget.Button;
28
29class BaseErrorDialog extends AlertDialog {
riddle_hsu7f1e3f32014-07-08 04:30:19 +080030 private static final int ENABLE_BUTTONS = 0;
31 private static final int DISABLE_BUTTONS = 1;
32
33 private boolean mConsuming = true;
34
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 public BaseErrorDialog(Context context) {
36 super(context, com.android.internal.R.style.Theme_Dialog_AppError);
37
38 getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
39 getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
40 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070041 WindowManager.LayoutParams attrs = getWindow().getAttributes();
42 attrs.setTitle("Error Dialog");
43 getWindow().setAttributes(attrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 }
45
46 public void onStart() {
47 super.onStart();
riddle_hsu7f1e3f32014-07-08 04:30:19 +080048 mHandler.sendEmptyMessage(DISABLE_BUTTONS);
49 mHandler.sendMessageDelayed(mHandler.obtainMessage(ENABLE_BUTTONS), 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 }
51
52 public boolean dispatchKeyEvent(KeyEvent event) {
53 if (mConsuming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080054 //Slog.i(TAG, "Consuming: " + event);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 return true;
56 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080057 //Slog.i(TAG, "Dispatching: " + event);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 return super.dispatchKeyEvent(event);
59 }
60
61 private void setEnabled(boolean enabled) {
62 Button b = (Button)findViewById(R.id.button1);
63 if (b != null) {
64 b.setEnabled(enabled);
65 }
66 b = (Button)findViewById(R.id.button2);
67 if (b != null) {
68 b.setEnabled(enabled);
69 }
Dan Egnorb7f03672009-12-09 16:22:32 -080070 b = (Button)findViewById(R.id.button3);
71 if (b != null) {
72 b.setEnabled(enabled);
73 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 }
75
76 private Handler mHandler = new Handler() {
77 public void handleMessage(Message msg) {
riddle_hsu7f1e3f32014-07-08 04:30:19 +080078 if (msg.what == ENABLE_BUTTONS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 mConsuming = false;
80 setEnabled(true);
riddle_hsu7f1e3f32014-07-08 04:30:19 +080081 } else if (msg.what == DISABLE_BUTTONS) {
82 setEnabled(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 }
84 }
85 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086}