use of android.graphics.Path in project material by rey5137.
the class Switch method buildShadow.
private void buildShadow() {
if (mShadowSize <= 0)
return;
if (mShadowPaint == null) {
mShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mShadowPaint.setStyle(Paint.Style.FILL);
mShadowPaint.setDither(true);
}
float startRatio = (float) mThumbRadius / (mThumbRadius + mShadowSize + mShadowOffset);
mShadowPaint.setShader(new RadialGradient(0, 0, mThumbRadius + mShadowSize, new int[] { COLOR_SHADOW_START, COLOR_SHADOW_START, COLOR_SHADOW_END }, new float[] { 0f, startRatio, 1f }, Shader.TileMode.CLAMP));
if (mShadowPath == null) {
mShadowPath = new Path();
mShadowPath.setFillType(Path.FillType.EVEN_ODD);
} else
mShadowPath.reset();
float radius = mThumbRadius + mShadowSize;
mTempRect.set(-radius, -radius, radius, radius);
mShadowPath.addOval(mTempRect, Path.Direction.CW);
radius = mThumbRadius - 1;
mTempRect.set(-radius, -radius - mShadowOffset, radius, radius - mShadowOffset);
mShadowPath.addOval(mTempRect, Path.Direction.CW);
}
use of android.graphics.Path in project android-tooltips by rharter.
the class ToolTipPointerView method onDraw.
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Path p = new Path();
if ((Gravity.VERTICAL_GRAVITY_MASK & mGravity) == Gravity.TOP) {
// Top
p.moveTo(0, 0);
p.lineTo(getWidth() / 2, getHeight());
p.lineTo(getWidth(), 0);
p.lineTo(0, 0);
} else if ((Gravity.VERTICAL_GRAVITY_MASK & mGravity) == Gravity.BOTTOM) {
// Bottom
p.moveTo(0, getHeight());
p.lineTo(getWidth() / 2, 0);
p.lineTo(getWidth(), getHeight());
p.lineTo(0, getHeight());
} else if ((Gravity.LEFT & mGravity) == Gravity.LEFT) {
// Left
p.moveTo(0, 0);
p.lineTo(getWidth(), getHeight() / 2);
p.lineTo(0, getHeight());
p.lineTo(0, 0);
} else if ((Gravity.RIGHT & mGravity) == Gravity.RIGHT) {
// Right
p.moveTo(getWidth(), 0);
p.lineTo(0, getHeight() / 2);
p.lineTo(getWidth(), getHeight());
p.lineTo(getWidth(), 0);
}
canvas.drawPath(p, mPaint);
}
use of android.graphics.Path in project fitscales by paulburton.
the class ScaleView method renderBmi.
private void renderBmi(Canvas canvas, float bmi, Paint bmiPaint, Paint bmiPaintTriangle, String text, Paint textPaint) {
if (bmi < minBmi || bmi > maxBmi)
return;
if (w > h) {
/* horizontal */
float x = Math.round(w * ((bmi - minBmi) / (maxBmi - minBmi)));
canvas.drawLine(x, barOffset / 2, x, h, bmiPaint);
if (bmiPaintTriangle != null) {
float len = barOffset * 0.6f;
Path p = new Path();
p.moveTo(x - (len / 2), barOffset / 2);
/* tl */
p.lineTo(x + (len / 2), barOffset / 2);
/* tr */
p.lineTo(x, (barOffset / 2) + (float) ((len / 2) / Math.sin(Math.PI / 6)));
/* b */
p.close();
canvas.drawPath(p, bmiPaintTriangle);
}
if (text != null && textPaint != null)
canvas.drawText(text, x + (h / 10), barRect.centerY() - (h / 8), textPaint);
} else {
/* vertical */
float y = Math.round(h * (1.0f - (bmi - minBmi) / (maxBmi - minBmi)));
canvas.drawLine(barOffset / 2, y, w, y, bmiPaint);
if (bmiPaintTriangle != null) {
float len = barOffset * 0.6f;
Path p = new Path();
p.moveTo(barOffset / 2, y - (len / 2));
/* bl */
p.lineTo(barOffset / 2, y + (len / 2));
/* tl */
p.lineTo((barOffset / 2) + (float) ((len / 2) / Math.sin(Math.PI / 6)), y);
/* r */
p.close();
canvas.drawPath(p, bmiPaintTriangle);
}
if (text != null && textPaint != null)
canvas.drawText(text, barRect.centerX(), y - (w / 10), textPaint);
}
}
use of android.graphics.Path in project kickmaterial by byoutline.
the class CircleTransition method createAnimator.
@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, final TransitionValues endValues) {
if (startValues == null || endValues == null) {
return null;
}
Rect startBounds = (Rect) startValues.values.get(PROPERTY_BOUNDS);
Rect endBounds = (Rect) endValues.values.get(PROPERTY_BOUNDS);
boolean boundsEqual = startBounds == null || endBounds == null || startBounds.equals(endBounds);
if (boundsEqual) {
return null;
}
int[] sceneRootLoc = new int[2];
sceneRoot.getLocationInWindow(sceneRootLoc);
int[] startLoc = (int[]) startValues.values.get(PROPERTY_POSITION);
final View startView = getStartView(sceneRoot, startValues, sceneRootLoc, startLoc);
final View endView = endValues.view;
endView.setAlpha(0f);
Path circlePath = getMovePath(endValues, startView, sceneRootLoc, startLoc, endView);
Animator circleAnimator = ObjectAnimator.ofFloat(startView, View.TRANSLATION_X, View.TRANSLATION_Y, circlePath);
circleAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
startView.setVisibility(View.INVISIBLE);
endView.setAlpha(1f);
sceneRoot.getOverlay().remove(startView);
}
});
AnimatorSet moveSet = new AnimatorSet();
float scaleRatio = ((float) endView.getWidth()) / startView.getWidth();
ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(startView, View.SCALE_X, 1, scaleRatio);
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(startView, View.SCALE_Y, 1, scaleRatio);
moveSet.playTogether(circleAnimator, scaleXAnimator, scaleYAnimator);
return moveSet;
}
use of android.graphics.Path in project UltimateAndroid by cymcsg.
the class SearchDrawable method createSearchPath.
private void createSearchPath(float phase) {
RectF oval = new RectF(0.0f, 0.0f, mRadius * 2.0f, mRadius * 2.0f);
float cx = oval.centerX();
float cy = oval.centerY();
float rx = oval.width() / 2.0f;
float ry = oval.height() / 2.0f;
final float TAN_PI_OVER_8 = 0.414213562f;
final float ROOT_2_OVER_2 = 0.707106781f;
float sx = rx * TAN_PI_OVER_8;
float sy = ry * TAN_PI_OVER_8;
float mx = rx * ROOT_2_OVER_2;
float my = ry * ROOT_2_OVER_2;
float L = oval.left;
float T = oval.top;
float R = oval.right;
float B = oval.bottom;
mPath = new Path();
mPath.moveTo(cx + mx, cy + my);
mPath.quadTo(cx + sx, B, cx, B);
mPath.quadTo(cx - sx, B, cx - mx, cy + my);
mPath.quadTo(L, cy + sy, L, cy);
mPath.quadTo(L, cy - sy, cx - mx, cy - my);
mPath.quadTo(cx - sx, T, cx, T);
mPath.quadTo(cx + sx, T, cx + mx, cy - my);
mPath.quadTo(R, cy - sy, R, cy);
mPath.quadTo(R, cy + sy, cx + mx, cy + my);
mPath.lineTo(1.5f * R, 1.5f * B);
}
Aggregations