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

Commit be11c364 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Fix padding adjustment for scrollbars in View, FastScroller" into klp-dev

parents 9b59e5aa 26bb253b
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -12062,7 +12062,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    }
    /**
     * Resolve padding depending on layout direction.
     * Resolves padding depending on layout direction, if applicable, and
     * recomputes internal padding values to adjust for scroll bars.
     *
     * @hide
     */
@@ -12102,11 +12103,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom;
            internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight,
                    mUserPaddingBottom);
            onRtlPropertiesChanged(resolvedLayoutDirection);
        }
        internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom);
        mPrivateFlags2 |= PFLAG2_PADDING_RESOLVED;
    }
+15 −2
Original line number Diff line number Diff line
@@ -1243,6 +1243,12 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            mFastScroller = new FastScroller(this);
            mFastScroller.setEnabled(true);
        }

        recomputePadding();

        if (mFastScroller != null) {
            mFastScroller.updateLayout();
        }
    }

    /**
@@ -1303,7 +1309,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te

    @Override
    public int getVerticalScrollbarWidth() {
        if (isFastScrollAlwaysVisible() && mFastScroller != null) {
        if (mFastScroller != null && mFastScroller.isEnabled()) {
            return Math.max(super.getVerticalScrollbarWidth(), mFastScroller.getWidth());
        }
        return super.getVerticalScrollbarWidth();
@@ -1327,6 +1333,14 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }
    }

    @Override
    public void setScrollBarStyle(int style) {
        super.setScrollBarStyle(style);
        if (mFastScroller != null) {
            mFastScroller.setScrollBarStyle(style);
        }
    }

    /**
     * If fast scroll is enabled, then don't draw the vertical scrollbar.
     * @hide
@@ -2787,7 +2801,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
    @Override
    public void onRtlPropertiesChanged(int layoutDirection) {
        super.onRtlPropertiesChanged(layoutDirection);

        if (mFastScroller != null) {
           mFastScroller.setScrollbarPosition(getVerticalScrollbarPosition());
        }
+74 −27
Original line number Diff line number Diff line
@@ -131,6 +131,9 @@ class FastScroller {
    /** Whether there is a track image to display. */
    private final boolean mHasTrackImage;

    /** Total width of decorations. */
    private final int mWidth;

    /** Set containing decoration transition animations. */
    private AnimatorSet mDecorAnimation;

