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.catrobat.paintroid.test.integration.BaseIntegrationTestClass.java

protected PointF getScreenPointFromSurfaceCoordinates(float pointX, float pointY) {
    return new PointF(pointX, pointY + getStatusbarHeight() + getActionbarHeight());
}

From source file:cn.ismartv.tvrecyclerview.widget.LinearLayoutManager.java

@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
    if (getChildCount() == 0) {
        return null;
    }/*from  w ww  . j a  v a 2  s .co  m*/
    final int firstChildPos = getPosition(getChildAt(0));
    final int direction = targetPosition < firstChildPos != mShouldReverseLayout ? -1 : 1;
    if (mOrientation == HORIZONTAL) {
        return new PointF(direction, 0);
    } else {
        return new PointF(0, direction);
    }
}

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

/**
 * Some logic ideas came from:/*from  w w w .j a v a  2  s  .c o m*/
 * https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/AbsSeekBar.java#L564
 *
 * @param event
 * @return
 */
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!isEnabled()) {
        return false;
    }

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        //PbLog.e(TAG, "onTouchEvent: ACTION_DOWN");
        if (isInScrollingContainer()) {
            //PbLog.e(TAG, "onTouchEvent: ACTION_DOWN isInScrollingContainer() == true; waiting for slop");
            mTouchDown = new PointF(event.getX(), event.getY());
        } else {
            //PbLog.e(TAG, "onTouchEvent: ACTION_DOWN isInScrollingContainer() == false; start tracking/processing");
            setPressed(true);
            //if (mThumb != null) {
            //    invalidate(mThumb.getBounds()); // This may be within the padding region
            //}
            invalidate();
            onStartTrackingTouch();
            trackTouchEvent(event);
            attemptClaimDrag();
        }
        break;
    case MotionEvent.ACTION_MOVE:
        //PbLog.e(TAG, "onTouchEvent: ACTION_MOVE");
        if (mIsTrackingTouch) {
            //PbLog.e(TAG, "onTouchEvent: ACTION_MOVE mIsTrackingTouch == true; track/process");
            trackTouchEvent(event);
        } else {
            final float x = event.getX();
            if (mTouchDown != null && Math.abs(x - mTouchDown.x) > mScaledTouchSlop) {
                //PbLog.e(TAG, "onTouchEvent: ACTION_MOVE mIsTrackingTouch == false; slop exceeded; start tracking/processing");
                setPressed(true);
                //if (mThumb != null) {
                //    invalidate(mThumb.getBounds()); // This may be within the padding region
                //}
                invalidate();
                onStartTrackingTouch();
                trackTouchEvent(event);
                attemptClaimDrag();
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        //PbLog.e(TAG, "onTouchEvent: ACTION_UP");
        if (mIsTrackingTouch) {
            //PbLog.e(TAG, "onTouchEvent: ACTION_UP mIsTrackingTouch == true; track/process and stop tracking/processing");
            trackTouchEvent(event);
            onStopTrackingTouch();
            setPressed(false);
        } else {
            //PbLog.e(TAG, "onTouchEvent: ACTION_UP mIsTrackingTouch == false; start and stop tracking/processing tap-seek");
            // Touch up when we never crossed the touch slop threshold should
            // be interpreted as a tap-seek to that location.
            onStartTrackingTouch();
            trackTouchEvent(event);
            onStopTrackingTouch();
        }
        mTouchDown = null;
        // ProgressBar doesn't know to repaint the thumb drawable
        // in its inactive state when the touch stops (because the
        // value has not apparently changed)
        invalidate();
        break;
    case MotionEvent.ACTION_CANCEL:
        //PbLog.e(TAG, "onTouchEvent: ACTION_CANCEL");
        if (mIsTrackingTouch) {
            //PbLog.e(TAG, "onTouchEvent: ACTION_CANCEL mIsTrackingTouch == true; stop tracking/processing");
            onStopTrackingTouch();
            setPressed(false);
        }
        mTouchDown = null;
        invalidate(); // see above explanation
        break;
    }
    return true;
}

From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java

