Search in sources :

Example 11 with PointF

use of android.graphics.PointF in project subsampling-scale-image-view by davemorrissey.

the class AdvancedEventHandlingActivity method initialiseImage.

private void initialiseImage() {
    final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) findViewById(id.imageView);
    final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (imageView.isReady()) {
                PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY());
                Toast.makeText(getApplicationContext(), "Single tap: " + ((int) sCoord.x) + ", " + ((int) sCoord.y), Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "Single tap: Image not ready", Toast.LENGTH_SHORT).show();
            }
            return true;
        }

        @Override
        public void onLongPress(MotionEvent e) {
            if (imageView.isReady()) {
                PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY());
                Toast.makeText(getApplicationContext(), "Long press: " + ((int) sCoord.x) + ", " + ((int) sCoord.y), Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "Long press: Image not ready", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (imageView.isReady()) {
                PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY());
                Toast.makeText(getApplicationContext(), "Double tap: " + ((int) sCoord.x) + ", " + ((int) sCoord.y), Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "Double tap: Image not ready", Toast.LENGTH_SHORT).show();
            }
            return true;
        }
    });
    imageView.setImage(ImageSource.asset("squirrel.jpg"));
    imageView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            return gestureDetector.onTouchEvent(motionEvent);
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) PointF(android.graphics.PointF) SubsamplingScaleImageView(com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView) GestureDetector(android.view.GestureDetector) SubsamplingScaleImageView(com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView) TextView(android.widget.TextView) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 12 with PointF

use of android.graphics.PointF in project PhotoPicker by donglua.

the class TouchImageView method getScrollPosition.

/**
   * Return the point at the center of the zoomed image. The PointF coordinates range
   * in value between 0 and 1 and the focus point is denoted as a fraction from the left
   * and top of the view. For example, the top left corner of the image would be (0, 0).
   * And the bottom right corner would be (1, 1).
   *
   * @return PointF representing the scroll position of the zoomed image.
   */
public PointF getScrollPosition() {
    Drawable drawable = getDrawable();
    if (drawable == null) {
        return null;
    }
    int drawableWidth = drawable.getIntrinsicWidth();
    int drawableHeight = drawable.getIntrinsicHeight();
    PointF point = transformCoordTouchToBitmap(viewWidth / 2, viewHeight / 2, true);
    point.x /= drawableWidth;
    point.y /= drawableHeight;
    return point;
}
Also used : PointF(android.graphics.PointF) Drawable(android.graphics.drawable.Drawable)

Example 13 with PointF

use of android.graphics.PointF in project PhotoPicker by donglua.

the class TouchImageView method getZoomedRect.

/**
   * Return a Rect representing the zoomed image.
   *
   * @return rect representing zoomed image
   */
public RectF getZoomedRect() {
    if (mScaleType == ScaleType.FIT_XY) {
        throw new UnsupportedOperationException("getZoomedRect() not supported with FIT_XY");
    }
    PointF topLeft = transformCoordTouchToBitmap(0, 0, true);
    PointF bottomRight = transformCoordTouchToBitmap(viewWidth, viewHeight, true);
    float w = getDrawable().getIntrinsicWidth();
    float h = getDrawable().getIntrinsicHeight();
    return new RectF(topLeft.x / w, topLeft.y / h, bottomRight.x / w, bottomRight.y / h);
}
Also used : RectF(android.graphics.RectF) PointF(android.graphics.PointF)

Example 14 with PointF

use of android.graphics.PointF in project PhotoPicker by donglua.

the class TouchImageView method setZoom.

/**
   * Set zoom parameters equal to another TouchImageView. Including scale, position,
   * and ScaleType.
   * @param img TouchImageView
   */
public void setZoom(TouchImageView img) {
    PointF center = img.getScrollPosition();
    setZoom(img.getCurrentZoom(), center.x, center.y, img.getScaleType());
}
Also used : PointF(android.graphics.PointF)

Example 15 with PointF

use of android.graphics.PointF in project UltimateAndroid by cymcsg.

the class MatchView method initWithPointList.

public void initWithPointList(ArrayList<float[]> pointList) {
    float drawWidth = 0;
    float drawHeight = 0;
    boolean shouldLayout = mItemList.size() > 0;
    mItemList.clear();
    for (int i = 0; i < pointList.size(); i++) {
        float[] line = pointList.get(i);
        PointF startPoint = new PointF(Utils.dp2px(line[0]) * mScale, Utils.dp2px(line[1]) * mScale);
        PointF endPoint = new PointF(Utils.dp2px(line[2]) * mScale, Utils.dp2px(line[3]) * mScale);
        drawWidth = Math.max(drawWidth, startPoint.x);
        drawWidth = Math.max(drawWidth, endPoint.x);
        drawHeight = Math.max(drawHeight, startPoint.y);
        drawHeight = Math.max(drawHeight, endPoint.y);
        MatchItem item = new MatchItem(i, startPoint, endPoint, mTextColor, mLineWidth);
        item.resetPosition(horizontalRandomness);
        mItemList.add(item);
    }
    mDrawZoneWidth = (int) Math.ceil(drawWidth);
    mDrawZoneHeight = (int) Math.ceil(drawHeight);
    if (shouldLayout) {
        requestLayout();
    }
}
Also used : PointF(android.graphics.PointF)

Aggregations

PointF (android.graphics.PointF)342 Paint (android.graphics.Paint)67 Test (org.junit.Test)31 Matrix (android.graphics.Matrix)28 RectF (android.graphics.RectF)21 Path (android.graphics.Path)18 Point (android.graphics.Point)18 View (android.view.View)12 ValueAnimator (android.animation.ValueAnimator)11 Drawable (android.graphics.drawable.Drawable)11 MotionEvent (android.view.MotionEvent)10 LinearSmoothScroller (android.support.v7.widget.LinearSmoothScroller)9 Animator (android.animation.Animator)8 NonNull (android.support.annotation.NonNull)8 ArrayList (java.util.ArrayList)8 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)7 Rect (android.graphics.Rect)7 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)6 Message (android.os.Message)6 Interpolator (android.view.animation.Interpolator)6