@Test public void testSetPatternPath() { Path pattern = new Path(); RectF oval = new RectF(0, 0, 100, 100); pattern.addArc(oval, 0, 180); PatternPathMotion patternPathMotion = new PatternPathMotion(); patternPathMotion.setPatternPath(pattern); assertSame(pattern, patternPathMotion.getPatternPath()); }
public void setPatternPath(Path patternPath) { PathMeasure pathMeasure = new PathMeasure(patternPath, false); float length = pathMeasure.getLength(); float[] pos = new float[2]; pathMeasure.getPosTan(length, pos, null); float endX = pos[0]; float endY = pos[1]; pathMeasure.getPosTan(0, pos, null); float startX = pos[0]; float startY = pos[1]; if (startX == endX && startY == endY) { throw new IllegalArgumentException("pattern must not end at the starting point"); } mTempMatrix.setTranslate(-startX, -startY); float dx = endX - startX; float dy = endY - startY; float distance = distance(dx, dy); float scale = 1 / distance; mTempMatrix.postScale(scale, scale); double angle = Math.atan2(dy, dx); mTempMatrix.postRotate((float) Math.toDegrees(-angle)); patternPath.transform(mTempMatrix, mPatternPath); mOriginalPatternPath = patternPath; }
PatternPathMotion extends PathMotion { public void setPatternPath(Path patternPath) { PathMeasure pathMeasure = new PathMeasure(patternPath, false); float length = pathMeasure.getLength(); float[] pos = new float[2]; pathMeasure.getPosTan(length, pos, null); float endX = pos[0]; float endY = pos[1]; pathMeasure.getPosTan(0, pos, null); float startX = pos[0]; float startY = pos[1]; if (startX == endX && startY == endY) { throw new IllegalArgumentException("pattern must not end at the starting point"); } mTempMatrix.setTranslate(-startX, -startY); float dx = endX - startX; float dy = endY - startY; float distance = distance(dx, dy); float scale = 1 / distance; mTempMatrix.postScale(scale, scale); double angle = Math.atan2(dy, dx); mTempMatrix.postRotate((float) Math.toDegrees(-angle)); patternPath.transform(mTempMatrix, mPatternPath); mOriginalPatternPath = patternPath; } }
PatternPathMotion extends PathMotion { public void setPatternPath(Path patternPath) { PathMeasure pathMeasure = new PathMeasure(patternPath, false); float length = pathMeasure.getLength(); float[] pos = new float[2]; pathMeasure.getPosTan(length, pos, null); float endX = pos[0]; float endY = pos[1]; pathMeasure.getPosTan(0, pos, null); float startX = pos[0]; float startY = pos[1]; if (startX == endX && startY == endY) { throw new IllegalArgumentException("pattern must not end at the starting point"); } mTempMatrix.setTranslate(-startX, -startY); float dx = endX - startX; float dy = endY - startY; float distance = distance(dx, dy); float scale = 1 / distance; mTempMatrix.postScale(scale, scale); double angle = Math.atan2(dy, dx); mTempMatrix.postRotate((float) Math.toDegrees(-angle)); patternPath.transform(mTempMatrix, mPatternPath); mOriginalPatternPath = patternPath; } PatternPathMotion();  PatternPathMotion(Context context, AttributeSet attrs);  PatternPathMotion(Path patternPath); }
PatternPathMotion extends PathMotion { public void setPatternPath(Path patternPath) { PathMeasure pathMeasure = new PathMeasure(patternPath, false); float length = pathMeasure.getLength(); float[] pos = new float[2]; pathMeasure.getPosTan(length, pos, null); float endX = pos[0]; float endY = pos[1]; pathMeasure.getPosTan(0, pos, null); float startX = pos[0]; float startY = pos[1]; if (startX == endX && startY == endY) { throw new IllegalArgumentException("pattern must not end at the starting point"); } mTempMatrix.setTranslate(-startX, -startY); float dx = endX - startX; float dy = endY - startY; float distance = distance(dx, dy); float scale = 1 / distance; mTempMatrix.postScale(scale, scale); double angle = Math.atan2(dy, dx); mTempMatrix.postRotate((float) Math.toDegrees(-angle)); patternPath.transform(mTempMatrix, mPatternPath); mOriginalPatternPath = patternPath; } PatternPathMotion();  PatternPathMotion(Context context, AttributeSet attrs);  PatternPathMotion(Path patternPath); Path getPatternPath(); void setPatternPath(Path patternPath); @Override Path getPath(float startX, float startY, float endX, float endY); }
PatternPathMotion extends PathMotion { public void setPatternPath(Path patternPath) { PathMeasure pathMeasure = new PathMeasure(patternPath, false); float length = pathMeasure.getLength(); float[] pos = new float[2]; pathMeasure.getPosTan(length, pos, null); float endX = pos[0]; float endY = pos[1]; pathMeasure.getPosTan(0, pos, null); float startX = pos[0]; float startY = pos[1]; if (startX == endX && startY == endY) { throw new IllegalArgumentException("pattern must not end at the starting point"); } mTempMatrix.setTranslate(-startX, -startY); float dx = endX - startX; float dy = endY - startY; float distance = distance(dx, dy); float scale = 1 / distance; mTempMatrix.postScale(scale, scale); double angle = Math.atan2(dy, dx); mTempMatrix.postRotate((float) Math.toDegrees(-angle)); patternPath.transform(mTempMatrix, mPatternPath); mOriginalPatternPath = patternPath; } PatternPathMotion();  PatternPathMotion(Context context, AttributeSet attrs);  PatternPathMotion(Path patternPath); Path getPatternPath(); void setPatternPath(Path patternPath); @Override Path getPath(float startX, float startY, float endX, float endY);  }