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

Commit a37c26f5 authored by Yein Jo's avatar Yein Jo
Browse files

Make RippleShader support circle and rounded box shapes.

There will be a follow up CL for adding a oval shape.
This CL breaks the RippleShader into smaller pieces
and glue only the neccessary parts together when
initializing.

Note that this CL, the rounded box shape is not being
used.

Bug: b/237282686
Test: Manual, WiredChargingRippleControllerTest

Change-Id: I09091a612e3307a76a0bc938ce0810153541243a
parent 3fce0b03
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -75,12 +75,12 @@ class AuthRippleView(context: Context?, attrs: AttributeSet?) : View(context, at
        }
    private var radius: Float = 0f
        set(value) {
            rippleShader.radius = value
            rippleShader.setMaxSize(value * 2f, value * 2f)
            field = value
        }
    private var origin: PointF = PointF()
        set(value) {
            rippleShader.origin = value
            rippleShader.setCenter(value.x, value.y)
            field = value
        }

+12 −8
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.charging
import android.content.Context
import android.content.res.Configuration
import android.graphics.PixelFormat
import android.graphics.PointF
import android.os.SystemProperties
import android.util.DisplayMetrics
import android.view.View
@@ -85,7 +84,7 @@ class WiredChargingRippleController @Inject constructor(
    private var debounceLevel = 0

    @VisibleForTesting
    var rippleView: RippleView = RippleView(context, attrs = null)
    var rippleView: RippleView = RippleView(context, attrs = null).also { it.setupShader() }

    init {
        pluggedIn = batteryController.isPluggedIn
@@ -177,20 +176,25 @@ class WiredChargingRippleController @Inject constructor(
        context.display.getRealMetrics(displayMetrics)
        val width = displayMetrics.widthPixels
        val height = displayMetrics.heightPixels
        rippleView.radius = Integer.max(width, height).toFloat()
        rippleView.origin = when (RotationUtils.getExactRotation(context)) {
        val maxDiameter = Integer.max(width, height) * 2f
        rippleView.setMaxSize(maxDiameter, maxDiameter)
        when (RotationUtils.getExactRotation(context)) {
            RotationUtils.ROTATION_LANDSCAPE -> {
                PointF(width * normalizedPortPosY, height * (1 - normalizedPortPosX))
                rippleView.setCenter(
                        width * normalizedPortPosY, height * (1 - normalizedPortPosX))
            }
            RotationUtils.ROTATION_UPSIDE_DOWN -> {
                PointF(width * (1 - normalizedPortPosX), height * (1 - normalizedPortPosY))
                rippleView.setCenter(
                        width * (1 - normalizedPortPosX), height * (1 - normalizedPortPosY))
            }
            RotationUtils.ROTATION_SEASCAPE -> {
                PointF(width * (1 - normalizedPortPosY), height * normalizedPortPosX)
                rippleView.setCenter(
                        width * (1 - normalizedPortPosY), height * normalizedPortPosX)
            }
            else -> {
                // ROTATION_NONE
                PointF(width * normalizedPortPosX, height * normalizedPortPosY)
                rippleView.setCenter(
                        width * normalizedPortPosX, height * normalizedPortPosY)
            }
        }
    }
+8 −6
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PointF;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
@@ -34,6 +33,7 @@ import android.widget.TextView;
import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.ripple.RippleShader;
import com.android.systemui.ripple.RippleView;

import java.text.NumberFormat;
@@ -138,6 +138,8 @@ public class WirelessChargingLayout extends FrameLayout {
        animatorSetScrim.start();

        mRippleView = findViewById(R.id.wireless_charging_ripple);
        // TODO: Make rounded box shape if the device is tablet.
        mRippleView.setupShader(RippleShader.RippleShape.CIRCLE);
        OnAttachStateChangeListener listener = new OnAttachStateChangeListener() {
            @Override
            public void onViewAttachedToWindow(View view) {
@@ -230,11 +232,11 @@ public class WirelessChargingLayout extends FrameLayout {
        if (mRippleView != null) {
            int width = getMeasuredWidth();
            int height = getMeasuredHeight();
            mRippleView.setColor(
                    Utils.getColorAttr(mRippleView.getContext(),
            mRippleView.setCenter(width * 0.5f, height * 0.5f);
            float maxSize = Math.max(width, height);
            mRippleView.setMaxSize(maxSize, maxSize);
            mRippleView.setColor(Utils.getColorAttr(mRippleView.getContext(),
                    android.R.attr.colorAccent).getDefaultColor());
            mRippleView.setOrigin(new PointF(width / 2, height / 2));
            mRippleView.setRadius(Math.max(width, height) * 0.5f);
        }

        super.onLayout(changed, left, top, right, bottom);
+3 −4
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.media.taptotransfer.receiver
import android.annotation.SuppressLint
import android.app.StatusBarManager
import android.content.Context
import android.graphics.PointF
import android.graphics.drawable.Drawable
import android.graphics.drawable.Icon
import android.media.MediaRoute2Info
@@ -201,10 +200,10 @@ class MediaTttChipControllerReceiver @Inject constructor(
        val height = windowBounds.height()
        val width = windowBounds.width()

        rippleView.radius = height / 5f
        val maxDiameter = height / 2.5f
        rippleView.setMaxSize(maxDiameter, maxDiameter)
        // Center the ripple on the bottom of the screen in the middle.
        rippleView.origin = PointF(/* x= */ width / 2f, /* y= */ height.toFloat())

        rippleView.setCenter(width * 0.5f, height.toFloat())
        val color = Utils.getColorAttrDefaultColor(context, R.attr.wallpaperTextColorAccent)
        val colorWithAlpha = ColorUtils.setAlphaComponent(color, 70)
        rippleView.setColor(colorWithAlpha)
+2 −3
Original line number Diff line number Diff line
@@ -23,10 +23,9 @@ import com.android.systemui.ripple.RippleView
/**
 * An expanding ripple effect for the media tap-to-transfer receiver chip.
 */
class ReceiverChipRippleView(
        context: Context?, attrs: AttributeSet?
) : RippleView(context, attrs) {
class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleView(context, attrs) {
    init {
        setupShader()
        setRippleFill(true)
        duration = 3000L
    }
Loading