Java Code Examples for android.graphics.drawable.NinePatchDrawable#setBounds()

The following examples show how to use android.graphics.drawable.NinePatchDrawable#setBounds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LineView.java    From SimplePomodoro-android with MIT License 6 votes vote down vote up
/**
 *
 * @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);
}
 
Example 2
Source File: LineView.java    From AndroidCharts with MIT License 6 votes vote down vote up
/**
 * @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);
}
 
Example 3
Source File: ShadowLinearLayout.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 4
Source File: ShadowLinearLayout.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 5
Source File: MaterialShadowContainerView.java    From android-materialshadowninepatch with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: ShadowLinearLayout.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 7
Source File: BarGraphRenderer.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
/**
 * 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);
	}			
 }
}