• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.internal.app;
18 
19 import android.app.Activity;
20 import android.content.DialogInterface;
21 import android.os.Bundle;
22 import 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  */
31 public 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
onCreate(Bundle savedInstanceState)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 
cancel()53     public void cancel() {
54         finish();
55     }
56 
dismiss()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      */
setupAlert()72     protected void setupAlert() {
73         mAlertParams.apply(mAlert);
74         mAlert.installContent();
75     }
76 
77     @Override
onKeyDown(int keyCode, KeyEvent event)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
onKeyUp(int keyCode, KeyEvent event)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