android.graphics.Insets Java Examples

The following examples show how to use android.graphics.Insets. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Switch.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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;
    } else {
        return 0;
    }
}
 
Example #2
Source File: AbsSeekBar.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
void drawTrack(Canvas canvas) {
    final Drawable thumbDrawable = mThumb;
    if (thumbDrawable != null && mSplitTrack) {
        final Insets insets = thumbDrawable.getOpticalInsets();
        final Rect tempRect = mTempRect;
        thumbDrawable.copyBounds(tempRect);
        tempRect.offset(mPaddingLeft - mThumbOffset, mPaddingTop);
        tempRect.left += insets.left;
        tempRect.right -= insets.right;

        final int saveCount = canvas.save();
        canvas.clipRect(tempRect, Op.DIFFERENCE);
        super.drawTrack(canvas);
        drawTickMarks(canvas);
        canvas.restoreToCount(saveCount);
    } else {
        super.drawTrack(canvas);
        drawTickMarks(canvas);
    }
}
 
Example #3
Source File: GridLayout.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * @hide
 */
@Override
protected void onDebugDraw(Canvas canvas) {
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.argb(50, 255, 255, 255));

    Insets insets = getOpticalInsets();

    int top    =               getPaddingTop()    + insets.top;
    int left   =               getPaddingLeft()   + insets.left;
    int right  = getWidth()  - getPaddingRight()  - insets.right;
    int bottom = getHeight() - getPaddingBottom() - insets.bottom;

    int[] xs = mHorizontalAxis.locations;
    if (xs != null) {
        for (int i = 0, length = xs.length; i < length; i++) {
            int x = left + xs[i];
            drawLine(canvas, x, top, x, bottom, paint);
        }
    }

    int[] ys = mVerticalAxis.locations;
    if (ys != null) {
        for (int i = 0, length = ys.length; i < length; i++) {
            int y = top + ys[i];
            drawLine(canvas, left, y, right, y, paint);
        }
    }

    super.onDebugDraw(canvas);
}
 
Example #4
Source File: BottomSheet.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.Q)
private int getAdditionalMandatoryOffsets() {
    if (!calcMandatoryInsets) {
        return 0;
    }
    Insets insets = lastInsets.getSystemGestureInsets();
    return !keyboardVisible && drawNavigationBar && insets != null && (insets.left != 0 || insets.right != 0) ? insets.bottom : 0;
}
 
Example #5
Source File: BottomSheet.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.Q)
private int getAdditionalMandatoryOffsets() {
    if (!calcMandatoryInsets) {
        return 0;
    }
    Insets insets = lastInsets.getSystemGestureInsets();
    return !keyboardVisible && drawNavigationBar && insets != null && (insets.left != 0 || insets.right != 0) ? insets.bottom : 0;
}
 
Example #6
Source File: Switch.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (mShowText) {
        if (mOnLayout == null) {
            mOnLayout = makeLayout(mTextOn);
        }

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

    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;
    if (mTrackDrawable != null) {
        mTrackDrawable.getPadding(padding);
        trackHeight = mTrackDrawable.getIntrinsicHeight();
    } else {
        padding.setEmpty();
        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;
    if (mThumbDrawable != null) {
        final Insets inset = mThumbDrawable.getOpticalInsets();
        paddingLeft = Math.max(paddingLeft, inset.left);
        paddingRight = Math.max(paddingRight, inset.right);
    }

    final int switchWidth = Math.max(mSwitchMinWidth,
            2 * mThumbWidth + paddingLeft + paddingRight);
    final int switchHeight = Math.max(trackHeight, thumbHeight);
    mSwitchWidth = switchWidth;
    mSwitchHeight = switchHeight;

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    final int measuredHeight = getMeasuredHeight();
    if (measuredHeight < switchHeight) {
        setMeasuredDimension(getMeasuredWidthAndState(), switchHeight);
    }
}
 
Example #7
Source File: Switch.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
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);
    }

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

    final int switchTop;
    final int switchBottom;
    switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) {
        default:
        case Gravity.TOP:
            switchTop = getPaddingTop();
            switchBottom = switchTop + mSwitchHeight;
            break;

        case Gravity.CENTER_VERTICAL:
            switchTop = (getPaddingTop() + getHeight() - getPaddingBottom()) / 2 -
                    mSwitchHeight / 2;
            switchBottom = switchTop + mSwitchHeight;
            break;

        case Gravity.BOTTOM:
            switchBottom = getHeight() - getPaddingBottom();
            switchTop = switchBottom - mSwitchHeight;
            break;
    }

    mSwitchLeft = switchLeft;
    mSwitchTop = switchTop;
    mSwitchBottom = switchBottom;
    mSwitchRight = switchRight;
}
 
Example #8
Source File: Switch.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@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 Insets thumbInsets;
    if (mThumbDrawable != null) {
        thumbInsets = mThumbDrawable.getOpticalInsets();
    } else {
        thumbInsets = 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 != 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);
    }

    // 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) {
            background.setHotspotBounds(thumbLeft, switchTop, thumbRight, switchBottom);
        }
    }

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