List of usage examples for android.graphics Path close
public void close()
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw a spade//from ww w .j av a 2s . c o m * @param canvas canvas to draw on * @param width width of the spade * @param height height of the spade */ public void drawSpade(final Canvas canvas, final float width, final float height) { final Paint paint = getBlackPaint(); final float width_half = width / 2; final float width_quarter = width / 4; final float width_fifth = width / 5; final float width_25th = width / 25; final float height_3_5th = height / 5 * 3; final Path path = new Path(); path.moveTo(width_half, 0); path.lineTo(width - width_25th, height_3_5th); path.lineTo(width_25th, height_3_5th); path.lineTo(width_half, 0); path.close(); canvas.drawPath(path, paint); canvas.drawCircle(width_quarter, height_3_5th, width_fifth, paint); canvas.drawCircle(width_quarter * 3, height_3_5th, width_fifth, paint); drawPedestal(canvas, width, height); }
From source file:com.hobby.uiframework.widget.PagerSlidingTab.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from w w w . j av a 2 s .c o m*/ } final int height = getHeight(); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates // between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } if (lineIndicator) { canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); } else { rectPaint.setStyle(Style.FILL); Path path = new Path(); float mid = (lineLeft + lineRight) * 0.5f; float triangleheight = getContext().getResources().getDimension(R.dimen.indicator_triangle_height); float left = mid - triangleheight; float right = mid + triangleheight; path.moveTo(left, height); path.lineTo(mid, height - triangleheight); path.lineTo(right, height); path.close(); canvas.drawPath(path, rectPaint); } // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw a pedestal ( clubs and spades stand on this ) * @param canvas canvas to draw on/*w w w . j a va 2 s .c om*/ * @param width width of the pedestal * @param height height of the pedestal */ public void drawPedestal(final Canvas canvas, final float width, final float height) { final Paint paint = getBlackPaint(); final float width_half = width / 2; final float width_fifth = width / 5; final float width_3_5ths = width_fifth * 3; final float height_5th = height / 5; canvas.drawRect(width_3_5ths, height_5th, width - width_3_5ths, height, paint); final Path path = new Path(); path.moveTo(width_fifth, height); path.lineTo(width_half, height - height_5th); path.lineTo(width - width_fifth, height); path.lineTo(width_fifth, height); path.close(); canvas.drawPath(path, paint); }
From source file:com.morninz.ninepinview.widget.NinePINView.java
/** * Compute the coordinates of 9 center points and wrong triangles. *///from w w w . j a v a 2s . co m protected void computePointsAndWrongTriangleCoordinate() { int drawWidth = getWidth() - getPaddingLeft() - getPaddingRight(); int drawHeight = getHeight() - getPaddingTop() - getPaddingBottom(); float baseX = getPaddingLeft() + mCircleRadius; float baseY = getPaddingTop() + mCircleRadius; float gapX = drawWidth / 2.0f - mCircleRadius; float gapY = drawHeight / 2.0f - mCircleRadius; float r = mCircleRadius; for (int i = 0; i < POINT_COUNT; i++) { // compute center point's coordinate Point point = new Point(); point.x = baseX + gapX * (i % 3); point.y = baseY + gapY * (i / 3); point.index = i; mCenterPoints[i] = point; // compute wrong triangle path of this point. Path path = new Path(); float x1, y1, x2, y2, x3, y3; x1 = point.x + r; y1 = point.y; x2 = point.x + r * (2.0f / 3); y2 = point.y - r * (1.0f / 3); x3 = x2; y3 = point.y + r * (1.0f / 3); path.moveTo(x1, y1); path.lineTo(x2, y2); path.lineTo(x3, y3); path.lineTo(x1, y1); path.close(); mWrongPaths[i] = path; Log.d(TAG, "[ " + x1 + ", " + y1 + " ], " + "[ " + x2 + ", " + y2 + " ], " + "[ " + x3 + ", " + y3 + " ]"); } }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw a diamond//from www . j ava 2 s. co m * @param canvas canvas to draw on * @param width width of the diamond * @param height height of the diamond */ public void drawDiamond(final Canvas canvas, final float width, final float height) { final Paint paint = getRedPaint(); final Path path = new Path(); path.moveTo(width / 2, 0); final float offset = height / 5; path.lineTo(offset, height / 2); path.lineTo(width / 2, height); path.lineTo(width - offset, height / 2); path.lineTo(width / 2, 0); path.close(); canvas.drawPath(path, paint); }
From source file:com.acceleratedio.pac_n_zoom.DrawSVG.java
public ArrayList<ImageView> DrawSVG(Context context, ImageView orgnlImageView, RelativeLayout rel_anm_lo) { paint.setColor(Color.WHITE);/* w w w . j a v a 2 s.c o m*/ paint.setStyle(Paint.Style.FILL); LoadSVG.SVGData data = AnimActivity.svg_data; ArrayList<ImageView> imgViews = new ArrayList<ImageView>(); imgViews.add(orgnlImageView); if (data.symbl != null) { ArrayList<String> sprt_ordr = data.svg.ordr; int sym_mbr = 0; Bitmap bitmap; Canvas canvas; // - Loop through the sprites int sprt_nmbr = sprt_ordr.size(); data.svg.initScl = new float[sprt_nmbr]; float[] initScl = data.svg.initScl; for (int sprt_mbr = 1; sprt_mbr < sprt_nmbr; sprt_mbr += 1) { String sprt_id = sprt_ordr.get(sprt_mbr); // e.g., id="g2_0" if (Integer.parseInt(sprt_id.substring(sprt_id.indexOf('_') + 1)) > 0) { // The symbol is already drawn; replicate the view String init_sprt = sprt_id.substring(0, sprt_id.indexOf('_') + 1) + '0'; String svg_ordr = data.svg.svg_ordr; String cnt_str = svg_ordr.substring(0, svg_ordr.indexOf(init_sprt)); ImageView init_vw = imgViews.get(StringUtils.countMatches(cnt_str, ",")); Bitmap initBmp = ((BitmapDrawable) init_vw.getDrawable()).getBitmap(); bitmap = Bitmap.createBitmap(initBmp.getWidth(), initBmp.getHeight(), initBmp.getConfig()); canvas = new Canvas(bitmap); canvas.save(Canvas.MATRIX_SAVE_FLAG); xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id); canvas.scale(crt_sprt.scl, crt_sprt.scl); initScl[sprt_mbr] = crt_sprt.scl; canvas.translate(0, 0); } else { // The symbol needs to be drawn; a new view is used bitmap = getCreatBmp(rel_anm_lo); canvas = new Canvas(bitmap); canvas.save(Canvas.MATRIX_SAVE_FLAG); // - Set the init values xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id); canvas.scale(crt_sprt.scl, crt_sprt.scl); initScl[sprt_mbr] = crt_sprt.scl; canvas.translate(0, 0); // - Draw the bitmap LoadSVG.symbol crt_sym = data.symbl.get(sym_mbr); ArrayList<LoadSVG.path> pths = crt_sym.pths; int pth_nmbr = pths.size(); // Loop through the paths for (int pth_mbr = 0; pth_mbr < pth_nmbr; pth_mbr += 1) { LoadSVG.path crt_pth = pths.get(pth_mbr); final Path path = new Path(); final Paint paint = new Paint(); /* Debug if (pth_mbr + 1 == pth_nmbr) { String log_str = "Paths: pth_mbr = " + String.valueOf(pth_mbr) + "; color = " + crt_pth.clr; Log.d("DrawSVG", log_str); } */ paint.setColor(Color.parseColor(crt_pth.clr)); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL_AND_STROKE); ld_pth_pnts(crt_pth.pth, path); path.close(); path.setFillType(Path.FillType.EVEN_ODD); canvas.drawPath(path, paint); } canvas.restore(); sym_mbr += 1; } ImageView iv = new ImageView(context); iv.setImageBitmap(bitmap); RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); iv.draw(canvas); iv.setLayoutParams(rlp); iv.setBackgroundColor(Color.TRANSPARENT); imgViews.add(iv); } // sprites } // if symbol return imgViews; }
From source file:com.chj.indicator.lib.TriangleSlidingIndicator.java
/** * /* w w w . j a v a 2 s. c o m*/ */ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return; } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates // between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } // // canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, // height, rectPaint); float left = lineLeft; float top = height - indicatorHeight; float right = lineRight; float bottom = height; // TODO: Path path = new Path(); float x1 = (right - left) / 2 + left;// :(right+left)/2 float y1 = top; float x2 = x1 - triangleWidth / 2; float y2 = bottom; float x3 = x1 + triangleWidth / 2; float y3 = bottom; path.moveTo(x1, y1); path.lineTo(x2, y2); path.lineTo(x3, y3); path.lineTo(x1, y1); path.close(); rectPaint.setColor(Color.RED);// ? canvas.drawPath(path, rectPaint); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } }
From source file:wm.xmwei.ui.view.indicator.PagerSlidingTabIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;// ww w. j a v a 2 s. c o m } final int height = getHeight(); final int width = getWidth(); // draw indicator line //rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); nextTab.setBackgroundResource(Color.TRANSPARENT); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } /* canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);*/ float center = (lineLeft + lineRight) / 2; // ,?? // Path path = new Path(); //path.moveTo(center,height - indicatorHeight);// BigDecimal a = BigDecimal.valueOf(1.736); BigDecimal b = BigDecimal.valueOf(3); BigDecimal bigDecimal = a.divide(b, BigDecimal.ROUND_HALF_UP); float result = bigDecimal.floatValue() * indicatorHeight; //path.lineTo(center-result-2, height); // path.lineTo(center+result+2, height); //path.close(); // ?? // canvas.drawPath(path, rectPaint); Path path2 = new Path(); path2.moveTo(0, 0);// path2.lineTo(0, height); path2.lineTo(center - result - 5, height); path2.lineTo(center, height - indicatorHeight); path2.lineTo(center + result + 5, height); path2.lineTo(tabsContainer.getWidth(), height); path2.lineTo(tabsContainer.getWidth(), 0); path2.close(); // ?? canvas.drawPath(path2, bgPaint); // draw underline /*rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);*/ // draw divider /* dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); }*/ }
From source file:org.mdc.chess.ChessBoard.java
private void drawMoveHints(Canvas canvas) { if ((moveHints == null) || blindMode) { return;/*from www .j ava 2s. co m*/ } float h = (float) (sqSize / 2.0); float d = (float) (sqSize / 8.0); double v = 35 * Math.PI / 180; double cosv = Math.cos(v); double sinv = Math.sin(v); double tanv = Math.tan(v); int n = Math.min(moveMarkPaint.size(), moveHints.size()); for (int i = 0; i < n; i++) { Move m = moveHints.get(i); if ((m == null) || (m.from == m.to)) { continue; } float x0 = getXCrd(Position.getX(m.from)) + h; float y0 = getYCrd(Position.getY(m.from)) + h; float x1 = getXCrd(Position.getX(m.to)) + h; float y1 = getYCrd(Position.getY(m.to)) + h; float x2 = (float) (Math.hypot(x1 - x0, y1 - y0) + d); float y2 = 0; float x3 = (float) (x2 - h * cosv); float y3 = (float) (y2 - h * sinv); float x4 = (float) (x3 - d * sinv); float y4 = (float) (y3 + d * cosv); float x5 = (float) (x4 + (-d / 2 - y4) / tanv); float y5 = -d / 2; float x6 = 0; float y6 = y5 / 2; Path path = new Path(); path.moveTo(x2, y2); path.lineTo(x3, y3); // path.lineTo(x4, y4); path.lineTo(x5, y5); path.lineTo(x6, y6); path.lineTo(x6, -y6); path.lineTo(x5, -y5); // path.lineTo(x4, -y4); path.lineTo(x3, -y3); path.close(); Matrix mtx = new Matrix(); mtx.postRotate((float) (Math.atan2(y1 - y0, x1 - x0) * 180 / Math.PI)); mtx.postTranslate(x0, y0); path.transform(mtx); Paint p = moveMarkPaint.get(i); canvas.drawPath(path, p); } }
From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java
public void drawShadow(Canvas canvas, float _sunPosX, float _sunPosY) { tmpSunPositionVector.setPosition(_sunPosX, _sunPosY); shadowPath.reset();//from w ww . ja v a 2 s. c o m for (int i = 0; i < vertexArray.size(); i++) { Path tmpPath = shadowPaths.get(i); tmpPath.reset(); AVector v1 = vertexArray.get(i); AVector v2 = vertexArray.get(i == getVertCount() - 1 ? 0 : i + 1); tmpPath.moveTo(v2.getX(), v2.getY()); tmpPath.lineTo(v1.getX(), v1.getY()); // Current shadow vertex AVector tmpShadowVector = AVector.sub(v1, tmpSunPositionVector); tmpShadowVector.normalize(); tmpShadowVector.multiply(600.0f); tmpShadowVector.add(v1); tmpPath.lineTo(tmpShadowVector.getX(), tmpShadowVector.getY()); // Current shadow vertex tmpShadowVector = AVector.sub(v2, tmpSunPositionVector); tmpShadowVector.normalize(); tmpShadowVector.multiply(600.0f); tmpShadowVector.add(v2); tmpPath.lineTo(tmpShadowVector.getX(), tmpShadowVector.getY()); tmpPath.close(); shadowPath.op(tmpPath, Path.Op.UNION); } canvas.drawPath(shadowPath, shadowPathPaint); }