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