private void setGestureDetector(final Context context) {
    this.detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override/*  w w w.  jav a2 s .  c  om*/
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (panEnabled && readySent && vTranslate != null && e1 != null && e2 != null
                    && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50)
                    && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !isZooming) {
                PointF vTranslateEnd = new PointF(vTranslate.x + (velocityX * 0.25f),
                        vTranslate.y + (velocityY * 0.25f));
                float sCenterXEnd = ((getWidth() / 2) - vTranslateEnd.x) / scale;
                float sCenterYEnd = ((getHeight() / 2) - vTranslateEnd.y) / scale;
                new AnimationBuilder(new PointF(sCenterXEnd, sCenterYEnd)).withEasing(EASE_OUT_QUAD)
                        .withPanLimited(false).start();
                return true;
            }
            return super.onFling(e1, e2, velocityX, velocityY);
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (doubleTapListener != null) {
                return doubleTapListener.onSingleTapConfirmed(e);
            }
            performClick();
            return true;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (zoomEnabled && readySent && vTranslate != null) {
                float doubleTapZoomScale = Math.min(maxScale,
                        SubsamplingScaleImageView.this.doubleTapZoomScale);
                boolean zoomIn = scale <= doubleTapZoomScale * 0.9;
                float targetScale = zoomIn ? doubleTapZoomScale
                        : Math.min(getWidth() / (float) sWidth(), getHeight() / (float) sHeight());
                PointF targetSCenter = viewToSourceCoord(new PointF(e.getX(), e.getY()));
                if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER_IMMEDIATE) {
                    setScaleAndCenter(targetScale, targetSCenter);
                } else if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER || !zoomIn) {
                    new AnimationBuilder(targetScale, targetSCenter).withInterruptible(false).start();
                } else if (doubleTapZoomStyle == ZOOM_FOCUS_FIXED) {
                    new AnimationBuilder(targetScale, targetSCenter, new PointF(e.getX(), e.getY()))
                            .withInterruptible(false).start();
                }

                // Hacky solution for #15 - after a double tap the
                // GestureDetector gets in a state where the next
                // fling is ignored, so here we replace it with a
                // new one.
                setGestureDetector(context);

                invalidate();
                return true;
            }
            return super.onDoubleTapEvent(e);
        }
    });
}

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

private void setClickGesture(Context context) {
    mClickDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {

        @Override/*  www .j  ava2  s . co  m*/
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (BuildConfig.DEBUG)
                Log.d(TAG, "?");
            performClick();
            return true;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (BuildConfig.DEBUG)
                Log.d(TAG, "?");
            if (mZoomEnabled && mQuickScaleEnabled && mReadySent && mViewTranslate != null) {
                //????
                setFilingGesture(getContext());
                PointF sourceCenter = viewToSourceCoordinate(new PointF(e.getX(), e.getY()));
                PointF viewFocus = new PointF(e.getX(), e.getY());
                startDoubleTapAnimator(sourceCenter, viewFocus);
                return true;
            }
            return false;
        }
    });
}

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

private void setFilingGesture(Context context) {
    mFlingDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override/*w w w.jav a 2s  . c om*/
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

            if (mTranslateEnabled && mReadySent && mViewTranslate != null && e1 != null && e2 != null
                    && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50)
                    && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !mIsZooming) {
                PointF vTranslateEnd = new PointF(mViewTranslate.x + (velocityX * 0.25f),
                        mViewTranslate.y + (velocityY * 0.25f));
                float sCenterXEnd = ((getWidth() / 2.0F) - vTranslateEnd.x) / mScale;
                float sCenterYEnd = ((getHeight() / 2.0F) - vTranslateEnd.y) / mScale;
                startFilingAnimation(sCenterXEnd, sCenterYEnd);
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "onFling: ");
                return true;
            }
            return false;
        }
    });
}

From source file:com.google.android.flexbox.FlexboxLayoutManager.java

@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
    if (getChildCount() == 0) {
        return null;
    }//w w  w.  j ava  2s . c  o  m
    int firstChildPos = getPosition(getChildAt(0));
    int direction = targetPosition < firstChildPos ? -1 : 1;
    if (isMainAxisDirectionHorizontal()) {
        return new PointF(0, direction);
    } else {
        return new PointF(direction, 0);
    }
}

From source file:com.here.android.example.venue.Venue3dActivity.java

@Override
public void onVenueTapped(Venue venue, float x, float y) {
    m_currentVenue = m_mapFragment.getVenueController(venue);
    m_map.pixelToGeo(new PointF(x, y));
    m_currentVenue.getVenue().getId();/*from w w  w . ja  va  2 s.  c  om*/
    m_mapFragment.selectVenue(venue);
}

