FileDocCategorySizeDatePackage
KeyguardBottomAreaView.javaAPI DocAndroid 5.1 API21505Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar.phone

KeyguardBottomAreaView

public class KeyguardBottomAreaView extends android.widget.FrameLayout implements UnlockMethodCache.OnUnlockMethodChangedListener, View.OnClickListener, AccessibilityController.AccessibilityStateChangedCallback, View.OnLongClickListener
Implementation for the bottom area of the Keyguard, including camera/phone affordance and status text.

Fields Summary
static final String
TAG
private static final android.content.Intent
SECURE_CAMERA_INTENT
private static final android.content.Intent
INSECURE_CAMERA_INTENT
private static final android.content.Intent
PHONE_INTENT
private static final int
DOZE_ANIMATION_STAGGER_DELAY
private static final int
DOZE_ANIMATION_ELEMENT_DURATION
private com.android.systemui.statusbar.KeyguardAffordanceView
mCameraImageView
private com.android.systemui.statusbar.KeyguardAffordanceView
mPhoneImageView
private com.android.systemui.statusbar.KeyguardAffordanceView
mLockIcon
private android.widget.TextView
mIndicationText
private android.view.ViewGroup
mPreviewContainer
private android.view.View
mPhonePreview
private android.view.View
mCameraPreview
private ActivityStarter
mActivityStarter
private UnlockMethodCache
mUnlockMethodCache
private com.android.internal.widget.LockPatternUtils
mLockPatternUtils
private com.android.systemui.statusbar.policy.FlashlightController
mFlashlightController
private com.android.systemui.statusbar.policy.PreviewInflater
mPreviewInflater
private com.android.systemui.statusbar.KeyguardIndicationController
mIndicationController
private com.android.systemui.statusbar.policy.AccessibilityController
mAccessibilityController
private PhoneStatusBar
mPhoneStatusBar
private final TrustDrawable
mTrustDrawable
private final android.view.animation.Interpolator
mLinearOutSlowInInterpolator
private int
mLastUnlockIconRes
private AccessibilityDelegate
mAccessibilityDelegate
private final android.content.BroadcastReceiver
mDevicePolicyReceiver
private final com.android.keyguard.KeyguardUpdateMonitorCallback
mUpdateMonitorCallback
Constructors Summary
public KeyguardBottomAreaView(android.content.Context context)


       
        this(context, null);
    
public KeyguardBottomAreaView(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, 0);
    
public KeyguardBottomAreaView(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)

        this(context, attrs, defStyleAttr, 0);
    
public KeyguardBottomAreaView(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)

        super(context, attrs, defStyleAttr, defStyleRes);
        mTrustDrawable = new TrustDrawable(mContext);
        mLinearOutSlowInInterpolator =
                AnimationUtils.loadInterpolator(context, android.R.interpolator.linear_out_slow_in);
    
Methods Summary
private android.content.IntentgetCameraIntent()

        KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
        boolean currentUserHasTrust = updateMonitor.getUserHasTrust(
                mLockPatternUtils.getCurrentUser());
        return mLockPatternUtils.isSecure() && !currentUserHasTrust
                ? SECURE_CAMERA_INTENT : INSECURE_CAMERA_INTENT;
    
public android.view.ViewgetCameraPreview()

        return mCameraPreview;
    
public com.android.systemui.statusbar.KeyguardAffordanceViewgetCameraView()

        return mCameraImageView;
    
public android.view.ViewgetIndicationView()

        return mIndicationText;
    
public com.android.systemui.statusbar.KeyguardAffordanceViewgetLockIcon()

        return mLockIcon;
    
public android.view.ViewgetPhonePreview()

        return mPhonePreview;
    
public com.android.systemui.statusbar.KeyguardAffordanceViewgetPhoneView()

        return mPhoneImageView;
    
