本文整理汇总了Java中android.graphics.NinePatch类的典型用法代码示例。如果您正苦于以下问题:Java NinePatch类的具体用法?Java NinePatch怎么用?Java NinePatch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NinePatch类属于android.graphics包,在下文中一共展示了NinePatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createImageBasedDrawable
import android.graphics.NinePatch; //导入依赖的package包/类
public static Drawable createImageBasedDrawable(byte[] byteArray, int bitmapDensityReference, boolean expectedNinePatch, Resources res)
{
if (expectedNinePatch)
return createNinePatchDrawable(byteArray,bitmapDensityReference,res);
Bitmap bitmap = BitmapUtil.createBitmap(byteArray,bitmapDensityReference,res);
byte[] chunk = bitmap.getNinePatchChunk();
boolean result = NinePatch.isNinePatchChunk(chunk);
if (result)
{
// Raro pero resulta que es un NinePatch (raro porque lo normal es que se especifique la extensión .9.png)
return createNinePatchDrawable(bitmap,res);
}
else
{
return new BitmapDrawable(res, bitmap);
}
}
示例2: assertEquals
import android.graphics.NinePatch; //导入依赖的package包/类
public static void assertEquals(NinePatchDrawable a,NinePatchDrawable b)
{
assertEqualsDrawable(a, b);
NinePatch a2 = (NinePatch) TestUtil.getField(a, "mNinePatch");
NinePatch b2 = (NinePatch) TestUtil.getField(b, "mNinePatch");
assertEquals((Bitmap) TestUtil.getField(a2, "mBitmap"), (Bitmap) TestUtil.getField(b2, "mBitmap"));
Paint a_paint = a.getPaint();
Paint b_paint = b.getPaint();
//assertEquals(a_paint.isAntiAlias(), b_paint.isAntiAlias());
assertEquals(a_paint.isDither(), b_paint.isDither());
// assertEquals(a_paint.isFilterBitmap(), b_paint.isFilterBitmap());
}
示例3: initPaint
import android.graphics.NinePatch; //导入依赖的package包/类
private void initPaint(Context context) {
this.mBmp = BitmapFactory.decodeResource(context.getResources(), mDrawableRid);
if (mBmp != null) {
if (mBmp.getNinePatchChunk() != null) {
hasNinePatch = true;
mNinePatch = new NinePatch(mBmp, mBmp.getNinePatchChunk(), null);
}
if (mMode == RVItemDecorationConst.MODE_HORIZONTAL)
mCurrentThickness = mThickness == 0 ? mBmp.getHeight() : mThickness;
if (mMode == RVItemDecorationConst.MODE_VERTICAL)
mCurrentThickness = mThickness == 0 ? mBmp.getWidth() : mThickness;
}
mPaint = new Paint();
mPaint.setColor(mColor);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(mThickness);
}
示例4: setParams
import android.graphics.NinePatch; //导入依赖的package包/类
public void setParams(Context context, Param params) {
this.mMode = params.mode;
this.mDrawableRid = params.drawableRid;
this.mColor = params.color;
this.mThickness = params.thickness;
this.mDashGap = params.dashGap;
this.mDashWidth = params.dashWidth;
this.mPaddingStart = params.paddingStart;
this.mPaddingEnd = params.paddingEnd;
this.mFirstLineVisible = params.firstLineVisible;
this.mLastLineVisible = params.lastLineVisible;
this.mGridLeftVisible = params.gridLeftVisible;
this.mGridRightVisible = params.gridRightVisible;
this.mGridTopVisible = params.gridTopVisible;
this.mGridBottomVisible = params.gridBottomVisible;
this.mGridHorizontalSpacing = params.gridHorizontalSpacing;
this.mGridVerticalSpacing = params.gridVerticalSpacing;
this.mParent = params.parent;
if (mParent != null) compatibleWithLayoutManager(mParent);
this.mBmp = BitmapFactory.decodeResource(context.getResources(), mDrawableRid);
if (mBmp != null) {
if (mBmp.getNinePatchChunk() != null) {
hasNinePatch = true;
mNinePatch = new NinePatch(mBmp, mBmp.getNinePatchChunk(), null);
}
if (mMode == MODE_HORIZONTAL)
mCurrentThickness = mThickness == 0 ? mBmp.getHeight() : mThickness;
if (mMode == MODE_VERTICAL)
mCurrentThickness = mThickness == 0 ? mBmp.getWidth() : mThickness;
}
initPaint();
}
示例5: a
import android.graphics.NinePatch; //导入依赖的package包/类
private Drawable a(String str, Context context) {
Drawable createFromStream;
IOException e;
try {
InputStream open = context.getApplicationContext().getAssets().open(str);
if (open == null) {
return null;
}
if (str.endsWith(".9.png")) {
Bitmap decodeStream = BitmapFactory.decodeStream(open);
if (decodeStream == null) {
return null;
}
byte[] ninePatchChunk = decodeStream.getNinePatchChunk();
NinePatch.isNinePatchChunk(ninePatchChunk);
return new NinePatchDrawable(decodeStream, ninePatchChunk, new Rect(), null);
}
createFromStream = Drawable.createFromStream(open, str);
try {
open.close();
return createFromStream;
} catch (IOException e2) {
e = e2;
e.printStackTrace();
return createFromStream;
}
} catch (IOException e3) {
IOException iOException = e3;
createFromStream = null;
e = iOException;
e.printStackTrace();
return createFromStream;
}
}
示例6: RecyclerViewItemDecoration
import android.graphics.NinePatch; //导入依赖的package包/类
public RecyclerViewItemDecoration(int recyclerviewMode, Context context, int drawableRid) {
this.recyclerviewMode = recyclerviewMode;
this.drawableRid = drawableRid;
this.bmp = BitmapFactory.decodeResource(context.getResources(), drawableRid);
if (bmp.getNinePatchChunk() != null) {
hasNinePatch = true;
ninePatch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
}
initPaint();
}
示例7: a
import android.graphics.NinePatch; //导入依赖的package包/类
private Drawable a(String str, Context context) {
IOException e;
Drawable createFromStream;
try {
InputStream open = context.getApplicationContext().getAssets().open(str);
if (open == null) {
return null;
}
if (str.endsWith(".9.png")) {
Bitmap decodeStream = BitmapFactory.decodeStream(open);
if (decodeStream == null) {
return null;
}
byte[] ninePatchChunk = decodeStream.getNinePatchChunk();
NinePatch.isNinePatchChunk(ninePatchChunk);
return new NinePatchDrawable(decodeStream, ninePatchChunk, new Rect(), null);
}
createFromStream = Drawable.createFromStream(open, str);
try {
open.close();
return createFromStream;
} catch (IOException e2) {
e = e2;
e.printStackTrace();
return createFromStream;
}
} catch (IOException e3) {
IOException iOException = e3;
createFromStream = null;
e = iOException;
e.printStackTrace();
return createFromStream;
}
}
示例8: type
import android.graphics.NinePatch; //导入依赖的package包/类
public static SubjectFactory<NinePatchSubject, NinePatch> type() {
return new SubjectFactory<NinePatchSubject, NinePatch>() {
@Override
public NinePatchSubject getSubject(FailureStrategy fs, NinePatch that) {
return new NinePatchSubject(fs, that);
}
};
}
示例9: createNinePatchDrawable
import android.graphics.NinePatch; //导入依赖的package包/类
public static NinePatchDrawable createNinePatchDrawable(Bitmap bitmap,Resources res)
{
byte[] chunk = bitmap.getNinePatchChunk();
boolean result = NinePatch.isNinePatchChunk(chunk);
if (!result) throw new ItsNatDroidException("Expected a 9 patch png, put a valid 9 patch in /res/drawable folder, generate the .apk (/build/outputs/apk in Android Studio), decompress as a zip and copy the png file");
return new NinePatchDrawable(res, bitmap, chunk, new Rect(), "XML 9 patch");
}
示例10: createDrawablesByImages
import android.graphics.NinePatch; //导入依赖的package包/类
public static Drawable[] createDrawablesByImages(Resources res, Bitmap[] bitmaps) {
Drawable[] drawables = new Drawable[bitmaps.length];
for (int i = 0; i < bitmaps.length; i++) {
byte[] chunk = bitmaps[i].getNinePatchChunk();
boolean result = NinePatch.isNinePatchChunk(chunk);
if (result) {
drawables[i] = new NinePatchDrawable(res, bitmaps[i], chunk, new Rect(), null);
} else {
drawables[i] = new BitmapDrawable(res, bitmaps[i]);
}
}
return drawables;
}
示例11: createFromResourceStream
import android.graphics.NinePatch; //导入依赖的package包/类
@Implementation // todo: this sucks, it's all just so we can detect 9-patches
public static Drawable createFromResourceStream(Resources res, TypedValue value,
InputStream is, String srcName, BitmapFactory.Options opts) {
if (is == null) {
return null;
}
Rect pad = new Rect();
if (opts == null) opts = new BitmapFactory.Options();
opts.inScreenDensity = DisplayMetrics.DENSITY_DEFAULT;
Bitmap bm = BitmapFactory.decodeResourceStream(res, value, is, pad, opts);
if (bm != null) {
boolean isNinePatch = srcName != null && srcName.contains(".9.");
if (isNinePatch) {
method("setNinePatchChunk").withParameterTypes(byte[].class).in(bm).invoke(new byte[0]);
}
byte[] np = bm.getNinePatchChunk();
if (np == null || !NinePatch.isNinePatchChunk(np)) {
np = null;
pad = null;
}
int[] layoutBounds = method("getLayoutBounds").withReturnType(int[].class).in(bm).invoke();
Rect layoutBoundsRect = null;
if (layoutBounds != null) {
layoutBoundsRect = new Rect(layoutBounds[0], layoutBounds[1],
layoutBounds[2], layoutBounds[3]);
}
if (np != null) {
// todo: wrong
return new NinePatchDrawable(res, bm, np, pad, /*layoutBoundsRect,*/ srcName);
}
return new BitmapDrawable(res, bm);
}
return null;
}
示例12: createNinePatch
import android.graphics.NinePatch; //导入依赖的package包/类
public static NinePatchDrawable createNinePatch(Resources res, Bitmap bitmap, PXOffsets insets,
String srcName) {
byte[] chunk = createNinePatchChunk(insets);
NinePatchDrawable drawable = new NinePatchDrawable(res, new NinePatch(bitmap, chunk,
srcName));
return drawable;
}
示例13: onCreate
import android.graphics.NinePatch; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res = getResources();
// Bitmap from runtime creation (Not compiled)
Bitmap run_bmp = createSampleBitmap();
((ImageView)findViewById(R.id.run_org)).setImageBitmap(run_bmp);
findViewById(R.id.run_bd).setBackgroundDrawable(
new BitmapDrawable(res, run_bmp));
findViewById(R.id.run_nd).setBackgroundDrawable(
NinePatchDrawableFactory.convertBitmap(res, run_bmp, null));
// Bitmap from resource (Compiled)
Bitmap res_bmp = BitmapFactory.decodeResource(res, R.drawable.sample);
((ImageView)findViewById(R.id.res_org)).setImageBitmap(res_bmp);
findViewById(R.id.res_bd).setBackgroundDrawable(
new BitmapDrawable(res, res_bmp));
findViewById(R.id.res_nd).setBackgroundDrawable(
new NinePatchDrawable(res,
new NinePatch(res_bmp, res_bmp.getNinePatchChunk(), null)));
findViewById(R.id.res_nd_pad).setBackgroundDrawable(
NinePatchDrawableFactory.convertBitmap(res, res_bmp, null));
findViewById(R.id.res_nd_rid).setBackgroundResource(R.drawable.sample);
}
示例14: ArtworkFactory
import android.graphics.NinePatch; //导入依赖的package包/类
public ArtworkFactory( Context context, int width, int height) {
mContext = context;
mRes = mContext.getResources();
mContentResolver = context.getContentResolver();
mLayoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mWidth = width;
mHeight = height;
mContentLabelFontsize = mRes.getDimension(R.dimen.ContentLabel_fontsize);
mBitmapOptions = new BitmapFactory.Options();
// RGB565 is OK for the artwork, 888 will be needed only when we add the shadow
// Also no need for dithering. OpenGL will do a good job at displaying it without.
//TODO: check if using ARGB888 is not faster since it will be converted after anyway
mBitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;
mBitmapOptions.inDither = ARTWORK_BITMAP_DITHERING;
mBitmapOptions.inSampleSize = 1; // no sub-sampling
mBitmapOptions.inJustDecodeBounds = false;
// Prepare a painter and enable filtering if showing large bitmaps to avoid ugly rendering of the rescaled bitmap
mPaint = new Paint();
mPaint.setFilterBitmap(ARTWORK_BITMAP_FILTERING);
mPaint.setDither(ARTWORK_BITMAP_DITHERING);
// ======== Now prepare the shadow stuff =========
// Create the destination bitmap and associate a canvas to it
// Require ARGB for the shadow effect
mShadowBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888 );
mShadowBitmap.eraseColor(Color.TRANSPARENT);
mCanvas = new Canvas(mShadowBitmap);
// Decode the shadow bitmap
int shadowId = ArchosFeatures.isAndroidTV(mContext)|| ArchosFeatures.isLUDO()?R.drawable.cover_shadow_512:(mWidth==128) ? R.drawable.cover_shadow_128 : R.drawable.cover_shadow_256;
InputStream is = context.getResources().openRawResource(shadowId);
mShadow9patchPadding = new Rect();
// We must use this version of "decode" in order to get the nine-patch padding
Bitmap shadowNinePatchBitmap = BitmapFactory.decodeStream(is, mShadow9patchPadding, null);
try {
is.close();
} catch (IOException e) {}
mShadow9patch = new NinePatch(shadowNinePatchBitmap, shadowNinePatchBitmap.getNinePatchChunk(), null);
}
示例15: createNinePatch
import android.graphics.NinePatch; //导入依赖的package包/类
public static NinePatch createNinePatch(Resources res, Bitmap bitmap, int top, int left, int bottom, int right, String srcName) {
ByteBuffer buffer = getByteBuffer(top, left, bottom, right);
NinePatch patch = new NinePatch(bitmap, buffer.array(), srcName);
return patch;
}