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

Commit 5876ff4a authored by Alan Viverette's avatar Alan Viverette
Browse files

Quantum for seek bars, spinners, switches

Fixes a bug in Switch that ignores the switch intrinsic height. Reverts
list selectors since they're not implemented in AbsListView yet. Also
adds Quantum for some miscellaneous widgets and icons.

Change-Id: I918bb0165b84e108cdf17a29eadc8424ac35f9ee
parent f75189d2
Loading
Loading
Loading
Loading
+35 −29
Original line number Original line Diff line number Diff line
@@ -511,15 +511,18 @@ public class Switch extends CompoundButton {
        if (mOnLayout == null) {
        if (mOnLayout == null) {
            mOnLayout = makeLayout(mTextOn);
            mOnLayout = makeLayout(mTextOn);
        }
        }

        if (mOffLayout == null) {
        if (mOffLayout == null) {
            mOffLayout = makeLayout(mTextOff);
            mOffLayout = makeLayout(mTextOff);
        }
        }


        mTrackDrawable.getPadding(mTempRect);
        mTrackDrawable.getPadding(mTempRect);

        final int maxTextWidth = Math.max(mOnLayout.getWidth(), mOffLayout.getWidth());
        final int maxTextWidth = Math.max(mOnLayout.getWidth(), mOffLayout.getWidth());
        final int switchWidth = Math.max(mSwitchMinWidth,
        final int switchWidth = Math.max(mSwitchMinWidth,
                maxTextWidth * 2 + mThumbTextPadding * 4 + mTempRect.left + mTempRect.right);
                maxTextWidth * 2 + mThumbTextPadding * 4 + mTempRect.left + mTempRect.right);
        final int switchHeight = mTrackDrawable.getIntrinsicHeight();
        final int switchHeight = Math.max(mTrackDrawable.getIntrinsicHeight(),
                mThumbDrawable.getIntrinsicHeight());


        mThumbWidth = maxTextWidth + mThumbTextPadding * 2;
        mThumbWidth = maxTextWidth + mThumbTextPadding * 2;


@@ -772,48 +775,51 @@ public class Switch extends CompoundButton {
    protected void onDraw(Canvas canvas) {
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        super.onDraw(canvas);


        // Draw the switch
        final Rect tempRect = mTempRect;
        int switchLeft = mSwitchLeft;
        final Drawable trackDrawable = mTrackDrawable;
        int switchTop = mSwitchTop;
        final Drawable thumbDrawable = mThumbDrawable;
        int switchRight = mSwitchRight;
        int switchBottom = mSwitchBottom;

        mTrackDrawable.setBounds(switchLeft, switchTop, switchRight, switchBottom);
        mTrackDrawable.draw(canvas);


        canvas.save();
        // Draw the switch

        final int switchLeft = mSwitchLeft;
        mTrackDrawable.getPadding(mTempRect);
        final int switchTop = mSwitchTop;
        int switchInnerLeft = switchLeft + mTempRect.left;
        final int switchRight = mSwitchRight;
        int switchInnerTop = switchTop + mTempRect.top;
        final int switchBottom = mSwitchBottom;
        int switchInnerRight = switchRight - mTempRect.right;
        trackDrawable.setBounds(switchLeft, switchTop, switchRight, switchBottom);
        int switchInnerBottom = switchBottom - mTempRect.bottom;
        trackDrawable.draw(canvas);

        final int saveCount = canvas.save();

        trackDrawable.getPadding(tempRect);
        final int switchInnerLeft = switchLeft + tempRect.left;
        final int switchInnerTop = switchTop + tempRect.top;
        final int switchInnerRight = switchRight - tempRect.right;
        final int switchInnerBottom = switchBottom - tempRect.bottom;
        canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight, switchBottom);
        canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight, switchBottom);


        // Relies on mTempRect, MUST be called first!
        // Relies on mTempRect, MUST be called first!
        final int thumbPos = getThumbOffset();
        final int thumbPos = getThumbOffset();


        mThumbDrawable.getPadding(mTempRect);
        thumbDrawable.getPadding(tempRect);
        int thumbLeft = switchInnerLeft - mTempRect.left + thumbPos;
        int thumbLeft = switchInnerLeft - tempRect.left + thumbPos;
        int thumbRight = switchInnerLeft + thumbPos + mThumbWidth + mTempRect.right;
        int thumbRight = switchInnerLeft + thumbPos + mThumbWidth + tempRect.right;
        mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom);
        thumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom);
        mThumbDrawable.draw(canvas);
        thumbDrawable.draw(canvas);


        // mTextColors should not be null, but just in case
        final int drawableState[] = getDrawableState();
        if (mTextColors != null) {
        if (mTextColors != null) {
            mTextPaint.setColor(mTextColors.getColorForState(getDrawableState(),
            mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0));
                    mTextColors.getDefaultColor()));
        }
        }
        mTextPaint.drawableState = getDrawableState();
        mTextPaint.drawableState = drawableState;


        Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
        final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
        if (switchText != null) {
        if (switchText != null) {
            canvas.translate((thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2,
            final int left = (thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2;
                    (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2);
            final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2;
            canvas.translate(left, top);
            switchText.draw(canvas);
            switchText.draw(canvas);
        }
        }


        canvas.restore();
        canvas.restoreToCount(saveCount);
    }
    }


    @Override
    @Override
+913 B
Loading image diff...
+473 B
Loading image diff...
+519 B
Loading image diff...
Loading