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

LockScreen

public class LockScreen extends android.widget.LinearLayout implements KeyguardUpdateMonitor.SimStateCallback, KeyguardScreen, KeyguardUpdateMonitor.ConfigurationChangeCallback, KeyguardUpdateMonitor.InfoCallback
The screen within {@link LockPatternKeyguardView} that shows general information about the device depending on its state, and how to get past it, as applicable.

Fields Summary
private final com.android.internal.widget.LockPatternUtils
mLockPatternUtils
private final KeyguardUpdateMonitor
mUpdateMonitor
private final KeyguardScreenCallback
mCallback
private android.widget.TextView
mHeaderSimOk1
private android.widget.TextView
mHeaderSimOk2
private android.widget.TextView
mHeaderSimBad1
private android.widget.TextView
mHeaderSimBad2
private android.widget.TextView
mTime
private android.widget.TextView
mDate
private android.view.ViewGroup
mBatteryInfoGroup
private android.widget.ImageView
mBatteryInfoIcon
private android.widget.TextView
mBatteryInfoText
private android.view.View
mBatteryInfoSpacer
private android.view.ViewGroup
mNextAlarmGroup
private android.widget.TextView
mAlarmText
private android.view.View
mAlarmSpacer
private android.view.ViewGroup
mScreenLockedMessageGroup
private android.widget.TextView
mLockInstructions
private android.widget.Button
mEmergencyCallButton
private boolean
mSimOk
false means sim is missing or PUK'd
private boolean
mShowingBatteryInfo
private boolean
mPluggedIn
private int
mBatteryLevel
private android.view.View[]
mOnlyVisibleWhenSimOk
private android.view.View[]
mOnlyVisibleWhenSimNotOk
Constructors Summary
LockScreen(android.content.Context context, com.android.internal.widget.LockPatternUtils lockPatternUtils, KeyguardUpdateMonitor updateMonitor, KeyguardScreenCallback callback)

param
context Used to setup the view.
param
lockPatternUtils Used to know the state of the lock pattern settings.
param
updateMonitor Used to register for updates on various keyguard related state, and query the initial state at setup.
param
callback Used to communicate back to the host keyguard view.


                                                             
       
             
              
        super(context);
        mLockPatternUtils = lockPatternUtils;
        mUpdateMonitor = updateMonitor;
        mCallback = callback;

        final LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.keyguard_screen_lock, this, true);

        mSimOk = isSimOk(updateMonitor.getSimState());
        mShowingBatteryInfo = updateMonitor.shouldShowBatteryInfo();
        mPluggedIn = updateMonitor.isDevicePluggedIn();
        mBatteryLevel = updateMonitor.getBatteryLevel();

        mHeaderSimOk1 = (TextView) findViewById(R.id.headerSimOk1);
        mHeaderSimOk2 = (TextView) findViewById(R.id.headerSimOk2);

        mHeaderSimBad1 = (TextView) findViewById(R.id.headerSimBad1);
        mHeaderSimBad2 = (TextView) findViewById(R.id.headerSimBad2);

        mTime = (TextView) findViewById(R.id.time);
        mDate = (TextView) findViewById(R.id.date);

        mBatteryInfoGroup = (ViewGroup) findViewById(R.id.batteryInfo);
        mBatteryInfoIcon = (ImageView) findViewById(R.id.batteryInfoIcon);
        mBatteryInfoText = (TextView) findViewById(R.id.batteryInfoText);
        mBatteryInfoSpacer = findViewById(R.id.batteryInfoSpacer);

        mNextAlarmGroup = (ViewGroup) findViewById(R.id.nextAlarmInfo);
        mAlarmText = (TextView) findViewById(R.id.nextAlarmText);
        mAlarmSpacer = findViewById(R.id.nextAlarmSpacer);

        mScreenLockedMessageGroup = (ViewGroup) findViewById(R.id.screenLockedInfo);

        mLockInstructions = (TextView) findViewById(R.id.lockInstructions);

        mEmergencyCallButton = (Button) findViewById(R.id.emergencyCallButton);

        mEmergencyCallButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                mCallback.takeEmergencyCallAction();
            }
        });

        mOnlyVisibleWhenSimOk = new View[] {
            mHeaderSimOk1,
            mHeaderSimOk2,
            mBatteryInfoGroup,
            mBatteryInfoSpacer,
            mNextAlarmGroup,
            mAlarmSpacer,
            mScreenLockedMessageGroup,
            mLockInstructions
        };

        mOnlyVisibleWhenSimNotOk = new View[] {
            mHeaderSimBad1,
            mHeaderSimBad2,
            mEmergencyCallButton
        };

        setFocusable(true);
        setFocusableInTouchMode(true);
        setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

        refreshBatteryDisplay();
        refreshAlarmDisplay();
        refreshTimeAndDateDisplay();
        refreshUnlockIntructions();
        refreshViewsWRTSimOk();
        refreshSimOkHeaders(mUpdateMonitor.getTelephonyPlmn(), mUpdateMonitor.getTelephonySpn());

        updateMonitor.registerInfoCallback(this);
        updateMonitor.registerSimStateCallback(this);
        updateMonitor.registerConfigurationChangeCallback(this);
    
