Search in sources :

Example 6 with PointF

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

the class SubsamplingScaleImageView 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 7 with PointF

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

the class SubsamplingScaleImageView method preDraw.

/**
     * Sets scale and translate ready for the next draw.
     */
private void preDraw() {
    if (getWidth() == 0 || getHeight() == 0 || sWidth <= 0 || sHeight <= 0) {
        return;
    }
    // If waiting to translate to new center position, set translate now
    if (sPendingCenter != null && pendingScale != null) {
        scale = pendingScale;
        if (vTranslate == null) {
            vTranslate = new PointF();
        }
        vTranslate.x = (getWidth() / 2) - (scale * sPendingCenter.x);
        vTranslate.y = (getHeight() / 2) - (scale * sPendingCenter.y);
        sPendingCenter = null;
        pendingScale = null;
        fitToBounds(true);
        refreshRequiredTiles(true);
    }
    // On first display of base image set up position, and in other cases make sure scale is correct.
    fitToBounds(false);
}
Also used : PointF(android.graphics.PointF)

Example 8 with PointF

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

the class SubsamplingScaleImageView 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)

Example 9 with PointF

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

the class AnimationActivity method onClick.

@Override
public void onClick(View view) {
    if (view.getId() == id.next) {
        position++;
        updateNotes();
    } else if (view.getId() == id.previous) {
        position--;
        updateNotes();
    } else if (view.getId() == id.play) {
        PinView pinView = (PinView) findViewById(id.imageView);
        Random random = new Random();
        if (pinView.isReady()) {
            float maxScale = pinView.getMaxScale();
            float minScale = pinView.getMinScale();
            float scale = (random.nextFloat() * (maxScale - minScale)) + minScale;
            PointF center = new PointF(random.nextInt(pinView.getSWidth()), random.nextInt(pinView.getSHeight()));
            pinView.setPin(center);
            AnimationBuilder animationBuilder = pinView.animateScaleAndCenter(scale, center);
            if (position == 3) {
                animationBuilder.withDuration(2000).withEasing(SubsamplingScaleImageView.EASE_OUT_QUAD).withInterruptible(false).start();
            } else {
                animationBuilder.withDuration(750).start();
            }
        }
    }
}
Also used : Random(java.util.Random) PointF(android.graphics.PointF) AnimationBuilder(com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.AnimationBuilder) PinView(com.davemorrissey.labs.subscaleview.sample.extension.views.PinView)

Example 10 with PointF

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

the class ConfigurationActivity method updateNotes.

private void updateNotes() {
    if (position > notes.size() - 1) {
        return;
    }
    getActionBar().setSubtitle(notes.get(position).subtitle);
    ((TextView) findViewById(id.note)).setText(notes.get(position).text);
    findViewById(id.next).setVisibility(position >= notes.size() - 1 ? View.INVISIBLE : View.VISIBLE);
    findViewById(id.previous).setVisibility(position <= 0 ? View.INVISIBLE : View.VISIBLE);
    SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) findViewById(id.imageView);
    if (position == 0) {
        imageView.setMinimumDpi(50);
    } else {
        imageView.setMaxScale(2F);
    }
    if (position == 1) {
        imageView.setMinimumTileDpi(50);
    } else {
        imageView.setMinimumTileDpi(500);
    }
    if (position == 4) {
        imageView.setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER);
    } else if (position == 5) {
        imageView.setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER_IMMEDIATE);
    } else {
        imageView.setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED);
    }
    if (position == 6) {
        imageView.setDoubleTapZoomDpi(240);
    } else {
        imageView.setDoubleTapZoomScale(1F);
    }
    if (position == 7) {
        imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_CENTER);
    } else if (position == 8) {
        imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_OUTSIDE);
    } else {
        imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
    }
    if (position == 9) {
        imageView.setDebug(true);
    } else {
        imageView.setDebug(false);
    }
    if (position == 2) {
        imageView.setScaleAndCenter(0f, new PointF(1228, 816));
        imageView.setPanEnabled(false);
    } else {
        imageView.setPanEnabled(true);
    }
    if (position == 3) {
        imageView.setScaleAndCenter(1f, new PointF(1228, 816));
        imageView.setZoomEnabled(false);
    } else {
        imageView.setZoomEnabled(true);
    }
}
Also used : PointF(android.graphics.PointF) TextView(android.widget.TextView) SubsamplingScaleImageView(com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView)

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