use of android.graphics.NinePatch in project android_frameworks_base by AOSPA.
the class NinePatchDrawable method updateStateFromTypedArray.
/**
* Updates the constant state from the values in the typed array.
*/
private void updateStateFromTypedArray(@NonNull TypedArray a) throws XmlPullParserException {
final Resources r = a.getResources();
final NinePatchState state = mNinePatchState;
// Account for any configuration changes.
state.mChangingConfigurations |= a.getChangingConfigurations();
// Extract the theme attributes, if any.
state.mThemeAttrs = a.extractThemeAttrs();
state.mDither = a.getBoolean(R.styleable.NinePatchDrawable_dither, state.mDither);
final int srcResId = a.getResourceId(R.styleable.NinePatchDrawable_src, 0);
if (srcResId != 0) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = !state.mDither;
options.inScreenDensity = r.getDisplayMetrics().noncompatDensityDpi;
final Rect padding = new Rect();
final Rect opticalInsets = new Rect();
Bitmap bitmap = null;
try {
final TypedValue value = new TypedValue();
final InputStream is = r.openRawResource(srcResId, value);
bitmap = BitmapFactory.decodeResourceStream(r, value, is, padding, options);
is.close();
} catch (IOException e) {
// Ignore
}
if (bitmap == null) {
throw new XmlPullParserException(a.getPositionDescription() + ": <nine-patch> requires a valid src attribute");
} else if (bitmap.getNinePatchChunk() == null) {
throw new XmlPullParserException(a.getPositionDescription() + ": <nine-patch> requires a valid 9-patch source image");
}
bitmap.getOpticalInsets(opticalInsets);
state.mNinePatch = new NinePatch(bitmap, bitmap.getNinePatchChunk());
state.mPadding = padding;
state.mOpticalInsets = Insets.of(opticalInsets);
}
state.mAutoMirrored = a.getBoolean(R.styleable.NinePatchDrawable_autoMirrored, state.mAutoMirrored);
state.mBaseAlpha = a.getFloat(R.styleable.NinePatchDrawable_alpha, state.mBaseAlpha);
final int tintMode = a.getInt(R.styleable.NinePatchDrawable_tintMode, -1);
if (tintMode != -1) {
state.mTintMode = Drawable.parseTintMode(tintMode, Mode.SRC_IN);
}
final ColorStateList tint = a.getColorStateList(R.styleable.NinePatchDrawable_tint);
if (tint != null) {
state.mTint = tint;
}
}
use of android.graphics.NinePatch in project android_frameworks_base by DirtyUnicorns.
the class NinePatchDrawable method updateStateFromTypedArray.
/**
* Updates the constant state from the values in the typed array.
*/
private void updateStateFromTypedArray(@NonNull TypedArray a) throws XmlPullParserException {
final Resources r = a.getResources();
final NinePatchState state = mNinePatchState;
// Account for any configuration changes.
state.mChangingConfigurations |= a.getChangingConfigurations();
// Extract the theme attributes, if any.
state.mThemeAttrs = a.extractThemeAttrs();
state.mDither = a.getBoolean(R.styleable.NinePatchDrawable_dither, state.mDither);
final int srcResId = a.getResourceId(R.styleable.NinePatchDrawable_src, 0);
if (srcResId != 0) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = !state.mDither;
options.inScreenDensity = r.getDisplayMetrics().noncompatDensityDpi;
final Rect padding = new Rect();
final Rect opticalInsets = new Rect();
Bitmap bitmap = null;
try {
final TypedValue value = new TypedValue();
final InputStream is = r.openRawResource(srcResId, value);
bitmap = BitmapFactory.decodeResourceStream(r, value, is, padding, options);
is.close();
} catch (IOException e) {
// Ignore
}
if (bitmap == null) {
throw new XmlPullParserException(a.getPositionDescription() + ": <nine-patch> requires a valid src attribute");
} else if (bitmap.getNinePatchChunk() == null) {
throw new XmlPullParserException(a.getPositionDescription() + ": <nine-patch> requires a valid 9-patch source image");
}
bitmap.getOpticalInsets(opticalInsets);
state.mNinePatch = new NinePatch(bitmap, bitmap.getNinePatchChunk());
state.mPadding = padding;
state.mOpticalInsets = Insets.of(opticalInsets);
}
state.mAutoMirrored = a.getBoolean(R.styleable.NinePatchDrawable_autoMirrored, state.mAutoMirrored);
state.mBaseAlpha = a.getFloat(R.styleable.NinePatchDrawable_alpha, state.mBaseAlpha);
final int tintMode = a.getInt(R.styleable.NinePatchDrawable_tintMode, -1);
if (tintMode != -1) {
state.mTintMode = Drawable.parseTintMode(tintMode, Mode.SRC_IN);
}
final ColorStateList tint = a.getColorStateList(R.styleable.NinePatchDrawable_tint);
if (tint != null) {
state.mTint = tint;
}
}
use of android.graphics.NinePatch in project android_frameworks_base by DirtyUnicorns.
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.NinePatch 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.NinePatch in project android_frameworks_base by crdroidandroid.
the class NinePatchDrawable method updateStateFromTypedArray.
/**
* Updates the constant state from the values in the typed array.
*/
private void updateStateFromTypedArray(@NonNull TypedArray a) throws XmlPullParserException {
final Resources r = a.getResources();
final NinePatchState state = mNinePatchState;
// Account for any configuration changes.
state.mChangingConfigurations |= a.getChangingConfigurations();
// Extract the theme attributes, if any.
state.mThemeAttrs = a.extractThemeAttrs();
state.mDither = a.getBoolean(R.styleable.NinePatchDrawable_dither, state.mDither);
final int srcResId = a.getResourceId(R.styleable.NinePatchDrawable_src, 0);
if (srcResId != 0) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = !state.mDither;
options.inScreenDensity = r.getDisplayMetrics().noncompatDensityDpi;
final Rect padding = new Rect();
final Rect opticalInsets = new Rect();
Bitmap bitmap = null;
try {
final TypedValue value = new TypedValue();
final InputStream is = r.openRawResource(srcResId, value);
bitmap = BitmapFactory.decodeResourceStream(r, value, is, padding, options);
is.close();
} catch (IOException e) {
// Ignore
}
if (bitmap == null) {
throw new XmlPullParserException(a.getPositionDescription() + ": <nine-patch> requires a valid src attribute");
} else if (bitmap.getNinePatchChunk() == null) {
throw new XmlPullParserException(a.getPositionDescription() + ": <nine-patch> requires a valid 9-patch source image");
}
bitmap.getOpticalInsets(opticalInsets);
state.mNinePatch = new NinePatch(bitmap, bitmap.getNinePatchChunk());
state.mPadding = padding;
state.mOpticalInsets = Insets.of(opticalInsets);
}
state.mAutoMirrored = a.getBoolean(R.styleable.NinePatchDrawable_autoMirrored, state.mAutoMirrored);
state.mBaseAlpha = a.getFloat(R.styleable.NinePatchDrawable_alpha, state.mBaseAlpha);
final int tintMode = a.getInt(R.styleable.NinePatchDrawable_tintMode, -1);
if (tintMode != -1) {
state.mTintMode = Drawable.parseTintMode(tintMode, Mode.SRC_IN);
}
final ColorStateList tint = a.getColorStateList(R.styleable.NinePatchDrawable_tint);
if (tint != null) {
state.mTint = tint;
}
}
Aggregations