List of usage examples for android.graphics Path computeBounds
@SuppressWarnings({ "UnusedDeclaration" }) public void computeBounds(RectF bounds, boolean exact)
From source file:Main.java
/** * Creates a simple region from the given path. * * @param path given path/*from ww w . ja va 2 s.c o m*/ * @return region object */ public static Region createRegionFromPath(Path path) { Region region = new Region(); if (path != null) { RectF box = new RectF(); path.computeBounds(box, true); region.setPath(path, new Region((int) box.left, (int) box.top, (int) box.right, (int) box.bottom)); } return region; }
From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java
private void computePathBounds(Path _path, RectF _rBounds) { _path.computeBounds(_rBounds, false); }
From source file:com.frapim.windwatch.Notifier.java
private Path getArrowPath(float degrees) { Path path = new Path(); int leftX = (mBigIconSize / 2) - (mArrowWidth / 2); int leftHeadX = leftX - mArrowWidth; int rightX = (mBigIconSize / 2) + (mArrowWidth / 2); int rightHeadX = rightX + mArrowWidth; path.moveTo(leftX, mArrowHeight); // bottom left path.lineTo(leftX, mArrowHeadHeight); // left, arrow head start path.lineTo(leftHeadX, mArrowHeadHeight); // left, arrow head end path.lineTo(mBigIconSize / 2, 0); // top path.lineTo(rightHeadX, mArrowHeadHeight); // right, arrow head end path.lineTo(rightX, mArrowHeadHeight); // right, arrow head start path.lineTo(rightX, mArrowHeight); // bottom right path.lineTo(leftX, mArrowHeight); // bottom left path.close();//from w w w . ja va 2s . c o m Matrix translateMatrix = new Matrix(); translateMatrix.postTranslate(0, 30); path.transform(translateMatrix); RectF bounds = new RectF(); path.computeBounds(bounds, true); Matrix rotateMatrix = new Matrix(); rotateMatrix.postRotate(degrees, (bounds.right + bounds.left) / 2, (bounds.bottom + bounds.top) / 2); path.transform(rotateMatrix); return path; }
From source file:com.codegarden.nativenavigation.JuceActivity.java
public final int[] renderGlyph(char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) { Path p = new Path(); paint.getTextPath(String.valueOf(glyph), 0, 1, 0.0f, 0.0f, p); RectF boundsF = new RectF(); p.computeBounds(boundsF, true); matrix.mapRect(boundsF);//from w w w . ja v a 2 s . com boundsF.roundOut(bounds); bounds.left--; bounds.right++; final int w = bounds.width(); final int h = Math.max(1, bounds.height()); Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bm); matrix.postTranslate(-bounds.left, -bounds.top); c.setMatrix(matrix); c.drawPath(p, paint); final int sizeNeeded = w * h; if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int[sizeNeeded]; bm.getPixels(cachedRenderArray, 0, w, 0, 0, w, h); bm.recycle(); return cachedRenderArray; }
From source file:com.juce.JuceAppActivity.java
public final int[] renderGlyph (char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) { Path p = new Path(); paint.getTextPath (String.valueOf (glyph), 0, 1, 0.0f, 0.0f, p); RectF boundsF = new RectF(); p.computeBounds (boundsF, true); matrix.mapRect (boundsF);//ww w . j a va 2s . c o m boundsF.roundOut (bounds); bounds.left--; bounds.right++; final int w = bounds.width(); final int h = Math.max (1, bounds.height()); Bitmap bm = Bitmap.createBitmap (w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas (bm); matrix.postTranslate (-bounds.left, -bounds.top); c.setMatrix (matrix); c.drawPath (p, paint); final int sizeNeeded = w * h; if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int [sizeNeeded]; bm.getPixels (cachedRenderArray, 0, w, 0, 0, w, h); bm.recycle(); return cachedRenderArray; }
From source file:ac.robinson.paperchains.PaperChainsActivity.java
private void processScribble(Path scribble) { try {/*from w w w . ja va 2s . c o m*/ // the file we're given via createTempFile is unplayable, but the name creation routine is useful... File outputFile = File.createTempFile(getString(R.string.app_name), ".mp4", getCacheDir()); String outputFilePath = outputFile.getAbsolutePath(); if (outputFile.delete()) { // get the bounding box and add to our list RectF scribbleBox = new RectF(); scribble.computeBounds(scribbleBox, true); Rect audioArea = new Rect(); scribbleBox.roundOut(audioArea); int scribbleWidth = Math .round(getResources().getDimensionPixelSize(R.dimen.scribble_stroke_width) / 2f); // expand to include stroke width (half either side of line) audioArea.inset(-scribbleWidth, -scribbleWidth); // initialise recording resetRecordingInterface(); mAudioRecorder = AudioRecorder.build(PaperChainsActivity.this, outputFilePath); mCurrentAudioRect = audioArea; mImageView.addAudioAreaRect(audioArea); mImageView.setScribbleEnabled(false); // position the recording buttons PointF centrePoint = mImageView .imagePointToScreenPoint(new Point(audioArea.centerX(), audioArea.centerY())); initialiseRecordingButtons(centrePoint); } else { Toast.makeText(PaperChainsActivity.this, getString(R.string.audio_recording_setup_error), Toast.LENGTH_SHORT).show(); } } catch (IOException | IllegalArgumentException e) { Toast.makeText(PaperChainsActivity.this, getString(R.string.audio_recording_setup_error), Toast.LENGTH_SHORT).show(); } }
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:/* w w w.j a v a 2 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:jp.co.recruit_lifestyle.android.widget.ColoringLoadingView.java
public void setCharacter(Character character) { if (!isPreDraw) { mCharacter = character;//ww w. j a v a 2 s . c o m return; } Path characterPath; switch (character) { case NINJA: characterPath = NinjaPath.getNinjaPath(mViewWidth / 1.5f, mCenterPoint); break; case BUTTERFLY: characterPath = ButterflyPath.getButterflyPath(mViewWidth / 1.5f, mCenterPoint); break; case AK: characterPath = AkPath.getAkPath(mViewWidth / 1.5f, mCenterPoint); break; case HAIR_STYLE: characterPath = HairStylePath.getHairStylePath(mViewWidth / 1.5f, mCenterPoint); break; case TOOTH: characterPath = ToothPath.getToothPath(mViewWidth / 1.5f, mCenterPoint); break; case STORM: characterPath = StormPath.getStormPath(mViewWidth / 1.5f, mCenterPoint); break; case DOGEZA: characterPath = DogezaPath.getDogezaPath(mViewWidth / 1.5f, mCenterPoint); break; case CAT: characterPath = CatPath.getCatPath(mViewWidth / 1.5f, mCenterPoint); break; case VIOLIN: characterPath = ViolinPath.getViolinPath(mViewWidth / 1.5f, mCenterPoint); break; case CUCUMBER: characterPath = CucumberPath.getCucumberPath(mViewWidth / 1.5f, mCenterPoint); break; case NINJA_STAR: characterPath = NinjaStarPath.getNinjaStarPath(mViewWidth / 1.5f, mCenterPoint); break; case SIM: characterPath = NinjaStarPath.getNinjaStarPath(mViewWidth / 1.5f, mCenterPoint); break; default: characterPath = NinjaPath.getNinjaPath(mViewWidth / 1.5f, mCenterPoint); break; } mCharacterPathMeasure = new PathMeasure(characterPath, false); mRectF.setEmpty(); characterPath.computeBounds(mRectF, true); mRegion.setEmpty(); mRegion.set((int) mRectF.left, (int) mRectF.top, (int) mRectF.right, (int) mRectF.bottom); mRegion.setPath(characterPath, mRegion); }