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

Commit 6230fca3 authored by Shan Huang's avatar Shan Huang Committed by Android (Google) Code Review
Browse files

Merge "Add charging ripple to wireless charging animation." into sc-dev

parents 4dd008b5 e3b3abee
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -22,6 +22,11 @@
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.android.systemui.statusbar.charging.ChargingRippleView
        android:id="@+id/wireless_charging_ripple"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <!-- Circle animation -->
    <ImageView
        android:id="@+id/wireless_charging_view"
+3 −4
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.os.Message;
import android.util.Log;
import android.util.Slog;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

/**
@@ -98,8 +97,8 @@ public class WirelessChargingAnimation {
        private final Handler mHandler;

        private int mGravity;
        private View mView;
        private View mNextView;
        private WirelessChargingLayout mView;
        private WirelessChargingLayout mNextView;
        private WindowManager mWM;
        private Callback mCallback;

@@ -112,7 +111,7 @@ public class WirelessChargingAnimation {
            mGravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER;

            final WindowManager.LayoutParams params = mParams;
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
            params.height = WindowManager.LayoutParams.MATCH_PARENT;
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.format = PixelFormat.TRANSLUCENT;

+25 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.PointF;
import android.graphics.drawable.Animatable;
import android.util.AttributeSet;
import android.util.TypedValue;
@@ -29,8 +30,10 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.settingslib.Utils;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.statusbar.charging.ChargingRippleView;

import java.text.NumberFormat;

@@ -38,7 +41,9 @@ import java.text.NumberFormat;
 * @hide
 */
public class WirelessChargingLayout extends FrameLayout {
    public final static int UNKNOWN_BATTERY_LEVEL = -1;
    public static final int UNKNOWN_BATTERY_LEVEL = -1;
    private static final long RIPPLE_ANIMATION_DURATION = 2000;
    private ChargingRippleView mRippleView;

    public WirelessChargingLayout(Context context) {
        super(context);
@@ -120,6 +125,8 @@ public class WirelessChargingLayout extends FrameLayout {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(textSizeAnimator, textOpacityAnimator, textFadeAnimator);

        mRippleView = findViewById(R.id.wireless_charging_ripple);

        if (!showTransmittingBatteryLevel) {
            chargingAnimation.start();
            animatorSet.start();
@@ -195,4 +202,21 @@ public class WirelessChargingLayout extends FrameLayout {
        animatorSetTransmitting.start();
        animatorSetIcon.start();
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        if (mRippleView != null) {
            int width = getMeasuredWidth();
            int height = getMeasuredHeight();
            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);
            mRippleView.setDuration(RIPPLE_ANIMATION_DURATION);
            mRippleView.startRipple();
        }

        super.onLayout(changed, left, top, right, bottom);
    }
}
+9 −10
Original line number Diff line number Diff line
@@ -25,10 +25,8 @@ import android.graphics.Paint
import android.graphics.PointF
import android.util.AttributeSet
import android.view.View
import kotlin.math.max

private const val RIPPLE_ANIMATION_DURATION: Long = 1500
private const val RIPPLE_SPARKLE_STRENGTH: Float = 0.3f
private const val RIPPLE_SPARKLE_STRENGTH: Float = 0.4f

/**
 * Expanding ripple effect that shows when charging begins.
@@ -39,17 +37,18 @@ class ChargingRippleView(context: Context?, attrs: AttributeSet?) : View(context
    private val defaultColor: Int = 0xffffffff.toInt()
    private val ripplePaint = Paint()

    var radius: Float = 0.0f
        set(value) { rippleShader.radius = value }
    var origin: PointF = PointF()
        set(value) { rippleShader.origin = value }
    var duration: Long = 1500

    init {
        rippleShader.color = defaultColor
        rippleShader.progress = 0f
        rippleShader.sparkleStrength = RIPPLE_SPARKLE_STRENGTH
        ripplePaint.shader = rippleShader
    }

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        rippleShader.origin = PointF(measuredWidth / 2f, measuredHeight.toFloat())
        rippleShader.radius = max(measuredWidth, measuredHeight).toFloat()
        super.onLayout(changed, left, top, right, bottom)
        visibility = View.GONE
    }

    fun startRipple() {
@@ -57,7 +56,7 @@ class ChargingRippleView(context: Context?, attrs: AttributeSet?) : View(context
            return // Ignore if ripple effect is already playing
        }
        val animator = ValueAnimator.ofFloat(0f, 1f)
        animator.duration = RIPPLE_ANIMATION_DURATION
        animator.duration = duration
        animator.addUpdateListener { animator ->
            val now = animator.currentPlayTime
            val phase = now / 30000f
+2 −2
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ class RippleShader internal constructor() : RuntimeShader(SHADER, false) {
                  float s = 0.0;
                  for (float i = 0; i < 4; i += 1) {
                    float l = i * 0.25;
                    float h = l + 0.025;
                    float h = l + 0.005;
                    float o = abs(sin(0.1 * PI * (t + i)));
                    s += threshold(n + o, l, h);
                  }
@@ -97,7 +97,7 @@ class RippleShader internal constructor() : RuntimeShader(SHADER, false) {
                    float fadeRipple = min(fadeIn, 1.-fadeOutRipple);
                    float rippleAlpha = softRing(p, in_origin, radius, 0.5)
                        * fadeRipple * in_color.a;
                    vec4 ripple = in_color * max(circle, rippleAlpha) * 0.4;
                    vec4 ripple = in_color * max(circle, rippleAlpha) * 0.3;
                    return mix(ripple, vec4(sparkle), sparkle * in_sparkle_strength);
                }"""
        private const val SHADER = SHADER_UNIFORMS + SHADER_LIB + SHADER_MAIN
Loading