From 659dc01e5b6c79b9187cf1066627333e7cb1da34 Mon Sep 17 00:00:00 2001 From: George Mount Date: Wed, 3 Mar 2021 19:31:24 +0000 Subject: [PATCH] Compatibility feature USE_STRETCH_EDGE_EFFECT_BY_DEFAULT Bug: 171228096 Added two ChangeIds for stretch overscroll: USE_STRETCH_EDGE_EFFECT_BY_DEFAULT makes stretch overscroll the default. USE_STRETCH_EDGE_EFFECT_FOR_SUPPORTED makes stretch overscroll the default for applications that use the new EdgeEffect constructor that accepts an AttributeSet. This indicates knowledge of stretch overscroll APIs and can be a proxy for supporting stretch overscroll. Test: Both flags on apps that support and don't support new api Change-Id: If2ec832c9656116fe1aa64d33682c489abbde30f --- core/java/android/widget/EdgeEffect.java | 44 +++++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java index dc42ad5835431..beafcc8740f75 100644 --- a/core/java/android/widget/EdgeEffect.java +++ b/core/java/android/widget/EdgeEffect.java @@ -20,6 +20,9 @@ import android.annotation.ColorInt; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.compat.Compatibility; +import android.compat.annotation.ChangeId; +import android.compat.annotation.EnabledSince; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.res.TypedArray; @@ -58,6 +61,29 @@ import java.lang.annotation.RetentionPolicy; * {@link #draw(Canvas)} method.

*/ public class EdgeEffect { + /** + * This sets the default value for {@link #setType(int)} to {@link #TYPE_STRETCH} instead + * of {@link #TYPE_GLOW}. The type can still be overridden by the theme, view attribute, + * or by calling {@link #setType(int)}. + * + * @hide + */ + @ChangeId + @EnabledSince(targetSdkVersion = Build.VERSION_CODES.S) + public static final long USE_STRETCH_EDGE_EFFECT_BY_DEFAULT = 171228096L; + + /** + * This sets the default value for {@link #setType(int)} to {@link #TYPE_STRETCH} instead + * of {@link #TYPE_GLOW} for views that instantiate with + * {@link #EdgeEffect(Context, AttributeSet)}, indicating use of S+ EdgeEffect support. The + * type can still be overridden by the theme, view attribute, or by calling + * {@link #setType(int)}. + * + * @hide + */ + @ChangeId + @EnabledSince(targetSdkVersion = Build.VERSION_CODES.S) + public static final long USE_STRETCH_EDGE_EFFECT_FOR_SUPPORTED = 178807038L; /** * The default blend mode used by {@link EdgeEffect}. @@ -132,7 +158,7 @@ public class EdgeEffect { private float mStretchIntensity = DEFAULT_MAX_STRETCH_INTENSITY; private float mStretchDistance = -1f; - private final Interpolator mInterpolator; + private final Interpolator mInterpolator = new DecelerateInterpolator(); private static final int STATE_IDLE = 0; private static final int STATE_PULL = 1; @@ -166,7 +192,7 @@ public class EdgeEffect { * @param context Context used to provide theming and resource information for the EdgeEffect */ public EdgeEffect(Context context) { - this(context, null); + this(context, null, Compatibility.isChangeEnabled(USE_STRETCH_EDGE_EFFECT_BY_DEFAULT)); } /** @@ -175,18 +201,26 @@ public class EdgeEffect { * @param attrs The attributes of the XML tag that is inflating the view */ public EdgeEffect(@NonNull Context context, @Nullable AttributeSet attrs) { - mPaint.setAntiAlias(true); + this(context, attrs, + Compatibility.isChangeEnabled(USE_STRETCH_EDGE_EFFECT_BY_DEFAULT) + || Compatibility.isChangeEnabled(USE_STRETCH_EDGE_EFFECT_FOR_SUPPORTED)); + } + + private EdgeEffect(@NonNull Context context, @Nullable AttributeSet attrs, + boolean defaultStretch) { final TypedArray a = context.obtainStyledAttributes( attrs, com.android.internal.R.styleable.EdgeEffect); final int themeColor = a.getColor( com.android.internal.R.styleable.EdgeEffect_colorEdgeEffect, 0xff666666); mEdgeEffectType = a.getInt( - com.android.internal.R.styleable.EdgeEffect_edgeEffectType, TYPE_GLOW); + com.android.internal.R.styleable.EdgeEffect_edgeEffectType, + defaultStretch ? TYPE_STRETCH : TYPE_GLOW); a.recycle(); + + mPaint.setAntiAlias(true); mPaint.setColor((themeColor & 0xffffff) | 0x33000000); mPaint.setStyle(Paint.Style.FILL); mPaint.setBlendMode(DEFAULT_BLEND_MODE); - mInterpolator = new DecelerateInterpolator(); } /**