Example usage for android.graphics PointF PointF

List of usage examples for android.graphics PointF PointF

Introduction

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

Prototype

public PointF(float x, float y) 

Source Link

Usage

From source file:org.mozilla.gecko.gfx.ViewportMetrics.java

public ViewportMetrics(ViewportMetrics viewport) {
    mPageSize = new FloatSize(viewport.getPageSize());
    mViewportRect = new RectF(viewport.getViewport());
    PointF offset = viewport.getViewportOffset();
    mViewportOffset = new PointF(offset.x, offset.y);
    mZoomFactor = viewport.getZoomFactor();
    mViewportBias = viewport.mViewportBias;
}

From source file:com.android.tabletcustomui.views.LeftCircleContainer.java

private void addCircle(int position, final int value, float diff, double ratio) {
    final int radius = value / 2;
    final RectF mOval = new RectF();
    mOval.set(0 + diff, 0 + diff, value - diff, value - diff);

    final Paint mPaintClip = new Paint();
    mPaintClip.setStyle(Paint.Style.FILL);
    mPaintClip.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.OVERLAY));
    mPaintClip.setAntiAlias(true);/*from www  . j  a va  2  s.co  m*/

    final PointF pointF = new PointF(mOval.centerX(), mOval.centerY());
    final Path clipPath = new Path();
    clipPath.addCircle(pointF.x, pointF.y, (float) (radius * ratio), Path.Direction.CW);

    View circleView;
    if (position == 0) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 330, 10, true, mPaintClip);
                canvas.drawArc(mOval, 342, 20, true, mPaintClip);
                canvas.drawArc(mOval, 4, 10, true, mPaintClip);

                canvas.drawArc(mOval, 240, 10, true, mPaintClip);
                canvas.drawArc(mOval, 252, 20, true, mPaintClip);
                canvas.drawArc(mOval, 275, 10, true, mPaintClip);

                canvas.drawArc(mOval, 150, 10, true, mPaintClip);
                canvas.drawArc(mOval, 162, 20, true, mPaintClip);
                canvas.drawArc(mOval, 185, 10, true, mPaintClip);

                canvas.drawArc(mOval, 60, 10, true, mPaintClip);
                canvas.drawArc(mOval, 72, 20, true, mPaintClip);
                canvas.drawArc(mOval, 95, 10, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);

        animateClockWise(circleView);

    } else if (position == 1) {

        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawCircle(pointF.x, pointF.y, radius, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 2) {

        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 55, 190, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 3) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 240, 190, true, mPaintClip);
                canvas.drawArc(mOval, 80, 150, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 4) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 335, 150, true, mPaintClip);
                canvas.drawArc(mOval, 140, 180, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 5) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_grey));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 330, 150, true, mPaintClip);
                canvas.drawArc(mOval, 140, 150, true, mPaintClip);
            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateClockWise(circleView);

    } else if (position == 6) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_purple_color));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 290, 5, true, mPaintClip);
                canvas.drawArc(mOval, 297, 20, true, mPaintClip);
                canvas.drawArc(mOval, 319, 20, true, mPaintClip);

                canvas.drawArc(mOval, 60, 15, true, mPaintClip);
                canvas.drawArc(mOval, 77, 8, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);

        animateClockWise(circleView);

    } else if (position == 7) {
        mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue));
        circleView = new View(getContext()) {

            @Override
            protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);

                canvas.clipPath(clipPath, Region.Op.DIFFERENCE);

                canvas.drawArc(mOval, 160, 10, true, mPaintClip);
                canvas.drawArc(mOval, 172, 30, true, mPaintClip);
                canvas.drawArc(mOval, 204, 30, true, mPaintClip);
                canvas.drawArc(mOval, 236, 10, true, mPaintClip);

                canvas.drawArc(mOval, 20, 20, true, mPaintClip);
                canvas.drawArc(mOval, 42, 8, true, mPaintClip);

            }
        };

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value);
        layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
        circleView.setLayoutParams(layoutParams);

        this.addView(circleView);
        animateAntiClockWise(circleView);
    }
}

From source file:com.zhihu.android.app.mirror.widget.ArtboardView.java

private GestureDetector.SimpleOnGestureListener buildSimpleOnGestureListener() {
    return new GestureDetector.SimpleOnGestureListener() {
        @Override/*  w  w w.ja v a  2s  . c o  m*/
        public boolean onDoubleTap(MotionEvent event) {
            if (!isReady()) {
                return true;
            }

            float scale;
            float screenWidth = DisplayUtils.getScreenWidth(getContext());
            if (getSWidth() >= getSHeight()) {
                if (getSWidth() >= screenWidth) {
                    scale = getMinScale();
                } else {
                    scale = screenWidth / (float) getSWidth();
                }
            } else {
                scale = screenWidth / (float) getSWidth();
            }

            animateScaleAndCenter(!isScaling() ? scale : getMinScale(), new PointF(event.getX(), event.getY()))
                    .withDuration(AnimUtils.DURATION).withEasing(SubsamplingScaleImageView.EASE_OUT_QUAD)
                    .withInterruptible(false).start();
            return true;
        }
    };
}

From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java

void setFrom(PointF from) {
    if (from.x < 0f || from.x > 1f || from.y < 0f || from.y > 1f) {
        throw new IllegalArgumentException("Invalid from: " + from);
    }/*w ww  .j a v a  2  s .  c  o m*/

    if (!m_from.equals(from)) {
        m_from = new PointF(from.x, from.y);

        clearCache();
    }
}

From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java

void setTo(PointF to) {
    if (to.x < 0f || to.x > 1f || to.y < 0f || to.y > 1f) {
        throw new IllegalArgumentException("Invalid to: " + to);
    }/*from ww  w  .  j  a  v a 2 s.  com*/

    if (!m_to.equals(to)) {
        m_to = new PointF(to.x, to.y);

        clearCache();
    }
}

