GlobalActionspublic class GlobalActions extends Object implements DialogInterface.OnDismissListener, DialogInterface.OnClickListenerHelper to show the global actions dialog. Each item is an {@link Action} that
may show depending on whether the keyguard is showing, and whether the device
is provisioned. |
Fields Summary |
---|
private android.app.StatusBarManager | mStatusBar | private final android.content.Context | mContext | private final android.os.LocalPowerManager | mPowerManager | private final android.media.AudioManager | mAudioManager | private ArrayList | mItems | private android.app.AlertDialog | mDialog | private ToggleAction | mSilentModeToggle | private MyAdapter | mAdapter | private boolean | mKeyguardShowing | private boolean | mDeviceProvisioned | private android.content.BroadcastReceiver | mBroadcastReceiver | private static final int | MESSAGE_DISMISS | private android.os.Handler | mHandler |
Constructors Summary |
---|
public GlobalActions(android.content.Context context, android.os.LocalPowerManager powerManager)
mContext = context;
mPowerManager = powerManager;
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
// receive broadcasts
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
context.registerReceiver(mBroadcastReceiver, filter);
|
Methods Summary |
---|
private android.app.AlertDialog | createDialog()Create the global actions dialog.
mSilentModeToggle = new ToggleAction(
R.drawable.ic_lock_silent_mode,
R.drawable.ic_lock_silent_mode_off,
R.string.global_action_toggle_silent_mode,
R.string.global_action_silent_mode_on_status,
R.string.global_action_silent_mode_off_status) {
void onToggle(boolean on) {
mAudioManager.setRingerMode(on ? AudioManager.RINGER_MODE_SILENT
: AudioManager.RINGER_MODE_NORMAL);
}
public boolean showDuringKeyguard() {
return true;
}
public boolean showBeforeProvisioning() {
return false;
}
};
mItems = Lists.newArrayList(
// first: lock screen
new SinglePressAction(com.android.internal.R.drawable.ic_lock_lock, R.string.global_action_lock) {
public void onPress() {
mPowerManager.goToSleep(SystemClock.uptimeMillis() + 1);
}
public boolean showDuringKeyguard() {
return false;
}
public boolean showBeforeProvisioning() {
return false;
}
},
// next: silent mode
mSilentModeToggle,
// last: power off
new SinglePressAction(com.android.internal.R.drawable.ic_lock_power_off, R.string.global_action_power_off) {
public void onPress() {
// shutdown by making sure radio and power are handled accordingly.
ShutdownThread.shutdownAfterDisablingRadio(mContext, true);
}
public boolean showDuringKeyguard() {
return true;
}
public boolean showBeforeProvisioning() {
return true;
}
});
mAdapter = new MyAdapter();
final AlertDialog.Builder ab = new AlertDialog.Builder(mContext);
ab.setAdapter(mAdapter, this)
.setInverseBackgroundForced(true)
.setTitle(R.string.global_actions);
final AlertDialog dialog = ab.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
dialog.setOnDismissListener(this);
return dialog;
| public void | onClick(android.content.DialogInterface dialog, int which){@inheritDoc}
dialog.dismiss();
mAdapter.getItem(which).onPress();
| public void | onDismiss(android.content.DialogInterface dialog){@inheritDoc}
mStatusBar.disable(StatusBarManager.DISABLE_NONE);
| private void | prepareDialog()
// TODO: May need another 'Vibrate' toggle button, but for now treat them the same
final boolean silentModeOn =
mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
mSilentModeToggle.updateState(silentModeOn);
mAdapter.notifyDataSetChanged();
if (mKeyguardShowing) {
mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
} else {
mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
}
| public void | showDialog(boolean keyguardShowing, boolean isDeviceProvisioned)Show the global actions dialog (creating if necessary)
mKeyguardShowing = keyguardShowing;
mDeviceProvisioned = isDeviceProvisioned;
if (mDialog == null) {
mStatusBar = (StatusBarManager)mContext.getSystemService(Context.STATUS_BAR_SERVICE);
mDialog = createDialog();
}
prepareDialog();
mStatusBar.disable(StatusBarManager.DISABLE_EXPAND);
mDialog.show();
|
|