Search in sources :

Example 26 with Insets

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

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

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

the class VectorDrawable method computeVectorSize.

/*
     * Update local dimensions to adjust for a target density that may differ
     * from the source density against which the constant state was loaded.
     */
void computeVectorSize() {
    final Insets opticalInsets = mVectorState.mOpticalInsets;
    final int sourceDensity = mVectorState.mDensity;
    final int targetDensity = mTargetDensity;
    if (targetDensity != sourceDensity) {
        mDpiScaledWidth = Drawable.scaleFromDensity((int) mVectorState.mBaseWidth, sourceDensity, targetDensity, true);
        mDpiScaledHeight = Drawable.scaleFromDensity((int) mVectorState.mBaseHeight, sourceDensity, targetDensity, true);
        final int left = Drawable.scaleFromDensity(opticalInsets.left, sourceDensity, targetDensity, false);
        final int right = Drawable.scaleFromDensity(opticalInsets.right, sourceDensity, targetDensity, false);
        final int top = Drawable.scaleFromDensity(opticalInsets.top, sourceDensity, targetDensity, false);
        final int bottom = Drawable.scaleFromDensity(opticalInsets.bottom, sourceDensity, targetDensity, false);
        mDpiScaledInsets = Insets.of(left, top, right, bottom);
    } else {
        mDpiScaledWidth = (int) mVectorState.mBaseWidth;
        mDpiScaledHeight = (int) mVectorState.mBaseHeight;
        mDpiScaledInsets = opticalInsets;
    }
    mDpiScaledDirty = false;
}
Also used : Insets(android.graphics.Insets)

Example 28 with Insets

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

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

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

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

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

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)

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