FileDocCategorySizeDatePackage
KeyguardIndicationController.javaAPI DocAndroid 5.1 API6534Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar

KeyguardIndicationController

public class KeyguardIndicationController extends Object
Controls the little text indicator on the keyguard.

Fields Summary
private static final String
TAG
private static final int
MSG_HIDE_TRANSIENT
private final android.content.Context
mContext
private final com.android.systemui.statusbar.phone.KeyguardIndicationTextView
mTextView
private final com.android.internal.app.IBatteryStats
mBatteryInfo
private String
mRestingIndication
private String
mTransientIndication
private boolean
mVisible
private boolean
mPowerPluggedIn
private boolean
mPowerCharged
com.android.keyguard.KeyguardUpdateMonitorCallback
mUpdateMonitor
android.content.BroadcastReceiver
mReceiver
private final android.os.Handler
mHandler
Constructors Summary
public KeyguardIndicationController(android.content.Context context, com.android.systemui.statusbar.phone.KeyguardIndicationTextView textView)


         
        mContext = context;
        mTextView = textView;

        mBatteryInfo = IBatteryStats.Stub.asInterface(
                ServiceManager.getService(BatteryStats.SERVICE_NAME));
        KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateMonitor);
        context.registerReceiverAsUser(
                mReceiver, UserHandle.OWNER, new IntentFilter(Intent.ACTION_TIME_TICK), null, null);
    
Methods Summary
private java.lang.StringcomputeIndication()

        if (!TextUtils.isEmpty(mTransientIndication)) {
            return mTransientIndication;
        }
        if (mPowerPluggedIn) {
            return computePowerIndication();
        }
        return mRestingIndication;
    
private java.lang.StringcomputePowerIndication()

        if (mPowerCharged) {
            return mContext.getResources().getString(R.string.keyguard_charged);
        }

        // Try fetching charging time from battery stats.
        try {
            long chargingTimeRemaining = mBatteryInfo.computeChargeTimeRemaining();
            if (chargingTimeRemaining > 0) {
                String chargingTimeFormatted = Formatter.formatShortElapsedTimeRoundingUpToMinutes(
                        mContext, chargingTimeRemaining);
                return mContext.getResources().getString(
                        R.string.keyguard_indication_charging_time, chargingTimeFormatted);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling IBatteryStats: ", e);
        }

        // Fall back to simple charging label.
        return mContext.getResources().getString(R.string.keyguard_plugged_in);
    
public voidhideTransientIndication()
Hides transient indication.

        if (mTransientIndication != null) {
            mTransientIndication = null;
            mHandler.removeMessages(MSG_HIDE_TRANSIENT);
            updateIndication();
        }
    
public voidhideTransientIndicationDelayed(long delayMs)
Hides transient indication in {@param delayMs}.

        mHandler.sendMessageDelayed(
                mHandler.obtainMessage(MSG_HIDE_TRANSIENT), delayMs);
    
public voidsetRestingIndication(java.lang.String restingIndication)
Sets the indication that is shown if nothing else is showing.

        mRestingIndication = restingIndication;
        updateIndication();
    
public voidsetVisible(boolean visible)

        mVisible = visible;
        mTextView.setVisibility(visible ? View.VISIBLE : View.GONE);
        if (visible) {
            hideTransientIndication();
            updateIndication();
        }
    
public voidshowTransientIndication(int transientIndication)
Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}.

        showTransientIndication(mContext.getResources().getString(transientIndication));
    
public voidshowTransientIndication(java.lang.String transientIndication)
Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}.

        mTransientIndication = transientIndication;
        mHandler.removeMessages(MSG_HIDE_TRANSIENT);
        updateIndication();
    
private voidupdateIndication()

        if (mVisible) {
            mTextView.switchIndication(computeIndication());
        }