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

Commit 1954cf52 authored by John Reck's avatar John Reck
Browse files

Limit ripple alpha to 50%

Many themes appear to have forgotten to set
the alphas value on the color state list they
pass to RippleDrawable. The previous implementation
always divided the alpha by 2 which resulted in
the accidentally opaque color being 50% opacity instead.

To match that behavior without adding back the
unusual divide by 2 we simply cap the alpha to 128.

Similarly we surpress the hover & focus events if
a press is already in progress, which prevents a funky
background flicker on views with FOCUSABLE_AUTO that
gain focus part way through a click event.

Also fixes a bug where rapid tapping resulted in the
hardware animation appearing to not play as it had
a start value of 0 instead of paint.getAlpha()
Software animation already has this correct behavior,
so no changes needed for the fallback path.

Bug: 72173993
Test: tested hangouts, pin entry
Change-Id: I7110779234422e82cdd5d737aa00c1280b13760c
parent 2baa9ab4
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -63,15 +63,21 @@ class RippleBackground extends RippleComponent {
        }
    }

    public void setState(boolean focused, boolean hovered, boolean animateChanged) {
    public void setState(boolean focused, boolean hovered, boolean pressed) {
        if (!mFocused) {
            focused = focused && !pressed;
        }
        if (!mHovered) {
            hovered = hovered && !pressed;
        }
        if (mHovered != hovered || mFocused != focused) {
            mHovered = hovered;
            mFocused = focused;
            onStateChanged(animateChanged);
            onStateChanged();
        }
    }

    private void onStateChanged(boolean animateChanged) {
    private void onStateChanged() {
        float newOpacity = 0.0f;
        if (mHovered) newOpacity += .25f;
        if (mFocused) newOpacity += .75f;
@@ -79,14 +85,10 @@ class RippleBackground extends RippleComponent {
            mAnimator.cancel();
            mAnimator = null;
        }
        if (animateChanged) {
        mAnimator = ObjectAnimator.ofFloat(this, OPACITY, newOpacity);
        mAnimator.setDuration(OPACITY_DURATION);
        mAnimator.setInterpolator(LINEAR_INTERPOLATOR);
        mAnimator.start();
        } else {
            mOpacity = newOpacity;
        }
    }

    public void jumpToFinal() {
+7 −4
Original line number Diff line number Diff line
@@ -264,7 +264,7 @@ public class RippleDrawable extends LayerDrawable {
        }

        setRippleActive(enabled && pressed);
        setBackgroundActive(hovered, focused);
        setBackgroundActive(hovered, focused, pressed);

        return changed;
    }
@@ -280,13 +280,13 @@ public class RippleDrawable extends LayerDrawable {
        }
    }

    private void setBackgroundActive(boolean hovered, boolean focused) {
    private void setBackgroundActive(boolean hovered, boolean focused, boolean pressed) {
        if (mBackground == null && (hovered || focused)) {
            mBackground = new RippleBackground(this, mHotspotBounds, isBounded());
            mBackground.setup(mState.mMaxRadius, mDensity);
        }
        if (mBackground != null) {
            mBackground.setState(focused, hovered, true);
            mBackground.setState(focused, hovered, pressed);
        }
    }

@@ -878,7 +878,10 @@ public class RippleDrawable extends LayerDrawable {

        // Grab the color for the current state and cut the alpha channel in
        // half so that the ripple and background together yield full alpha.
        final int color = mState.mColor.getColorForState(getState(), Color.BLACK);
        int color = mState.mColor.getColorForState(getState(), Color.BLACK);
        if (Color.alpha(color) > 128) {
            color = (color & 0x00FFFFFF) | 0x80000000;
        }
        final Paint p = mRipplePaint;

        if (mMaskColorFilter != null) {
+1 −0
Original line number Diff line number Diff line
@@ -289,6 +289,7 @@ class RippleForeground extends RippleComponent {
        opacity.setInterpolator(LINEAR_INTERPOLATOR);
        opacity.addListener(mAnimationListener);
        opacity.setStartDelay(computeFadeOutDelay());
        opacity.setStartValue(mOwner.getRipplePaint().getAlpha());
        mPendingHwAnimators.add(opacity);
        invalidateSelf();
    }