Methods Summary
public voidcleanUp()
{@inheritDoc}

        mUpdateMonitor.removeCallback(this);
    
private booleanisSimOk(SimCard.State simState)

return
Whether the sim state is ok, meaning we don't need to show a special screen with the emergency call button and keep them from doing anything else.

        boolean missingAndNotProvisioned = (!mUpdateMonitor.isDeviceProvisioned()
                && simState == SimCard.State.ABSENT);
        return !(missingAndNotProvisioned || simState == SimCard.State.PUK_REQUIRED);
    
public booleanneedsInput()
{@inheritDoc}

        return false;
    
public booleanonKeyDown(int keyCode, android.view.KeyEvent event)

        if (keyCode == KeyEvent.KEYCODE_MENU) {
            mCallback.goToUnlockScreen();
        }
        return false;
    
public voidonKeyboardChange(boolean isKeyboardOpen)

        if (isKeyboardOpen) {
            mCallback.goToUnlockScreen();
        }
    
public voidonOrientationChange(boolean inPortrait)

    
public voidonPause()
{@inheritDoc}


    
public voidonRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn, int batteryLevel)

        mShowingBatteryInfo = showBatteryInfo;
        mPluggedIn = pluggedIn;
        mBatteryLevel = batteryLevel;

        refreshBatteryDisplay();
    
public voidonRefreshCarrierInfo(java.lang.CharSequence plmn, java.lang.CharSequence spn)

        refreshSimOkHeaders(plmn, spn);
    
public voidonResume()
{@inheritDoc}


    
public voidonSimStateChanged(SimCard.State simState)

        mSimOk = isSimOk(simState);
        refreshViewsWRTSimOk();
    
public voidonTimeChanged()

        refreshTimeAndDateDisplay();
    
private voidrefreshAlarmDisplay()

        String nextAlarmText = mLockPatternUtils.getNextAlarm();
        if (nextAlarmText != null && mSimOk) {
            setAlarmInfoVisible(true);
            mAlarmText.setText(nextAlarmText);
        } else {
            setAlarmInfoVisible(false);
        }
    
private voidrefreshBatteryDisplay()

        if (!mShowingBatteryInfo || !mSimOk) {
            mBatteryInfoGroup.setVisibility(View.GONE);
            mBatteryInfoSpacer.setVisibility(View.GONE);
            return;
        }
        mBatteryInfoGroup.setVisibility(View.VISIBLE);
        mBatteryInfoSpacer.setVisibility(View.VISIBLE);

        if (mPluggedIn) {
            mBatteryInfoIcon.setImageResource(R.drawable.ic_lock_idle_charging);
            mBatteryInfoText.setText(
                    getContext().getString(R.string.lockscreen_plugged_in, mBatteryLevel));
        } else {
            mBatteryInfoIcon.setImageResource(R.drawable.ic_lock_idle_low_battery);
            mBatteryInfoText.setText(R.string.lockscreen_low_battery);
        }
    
