public static Drawable createImageBasedDrawable(byte[] byteArray,int bitmapDensityReference,boolean expectedninePatch,Resources res)
{
if (expectedninePatch)
return createNinePatchDrawable(byteArray,bitmapDensityReference,res);
Bitmap bitmap = BitmapUtil.createBitmap(byteArray,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);
}
}
项目:itsnat_droid
文件:Assert.java
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());
}
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);
}
项目:FriendBook
文件:RecyclerViewItemdecoration.java
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(),null);
}
if (mMode == MODE_HORIZONTAL)
mCurrentThickness = mThickness == 0 ? mBmp.getHeight() : mThickness;
if (mMode == MODE_VERTICAL)
mCurrentThickness = mThickness == 0 ? mBmp.getWidth() : mThickness;
}
initPaint();
}
项目:letv
文件:AuthAgent.java
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;
}
}
项目:letv
文件:TaskGuide.java
private Drawable a(String str,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;
}
}
项目:AndroidButtonLib
文件:RecyclerViewItemdecoration.java
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();
}
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,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;
}
}
项目:truth-android
文件:NinePatchSubject.java
public static SubjectFactory<NinePatchSubject,NinePatch> type() {
return new SubjectFactory<NinePatchSubject,NinePatch>() {
@Override
public NinePatchSubject getSubject(FailureStrategy fs,NinePatch that) {
return new NinePatchSubject(fs,that);
}
};
}
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,"XML 9 patch");
}
项目:pure
文件:MaterialUtils.java
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],null);
} else {
drawables[i] = new BitmapDrawable(res,bitmaps[i]);
}
}
return drawables;
}
项目:FullRobolectricTestSample
文件:ShadowDrawable.java
@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,/*layoutBoundsRect,*/ srcName);
}
return new BitmapDrawable(res,bm);
}
return null;
}
项目:pixate-freestyle-android
文件:NinePatchUtil.java
public static NinePatchDrawable createNinePatch(Resources res,Bitmap bitmap,PXOffsets insets,String srcName) {
byte[] chunk = createNinePatchChunk(insets);
NinePatchDrawable drawable = new NinePatchDrawable(res,new NinePatch(bitmap,srcName));
return drawable;
}
项目:Android_NinePatchDrawableFactory
文件:MainActivity.java
@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);
}
项目:aos-MediaLib
文件:ArtworkFactory.java
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);
}
项目:ROKO.Stickers-Android
文件:NinePatchBitmapFactory.java
项目:Android-Application-ZJB
文件:HomeAdapter.java
private Observable<String> getBubbleDrawable(String imageUrl,Context context) {
return Observable.<String>create(subscriber -> {
if (TextUtils.isEmpty(imageUrl)) {
subscriber.onError(new NullPointerException());
return;
}
//先从内存缓存中获取
NinePatchDrawable drawable = mBubbleMap.get(imageUrl);
if (null != drawable) {
subscriber.onNext("bitmap has cached!");
subscriber.onCompleted();
return;
}
String filePath = ZjbImageLoader.getQiniudiskCachePath(imageUrl);
File imageFile = new File(filePath);
if (imageFile.exists()) {
filePath = imageFile.getAbsolutePath();
Rect rect = new Rect();
Bitmap bm = null;
InputStream stream = null;
try {
stream = new FileInputStream(filePath);
bm = BitmapFactory.decodeStream(stream,rect,null);
byte[] chunk = bm.getNinePatchChunk();
if (NinePatch.isNinePatchChunk(chunk)) {
//如果是合法的NinePatchDrawable
NinePatchDrawable patchDrawable = new NinePatchDrawable(context.getResources(),null);
mBubbleMap.put(imageUrl,patchDrawable);
}
subscriber.onNext("complete!");
subscriber.onCompleted();
} catch (FileNotFoundException e) {
e.printstacktrace();
subscriber.onError(e);
}
} else {
subscriber.onNext("image not download!");
subscriber.onCompleted();
}
}).subscribeOn(Schedulers.io());
}
项目:truth-android
文件:NinePatchSubject.java
protected NinePatchSubject(FailureStrategy failureStrategy,NinePatch subject) {
super(failureStrategy,subject);
}
项目:Chateau
文件:ChatBubbleLayout.java
private NinePatchDrawable createMask(@DrawableRes int res) {
final Bitmap maskBitmap = BitmapFactory.decodeResource(getResources(),res);
final NinePatch patch = new NinePatch(maskBitmap,maskBitmap.getNinePatchChunk(),"BubbleMask");
return new NinePatchDrawable(getResources(),patch);
}
/**
* Attempts to decode 9-patch data from a {@link Bitmap}.
* @param bitmap The {@link Bitmap} to check.
* @return An instance of {@link NinePatchData} representing the 9-patch @R_926_4045@ion
* encoded in {@code bitmap} or {@code null} if the {@link Bitmap} wasn't a
* 9-patch.
*/
public static NinePatchData create(Bitmap bitmap) {
if (bitmap == null) return null;
try {
byte[] chunk = bitmap.getNinePatchChunk();
if (chunk == null || !NinePatch.isNinePatchChunk(chunk)) return null;
ByteBuffer buffer = ByteBuffer.wrap(chunk).order(ByteOrder.nativeOrder());
// int8_t wasDeserialized
if (buffer.get() == 0) return null;
// int8_t numXDivs
int numDivX = buffer.get();
if (numDivX == 0 || (numDivX & 0x01) != 0) return null;
// int8_t numYDivs
int numDivY = buffer.get();
if (numDivY == 0 || (numDivY & 0x01) != 0) return null;
// int8_t numColors
buffer.get();
// uint32_t xDivsOffset
buffer.getInt();
// uint32_t yDivsOffset
buffer.getInt();
Rect padding = new Rect();
// uint32_t paddingLeft
padding.left = buffer.getInt();
// uint32_t paddingRight
padding.right = buffer.getInt();
// uint32_t paddingTop
padding.top = buffer.getInt();
// uint32_t paddingBottom
padding.bottom = buffer.getInt();
// uint32_t colorsOffset
buffer.getInt();
// uint32_t uint32_t uint32_t ...
int[] divX = new int[numDivX];
for (int i = 0; i < numDivX; i++) divX[i] = buffer.getInt();
// uint32_t uint32_t uint32_t ...
int[] divY = new int[numDivY];
for (int i = 0; i < numDivY; i++) divY[i] = buffer.getInt();
return new NinePatchData(bitmap.getWidth(),bitmap.getHeight(),padding,divX,divY);
} catch (BufferUnderflowException ex) {
return null;
}
}
项目:assertj-android
文件:NinePatchAssert.java
public NinePatchAssert(NinePatch actual) {
super(actual,NinePatchAssert.class);
}
项目:xlight_android_native
文件:RangeSeekBar.java
项目:RxTools
文件:RxSeekBar.java
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。