blob: 7456def4c346ea61397e93673b123f263314c1ed [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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.internal.app;
18
19import android.app.Activity;
20import android.content.DialogInterface;
21import android.os.Bundle;
22import android.view.KeyEvent;
23
24/**
25 * An activity that follows the visual style of an AlertDialog.
26 *
27 * @see #mAlert
28 * @see #mAlertParams
29 * @see #setupAlert()
30 */
31public abstract class AlertActivity extends Activity implements DialogInterface {
32
33 /**
34 * The model for the alert.
35 *
36 * @see #mAlertParams
37 */
38 protected AlertController mAlert;
Amith Yamasani655d0e22013-06-12 14:19:10 -070039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 /**
41 * The parameters for the alert.
42 */
43 protected AlertController.AlertParams mAlertParams;
Amith Yamasani655d0e22013-06-12 14:19:10 -070044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 @Override
46 protected void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
Amith Yamasani655d0e22013-06-12 14:19:10 -070048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 mAlert = new AlertController(this, this, getWindow());
Amith Yamasani655d0e22013-06-12 14:19:10 -070050 mAlertParams = new AlertController.AlertParams(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 }
52
53 public void cancel() {
54 finish();
55 }
56
57 public void dismiss() {
58 // This is called after the click, since we finish when handling the
59 // click, don't do that again here.
60 if (!isFinishing()) {
61 finish();
62 }
63 }
64
65 /**
66 * Sets up the alert, including applying the parameters to the alert model,
67 * and installing the alert's content.
Amith Yamasani655d0e22013-06-12 14:19:10 -070068 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 * @see #mAlert
70 * @see #mAlertParams
71 */
72 protected void setupAlert() {
73 mAlertParams.apply(mAlert);
74 mAlert.installContent();
75 }
Amith Yamasani655d0e22013-06-12 14:19:10 -070076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 @Override
78 public boolean onKeyDown(int keyCode, KeyEvent event) {
79 if (mAlert.onKeyDown(keyCode, event)) return true;
80 return super.onKeyDown(keyCode, event);
81 }
82
83 @Override
84 public boolean onKeyUp(int keyCode, KeyEvent event) {
85 if (mAlert.onKeyUp(keyCode, event)) return true;
86 return super.onKeyUp(keyCode, event);
87 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088}