List of usage examples for android.graphics RectF width
public final float width()
From source file:org.mariotaku.twidere.fragment.AccountsDashboardFragment.java
private void onAccountSelected(AccountProfileImageViewHolder holder, @NonNull final ParcelableAccount account) { if (mSwitchAccountAnimationPlaying) return;//from w w w. j a va 2s. 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(); if (oldSelectedAccount == null) return; mMediaLoader.displayDashboardProfileImage(clickedImageView, oldSelectedAccount, profileDrawable); clickedImageView.setBorderColors(profileImageView.getBorderColors()); displayAccountBanner(account); 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.putString(KEY_DEFAULT_ACCOUNT_KEY, account.account_key.toString()); editor.apply(); mAccountsAdapter.setSelectedAccount(account); updateAccountActions(); displayCurrentAccount(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:com.android.gallery3d.filtershow.imageshow.ImageShow.java
private void constrainTranslation(Point translation, float scale) { int currentEdgeEffect = 0; if (scale <= 1) { mCurrentEdgeEffect = 0;//from www .ja v a 2s . c om mEdgeEffect.finish(); return; } Matrix originalToScreen = MasterImage.getImage().originalImageToScreen(); Rect originalBounds = MasterImage.getImage().getOriginalBounds(); RectF screenPos = new RectF(originalBounds); originalToScreen.mapRect(screenPos); boolean rightConstraint = screenPos.right < getWidth() - mShadowMargin; boolean leftConstraint = screenPos.left > mShadowMargin; boolean topConstraint = screenPos.top > mShadowMargin; boolean bottomConstraint = screenPos.bottom < getHeight() - mShadowMargin; if (screenPos.width() > getWidth()) { if (rightConstraint && !leftConstraint) { float tx = screenPos.right - translation.x * scale; translation.x = (int) ((getWidth() - mShadowMargin - tx) / scale); currentEdgeEffect = EDGE_RIGHT; } else if (leftConstraint && !rightConstraint) { float tx = screenPos.left - translation.x * scale; translation.x = (int) ((mShadowMargin - tx) / scale); currentEdgeEffect = EDGE_LEFT; } } else { float tx = screenPos.right - translation.x * scale; float dx = (getWidth() - 2 * mShadowMargin - screenPos.width()) / 2f; translation.x = (int) ((getWidth() - mShadowMargin - tx - dx) / scale); } if (screenPos.height() > getHeight()) { if (bottomConstraint && !topConstraint) { float ty = screenPos.bottom - translation.y * scale; translation.y = (int) ((getHeight() - mShadowMargin - ty) / scale); currentEdgeEffect = EDGE_BOTTOM; } else if (topConstraint && !bottomConstraint) { float ty = screenPos.top - translation.y * scale; translation.y = (int) ((mShadowMargin - ty) / scale); currentEdgeEffect = EDGE_TOP; } } else { float ty = screenPos.bottom - translation.y * scale; float dy = (getHeight() - 2 * mShadowMargin - screenPos.height()) / 2f; translation.y = (int) ((getHeight() - mShadowMargin - ty - dy) / scale); } if (mCurrentEdgeEffect != currentEdgeEffect) { if (mCurrentEdgeEffect == 0 || currentEdgeEffect != 0) { mCurrentEdgeEffect = currentEdgeEffect; mEdgeEffect.finish(); } mEdgeEffect.setSize(getWidth(), mEdgeSize); } if (currentEdgeEffect != 0) { mEdgeEffect.onPull(mEdgeSize); } }
From source file:com.github.chrisbanes.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView) { mImageView = imageView;/*from w ww . j ava 2s . co 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(); final float x = e.getX(), y = e.getY(); if (mViewTapListener != null) { mViewTapListener.onViewTap(mImageView, x, y); } if (displayRect != null) { // 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:cn.golden.pinchzoomcanvasview.PinchZoomCanvasViewAttacher.java
private boolean checkMatrixBounds() { final ImageView imageView = getImageView(); if (null == imageView) { return false; }// w w w . ja v a 2 s . com final RectF rect = getDisplayRect(getDrawMatrix()); if (null == rect) { return false; } final float height = rect.height(), width = rect.width(); float deltaX = 0, deltaY = 0; final int viewHeight = getImageViewHeight(imageView); 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(imageView); 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; } // Finally actually translate the matrix mSuppMatrix.postTranslate(deltaX, deltaY); return true; }
From source file:com.frank.protean.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView) { mImageView = imageView;// ww w . j a v a2 s . c om imageView.setOnTouchListener(this); imageView.addOnLayoutChangeListener(this); if (imageView.isInEditMode()) { return; } mBaseRotation = 0.0f; // Create Gesture Detectors... mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), onGestureListener); 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(); final float x = e.getX(), y = e.getY(); if (mViewTapListener != null) { mViewTapListener.onViewTap(mImageView, x, y); } if (displayRect != null) { // 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:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java
private boolean checkMatrixBounds() { final ImageView imageView = getImageView(); if (null == imageView) { return false; }/*from w w w . jav a2s. c o m*/ final RectF rect = getDisplayRect(getDrawMatrix()); if (null == rect) { return false; } final float height = rect.height(), width = rect.width(); float deltaX = 0, deltaY = 0; final int viewHeight = getImageViewHeight(imageView); 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(imageView); 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; } // Finally actually translate the matrix mSuppMatrix.postTranslate(deltaX, deltaY); return true; }
From source file:com.huyn.demogroup.zoomageview.view.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView) { mImageView = imageView;/*from w ww . j a va2 s .c om*/ View parent = (View) mImageView.getParent(); parent.setOnTouchListener(this); parent.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 (mIsDragging) { return false; } 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:com.mooc.viewpage_photoview_circleindicator.photoview.PhotoViewAttacher.java
/** * drawable?//from ww w. j av a 2s . co m * * @return */ private boolean checkMatrixBounds() { final ImageView imageView = getImageView(); if (null == imageView) { return false; } //?drawable final RectF rect = getDisplayRect(getDrawMatrix()); if (null == rect) { return false; } final float height = rect.height(), width = rect.width(); float deltaX = 0, deltaY = 0; final int viewHeight = getImageViewHeight(imageView); 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(imageView); 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; } // Finally actually translate the matrix mSuppMatrix.postTranslate(deltaX, deltaY); return true; }
From source file:org.stockchart.core.Area.java
@Override protected void onBoundsChanged() { final RectF margins = this.getSideMargins(); margins.left = Math.max(fGlobalLeftMargin, margins.left); margins.right = Math.max(fGlobalRightMargin, margins.right); final RectF legendSize = this.fLegend.getSize(); final float horizontalAxisWidth = getBounds().width() - (margins.left + margins.right); final float verticalAxisHeight = getBounds().height() - (margins.top + margins.bottom); getTopAxis().setBounds(margins.left, margins.top - getTopAxis().getSize(0f), horizontalAxisWidth, getTopAxis().getSize(0f));/*from ww w .j a va 2 s .c o m*/ getBottomAxis().setBounds(margins.left, getBounds().height() - margins.bottom, horizontalAxisWidth, getBottomAxis().getSize(0f)); getLeftAxis().setBounds(margins.left - getLeftAxis().getSize(0f), margins.top, getLeftAxis().getSize(0f), verticalAxisHeight); getRightAxis().setBounds(getBounds().width() - margins.right, margins.top, getRightAxis().getSize(0f), verticalAxisHeight); fPlot.setBounds(margins.left, margins.top, horizontalAxisWidth, verticalAxisHeight); switch (fLegend.getSide()) { case LEFT: fLegend.setBounds(0, margins.top + (verticalAxisHeight - legendSize.height()) / 2f, legendSize.width(), legendSize.height()); break; case RIGHT: fLegend.setBounds(getBounds().width() - legendSize.width(), margins.top + (verticalAxisHeight - legendSize.height()) / 2f, legendSize.width(), legendSize.height()); break; case TOP: fLegend.setBounds(margins.left + (horizontalAxisWidth - legendSize.width()) / 2f, 0f, legendSize.width(), legendSize.height()); break; case BOTTOM: fLegend.setBounds(margins.left + (horizontalAxisWidth - legendSize.width()) / 2f, getBounds().height() - legendSize.height(), legendSize.width(), legendSize.height()); break; } }
From source file:com.iiordanov.bVNC.RemoteCanvas.java
/** * Invalidates (to redraw) the location of the remote pointer. *///w w w .jav a 2 s .c om public void invalidateMousePosition() { if (bitmapData != null) { bitmapData.moveCursorRect(pointer.getX(), pointer.getY()); RectF r = bitmapData.getCursorRect(); reDraw(r.left, r.top, r.width(), r.height()); } }