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