private AnimationBuilder(float scale) { this.targetScale = scale; this.targetSCenter = getCenter(); this.vFocus = null; }
@Override public boolean onSingleTapConfirmed(MotionEvent e) { performClick(); return true; } });
/** * Get source width taking rotation into account. */ @SuppressWarnings("SuspiciousNameCombination") private int sWidth() { int rotation = getRequiredRotation(); if (rotation == 90 || rotation == 270) { return sHeight; } else { return sWidth; } }
/** * Check whether view and image dimensions are known and either a preview, full size image or * base layer tiles are loaded. First time, send ready event to listener. The next draw will * display an image. */ private boolean checkReady() { boolean ready = getWidth() > 0 && getHeight() > 0 && sWidth > 0 && sHeight > 0 && (bitmap != null || isBaseLayerReady()); if (!readySent && ready) { preDraw(); readySent = true; onReady(); if (onImageEventListener != null) { onImageEventListener.onReady(); } } return ready; }
/** * 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; }
/** * Determine whether tile is visible. */ private boolean tileVisible(Tile tile) { float sVisLeft = viewToSourceX(0), sVisRight = viewToSourceX(getWidth()), sVisTop = viewToSourceY(0), sVisBottom = viewToSourceY(getHeight()); return !(sVisLeft > tile.sRect.right || tile.sRect.left > sVisRight || sVisTop > tile.sRect.bottom || tile.sRect.top > sVisBottom); }
void setPage(PdfRenderer.Page page) { if (bitmap==null) { int height=2000; int width=height * page.getWidth() / page.getHeight(); bitmap=Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); } bitmap.eraseColor(0xFFFFFFFF); page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY); iv.resetScaleAndCenter(); iv.setImage(ImageSource.cachedBitmap(bitmap)); } }
/** * Set scale, center and orientation from saved state. */ private void restoreState(ImageViewState state) { if (state != null && VALID_ORIENTATIONS.contains(state.getOrientation())) { this.orientation = state.getOrientation(); this.pendingScale = state.getScale(); this.sPendingCenter = state.getCenter(); invalidate(); } }
/** * Check whether either the full size bitmap or base layer tiles are loaded. First time, send image * loaded event to listener. */ private boolean checkImageLoaded() { boolean imageLoaded = isBaseLayerReady(); if (!imageLoadedSent && imageLoaded) { preDraw(); imageLoadedSent = true; onImageLoaded(); if (onImageEventListener != null) { onImageEventListener.onImageLoaded(); } } return imageLoaded; }
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); } }
@Override public void onClick(View v) { imageView.setOrientation((imageView.getOrientation() + 90) % 360); } });
/** * Creates a scale animation builder, that when started will animate a zoom in or out. If this would move the image * beyond the panning limits, the image is automatically panned during the animation. * @param scale Target scale. * @return {@link AnimationBuilder} instance. Call {@link SubsamplingScaleImageView.AnimationBuilder#start()} to start the anim. */ @Nullable public AnimationBuilder animateScale(float scale) { if (!isReady()) { return null; } return new AnimationBuilder(scale); }
/** * 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; } }
public boolean handleMessage(Message message) { if (message.what == MESSAGE_LONG_CLICK && onLongClickListener != null) { maxTouchCount = 0; SubsamplingScaleImageView.super.setOnLongClickListener(onLongClickListener); performLongClick(); SubsamplingScaleImageView.super.setOnLongClickListener(null); } return true; } });
/** * Releases all resources the view is using and resets the state, nulling any fields that use significant memory. * After you have called this method, the view can be re-used by setting a new image. Settings are remembered * but state (scale and center) is forgotten. You can restore these yourself if required. */ public void recycle() { reset(true); bitmapPaint = null; debugTextPaint = null; debugLinePaint = null; tileBgPaint = null; }
/** * Returns the minimum allowed scale. * @return the minimum scale as a source/view pixels ratio. */ public final float getMinScale() { return minScale(); }
/** * Creates a scale animation builder, that when started will animate a zoom in or out. If this would move the image * beyond the panning limits, the image is automatically panned during the animation. * @param scale Target scale. * @param sCenter Target source center. * @return {@link AnimationBuilder} instance. Call {@link SubsamplingScaleImageView.AnimationBuilder#start()} to start the anim. */ @Nullable public AnimationBuilder animateScaleAndCenter(float scale, PointF sCenter) { if (!isReady()) { return null; } return new AnimationBuilder(scale, sCenter); }
/** * Get source height taking rotation into account. */ @SuppressWarnings("SuspiciousNameCombination") private int sHeight() { int rotation = getRequiredRotation(); if (rotation == 90 || rotation == 270) { return sWidth; } else { return sHeight; } }
@Override public boolean onSingleTapConfirmed(MotionEvent e) { performClick(); return true; }
/** * Returns the actual orientation of the image relative to the source file. This will be based on the source file's * EXIF orientation if you're using ORIENTATION_USE_EXIF. Values are 0, 90, 180, 270. * @return the orientation applied after EXIF information has been extracted. See static fields. */ public final int getAppliedOrientation() { return getRequiredRotation(); }