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

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

Merge "Revert "Update switch assets, fix SearchView asset 9-patch areas"" into lmp-dev

parents d922a546 9b38f6c2
Loading
Loading
Loading
Loading
+40 −129
Original line number Diff line number Diff line
@@ -100,35 +100,13 @@ public class Switch extends CompoundButton {
    private int mMinFlingVelocity;

    private float mThumbPosition;

    /**
     * Width required to draw the switch track and thumb. Includes padding and
     * optical bounds for both the track and thumb.
     */
    private int mSwitchWidth;

    /**
     * Height required to draw the switch track and thumb. Includes padding and
     * optical bounds for both the track and thumb.
     */
    private int mSwitchHeight;
    private int mThumbWidth; // Does not include padding

    /**
     * Width of the thumb's content region. Does not include padding or
     * optical bounds.
     */
    private int mThumbWidth;

    /** Left bound for drawing the switch track and thumb. */
    private int mSwitchLeft;

    /** Top bound for drawing the switch track and thumb. */
    private int mSwitchTop;

    /** Right bound for drawing the switch track and thumb. */
    private int mSwitchRight;

    /** Bottom bound for drawing the switch track and thumb. */
    private int mSwitchBottom;

    private TextPaint mTextPaint;
@@ -561,7 +539,7 @@ public class Switch extends CompoundButton {
     * Sets whether the on/off text should be displayed.
     *
     * @param showText {@code true} to display on/off text
     * @attr ref android.R.styleable#Switch_showText
     * @hide
     */
    public void setShowText(boolean showText) {
        if (mShowText != showText) {
@@ -572,7 +550,7 @@ public class Switch extends CompoundButton {

    /**
     * @return whether the on/off text should be displayed
     * @attr ref android.R.styleable#Switch_showText
     * @hide
     */
    public boolean getShowText() {
        return mShowText;
@@ -590,30 +568,8 @@ public class Switch extends CompoundButton {
            }
        }

        final Rect padding = mTempRect;
        final int thumbWidth;
        final int thumbHeight;
        if (mThumbDrawable != null) {
            // Cached thumb width does not include padding.
            mThumbDrawable.getPadding(padding);
            thumbWidth = mThumbDrawable.getIntrinsicWidth() - padding.left - padding.right;
            thumbHeight = mThumbDrawable.getIntrinsicHeight();
        } else {
            thumbWidth = 0;
            thumbHeight = 0;
        }

        final int maxTextWidth;
        if (mShowText) {
            maxTextWidth = Math.max(mOnLayout.getWidth(), mOffLayout.getWidth())
                    + mThumbTextPadding * 2;
        } else {
            maxTextWidth = 0;
        }

        mThumbWidth = Math.max(maxTextWidth, thumbWidth);

        final int trackHeight;
        final Rect padding = mTempRect;
        if (mTrackDrawable != null) {
            mTrackDrawable.getPadding(padding);
            trackHeight = mTrackDrawable.getIntrinsicHeight();
@@ -622,18 +578,22 @@ public class Switch extends CompoundButton {
            trackHeight = 0;
        }

        // Adjust left and right padding to ensure there's enough room for the
        // thumb's padding (when present).
        int paddingLeft = padding.left;
        int paddingRight = padding.right;
        final int thumbWidth;
        final int thumbHeight;
        if (mThumbDrawable != null) {
            final Insets inset = mThumbDrawable.getOpticalInsets();
            paddingLeft = Math.max(paddingLeft, inset.left);
            paddingRight = Math.max(paddingRight, inset.right);
            thumbWidth = mThumbDrawable.getIntrinsicWidth();
            thumbHeight = mThumbDrawable.getIntrinsicHeight();
        } else {
            thumbWidth = 0;
            thumbHeight = 0;
        }

        final int maxTextWidth = mShowText ? Math.max(mOnLayout.getWidth(), mOffLayout.getWidth())
                + mThumbTextPadding * 2 : 0;
        mThumbWidth = Math.max(maxTextWidth, thumbWidth);

        final int switchWidth = Math.max(mSwitchMinWidth,
                2 * mThumbWidth + paddingLeft + paddingRight);
                2 * mThumbWidth + padding.left + padding.right);
        final int switchHeight = Math.max(trackHeight, thumbHeight);
        mSwitchWidth = switchWidth;
        mSwitchHeight = switchHeight;
@@ -846,33 +806,19 @@ public class Switch extends CompoundButton {
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);

        int opticalInsetLeft = 0;
        int opticalInsetRight = 0;
        if (mThumbDrawable != null) {
            final Rect trackPadding = mTempRect;
            if (mTrackDrawable != null) {
                mTrackDrawable.getPadding(trackPadding);
            } else {
                trackPadding.setEmpty();
            }

            final Insets insets = mThumbDrawable.getOpticalInsets();
            opticalInsetLeft = Math.max(0, insets.left - trackPadding.left);
            opticalInsetRight = Math.max(0, insets.right - trackPadding.right);
        }
        int switchRight;
        int switchLeft;

        final int switchRight;
        final int switchLeft;
        if (isLayoutRtl()) {
            switchLeft = getPaddingLeft() + opticalInsetLeft;
            switchRight = switchLeft + mSwitchWidth - opticalInsetLeft - opticalInsetRight;
            switchLeft = getPaddingLeft();
            switchRight = switchLeft + mSwitchWidth;
        } else {
            switchRight = getWidth() - getPaddingRight() - opticalInsetRight;
            switchLeft = switchRight - mSwitchWidth + opticalInsetLeft + opticalInsetRight;
            switchRight = getWidth() - getPaddingRight();
            switchLeft = switchRight - mSwitchWidth;
        }

        final int switchTop;
        final int switchBottom;
        int switchTop = 0;
        int switchBottom = 0;
        switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) {
            default:
            case Gravity.TOP:
@@ -901,55 +847,27 @@ public class Switch extends CompoundButton {
    @Override
    public void draw(Canvas c) {
        final Rect padding = mTempRect;

        // Layout the track.
        final int switchLeft = mSwitchLeft;
        final int switchTop = mSwitchTop;
        final int switchRight = mSwitchRight;
        final int switchBottom = mSwitchBottom;

        int thumbInitialLeft = switchLeft + getThumbOffset();

        final Insets thumbInsets;
        if (mThumbDrawable != null) {
            thumbInsets = mThumbDrawable.getOpticalInsets();
        } else {
            thumbInsets = Insets.NONE;
        }

        // Layout the track.
        if (mTrackDrawable != null) {
            mTrackDrawable.setBounds(switchLeft, switchTop, switchRight, switchBottom);
            mTrackDrawable.getPadding(padding);
        }

            // Adjust thumb position for track padding.
            thumbInitialLeft += padding.left;
        final int switchInnerLeft = switchLeft + padding.left;

            // If necessary, offset by the optical insets of the thumb asset.
            int trackLeft = switchLeft;
            int trackTop = switchTop;
            int trackRight = switchRight;
            int trackBottom = switchBottom;
            if (thumbInsets != Insets.NONE) {
                if (thumbInsets.left > padding.left) {
                    trackLeft += thumbInsets.left - padding.left;
                }
                if (thumbInsets.top > padding.top) {
                    trackTop += thumbInsets.top - padding.top;
                }
                if (thumbInsets.right > padding.right) {
                    trackRight -= thumbInsets.right - padding.right;
                }
                if (thumbInsets.bottom > padding.bottom) {
                    trackBottom -= thumbInsets.bottom - padding.bottom;
                }
            }
            mTrackDrawable.setBounds(trackLeft, trackTop, trackRight, trackBottom);
        }
        // Relies on mTempRect, MUST be called first!
        final int thumbPos = getThumbOffset();

        // Layout the thumb.
        if (mThumbDrawable != null) {
            mThumbDrawable.getPadding(padding);

            final int thumbLeft = thumbInitialLeft - padding.left;
            final int thumbRight = thumbInitialLeft + mThumbWidth + padding.right;
            final int thumbLeft = switchInnerLeft - padding.left + thumbPos;
            final int thumbRight = switchInnerLeft + thumbPos + mThumbWidth + padding.right;
            mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom);

            final Drawable background = getBackground();
@@ -976,7 +894,9 @@ public class Switch extends CompoundButton {

        final int switchTop = mSwitchTop;
        final int switchBottom = mSwitchBottom;
        final int switchInnerLeft = mSwitchLeft + padding.left;
        final int switchInnerTop = switchTop + padding.top;
        final int switchInnerRight = mSwitchRight - padding.right;
        final int switchInnerBottom = switchBottom - padding.bottom;

        final Drawable thumbDrawable = mThumbDrawable;
@@ -999,6 +919,7 @@ public class Switch extends CompoundButton {
        final int saveCount = canvas.save();

        if (thumbDrawable != null) {
            canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight, switchBottom);
            thumbDrawable.draw(canvas);
        }

@@ -1053,7 +974,7 @@ public class Switch extends CompoundButton {

    /**
     * Translates thumb position to offset according to current RTL setting and
     * thumb scroll range. Accounts for both track and thumb padding.
     * thumb scroll range.
     *
     * @return thumb offset
     */
@@ -1069,18 +990,8 @@ public class Switch extends CompoundButton {

    private int getThumbScrollRange() {
        if (mTrackDrawable != null) {
            final Rect padding = mTempRect;
            mTrackDrawable.getPadding(padding);

            final Insets insets;
            if (mThumbDrawable != null) {
                insets = mThumbDrawable.getOpticalInsets();
            } else {
                insets = Insets.NONE;
            }

            return mSwitchWidth - mThumbWidth - padding.left - padding.right
                    - insets.left - insets.right;
            mTrackDrawable.getPadding(mTempRect);
            return mSwitchWidth - mThumbWidth - mTempRect.left - mTempRect.right;
        } else {
            return 0;
        }
+740 B
Loading image diff...
−16.4 KiB
Loading image diff...
−16.4 KiB
Loading image diff...
−16.5 KiB
Loading image diff...
Loading