use of android.graphics.Insets in project android_frameworks_base by AOSPA.
the class NinePatchDrawable method computeBitmapSize.
private void computeBitmapSize() {
final NinePatch ninePatch = mNinePatchState.mNinePatch;
if (ninePatch == null) {
return;
}
final int sourceDensity = ninePatch.getDensity();
final int targetDensity = mTargetDensity;
final Insets sourceOpticalInsets = mNinePatchState.mOpticalInsets;
if (sourceOpticalInsets != Insets.NONE) {
final int left = Drawable.scaleFromDensity(sourceOpticalInsets.left, sourceDensity, targetDensity, true);
final int top = Drawable.scaleFromDensity(sourceOpticalInsets.top, sourceDensity, targetDensity, true);
final int right = Drawable.scaleFromDensity(sourceOpticalInsets.right, sourceDensity, targetDensity, true);
final int bottom = Drawable.scaleFromDensity(sourceOpticalInsets.bottom, sourceDensity, targetDensity, true);
mOpticalInsets = Insets.of(left, top, right, bottom);
} else {
mOpticalInsets = Insets.NONE;
}
final Rect sourcePadding = mNinePatchState.mPadding;
if (sourcePadding != null) {
if (mPadding == null) {
mPadding = new Rect();
}
mPadding.left = Drawable.scaleFromDensity(sourcePadding.left, sourceDensity, targetDensity, false);
mPadding.top = Drawable.scaleFromDensity(sourcePadding.top, sourceDensity, targetDensity, false);
mPadding.right = Drawable.scaleFromDensity(sourcePadding.right, sourceDensity, targetDensity, false);
mPadding.bottom = Drawable.scaleFromDensity(sourcePadding.bottom, sourceDensity, targetDensity, false);
} else {
mPadding = null;
}
mBitmapHeight = Drawable.scaleFromDensity(ninePatch.getHeight(), sourceDensity, targetDensity, true);
mBitmapWidth = Drawable.scaleFromDensity(ninePatch.getWidth(), sourceDensity, targetDensity, true);
final NinePatch.InsetStruct insets = ninePatch.getBitmap().getNinePatchInsets();
if (insets != null) {
Rect outlineRect = insets.outlineRect;
mOutlineInsets = NinePatch.InsetStruct.scaleInsets(outlineRect.left, outlineRect.top, outlineRect.right, outlineRect.bottom, targetDensity / (float) sourceDensity);
mOutlineRadius = Drawable.scaleFromDensity(insets.outlineRadius, sourceDensity, targetDensity);
} else {
mOutlineInsets = null;
}
}
use of android.graphics.Insets in project android_frameworks_base by AOSPA.
the class View method measure.
/**
* <p>
* This is called to find out how big a view should be. The parent
* supplies constraint information in the width and height parameters.
* </p>
*
* <p>
* The actual measurement work of a view is performed in
* {@link #onMeasure(int, int)}, called by this method. Therefore, only
* {@link #onMeasure(int, int)} can and must be overridden by subclasses.
* </p>
*
*
* @param widthMeasureSpec Horizontal space requirements as imposed by the
* parent
* @param heightMeasureSpec Vertical space requirements as imposed by the
* parent
*
* @see #onMeasure(int, int)
*/
public final void measure(int widthMeasureSpec, int heightMeasureSpec) {
boolean optical = isLayoutModeOptical(this);
if (optical != isLayoutModeOptical(mParent)) {
Insets insets = getOpticalInsets();
int oWidth = insets.left + insets.right;
int oHeight = insets.top + insets.bottom;
widthMeasureSpec = MeasureSpec.adjust(widthMeasureSpec, optical ? -oWidth : oWidth);
heightMeasureSpec = MeasureSpec.adjust(heightMeasureSpec, optical ? -oHeight : oHeight);
}
// Suppress sign extension for the low bytes
long key = (long) widthMeasureSpec << 32 | (long) heightMeasureSpec & 0xffffffffL;
if (mMeasureCache == null)
mMeasureCache = new LongSparseLongArray(2);
final boolean forceLayout = (mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT;
// Optimize layout by avoiding an extra EXACTLY pass when the view is
// already measured as the correct size. In API 23 and below, this
// extra pass is required to make LinearLayout re-distribute weight.
final boolean specChanged = widthMeasureSpec != mOldWidthMeasureSpec || heightMeasureSpec != mOldHeightMeasureSpec;
final boolean isSpecExactly = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY && MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY;
final boolean matchesSpecSize = getMeasuredWidth() == MeasureSpec.getSize(widthMeasureSpec) && getMeasuredHeight() == MeasureSpec.getSize(heightMeasureSpec);
final boolean needsLayout = specChanged && (sAlwaysRemeasureExactly || !isSpecExactly || !matchesSpecSize);
if (forceLayout || needsLayout) {
// first clears the measured dimension flag
mPrivateFlags &= ~PFLAG_MEASURED_DIMENSION_SET;
resolveRtlPropertiesIfNeeded();
int cacheIndex = forceLayout ? -1 : mMeasureCache.indexOfKey(key);
if (cacheIndex < 0 || sIgnoreMeasureCache) {
// measure ourselves, this should set the measured dimension flag back
onMeasure(widthMeasureSpec, heightMeasureSpec);
mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT;
} else {
long value = mMeasureCache.valueAt(cacheIndex);
// Casting a long to int drops the high 32 bits, no mask needed
setMeasuredDimensionRaw((int) (value >> 32), (int) value);
mPrivateFlags3 |= PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT;
}
// an exception to warn the developer
if ((mPrivateFlags & PFLAG_MEASURED_DIMENSION_SET) != PFLAG_MEASURED_DIMENSION_SET) {
throw new IllegalStateException("View with id " + getId() + ": " + getClass().getName() + "#onMeasure() did not set the" + " measured dimension by calling" + " setMeasuredDimension()");
}
mPrivateFlags |= PFLAG_LAYOUT_REQUIRED;
}
mOldWidthMeasureSpec = widthMeasureSpec;
mOldHeightMeasureSpec = heightMeasureSpec;
mMeasureCache.put(key, ((long) mMeasuredWidth) << 32 | // suppress sign extension
(long) mMeasuredHeight & 0xffffffffL);
}
use of android.graphics.Insets in project android_frameworks_base by ResurrectionRemix.
the class NinePatchDrawable method computeBitmapSize.
private void computeBitmapSize() {
final NinePatch ninePatch = mNinePatchState.mNinePatch;
if (ninePatch == null) {
return;
}
final int sourceDensity = ninePatch.getDensity();
final int targetDensity = mTargetDensity;
final Insets sourceOpticalInsets = mNinePatchState.mOpticalInsets;
if (sourceOpticalInsets != Insets.NONE) {
final int left = Drawable.scaleFromDensity(sourceOpticalInsets.left, sourceDensity, targetDensity, true);
final int top = Drawable.scaleFromDensity(sourceOpticalInsets.top, sourceDensity, targetDensity, true);
final int right = Drawable.scaleFromDensity(sourceOpticalInsets.right, sourceDensity, targetDensity, true);
final int bottom = Drawable.scaleFromDensity(sourceOpticalInsets.bottom, sourceDensity, targetDensity, true);
mOpticalInsets = Insets.of(left, top, right, bottom);
} else {
mOpticalInsets = Insets.NONE;
}
final Rect sourcePadding = mNinePatchState.mPadding;
if (sourcePadding != null) {
if (mPadding == null) {
mPadding = new Rect();
}
mPadding.left = Drawable.scaleFromDensity(sourcePadding.left, sourceDensity, targetDensity, false);
mPadding.top = Drawable.scaleFromDensity(sourcePadding.top, sourceDensity, targetDensity, false);
mPadding.right = Drawable.scaleFromDensity(sourcePadding.right, sourceDensity, targetDensity, false);
mPadding.bottom = Drawable.scaleFromDensity(sourcePadding.bottom, sourceDensity, targetDensity, false);
} else {
mPadding = null;
}
mBitmapHeight = Drawable.scaleFromDensity(ninePatch.getHeight(), sourceDensity, targetDensity, true);
mBitmapWidth = Drawable.scaleFromDensity(ninePatch.getWidth(), sourceDensity, targetDensity, true);
final NinePatch.InsetStruct insets = ninePatch.getBitmap().getNinePatchInsets();
if (insets != null) {
Rect outlineRect = insets.outlineRect;
mOutlineInsets = NinePatch.InsetStruct.scaleInsets(outlineRect.left, outlineRect.top, outlineRect.right, outlineRect.bottom, targetDensity / (float) sourceDensity);
mOutlineRadius = Drawable.scaleFromDensity(insets.outlineRadius, sourceDensity, targetDensity);
} else {
mOutlineInsets = null;
}
}
use of android.graphics.Insets in project android_frameworks_base by ResurrectionRemix.
the class Switch method onDraw.
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
final Rect padding = mTempRect;
final Drawable trackDrawable = mTrackDrawable;
if (trackDrawable != null) {
trackDrawable.getPadding(padding);
} else {
padding.setEmpty();
}
final int switchTop = mSwitchTop;
final int switchBottom = mSwitchBottom;
final int switchInnerTop = switchTop + padding.top;
final int switchInnerBottom = switchBottom - padding.bottom;
final Drawable thumbDrawable = mThumbDrawable;
if (trackDrawable != null) {
if (mSplitTrack && thumbDrawable != null) {
final Insets insets = thumbDrawable.getOpticalInsets();
thumbDrawable.copyBounds(padding);
padding.left += insets.left;
padding.right -= insets.right;
final int saveCount = canvas.save();
canvas.clipRect(padding, Op.DIFFERENCE);
trackDrawable.draw(canvas);
canvas.restoreToCount(saveCount);
} else {
trackDrawable.draw(canvas);
}
}
final int saveCount = canvas.save();
if (thumbDrawable != null) {
thumbDrawable.draw(canvas);
}
final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
if (switchText != null) {
final int[] drawableState = getDrawableState();
if (mTextColors != null) {
mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0));
}
mTextPaint.drawableState = drawableState;
final int cX;
if (thumbDrawable != null) {
final Rect bounds = thumbDrawable.getBounds();
cX = bounds.left + bounds.right;
} else {
cX = getWidth();
}
final int left = cX / 2 - switchText.getWidth() / 2;
final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2;
canvas.translate(left, top);
switchText.draw(canvas);
}
canvas.restoreToCount(saveCount);
}
use of android.graphics.Insets in project android_frameworks_base by ResurrectionRemix.
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;
}
}
Aggregations