| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.app; |
| 18 |
|
| 19 |
import android.app.Activity; |
| 20 |
import android.app.Dialog; |
| 21 |
import android.compat.annotation.UnsupportedAppUsage; |
| 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 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public abstract class AlertActivity extends Activity implements DialogInterface { |
| 36 |
|
| 37 |
@UnsupportedAppUsage |
| 38 |
public AlertActivity() { |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
@UnsupportedAppUsage |
| 47 |
protected AlertController mAlert; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
@UnsupportedAppUsage |
| 53 |
protected AlertController.AlertParams mAlertParams; |
| 54 |
|
| 55 |
@Override |
| 56 |
protected void onCreate(Bundle savedInstanceState) { |
| 57 |
super.onCreate(savedInstanceState); |
| 58 |
|
| 59 |
mAlert = AlertController.create(this, this, getWindow()); |
| 60 |
mAlertParams = new AlertController.AlertParams(this); |
| 61 |
} |
| 62 |
|
| 63 |
public void cancel() { |
| 64 |
finish(); |
| 65 |
} |
| 66 |
|
| 67 |
public void dismiss() { |
| 68 |
|
| 69 |
|
| 70 |
if (!isFinishing()) { |
| 71 |
finish(); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
@Override |
| 76 |
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 77 |
return dispatchPopulateAccessibilityEvent(this, event); |
| 78 |
} |
| 79 |
|
| 80 |
public static boolean dispatchPopulateAccessibilityEvent(Activity act, |
| 81 |
AccessibilityEvent event) { |
| 82 |
event.setClassName(Dialog.class.getName()); |
| 83 |
event.setPackageName(act.getPackageName()); |
| 84 |
|
| 85 |
ViewGroup.LayoutParams params = act.getWindow().getAttributes(); |
| 86 |
boolean isFullScreen = (params.width == ViewGroup.LayoutParams.MATCH_PARENT) && |
| 87 |
(params.height == ViewGroup.LayoutParams.MATCH_PARENT); |
| 88 |
event.setFullScreen(isFullScreen); |
| 89 |
|
| 90 |
return false; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
@UnsupportedAppUsage |
| 101 |
protected void setupAlert() { |
| 102 |
mAlert.installContent(mAlertParams); |
| 103 |
} |
| 104 |
|
| 105 |
@Override |
| 106 |
public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 107 |
if (mAlert.onKeyDown(keyCode, event)) return true; |
| 108 |
return super.onKeyDown(keyCode, event); |
| 109 |
} |
| 110 |
|
| 111 |
@Override |
| 112 |
public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 113 |
if (mAlert.onKeyUp(keyCode, event)) return true; |
| 114 |
return super.onKeyUp(keyCode, event); |
| 115 |
} |
| 116 |
} |