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

Commit 39620d2f authored by Yigit Boyar's avatar Yigit Boyar Committed by Android (Google) Code Review
Browse files

Merge "Add edge effect color APIs to ScrollViews"

parents caf294d0 08b1d993
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -55869,11 +55869,16 @@ package android.widget {
    method public boolean executeKeyEvent(android.view.KeyEvent);
    method public void fling(int);
    method public boolean fullScroll(int);
    method @ColorInt public int getLeftEdgeEffectColor();
    method public int getMaxScrollAmount();
    method @ColorInt public int getRightEdgeEffectColor();
    method public boolean isFillViewport();
    method public boolean isSmoothScrollingEnabled();
    method public boolean pageScroll(int);
    method public void setEdgeEffectColor(@ColorInt int);
    method public void setFillViewport(boolean);
    method public void setLeftEdgeEffectColor(@ColorInt int);
    method public void setRightEdgeEffectColor(@ColorInt int);
    method public void setSmoothScrollingEnabled(boolean);
    method public final void smoothScrollBy(int, int);
    method public final void smoothScrollTo(int, int);
@@ -56672,13 +56677,18 @@ package android.widget {
    method public boolean executeKeyEvent(android.view.KeyEvent);
    method public void fling(int);
    method public boolean fullScroll(int);
    method @ColorInt public int getBottomEdgeEffectColor();
    method public int getMaxScrollAmount();
    method @ColorInt public int getTopEdgeEffectColor();
    method public boolean isFillViewport();
    method public boolean isSmoothScrollingEnabled();
    method public boolean pageScroll(int);
    method public void scrollToDescendant(android.view.View);
    method public void setBottomEdgeEffectColor(@ColorInt int);
    method public void setEdgeEffectColor(@ColorInt int);
    method public void setFillViewport(boolean);
    method public void setSmoothScrollingEnabled(boolean);
    method public void setTopEdgeEffectColor(@ColorInt int);
    method public final void smoothScrollBy(int, int);
    method public final void smoothScrollTo(int, int);
  }
+93 −21
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.widget;

import android.annotation.ColorInt;
import android.annotation.NonNull;
import android.annotation.UnsupportedAppUsage;
import android.content.Context;
@@ -80,10 +81,24 @@ public class HorizontalScrollView extends FrameLayout {
    private final Rect mTempRect = new Rect();
    @UnsupportedAppUsage
    private OverScroller mScroller;
    @UnsupportedAppUsage
    private EdgeEffect mEdgeGlowLeft;
    @UnsupportedAppUsage
    private EdgeEffect mEdgeGlowRight;
    /**
     * Tracks the state of the left edge glow.
     *
     * Even though this field is practically final, we cannot make it final because there are apps
     * setting it via reflection and they need to keep working until they target Q.
     */
    @NonNull
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 124053130)
    private EdgeEffect mEdgeGlowLeft = new EdgeEffect(getContext());

    /**
     * Tracks the state of the bottom edge glow.
     *
     * Even though this field is practically final, we cannot make it final because there are apps
     * setting it via reflection and they need to keep working until they target Q.
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 124052619)
    private EdgeEffect mEdgeGlowRight = new EdgeEffect(getContext());

    /**
     * Position of the last motion event.
@@ -215,6 +230,74 @@ public class HorizontalScrollView extends FrameLayout {
        return 1.0f;
    }

    /**
     * Sets the edge effect color for both left and right edge effects.
     *
     * @param color The color for the edge effects.
     * @see #setLeftEdgeEffectColor(int)
     * @see #setRightEdgeEffectColor(int)
     * @see #getLeftEdgeEffectColor()
     * @see #getRightEdgeEffectColor()
     */
    public void setEdgeEffectColor(@ColorInt int color) {
        setLeftEdgeEffectColor(color);
        setRightEdgeEffectColor(color);
    }

    /**
     * Sets the right edge effect color.
     *
     * @param color The color for the right edge effect.
     * @see #setLeftEdgeEffectColor(int)
     * @see #setEdgeEffectColor(int)
     * @see #getLeftEdgeEffectColor()
     * @see #getRightEdgeEffectColor()
     */
    public void setRightEdgeEffectColor(@ColorInt int color) {
        mEdgeGlowRight.setColor(color);
    }

    /**
     * Sets the left edge effect color.
     *
     * @param color The color for the left edge effect.
     * @see #setRightEdgeEffectColor(int)
     * @see #setEdgeEffectColor(int)
     * @see #getLeftEdgeEffectColor()
     * @see #getRightEdgeEffectColor()
     */
    public void setLeftEdgeEffectColor(@ColorInt int color) {
        mEdgeGlowLeft.setColor(color);
    }

    /**
     * Returns the left edge effect color.
     *
     * @return The left edge effect color.
     * @see #setEdgeEffectColor(int)
     * @see #setLeftEdgeEffectColor(int)
     * @see #setRightEdgeEffectColor(int)
     * @see #getRightEdgeEffectColor()
     */
    @ColorInt
    public int getLeftEdgeEffectColor() {
        return mEdgeGlowLeft.getColor();
    }

    /**
     * Returns the right edge effect color.
     *
     * @return The right edge effect color.
     * @see #setEdgeEffectColor(int)
     * @see #setLeftEdgeEffectColor(int)
     * @see #setRightEdgeEffectColor(int)
     * @see #getLeftEdgeEffectColor()
     */
    @ColorInt
    public int getRightEdgeEffectColor() {
        return mEdgeGlowRight.getColor();
    }

    /**
     * @return The maximum amount this scroll view will scroll in response to
     *   an arrow event.
@@ -665,7 +748,7 @@ public class HorizontalScrollView extends FrameLayout {
                                mEdgeGlowLeft.onRelease();
                            }
                        }
                        if (mEdgeGlowLeft != null
                        if (shouldDisplayEdgeEffects()
                                && (!mEdgeGlowLeft.isFinished() || !mEdgeGlowRight.isFinished())) {
                            postInvalidateOnAnimation();
                        }
@@ -693,7 +776,7 @@ public class HorizontalScrollView extends FrameLayout {
                    mIsBeingDragged = false;
                    recycleVelocityTracker();

                    if (mEdgeGlowLeft != null) {
                    if (shouldDisplayEdgeEffects()) {
                        mEdgeGlowLeft.onRelease();
                        mEdgeGlowRight.onRelease();
                    }
@@ -708,7 +791,7 @@ public class HorizontalScrollView extends FrameLayout {
                    mIsBeingDragged = false;
                    recycleVelocityTracker();

                    if (mEdgeGlowLeft != null) {
                    if (shouldDisplayEdgeEffects()) {
                        mEdgeGlowLeft.onRelease();
                        mEdgeGlowRight.onRelease();
                    }
@@ -1650,26 +1733,15 @@ public class HorizontalScrollView extends FrameLayout {
        }
    }

    @Override
    public void setOverScrollMode(int mode) {
        if (mode != OVER_SCROLL_NEVER) {
            if (mEdgeGlowLeft == null) {
                Context context = getContext();
                mEdgeGlowLeft = new EdgeEffect(context);
                mEdgeGlowRight = new EdgeEffect(context);
            }
        } else {
            mEdgeGlowLeft = null;
            mEdgeGlowRight = null;
        }
        super.setOverScrollMode(mode);
    private boolean shouldDisplayEdgeEffects() {
        return getOverScrollMode() != OVER_SCROLL_NEVER;
    }

    @SuppressWarnings({"SuspiciousNameCombination"})
    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        if (mEdgeGlowLeft != null) {
        if (shouldDisplayEdgeEffects()) {
            final int scrollX = mScrollX;
            if (!mEdgeGlowLeft.isFinished()) {
                final int restoreCount = canvas.save();
+95 −22
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.widget;

import android.annotation.ColorInt;
import android.annotation.NonNull;
import android.annotation.UnsupportedAppUsage;
import android.content.Context;
@@ -89,10 +90,25 @@ public class ScrollView extends FrameLayout {
    private final Rect mTempRect = new Rect();
    @UnsupportedAppUsage
    private OverScroller mScroller;
    @UnsupportedAppUsage
    private EdgeEffect mEdgeGlowTop;
    @UnsupportedAppUsage
    private EdgeEffect mEdgeGlowBottom;
    /**
     * Tracks the state of the top edge glow.
     *
     * Even though this field is practically final, we cannot make it final because there are apps
     * setting it via reflection and they need to keep working until they target Q.
     */
    @NonNull
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768600)
    private EdgeEffect mEdgeGlowTop = new EdgeEffect(getContext());

    /**
     * Tracks the state of the bottom edge glow.
     *
     * Even though this field is practically final, we cannot make it final because there are apps
     * setting it via reflection and they need to keep working until they target Q.
     */
    @NonNull
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123769386)
    private EdgeEffect mEdgeGlowBottom = new EdgeEffect(getContext());

    /**
     * Position of the last motion event.
@@ -246,6 +262,74 @@ public class ScrollView extends FrameLayout {
        return 1.0f;
    }

    /**
     * Sets the edge effect color for both top and bottom edge effects.
     *
     * @param color The color for the edge effects.
     * @see #setTopEdgeEffectColor(int)
     * @see #setBottomEdgeEffectColor(int)
     * @see #getTopEdgeEffectColor()
     * @see #getBottomEdgeEffectColor()
     */
    public void setEdgeEffectColor(@ColorInt int color) {
        setTopEdgeEffectColor(color);
        setBottomEdgeEffectColor(color);
    }

    /**
     * Sets the bottom edge effect color.
     *
     * @param color The color for the bottom edge effect.
     * @see #setTopEdgeEffectColor(int)
     * @see #setEdgeEffectColor(int)
     * @see #getTopEdgeEffectColor()
     * @see #getBottomEdgeEffectColor()
     */
    public void setBottomEdgeEffectColor(@ColorInt int color) {
        mEdgeGlowBottom.setColor(color);
    }

    /**
     * Sets the top edge effect color.
     *
     * @param color The color for the top edge effect.
     * @see #setBottomEdgeEffectColor(int)
     * @see #setEdgeEffectColor(int)
     * @see #getTopEdgeEffectColor()
     * @see #getBottomEdgeEffectColor()
     */
    public void setTopEdgeEffectColor(@ColorInt int color) {
        mEdgeGlowTop.setColor(color);
    }

    /**
     * Returns the top edge effect color.
     *
     * @return The top edge effect color.
     * @see #setEdgeEffectColor(int)
     * @see #setTopEdgeEffectColor(int)
     * @see #setBottomEdgeEffectColor(int)
     * @see #getBottomEdgeEffectColor()
     */
    @ColorInt
    public int getTopEdgeEffectColor() {
        return mEdgeGlowTop.getColor();
    }

    /**
     * Returns the bottom edge effect color.
     *
     * @return The bottom edge effect color.
     * @see #setEdgeEffectColor(int)
     * @see #setTopEdgeEffectColor(int)
     * @see #setBottomEdgeEffectColor(int)
     * @see #getTopEdgeEffectColor()
     */
    @ColorInt
    public int getBottomEdgeEffectColor() {
        return mEdgeGlowBottom.getColor();
    }

    /**
     * @return The maximum amount this scroll view will scroll in response to
     *   an arrow event.
@@ -624,6 +708,10 @@ public class ScrollView extends FrameLayout {
        return mIsBeingDragged;
    }

    private boolean shouldDisplayEdgeEffects() {
        return getOverScrollMode() != OVER_SCROLL_NEVER;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        initVelocityTrackerIfNotExists();
@@ -732,7 +820,7 @@ public class ScrollView extends FrameLayout {
                                mEdgeGlowTop.onRelease();
                            }
                        }
                        if (mEdgeGlowTop != null
                        if (shouldDisplayEdgeEffects()
                                && (!mEdgeGlowTop.isFinished() || !mEdgeGlowBottom.isFinished())) {
                            postInvalidateOnAnimation();
                        }
@@ -1670,7 +1758,7 @@ public class ScrollView extends FrameLayout {

        recycleVelocityTracker();

        if (mEdgeGlowTop != null) {
        if (shouldDisplayEdgeEffects()) {
            mEdgeGlowTop.onRelease();
            mEdgeGlowBottom.onRelease();
        }
@@ -1699,21 +1787,6 @@ public class ScrollView extends FrameLayout {
        }
    }

    @Override
    public void setOverScrollMode(int mode) {
        if (mode != OVER_SCROLL_NEVER) {
            if (mEdgeGlowTop == null) {
                Context context = getContext();
                mEdgeGlowTop = new EdgeEffect(context);
                mEdgeGlowBottom = new EdgeEffect(context);
            }
        } else {
            mEdgeGlowTop = null;
            mEdgeGlowBottom = null;
        }
        super.setOverScrollMode(mode);
    }

    @Override
    public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) {
        return (nestedScrollAxes & SCROLL_AXIS_VERTICAL) != 0;
@@ -1758,7 +1831,7 @@ public class ScrollView extends FrameLayout {
    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        if (mEdgeGlowTop != null) {
        if (shouldDisplayEdgeEffects()) {
            final int scrollY = mScrollY;
            final boolean clipToPadding = getClipToPadding();
            if (!mEdgeGlowTop.isFinished()) {