private voidhandleTrustCircleClick()

        EventLogTags.writeSysuiLockscreenGesture(
                EventLogConstants.SYSUI_LOCKSCREEN_GESTURE_TAP_LOCK, 0 /* lengthDp - N/A */,
                0 /* velocityDp - N/A */);
        mIndicationController.showTransientIndication(
                R.string.keyguard_indication_trust_disabled);
        mLockPatternUtils.requireCredentialEntry(mLockPatternUtils.getCurrentUser());
    
public booleanhasOverlappingRendering()

        return false;
    
private voidinflatePreviews()

        mPhonePreview = mPreviewInflater.inflatePreview(PHONE_INTENT);
        mCameraPreview = mPreviewInflater.inflatePreview(getCameraIntent());
        if (mPhonePreview != null) {
            mPreviewContainer.addView(mPhonePreview);
            mPhonePreview.setVisibility(View.INVISIBLE);
        }
        if (mCameraPreview != null) {
            mPreviewContainer.addView(mCameraPreview);
            mCameraPreview.setVisibility(View.INVISIBLE);
        }
    
private voidinitAccessibility()

        mLockIcon.setAccessibilityDelegate(mAccessibilityDelegate);
        mPhoneImageView.setAccessibilityDelegate(mAccessibilityDelegate);
        mCameraImageView.setAccessibilityDelegate(mAccessibilityDelegate);
    
