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 | |
Vishnu Nair | 9ccb1d2 | 2019-03-20 16:32:44 +0000 | [diff] [blame] | 19 | import com.android.internal.R; |
| 20 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 29 | public class BaseErrorDialog extends AlertDialog { |
riddle_hsu | 7f1e3f3 | 2014-07-08 04:30:19 +0800 | [diff] [blame] | 30 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | public BaseErrorDialog(Context context) { |
Lucas Dupin | 332d34f | 2018-09-11 11:08:17 -0700 | [diff] [blame] | 36 | super(context, com.android.internal.R.style.Theme_DeviceDefault_Dialog_AppError); |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 37 | context.assertRuntimeOverlayThemable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Vishnu Nair | 9ccb1d2 | 2019-03-20 16:32:44 +0000 | [diff] [blame] | 39 | getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
| 41 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 42 | WindowManager.LayoutParams attrs = getWindow().getAttributes(); |
| 43 | attrs.setTitle("Error Dialog"); |
| 44 | getWindow().setAttributes(attrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | public void onStart() { |
| 48 | super.onStart(); |
riddle_hsu | 7f1e3f3 | 2014-07-08 04:30:19 +0800 | [diff] [blame] | 49 | mHandler.sendEmptyMessage(DISABLE_BUTTONS); |
| 50 | mHandler.sendMessageDelayed(mHandler.obtainMessage(ENABLE_BUTTONS), 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 54 | if (mConsuming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 55 | //Slog.i(TAG, "Consuming: " + event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | return true; |
| 57 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 58 | //Slog.i(TAG, "Dispatching: " + event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | return super.dispatchKeyEvent(event); |
| 60 | } |
| 61 | |
| 62 | private void setEnabled(boolean enabled) { |
| 63 | Button b = (Button)findViewById(R.id.button1); |
| 64 | if (b != null) { |
| 65 | b.setEnabled(enabled); |
| 66 | } |
| 67 | b = (Button)findViewById(R.id.button2); |
| 68 | if (b != null) { |
| 69 | b.setEnabled(enabled); |
| 70 | } |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 71 | b = (Button)findViewById(R.id.button3); |
| 72 | if (b != null) { |
| 73 | b.setEnabled(enabled); |
| 74 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | private Handler mHandler = new Handler() { |
| 78 | public void handleMessage(Message msg) { |
riddle_hsu | 7f1e3f3 | 2014-07-08 04:30:19 +0800 | [diff] [blame] | 79 | if (msg.what == ENABLE_BUTTONS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | mConsuming = false; |
| 81 | setEnabled(true); |
riddle_hsu | 7f1e3f3 | 2014-07-08 04:30:19 +0800 | [diff] [blame] | 82 | } else if (msg.what == DISABLE_BUTTONS) { |
| 83 | setEnabled(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | } |