本文整理汇总了Java中android.graphics.drawable.NinePatchDrawable.draw方法的典型用法代码示例。如果您正苦于以下问题:Java NinePatchDrawable.draw方法的具体用法?Java NinePatchDrawable.draw怎么用?Java NinePatchDrawable.draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.NinePatchDrawable
的用法示例。
在下文中一共展示了NinePatchDrawable.draw方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDraggingItemImage
import android.graphics.drawable.NinePatchDrawable; //导入方法依赖的package包/类
private Bitmap createDraggingItemImage(View v, NinePatchDrawable shadow) {
int width = v.getWidth() + mShadowPadding.left + mShadowPadding.right;
int height = v.getHeight() + mShadowPadding.top + mShadowPadding.bottom;
final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
if (shadow != null) {
shadow.setBounds(0, 0, width, height);
shadow.draw(canvas);
}
final int savedCount = canvas.save(Canvas.CLIP_SAVE_FLAG | Canvas.MATRIX_SAVE_FLAG);
// NOTE: Explicitly set clipping rect. This is required on Gingerbread.
canvas.clipRect(mShadowPadding.left, mShadowPadding.top, width - mShadowPadding.right, height - mShadowPadding.bottom);
canvas.translate(mShadowPadding.left, mShadowPadding.top);
v.draw(canvas);
canvas.restoreToCount(savedCount);
return bitmap;
}
开发者ID:fabricethilaw,项目名称:expandable-recyclerview-with-gridlayout,代码行数:23,代码来源:DraggingItemDecorator.java
示例2: drawPopup
import android.graphics.drawable.NinePatchDrawable; //导入方法依赖的package包/类
/**
* @param canvas The canvas you need to draw on.
* @param point The Point consists of the x y coordinates from left bottom to right top.
* Like is
* <p/>
* 3
* 2
* 1
* 0 1 2 3 4 5
*/
private void drawPopup(Canvas canvas, String num, Point point, int PopupColor) {
boolean singularNum = (num.length() == 1);
int sidePadding = ChartUtils.dip2px(getContext(), singularNum ? 8 : 5);
int x = point.x;
int y = point.y - ChartUtils.dip2px(getContext(), 5);
Rect popupTextRect = new Rect();
popupTextPaint.getTextBounds(num, 0, num.length(), popupTextRect);
Rect r = new Rect(x - popupTextRect.width() / 2 - sidePadding,
y - popupTextRect.height() - bottomTriangleHeight - popupTopPadding * 2 - popupBottomMargin,
x + popupTextRect.width() / 2 + sidePadding,
y + popupTopPadding - popupBottomMargin);
NinePatchDrawable popup = (NinePatchDrawable) getResources().getDrawable(PopupColor);
popup.setBounds(r);
popup.draw(canvas);
canvas.drawText(num, x, y - bottomTriangleHeight - popupBottomMargin, popupTextPaint);
}
示例3: drawPopup
import android.graphics.drawable.NinePatchDrawable; //导入方法依赖的package包/类
/**
*
* @param canvas The canvas you need to draw on.
* @param point The Point consists of the x y coordinates from left bottom to right top.
* Like is
*
* 3
* 2
* 1
* 0 1 2 3 4 5
*/
private void drawPopup(Canvas canvas,String num, Point point,int PopupColor){
boolean singularNum = (num.length() == 1);
int sidePadding = MyUtils.dip2px(getContext(),singularNum? 8:5);
int x = point.x;
int y = point.y-MyUtils.dip2px(getContext(),5);
Rect popupTextRect = new Rect();
popupTextPaint.getTextBounds(num,0,num.length(),popupTextRect);
Rect r = new Rect(x-popupTextRect.width()/2-sidePadding,
y - popupTextRect.height()-bottomTriangleHeight-popupTopPadding*2-popupBottomMargin,
x + popupTextRect.width()/2+sidePadding,
y+popupTopPadding-popupBottomMargin);
NinePatchDrawable popup = (NinePatchDrawable)getResources().getDrawable(PopupColor);
popup.setBounds(r);
popup.draw(canvas);
canvas.drawText(num, x, y-bottomTriangleHeight-popupBottomMargin, popupTextPaint);
}
示例4: drawPopup
import android.graphics.drawable.NinePatchDrawable; //导入方法依赖的package包/类
/**
*
* @param canvas The canvas you need to draw on.
* @param point The Point consists of the x y coordinates from left bottom to right top.
* Like is ↓
* 3
* 2
* 1
* 0 1 2 3 4 5
*/
private void drawPopup(Canvas canvas,String num, Point point){
boolean singularNum = (num.length() == 1);
int sidePadding = MyUtils.dip2px(getContext(),singularNum? 8:5);
int x = point.x;
int y = point.y-MyUtils.dip2px(getContext(),5);
Rect popupTextRect = new Rect();
popupTextPaint.getTextBounds(num,0,num.length(),popupTextRect);
Rect r = new Rect(x-popupTextRect.width()/2-sidePadding,
y - popupTextRect.height()-bottomTriangleHeight-popupTopPadding*2-popupBottomMargin,
x + popupTextRect.width()/2+sidePadding,
y+popupTopPadding-popupBottomMargin);
NinePatchDrawable popup = (NinePatchDrawable)getResources().
getDrawable(R.drawable.popup_red);
popup.setBounds(r);
popup.draw(canvas);
canvas.drawText(num, x, y-bottomTriangleHeight-popupBottomMargin, popupTextPaint);
}
示例5: drawPopup
import android.graphics.drawable.NinePatchDrawable; //导入方法依赖的package包/类
/**
* @param canvas The canvas you need to draw on.
* @param point The Point consists of the x y coordinates from left bottom to right top.
* Like is
*
* 3
* 2
* 1
* 0 1 2 3 4 5
*/
private void drawPopup(Canvas canvas, float num, Point point, int PopupColor) {
String numStr = showFloatNumInPopup ? String.valueOf(num) : String.valueOf(Math.round(num));
boolean singularNum = (numStr.length() == 1);
int sidePadding = MyUtils.dip2px(getContext(), singularNum ? 8 : 5);
int x = point.x;
int y = point.y - MyUtils.dip2px(getContext(), 5);
Rect popupTextRect = new Rect();
popupTextPaint.getTextBounds(numStr, 0, numStr.length(), popupTextRect);
Rect r = new Rect(x - popupTextRect.width() / 2 - sidePadding, y
- popupTextRect.height()
- bottomTriangleHeight
- popupTopPadding * 2
- popupBottomMargin, x + popupTextRect.width() / 2 + sidePadding,
y + popupTopPadding - popupBottomMargin + popupBottomPadding);
NinePatchDrawable popup =
(NinePatchDrawable) getResources().getDrawable(R.drawable.popup_white);
popup.setColorFilter(new PorterDuffColorFilter(PopupColor, PorterDuff.Mode.MULTIPLY));
popup.setBounds(r);
popup.draw(canvas);
canvas.drawText(numStr, x, y - bottomTriangleHeight - popupBottomMargin, popupTextPaint);
}
示例6: onDraw
import android.graphics.drawable.NinePatchDrawable; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
try {
// get the original bitmap drawable
BitmapDrawable drawable = (BitmapDrawable) getDrawable();
if (drawable == null || getWidth() == 0 || getHeight() == 0) {
return;
}
Bitmap fullSizeBitmap = drawable.getBitmap();
int height = fullSizeBitmap.getHeight();
int width = fullSizeBitmap.getWidth();
Canvas canvasT = getDrawnCanvas(width, height, fullSizeBitmap);
// Draw this bitmap to the image view
canvas.drawBitmap(fullSizeBitmap, 0, 0, null);
NinePatchDrawable nicepatchDrawable = getCachedNinePatchDrawable(width, height);
// Draw the NinePatchDrawable to a new output_bitmap
Bitmap output_bitmap = getCachedBitmap(width, height);
canvasT = getCachedCanvas(width, height);
nicepatchDrawable.draw(canvasT);
// Draw the output_bitmap to image view
canvas.drawBitmap(output_bitmap, 0, 0, null);
} catch (OutOfMemoryError e) {
if (greendroid.util.Config.GD_ERROR_LOGS_ENABLED)
Log.e("RetangleImageView", e.getMessage());
}
}
示例7: getNinepatchBitmap
import android.graphics.drawable.NinePatchDrawable; //导入方法依赖的package包/类
public static Bitmap getNinepatchBitmap(int id, int x, int y, Context context) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), id);
byte[] chunk = bitmap.getNinePatchChunk();
NinePatchDrawable np_drawable = new NinePatchDrawable(context.getResources(), bitmap, chunk, new Rect(), null);
np_drawable.setBounds(0, 0, x, y);
Bitmap output_bitmap = Bitmap.createBitmap(x, y, Config.ARGB_8888);
Canvas canvas = new Canvas(output_bitmap);
np_drawable.draw(canvas);
return output_bitmap;
}
示例8: build
import android.graphics.drawable.NinePatchDrawable; //导入方法依赖的package包/类
private void build() {
NinePatchDrawable drawable = (NinePatchDrawable) Core.context.getResources().getDrawable(bgResId);
drawable.setBounds(0, 0, (int)w, (int)h);
Bitmap bgBitmap = Bitmap.createBitmap((int)w, (int)h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bgBitmap);
drawable.draw(canvas);
setTextureHandle(BitmapUtils.loadBitmap(bgBitmap, textureHandle));
}
示例9: onRender
import android.graphics.drawable.NinePatchDrawable; //导入方法依赖的package包/类
/**
* Renders a 14 line bar graph/ histogram of the FFT data
*/
@Override
public void onRender(Canvas canvas, FFTData data, Rect rect)
{
//space between lines of graph
float space = 4f;
Resources resources = mContext.getResources();
NinePatchDrawable bg = (NinePatchDrawable) resources.getDrawable(R.drawable.music_bar_graph);
DisplayMetrics metrics = resources.getDisplayMetrics();
//margin from left/right edges
int margin = (int) ( ( 16 * (metrics.densityDpi/160f) ) + 0.5f );
//Calculate width of each bar
float bar_width = ( ( rect.width() - ((13 * space) + (margin * 2)) ) / 14 );
//calculate length between the start of each bar
float next_start = bar_width + space;
for (int i = 0; i < 14; i++) {
//set x start of bar
float x1 = margin + (i * next_start);
//calculate height of bar based on sampling 4 data points
byte rfk = data.bytes[ (10 * i)];
byte ifk = data.bytes[ (10 * i + 1)];
float magnitude = (rfk * rfk + ifk * ifk);
int dbValue = (int) (10 * Math.log10(magnitude));
rfk = data.bytes[ (10 * i + 2)];
ifk = data.bytes[ (10 * i + 3)];
magnitude = (rfk * rfk + ifk * ifk);
dbValue = (int) ( (10 * Math.log10(magnitude)) + dbValue) / 2;
//Average with previous bars value(reduce spikes / smoother transitions)
dbValue =( mData[i] + ((dbValue < 0) ? 0 : dbValue) ) / 2;
mData[i] = dbValue;
//only jump height on multiples of 5
if(dbValue >= 5)
dbValue = (int) Math.floor(dbValue/5) * 5;
//bottom edge of canvas
float y1 = rect.height();
int blockHeight = 10;
int numBlocks = (int) Math.floor((dbValue * 8) / blockHeight);
//cycle through and render individual blocks
for( int j = 0; j < numBlocks; j++ ){
int yEnd = (int)( y1 - ( blockHeight * j ));
Rect nRect = new Rect((int)x1, yEnd - blockHeight, (int)(x1+bar_width), yEnd);
bg.setBounds(nRect);
bg.draw(canvas);
}
}
}
示例10: toRoundCorner
import android.graphics.drawable.NinePatchDrawable; //导入方法依赖的package包/类
public static Bitmap toRoundCorner(Context context, Bitmap src, Bitmap dst) {
NinePatchDrawable nine = (NinePatchDrawable) context.getResources().getDrawable(R.drawable.gotye_bg_msg_text_normal_right);
nine.setBounds(0, 0, src.getWidth(), src.getHeight());
Bitmap output = Bitmap.createBitmap(src.getWidth(),
src.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
nine.draw(canvas);
Paint paint = new Paint();
paint.setAntiAlias(true);
canvas.drawBitmap(dst, 0, 0, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.MULTIPLY));
canvas.drawBitmap(src, 0, 0, paint);
return output;
}
示例11: onRender
import android.graphics.drawable.NinePatchDrawable; //导入方法依赖的package包/类
/**
* Renders a 14 line bar graph/ histogram of the FFT data
*/
@Override
public void onRender(Canvas canvas, FFTData data, Rect rect)
{
//space between lines of graph
float space = 4f;
Resources resources = mContext.getResources();
NinePatchDrawable bg = (NinePatchDrawable) resources.getDrawable(R.drawable.bar_graph);
DisplayMetrics metrics = resources.getDisplayMetrics();
//margin from left/right edges
int margin = (int) ( ( 16 * (metrics.densityDpi/160f) ) + 0.5f );
//Calculate width of each bar
float bar_width = ( ( rect.width() - ((13 * space) + (margin * 2)) ) / 14 );
//calculate length between the start of each bar
float next_start = bar_width + space;
for (int i = 0; i < 14; i++) {
//set x start of bar
float x1 = margin + (i * next_start);
//calculate height of bar based on sampling 4 data points
byte rfk = data.bytes[ (10 * i)];
byte ifk = data.bytes[ (10 * i + 1)];
float magnitude = (rfk * rfk + ifk * ifk);
int dbValue = (int) (10 * Math.log10(magnitude));
rfk = data.bytes[ (10 * i + 2)];
ifk = data.bytes[ (10 * i + 3)];
magnitude = (rfk * rfk + ifk * ifk);
dbValue = (int) ( (10 * Math.log10(magnitude)) + dbValue) / 2;
//Average with previous bars value(reduce spikes / smoother transitions)
dbValue =( mData[i] + ((dbValue < 0) ? 0 : dbValue) ) / 2;
mData[i] = dbValue;
//only jump height on multiples of 5
if(dbValue >= 5)
dbValue = (int) Math.floor(dbValue/5) * 5;
//bottom edge of canvas
float y1 = rect.height();
int blockHeight = 10;
int numBlocks = (int) Math.floor((dbValue * 8) / blockHeight);
//cycle through and render individual blocks
for( int j = 0; j < numBlocks; j++ ){
int yEnd = (int)( y1 - ( blockHeight * j ));
Rect nRect = new Rect((int)x1, yEnd - blockHeight, (int)(x1+bar_width), yEnd);
bg.setBounds(nRect);
bg.draw(canvas);
}
}
}