1/*
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;
39
40    /**
41     * The parameters for the alert.
42     */
43    protected AlertController.AlertParams mAlertParams;
44
45    @Override
46    protected void onCreate(Bundle savedInstanceState) {
47        super.onCreate(savedInstanceState);
48
49        mAlert = new AlertController(this, this, getWindow());
50        mAlertParams = new AlertController.AlertParams(this);
51    }
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.
68     *
69     * @see #mAlert
70     * @see #mAlertParams
71     */
72    protected void setupAlert() {
73        mAlertParams.apply(mAlert);
74        mAlert.installContent();
75    }
76
77    @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    }
88
89
90}
91