private voidrefreshSimBadInfo()

        final SimCard.State simState = mUpdateMonitor.getSimState();
        if (simState == SimCard.State.PUK_REQUIRED) {
            mHeaderSimBad1.setText(R.string.lockscreen_sim_puk_locked_message);
            mHeaderSimBad2.setText(R.string.lockscreen_sim_puk_locked_instructions);
        } else if (simState == SimCard.State.ABSENT) {
            mHeaderSimBad1.setText(R.string.lockscreen_missing_sim_message);
            mHeaderSimBad2.setVisibility(View.GONE);
            //mHeaderSimBad2.setText(R.string.lockscreen_missing_sim_instructions);
        } else {
            mHeaderSimBad1.setVisibility(View.GONE);
            mHeaderSimBad2.setVisibility(View.GONE);
        }
    
private voidrefreshSimOkHeaders(java.lang.CharSequence plmn, java.lang.CharSequence spn)

        final SimCard.State simState = mUpdateMonitor.getSimState();
        if (simState == SimCard.State.READY) {
            if (plmn != null) {
                mHeaderSimOk1.setVisibility(View.VISIBLE);
                mHeaderSimOk1.setText(plmn);
            } else {
                mHeaderSimOk1.setVisibility(View.GONE);
            }

            if (spn != null) {
                mHeaderSimOk2.setVisibility(View.VISIBLE);
                mHeaderSimOk2.setText(spn);
            } else {
                mHeaderSimOk2.setVisibility(View.GONE);
            }
        } else if (simState == SimCard.State.PIN_REQUIRED) {
            mHeaderSimOk1.setVisibility(View.VISIBLE);
            mHeaderSimOk1.setText(R.string.lockscreen_sim_locked_message);
            mHeaderSimOk2.setVisibility(View.GONE);
        } else if (simState == SimCard.State.ABSENT) {
            mHeaderSimOk1.setVisibility(View.VISIBLE);
            mHeaderSimOk1.setText(R.string.lockscreen_missing_sim_message_short);
            mHeaderSimOk2.setVisibility(View.GONE);
        } else if (simState == SimCard.State.NETWORK_LOCKED) {
            mHeaderSimOk1.setVisibility(View.VISIBLE);
            mHeaderSimOk1.setText(R.string.lockscreen_network_locked_message);
            mHeaderSimOk2.setVisibility(View.GONE);
        }
    
private voidrefreshTimeAndDateDisplay()

        Date now = new Date();
        mTime.setText(DateFormat.getTimeFormat(getContext()).format(now));
        mDate.setText(DateFormat.getDateFormat(getContext()).format(now));
    
private voidrefreshUnlockIntructions()

        if (mLockPatternUtils.isLockPatternEnabled()
                || mUpdateMonitor.getSimState() == SimCard.State.PIN_REQUIRED) {
            mLockInstructions.setText(R.string.lockscreen_instructions_when_pattern_enabled);
        } else {
            mLockInstructions.setText(R.string.lockscreen_instructions_when_pattern_disabled);
        }
    
private voidrefreshViewsWRTSimOk()

        if (mSimOk) {
            for (int i = 0; i < mOnlyVisibleWhenSimOk.length; i++) {
                final View view = mOnlyVisibleWhenSimOk[i];
                if (view == null) throw new RuntimeException("index " + i + " null");
                view.setVisibility(View.VISIBLE);
            }
            for (int i = 0; i < mOnlyVisibleWhenSimNotOk.length; i++) {
                final View view = mOnlyVisibleWhenSimNotOk[i];
                view.setVisibility(View.GONE);
            }
            refreshSimOkHeaders(mUpdateMonitor.getTelephonyPlmn(), mUpdateMonitor.getTelephonySpn());
            refreshAlarmDisplay();
            refreshBatteryDisplay();
        } else {
            for (int i = 0; i < mOnlyVisibleWhenSimOk.length; i++) {
                final View view = mOnlyVisibleWhenSimOk[i];
                view.setVisibility(View.GONE);
            }
            for (int i = 0; i < mOnlyVisibleWhenSimNotOk.length; i++) {
                final View view = mOnlyVisibleWhenSimNotOk[i];
                view.setVisibility(View.VISIBLE);
            }
            refreshSimBadInfo();
        }
    
private voidsetAlarmInfoVisible(boolean visible)

        final int visibilityFlag = visible ? View.VISIBLE : View.GONE;
        mNextAlarmGroup.setVisibility(visibilityFlag);
        mAlarmSpacer.setVisibility(visibilityFlag);