From source file:xiaofan.llongimageview.view.SubsamplingScaleImageView.java

/**
 * Handle touch events. One finger pans, and two finger pinch and zoom plus panning.
 *///from   ww  w . ja v  a 2 s  .co m
@Override
public boolean onTouchEvent(MotionEvent event) {
    PointF vCenterEnd;
    float vDistEnd;
    // During non-interruptible anims, ignore all touch events
    if (anim != null && !anim.interruptible) {
        getParent().requestDisallowInterceptTouchEvent(true);
        return true;
    } else {
        anim = null;
    }

    // Abort if not ready
    if (vTranslate == null) {
        return true;
    }
    // Detect flings, taps and double taps
    if (detector == null || detector.onTouchEvent(event)) {
        return true;
    }

    int touchCount = event.getPointerCount();
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_1_DOWN:
    case MotionEvent.ACTION_POINTER_2_DOWN:
        anim = null;
        getParent().requestDisallowInterceptTouchEvent(true);
        maxTouchCount = Math.max(maxTouchCount, touchCount);
        if (touchCount >= 2) {
            if (zoomEnabled) {
                // Start pinch to zoom. Calculate distance between touch points and center point of the pinch.
                float distance = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                scaleStart = scale;
                vDistStart = distance;
                vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                vCenterStart = new PointF((event.getX(0) + event.getX(1)) / 2,
                        (event.getY(0) + event.getY(1)) / 2);
            } else {
                // Abort all gestures on second touch
                maxTouchCount = 0;
            }
            // Cancel long click timer
            handler.removeMessages(MESSAGE_LONG_CLICK);
        } else {
            // Start one-finger pan
            vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
            vCenterStart = new PointF(event.getX(), event.getY());

            // Start long click timer
            handler.sendEmptyMessageDelayed(MESSAGE_LONG_CLICK, 600);
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        boolean consumed = false;
        if (maxTouchCount > 0) {
            if (touchCount >= 2) {
                // Calculate new distance between touch points, to scale and pan relative to start values.
                vDistEnd = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                vCenterEnd = new PointF((event.getX(0) + event.getX(1)) / 2,
                        (event.getY(0) + event.getY(1)) / 2);

                if (zoomEnabled && (distance(vCenterStart.x, vCenterEnd.x, vCenterStart.y, vCenterEnd.y) > 5
                        || Math.abs(vDistEnd - vDistStart) > 5 || isPanning)) {
                    isZooming = true;
                    isPanning = true;
                    consumed = true;

                    scale = Math.min(maxScale, (vDistEnd / vDistStart) * scaleStart);

                    if (scale <= minScale()) {
                        // Minimum scale reached so don't pan. Adjust start settings so any expand will zoom in.
                        vDistStart = vDistEnd;
                        scaleStart = minScale();
                        vCenterStart = vCenterEnd;
                        vTranslateStart = vTranslate;
                    } else if (panEnabled) {
                        // Translate to place the source image coordinate that was at the center of the pinch at the start
                        // at the center of the pinch now, to give simultaneous pan + zoom.
                        float vLeftStart = vCenterStart.x - vTranslateStart.x;
                        float vTopStart = vCenterStart.y - vTranslateStart.y;
                        float vLeftNow = vLeftStart * (scale / scaleStart);
                        float vTopNow = vTopStart * (scale / scaleStart);
                        vTranslate.x = vCenterEnd.x - vLeftNow;
                        vTranslate.y = vCenterEnd.y - vTopNow;
                    } else if (sRequestedCenter != null) {
                        // With a center specified from code, zoom around that point.
                        vTranslate.x = (getWidth() / 2) - (scale * sRequestedCenter.x);
                        vTranslate.y = (getHeight() / 2) - (scale * sRequestedCenter.y);
                    } else {
                        // With no requested center, scale around the image center.
                        vTranslate.x = (getWidth() / 2) - (scale * (sWidth() / 2));
                        vTranslate.y = (getHeight() / 2) - (scale * (sHeight() / 2));
                    }

                    fitToBounds(true);
                    refreshRequiredTiles(false);
                }
            } else if (!isZooming) {
                // One finger pan - translate the image. We do this calculation even with pan disabled so click
                // and long click behaviour is preserved.
                float dx = Math.abs(event.getX() - vCenterStart.x);
                float dy = Math.abs(event.getY() - vCenterStart.y);
                if (dx > 5 || dy > 5 || isPanning) {
                    consumed = true;
                    vTranslate.x = vTranslateStart.x + (event.getX() - vCenterStart.x);
                    vTranslate.y = vTranslateStart.y + (event.getY() - vCenterStart.y);

                    float lastX = vTranslate.x;
                    float lastY = vTranslate.y;
                    fitToBounds(true);
                    if (lastX == vTranslate.x || (lastY == vTranslate.y && dy > 10) || isPanning) {
                        isPanning = true;
                    } else if (dx > 5) {
                        // Haven't panned the image, and we're at the left or right edge. Switch to page swipe.
                        maxTouchCount = 0;
                        handler.removeMessages(MESSAGE_LONG_CLICK);
                        getParent().requestDisallowInterceptTouchEvent(false);
                    }

                    if (!panEnabled) {
                        vTranslate.x = vTranslateStart.x;
                        vTranslate.y = vTranslateStart.y;
                        getParent().requestDisallowInterceptTouchEvent(false);
                    }

                    refreshRequiredTiles(false);
                }
            }
        }
        if (consumed) {
            handler.removeMessages(MESSAGE_LONG_CLICK);
            invalidate();
            return true;
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_POINTER_2_UP:
        handler.removeMessages(MESSAGE_LONG_CLICK);
        if (maxTouchCount > 0 && (isZooming || isPanning)) {
            if (isZooming && touchCount == 2) {
                // Convert from zoom to pan with remaining touch
                isPanning = true;
                vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                if (event.getActionIndex() == 1) {
                    vCenterStart = new PointF(event.getX(0), event.getY(0));
                } else {
                    vCenterStart = new PointF(event.getX(1), event.getY(1));
                }
            }
            if (touchCount < 3) {
                // End zooming when only one touch point
                isZooming = false;
            }
            if (touchCount < 2) {
                // End panning when no touch points
                isPanning = false;
                maxTouchCount = 0;
            }
            // Trigger load of tiles now required
            refreshRequiredTiles(true);
            return true;
        }
        if (touchCount == 1) {
            isZooming = false;
            isPanning = false;
            maxTouchCount = 0;
        }
        return true;
    }
    return super.onTouchEvent(event);
}

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

/**
 * From:/*ww w .  j  a  v a 2 s .  c o m*/
 * ...
 *
 * @param event
 */
private void trackTouchEvent(MotionEvent event) {
    //PbLog.e(TAG, "trackTouchEvent(event=" + event + ')');
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mDraggingPin = getTargetPinView(event.getX(), event.getY());
        //PbLog.e(TAG, "trackTouchEvent: ACTION_DOWN mDraggingPin=" + mDraggingPin);
        if (mDraggingPin != null) {
            pressPin(mDraggingPin);
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDraggingPin == null && mTouchDown != null) {
            mDraggingPin = getTargetPinView(mTouchDown.x, mTouchDown.y);
            //PbLog.e(TAG, "trackTouchEvent: ACTION_MOVE mDraggingPin=" + mDraggingPin);
            if (mDraggingPin != null) {
                pressPin(mDraggingPin);
            }
        }
        if (mDraggingPin != null) {
            int nearestTickIndex = getNearestIndex(mDraggingPin);
            //PbLog.e(TAG, "trackTouchEvent: ACTION_MOVE nearestTickIndex=" + nearestTickIndex);
            PointF point = new PointF(event.getX(), event.getY());

            int firstPinIndex = -1;
            int secondPinIndex = -1;
            if (mFirstPinView.equals(mDraggingPin)) {
                firstPinIndex = nearestTickIndex;
                secondPinIndex = mSecondPinView.getIndex();
            } else if (mSecondPinView.equals(mDraggingPin)) {
                firstPinIndex = mFirstPinView.getIndex();
                secondPinIndex = nearestTickIndex;
            }

            if (firstPinIndex != -1 && secondPinIndex != -1) {
                setPinIndices(firstPinIndex, secondPinIndex, mDraggingPin, point);
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mDraggingPin != null) {
            releasePin(mDraggingPin);
            mDraggingPin = null;
        } // else {
          //    // Touch up when we never crossed the touch slop threshold should
          //    // be interpreted as a tap-seek to that location. But let's not do that now.
          //}
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mDraggingPin != null) {
            mDraggingPin = null;
        }
        break;
    }
}