Search in sources :

Example 21 with Insets

use of android.graphics.Insets in project android_frameworks_base by AOSPA.

the class Switch method onMeasure.

@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);
    }
}
Also used : Rect(android.graphics.Rect) Insets(android.graphics.Insets) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 22 with Insets

use of android.graphics.Insets in project android_frameworks_base by AOSPA.

the class Switch method onLayout.

@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;
}
Also used : Rect(android.graphics.Rect) Insets(android.graphics.Insets) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 23 with Insets

use of android.graphics.Insets in project android_frameworks_base by AOSPA.

the class Switch method getThumbScrollRange.

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;
    }
}
Also used : Rect(android.graphics.Rect) Insets(android.graphics.Insets)

Example 24 with Insets

use of android.graphics.Insets in project android_frameworks_base by AOSPA.

the class View method setMeasuredDimension.

/**
     * <p>This method must be called by {@link #onMeasure(int, int)} to store the
     * measured width and measured height. Failing to do so will trigger an
     * exception at measurement time.</p>
     *
     * @param measuredWidth The measured width of this view.  May be a complex
     * bit mask as defined by {@link #MEASURED_SIZE_MASK} and
     * {@link #MEASURED_STATE_TOO_SMALL}.
     * @param measuredHeight The measured height of this view.  May be a complex
     * bit mask as defined by {@link #MEASURED_SIZE_MASK} and
     * {@link #MEASURED_STATE_TOO_SMALL}.
     */
protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) {
    boolean optical = isLayoutModeOptical(this);
    if (optical != isLayoutModeOptical(mParent)) {
        Insets insets = getOpticalInsets();
        int opticalWidth = insets.left + insets.right;
        int opticalHeight = insets.top + insets.bottom;
        measuredWidth += optical ? opticalWidth : -opticalWidth;
        measuredHeight += optical ? opticalHeight : -opticalHeight;
    }
    setMeasuredDimensionRaw(measuredWidth, measuredHeight);
}
Also used : Insets(android.graphics.Insets) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 25 with Insets

use of android.graphics.Insets in project android_frameworks_base by ResurrectionRemix.

the class GridLayout method onDebugDraw.

/**
     * @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);
}
Also used : Insets(android.graphics.Insets) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Aggregations

Insets (android.graphics.Insets)73 Paint (android.graphics.Paint)53 Rect (android.graphics.Rect)35 TextPaint (android.text.TextPaint)26 Drawable (android.graphics.drawable.Drawable)15 Point (android.graphics.Point)10 NinePatch (android.graphics.NinePatch)5 Layout (android.text.Layout)5 StaticLayout (android.text.StaticLayout)5 LongSparseLongArray (android.util.LongSparseLongArray)4