當前位置: 首頁>>代碼示例>>Java>>正文


Java NinePatchDrawable.draw方法代碼示例

本文整理匯總了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);
}
 
開發者ID:souliss,項目名稱:soulissapp,代碼行數:28,代碼來源:LineView.java

示例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);
}
 
開發者ID:tomazsh,項目名稱:character-lab-android-app,代碼行數:29,代碼來源:LineView.java

示例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);
}
 
開發者ID:dacer,項目名稱:SimplePomodoro-android,代碼行數:29,代碼來源:LineView.java

示例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);
}
 
開發者ID:HackPlan,項目名稱:AndroidCharts,代碼行數:33,代碼來源:LineView.java

示例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());
  }
}
 
開發者ID:paristote,項目名稱:mobile-android-studio,代碼行數:35,代碼來源:RetangleImageView.java

示例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;
}
 
開發者ID:muyuballs,項目名稱:FxExplorer,代碼行數:11,代碼來源:ImageUtility.java

示例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));
}
 
開發者ID:idunnololz,項目名稱:DivisionByZero,代碼行數:10,代碼來源:BaseDialog.java

示例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);
	}			
 }
}
 
開發者ID:hubcarl,項目名稱:mobile-manager-tool,代碼行數:56,代碼來源:BarGraphRenderer.java

示例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;
}
 
開發者ID:Gotye-QPlus,項目名稱:GotyeSDK-Android,代碼行數:22,代碼來源:MainActivity.java

示例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);
	}			
 }
}
 
開發者ID:cpoopc,項目名稱:com.cp.monsterMod,代碼行數:56,代碼來源:BarGraphRenderer.java


注:本文中的android.graphics.drawable.NinePatchDrawable.draw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。