private booleanisCameraDisabledByDpm()

        final DevicePolicyManager dpm =
                (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
        if (dpm != null) {
            try {
                final int userId = ActivityManagerNative.getDefault().getCurrentUser().id;
                final int disabledFlags = dpm.getKeyguardDisabledFeatures(null, userId);
                final  boolean disabledBecauseKeyguardSecure =
                        (disabledFlags & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0
                                && mPhoneStatusBar.isKeyguardSecure();
                return dpm.getCameraDisabled(null) || disabledBecauseKeyguardSecure;
            } catch (RemoteException e) {
                Log.e(TAG, "Can't get userId", e);
            }
        }
        return false;
    
private booleanisPhoneVisible()

        PackageManager pm = mContext.getPackageManager();
        return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
                && pm.resolveActivity(PHONE_INTENT, 0) != null;
    
public voidlaunchCamera()

        mFlashlightController.killFlashlight();
        Intent intent = getCameraIntent();
        boolean wouldLaunchResolverActivity = PreviewInflater.wouldLaunchResolverActivity(
                mContext, intent, mLockPatternUtils.getCurrentUser());
        if (intent == SECURE_CAMERA_INTENT && !wouldLaunchResolverActivity) {
            mContext.startActivityAsUser(intent, UserHandle.CURRENT);
        } else {

            // We need to delay starting the activity because ResolverActivity finishes itself if
            // launched behind lockscreen.
            mActivityStarter.startActivity(intent, false /* dismissShade */);
        }
    
public voidlaunchPhone()

        final TelecomManager tm = TelecomManager.from(mContext);
        if (tm.isInCall()) {
            AsyncTask.execute(new Runnable() {
                @Override
                public void run() {
                    tm.showInCallScreen(false /* showDialpad */);
                }
            });
        } else {
            mActivityStarter.startActivity(PHONE_INTENT, false /* dismissShade */);
        }
    
public voidonClick(android.view.View v)

        if (v == mCameraImageView) {
            launchCamera();
        } else if (v == mPhoneImageView) {
            launchPhone();
        } if (v == mLockIcon) {
            if (!mAccessibilityController.isAccessibilityEnabled()) {
                handleTrustCircleClick();
            } else {
                mPhoneStatusBar.animateCollapsePanels(
                        CommandQueue.FLAG_EXCLUDE_NONE, true /* force */);
            }
        }
    
protected voidonConfigurationChanged(android.content.res.Configuration newConfig)

        super.onConfigurationChanged(newConfig);
        int indicationBottomMargin = getResources().getDimensionPixelSize(
                R.dimen.keyguard_indication_margin_bottom);
        MarginLayoutParams mlp = (MarginLayoutParams) mIndicationText.getLayoutParams();
        if (mlp.bottomMargin != indicationBottomMargin) {
            mlp.bottomMargin = indicationBottomMargin;
            mIndicationText.setLayoutParams(mlp);
        }

        // Respect font size setting.
        mIndicationText.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimensionPixelSize(
                        com.android.internal.R.dimen.text_size_small_material));
    
protected voidonDetachedFromWindow()

        super.onDetachedFromWindow();
        mTrustDrawable.stop();
    
protected voidonFinishInflate()


    
       
        super.onFinishInflate();
        mLockPatternUtils = new LockPatternUtils(mContext);
        mPreviewContainer = (ViewGroup) findViewById(R.id.preview_container);
        mCameraImageView = (KeyguardAffordanceView) findViewById(R.id.camera_button);
        mPhoneImageView = (KeyguardAffordanceView) findViewById(R.id.phone_button);
        mLockIcon = (KeyguardAffordanceView) findViewById(R.id.lock_icon);
        mIndicationText = (TextView) findViewById(R.id.keyguard_indication_text);
        watchForCameraPolicyChanges();
        updateCameraVisibility();
        updatePhoneVisibility();
        mUnlockMethodCache = UnlockMethodCache.getInstance(getContext());
        mUnlockMethodCache.addListener(this);
        updateLockIcon();
        setClipChildren(false);
        setClipToPadding(false);
        mPreviewInflater = new PreviewInflater(mContext, new LockPatternUtils(mContext));
        inflatePreviews();
        mLockIcon.setOnClickListener(this);
        mLockIcon.setBackground(mTrustDrawable);
        mLockIcon.setOnLongClickListener(this);
        mCameraImageView.setOnClickListener(this);
        mPhoneImageView.setOnClickListener(this);
        initAccessibility();
    
public booleanonLongClick(android.view.View v)

        handleTrustCircleClick();
        return true;
    
public voidonStateChanged(boolean accessibilityEnabled, boolean touchExplorationEnabled)

        mCameraImageView.setClickable(touchExplorationEnabled);
        mPhoneImageView.setClickable(touchExplorationEnabled);
        mCameraImageView.setFocusable(accessibilityEnabled);
        mPhoneImageView.setFocusable(accessibilityEnabled);
        updateLockIconClickability();
    
public voidonUnlockMethodStateChanged()

        updateLockIcon();
        updateCameraVisibility();
    
protected voidonVisibilityChanged(android.view.View changedView, int visibility)

        super.onVisibilityChanged(changedView, visibility);
        if (isShown()) {
            mTrustDrawable.start();
        } else {
            mTrustDrawable.stop();
        }
        if (changedView == this && visibility == VISIBLE) {
            updateLockIcon();
            updateCameraVisibility();
        }
    
public voidsetAccessibilityController(com.android.systemui.statusbar.policy.AccessibilityController accessibilityController)

        mAccessibilityController = accessibilityController;
        accessibilityController.addStateChangedCallback(this);
    
public voidsetActivityStarter(ActivityStarter activityStarter)

        mActivityStarter = activityStarter;
    
public voidsetFlashlightController(com.android.systemui.statusbar.policy.FlashlightController flashlightController)

        mFlashlightController = flashlightController;
    
public voidsetKeyguardIndicationController(com.android.systemui.statusbar.KeyguardIndicationController keyguardIndicationController)


      
              
        mIndicationController = keyguardIndicationController;
    
public voidsetPhoneStatusBar(PhoneStatusBar phoneStatusBar)

        mPhoneStatusBar = phoneStatusBar;
    
public voidstartFinishDozeAnimation()

        long delay = 0;
        if (mPhoneImageView.getVisibility() == View.VISIBLE) {
            startFinishDozeAnimationElement(mPhoneImageView, delay);
            delay += DOZE_ANIMATION_STAGGER_DELAY;
        }
        startFinishDozeAnimationElement(mLockIcon, delay);
        delay += DOZE_ANIMATION_STAGGER_DELAY;
        if (mCameraImageView.getVisibility() == View.VISIBLE) {
            startFinishDozeAnimationElement(mCameraImageView, delay);
        }
        mIndicationText.setAlpha(0f);
        mIndicationText.animate()
                .alpha(1f)
                .setInterpolator(mLinearOutSlowInInterpolator)
                .setDuration(NotificationPanelView.DOZE_ANIMATION_DURATION);
    
private voidstartFinishDozeAnimationElement(android.view.View element, long delay)

        element.setAlpha(0f);
        element.setTranslationY(element.getHeight() / 2);
        element.animate()
                .alpha(1f)
                .translationY(0f)
                .setInterpolator(mLinearOutSlowInInterpolator)
                .setStartDelay(delay)
                .setDuration(DOZE_ANIMATION_ELEMENT_DURATION);
    
private voidupdateCameraVisibility()

        ResolveInfo resolved = mContext.getPackageManager().resolveActivityAsUser(getCameraIntent(),
                PackageManager.MATCH_DEFAULT_ONLY,
                mLockPatternUtils.getCurrentUser());
        boolean visible = !isCameraDisabledByDpm() && resolved != null
                && getResources().getBoolean(R.bool.config_keyguardShowCameraAffordance);
        mCameraImageView.setVisibility(visible ? View.VISIBLE : View.GONE);
    
private voidupdateLockIcon()

        boolean visible = isShown() && KeyguardUpdateMonitor.getInstance(mContext).isScreenOn();
        if (visible) {
            mTrustDrawable.start();
        } else {
            mTrustDrawable.stop();
        }
        if (!visible) {
            return;
        }
        // TODO: Real icon for facelock.
        int iconRes = mUnlockMethodCache.isFaceUnlockRunning()
                ? com.android.internal.R.drawable.ic_account_circle
                : mUnlockMethodCache.isCurrentlyInsecure() ? R.drawable.ic_lock_open_24dp
                : R.drawable.ic_lock_24dp;
        if (mLastUnlockIconRes != iconRes) {
            Drawable icon = mContext.getDrawable(iconRes);
            int iconHeight = getResources().getDimensionPixelSize(
                    R.dimen.keyguard_affordance_icon_height);
            int iconWidth = getResources().getDimensionPixelSize(
                    R.dimen.keyguard_affordance_icon_width);
            if (icon.getIntrinsicHeight() != iconHeight || icon.getIntrinsicWidth() != iconWidth) {
                icon = new IntrinsicSizeDrawable(icon, iconWidth, iconHeight);
            }
            mLockIcon.setImageDrawable(icon);
        }
        boolean trustManaged = mUnlockMethodCache.isTrustManaged();
        mTrustDrawable.setTrustManaged(trustManaged);
        updateLockIconClickability();
    
private voidupdateLockIconClickability()

        if (mAccessibilityController == null) {
            return;
        }
        boolean clickToUnlock = mAccessibilityController.isTouchExplorationEnabled();
        boolean clickToForceLock = mUnlockMethodCache.isTrustManaged()
                && !mAccessibilityController.isAccessibilityEnabled();
        boolean longClickToForceLock = mUnlockMethodCache.isTrustManaged()
                && !clickToForceLock;
        mLockIcon.setClickable(clickToForceLock || clickToUnlock);
        mLockIcon.setLongClickable(longClickToForceLock);
        mLockIcon.setFocusable(mAccessibilityController.isAccessibilityEnabled());
    
private voidupdatePhoneVisibility()

        boolean visible = isPhoneVisible();
        mPhoneImageView.setVisibility(visible ? View.VISIBLE : View.GONE);
    
private voidwatchForCameraPolicyChanges()

        final IntentFilter filter = new IntentFilter();
        filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
        getContext().registerReceiverAsUser(mDevicePolicyReceiver,
                UserHandle.ALL, filter, null, null);
        KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);