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() 

Source Link

Usage

From source file:com.dgmltn.ranger.internal.AbsRangeBar.java

private boolean setPinIndex(PinView pinView, int index, PointF point) {
    //PbLog.e(TAG, "setPinIndex(pinView=" + pinView + ", index=" + index + ", point=" + point + ')');
    if (pinView == null) {
        return false;
    }// ww w  . j  av a 2  s  . co  m

    PointF pointIndex = new PointF();
    if (point == null) {
        getPointOfIndex(index, pointIndex);
    } else {
        getNearestPointOnBar(point, pointIndex);
    }
    //PbLog.e(TAG, "setPinIndex: pointIndex=" + pointIndex);

    int indexMin;
    int indexMax;
    if (mFirstPinView.equals(pinView)) {
        indexMin = 0;
        indexMax = mSecondPinView.getIndex() - 1;
    } else if (mSecondPinView.equals(pinView)) {
        indexMin = mFirstPinView.getIndex() + 1;
        indexMax = mTickCount - 1;
    } else {
        //PbLog.e(TAG, "setPinIndex: pinView != mFirstPinView || pinView != mSecondPinView; ignoring");
        return false;
    }

    //PbLog.e(TAG, "setPinIndex: indexMin=" + indexMin);
    //PbLog.e(TAG, "setPinIndex: indexMax=" + indexMax);

    PointF pointMin = new PointF();
    getPointOfIndex(indexMin, pointMin);
    //PbLog.e(TAG, "setPinIndex: pointMin=" + pointMin);
    PointF pointMax = new PointF();
    getPointOfIndex(indexMax, pointMax);
    //PbLog.e(TAG, "setPinIndex: pointMax=" + pointMax);

    boolean changed = false;
    if (comparePointsOnBar(pointMin, pointIndex) > 0) {
        pointIndex = pointMin;
        index = indexMin;
    } else if (comparePointsOnBar(pointIndex, pointMax) > 0) {
        pointIndex = pointMax;
        index = indexMax;
    } else {
        changed = pinView.setIndex(index);
    }
    //PbLog.e(TAG, "setPinIndex: changed=" + changed);

    movePin(pinView, pointIndex);

    String label = getPinLabel(index);
    pinView.setLabel(label);

    return changed;
}

From source file:com.mylikes.likes.etchasketch.Slate.java

PointF getCenter(MotionEvent event, PointF out) {
    int P = event.getPointerCount();
    PointF pt = ((out == null) ? new PointF() : out);
    pt.set(event.getX(0), event.getY(0));
    final int zero[] = { 0, 0 };
    getLocationOnScreen(zero);//from w w w  . j  a va2s  .  c o  m
    for (int j = 1; j < P; j++) {
        pt.x += event.getX(j) + zero[0];
        pt.y += event.getY(j) + zero[1];
    }
    pt.x /= P;
    pt.y /= P;
    return pt;
}

From source file:com.google.android.apps.forscience.whistlepunk.RunReviewOverlay.java

public void setOnLabelClickListener(OnLabelClickListener onLabelClickListener) {
    mOnLabelClickListener = onLabelClickListener;
    this.setOnTouchListener(new OnTouchListener() {
        private PointF downPoint = new PointF();

        @Override/*from ww w.j av  a2 s .co  m*/
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                if ((!mIsCropping && eventOnFlag(event, mPointData)) || mIsCropping
                        && (eventOnFlag(event, mCropStartData) || eventOnFlag(event, mCropEndData))) {
                    downPoint.set(event.getX(), event.getY());
                    return true;
                }
            } else if (event.getActionMasked() == MotionEvent.ACTION_UP) {
                // See if the click is ending in any of the label boxes
                if (!mIsCropping && eventOnFlag(event, mPointData)
                        && mPointData.labelRect.contains(downPoint.x, downPoint.y)) {
                    mOnLabelClickListener.onValueLabelClicked();
                    return true;
                } else if (mIsCropping && eventOnFlag(event, mCropStartData)
                        && mCropStartData.labelRect.contains(downPoint.x, downPoint.y)) {
                    mOnLabelClickListener.onCropStartLabelClicked();
                    return true;
                } else if (mIsCropping && eventOnFlag(event, mCropEndData)
                        && mCropEndData.labelRect.contains(downPoint.x, downPoint.y)) {
                    mOnLabelClickListener.onCropEndLabelClicked();
                    return true;
                }
            }
            return false;
        }

        private boolean eventOnFlag(MotionEvent event, OverlayPointData pointData) {
            return pointData.labelRect.contains(event.getX(), event.getY());
        }
    });
    // TODO: P3: Could add an ExploreByTouchHelper to make these discoverable for a11y users.
    // Since the same functionality is accessible from the menu options, this is not high
    // priority.
    // https://developer.android.com/reference/android/support/v4/widget/ExploreByTouchHelper.html
}

