Merge "Add a flag for rounded box charging ripple." into tm-qpr-dev

This commit is contained in:
Yein Jo
2022-08-09 19:22:17 +00:00
committed by Android (Google) Code Review
8 changed files with 46 additions and 35 deletions

View File

@@ -16,8 +16,6 @@
package com.android.systemui.charging; package com.android.systemui.charging;
import static com.android.systemui.charging.WirelessChargingLayout.UNKNOWN_BATTERY_LEVEL;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.content.Context; import android.content.Context;
@@ -32,13 +30,14 @@ import android.view.WindowManager;
import com.android.internal.logging.UiEvent; import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLogger;
import com.android.systemui.ripple.RippleShader.RippleShape;
/** /**
* A WirelessChargingAnimation is a view containing view + animation for wireless charging. * A WirelessChargingAnimation is a view containing view + animation for wireless charging.
* @hide * @hide
*/ */
public class WirelessChargingAnimation { public class WirelessChargingAnimation {
public static final int UNKNOWN_BATTERY_LEVEL = -1;
public static final long DURATION = 1500; public static final long DURATION = 1500;
private static final String TAG = "WirelessChargingView"; private static final String TAG = "WirelessChargingView";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -58,11 +57,12 @@ public class WirelessChargingAnimation {
* before calling {@link #show} - can be done through {@link #makeWirelessChargingAnimation}. * before calling {@link #show} - can be done through {@link #makeWirelessChargingAnimation}.
* @hide * @hide
*/ */
public WirelessChargingAnimation(@NonNull Context context, @Nullable Looper looper, private WirelessChargingAnimation(@NonNull Context context, @Nullable Looper looper,
int transmittingBatteryLevel, int batteryLevel, Callback callback, boolean isDozing, int transmittingBatteryLevel, int batteryLevel, Callback callback, boolean isDozing,
UiEventLogger uiEventLogger) { RippleShape rippleShape, UiEventLogger uiEventLogger) {
mCurrentWirelessChargingView = new WirelessChargingView(context, looper, mCurrentWirelessChargingView = new WirelessChargingView(context, looper,
transmittingBatteryLevel, batteryLevel, callback, isDozing, uiEventLogger); transmittingBatteryLevel, batteryLevel, callback, isDozing,
rippleShape, uiEventLogger);
} }
/** /**
@@ -72,9 +72,10 @@ public class WirelessChargingAnimation {
*/ */
public static WirelessChargingAnimation makeWirelessChargingAnimation(@NonNull Context context, public static WirelessChargingAnimation makeWirelessChargingAnimation(@NonNull Context context,
@Nullable Looper looper, int transmittingBatteryLevel, int batteryLevel, @Nullable Looper looper, int transmittingBatteryLevel, int batteryLevel,
Callback callback, boolean isDozing, UiEventLogger uiEventLogger) { Callback callback, boolean isDozing, RippleShape rippleShape,
UiEventLogger uiEventLogger) {
return new WirelessChargingAnimation(context, looper, transmittingBatteryLevel, return new WirelessChargingAnimation(context, looper, transmittingBatteryLevel,
batteryLevel, callback, isDozing, uiEventLogger); batteryLevel, callback, isDozing, rippleShape, uiEventLogger);
} }
/** /**
@@ -82,9 +83,10 @@ public class WirelessChargingAnimation {
* battery level without charging number shown. * battery level without charging number shown.
*/ */
public static WirelessChargingAnimation makeChargingAnimationWithNoBatteryLevel( public static WirelessChargingAnimation makeChargingAnimationWithNoBatteryLevel(
@NonNull Context context, UiEventLogger uiEventLogger) { @NonNull Context context, RippleShape rippleShape, UiEventLogger uiEventLogger) {
return makeWirelessChargingAnimation(context, null, return makeWirelessChargingAnimation(context, null,
UNKNOWN_BATTERY_LEVEL, UNKNOWN_BATTERY_LEVEL, null, false, uiEventLogger); UNKNOWN_BATTERY_LEVEL, UNKNOWN_BATTERY_LEVEL, null, false,
rippleShape, uiEventLogger);
} }
/** /**
@@ -121,10 +123,10 @@ public class WirelessChargingAnimation {
public WirelessChargingView(Context context, @Nullable Looper looper, public WirelessChargingView(Context context, @Nullable Looper looper,
int transmittingBatteryLevel, int batteryLevel, Callback callback, int transmittingBatteryLevel, int batteryLevel, Callback callback,
boolean isDozing, UiEventLogger uiEventLogger) { boolean isDozing, RippleShape rippleShape, UiEventLogger uiEventLogger) {
mCallback = callback; mCallback = callback;
mNextView = new WirelessChargingLayout(context, transmittingBatteryLevel, batteryLevel, mNextView = new WirelessChargingLayout(context, transmittingBatteryLevel, batteryLevel,
isDozing); isDozing, rippleShape);
mGravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER; mGravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER;
mUiEventLogger = uiEventLogger; mUiEventLogger = uiEventLogger;

View File

@@ -33,7 +33,7 @@ import android.widget.TextView;
import com.android.settingslib.Utils; import com.android.settingslib.Utils;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.animation.Interpolators; import com.android.systemui.animation.Interpolators;
import com.android.systemui.ripple.RippleShader; import com.android.systemui.ripple.RippleShader.RippleShape;
import com.android.systemui.ripple.RippleView; import com.android.systemui.ripple.RippleView;
import java.text.NumberFormat; import java.text.NumberFormat;
@@ -41,37 +41,36 @@ import java.text.NumberFormat;
/** /**
* @hide * @hide
*/ */
public class WirelessChargingLayout extends FrameLayout { final class WirelessChargingLayout extends FrameLayout {
public static final int UNKNOWN_BATTERY_LEVEL = -1;
private static final long RIPPLE_ANIMATION_DURATION = 1500; private static final long RIPPLE_ANIMATION_DURATION = 1500;
private static final int SCRIM_COLOR = 0x4C000000; private static final int SCRIM_COLOR = 0x4C000000;
private static final int SCRIM_FADE_DURATION = 300; private static final int SCRIM_FADE_DURATION = 300;
private RippleView mRippleView; private RippleView mRippleView;
public WirelessChargingLayout(Context context) { WirelessChargingLayout(Context context, int transmittingBatteryLevel, int batteryLevel,
boolean isDozing, RippleShape rippleShape) {
super(context); super(context);
init(context, null, false); init(context, null, transmittingBatteryLevel, batteryLevel, isDozing, rippleShape);
} }
public WirelessChargingLayout(Context context, int transmittingBatteryLevel, int batteryLevel, private WirelessChargingLayout(Context context) {
boolean isDozing) {
super(context); super(context);
init(context, null, transmittingBatteryLevel, batteryLevel, isDozing); init(context, null, /* isDozing= */ false, RippleShape.CIRCLE);
} }
public WirelessChargingLayout(Context context, AttributeSet attrs) { private WirelessChargingLayout(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
init(context, attrs, false); init(context, attrs, /* isDozing= */false, RippleShape.CIRCLE);
} }
private void init(Context c, AttributeSet attrs, boolean isDozing) { private void init(Context c, AttributeSet attrs, boolean isDozing, RippleShape rippleShape) {
init(c, attrs, -1, -1, false); init(c, attrs, -1, -1, isDozing, rippleShape);
} }
private void init(Context context, AttributeSet attrs, int transmittingBatteryLevel, private void init(Context context, AttributeSet attrs, int transmittingBatteryLevel,
int batteryLevel, boolean isDozing) { int batteryLevel, boolean isDozing, RippleShape rippleShape) {
final boolean showTransmittingBatteryLevel = final boolean showTransmittingBatteryLevel =
(transmittingBatteryLevel != UNKNOWN_BATTERY_LEVEL); (transmittingBatteryLevel != WirelessChargingAnimation.UNKNOWN_BATTERY_LEVEL);
// set style based on background // set style based on background
int style = R.style.ChargingAnim_WallpaperBackground; int style = R.style.ChargingAnim_WallpaperBackground;
@@ -84,7 +83,7 @@ public class WirelessChargingLayout extends FrameLayout {
// amount of battery: // amount of battery:
final TextView percentage = findViewById(R.id.wireless_charging_percentage); final TextView percentage = findViewById(R.id.wireless_charging_percentage);
if (batteryLevel != UNKNOWN_BATTERY_LEVEL) { if (batteryLevel != WirelessChargingAnimation.UNKNOWN_BATTERY_LEVEL) {
percentage.setText(NumberFormat.getPercentInstance().format(batteryLevel / 100f)); percentage.setText(NumberFormat.getPercentInstance().format(batteryLevel / 100f));
percentage.setAlpha(0); percentage.setAlpha(0);
} }
@@ -138,8 +137,7 @@ public class WirelessChargingLayout extends FrameLayout {
animatorSetScrim.start(); animatorSetScrim.start();
mRippleView = findViewById(R.id.wireless_charging_ripple); mRippleView = findViewById(R.id.wireless_charging_ripple);
// TODO: Make rounded box shape if the device is tablet. mRippleView.setupShader(rippleShape);
mRippleView.setupShader(RippleShader.RippleShape.CIRCLE);
OnAttachStateChangeListener listener = new OnAttachStateChangeListener() { OnAttachStateChangeListener listener = new OnAttachStateChangeListener() {
@Override @Override
public void onViewAttachedToWindow(View view) { public void onViewAttachedToWindow(View view) {
@@ -233,8 +231,12 @@ public class WirelessChargingLayout extends FrameLayout {
int width = getMeasuredWidth(); int width = getMeasuredWidth();
int height = getMeasuredHeight(); int height = getMeasuredHeight();
mRippleView.setCenter(width * 0.5f, height * 0.5f); mRippleView.setCenter(width * 0.5f, height * 0.5f);
if (mRippleView.getRippleShape() == RippleShape.ROUNDED_BOX) {
mRippleView.setMaxSize(width * 1.5f, height * 1.5f);
} else {
float maxSize = Math.max(width, height); float maxSize = Math.max(width, height);
mRippleView.setMaxSize(maxSize, maxSize); mRippleView.setMaxSize(maxSize, maxSize);
}
mRippleView.setColor(Utils.getColorAttr(mRippleView.getContext(), mRippleView.setColor(Utils.getColorAttr(mRippleView.getContext(),
android.R.attr.colorAccent).getDefaultColor()); android.R.attr.colorAccent).getDefaultColor());
} }

View File

@@ -185,6 +185,7 @@ public class Flags {
new ReleasedFlag(1000); new ReleasedFlag(1000);
public static final ReleasedFlag DOCK_SETUP_ENABLED = new ReleasedFlag(1001); public static final ReleasedFlag DOCK_SETUP_ENABLED = new ReleasedFlag(1001);
public static final UnreleasedFlag ROUNDED_BOX_RIPPLE = new UnreleasedFlag(1002, false);
// 1100 - windowing // 1100 - windowing
@Keep @Keep

View File

@@ -39,7 +39,7 @@ class RippleShader internal constructor(rippleShape: RippleShape = RippleShape.C
ROUNDED_BOX, ROUNDED_BOX,
ELLIPSE ELLIPSE
} }
//language=AGSL
companion object { companion object {
private const val SHADER_UNIFORMS = """uniform vec2 in_center; private const val SHADER_UNIFORMS = """uniform vec2 in_center;
uniform vec2 in_size; uniform vec2 in_size;

View File

@@ -17,6 +17,7 @@ package com.android.systemui.ripple
/** A common utility functions that are used for computing [RippleShader]. */ /** A common utility functions that are used for computing [RippleShader]. */
class RippleShaderUtilLibrary { class RippleShaderUtilLibrary {
//language=AGSL
companion object { companion object {
const val SHADER_LIB = """ const val SHADER_LIB = """
float triangleNoise(vec2 n) { float triangleNoise(vec2 n) {

View File

@@ -39,7 +39,9 @@ private const val RIPPLE_DEFAULT_COLOR: Int = 0xffffffff.toInt()
open class RippleView(context: Context?, attrs: AttributeSet?) : View(context, attrs) { open class RippleView(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
private lateinit var rippleShader: RippleShader private lateinit var rippleShader: RippleShader
private lateinit var rippleShape: RippleShape lateinit var rippleShape: RippleShape
private set
private val ripplePaint = Paint() private val ripplePaint = Paint()
var rippleInProgress: Boolean = false var rippleInProgress: Boolean = false

View File

@@ -17,6 +17,7 @@ package com.android.systemui.ripple
/** Library class that contains 2D signed distance functions. */ /** Library class that contains 2D signed distance functions. */
class SdfShaderLibrary { class SdfShaderLibrary {
//language=AGSL
companion object { companion object {
const val CIRCLE_SDF = """ const val CIRCLE_SDF = """
float sdCircle(vec2 p, float r) { float sdCircle(vec2 p, float r) {

View File

@@ -31,7 +31,7 @@ import static androidx.core.view.ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_
import static androidx.lifecycle.Lifecycle.State.RESUMED; import static androidx.lifecycle.Lifecycle.State.RESUMED;
import static com.android.systemui.Dependency.TIME_TICK_HANDLER_NAME; import static com.android.systemui.Dependency.TIME_TICK_HANDLER_NAME;
import static com.android.systemui.charging.WirelessChargingLayout.UNKNOWN_BATTERY_LEVEL; import static com.android.systemui.charging.WirelessChargingAnimation.UNKNOWN_BATTERY_LEVEL;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP; import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP;
import static com.android.systemui.statusbar.NotificationLockscreenUserManager.PERMISSION_SELF; import static com.android.systemui.statusbar.NotificationLockscreenUserManager.PERMISSION_SELF;
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT; import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT;
@@ -172,6 +172,7 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.qs.QSFragment; import com.android.systemui.qs.QSFragment;
import com.android.systemui.qs.QSPanelController; import com.android.systemui.qs.QSPanelController;
import com.android.systemui.recents.ScreenPinningRequest; import com.android.systemui.recents.ScreenPinningRequest;
import com.android.systemui.ripple.RippleShader.RippleShape;
import com.android.systemui.scrim.ScrimView; import com.android.systemui.scrim.ScrimView;
import com.android.systemui.settings.brightness.BrightnessSliderController; import com.android.systemui.settings.brightness.BrightnessSliderController;
import com.android.systemui.shade.NotificationPanelViewController; import com.android.systemui.shade.NotificationPanelViewController;
@@ -2211,7 +2212,8 @@ public class CentralSurfacesImpl extends CoreStartable implements
public void onAnimationEnded() { public void onAnimationEnded() {
mNotificationShadeWindowController.setRequestTopUi(false, TAG); mNotificationShadeWindowController.setRequestTopUi(false, TAG);
} }
}, false, sUiEventLogger).show(animationDelay); }, /* isDozing= */ false, RippleShape.CIRCLE,
sUiEventLogger).show(animationDelay);
} }
@Override @Override