Search in sources :

Example 86 with PointF

use of android.graphics.PointF in project qksms by moezbhatti.

the class SmoothLinearLayoutManager method smoothScrollToPosition.

@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
    super.smoothScrollToPosition(recyclerView, state, position);
    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {

        // This controls the direction in which smoothScroll looks for your view
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return new PointF(0, 1);
        }

        // This returns the milliseconds it takes to scroll one pixel.
        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
Also used : PointF(android.graphics.PointF) LinearSmoothScroller(android.support.v7.widget.LinearSmoothScroller) DisplayMetrics(android.util.DisplayMetrics)

Example 87 with PointF

use of android.graphics.PointF in project RxTools by vondear.

the class RxScaleImageView method onSizeChanged.

/**
 * On resize, preserve center and scale. Various behaviours are possible, override this method to use another.
 */
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    debug("onSizeChanged %dx%d -> %dx%d", oldw, oldh, w, h);
    PointF sCenter = getCenter();
    if (readySent && sCenter != null) {
        this.anim = null;
        this.pendingScale = scale;
        this.sPendingCenter = sCenter;
    }
}
Also used : PointF(android.graphics.PointF)

Example 88 with PointF

use of android.graphics.PointF in project RxTools by vondear.

the class RxScaleImageView method setGestureDetector.

private void setGestureDetector(final Context context) {
    this.detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {

        @Override
        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).withOrigin(ORIGIN_FLING).start();
                return true;
            }
            return super.onFling(e1, e2, velocityX, velocityY);
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            performClick();
            return true;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (zoomEnabled && readySent && vTranslate != null) {
                // 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);
                if (quickScaleEnabled) {
                    // Store quick scale params. This will become either a double tap zoom or a
                    // quick scale depending on whether the user swipes.
                    vCenterStart = new PointF(e.getX(), e.getY());
                    vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                    scaleStart = scale;
                    isQuickScaling = true;
                    isZooming = true;
                    quickScaleLastDistance = -1F;
                    quickScaleSCenter = viewToSourceCoord(vCenterStart);
                    quickScaleVStart = new PointF(e.getX(), e.getY());
                    quickScaleVLastPoint = new PointF(quickScaleSCenter.x, quickScaleSCenter.y);
                    quickScaleMoved = false;
                    // We need to get events in onTouchEvent after this.
                    return false;
                } else {
                    // Start double tap zoom animation.
                    doubleTapZoom(viewToSourceCoord(new PointF(e.getX(), e.getY())), new PointF(e.getX(), e.getY()));
                    return true;
                }
            }
            return super.onDoubleTapEvent(e);
        }
    });
}
Also used : PointF(android.graphics.PointF) GestureDetector(android.view.GestureDetector) MotionEvent(android.view.MotionEvent)

Example 89 with PointF

use of android.graphics.PointF in project RxTools by vondear.

the class RxScaleImageView method onTouchEvent.

/**
 * Handle touch events. One finger pans, and two finger pinch and zoom plus panning.
 */
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    // During non-interruptible anims, ignore all touch events
    if (anim != null && !anim.interruptible) {
        requestDisallowInterceptTouchEvent(true);
        return true;
    } else {
        if (anim != null && anim.listener != null) {
            try {
                anim.listener.onInterruptedByUser();
            } catch (Exception e) {
                Log.w(TAG, "Error thrown by animation listener", e);
            }
        }
        anim = null;
    }
    // Abort if not ready
    if (vTranslate == null) {
        return true;
    }
    // Detect flings, taps and double taps
    if (!isQuickScaling && (detector == null || detector.onTouchEvent(event))) {
        isZooming = false;
        isPanning = false;
        maxTouchCount = 0;
        return true;
    }
    if (vTranslateStart == null) {
        vTranslateStart = new PointF(0, 0);
    }
    if (vTranslateBefore == null) {
        vTranslateBefore = new PointF(0, 0);
    }
    if (vCenterStart == null) {
        vCenterStart = new PointF(0, 0);
    }
    // Store current values so we can send an event if they change
    float scaleBefore = scale;
    vTranslateBefore.set(vTranslate);
    boolean handled = onTouchEventInternal(event);
    sendStateChanged(scaleBefore, vTranslateBefore, ORIGIN_TOUCH);
    return handled || super.onTouchEvent(event);
}
Also used : PointF(android.graphics.PointF)

Example 90 with PointF

use of android.graphics.PointF in project RxTools by vondear.

the class RxScaleImageView method fitToBounds.

/**
 * Adjusts current scale and translate values to keep scale within the allowed range and the image on screen. Minimum scale
 * is set so one dimension fills the view and the image is centered on the other dimension.
 *
 * @param center Whether the image should be centered in the dimension it's too small to fill. While animating this can be false to avoid changes in direction as bounds are reached.
 */
private void fitToBounds(boolean center) {
    boolean init = false;
    if (vTranslate == null) {
        init = true;
        vTranslate = new PointF(0, 0);
    }
    if (satTemp == null) {
        satTemp = new ScaleAndTranslate(0, new PointF(0, 0));
    }
    satTemp.scale = scale;
    satTemp.vTranslate.set(vTranslate);
    fitToBounds(center, satTemp);
    scale = satTemp.scale;
    vTranslate.set(satTemp.vTranslate);
    if (init) {
        vTranslate.set(vTranslateForSCenter(sWidth() / 2, sHeight() / 2, scale));
    }
}
Also used : PointF(android.graphics.PointF)

Aggregations

PointF (android.graphics.PointF)686 Paint (android.graphics.Paint)132 Point (android.graphics.Point)53 RectF (android.graphics.RectF)53 Matrix (android.graphics.Matrix)43 Test (org.junit.Test)40 Path (android.graphics.Path)29 View (android.view.View)28 Drawable (android.graphics.drawable.Drawable)23 ArrayList (java.util.ArrayList)23 MotionEvent (android.view.MotionEvent)22 NonNull (android.support.annotation.NonNull)21 Rect (android.graphics.Rect)18 ValueAnimator (android.animation.ValueAnimator)14 ViewGroup (android.view.ViewGroup)11 List (java.util.List)11 Animator (android.animation.Animator)10 Bitmap (android.graphics.Bitmap)10 GestureDetector (android.view.GestureDetector)10 LinearSmoothScroller (android.support.v7.widget.LinearSmoothScroller)9