Search in sources :

Example 31 with Insets

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

the class TextView method getBoxHeight.

/////////////////////////////////////////////////////////////////////////
private int getBoxHeight(Layout l) {
    Insets opticalInsets = isLayoutModeOptical(mParent) ? getOpticalInsets() : Insets.NONE;
    int padding = (l == mHintLayout) ? getCompoundPaddingTop() + getCompoundPaddingBottom() : getExtendedPaddingTop() + getExtendedPaddingBottom();
    return getMeasuredHeight() - padding + opticalInsets.top + opticalInsets.bottom;
}
Also used : Insets(android.graphics.Insets) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 32 with Insets

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

the class Switch method draw.

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

Example 33 with Insets

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

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 34 with Insets

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

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 35 with Insets

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

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