| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package com.android.internal.globalactions; |
| 17 |
|
| 18 |
import android.app.Dialog; |
| 19 |
import android.content.Context; |
| 20 |
import android.content.DialogInterface; |
| 21 |
import android.os.Bundle; |
| 22 |
import android.util.TypedValue; |
| 23 |
import android.view.accessibility.AccessibilityEvent; |
| 24 |
import android.view.KeyEvent; |
| 25 |
import android.widget.ListView; |
| 26 |
import com.android.internal.app.AlertController; |
| 27 |
|
| 28 |
|
| 29 |
public final class ActionsDialog extends Dialog implements DialogInterface { |
| 30 |
private final Context mContext; |
| 31 |
private final AlertController mAlert; |
| 32 |
private final ActionsAdapter mAdapter; |
| 33 |
|
| 34 |
public ActionsDialog(Context context, AlertController.AlertParams params) { |
| 35 |
super(context, getDialogTheme(context)); |
| 36 |
mContext = getContext(); |
| 37 |
mAlert = AlertController.create(mContext, this, getWindow()); |
| 38 |
mAdapter = (ActionsAdapter) params.mAdapter; |
| 39 |
params.apply(mAlert); |
| 40 |
} |
| 41 |
|
| 42 |
private static int getDialogTheme(Context context) { |
| 43 |
TypedValue outValue = new TypedValue(); |
| 44 |
context.getTheme().resolveAttribute(com.android.internal.R.attr.alertDialogTheme, |
| 45 |
outValue, true); |
| 46 |
return outValue.resourceId; |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
protected void onStart() { |
| 51 |
super.setCanceledOnTouchOutside(true); |
| 52 |
super.onStart(); |
| 53 |
} |
| 54 |
|
| 55 |
public ListView getListView() { |
| 56 |
return mAlert.getListView(); |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
protected void onCreate(Bundle savedInstanceState) { |
| 61 |
super.onCreate(savedInstanceState); |
| 62 |
mAlert.installContent(); |
| 63 |
} |
| 64 |
|
| 65 |
@Override |
| 66 |
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 67 |
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { |
| 68 |
for (int i = 0; i < mAdapter.getCount(); ++i) { |
| 69 |
CharSequence label = |
| 70 |
mAdapter.getItem(i).getLabelForAccessibility(getContext()); |
| 71 |
if (label != null) { |
| 72 |
event.getText().add(label); |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
return super.dispatchPopulateAccessibilityEvent(event); |
| 77 |
} |
| 78 |
|
| 79 |
@Override |
| 80 |
public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 81 |
if (mAlert.onKeyDown(keyCode, event)) { |
| 82 |
return true; |
| 83 |
} |
| 84 |
return super.onKeyDown(keyCode, event); |
| 85 |
} |
| 86 |
|
| 87 |
@Override |
| 88 |
public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 89 |
if (mAlert.onKeyUp(keyCode, event)) { |
| 90 |
return true; |
| 91 |
} |
| 92 |
return super.onKeyUp(keyCode, event); |
| 93 |
} |
| 94 |
} |