Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9a08ff13 authored by Aaron Liu's avatar Aaron Liu
Browse files

[Bouncer] Refine bouncer title.

Add animation to bouncer title. Also remove setMessageIfEmpty. Remove
instances of hiding the message in many cases as these cases were mean
to prevent the textview from flashing when bouncer isn't being shown.

Test: Tested simpin, simpuk, pattern, password, and pin on device. Also
added unit tests
Fixes: 174020764

Change-Id: I2f8e6f3d1a0400ead7e658b7d003dbc7b608a1cf
parent 668aee06
Loading
Loading
Loading
Loading
+53 −1
Original line number Diff line number Diff line
@@ -16,19 +16,29 @@

package com.android.keyguard

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.TypedArray
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
import com.android.settingslib.Utils
import com.android.systemui.animation.Interpolators

/** Displays security messages for the keyguard bouncer. */
class BouncerKeyguardMessageArea(context: Context?, attrs: AttributeSet?) :
open class BouncerKeyguardMessageArea(context: Context?, attrs: AttributeSet?) :
    KeyguardMessageArea(context, attrs) {
    private val DEFAULT_COLOR = -1
    private var mDefaultColorState: ColorStateList? = null
    private var mNextMessageColorState: ColorStateList? = ColorStateList.valueOf(DEFAULT_COLOR)
    private val animatorSet = AnimatorSet()
    private var textAboutToShow: CharSequence? = null
    protected open val SHOW_DURATION_MILLIS = 150L
    protected open val HIDE_DURATION_MILLIS = 200L

    override fun updateTextColor() {
        var colorState = mDefaultColorState
@@ -58,4 +68,46 @@ class BouncerKeyguardMessageArea(context: Context?, attrs: AttributeSet?) :
        mDefaultColorState = Utils.getColorAttr(context, android.R.attr.textColorPrimary)
        super.reloadColor()
    }

    override fun setMessage(msg: CharSequence?) {
        if (msg == textAboutToShow || msg == text) {
            return
        }
        textAboutToShow = msg

        if (animatorSet.isRunning) {
            animatorSet.cancel()
            textAboutToShow = null
        }

        val hideAnimator =
            ObjectAnimator.ofFloat(this, View.ALPHA, 1f, 0f).apply {
                duration = HIDE_DURATION_MILLIS
                interpolator = Interpolators.STANDARD_ACCELERATE
            }

        hideAnimator.addListener(
            object : AnimatorListenerAdapter() {
                override fun onAnimationEnd(animation: Animator?) {
                    super@BouncerKeyguardMessageArea.setMessage(msg)
                }
            }
        )
        val showAnimator =
            ObjectAnimator.ofFloat(this, View.ALPHA, 0f, 1f).apply {
                duration = SHOW_DURATION_MILLIS
                interpolator = Interpolators.STANDARD_DECELERATE
            }

        showAnimator.addListener(
            object : AnimatorListenerAdapter() {
                override fun onAnimationEnd(animation: Animator?) {
                    textAboutToShow = null
                }
            }
        )

        animatorSet.playSequentially(hideAnimator, showAnimator)
        animatorSet.start()
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -152,6 +152,7 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
    }

    public void startAppearAnimation() {
        mMessageAreaController.setMessage(getInitialMessageResId());
        mView.startAppearAnimation();
    }

@@ -169,6 +170,11 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
        return view.indexOfChild(mView);
    }

    /** Determines the message to show in the bouncer when it first appears. */
    protected int getInitialMessageResId() {
        return 0;
    }

    /** Factory for a {@link KeyguardInputViewController}. */
    public static class Factory {
        private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
+0 −10
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.keyguard;

import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.text.TextUtils;

import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
@@ -100,15 +99,6 @@ public class KeyguardMessageAreaController<T extends KeyguardMessageArea>
        mView.setMessage(resId);
    }

    /**
     * Set Text if KeyguardMessageArea is empty.
     */
    public void setMessageIfEmpty(int resId) {
        if (TextUtils.isEmpty(mView.getText())) {
            setMessage(resId);
        }
    }

    public void setNextMessageColor(ColorStateList colorState) {
        mView.setNextMessageColor(colorState);
    }
+6 −2
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ public class KeyguardPasswordViewController
    @Override
    void resetState() {
        mPasswordEntry.setTextOperationUser(UserHandle.of(KeyguardUpdateMonitor.getCurrentUser()));
        mMessageAreaController.setMessage("");
        mMessageAreaController.setMessage(getInitialMessageResId());
        final boolean wasDisabled = mPasswordEntry.isEnabled();
        mView.setPasswordEntryEnabled(true);
        mView.setPasswordEntryInputEnabled(true);
@@ -207,7 +207,6 @@ public class KeyguardPasswordViewController
        if (reason != KeyguardSecurityView.SCREEN_ON || mShowImeAtScreenOn) {
            showInput();
        }
        mMessageAreaController.setMessageIfEmpty(R.string.keyguard_enter_your_password);
    }

    private void showInput() {
@@ -324,4 +323,9 @@ public class KeyguardPasswordViewController
                //enabled input method subtype (The current IME should be LatinIME.)
                || imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
    }

    @Override
    protected int getInitialMessageResId() {
        return R.string.keyguard_enter_your_password;
    }
}
+6 −7
Original line number Diff line number Diff line
@@ -297,12 +297,6 @@ public class KeyguardPatternViewController
        displayDefaultSecurityMessage();
    }

    @Override
    public void onResume(int reason) {
        super.onResume(reason);
        mMessageAreaController.setMessageIfEmpty(R.string.keyguard_enter_your_pattern);
    }

    @Override
    public boolean needsInput() {
        return false;
@@ -361,7 +355,7 @@ public class KeyguardPatternViewController
    }

    private void displayDefaultSecurityMessage() {
        mMessageAreaController.setMessage("");
        mMessageAreaController.setMessage(getInitialMessageResId());
    }

    private void handleAttemptLockout(long elapsedRealtimeDeadline) {
@@ -392,4 +386,9 @@ public class KeyguardPatternViewController

        }.start();
    }

    @Override
    protected int getInitialMessageResId() {
        return R.string.keyguard_enter_your_pattern;
    }
}
Loading