FileDocCategorySizeDatePackage
GlobalActions.javaAPI DocAndroid 1.5 API14664Wed May 06 22:42:04 BST 2009com.android.internal.policy.impl

GlobalActions

public class GlobalActions extends Object implements DialogInterface.OnDismissListener, DialogInterface.OnClickListener
Helper 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)

param
context everything needs a context :)
param
powerManager used to turn the screen off (the lock action).


                           
         
        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.AlertDialogcreateDialog()
Create the global actions dialog.

return
A new 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 voidonClick(android.content.DialogInterface dialog, int which)
{@inheritDoc}

        dialog.dismiss();
        mAdapter.getItem(which).onPress();
    
public voidonDismiss(android.content.DialogInterface dialog)
{@inheritDoc}

        mStatusBar.disable(StatusBarManager.DISABLE_NONE);
    
private voidprepareDialog()

        // 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 voidshowDialog(boolean keyguardShowing, boolean isDeviceProvisioned)
Show the global actions dialog (creating if necessary)

param
keyguardShowing True if keyguard is showing

        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();