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

Commit 43b7eada authored by Antonio Kantek's avatar Antonio Kantek
Browse files

Setting NumPadAnimator only if background is RippleDrawable

NumPadKey's background is a StateListDrawable in Android Auto.

Bug: 189151122
Test: atest AndroidCarApiTest
Change-Id: Ib13c8a2d254e5841a59bf23fd6dc483e4d5b2d18
parent 248d942b
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -16,22 +16,36 @@
package com.android.keyguard;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.VectorDrawable;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.annotation.Nullable;

import com.android.settingslib.Utils;
import com.android.systemui.R;

/**
 * Similar to the {@link NumPadKey}, but displays an image.
 */
public class NumPadButton extends AlphaOptimizedImageButton {

    @Nullable
    private NumPadAnimator mAnimator;

    public NumPadButton(Context context, AttributeSet attrs) {
        super(context, attrs);

        Drawable background = getBackground();
        if (background instanceof RippleDrawable) {
            mAnimator = new NumPadAnimator(context, (RippleDrawable) getBackground(),
                    attrs.getStyleAttribute());
        } else {
            mAnimator = null;
        }
    }

    @Override
@@ -41,7 +55,7 @@ public class NumPadButton extends AlphaOptimizedImageButton {
        // Set width/height to the same value to ensure a smooth circle for the bg, but shrink
        // the height to match the old pin bouncer
        int width = getMeasuredWidth();
        int height = width;
        int height = mAnimator == null ? (int) (width * .75f) : width;

        setMeasuredDimension(getMeasuredWidth(), height);
    }
@@ -50,12 +64,12 @@ public class NumPadButton extends AlphaOptimizedImageButton {
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);

        mAnimator.onLayout(b - t);
        if (mAnimator != null) mAnimator.onLayout(b - t);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
        if (event.getActionMasked() == MotionEvent.ACTION_DOWN && mAnimator != null) {
            mAnimator.start();
        }
        return super.onTouchEvent(event);
@@ -65,6 +79,13 @@ public class NumPadButton extends AlphaOptimizedImageButton {
     * Reload colors from resources.
     **/
    public void reloadColors() {
        if (mAnimator != null) {
            mAnimator.reloadColors(getContext());
	} else {
            // Needed for old style pin
            int textColor = Utils.getColorAttr(getContext(), android.R.attr.textColorPrimary)
                    .getDefaultColor();
            ((VectorDrawable) getDrawable()).setTintList(ColorStateList.valueOf(textColor));
        }
    }
}
+15 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.keyguard;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.os.PowerManager;
import android.os.SystemClock;
@@ -30,6 +31,8 @@ import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.android.internal.widget.LockPatternUtils;
import com.android.settingslib.Utils;
import com.android.systemui.R;
@@ -47,6 +50,7 @@ public class NumPadKey extends ViewGroup {
    private int mTextViewResId;
    private PasswordTextView mTextView;

    @Nullable
    private NumPadAnimator mAnimator;

    private View.OnClickListener mListener = new View.OnClickListener() {
@@ -126,8 +130,13 @@ public class NumPadKey extends ViewGroup {

        setContentDescription(mDigitText.getText().toString());

        mAnimator = new NumPadAnimator(context, (RippleDrawable) getBackground(),
        Drawable background = getBackground();
        if (background instanceof RippleDrawable) {
            mAnimator = new NumPadAnimator(context, (RippleDrawable) background,
                    R.style.NumPadKey);
        } else {
            mAnimator = null;
        }
    }

    /**
@@ -141,14 +150,14 @@ public class NumPadKey extends ViewGroup {
        mDigitText.setTextColor(textColor);
        mKlondikeText.setTextColor(klondikeColor);

        mAnimator.reloadColors(getContext());
        if (mAnimator != null) mAnimator.reloadColors(getContext());
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
            doHapticKeyClick();
            mAnimator.start();
            if (mAnimator != null) mAnimator.start();
        }

        return super.onTouchEvent(event);
@@ -162,7 +171,7 @@ public class NumPadKey extends ViewGroup {
        // Set width/height to the same value to ensure a smooth circle for the bg, but shrink
        // the height to match the old pin bouncer
        int width = getMeasuredWidth();
        int height = width;
        int height = mAnimator == null ? (int) (width * .75f) : width;

        setMeasuredDimension(getMeasuredWidth(), height);
    }
@@ -183,7 +192,7 @@ public class NumPadKey extends ViewGroup {
        left = centerX - mKlondikeText.getMeasuredWidth() / 2;
        mKlondikeText.layout(left, top, left + mKlondikeText.getMeasuredWidth(), bottom);

        mAnimator.onLayout(b - t);
        if (mAnimator != null) mAnimator.onLayout(b - t);
    }

    @Override