List of usage examples for android.graphics Path lineTo
public void lineTo(float x, float y)
From source file:nu.yona.app.customview.graph.SpreadGraph.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); this.mCanvas = canvas; float fullWidth = canvas.getWidth(); float heightOfbar = GraphUtils.convertSizeToDeviceDependent(mContext, graphHeight); //first bar/*from w w w. ja va 2 s . c om*/ float mXStart = 0, mYStart = heightOfbar; // basically (X1, Y1) float bottom = heightOfbar; // height (distance from Y1 to Y2) mStartPoint = 0; mMiddlePoint = (fullWidth / 2); float spreadtime = fullWidth; float mPartSize = spreadtime / mNoParts; //todraw text from height float heightDraw = bottom + (GraphUtils.MARGIN_TOP * scaleFactor); //draw graphics of sun and moon Bitmap moonBitmap = drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon)); float bitmapWidth = moonBitmap.getWidth() / 2; mCanvas.drawBitmap(moonBitmap, mStartPoint - (5 * scaleFactor), bottom + (5 * scaleFactor), null); mCanvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icn_sun)), mMiddlePoint - bitmapWidth, bottom + (5 * scaleFactor), null); float textPoint = (mMiddlePoint / 2) / 2; mCanvas.drawText(mContext.getString(R.string.four_hours), textPoint, heightDraw + scaleFactor, getFontStyle()); float textPoint2 = textPoint * 2 + ((textPoint / 2)); mCanvas.drawText(mContext.getString(R.string.eight_hours), textPoint2, heightDraw + scaleFactor, getFontStyle()); float textPoint3 = textPoint * 5; mCanvas.drawText(mContext.getString(R.string.sixteen_hours), textPoint3 - bitmapWidth, heightDraw + scaleFactor, getFontStyle()); float textPoint4 = textPoint * 6 + ((textPoint / 2)); mCanvas.drawText(mContext.getString(R.string.twenty_hours), textPoint4 - bitmapWidth, heightDraw + scaleFactor, getFontStyle()); float textPoint5 = textPoint * 7 + ((textPoint / 2)); mCanvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon)), textPoint5, bottom + (5 * scaleFactor), null); if (mListZoneSpread != null && mListZoneSpread.size() > 0) { float currentStartPos; float currentEndPos; Paint barGraphPaint = new Paint(); barGraphPaint.setStyle(Paint.Style.STROKE); barGraphPaint.setStrokeWidth(5); boolean skipThis; for (TimeZoneSpread timeZoneSpread : mListZoneSpread) { skipThis = false; currentStartPos = (float) timeZoneSpread.getIndex() * mPartSize; Path barPath = new Path(); if (timeZoneSpread.getColor() == GraphUtils.COLOR_PINK || timeZoneSpread.getColor() == GraphUtils.COLOR_BLUE) { currentEndPos = timeZoneSpread.getUsedValue(); barGraphPaint.setColor(timeZoneSpread.getColor()); } else if (timeZoneSpread.getColor() == GraphUtils.COLOR_GREEN) { if (timeZoneSpread.getUsedValue() == 15) { currentEndPos = startEndPoint; barGraphPaint.setColor(GraphUtils.COLOR_BULLET_DOT); } else { currentEndPos = startEndPoint; barGraphPaint.setColor(GraphUtils.COLOR_BLUE); } } else if (timeZoneSpread.getUsedValue() != 15 && timeZoneSpread.getColor() == GraphUtils.COLOR_BULLET_LIGHT_DOT) { currentEndPos = startEndPoint; barGraphPaint.setColor(timeZoneSpread.getColor()); skipThis = true; } else { currentEndPos = startEndPoint; barGraphPaint.setColor(timeZoneSpread.getColor()); } if (!skipThis) { float newXPos = mXStart + currentStartPos; barPath.moveTo(newXPos + 2, mYStart); float noPartsHeight = heightOfbar / 15; barPath.lineTo(currentStartPos + 2, mYStart - (currentEndPos * noPartsHeight) - 1); canvas.drawPath(barPath, barGraphPaint); } } } }
From source file:org.onebusaway.android.map.googlemapsv2.StopOverlay.java
/** * Creates a bus stop icon with the given direction arrow, or without a direction arrow if * the direction is NO_DIRECTION//from w w w. j av a2 s . c om * * @param direction Bus stop direction, obtained from ObaStop.getDirection() and defined in * constants in this class, or NO_DIRECTION if the stop icon shouldn't have a * direction arrow * @return a bus stop icon bitmap with the arrow pointing the given direction, or with no arrow * if direction is NO_DIRECTION */ private static Bitmap createBusStopIcon(String direction) throws NullPointerException { if (direction == null) { throw new IllegalArgumentException(direction); } Resources r = Application.get().getResources(); Context context = Application.get(); Float directionAngle = null; // 0-360 degrees Bitmap bm; Canvas c; Drawable shape; Float rotationX = null, rotationY = null; // Point around which to rotate the arrow Paint arrowPaintFill = new Paint(); arrowPaintFill.setStyle(Paint.Style.FILL); arrowPaintFill.setAntiAlias(true); if (direction.equals(NO_DIRECTION)) { // Don't draw the arrow bm = Bitmap.createBitmap(mPx, mPx, Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, 0, bm.getWidth(), bm.getHeight()); } else if (direction.equals(NORTH)) { directionAngle = 0f; bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight()); // Shade with darkest color at tip of arrow arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, 0, bm.getWidth() / 2, mArrowHeightPx, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // For NORTH, no rotation occurs - use center of image anyway so we have some value rotationX = bm.getWidth() / 2f; rotationY = bm.getHeight() / 2f; } else if (direction.equals(NORTH_WEST)) { directionAngle = 315f; // Arrow is drawn N, rotate 315 degrees bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds((int) mBuffer, (int) mBuffer, bm.getWidth(), bm.getHeight()); // Shade with darkest color at tip of arrow arrowPaintFill.setShader(new LinearGradient(0, 0, mBuffer, mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // Rotate around below coordinates (trial and error) rotationX = mPx / 2f + mBuffer / 2f; rotationY = bm.getHeight() / 2f - mBuffer / 2f; } else if (direction.equals(WEST)) { directionAngle = 0f; // Arrow is drawn pointing West, so no rotation bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds((int) mBuffer, 0, bm.getWidth(), bm.getHeight()); arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight() / 2, mArrowHeightPx, bm.getHeight() / 2, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // For WEST rotationX = bm.getHeight() / 2f; rotationY = bm.getHeight() / 2f; } else if (direction.equals(SOUTH_WEST)) { directionAngle = 225f; // Arrow is drawn N, rotate 225 degrees bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds((int) mBuffer, 0, bm.getWidth(), mPx); arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight(), mBuffer, bm.getHeight() - mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // Rotate around below coordinates (trial and error) rotationX = bm.getWidth() / 2f - mBuffer / 4f; rotationY = mPx / 2f + mBuffer / 4f; } else if (direction.equals(SOUTH)) { directionAngle = 180f; // Arrow is drawn N, rotate 180 degrees bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, 0, bm.getWidth(), (int) (bm.getHeight() - mBuffer)); arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, bm.getHeight(), bm.getWidth() / 2, bm.getHeight() - mArrowHeightPx, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); rotationX = bm.getWidth() / 2f; rotationY = bm.getHeight() / 2f; } else if (direction.equals(SOUTH_EAST)) { directionAngle = 135f; // Arrow is drawn N, rotate 135 degrees bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, 0, mPx, mPx); arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight(), bm.getWidth() - mBuffer, bm.getHeight() - mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // Rotate around below coordinates (trial and error) rotationX = (mPx + mBuffer / 2) / 2f; rotationY = bm.getHeight() / 2f; } else if (direction.equals(EAST)) { directionAngle = 180f; // Arrow is drawn pointing West, so rotate 180 bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, 0, mPx, bm.getHeight()); arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight() / 2, bm.getWidth() - mArrowHeightPx, bm.getHeight() / 2, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); rotationX = bm.getWidth() / 2f; rotationY = bm.getHeight() / 2f; } else if (direction.equals(NORTH_EAST)) { directionAngle = 45f; // Arrow is drawn pointing N, so rotate 45 degrees bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888); c = new Canvas(bm); shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon); shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight()); // Shade with darkest color at tip of arrow arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), 0, bm.getWidth() - mBuffer, mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR)); // Rotate around middle of circle rotationX = (float) mPx / 2; rotationY = bm.getHeight() - (float) mPx / 2; } else { throw new IllegalArgumentException(direction); } shape.draw(c); if (direction.equals(NO_DIRECTION)) { // Everything after this point is for drawing the arrow image, so return the bitmap as-is for no arrow return bm; } /** * Draw the arrow - all dimensions should be relative to px so the arrow is drawn the same * size for all orientations */ // Height of the cutout in the bottom of the triangle that makes it an arrow (0=triangle) final float CUTOUT_HEIGHT = mPx / 12; Path path = new Path(); float x1 = 0, y1 = 0; // Tip of arrow float x2 = 0, y2 = 0; // lower left float x3 = 0, y3 = 0; // cutout in arrow bottom float x4 = 0, y4 = 0; // lower right if (direction.equals(NORTH) || direction.equals(SOUTH) || direction.equals(NORTH_EAST) || direction.equals(SOUTH_EAST) || direction.equals(NORTH_WEST) || direction.equals(SOUTH_WEST)) { // Arrow is drawn pointing NORTH // Tip of arrow x1 = mPx / 2; y1 = 0; // lower left x2 = (mPx / 2) - (mArrowWidthPx / 2); y2 = mArrowHeightPx; // cutout in arrow bottom x3 = mPx / 2; y3 = mArrowHeightPx - CUTOUT_HEIGHT; // lower right x4 = (mPx / 2) + (mArrowWidthPx / 2); y4 = mArrowHeightPx; } else if (direction.equals(EAST) || direction.equals(WEST)) { // Arrow is drawn pointing WEST // Tip of arrow x1 = 0; y1 = mPx / 2; // lower left x2 = mArrowHeightPx; y2 = (mPx / 2) - (mArrowWidthPx / 2); // cutout in arrow bottom x3 = mArrowHeightPx - CUTOUT_HEIGHT; y3 = mPx / 2; // lower right x4 = mArrowHeightPx; y4 = (mPx / 2) + (mArrowWidthPx / 2); } path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(x1, y1); path.lineTo(x2, y2); path.lineTo(x3, y3); path.lineTo(x4, y4); path.lineTo(x1, y1); path.close(); // Rotate arrow around (rotationX, rotationY) point Matrix matrix = new Matrix(); matrix.postRotate(directionAngle, rotationX, rotationY); path.transform(matrix); c.drawPath(path, arrowPaintFill); c.drawPath(path, mArrowPaintStroke); return bm; }
From source file:de.hs_bremen.aurora_hunter.ui.views.KpIndexChartView.java
public void onDraw(Canvas canvas) { if (points.size() == 0) { return;/*from w w w .j a v a2s . co m*/ } Path path = new Path(); int height = canvas.getHeight(); int width = canvas.getWidth(); for (Point point : points) { point.x = point.percentageX * width + 60; // Log.i("scaleFactor", " : " + scaleFactor); //Log.i("percent", " : " + percent); point.y = (float) ((1 - point.percentageY * scaleFactor) * height * 0.7 + 30); } if (points.size() > 1) { //calcuate x/y based on size of canvas for (int i = 0; i < points.size(); i++) { if (i >= 0) { Point point = points.get(i); // Log.i("dx",point.x + " - " + point.y ); if (i == 0) { Point next = points.get(i + 1); point.dx = ((next.x - point.x) / 5); point.dy = ((next.y - point.y) / 5); } else if (i == points.size() - 1) { Point prev = points.get(i - 1); point.dx = ((point.x - prev.x) / 5); point.dy = ((point.y - prev.y) / 5); } else { Point next = points.get(i + 1); Point prev = points.get(i - 1); point.dx = ((next.x - prev.x) / 5); point.dy = ((next.y - prev.y) / 5); } } } } if (points.size() > 0) { path.moveTo(0, (float) (canvas.getHeight() * 0.8)); path.lineTo(0, points.get(0).y); } boolean first = true; for (int i = 0; i < points.size(); i++) { Point point = points.get(i); if (first) { first = false; path.cubicTo(point.x - point.x * 2, point.y - point.y / 5, point.x - point.dx, point.y - point.dy, point.x, point.y); } else { Point prev = points.get(i - 1); // Log.i("Draw", point.dx + " " + point.dy); path.cubicTo(prev.x + prev.dx, prev.y + prev.dy, point.x - point.dx, point.y - point.dy, point.x, point.y); } } path.lineTo(width, (float) (height * 0.8)); path.lineTo(width, (float) (height * 0.9)); path.lineTo(0, (float) (height * 0.9)); canvas.drawPath(path, mGraphPaint); canvas.drawRect(0, (float) (height * 0.9), width, height, mGraphPaint); double Kp1Height = (1 - 0.6666666) * height;//points.get(points.size()-1).y; canvas.drawRect(0, (float) Kp1Height, width, (float) Kp1Height + 1, paintG1Line); canvas.drawText("G1", 2, (float) Kp1Height, paintTxt); int detlaY = 15; for (Point p : points) { int val = (int) Math.round(9 * p.percentageY); //if last element if (points.indexOf(p) == points.size() - 1) { //Log.i("last", p.toString()); // canvas.drawText(val + "", p.x-150,p.y - detlaY, paintTxt); } else { canvas.drawText(val + "", p.x - 10, p.y - detlaY, paintTxt); } //Log.i("point", p.toString()); } // Log.i("Lenght", points.size() + " "); }
From source file:org.akop.crosswords.view.CrosswordView.java
private void renderCell(Canvas canvas, Cell cell, RectF cellRect, Paint fillPaint) { canvas.drawRect(cellRect, fillPaint); canvas.drawRect(cellRect, mCellStrokePaint); if (cell.mCircled) { canvas.drawCircle(cellRect.centerX(), cellRect.centerY(), mCircleRadius, mCircleStrokePaint); }//from w w w. j a v a2s . c o m if (cell.mNumber != null) { mNumberTextPaint.getTextBounds(cell.mNumber, 0, cell.mNumber.length(), mTempRect); float numberX = cellRect.left + mNumberTextPadding + (mTempRect.width() / 2); float numberY = cellRect.top + mNumberTextPadding + mTempRect.height(); if (cell.mCircled) { canvas.drawText(cell.mNumber, numberX, numberY, mNumberStrokePaint); } canvas.drawText(cell.mNumber, numberX, numberY, mNumberTextPaint); } if (cell.mCheated) { Path path = new Path(); path.moveTo(cellRect.right, cellRect.bottom); path.lineTo(cellRect.right - mMarkerSideLength, cellRect.bottom); path.lineTo(cellRect.right, cellRect.bottom - mMarkerSideLength); path.close(); canvas.drawPath(path, mCheatedCellFillPaint); canvas.drawPath(path, mCellStrokePaint); } if (cell.mError) { Path path = new Path(); path.moveTo(cellRect.left, cellRect.bottom); path.lineTo(cellRect.left + mMarkerSideLength, cellRect.bottom); path.lineTo(cellRect.left, cellRect.bottom - mMarkerSideLength); path.close(); canvas.drawPath(path, mMistakeCellFillPaint); canvas.drawPath(path, mCellStrokePaint); } if (!cell.isEmpty()) { mAnswerTextPaint.getTextBounds(cell.mCharStr, 0, cell.mCharStr.length(), mTempRect); canvas.drawText(cell.mCharStr, cellRect.left + mCellSize / 2, cellRect.top + mCellSize - mAnswerTextPadding, mAnswerTextPaint); } }
From source file:de.hs_bremen.aurora_hunter.ui.views.PredictionGraphView.java
public void onDraw(Canvas canvas) { if (mPoints.size() == 0) { return;//from w w w . ja v a2s .c o m } int yOffsetForLabels = 0; if (mMax * mScaleFactor > 0.8) { yOffsetForLabels = 15; } Path path = new Path(); int height = canvas.getHeight(); int width = canvas.getWidth(); for (Point point : mPoints) { point.x = point.percentageX * width + 60; // Log.i("mScaleFactor", " : " + mScaleFactor); //Log.i("percent", " : " + percent); point.y = (float) ((1 - point.percentageY * mScaleFactor) * height) + yOffsetForLabels * 3; } if (mPoints.size() > 1) { //calcuate x/y based on size of canvas for (int i = 0; i < mPoints.size(); i++) { if (i >= 0) { Point point = mPoints.get(i); // Log.i("dx",point.x + " - " + point.y ); if (i == 0) { Point next = mPoints.get(i + 1); point.dx = ((next.x - point.x) / 5); point.dy = ((next.y - point.y) / 5); } else if (i == mPoints.size() - 1) { Point prev = mPoints.get(i - 1); point.dx = ((point.x - prev.x) / 5); point.dy = ((point.y - prev.y) / 5); } else { Point next = mPoints.get(i + 1); Point prev = mPoints.get(i - 1); point.dx = ((next.x - prev.x) / 5); point.dy = ((next.y - prev.y) / 5); } } } } if (mPoints.size() > 0) { path.moveTo(0, (float) (canvas.getHeight() * 0.8)); path.lineTo(0, mPoints.get(0).y); } boolean first = true; for (int i = 0; i < mPoints.size(); i++) { Point point = mPoints.get(i); if (first) { first = false; path.cubicTo(point.x - point.x * 2, point.y - point.y / 5, point.x - point.dx, point.y - point.dy, point.x, point.y); } else { Point prev = mPoints.get(i - 1); // Log.i("Draw", point.dx + " " + point.dy); path.cubicTo(prev.x + prev.dx, prev.y + prev.dy, point.x - point.dx, point.y - point.dy, point.x, point.y); } } if (mPoints.size() > 0) { path.lineTo(width, mPoints.get(mPoints.size() - 1).y); } path.lineTo(width, height); path.lineTo(0, height); canvas.drawPath(path, mGraphPaint); int detlaY = 30; for (Point p : mPoints) { int val = (int) Math.round(p.percentageY * 100); //if last element if (mPoints.indexOf(p) == mPoints.size() - 1) { //Log.i("last", p.toString()); if (val == 0 || p.y > getHeight()) { canvas.drawText(val + "%", p.x - 150, getHeight() - detlaY, mTextPaint); } else { canvas.drawText(val + "%", p.x - 150, p.y - detlaY + yOffsetForLabels, mTextPaint); } } else { if (val == 0 || p.y > getHeight()) { canvas.drawText(val + "%", p.x - 20, getHeight() - detlaY, mTextPaint); } else { canvas.drawText(val + "%", p.x - 20, p.y - detlaY + yOffsetForLabels, mTextPaint); } } //Log.i("point", p.toString()); } // Log.i("Lenght", mPoints.size() + " "); float levelStart = (float) (canvas.getHeight() - (mNotificationLevel * canvas.getHeight())); float lineHeight = DpToPixelUtil.convertDpToPixel(2, getContext()); if (mViewMode == PredictionFragment.NOTIFICATION_MODE.SET_NOTIFICATION_LEVEL) { mNotificationLevelPaint.setAlpha(150); float leftOffset = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { float arcHeight = DpToPixelUtil.convertDpToPixel(30, getContext()); leftOffset = arcHeight; RectF rectF = new RectF(getWidth() - arcHeight, levelStart - arcHeight / 2, getWidth(), levelStart + arcHeight / 2); canvas.drawArc(rectF, 0, 360, true, mNotificationLevelPaint); } canvas.drawRect(0, levelStart, canvas.getWidth() - leftOffset, levelStart + lineHeight, mNotificationLevelPaint); mNotificationLevelPaint.setAlpha(20); canvas.drawRect(0, levelStart + lineHeight, canvas.getWidth(), canvas.getHeight(), mNotificationLevelPaint); String text = Math.round(mNotificationLevel * 100) + "%"; canvas.drawText(text, DpToPixelUtil.convertDpToPixel(10, getContext()), levelStart + DpToPixelUtil.convertDpToPixel(25, getContext()), mNotificationLevelTextPaint); } else { mNotificationLevelPaint.setAlpha(30); canvas.drawRect(0, levelStart, canvas.getWidth(), levelStart + lineHeight, mNotificationLevelPaint); } }
From source file:net.droidsolutions.droidcharts.core.renderer.category.LineAndShapeRenderer.java
private Path convertAwtPathToAndroid(PathIterator pi) { Path path = new Path(); float[] coords = new float[6]; while (!pi.isDone()) { int windingRule = pi.getWindingRule(); if (windingRule == PathIterator.WIND_EVEN_ODD) { path.setFillType(Path.FillType.EVEN_ODD); } else {//ww w. java 2 s .c o m path.setFillType(Path.FillType.INVERSE_EVEN_ODD); } int pathType = pi.currentSegment(coords); switch (pathType) { case PathIterator.SEG_CLOSE: path.close(); break; case PathIterator.SEG_CUBICTO: path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_LINETO: path.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_MOVETO: path.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; } pi.next(); } return path; }
From source file:cw.kop.autobackground.settings.WearSettingsFragment.java
private void drawAnalog() { if (!AppSettings.getTimeType().equals(AppSettings.ANALOG)) { return;//from www . ja v a 2 s . c o m } canvas = surfaceView.getHolder().lockCanvas(); if (canvas == null) { return; } setPaints(); if (imageBitmap != null) { canvas.drawBitmap(imageBitmap, 0, 0, bitmapPaint); } // Time time = new Time(); // time.setToNow(); // time.set(time.toMillis(false) + AppSettings.getTimeOffset()); // // float hour = time.hour + time.minute / 60f; // float minute = time.minute + time.second / 60f; // float second = time.second; float centerX = watchContainer.getWidth() * 0.222f; float centerY = watchContainer.getHeight() * 0.222f; float radius = centerX; // Draw tick marks for (int i = 0; i < 12; i++) { canvas.drawLine((float) (centerX + (radius * tickRadius / 100f) * Math.cos(Math.toRadians(i * 30f))), (float) (centerY + (radius * tickRadius / 100f) * Math.sin(Math.toRadians(i * 30f))), (float) (centerX + (radius) * Math.cos(Math.toRadians(i * 30f))), (float) (centerY + (radius) * Math.sin(Math.toRadians(i * 30f))), tickPaint); } // Draw clock hands // Draw shadows first to prevent outline overlapping other hands Path hourShadowPath = new Path(); hourShadowPath.moveTo((float) (centerX + hourWidth / 1.5f * Math.cos(Math.toRadians(90f))), (float) (centerY + hourWidth / 1.5f * Math.sin(Math.toRadians(90f)))); hourShadowPath.quadTo((float) (centerX - (hourWidth / 1.5f) * Math.cos(Math.toRadians(0f))), (float) (centerY - (hourWidth / 1.5f) * Math.sin(Math.toRadians(0f))), (float) (centerX + hourWidth / 1.5f * Math.cos(Math.toRadians(270f))), (float) (centerY + hourWidth / 1.5f * Math.sin(Math.toRadians(270f)))); hourShadowPath.lineTo( (float) (centerX + (radius * hourRadius / 100f + 2.0f) * Math.cos(Math.toRadians(0f))), (float) (centerY + (radius * hourRadius / 100f + 2.0f) * Math.sin(Math.toRadians(0f)))); hourShadowPath.close(); canvas.drawPath(hourShadowPath, hourShadowPaint); Path minuteShadowPath = new Path(); minuteShadowPath.moveTo((float) (centerX + minuteWidth / 1.5f * Math.cos(Math.toRadians(0f))), (float) (centerY + minuteWidth / 1.5f * Math.sin(Math.toRadians(0f)))); minuteShadowPath.quadTo((float) (centerX - (minuteWidth / 1.5f) * Math.cos(Math.toRadians(-180f))), (float) (centerY - (minuteWidth / 1.5f) * Math.sin(Math.toRadians(-180f))), (float) (centerX + minuteWidth / 1.5f * Math.cos(Math.toRadians(90f))), (float) (centerY + minuteWidth / 1.5f * Math.sin(Math.toRadians(90f)))); minuteShadowPath.lineTo( (float) (centerX + (radius * minuteRadius / 100f + 2.0f) * Math.cos(Math.toRadians(-90f))), (float) (centerY + (radius * minuteRadius / 100f + 2.0f) * Math.sin(Math.toRadians(-90f)))); minuteShadowPath.close(); canvas.drawPath(minuteShadowPath, minuteShadowPaint); Path secondShadowPath = new Path(); secondShadowPath.moveTo((float) (centerX + secondWidth / 1.5f * Math.cos(Math.toRadians(225f))), (float) (centerY + secondWidth / 1.5f * Math.sin(Math.toRadians(225f)))); secondShadowPath.quadTo((float) (centerX - (secondWidth / 1.5f) * Math.cos(Math.toRadians(45f))), (float) (centerY - (secondWidth / 1.5f) * Math.sin(Math.toRadians(45f))), (float) (centerX + secondWidth / 1.5f * Math.cos(Math.toRadians(315f))), (float) (centerY + secondWidth / 1.5f * Math.sin(Math.toRadians(315f)))); secondShadowPath.lineTo( (float) (centerX + (radius * secondRadius / 100f + 2f) * Math.cos(Math.toRadians(135f))), (float) (centerY + (radius * secondRadius / 100f + 2.0f) * Math.sin(Math.toRadians(135f)))); secondShadowPath.close(); canvas.drawPath(secondShadowPath, secondShadowPaint); // Now draw actual hands Path hourPath = new Path(); hourPath.moveTo((float) (centerX + hourWidth / 2f * Math.cos(Math.toRadians(90f))), (float) (centerY + hourWidth / 2f * Math.sin(Math.toRadians(90f)))); hourPath.quadTo((float) (centerX - (hourWidth / 2f) * Math.cos(Math.toRadians(0f))), (float) (centerY - (hourWidth / 2f) * Math.sin(Math.toRadians(0f))), (float) (centerX + hourWidth / 2f * Math.cos(Math.toRadians(270f))), (float) (centerY + hourWidth / 2f * Math.sin(Math.toRadians(270f)))); hourPath.lineTo((float) (centerX + (radius * hourRadius / 100f) * Math.cos(Math.toRadians(0f))), (float) (centerY + (radius * hourRadius / 100f) * Math.sin(Math.toRadians(0f)))); hourPath.close(); canvas.drawPath(hourPath, hourPaint); Path minutePath = new Path(); minutePath.moveTo((float) (centerX + minuteWidth / 2f * Math.cos(Math.toRadians(0f))), (float) (centerY + minuteWidth / 2f * Math.sin(Math.toRadians(0f)))); minutePath.quadTo((float) (centerX - (minuteWidth / 2f) * Math.cos(Math.toRadians(-180f))), (float) (centerY - (minuteWidth / 2f) * Math.sin(Math.toRadians(-180f))), (float) (centerX + minuteWidth / 2f * Math.cos(Math.toRadians(90f))), (float) (centerY + minuteWidth / 2f * Math.sin(Math.toRadians(90f)))); minutePath.lineTo((float) (centerX + (radius * minuteRadius / 100f) * Math.cos(Math.toRadians(-90f))), (float) (centerY + (radius * minuteRadius / 100f) * Math.sin(Math.toRadians(-90f)))); minutePath.close(); canvas.drawPath(minutePath, minutePaint); Path secondPath = new Path(); secondPath.moveTo((float) (centerX + secondWidth / 2f * Math.cos(Math.toRadians(225f))), (float) (centerY + secondWidth / 2f * Math.sin(Math.toRadians(225f)))); secondPath.quadTo((float) (centerX - (secondWidth / 2f) * Math.cos(Math.toRadians(45f))), (float) (centerY - (secondWidth / 2f) * Math.sin(Math.toRadians(45f))), (float) (centerX + secondWidth / 2f * Math.cos(Math.toRadians(315f))), (float) (centerY + secondWidth / 2f * Math.sin(Math.toRadians(315f)))); secondPath.lineTo((float) (centerX + (radius * secondRadius / 100f) * Math.cos(Math.toRadians(135f))), (float) (centerY + (radius * secondRadius / 100f) * Math.sin(Math.toRadians(135f)))); secondPath.close(); canvas.drawPath(secondPath, secondPaint); surfaceView.getHolder().unlockCanvasAndPost(canvas); }
From source file:com.larvalabs.svgandroid.SVGParser.java
/** * This is where the hard-to-parse paths are handled. * Uppercase rules are absolute positions, lowercase are relative. * Types of path rules://from w w w . j a va2 s.c om * <p/> * <ol> * <li>M/m - (x y)+ - Move to (without drawing) * <li>Z/z - (no params) - Close path (back to starting point) * <li>L/l - (x y)+ - Line to * <li>H/h - x+ - Horizontal ine to * <li>V/v - y+ - Vertical line to * <li>C/c - (x1 y1 x2 y2 x y)+ - Cubic bezier to * <li>S/s - (x2 y2 x y)+ - Smooth cubic bezier to (shorthand that assumes the x2, y2 from previous C/S is the x1, y1 of this bezier) * <li>Q/q - (x1 y1 x y)+ - Quadratic bezier to * <li>T/t - (x y)+ - Smooth quadratic bezier to (assumes previous control point is "reflection" of last one w.r.t. to current point) * </ol> * <p/> * Numbers are separate by whitespace, comma or nothing at all (!) if they are self-delimiting, (ie. begin with a - sign) * * @param s the path string from the XML */ private static Path doPath(String s) { int n = s.length(); ParserHelper ph = new ParserHelper(s, 0); ph.skipWhitespace(); Path p = new Path(); float lastX = 0; float lastY = 0; float lastX1 = 0; float lastY1 = 0; RectF r = new RectF(); char cmd = 'x'; while (ph.pos < n) { char next = s.charAt(ph.pos); if (!Character.isDigit(next) && !(next == '.') && !(next == '-')) { cmd = next; ph.advance(); } else if (cmd == 'M') { // implied command cmd = 'L'; } else if (cmd == 'm') { // implied command cmd = 'l'; } else { // implied command // Log.d(TAG, "Implied command: " + cmd); } p.computeBounds(r, true); // Log.d(TAG, " " + cmd + " " + r); // Util.debug("* Commands remaining: '" + path + "'."); boolean wasCurve = false; switch (cmd) { case 'M': case 'm': { float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 'm') { p.rMoveTo(x, y); lastX += x; lastY += y; } else { p.moveTo(x, y); lastX = x; lastY = y; } break; } case 'Z': case 'z': { p.close(); break; } case 'L': case 'l': { float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 'l') { p.rLineTo(x, y); lastX += x; lastY += y; } else { p.lineTo(x, y); lastX = x; lastY = y; } break; } case 'H': case 'h': { float x = ph.nextFloat(); if (cmd == 'h') { p.rLineTo(x, 0); lastX += x; } else { p.lineTo(x, lastY); lastX = x; } break; } case 'V': case 'v': { float y = ph.nextFloat(); if (cmd == 'v') { p.rLineTo(0, y); lastY += y; } else { p.lineTo(lastX, y); lastY = y; } break; } case 'C': case 'c': { wasCurve = true; float x1 = ph.nextFloat(); float y1 = ph.nextFloat(); float x2 = ph.nextFloat(); float y2 = ph.nextFloat(); float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 'c') { x1 += lastX; x2 += lastX; x += lastX; y1 += lastY; y2 += lastY; y += lastY; } p.cubicTo(x1, y1, x2, y2, x, y); lastX1 = x2; lastY1 = y2; lastX = x; lastY = y; break; } case 'S': case 's': { wasCurve = true; float x2 = ph.nextFloat(); float y2 = ph.nextFloat(); float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 's') { x2 += lastX; x += lastX; y2 += lastY; y += lastY; } float x1 = 2 * lastX - lastX1; float y1 = 2 * lastY - lastY1; p.cubicTo(x1, y1, x2, y2, x, y); lastX1 = x2; lastY1 = y2; lastX = x; lastY = y; break; } case 'A': case 'a': { float rx = ph.nextFloat(); float ry = ph.nextFloat(); float theta = ph.nextFloat(); int largeArc = (int) ph.nextFloat(); int sweepArc = (int) ph.nextFloat(); float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 'a') { x += lastX; y += lastY; } drawArc(p, lastX, lastY, x, y, rx, ry, theta, largeArc == 1, sweepArc == 1); lastX = x; lastY = y; break; } default: Log.d(TAG, "Invalid path command: " + cmd); ph.advance(); } if (!wasCurve) { lastX1 = lastX; lastY1 = lastY; } ph.skipWhitespace(); } return p; }
From source file:com.hippo.widget.lockpattern.LockPatternView.java
@Override protected void onDraw(Canvas canvas) { final ArrayList<Cell> pattern = mPattern; final int count = pattern.size(); final boolean[][] drawLookup = mPatternDrawLookup; if (mPatternDisplayMode == DisplayMode.Animate) { // figure out which circles to draw // + 1 so we pause on complete pattern final int oneCycle = (count + 1) * MILLIS_PER_CIRCLE_ANIMATING; final int spotInCycle = (int) (SystemClock.elapsedRealtime() - mAnimatingPeriodStart) % oneCycle; final int numCircles = spotInCycle / MILLIS_PER_CIRCLE_ANIMATING; clearPatternDrawLookup();//from ww w . j av a 2s.c o m for (int i = 0; i < numCircles; i++) { final Cell cell = pattern.get(i); drawLookup[cell.getRow()][cell.getColumn()] = true; } // figure out in progress portion of ghosting line final boolean needToUpdateInProgressPoint = numCircles > 0 && numCircles < count; if (needToUpdateInProgressPoint) { final float percentageOfNextCircle = ((float) (spotInCycle % MILLIS_PER_CIRCLE_ANIMATING)) / MILLIS_PER_CIRCLE_ANIMATING; final Cell currentCell = pattern.get(numCircles - 1); final float centerX = getCenterXForColumn(currentCell.column); final float centerY = getCenterYForRow(currentCell.row); final Cell nextCell = pattern.get(numCircles); final float dx = percentageOfNextCircle * (getCenterXForColumn(nextCell.column) - centerX); final float dy = percentageOfNextCircle * (getCenterYForRow(nextCell.row) - centerY); mInProgressX = centerX + dx; mInProgressY = centerY + dy; } // TODO: Infinite loop here... invalidate(); } final Path currentPath = mCurrentPath; currentPath.rewind(); // draw the circles for (int i = 0; i < 3; i++) { float centerY = getCenterYForRow(i); for (int j = 0; j < 3; j++) { CellState cellState = mCellStates[i][j]; float centerX = getCenterXForColumn(j); float size = cellState.size * cellState.scale; float translationY = cellState.translateY; drawCircle(canvas, (int) centerX, (int) centerY + translationY, size, drawLookup[i][j], cellState.alpha); } } // TODO: the path should be created and cached every time we hit-detect a cell // only the last segment of the path should be computed here // draw the path of the pattern (unless we are in stealth mode) final boolean drawPath = !mInStealthMode; if (drawPath) { mPathPaint.setColor(getCurrentColor(true /* partOfPattern */)); boolean anyCircles = false; float lastX = 0f; float lastY = 0f; for (int i = 0; i < count; i++) { Cell cell = pattern.get(i); // only draw the part of the pattern stored in // the lookup table (this is only different in the case // of animation). if (!drawLookup[cell.row][cell.column]) { break; } anyCircles = true; float centerX = getCenterXForColumn(cell.column); float centerY = getCenterYForRow(cell.row); if (i != 0) { CellState state = mCellStates[cell.row][cell.column]; currentPath.rewind(); currentPath.moveTo(lastX, lastY); if (state.lineEndX != Float.MIN_VALUE && state.lineEndY != Float.MIN_VALUE) { currentPath.lineTo(state.lineEndX, state.lineEndY); } else { currentPath.lineTo(centerX, centerY); } canvas.drawPath(currentPath, mPathPaint); } lastX = centerX; lastY = centerY; } // draw last in progress section if ((mPatternInProgress || mPatternDisplayMode == DisplayMode.Animate) && anyCircles) { currentPath.rewind(); currentPath.moveTo(lastX, lastY); currentPath.lineTo(mInProgressX, mInProgressY); mPathPaint.setAlpha( (int) (calculateLastSegmentAlpha(mInProgressX, mInProgressY, lastX, lastY) * 255f)); canvas.drawPath(currentPath, mPathPaint); } } }
From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java
/** * This is where the hard-to-parse paths are handled. Uppercase rules are * absolute positions, lowercase are relative. Types of path rules: * <p/>//from w ww . j av a 2s . c o m * <ol> * <li>M/m - (x y)+ - Move to (without drawing) * <li>Z/z - (no params) - Close path (back to starting point) * <li>L/l - (x y)+ - Line to * <li>H/h - x+ - Horizontal ine to * <li>V/v - y+ - Vertical line to * <li>C/c - (x1 y1 x2 y2 x y)+ - Cubic bezier to * <li>S/s - (x2 y2 x y)+ - Smooth cubic bezier to (shorthand that assumes * the x2, y2 from previous C/S is the x1, y1 of this bezier) * <li>Q/q - (x1 y1 x y)+ - Quadratic bezier to * <li>T/t - (x y)+ - Smooth quadratic bezier to (assumes previous control * point is "reflection" of last one w.r.t. to current point) * </ol> * <p/> * Numbers are separate by whitespace, comma or nothing at all (!) if they * are self-delimiting, (ie. begin with a - sign) * * @param s * the path string from the XML */ private static Path doPath(String s) { int n = s.length(); ParserHelper ph = new ParserHelper(s, 0); ph.skipWhitespace(); Path p = new Path(); float lastX = 0; float lastY = 0; float lastX1 = 0; float lastY1 = 0; float subPathStartX = 0; float subPathStartY = 0; char prevCmd = 0; while (ph.pos < n) { char cmd = s.charAt(ph.pos); switch (cmd) { case '-': case '+': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (prevCmd == 'm' || prevCmd == 'M') { cmd = (char) ((prevCmd) - 1); break; } else if (("lhvcsqta").indexOf(Character.toLowerCase(prevCmd)) >= 0) { cmd = prevCmd; break; } default: { ph.advance(); prevCmd = cmd; } } boolean wasCurve = false; switch (cmd) { case 'M': case 'm': { float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 'm') { subPathStartX += x; subPathStartY += y; p.rMoveTo(x, y); lastX += x; lastY += y; } else { subPathStartX = x; subPathStartY = y; p.moveTo(x, y); lastX = x; lastY = y; } break; } case 'Z': case 'z': { p.close(); p.moveTo(subPathStartX, subPathStartY); lastX = subPathStartX; lastY = subPathStartY; lastX1 = subPathStartX; lastY1 = subPathStartY; wasCurve = true; break; } case 'T': case 't': // todo - smooth quadratic Bezier (two parameters) case 'L': case 'l': { float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 'l') { p.rLineTo(x, y); lastX += x; lastY += y; } else { p.lineTo(x, y); lastX = x; lastY = y; } break; } case 'H': case 'h': { float x = ph.nextFloat(); if (cmd == 'h') { p.rLineTo(x, 0); lastX += x; } else { p.lineTo(x, lastY); lastX = x; } break; } case 'V': case 'v': { float y = ph.nextFloat(); if (cmd == 'v') { p.rLineTo(0, y); lastY += y; } else { p.lineTo(lastX, y); lastY = y; } break; } case 'C': case 'c': { wasCurve = true; float x1 = ph.nextFloat(); float y1 = ph.nextFloat(); float x2 = ph.nextFloat(); float y2 = ph.nextFloat(); float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 'c') { x1 += lastX; x2 += lastX; x += lastX; y1 += lastY; y2 += lastY; y += lastY; } p.cubicTo(x1, y1, x2, y2, x, y); lastX1 = x2; lastY1 = y2; lastX = x; lastY = y; break; } case 'Q': case 'q': // todo - quadratic Bezier (four parameters) case 'S': case 's': { wasCurve = true; float x2 = ph.nextFloat(); float y2 = ph.nextFloat(); float x = ph.nextFloat(); float y = ph.nextFloat(); if (Character.isLowerCase(cmd)) { x2 += lastX; x += lastX; y2 += lastY; y += lastY; } float x1 = 2 * lastX - lastX1; float y1 = 2 * lastY - lastY1; p.cubicTo(x1, y1, x2, y2, x, y); lastX1 = x2; lastY1 = y2; lastX = x; lastY = y; break; } case 'A': case 'a': { float rx = ph.nextFloat(); float ry = ph.nextFloat(); float theta = ph.nextFloat(); int largeArc = ph.nextFlag(); int sweepArc = ph.nextFlag(); float x = ph.nextFloat(); float y = ph.nextFloat(); if (cmd == 'a') { x += lastX; y += lastY; } drawArc(p, lastX, lastY, x, y, rx, ry, theta, largeArc, sweepArc); lastX = x; lastY = y; break; } default: Log.w(TAG, "Invalid path command: " + cmd); ph.advance(); } if (!wasCurve) { lastX1 = lastX; lastY1 = lastY; } ph.skipWhitespace(); } return p; }