本文整理匯總了Java中android.graphics.drawable.NinePatchDrawable.setBounds方法的典型用法代碼示例。如果您正苦於以下問題:Java NinePatchDrawable.setBounds方法的具體用法?Java NinePatchDrawable.setBounds怎麽用?Java NinePatchDrawable.setBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.NinePatchDrawable
的用法示例。
在下文中一共展示了NinePatchDrawable.setBounds方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: addDummyBoundaryPatch
import android.graphics.drawable.NinePatchDrawable; //導入方法依賴的package包/類
/**
* Add boundary patch for external Dummy input.
*
* @param xTo Horizontal coordinate to which the patch should extend. The starting coordinate
* is determined from this by subtracting patch width.
* @param inputView The {@link InputView} for the current input. This is used to determine patch
* height.
* @param inputLayoutOrigin The layout origin for the current input. This is used to determine
* the vertical position for the patch.
*/
private void addDummyBoundaryPatch(boolean isShadow, int xTo, InputView inputView,
ViewPoint inputLayoutOrigin) {
// For external dummy inputs, put a patch for the block boundary.
final NinePatchDrawable inputDrawable = getColoredPatchDrawable(
isShadow ? R.drawable.dummy_input_shadow : R.drawable.dummy_input);
final NinePatchDrawable inputBorderDrawable =
mPatchManager.getPatchDrawable(R.drawable.dummy_input_border);
int width = inputDrawable.getIntrinsicWidth();
if (mHasValueInput) {
// Stretch the patch horizontally if this block has at least one value
// input, so that the dummy input block boundary is as thick as the
// boundary with value input connector.
width += mPatchManager.mValueInputWidth;
}
boolean inTopRow = (inputLayoutOrigin.y == 0);
mHelper.setRtlAwareBounds(tempRect,
/* this width */ mBlockViewSize.x,
/* LTR start */ xTo - width,
/* top */ inputLayoutOrigin.y + (inTopRow ? mBlockTopPadding : 0),
/* LTR end */ xTo,
/* bottom */ inputLayoutOrigin.y + inputView.getRowHeight());
inputDrawable.setBounds(tempRect);
inputBorderDrawable.setBounds(tempRect);
mBlockPatches.add(inputDrawable);
mBlockBorderPatches.add(inputBorderDrawable);
}
示例7: updateShadowBounds
import android.graphics.drawable.NinePatchDrawable; //導入方法依賴的package包/類
private void updateShadowBounds() {
NinePatchDrawable shadow = mShadow;
if (shadow == null) {
return;
}
int width = getWidth();
int height = getHeight();
Rect paddings = mShadowPaddings;
if (width != 0 && height != 0) {
shadow.setBounds(-paddings.left, -paddings.top, width + paddings.right, height + paddings.bottom);
}
}
示例8: updateNinePatchBounds
import android.graphics.drawable.NinePatchDrawable; //導入方法依賴的package包/類
private void updateNinePatchBounds(NinePatchDrawable ninePatch, int childLeft, int childTop, int childRight, int childBottom) {
if (ninePatch == null) {
return;
}
final Rect t = mTempRect;
ninePatch.getPadding(t);
ninePatch.setBounds(
childLeft - t.left, childTop - t.top,
childRight + t.right, childBottom + t.bottom);
}
示例9: 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;
}
示例10: 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));
}
示例11: addTopLeftPatch
import android.graphics.drawable.NinePatchDrawable; //導入方法依賴的package包/類
/**
* Add the top-left corner drawable.
*
* @param xTo Horizontal end position for the drawable.
* @param yTop Vertical position for the drawable.
*
* @return The added drawable. This can be used to position other drawables, e.g., the
* bottom-left drawable, relative to it.
*/
@NonNull
private NinePatchDrawable addTopLeftPatch(boolean isShadow, int xTo, int yTop) {
// Select and position the correct patch for the top and left block sides including the
// top-left corner.
NinePatchDrawable topStartDrawable;
NinePatchDrawable topStartBorderDrawable;
if (mBlock.getPreviousConnection() != null) {
mHelper.setPointMaybeFlip(mPreviousConnectorOffset, mOutputConnectorMargin, yTop);
topStartDrawable = getColoredPatchDrawable(isShadow
? R.drawable.top_start_previous_shadow : R.drawable.top_start_previous);
topStartBorderDrawable =
mPatchManager.getPatchDrawable(R.drawable.top_start_previous_border);
mPreviousConnectorHighlightPatch =
mPatchManager.getPatchDrawable(R.drawable.top_start_previous_connection);
} else if (mBlock.getOutputConnection() != null) {
mHelper.setPointMaybeFlip(mOutputConnectorOffset, mOutputConnectorMargin, yTop);
topStartDrawable = getColoredPatchDrawable(
isShadow ? R.drawable.top_start_output_shadow : R.drawable.top_start_output);
topStartBorderDrawable =
mPatchManager.getPatchDrawable(R.drawable.top_start_output_border);
mOutputConnectorHighlightPatch =
mPatchManager.getPatchDrawable(R.drawable.top_start_output_connection);
} else if (mUseHat) {
topStartDrawable = getColoredPatchDrawable(
isShadow ? R.drawable.top_start_hat_shadow : R.drawable.top_start_hat);
topStartBorderDrawable =
mPatchManager.getPatchDrawable(R.drawable.top_start_hat_border);
} else {
topStartDrawable = getColoredPatchDrawable(
isShadow ? R.drawable.top_start_default_shadow : R.drawable.top_start_default);
topStartBorderDrawable =
mPatchManager.getPatchDrawable(R.drawable.top_start_default_border);
}
mHelper.setRtlAwareBounds(tempRect,
/* this width */ mBlockViewSize.x,
/* LTR start */ 0,
/* top */ 0,
/* LTR end */ xTo,
/* bottom */ topStartDrawable.getIntrinsicHeight());
topStartDrawable.setBounds(tempRect);
topStartBorderDrawable.setBounds(tempRect);
if (mPreviousConnectorHighlightPatch != null) {
mPreviousConnectorHighlightPatch.setBounds(tempRect);
}
if (mOutputConnectorHighlightPatch != null) {
mOutputConnectorHighlightPatch.setBounds(tempRect);
}
mBlockPatches.add(topStartDrawable);
mBlockBorderPatches.add(topStartBorderDrawable);
return topStartDrawable;
}
示例12: addExternalValueInputPatch
import android.graphics.drawable.NinePatchDrawable; //導入方法依賴的package包/類
/**
* Add connector patch for external Value inputs.
*
* @param i The index of the current input. This is used to determine whether to position patch
* vertically below the field top boundary to account for the block's top boundary.
* @param xTo Horizontal coordinate to which the patch should extend. The starting coordinate
* is determined from this by subtracting patch width.
* @param inputView The {@link InputView} for the current input. This is used to determine patch
* height.
* @param inputLayoutOrigin The layout origin for the current input. This is used to determine
* the vertical position for the patch.
*/
private void addExternalValueInputPatch(boolean isShadow, int i, int xTo,
InputView inputView, ViewPoint inputLayoutOrigin) {
// Position patch and connector for external value input.
mHelper.setPointMaybeFlip(mInputConnectorOffsets.get(i), xTo, inputLayoutOrigin.y);
final NinePatchDrawable inputDrawable = getColoredPatchDrawable(isShadow
? R.drawable.value_input_external_shadow : R.drawable.value_input_external);
final NinePatchDrawable inputBorderDrawable =
mPatchManager.getPatchDrawable(R.drawable.value_input_external_border);
final NinePatchDrawable connectionHighlightDrawable =
mPatchManager.getPatchDrawable(R.drawable.value_input_external_connection);
int patchLeft = xTo - inputDrawable.getIntrinsicWidth();
int patchRight = xTo;
int connectorTop = inputLayoutOrigin.y + mBlockTopPadding;
int connectorBottom = inputLayoutOrigin.y + inputView.getMeasuredHeight();
mHelper.setRtlAwareBounds(tempRect,
/* this width */ mBlockViewSize.x,
/* LTR start */ patchLeft,
/* top */ connectorTop,
/* LTR end */ patchRight,
/* bottom */ connectorBottom);
inputDrawable.setBounds(tempRect);
inputBorderDrawable.setBounds(tempRect);
connectionHighlightDrawable.setBounds(tempRect);
mBlockPatches.add(inputDrawable);
mBlockBorderPatches.add(inputBorderDrawable);
mInputConnectionHighlightPatches.set(i, connectionHighlightDrawable);
if (i > 0) {
// If this is not the first input in the block, then a gap above the
// input connector patch must be closed by a non-input boundary patch.
// The gap is the result of the need to not draw over the top block
// boundary.
final NinePatchDrawable boundaryGapDrawable =
getColoredPatchDrawable(R.drawable.dummy_input);
final NinePatchDrawable boundaryGapBorderDrawable =
mPatchManager.getPatchDrawable(R.drawable.dummy_input_border);
mHelper.setRtlAwareBounds(tempRect,
/* this width */ mBlockViewSize.x,
/* LTR start */ patchLeft,
/* top */ inputLayoutOrigin.y,
/* LTR end */patchRight,
/* bottom */ connectorTop);
boundaryGapDrawable.setBounds(tempRect);
boundaryGapBorderDrawable.setBounds(tempRect);
mBlockPatches.add(boundaryGapDrawable);
mBlockBorderPatches.add(boundaryGapBorderDrawable);
}
}
示例13: addStatementInputPatches
import android.graphics.drawable.NinePatchDrawable; //導入方法依賴的package包/類
/**
* Add patches (top and bottom) for a Statement input connector.
*
* @param i Index of the input.
* @param xFrom Horizontal offset of block content.
* @param xToAbove Horizontal end coordinate for connector above input.
* @param xToBelow Horizontal end coordinate for connector below input.
* @param inputView The view for this input.
* @param inputLayoutOrigin Layout origin for this input.
*/
private void addStatementInputPatches(boolean isShadow, int i,
int xFrom, int xToAbove, int xToBelow,
InputView inputView, ViewPoint inputLayoutOrigin) {
// Position connector. Shift by horizontal and vertical patch thickness to line up with
// "Previous" connector on child block.
int xOffset = xFrom + inputView.getFieldLayoutWidth();
mHelper.setPointMaybeFlip(mInputConnectorOffsets.get(i),
xOffset + mPatchManager.mStatementInputPadding,
inputLayoutOrigin.y + mPatchManager.mStatementTopThickness);
// Position patch for the top part of the Statement connector. This patch is
// stretched only horizontally to extend to the block boundary.
final NinePatchDrawable statementTopDrawable = getColoredPatchDrawable(
isShadow ? R.drawable.statementinput_top_shadow : R.drawable.statementinput_top);
final NinePatchDrawable statementTopBorderDrawable =
mPatchManager.getPatchDrawable(R.drawable.statementinput_top_border);
final NinePatchDrawable statementConnectionHighlight =
mPatchManager.getPatchDrawable(R.drawable.statementinput_top_connection);
mHelper.setRtlAwareBounds(tempRect,
/* this width */ mBlockViewSize.x,
/* LTR start */ xOffset,
/* top */ inputLayoutOrigin.y,
/* LTR end */ xToAbove,
/* bottom */ inputLayoutOrigin.y + statementTopDrawable.getIntrinsicHeight());
statementTopDrawable.setBounds(tempRect);
statementTopBorderDrawable.setBounds(tempRect);
statementConnectionHighlight.setBounds(tempRect);
mBlockPatches.add(statementTopDrawable);
mBlockBorderPatches.add(statementTopBorderDrawable);
mInputConnectionHighlightPatches.set(i, statementConnectionHighlight);
// Position patch for the bottom part of the Statement connector. The bottom
// patch is stretched horizontally, like the top patch, but also vertically to
// accomodate height of the input fields as well as the size of any connected
// blocks.
final NinePatchDrawable statementBottomDrawable = getColoredPatchDrawable(isShadow ?
R.drawable.statementinput_bottom_shadow : R.drawable.statementinput_bottom);
final NinePatchDrawable statementBottomBorderDrawable =
mPatchManager.getPatchDrawable(R.drawable.statementinput_bottom_border);
final int connectorHeight =
Math.max(inputView.getTotalChildHeight(),
inputView.getMeasuredHeight());
mHelper.setRtlAwareBounds(tempRect,
/* this width */ mBlockViewSize.x,
/* LTR start */ xOffset,
/* top */ inputLayoutOrigin.y + statementTopDrawable.getIntrinsicHeight(),
/* LTR end */ xToBelow,
/* bottom */ inputLayoutOrigin.y + connectorHeight);
statementBottomDrawable.setBounds(tempRect);
statementBottomBorderDrawable.setBounds(tempRect);
mBlockPatches.add(statementBottomDrawable);
mBlockBorderPatches.add(statementBottomBorderDrawable);
}
示例14: 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);
}
}
}
示例15: 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;
}