Example usage for android.support.v4.graphics.drawable DrawableCompat setHotspotBounds

List of usage examples for android.support.v4.graphics.drawable DrawableCompat setHotspotBounds

Introduction

In this page you can find the example usage for android.support.v4.graphics.drawable DrawableCompat setHotspotBounds.

Prototype

public static void setHotspotBounds(Drawable drawable, int i, int i2, int i3, int i4) 

Source Link

Usage

From source file:rikka.akashitoolkit.ui.widget.IconSwitchCompat.java

@Override
public void draw(Canvas c) {
    final Rect padding = mTempRect;
    final int switchLeft = mSwitchLeft;
    final int switchTop = mSwitchTop;
    final int switchRight = mSwitchRight;
    final int switchBottom = mSwitchBottom;

    int thumbInitialLeft = switchLeft + getThumbOffset();

    final Rect thumbInsets;
    if (mThumbDrawable != null) {
        thumbInsets = DrawableUtils.getOpticalBounds(mThumbDrawable);
    } else {/*from w w w . j  a v  a2s  .  c  o m*/
        thumbInsets = DrawableUtils.INSETS_NONE;
    }

    // Layout the track.
    if (mTrackDrawable != null) {
        mTrackDrawable.getPadding(padding);

        // Adjust thumb position for track padding.
        thumbInitialLeft += 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 != null) {
            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);
    }

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

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

        if (mIconDrawable != null) {
            mIconDrawable.getPadding(padding);
            mIconDrawable.setBounds(thumbLeft + (int) ((thumbRight - thumbLeft) * 0.23),
                    switchTop + (int) ((switchBottom - switchTop) * 0.23),
                    thumbRight - (int) ((thumbRight - thumbLeft) * 0.23),
                    switchBottom - (int) ((switchBottom - switchTop) * 0.23));
        }

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

    // Draw the background.
    super.draw(c);
}

From source file:org.mariotaku.multivalueswitch.library.MultiValueSwitch.java

@Override
public void draw(Canvas c) {
    final Rect padding = mTempRect;
    final int switchLeft = mSwitchLeft;
    final int switchTop = mSwitchTop;
    final int switchRight = mSwitchRight;
    final int switchBottom = mSwitchBottom;

    int thumbInitialLeft = switchLeft + getThumbOffset();

    final Rect thumbInsets;
    if (mThumbDrawable != null) {
        thumbInsets = MVS_DrawableUtilsAccessor.getOpticalBounds(mThumbDrawable);
    } else {/*from   w  ww. j a  v a2  s .  co  m*/
        thumbInsets = MVS_DrawableUtilsAccessor.INSETS_NONE;
    }

    // Layout the track.
    if (mTrackDrawable != null) {
        mTrackDrawable.getPadding(padding);

        // Adjust thumb position for track padding.
        thumbInitialLeft += 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 != null) {
            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);
    }

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

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

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

    // Draw the background.
    super.draw(c);
}

From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java

@Override
public void draw(Canvas c) {
    final Rect padding = mTempRect;
    final int switchLeft = mSwitchLeft;
    final int switchTop = mSwitchTop;
    final int switchRight = mSwitchRight;
    final int switchBottom = mSwitchBottom;

    int thumbInitialLeft = switchLeft + getThumbOffset();

    // Layout the track.
    if (mTrackDrawable != null) {
        mTrackDrawable.getPadding(padding);

        // Adjust thumb position for track padding.
        thumbInitialLeft += 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;
        mTrackDrawable.setBounds(trackLeft, trackTop, trackRight, trackBottom);
    }//  ww  w.j  a va  2s .  c om

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

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

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

    // Draw the background.
    super.draw(c);
}