private AnimationBuilder(float scale) { this.targetScale = scale; this.targetSCenter = getCenter(); this.vFocus = null; }
/** * 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; } }
/** * Get the current state of the view (scale, center, orientation) for restoration after rotate. Will return null if * the view is not ready. * @return an {@link ImageViewState} instance representing the current position of the image. null if the view isn't ready. */ @Nullable public final ImageViewState getState() { if (vTranslate != null && sWidth > 0 && sHeight > 0) { //noinspection ConstantConditions return new ImageViewState(getScale(), getCenter(), getOrientation()); } return null; }
private void sendStateChanged(float oldScale, PointF oldVTranslate, int origin) { if (onStateChangedListener != null && scale != oldScale) { onStateChangedListener.onScaleChanged(scale, origin); } if (onStateChangedListener != null && !vTranslate.equals(oldVTranslate)) { onStateChangedListener.onCenterChanged(getCenter(), origin); } }
anim.time = System.currentTimeMillis(); anim.sCenterEndRequested = targetSCenter; anim.sCenterStart = getCenter(); anim.sCenterEnd = targetSCenter; anim.vFocusStart = sourceToViewCoord(targetSCenter);
canvas.drawText("Scale: " + String.format(Locale.ENGLISH, "%.2f", scale) + " (" + String.format(Locale.ENGLISH, "%.2f", minScale()) + " - " + String.format(Locale.ENGLISH, "%.2f", maxScale) + ")", px(5), px(15), debugTextPaint); canvas.drawText("Translate: " + String.format(Locale.ENGLISH, "%.2f", vTranslate.x) + ":" + String.format(Locale.ENGLISH, "%.2f", vTranslate.y), px(5), px(30), debugTextPaint); PointF center = getCenter();
private AnimationBuilder(float scale) { this.targetScale = scale; this.targetSCenter = getCenter(); this.vFocus = null; }
/** * 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; } }
/** * Get the current state of the view (scale, center, orientation) for restoration after rotate. Will return null if * the view is not ready. */ public final ImageViewState getState() { if (vTranslate != null && sWidth > 0 && sHeight > 0) { return new ImageViewState(getScale(), getCenter(), getOrientation()); } return null; }
private void sendStateChanged(float oldScale, PointF oldVTranslate, int origin) { if (onStateChangedListener != null) { if (scale != oldScale) { onStateChangedListener.onScaleChanged(scale, origin); } if (!vTranslate.equals(oldVTranslate)) { onStateChangedListener.onCenterChanged(getCenter(), origin); } } }
private Rect getCroppedRect() { SubsamplingScaleImageView imageView = findViewById(R.id.imageView); PointF center = imageView.getCenter(); if (center != null) { int left = (int) (center.x - imageView.getWidth() / 2); return new Rect(left, 0, imageView.getSWidth(), imageView.getSHeight()); } return new Rect(0, 0, imageView.getSWidth(), imageView.getSHeight()); }
canvas.drawText("Scale: " + String.format(Locale.ENGLISH, "%.2f", scale), 5, 15, debugPaint); canvas.drawText("Translate: " + String.format(Locale.ENGLISH, "%.2f", vTranslate.x) + ":" + String.format(Locale.ENGLISH, "%.2f", vTranslate.y), 5, 35, debugPaint); PointF center = getCenter(); canvas.drawText("Source center: " + String.format(Locale.ENGLISH, "%.2f", center.x) + ":" + String.format(Locale.ENGLISH, "%.2f", center.y), 5, 55, debugPaint); debugPaint.setStrokeWidth(2f);
anim.time = System.currentTimeMillis(); anim.sCenterEndRequested = targetSCenter; anim.sCenterStart = getCenter(); anim.sCenterEnd = targetSCenter; anim.vFocusStart = sourceToViewCoord(targetSCenter);