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

Commit 167dea12 authored by George Mount's avatar George Mount Committed by Android (Google) Code Review
Browse files

Merge "Compatibility feature USE_STRETCH_EDGE_EFFECT_BY_DEFAULT" into sc-dev

parents f4305279 659dc01e
Loading
Loading
Loading
Loading
+39 −5
Original line number Original line Diff line number Diff line
@@ -20,6 +20,9 @@ import android.annotation.ColorInt;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
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.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
@@ -58,6 +61,29 @@ import java.lang.annotation.RetentionPolicy;
 * {@link #draw(Canvas)} method.</p>
 * {@link #draw(Canvas)} method.</p>
 */
 */
public class EdgeEffect {
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}.
     * The default blend mode used by {@link EdgeEffect}.
@@ -132,7 +158,7 @@ public class EdgeEffect {
    private float mStretchIntensity = DEFAULT_MAX_STRETCH_INTENSITY;
    private float mStretchIntensity = DEFAULT_MAX_STRETCH_INTENSITY;
    private float mStretchDistance = -1f;
    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_IDLE = 0;
    private static final int STATE_PULL = 1;
    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
     * @param context Context used to provide theming and resource information for the EdgeEffect
     */
     */
    public EdgeEffect(Context context) {
    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
     * @param attrs The attributes of the XML tag that is inflating the view
     */
     */
    public EdgeEffect(@NonNull Context context, @Nullable AttributeSet attrs) {
    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(
        final TypedArray a = context.obtainStyledAttributes(
                attrs, com.android.internal.R.styleable.EdgeEffect);
                attrs, com.android.internal.R.styleable.EdgeEffect);
        final int themeColor = a.getColor(
        final int themeColor = a.getColor(
                com.android.internal.R.styleable.EdgeEffect_colorEdgeEffect, 0xff666666);
                com.android.internal.R.styleable.EdgeEffect_colorEdgeEffect, 0xff666666);
        mEdgeEffectType = a.getInt(
        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();
        a.recycle();

        mPaint.setAntiAlias(true);
        mPaint.setColor((themeColor & 0xffffff) | 0x33000000);
        mPaint.setColor((themeColor & 0xffffff) | 0x33000000);
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setBlendMode(DEFAULT_BLEND_MODE);
        mPaint.setBlendMode(DEFAULT_BLEND_MODE);
        mInterpolator = new DecelerateInterpolator();
    }
    }


    /**
    /**