@@ -155,6 +158,9 @@ class FastScroller {
    /** The index of the current section. */
    private int mCurrentSection = -1;

    /** The current scrollbar position. */
    private int mScrollbarPosition = -1;

    /** Whether the list is long enough to need a fast scroller. */
    private boolean mLongList;

@@ -194,6 +200,9 @@ class FastScroller {
     */
    private int mOverlayPosition;

    /** Current scrollbar style, including inset and overlay properties. */
    private int mScrollBarStyle;

    /** Whether to precisely match the thumb position to the list. */
    private boolean mMatchDragPosition;

@@ -245,34 +254,44 @@ class FastScroller {
        final Resources res = context.getResources();
        final TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS);

        mTrackImage = new ImageView(context);
        final ImageView trackImage = new ImageView(context);
        mTrackImage = trackImage;

        int width = 0;

        // Add track to overlay if it has an image.
        final int trackResId = ta.getResourceId(TRACK_DRAWABLE, 0);
        if (trackResId != 0) {
        final Drawable trackDrawable = ta.getDrawable(TRACK_DRAWABLE);
        if (trackDrawable != null) {
            mHasTrackImage = true;
            mTrackImage.setBackgroundResource(trackResId);
            mOverlay.add(mTrackImage);
            trackImage.setBackground(trackDrawable);
            mOverlay.add(trackImage);
            width = Math.max(width, trackDrawable.getIntrinsicWidth());
        } else {
            mHasTrackImage = false;
        }

        mThumbImage = new ImageView(context);
        final ImageView thumbImage = new ImageView(context);
        mThumbImage = thumbImage;

        // Add thumb to overlay if it has an image.
        final Drawable thumbDrawable = ta.getDrawable(THUMB_DRAWABLE);
        if (thumbDrawable != null) {
            mThumbImage.setImageDrawable(thumbDrawable);
            mOverlay.add(mThumbImage);
            thumbImage.setImageDrawable(thumbDrawable);
            mOverlay.add(thumbImage);
            width = Math.max(width, thumbDrawable.getIntrinsicWidth());
        }

        // If necessary, apply minimum thumb width and height.
        if (thumbDrawable.getIntrinsicWidth() <= 0 || thumbDrawable.getIntrinsicHeight() <= 0) {
            mThumbImage.setMinimumWidth(res.getDimensionPixelSize(R.dimen.fastscroll_thumb_width));
            mThumbImage.setMinimumHeight(
            final int minWidth = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_width);
            thumbImage.setMinimumWidth(minWidth);
            thumbImage.setMinimumHeight(
                    res.getDimensionPixelSize(R.dimen.fastscroll_thumb_height));
            width = Math.max(width, minWidth);
        }

        mWidth = width;

        final int previewSize = res.getDimensionPixelSize(R.dimen.fastscroll_overlay_size);
        mPreviewImage = new ImageView(context);
        mPreviewImage.setMinimumWidth(previewSize);
@@ -297,10 +316,11 @@ class FastScroller {
        mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING);
        ta.recycle();

        mScrollBarStyle = listView.getScrollBarStyle();
        mScrollCompleted = true;
        mState = STATE_VISIBLE;
        mMatchDragPosition =
                context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB;
        mMatchDragPosition = context.getApplicationInfo().targetSdkVersion
                >= Build.VERSION_CODES.HONEYCOMB;

        getSectionsFromIndexer();
        refreshDrawablePressedState();
@@ -362,6 +382,14 @@ class FastScroller {
        return mAlwaysShow;
    }

    public void setScrollBarStyle(int style) {
        if (mScrollBarStyle != style) {
            mScrollBarStyle = style;

            updateLayout();
        }
    }

    /**
     * Immediately transitions the fast scroller decorations to a hidden state.
     */
@@ -375,6 +403,8 @@ class FastScroller {
                    View.SCROLLBAR_POSITION_LEFT : View.SCROLLBAR_POSITION_RIGHT;
        }

        if (mScrollbarPosition != position) {
            mScrollbarPosition = position;
            mLayoutFromRight = position != View.SCROLLBAR_POSITION_LEFT;

            final int previewResId = mPreviewResId[mLayoutFromRight ? PREVIEW_RIGHT : PREVIEW_LEFT];
@@ -389,11 +419,13 @@ class FastScroller {
                mPreviewImage.setPadding(padding.left, padding.top, padding.right, padding.bottom);
            }

            // Requires re-layout.
            updateLayout();
        }
    }

    public int getWidth() {
        return mThumbImage.getWidth();
        return mWidth;
    }

    public void onSizeChanged(int w, int h, int oldw, int oldh) {
@@ -437,7 +469,7 @@ class FastScroller {
    /**
     * Measures and layouts the scrollbar and decorations.
     */
    private void updateLayout() {
    public void updateLayout() {
        // Prevent re-entry when RTL properties change as a side-effect of
        // resolving padding.
        if (mUpdatingLayout) {
@@ -594,21 +626,36 @@ class FastScroller {
        out.set(left, top, right, bottom);
    }

    /**
     * Updates the container rectangle used for layout.
     */
    private void updateContainerRect() {
        final AbsListView list = mList;
        list.resolvePadding();

        final Rect container = mContainerRect;
        container.left = 0;
        container.top = 0;
        container.right = list.getWidth();
        container.bottom = list.getHeight();

        final int scrollbarStyle = list.getScrollBarStyle();
        final int scrollbarStyle = mScrollBarStyle;
        if (scrollbarStyle == View.SCROLLBARS_INSIDE_INSET
                || scrollbarStyle == View.SCROLLBARS_INSIDE_OVERLAY) {
            container.left += list.getPaddingLeft();
            container.top += list.getPaddingTop();
            container.right -= list.getPaddingRight();
            container.bottom -= list.getPaddingBottom();

            // In inset mode, we need to adjust for padded scrollbar width.
            if (scrollbarStyle == View.SCROLLBARS_INSIDE_INSET) {
                final int width = getWidth();
                if (mScrollbarPosition == View.SCROLLBAR_POSITION_RIGHT) {
                    container.right += width;
                } else {
                    container.left -= width;
                }
            }
        }
    }