From source file:xyz.zpayh.hdimage.HDImageView.java

private void preDraw() {
    if (getWidth() == 0 || getHeight() == 0 || mSourceWidth <= 0 || mSourceHeight <= 0) {
        return;//from w w w.ja  v a2s  .  c o  m
    }

    if (mSourcePendingCenter != null && mPendingScale > -1f) {

        if (mViewTranslate == null) {
            mViewTranslate = new PointF();
        }

        mScale = mPendingScale;
        mViewTranslate.x = getWidth() / 2.0F - mScale * mSourcePendingCenter.x;
        mViewTranslate.y = getHeight() / 2.0F - mScale * mSourcePendingCenter.y;
        mSourcePendingCenter = null;
        mPendingScale = -1f;
        fitToBounds(true);
        refreshRequiredTiles(true);
    }

    fitToBounds(false);
}

From source file:com.dgmltn.ranger.internal.AbsRangeBar.java

private void initPin(PinView pinView, int pinColor, int pinTextColor, int pinSelectorColor) {

    int pinIndex = pinView.getIndex();

    PointF pinPoint = new PointF();
    getPointOfIndex(pinIndex, pinPoint);

    pinView.init(pinPoint, 0, pinColor, pinTextColor, mSelectorSize, pinSelectorColor, mMinPinFont,
            mMaxPinFont);/*from w  w  w. j  a  v  a2  s .c  o  m*/

    pinView.setLabel(getPinLabel(pinIndex));
}

From source file:com.dgmltn.ranger.internal.AbsRangeBar.java

/**
 * Set the thumb to be in the normal/un-pressed state and calls invalidate()
 * to redraw the canvas to reflect the updated state.
 *
 * @param pinView the thumb to release/*from  w w  w .  j  a va 2 s  .  co m*/
 */
private void releasePin(final PinView pinView) {
    PointF point = new PointF();
    getNearestIndexPosition(pinView.getPosition(), point);
    pinView.setPosition(point);
    int tickIndex = getNearestIndex(pinView);

    pinView.setLabel(getPinLabel(tickIndex));

    if (mArePinsTemporary) {
        ValueAnimator animator = ValueAnimator.ofFloat(mExpandedPinRadius, 0);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mPinRadius = (Float) (animation.getAnimatedValue());
                pinView.setSize(mPinRadius, mPinPadding - (mPinPadding * animation.getAnimatedFraction()));
                invalidate();
            }
        });
        animator.start();
        pinView.release();
    } else {
        invalidate();
    }
}

From source file:com.dgmltn.ranger.internal.AbsRangeBar.java

/**
 * Draws the tick marks on the bar.//  w  w w  .  j a  va2s  . c o m
 *
 * @param canvas Canvas to draw on; should be the Canvas passed into {#link
 *               View#onDraw()}
 */
protected void drawTicks(Canvas canvas) {
    PointF tempPoint = new PointF();
    for (int i = 0; i < mTickCount; i++) {
        getPointOfIndex(i, tempPoint);
        canvas.drawCircle(tempPoint.x, tempPoint.y, mTickSize, mTickPaint);
    }
}

From source file:xyz.zpayh.hdimage.HDImageView.java

/**
 * ???????//from   w  ww  .jav a  2  s.com
 * @param viewCoordinate view??
 * @return
 *  ??
 */
public final PointF viewToSourceCoordinate(@NonNull PointF viewCoordinate) {
    return viewToSourceCoordinate(viewCoordinate.x, viewCoordinate.y, new PointF());
}

From source file:xyz.zpayh.hdimage.HDImageView.java

/**
 * ???????//from  www .  ja v a 2  s.  c  om
 * @param viewX viewx??
 * @param viewY viewy??
 * @return
 *  ??
 */
public final PointF viewToSourceCoordinate(float viewX, float viewY) {
    return viewToSourceCoordinate(viewX, viewY, new PointF());
}

From source file:xyz.zpayh.hdimage.HDImageView.java

/**
 * ???????//from   ww  w.  j  a va2  s  .  c o m
 * @param sourceCoordinate ???
 * @return
 *  ??
 */
public final PointF sourceToViewCoordinate(@NonNull PointF sourceCoordinate) {
    return sourceToViewCoordinate(sourceCoordinate.x, sourceCoordinate.y, new PointF());
}