当前位置: 首页>>代码示例>>Java>>正文


Java NinePatch类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:jmarranz,项目名称:itsnat_droid,代码行数:20,代码来源:BitmapDrawableUtil.java

示例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());

}
 
开发者ID:jmarranz,项目名称:itsnat_droid,代码行数:18,代码来源:Assert.java

示例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);
    }
 
开发者ID:arjinmc,项目名称:RecyclerViewDecoration,代码行数:22,代码来源:RecyclerViewItemDecoration.java

示例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();

    }
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:41,代码来源:RecyclerViewItemDecoration.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:35,代码来源:AuthAgent.java

示例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();

}
 
开发者ID:arjinmc,项目名称:AndroidButtonLib,代码行数:13,代码来源:RecyclerViewItemDecoration.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:35,代码来源:AuthAgent.java

示例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);
    }
  };
}
 
开发者ID:pkware,项目名称:truth-android,代码行数:9,代码来源:NinePatchSubject.java

示例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");
}
 
开发者ID:jmarranz,项目名称:itsnat_droid,代码行数:9,代码来源:BitmapDrawableUtil.java

示例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;
}
 
开发者ID:cdkd321,项目名称:pure,代码行数:14,代码来源:MaterialUtils.java

示例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;
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:38,代码来源:ShadowDrawable.java

示例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;
}
 
开发者ID:Pixate,项目名称:pixate-freestyle-android,代码行数:9,代码来源:NinePatchUtil.java

示例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);
}
 
开发者ID:MorihiroSoft,项目名称:Android_NinePatchDrawableFactory,代码行数:31,代码来源:MainActivity.java

示例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);
	}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:47,代码来源:ArtworkFactory.java

示例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;
}
 
开发者ID:ROKOLabs,项目名称:ROKO.Stickers-Android,代码行数:6,代码来源:NinePatchBitmapFactory.java


注:本文中的android.graphics.NinePatch类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。