Example usage for android.graphics RectF height

List of usage examples for android.graphics RectF height

Introduction

In this page you can find the example usage for android.graphics RectF height.

Prototype

public final float height() 

Source Link

Usage

From source file:com.goka.flickableview.ImageViewTouchBase.java

protected void getProperBaseMatrix(Drawable drawable, Matrix matrix, RectF rect) {
    float w = mBitmapRect.width();
    float h = mBitmapRect.height();
    float widthScale, heightScale;

    matrix.reset();/*w ww. ja v a2s .  co m*/

    widthScale = rect.width() / w;
    heightScale = rect.height() / h;
    float scale = Math.min(widthScale, heightScale);
    matrix.postScale(scale, scale);
    matrix.postTranslate(rect.left, rect.top);

    float tw = (rect.width() - w * scale) / 2.0f;
    float th = (rect.height() - h * scale) / 2.0f;
    matrix.postTranslate(tw, th);
    printMatrix(matrix);
}

From source file:com.cosmicsubspace.nerdyaudio.visuals.PlayControlsView.java

protected void parseMusicInformation(final MusicInformation mi) {
    if (mi == null)
        return;//from   w  ww. j  a  v  a  2 s . com

    currentMusic = mi;
    title = mi.getTitle();
    titleAnimatable.setText(mi.getTitle());
    artist = mi.getArtist();
    artistAnimatable.setText(mi.getArtist());
    filePath.setText(mi.getFilepath());

    if (mi.hasArt()) {
        artistNormal.getInfluence().set(0);
        artistNoArt.getInfluence().set(1);

        new Thread(new Runnable() {
            @Override
            public void run() {
                //TODO this soometimes cause weird race condition glithches.
                RectF bounds = artBoundsAnim.getRectF(currentFrameTime);
                albumArt = BitmapConversions.decodeSampledBitmapFromResource(mi.getArtByteArray(),
                        Math.round(bounds.width()), Math.round(bounds.height()));
                albumArtNormal.getInfluence().animate(1, 1, EasingEquations.DEFAULT_EASE);
                albumArtNone.getInfluence().animate(0, 1, EasingEquations.DEFAULT_EASE);
            }
        }).start();

        titleNormal.getInfluence().animate(1, 1, EasingEquations.DEFAULT_EASE);
        titleNoArt.getInfluence().animate(0, 1, EasingEquations.DEFAULT_EASE);
        titleAnimatable.enableMarquee(w - (albumArtSize + albumArtMargin) * density, 16 * density);
        filePath.enableMarquee(w - (albumArtSize + albumArtMargin) * density, 16 * density);
        filePathActiveArt.getInfluence().animate(1, 1, EasingEquations.DEFAULT_EASE);
        filePathActiveNoArt.getInfluence().animate(0, 1, EasingEquations.DEFAULT_EASE);
        artistNormal.getInfluence().animate(1, 1, EasingEquations.DEFAULT_EASE);
        artistNoArt.getInfluence().animate(0, 1, EasingEquations.DEFAULT_EASE);

        if (!expanded)
            buttonsCenter(false);

    } else {
        titleNormal.getInfluence().animate(0, 1, EasingEquations.DEFAULT_EASE);
        titleNoArt.getInfluence().animate(1, 1, EasingEquations.DEFAULT_EASE);
        titleAnimatable.enableMarquee(w - albumArtMargin * 2 * density, 16 * density);
        filePath.enableMarquee(w - albumArtMargin * 2 * density, 16 * density);
        filePathActiveArt.getInfluence().animate(0, 1, EasingEquations.DEFAULT_EASE);
        filePathActiveNoArt.getInfluence().animate(1, 1, EasingEquations.DEFAULT_EASE);
        albumArtNormal.getInfluence().animate(0, 1, EasingEquations.DEFAULT_EASE);
        albumArtNone.getInfluence().animate(1, 1, EasingEquations.DEFAULT_EASE);
        artistNormal.getInfluence().animate(0, 1, EasingEquations.DEFAULT_EASE);
        artistNoArt.getInfluence().animate(1, 1, EasingEquations.DEFAULT_EASE);

        if (!expanded)
            buttonsCenter(true);
    }
}

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  w ww .j  a  va2s.c  o 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.guodong.sun.guodong.widget.ZoomImageView.java

