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

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

Merge "Add ripple to switches, radio buttons, check boxes, seek bars"

parents a822d393 61956606
Loading
Loading
Loading
Loading
+44 −14
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;

import com.android.internal.R;

public abstract class AbsSeekBar extends ProgressBar {
    private Drawable mThumb;
    private int mThumbOffset;
@@ -289,28 +291,39 @@ public abstract class AbsSeekBar extends ProgressBar {
     */
    private void setThumbPos(int w, Drawable thumb, float scale, int gap) {
        int available = w - mPaddingLeft - mPaddingRight;
        int thumbWidth = thumb.getIntrinsicWidth();
        int thumbHeight = thumb.getIntrinsicHeight();
        final int thumbWidth = thumb.getIntrinsicWidth();
        final int thumbHeight = thumb.getIntrinsicHeight();
        available -= thumbWidth;

        // The extra space for the thumb to move on the track
        available += mThumbOffset * 2;

        int thumbPos = (int) (scale * available + 0.5f);
        final int thumbPos = (int) (scale * available + 0.5f);

        int topBound, bottomBound;
        final int top, bottom;
        if (gap == Integer.MIN_VALUE) {
            Rect oldBounds = thumb.getBounds();
            topBound = oldBounds.top;
            bottomBound = oldBounds.bottom;
            final Rect oldBounds = thumb.getBounds();
            top = oldBounds.top;
            bottom = oldBounds.bottom;
        } else {
            topBound = gap;
            bottomBound = gap + thumbHeight;
            top = gap;
            bottom = gap + thumbHeight;
        }

        // Canvas will be translated, so 0,0 is where we start drawing
        final int left = (isLayoutRtl() && mMirrorForRtl) ? available - thumbPos : thumbPos;
        thumb.setBounds(left, topBound, left + thumbWidth, bottomBound);
        final int right = left + thumbWidth;

        final Drawable background = getBackground();
        if (background.supportsHotspots()) {
            final Rect bounds = mThumb.getBounds();
            final int offsetX = mPaddingLeft - mThumbOffset;
            final int offsetY = mPaddingTop;
            background.setHotspotBounds(left + offsetX, bounds.top + offsetY,
                    right + offsetX, bounds.bottom + offsetY);
        }

        // Canvas will be translated, so 0,0 is where we start drawing
        thumb.setBounds(left, top, right, bottom);
    }

    /**
@@ -328,6 +341,7 @@ public abstract class AbsSeekBar extends ProgressBar {
    @Override
    protected synchronized void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        if (mThumb != null) {
            canvas.save();
            // Translate the padding. For the x, we need to allow the thumb to
@@ -424,10 +438,24 @@ public abstract class AbsSeekBar extends ProgressBar {
        return true;
    }

    private void setHotspot(int id, float x, float y) {
        final Drawable bg = getBackground();
        if (bg != null && bg.supportsHotspots()) {
            bg.setHotspot(id, x, y);
        }
    }

    private void clearHotspot(int id) {
        final Drawable bg = getBackground();
        if (bg != null && bg.supportsHotspots()) {
            bg.removeHotspot(id);
        }
    }

    private void trackTouchEvent(MotionEvent event) {
        final int width = getWidth();
        final int available = width - mPaddingLeft - mPaddingRight;
        int x = (int)event.getX();
        final int x = (int) event.getX();
        float scale;
        float progress = 0;
        if (isLayoutRtl() && mMirrorForRtl) {
@@ -452,6 +480,7 @@ public abstract class AbsSeekBar extends ProgressBar {
        final int max = getMax();
        progress += scale * max;

        setHotspot(R.attr.state_pressed, x, (int) event.getY());
        setProgress((int) progress, true);
    }

@@ -477,6 +506,7 @@ public abstract class AbsSeekBar extends ProgressBar {
     * canceled.
     */
    void onStopTrackingTouch() {
        clearHotspot(R.attr.state_pressed);
        mIsDragging = false;
    }

+16 −6
Original line number Diff line number Diff line
@@ -261,15 +261,13 @@ public abstract class CompoundButton extends Button implements Checkable {

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        final Drawable buttonDrawable = mButtonDrawable;
        if (buttonDrawable != null) {
            final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
            final int drawableHeight = buttonDrawable.getIntrinsicHeight();
            final int drawableWidth = buttonDrawable.getIntrinsicWidth();

            int top = 0;
            final int top;
            switch (verticalGravity) {
                case Gravity.BOTTOM:
                    top = getHeight() - drawableHeight;
@@ -277,12 +275,24 @@ public abstract class CompoundButton extends Button implements Checkable {
                case Gravity.CENTER_VERTICAL:
                    top = (getHeight() - drawableHeight) / 2;
                    break;
                default:
                    top = 0;
            }
            int bottom = top + drawableHeight;
            int left = isLayoutRtl() ? getWidth() - drawableWidth : 0;
            int right = isLayoutRtl() ? getWidth() : drawableWidth;
            final int bottom = top + drawableHeight;
            final int left = isLayoutRtl() ? getWidth() - drawableWidth : 0;
            final int right = isLayoutRtl() ? getWidth() : drawableWidth;

            buttonDrawable.setBounds(left, top, right, bottom);

            final Drawable background = getBackground();
            if (background.supportsHotspots()) {
                background.setHotspotBounds(left, top, right, bottom);
            }
        }

        super.onDraw(canvas);

        if (buttonDrawable != null) {
            buttonDrawable.draw(canvas);
        }
    }
+13 −7
Original line number Diff line number Diff line
@@ -773,8 +773,6 @@ public class Switch extends CompoundButton {

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        final Rect tempRect = mTempRect;
        final Drawable trackDrawable = mTrackDrawable;
        final Drawable thumbDrawable = mThumbDrawable;
@@ -785,16 +783,12 @@ public class Switch extends CompoundButton {
        final int switchRight = mSwitchRight;
        final int switchBottom = mSwitchBottom;
        trackDrawable.setBounds(switchLeft, switchTop, switchRight, switchBottom);
        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);

        // Relies on mTempRect, MUST be called first!
        final int thumbPos = getThumbOffset();
@@ -803,6 +797,18 @@ public class Switch extends CompoundButton {
        int thumbLeft = switchInnerLeft - tempRect.left + thumbPos;
        int thumbRight = switchInnerLeft + thumbPos + mThumbWidth + tempRect.right;
        thumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom);

        final Drawable background = getBackground();
        if (background.supportsHotspots()) {
            background.setHotspotBounds(thumbLeft, switchTop, thumbRight, switchBottom);
        }

        super.onDraw(canvas);

        trackDrawable.draw(canvas);

        final int saveCount = canvas.save();
        canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight, switchBottom);
        thumbDrawable.draw(canvas);

        final int drawableState[] = getDrawableState();
+9 −7
Original line number Diff line number Diff line
@@ -15,18 +15,20 @@
-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:state_enabled="true" android:state_pressed="true">
        <bitmap android:src="@drawable/btn_radio_on_pressed_qntm_alpha"
            android:tint="?attr/colorControlActivated" />
    <item android:state_enabled="false" android:state_checked="true">
        <bitmap android:src="@drawable/btn_radio_on_qntm_alpha"
            android:tint="?attr/colorControlNormal"
            android:alpha="?attr/disabledAlpha" />
    </item>
    <item android:state_enabled="false">
        <bitmap android:src="@drawable/btn_radio_off_qntm_alpha"
            android:tint="?attr/colorControlNormal"
            android:alpha="?attr/disabledAlpha" />
    </item>
    <item android:state_checked="true">
        <bitmap android:src="@drawable/btn_radio_on_qntm_alpha"
            android:tint="?attr/colorControlActivated" />
    </item>
    <item android:state_enabled="true" android:state_pressed="true">
        <bitmap android:src="@drawable/btn_radio_off_pressed_qntm_alpha"
            android:tint="?attr/colorControlActivated" />
    </item>
    <item>
        <bitmap android:src="@drawable/btn_radio_off_qntm_alpha"
            android:tint="?attr/colorControlNormal" />
+0 −4
Original line number Diff line number Diff line
@@ -19,10 +19,6 @@
        <bitmap android:src="@drawable/scrubber_control_off_qntm_alpha"
            android:tint="?attr/colorControlNormal" />
    </item>
    <item android:state_pressed="true">
        <bitmap android:src="@drawable/scrubber_control_on_pressed_qntm_alpha"
            android:tint="?attr/colorControlActivated" />
    </item>
    <item>
        <bitmap android:src="@drawable/scrubber_control_on_qntm_alpha"
            android:tint="?attr/colorControlActivated" />
Loading