• 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.app.AlertDialog;
21 import android.app.Dialog;
22 import android.content.DialogInterface;
23 import android.os.Bundle;
24 import android.text.TextUtils;
25 import android.view.KeyEvent;
26 import android.view.ViewGroup;
27 import android.view.accessibility.AccessibilityEvent;
28 
29 /**
30  * An activity that follows the visual style of an AlertDialog.
31  *
32  * @see #mAlert
33  * @see #mAlertParams
34  * @see #setupAlert()
35  */
36 public abstract class AlertActivity extends Activity implements DialogInterface {
37 
38     /**
39      * The model for the alert.
40      *
41      * @see #mAlertParams
42      */
43     protected AlertController mAlert;
44 
45     /**
46      * The parameters for the alert.
47      */
48     protected AlertController.AlertParams mAlertParams;
49 
50     @Override
onCreate(Bundle savedInstanceState)51     protected void onCreate(Bundle savedInstanceState) {
52         super.onCreate(savedInstanceState);
53 
54         mAlert = new AlertController(this, this, getWindow());
55         mAlertParams = new AlertController.AlertParams(this);
56     }
57 
cancel()58     public void cancel() {
59         finish();
60     }
61 
dismiss()62     public void dismiss() {
63         // This is called after the click, since we finish when handling the
64         // click, don't do that again here.
65         if (!isFinishing()) {
66             finish();
67         }
68     }
69 
70     @Override
dispatchPopulateAccessibilityEvent(AccessibilityEvent event)71     public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
72         event.setClassName(Dialog.class.getName());
73         event.setPackageName(getPackageName());
74 
75         ViewGroup.LayoutParams params = getWindow().getAttributes();
76         boolean isFullScreen = (params.width == ViewGroup.LayoutParams.MATCH_PARENT) &&
77                 (params.height == ViewGroup.LayoutParams.MATCH_PARENT);
78         event.setFullScreen(isFullScreen);
79 
80         return false;
81     }
82 
83     /**
84      * Sets up the alert, including applying the parameters to the alert model,
85      * and installing the alert's content.
86      *
87      * @see #mAlert
88      * @see #mAlertParams
89      */
setupAlert()90     protected void setupAlert() {
91         mAlertParams.apply(mAlert);
92         mAlert.installContent();
93     }
94 
95     @Override
onKeyDown(int keyCode, KeyEvent event)96     public boolean onKeyDown(int keyCode, KeyEvent event) {
97         if (mAlert.onKeyDown(keyCode, event)) return true;
98         return super.onKeyDown(keyCode, event);
99     }
100 
101     @Override
onKeyUp(int keyCode, KeyEvent event)102     public boolean onKeyUp(int keyCode, KeyEvent event) {
103         if (mAlert.onKeyUp(keyCode, event)) return true;
104         return super.onKeyUp(keyCode, event);
105     }
106 }
107