List of usage examples for android.graphics RectF width
public final float width()
From source file:com.hippo.largeimageview.LargeImageView.java
private void adjustPosition() { final int wWidth = mWindowWidth; final int wHeight = mWindowHeight; if (wWidth <= 0 || wHeight <= 0) { return;/*from w ww . j a v a 2s .c o m*/ } final RectF dst = mDst; final float dWidth = dst.width(); final float dHeight = dst.height(); if (dWidth <= 0 || dHeight <= 0) { return; } if (dWidth > wWidth) { float fixXOffset = dst.left; if (fixXOffset > 0) { dst.left -= fixXOffset; dst.right -= fixXOffset; mRectDirty = true; } else if ((fixXOffset = wWidth - dst.right) > 0) { dst.left += fixXOffset; dst.right += fixXOffset; mRectDirty = true; } } else { final float left = (wWidth - dWidth) / 2; dst.offsetTo(left, dst.top); mRectDirty = true; } if (dHeight > wHeight) { float fixYOffset = dst.top; if (fixYOffset > 0) { dst.top -= fixYOffset; dst.bottom -= fixYOffset; mRectDirty = true; } else if ((fixYOffset = wHeight - dst.bottom) > 0) { dst.top += fixYOffset; dst.bottom += fixYOffset; mRectDirty = true; } } else { final float top = (wHeight - dHeight) / 2; dst.offsetTo(dst.left, top); mRectDirty = true; } }
From source file:com.guodong.sun.guodong.widget.ZoomImageView.java
/** * ?/*from w ww . j av a 2 s.c o m*/ */ private void checkBorderAndCenterWhenScale() { RectF rectF = getMatrixRectF(); float delatX = 0; float delatY = 0; int width = getWidth(); int height = getHeight(); // if (rectF.width() >= width) { if (rectF.left > 0) { delatX = -rectF.left; } if (rectF.right < width) { delatX = width - rectF.right; } } if (rectF.height() >= height) { if (rectF.top > 0) { delatY = -rectF.top; } if (rectF.bottom < height) { delatY = height - rectF.bottom; } } // ? if (rectF.width() < width) { delatX = width * 0.5f - rectF.right + rectF.width() * 0.5f; } if (rectF.height() < height) { delatY = height * 0.5f - rectF.bottom + rectF.height() * 0.5f; } mScaleMatrix.postTranslate(delatX, delatY); }
From source file:com.hippo.largeimageview.LargeImageView.java
private void translate(float dx, float dy) { final int wWidth = mWindowWidth; final int wHeight = mWindowHeight; if (wWidth <= 0 || wHeight <= 0) { return;//ww w . jav a 2 s . c o m } final RectF dst = mDst; final float dWidth = dst.width(); final float dHeight = dst.height(); if (dWidth <= 0 || dHeight <= 0) { return; } final float remainX; final float remainY; if (dWidth > wWidth) { dst.left -= dx; dst.right -= dx; float fixXOffset = dst.left; if (fixXOffset > 0) { dst.left -= fixXOffset; dst.right -= fixXOffset; remainX = -fixXOffset; } else if ((fixXOffset = wWidth - dst.right) > 0) { dst.left += fixXOffset; dst.right += fixXOffset; remainX = fixXOffset; } else { remainX = 0; } } else { remainX = dx; } if (dHeight > wHeight) { dst.top -= dy; dst.bottom -= dy; float fixYOffset = dst.top; if (fixYOffset > 0) { dst.top -= fixYOffset; dst.bottom -= fixYOffset; remainY = -fixYOffset; } else if ((fixYOffset = wHeight - dst.bottom) > 0) { dst.top += fixYOffset; dst.bottom += fixYOffset; remainY = fixYOffset; } else { remainY = 0; } } else { remainY = dy; } // Check requestDisallowInterceptTouchEvent // Don't call requestDisallowInterceptTouchEvent when animated // Only call requestDisallowInterceptTouchEvent when on room for scroll left or right if (mAnimating == 0 && dx == remainX) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(false); } } if (dx != remainX || dy != remainY) { mRectDirty = true; invalidate(); } }
From source file:com.huyn.demogroup.zoomageview.view.PhotoViewAttacher.java
private boolean checkMatrixBoundsFromAnim(RectF origin) { final RectF rect = getDisplayRect(getDrawMatrix()); if (rect == null) { return false; }/*from www . j a va 2 s .co m*/ final float height = rect.height(), width = rect.width(); float deltaX = 0, deltaY = 0; System.out.println(mScaleType + ">>>rect...left:" + rect.left + "/" + rect.top + "/" + rect.right + "/" + rect.bottom + "===w:" + width + "/" + height); final float viewHeight = origin.height();//getImageViewHeight(mImageView); float top = rect.top - origin.top; if (height <= viewHeight) { deltaY = (viewHeight - height) / 2 - top; } else if (top > 0) { deltaY = -top; } else if (rect.bottom - origin.top < viewHeight) { deltaY = viewHeight - rect.bottom + origin.top; } final float viewWidth = origin.width();//getImageViewWidth(mImageView); float left = rect.left - origin.left; if (width <= viewWidth) { deltaX = (viewWidth - width) / 2 - left; mScrollEdge = EDGE_BOTH; } else if (left > 0) { mScrollEdge = EDGE_LEFT; deltaX = -left; } else if (rect.right - origin.left < viewWidth) { deltaX = viewWidth - rect.right + origin.left; mScrollEdge = EDGE_RIGHT; } else { mScrollEdge = EDGE_NONE; } System.out.println("===origin left : " + origin.left + "/" + origin.top); System.out .println(mScaleType + ">>>x:" + deltaX + "/" + deltaY + "===width:" + viewWidth + "/" + viewHeight); // Finally actually translate the matrix mSuppMatrix.postTranslate(deltaX, deltaY); return true; }
From source file:com.huyn.demogroup.zoomageview.view.PhotoViewAttacher.java
private boolean checkMatrixBounds() { final RectF rect = getDisplayRect(getDrawMatrix()); if (rect == null) { return false; }/*from w w w .j a v a 2 s.c om*/ final float height = rect.height(), width = rect.width(); float deltaX = 0, deltaY = 0; final int viewHeight = getImageViewHeight(mImageView); if (height <= viewHeight) { switch (mScaleType) { case FIT_START: deltaY = -rect.top; break; case FIT_END: deltaY = viewHeight - height - rect.top; break; default: deltaY = (viewHeight - height) / 2 - rect.top; break; } } else if (rect.top > 0) { deltaY = -rect.top; } else if (rect.bottom < viewHeight) { deltaY = viewHeight - rect.bottom; } final int viewWidth = getImageViewWidth(mImageView); if (width <= viewWidth) { switch (mScaleType) { case FIT_START: deltaX = -rect.left; break; case FIT_END: deltaX = viewWidth - width - rect.left; break; default: deltaX = (viewWidth - width) / 2 - rect.left; break; } mScrollEdge = EDGE_BOTH; } else if (rect.left > 0) { mScrollEdge = EDGE_LEFT; deltaX = -rect.left; } else if (rect.right < viewWidth) { deltaX = viewWidth - rect.right; mScrollEdge = EDGE_RIGHT; } else { mScrollEdge = EDGE_NONE; } System.out.println(mScaleType + ">>>rect...left:" + rect.left + "/" + rect.top + "/" + rect.right + "/" + rect.bottom + ">>>" + deltaY); // Finally actually translate the matrix mSuppMatrix.postTranslate(deltaX, deltaY); return true; }
From source file:com.tjw.selectimage.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView) { mImageView = imageView;// w w w .j a v a 2 s . c o m imageView.setOnTouchListener(this); imageView.addOnLayoutChangeListener(this); if (imageView.isInEditMode()) { return; } mBaseRotation = 0.0f; // Create Gesture Detectors... mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // forward long click listener @Override public void onLongPress(MotionEvent e) { if (mLongClickListener != null) { mLongClickListener.onLongClick(mImageView); } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mSingleFlingListener != null) { if (getScale() > DEFAULT_MIN_SCALE) { return false; } if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) { return false; } return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY); } return false; } }); mGestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() { @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (mOnClickListener != null) { mOnClickListener.onClick(mImageView); } final RectF displayRect = getDisplayRect(); if (displayRect != null) { final float x = e.getX(), y = e.getY(); // Check to see if the user tapped on the photo if (displayRect.contains(x, y)) { float xResult = (x - displayRect.left) / displayRect.width(); float yResult = (y - displayRect.top) / displayRect.height(); if (mPhotoTapListener != null) { mPhotoTapListener.onPhotoTap(mImageView, xResult, yResult); } return true; } else { if (mOutsidePhotoTapListener != null) { mOutsidePhotoTapListener.onOutsidePhotoTap(mImageView); } } } return false; } @Override public boolean onDoubleTap(MotionEvent ev) { try { float scale = getScale(); float x = ev.getX(); float y = ev.getY(); if (scale < getMediumScale()) { setScale(getMediumScale(), x, y, true); } else if (scale >= getMediumScale() && scale < getMaximumScale()) { setScale(getMaximumScale(), x, y, true); } else { setScale(getMinimumScale(), x, y, true); } } catch (ArrayIndexOutOfBoundsException e) { // Can sometimes happen when getX() and getY() is called } return true; } @Override public boolean onDoubleTapEvent(MotionEvent e) { // Wait for the confirmed onDoubleTap() instead return false; } }); }
From source file:org.getlantern.firetweet.fragment.support.AccountsDashboardFragment.java
private void onAccountSelected(AccountProfileImageViewHolder holder, final ParcelableAccount account) { if (mSwitchAccountAnimationPlaying) return;// w ww . j ava2 s . c om final ImageView snapshotView = mFloatingProfileImageSnapshotView; final ShapedImageView profileImageView = mAccountProfileImageView; final ShapedImageView clickedImageView = holder.getIconView(); // Reset snapshot view position snapshotView.setPivotX(0); snapshotView.setPivotY(0); snapshotView.setTranslationX(0); snapshotView.setTranslationY(0); final Matrix matrix = new Matrix(); final RectF sourceBounds = new RectF(), destBounds = new RectF(), snapshotBounds = new RectF(); getLocationOnScreen(clickedImageView, sourceBounds); getLocationOnScreen(profileImageView, destBounds); getLocationOnScreen(snapshotView, snapshotBounds); final float finalScale = destBounds.width() / sourceBounds.width(); final Bitmap snapshotBitmap = TransitionUtils.createViewBitmap(clickedImageView, matrix, new RectF(0, 0, sourceBounds.width(), sourceBounds.height())); final ViewGroup.LayoutParams lp = snapshotView.getLayoutParams(); lp.width = clickedImageView.getWidth(); lp.height = clickedImageView.getHeight(); snapshotView.setLayoutParams(lp); // Copied from MaterialNavigationDrawer: https://github.com/madcyph3r/AdvancedMaterialDrawer/ AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(snapshotView, View.TRANSLATION_X, sourceBounds.left - snapshotBounds.left, destBounds.left - snapshotBounds.left)) .with(ObjectAnimator.ofFloat(snapshotView, View.TRANSLATION_Y, sourceBounds.top - snapshotBounds.top, destBounds.top - snapshotBounds.top)) .with(ObjectAnimator.ofFloat(snapshotView, View.SCALE_X, 1, finalScale)) .with(ObjectAnimator.ofFloat(snapshotView, View.SCALE_Y, 1, finalScale)) .with(ObjectAnimator.ofFloat(profileImageView, View.ALPHA, 1, 0)) .with(ObjectAnimator.ofFloat(clickedImageView, View.SCALE_X, 0, 1)) .with(ObjectAnimator.ofFloat(clickedImageView, View.SCALE_Y, 0, 1)); final long animationTransition = 400; set.setDuration(animationTransition); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListener() { private Drawable clickedDrawable; private int[] clickedColors; @Override public void onAnimationStart(Animator animation) { snapshotView.setVisibility(View.VISIBLE); snapshotView.setImageBitmap(snapshotBitmap); final Drawable profileDrawable = profileImageView.getDrawable(); clickedDrawable = clickedImageView.getDrawable(); clickedColors = clickedImageView.getBorderColors(); final ParcelableAccount oldSelectedAccount = mAccountsAdapter.getSelectedAccount(); mImageLoader.displayDashboardProfileImage(clickedImageView, oldSelectedAccount.profile_image_url, profileDrawable); // mImageLoader.displayDashboardProfileImage(profileImageView, // account.profile_image_url, clickedDrawable); clickedImageView.setBorderColors(profileImageView.getBorderColors()); mSwitchAccountAnimationPlaying = true; } @Override public void onAnimationEnd(Animator animation) { finishAnimation(); } private void finishAnimation() { final Editor editor = mPreferences.edit(); editor.putLong(KEY_DEFAULT_ACCOUNT_ID, account.account_id); editor.apply(); mAccountsAdapter.setSelectedAccountId(account.account_id); mAccountOptionsAdapter.setSelectedAccount(account); updateAccountOptionsSeparatorLabel(clickedDrawable); snapshotView.setVisibility(View.INVISIBLE); snapshotView.setImageDrawable(null); profileImageView.setImageDrawable(clickedDrawable); profileImageView.setBorderColors(clickedColors); profileImageView.setAlpha(1f); clickedImageView.setScaleX(1); clickedImageView.setScaleY(1); clickedImageView.setAlpha(1f); mSwitchAccountAnimationPlaying = false; } @Override public void onAnimationCancel(Animator animation) { finishAnimation(); } @Override public void onAnimationRepeat(Animator animation) { } }); set.start(); }
From source file:it.configure.imageloader.zoom.PhotoViewAttacher.java
public final boolean onSingleTapConfirmed(MotionEvent e) { ImageView imageView = getImageView(); if (null != imageView) { if (null != mPhotoTapListener) { final RectF displayRect = getDisplayRect(); if (null != displayRect) { final float x = e.getX(), y = e.getY(); // Check to see if the user tapped on the photo if (displayRect.contains(x, y)) { float xResult = (x - displayRect.left) / displayRect.width(); float yResult = (y - displayRect.top) / displayRect.height(); mPhotoTapListener.onPhotoTap(imageView, xResult, yResult); return true; }/*from www . ja va 2s . c o m*/ } } if (null != mViewTapListener) { mViewTapListener.onViewTap(imageView, e.getX(), e.getY()); } } return false; }
From source file:org.mariotaku.twidere.fragment.support.AccountsDashboardFragment.java
private void onAccountSelected(AccountProfileImageViewHolder holder, final ParcelableAccount account) { if (mSwitchAccountAnimationPlaying) return;//w w w . jav a 2 s.c o m final ImageView snapshotView = mFloatingProfileImageSnapshotView; final ShapedImageView profileImageView = mAccountProfileImageView; final ShapedImageView clickedImageView = holder.getIconView(); // Reset snapshot view position snapshotView.setPivotX(0); snapshotView.setPivotY(0); snapshotView.setTranslationX(0); snapshotView.setTranslationY(0); final Matrix matrix = new Matrix(); final RectF sourceBounds = new RectF(), destBounds = new RectF(), snapshotBounds = new RectF(); getLocationOnScreen(clickedImageView, sourceBounds); getLocationOnScreen(profileImageView, destBounds); getLocationOnScreen(snapshotView, snapshotBounds); final float finalScale = destBounds.width() / sourceBounds.width(); final Bitmap snapshotBitmap = TransitionUtils.createViewBitmap(clickedImageView, matrix, new RectF(0, 0, sourceBounds.width(), sourceBounds.height())); final ViewGroup.LayoutParams lp = snapshotView.getLayoutParams(); lp.width = clickedImageView.getWidth(); lp.height = clickedImageView.getHeight(); snapshotView.setLayoutParams(lp); // Copied from MaterialNavigationDrawer: https://github.com/madcyph3r/AdvancedMaterialDrawer/ AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(snapshotView, View.TRANSLATION_X, sourceBounds.left - snapshotBounds.left, destBounds.left - snapshotBounds.left)) .with(ObjectAnimator.ofFloat(snapshotView, View.TRANSLATION_Y, sourceBounds.top - snapshotBounds.top, destBounds.top - snapshotBounds.top)) .with(ObjectAnimator.ofFloat(snapshotView, View.SCALE_X, 1, finalScale)) .with(ObjectAnimator.ofFloat(snapshotView, View.SCALE_Y, 1, finalScale)) .with(ObjectAnimator.ofFloat(profileImageView, View.ALPHA, 1, 0)) .with(ObjectAnimator.ofFloat(clickedImageView, View.SCALE_X, 0, 1)) .with(ObjectAnimator.ofFloat(clickedImageView, View.SCALE_Y, 0, 1)); final long animationTransition = 400; set.setDuration(animationTransition); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListener() { private Drawable clickedDrawable; private int[] clickedColors; @Override public void onAnimationStart(Animator animation) { snapshotView.setVisibility(View.VISIBLE); snapshotView.setImageBitmap(snapshotBitmap); final Drawable profileDrawable = profileImageView.getDrawable(); clickedDrawable = clickedImageView.getDrawable(); clickedColors = clickedImageView.getBorderColors(); final ParcelableAccount oldSelectedAccount = mAccountsAdapter.getSelectedAccount(); mImageLoader.displayDashboardProfileImage(clickedImageView, oldSelectedAccount.profile_image_url, profileDrawable); // mImageLoader.displayDashboardProfileImage(profileImageView, // account.profile_image_url, clickedDrawable); clickedImageView.setBorderColors(profileImageView.getBorderColors()); mSwitchAccountAnimationPlaying = true; } @Override public void onAnimationEnd(Animator animation) { finishAnimation(); } @Override public void onAnimationCancel(Animator animation) { finishAnimation(); } @Override public void onAnimationRepeat(Animator animation) { } private void finishAnimation() { final Editor editor = mPreferences.edit(); editor.putLong(KEY_DEFAULT_ACCOUNT_ID, account.account_id); editor.apply(); mAccountsAdapter.setSelectedAccountId(account.account_id); mAccountOptionsAdapter.setSelectedAccount(account); updateAccountOptionsSeparatorLabel(clickedDrawable); snapshotView.setVisibility(View.INVISIBLE); snapshotView.setImageDrawable(null); profileImageView.setImageDrawable(clickedDrawable); profileImageView.setBorderColors(clickedColors); profileImageView.setAlpha(1f); clickedImageView.setScaleX(1); clickedImageView.setScaleY(1); clickedImageView.setAlpha(1f); mSwitchAccountAnimationPlaying = false; } }); set.start(); }
From source file:info.awesomedevelopment.tvgrid.library.TVGridView.java
/** * Helper method to paint the canvas used in generate bitmap * * @param canvas the canvas used to draw onto * @param rectF size//www .ja v a 2 s .c om * @param paint paint */ private void paintCanvas(Canvas canvas, RectF rectF, Paint paint) { if (mSelectorShape == RECTANGLE) { canvas.drawRoundRect(rectF, mCornerRadiusX, mCornerRadiusY, paint); } else if (mSelectorShape == CIRCLE) { canvas.drawCircle(rectF.centerX(), rectF.centerY(), rectF.width() / 2, paint); } else { throw new IllegalArgumentException("Selector shape must be one of RECTANGLE or CIRCLE"); } }