BaseErrorDialog.java revision 8a9b22056b13477f59df934928c00c58b5871c95
1840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee/*
2840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee * Copyright (C) 2006 The Android Open Source Project
3840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee *
4840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee * Licensed under the Apache License, Version 2.0 (the "License");
5840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee * you may not use this file except in compliance with the License.
6840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee * You may obtain a copy of the License at
7840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee *
8840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee *      http://www.apache.org/licenses/LICENSE-2.0
9840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee *
10840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee * Unless required by applicable law or agreed to in writing, software
11840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee * distributed under the License is distributed on an "AS IS" BASIS,
12840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee * See the License for the specific language governing permissions and
14840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee * limitations under the License.
15840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee */
16840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee
17840c566d13b8c84ad5edb37006176d6731bad250Bryce Leepackage com.android.server.am;
18840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee
195daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Leeimport com.android.internal.R;
20840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee
21840c566d13b8c84ad5edb37006176d6731bad250Bryce Leeimport android.app.AlertDialog;
225daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Leeimport android.content.Context;
23840c566d13b8c84ad5edb37006176d6731bad250Bryce Leeimport android.os.Handler;
24943ebe705cece8f643d9d7ace005322ddf114d86Bryce Leeimport android.os.Message;
25840c566d13b8c84ad5edb37006176d6731bad250Bryce Leeimport android.view.KeyEvent;
263345c4ea9687bb35a8c419ec21ec90b49616b2c9Bryce Leeimport android.view.WindowManager;
27840c566d13b8c84ad5edb37006176d6731bad250Bryce Leeimport android.widget.Button;
28840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee
29840c566d13b8c84ad5edb37006176d6731bad250Bryce Leeclass BaseErrorDialog extends AlertDialog {
30840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee    public BaseErrorDialog(Context context) {
31840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        super(context, com.android.internal.R.style.Theme_Dialog_AppError);
32840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee
33840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
34840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
35840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
36840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        getWindow().setTitle("Error Dialog");
37840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        setIcon(R.drawable.ic_dialog_alert);
38840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee    }
39840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee
40840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee    public void onStart() {
41840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        super.onStart();
42840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        setEnabled(false);
43840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        mHandler.sendMessageDelayed(mHandler.obtainMessage(0), 1000);
4404ab3466fabb7244660adf54740a4f60874b02a1Bryce Lee    }
4504ab3466fabb7244660adf54740a4f60874b02a1Bryce Lee
46840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee    public boolean dispatchKeyEvent(KeyEvent event) {
47840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        if (mConsuming) {
48840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee            //Slog.i(TAG, "Consuming: " + event);
49840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee            return true;
50840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        }
5104ab3466fabb7244660adf54740a4f60874b02a1Bryce Lee        //Slog.i(TAG, "Dispatching: " + event);
52840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        return super.dispatchKeyEvent(event);
5304ab3466fabb7244660adf54740a4f60874b02a1Bryce Lee    }
5404ab3466fabb7244660adf54740a4f60874b02a1Bryce Lee
55840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee    private void setEnabled(boolean enabled) {
56840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        Button b = (Button)findViewById(R.id.button1);
575daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee        if (b != null) {
58840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee            b.setEnabled(enabled);
59840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        }
60840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        b = (Button)findViewById(R.id.button2);
6104ab3466fabb7244660adf54740a4f60874b02a1Bryce Lee        if (b != null) {
62840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee            b.setEnabled(enabled);
63840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        }
6404ab3466fabb7244660adf54740a4f60874b02a1Bryce Lee        b = (Button)findViewById(R.id.button3);
6504ab3466fabb7244660adf54740a4f60874b02a1Bryce Lee        if (b != null) {
66840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee            b.setEnabled(enabled);
67840c566d13b8c84ad5edb37006176d6731bad250Bryce Lee        }
685daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee    }
695daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee
705daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee    private Handler mHandler = new Handler() {
715daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee        public void handleMessage(Message msg) {
725daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee            if (msg.what == 0) {
735daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee                mConsuming = false;
745daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee                setEnabled(true);
755daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee            }
765daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee        }
775daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee    };
785daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee
795daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee    private boolean mConsuming = true;
805daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee}
815daa3121a92f5e3124b8db469aeddea269a4c1dfBryce Lee