FileDocCategorySizeDatePackage
PowerDialog.javaAPI DocAndroid 1.5 API6046Wed May 06 22:42:06 BST 2009com.android.internal.policy.impl

PowerDialog

public class PowerDialog extends android.app.Dialog implements android.view.View.OnClickListener, android.view.View.OnKeyListener
deprecated
use {@link GlobalActions} instead.

Fields Summary
private static final String
TAG
private static android.app.StatusBarManager
sStatusBar
private android.widget.Button
mKeyguard
private android.widget.Button
mPower
private android.widget.Button
mRadioPower
private android.widget.Button
mSilent
private android.os.LocalPowerManager
mPowerManager
Constructors Summary
public PowerDialog(android.content.Context context, android.os.LocalPowerManager powerManager)


         
        super(context);
        mPowerManager = powerManager;
    
Methods Summary
public voiddismiss()

        super.dismiss();
        Log.d(TAG, "dismiss... reenabling expand");
        sStatusBar.disable(StatusBarManager.DISABLE_NONE);
    
public voidonClick(android.view.View v)

        this.dismiss();
        if (v == mPower) {
            // shutdown by making sure radio and power are handled accordingly.
            ShutdownThread.shutdownAfterDisablingRadio(getContext(), true);
        } else if (v == mRadioPower) {
            try {
                ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
                if (phone != null) {
                    phone.toggleRadioOnOff();
                }
            } catch (RemoteException ex) {
                // ignore it
            }
        } else if (v == mSilent) {
            // do something
        } else if (v == mKeyguard) {
            if (v.isInTouchMode()) {
                // only in touch mode for the reasons explained in onKey.
                this.dismiss();
                mPowerManager.goToSleep(SystemClock.uptimeMillis() + 1);
            }
        }
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);

        Context context = getContext();

        if (sStatusBar == null) {
            sStatusBar = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);
        }

        setContentView(com.android.internal.R.layout.power_dialog);

        getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
                WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

        setTitle(context.getText(R.string.power_dialog));

        mKeyguard = (Button) findViewById(R.id.keyguard);
        mPower = (Button) findViewById(R.id.off);
        mRadioPower = (Button) findViewById(R.id.radio_power);
        mSilent = (Button) findViewById(R.id.silent);

        if (mKeyguard != null) {
            mKeyguard.setOnKeyListener(this);
            mKeyguard.setOnClickListener(this);
        }
        if (mPower != null) {
            mPower.setOnClickListener(this);
        }
        if (mRadioPower != null) {
            mRadioPower.setOnClickListener(this);
        }
        if (mSilent != null) {
            mSilent.setOnClickListener(this);
            // XXX: HACK for now hide the silent until we get mute support
            mSilent.setVisibility(View.GONE);
        }

        CharSequence text;

        // set the keyguard button's text
        text = context.getText(R.string.screen_lock);
        mKeyguard.setText(text);
        mKeyguard.requestFocus();

        try {
            ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
            if (phone != null) {
                text = phone.isRadioOn() ? context
                        .getText(R.string.turn_off_radio) : context
                        .getText(R.string.turn_on_radio);
            }
        } catch (RemoteException ex) {
            // ignore it
        }

        mRadioPower.setText(text);
    
public booleanonKey(android.view.View v, int keyCode, android.view.KeyEvent event)

        // The activate keyguard button needs to put the device to sleep on the
        // key up event. If we try to put it to sleep on the click or down
        // action
        // the the up action will cause the device to wake back up.

        // Log.i(TAG, "keyCode: " + keyCode + " action: " + event.getAction());
        if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER
                || event.getAction() != KeyEvent.ACTION_UP) {
            // Log.i(TAG, "getting out of dodge...");
            return false;
        }

        // Log.i(TAG, "Clicked mKeyguard! dimissing dialog");
        this.dismiss();
        // Log.i(TAG, "onKey: turning off the screen...");
        // XXX: arve says this is a hack for now
        mPowerManager.goToSleep(event.getEventTime() + 1);
        return true;
    
public voidshow()

        super.show();
        Log.d(TAG, "show... disabling expand");
        sStatusBar.disable(StatusBarManager.DISABLE_EXPAND);