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

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

Merge "Add edge effect color APIs to AbsListView"

parents b9218244 b621847e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -54849,6 +54849,7 @@ package android.widget {
    method public void deferNotifyDataSetChanged();
    method public void fling(int);
    method public android.widget.AbsListView.LayoutParams generateLayoutParams(android.util.AttributeSet);
    method @ColorInt public int getBottomEdgeEffectColor();
    method @android.view.ViewDebug.ExportedProperty(category="drawing") @ColorInt public int getCacheColorHint();
    method public int getCheckedItemCount();
    method public long[] getCheckedItemIds();
@@ -54863,6 +54864,7 @@ package android.widget {
    method @android.view.ViewDebug.ExportedProperty public android.view.View getSelectedView();
    method public android.graphics.drawable.Drawable getSelector();
    method public CharSequence getTextFilter();
    method @ColorInt public int getTopEdgeEffectColor();
    method public int getTranscriptMode();
    method protected void handleDataChanged();
    method public boolean hasTextFilter();
@@ -54890,9 +54892,11 @@ package android.widget {
    method public void reclaimViews(java.util.List<android.view.View>);
    method public void scrollListBy(int);
    method public void setAdapter(android.widget.ListAdapter);
    method public void setBottomEdgeEffectColor(@ColorInt int);
    method public void setCacheColorHint(@ColorInt int);
    method public void setChoiceMode(int);
    method public void setDrawSelectorOnTop(boolean);
    method public void setEdgeEffectColor(@ColorInt int);
    method public void setFastScrollAlwaysVisible(boolean);
    method public void setFastScrollEnabled(boolean);
    method public void setFastScrollStyle(int);
@@ -54911,6 +54915,7 @@ package android.widget {
    method public void setSmoothScrollbarEnabled(boolean);
    method public void setStackFromBottom(boolean);
    method public void setTextFilterEnabled(boolean);
    method public void setTopEdgeEffectColor(@ColorInt int);
    method public void setTranscriptMode(int);
    method public void setVelocityScale(float);
    method public void smoothScrollBy(int, int);
+92 −25
Original line number Diff line number Diff line
@@ -708,15 +708,23 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te

    /**
     * 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.
     */
    @UnsupportedAppUsage
    private EdgeEffect mEdgeGlowTop;
    @NonNull
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123769408)
    private EdgeEffect mEdgeGlowTop = new EdgeEffect(mContext);

    /**
     * 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
    private EdgeEffect mEdgeGlowBottom;
    @NonNull
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768444)
    private EdgeEffect mEdgeGlowBottom = new EdgeEffect(mContext);

    /**
     * An estimate of how many pixels are between the top of the list and
@@ -923,21 +931,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        mDensityScale = getContext().getResources().getDisplayMetrics().density;
    }

    @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);
    }

    /**
     * {@inheritDoc}
     */
@@ -3772,7 +3765,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
    }

    private void invalidateTopGlow() {
        if (mEdgeGlowTop == null) {
        if (!shouldDisplayEdgeEffects()) {
            return;
        }
        final boolean clipToPadding = getClipToPadding();
@@ -3783,7 +3776,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
    }

    private void invalidateBottomGlow() {
        if (mEdgeGlowBottom == null) {
        if (!shouldDisplayEdgeEffects()) {
            return;
        }
        final boolean clipToPadding = getClipToPadding();
@@ -4208,7 +4201,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te

        setPressed(false);

        if (mEdgeGlowTop != null) {
        if (shouldDisplayEdgeEffects()) {
            mEdgeGlowTop.onRelease();
            mEdgeGlowBottom.onRelease();
        }
@@ -4233,6 +4226,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }
    }

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

    private void onTouchCancel() {
        switch (mTouchMode) {
        case TOUCH_MODE_OVERSCROLL:
@@ -4258,7 +4255,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            recycleVelocityTracker();
        }

        if (mEdgeGlowTop != null) {
        if (shouldDisplayEdgeEffects()) {
            mEdgeGlowTop.onRelease();
            mEdgeGlowBottom.onRelease();
        }
@@ -4379,7 +4376,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        if (mEdgeGlowTop != null) {
        if (shouldDisplayEdgeEffects()) {
            final int scrollY = mScrollY;
            final boolean clipToPadding = getClipToPadding();
            final int width;
@@ -6371,7 +6368,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
    }

    private void finishGlows() {
        if (mEdgeGlowTop != null) {
        if (shouldDisplayEdgeEffects()) {
            mEdgeGlowTop.finish();
            mEdgeGlowBottom.finish();
        }
@@ -6477,6 +6474,76 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }
    }

    /**
     * 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);
        invalidateBottomGlow();
    }

    /**
     * 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);
        invalidateTopGlow();
    }

    /**
     * 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();
    }

    /**
     * Sets the recycler listener to be notified whenever a View is set aside in
     * the recycler for later reuse. This listener can be used to free resources