Example usage for android.graphics Path quadTo

List of usage examples for android.graphics Path quadTo

Introduction

In this page you can find the example usage for android.graphics Path quadTo.

Prototype

public void quadTo(float x1, float y1, float x2, float y2) 

Source Link

Document

Add a quadratic bezier from the last point, approaching control point (x1,y1), and ending at (x2,y2).

Usage

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void hideLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        controlX = mFabOriginalX * 0.98f;
    } else {//from   www  .  j a v  a2s .  c o m
        controlX = mFabOriginalX * 1.02f;
    }

    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, mFabOriginalX, mFabOriginalY + getTranslationY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_UNMORPH_DURATION);
    anim.setStartDelay(FAB_UNMORPH_DELAY);
    anim.start();

    /**
     * Animate FAB elevation back to 6dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, 0);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_UNMORPH_DURATION);
    anim.setStartDelay(FAB_UNMORPH_DELAY);
    anim.start();

    /**
     * Restore alpha of FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 255));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration(FAB_UNMORPH_DURATION);
        anim.setStartDelay(FAB_UNMORPH_DELAY);
        anim.start();
    }

    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) (Math.hypot(getWidth() / 2, getHeight() / 2)), (float) mFab.getWidth() / 2f);

    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            setVisibility(View.INVISIBLE);
            mFab.setVisibility(View.VISIBLE);
            mMorphing = false;
        }
    });
    toolbarReveal.setDuration(CIRCULAR_UNREVEAL_DURATION);
    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_UNREVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar animation back to 6dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0);
    anim.setDuration(CIRCULAR_UNREVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_UNREVEAL_DELAY);
    anim.start();
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void showLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float endFabX;
    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        endFabX = rootWidth / 2f + (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 0.98f;
    } else {//w  w  w. jav a2 s.co m
        endFabX = rootWidth / 2f - (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 1.02f;
    }

    /**
     * Animate FAB movement
     */
    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, endFabX, getY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Fade FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 0));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration((long) (FAB_MORPH_DURATION / 3f));
        anim.start();
    }

    /**
     * Animate FAB elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, dpToPixels(2));
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Create circular reveal
     */
    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) mFab.getWidth() / 2f, (float) (Math.hypot(getWidth() / 2, getHeight() / 2)));

    toolbarReveal.setDuration(CIRCULAR_REVEAL_DURATION);
    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mFab.setVisibility(View.INVISIBLE);
            setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mMorphing = false;
        }
    });

    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_REVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, dpToPixels(2));
    anim.setDuration(CIRCULAR_REVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_REVEAL_DELAY);
    anim.start();
}

From source file:cw.kop.autobackground.settings.WearSettingsFragment.java

private void drawAnalog() {
    if (!AppSettings.getTimeType().equals(AppSettings.ANALOG)) {
        return;/* ww  w .ja  v a  2 s. c  om*/
    }

    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: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 {/*w  w  w  .ja  v  a 2  s.c  om*/
            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:com.codename1.impl.android.AndroidImplementation.java

static Path cn1ShapeToAndroidPath(com.codename1.ui.geom.Shape shape, Path p) {
    //Path p = new Path();
    p.rewind();/*from w ww.  ja  v a 2 s . co m*/
    com.codename1.ui.geom.PathIterator it = shape.getPathIterator();
    //p.setWindingRule(it.getWindingRule() == com.codename1.ui.geom.PathIterator.WIND_EVEN_ODD ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO);
    float[] buf = new float[6];
    while (!it.isDone()) {
        int type = it.currentSegment(buf);
        switch (type) {
        case com.codename1.ui.geom.PathIterator.SEG_MOVETO:
            p.moveTo(buf[0], buf[1]);
            break;
        case com.codename1.ui.geom.PathIterator.SEG_LINETO:
            p.lineTo(buf[0], buf[1]);
            break;
        case com.codename1.ui.geom.PathIterator.SEG_QUADTO:
            p.quadTo(buf[0], buf[1], buf[2], buf[3]);
            break;
        case com.codename1.ui.geom.PathIterator.SEG_CUBICTO:
            p.cubicTo(buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
            break;
        case com.codename1.ui.geom.PathIterator.SEG_CLOSE:
            p.close();
            break;

        }
        it.next();
    }

    return p;
}