From source file:Main.java

/**
 * Returns the point of a given angle (in radians) on a circle.
 *
 * @param center       The center of the circle.
 * @param radius       The radius of the circle.
 * @param angleRadians The angle (in radians).
 *
 * @return The point of the given angle on the specified circle.
 *
 * @see #pointFromAngleDegrees(PointF, float, float)
 *//*from   w ww. java 2s  .c o m*/
@NonNull
public static PointF pointFromAngleRadians(@NonNull PointF center, float radius, double angleRadians) {
    return new PointF((float) (center.x + radius * cos(angleRadians)),
            (float) (center.y + radius * sin(angleRadians)));
}

From source file:org.mozilla.gecko.gfx.ViewportMetrics.java

public ViewportMetrics(JSONObject json) throws JSONException {
    float x = (float) json.getDouble("x");
    float y = (float) json.getDouble("y");
    float width = (float) json.getDouble("width");
    float height = (float) json.getDouble("height");
    float pageWidth = (float) json.getDouble("pageWidth");
    float pageHeight = (float) json.getDouble("pageHeight");
    float offsetX = (float) json.getDouble("offsetX");
    float offsetY = (float) json.getDouble("offsetY");
    float zoom = (float) json.getDouble("zoom");

    mPageSize = new FloatSize(pageWidth, pageHeight);
    mViewportRect = new RectF(x, y, x + width, y + height);
    mViewportOffset = new PointF(offsetX, offsetY);
    mZoomFactor = zoom;/*from   w w  w  .  j a  va 2 s .  c  o  m*/
    mViewportBias = new PointF(0.0f, 0.0f);
}

From source file:cc.kenai.common.AnimatedSvgView.java

private void init(Context context, AttributeSet attrs) {
    mFillPaint = new Paint();
    mFillPaint.setAntiAlias(true);//from  w  w w  . j  av  a 2  s . c  o m
    mFillPaint.setStyle(Paint.Style.FILL);

    mMarkerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, MARKER_LENGTH_DIP,
            getResources().getDisplayMetrics());

    mTraceColors = new int[1];
    mTraceColors[0] = Color.BLACK;
    mTraceResidueColors = new int[1];
    mTraceResidueColors[0] = Color.argb(50, 0, 0, 0);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedSvgView);

        mViewportWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        Log.i(TAG, "mViewportWidth=" + mViewportWidth);
        mRatioSizingInfo.aspectRatioWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        mViewportHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);
        mRatioSizingInfo.aspectRatioHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);

        mTraceTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTime, 2000);
        mTraceTimePerGlyph = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTimePerGlyph, 1000);
        mFillStart = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillStart, 1200);
        mFillTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillTime, 1000);

        a.recycle();

        mViewport = new PointF(mViewportWidth, mViewportHeight);
    }
    loadConfig();
}

From source file:org.epstudios.epcalipers.CalipersView.java

private void setTouchedCaliper(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();
    touchedCaliper = null;/*from  w w w. jav  a 2 s  .  c om*/
    PointF p = new PointF(x, y);
    for (int i = calipersCount() - 1; i >= 0; i--) {
        if (calipers.get(i).pointNearCaliper(p) && touchedCaliper == null) {
            touchedCaliper = calipers.get(i);
            touchedCaliper.setTouchedBar(Caliper.TouchedBar.NONE);
            if (touchedCaliper.pointNearCrossBar(p)) {
                touchedCaliper.setTouchedBar(Caliper.TouchedBar.CROSSBAR);
            } else if (touchedCaliper.pointNearBar1(p)) {
                touchedCaliper.setTouchedBar(Caliper.TouchedBar.BAR1);
            } else if (touchedCaliper.pointNearBar2(p)) {
                touchedCaliper.setTouchedBar(Caliper.TouchedBar.BAR2);
            }
        }
    }
}

From source file:oak.animatedsvgview.AnimatedSvgView.java

@SuppressWarnings("NewApi")
private void init(Context context, AttributeSet attrs) {
    mFillPaint = new Paint();
    mFillPaint.setAntiAlias(true);//from  www  . j  av a 2s . c o m
    mFillPaint.setStyle(Paint.Style.FILL);

    mMarkerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, MARKER_LENGTH_DIP,
            getResources().getDisplayMetrics());

    mTraceColors = new int[1];
    mTraceColors[0] = Color.BLACK;
    mTraceResidueColors = new int[1];
    mTraceResidueColors[0] = Color.argb(50, 0, 0, 0);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedSvgView);

        mViewportWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        mRatioSizingInfo.aspectRatioWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        mViewportHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);
        mRatioSizingInfo.aspectRatioHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);

        mTraceTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTime, 2000);
        mTraceTimePerGlyph = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTimePerGlyph, 1000);
        mFillStart = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillStart, 1200);
        mFillTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillTime, 1000);

        a.recycle();

        mViewport = new PointF(mViewportWidth, mViewportHeight);
    }

    // See https://github.com/romainguy/road-trip/blob/master/application/src/main/java/org/curiouscreature/android/roadtrip/IntroView.java
    // Note: using a software layer here is an optimization. This view works with
    // hardware accelerated rendering but every time a path is modified (when the
    // dash path effect is modified), the graphics pipeline will rasterize the path
    // again in a new texture. Since we are dealing with dozens of paths, it is much
    // more efficient to rasterize the entire view into a single re-usable texture
    // instead. Ideally this should be toggled using a heuristic based on the number
    // and or dimensions of paths to render.
    // Note that PathDashPathEffects can lead to clipping issues with hardware rendering.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
}