@Override
public boolean onTouch(View v, MotionEvent event) {

    if (mGestureDetector.onTouchEvent(event))
        return true;

    mScaleGestureDetector.onTouchEvent(event);

    float x = 0;// www . ja va2  s .c  o  m
    float y = 0;
    // ?
    final int mPointerCount = event.getPointerCount();
    for (int i = 0; i < mPointerCount; i++) {

        x += event.getX(i);
        y += event.getY(i);
    }

    x = x / mPointerCount;
    y = y / mPointerCount;

    /**
     * ????mLasX , mLastY
     */
    if (mLastPointerCount != mPointerCount) {
        isCanDrag = false;
        mLastX = x;
        mLastY = y;
    }

    mLastPointerCount = mPointerCount;

    RectF rectF = getMatrixRectF();

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:

        if (rectF.width() > getWidth() + 0.01 || rectF.height() > getHeight() + 0.01) {
            if (getParent() instanceof ViewPager)
                getParent().requestDisallowInterceptTouchEvent(true);
        }
        break;
    case MotionEvent.ACTION_MOVE:

        if (rectF.width() > getWidth() + 0.01 || rectF.height() > getHeight() + 0.01) {
            if (getParent() instanceof ViewPager)
                getParent().requestDisallowInterceptTouchEvent(true);
        }

        float dX = x - mLastX;
        float dY = y - mLastY;

        if (!isCanDrag) {
            isCanDrag = isMoveAction(dX, dY);
        }

        if (isCanDrag) {
            if (getDrawable() != null) {

                isCheckLeftAndRight = isCheckTopAndBottom = true;

                // ????
                if (rectF.width() < getWidth()) {
                    dX = 0;
                    isCheckLeftAndRight = false;
                }
                // ????
                if (rectF.height() < getHeight()) {
                    dY = 0;
                    isCheckTopAndBottom = false;
                }

                mScaleMatrix.postTranslate(dX, dY);

                checkBorderWhenTranslate();

                setImageMatrix(mScaleMatrix);

            }
        }
        mLastX = x;
        mLastY = y;
        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mLastPointerCount = 0;
        break;
    }
    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   ww  w .  j  av a2  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.hippo.largeimageview.LargeImageView.java

private void setScale(float x, float y, float scale) {
    final int iWidth = mImageWidth;
    final int iHeight = mImageHeight;
    if (iWidth <= 0 || iHeight <= 0) {
        return;//from  w  w  w .  j a v a  2  s . co m
    }
    final RectF dst = mDst;
    final float dWidth = dst.width();
    final float dHeight = dst.height();
    if (dWidth <= 0 || dHeight <= 0) {
        return;
    }

    scale = clamp(scale, mMinScale, mMaxScale);
    if (mScale == scale) {
        return;
    }

    final float sScale = scale / mScale;
    mScale = scale;
    dst.left = (x - ((x - dst.left) * sScale));
    dst.top = (y - ((y - dst.top) * sScale));
    dst.right = dst.left + (iWidth * scale);
    dst.bottom = dst.top + (iHeight * scale);

    // Adjust position
    adjustPosition();

    mRectDirty = true;
    invalidate();
}

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 w w .j  ava  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.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.  j  a  v a2 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.tjw.selectimage.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;// ww  w  . j  av a 2  s  . c om
    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: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   w w  w. j  a v  a  2 s .co m
            }
        }
        if (null != mViewTapListener) {
            mViewTapListener.onViewTap(imageView, e.getX(), e.getY());
        }
    }

    return false;
}