Example usage for android.graphics RectF width

List of usage examples for android.graphics RectF width

Introduction

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

Prototype

public final float width() 

Source Link

Usage

From source file:de.vanita5.twittnuker.view.ColorPickerView.java

private Point satValToPoint(final float sat, final float val) {

    final RectF rect = mSatValRect;
    final float height = rect.height();
    final float width = rect.width();

    final Point p = new Point();

    p.x = (int) (sat * width + rect.left);
    p.y = (int) ((1f - val) * height + rect.top);

    return p;//  w ww .  ja va  2  s .  com
}

From source file:com.frank.protean.photoview.PhotoViewAttacher.java

private boolean checkMatrixBounds() {

    final RectF rect = getDisplayRect(getDrawMatrix());
    if (rect == null) {
        return false;
    }//  ww w . j  a v  a2 s.  com

    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;
    }

    // Finally actually translate the matrix
    mSuppMatrix.postTranslate(deltaX, deltaY);
    return true;
}

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

protected RectF getCenter(Matrix supportMatrix, boolean horizontal, boolean vertical) {
    final Drawable drawable = getDrawable();

    if (drawable == null) {
        return new RectF(0, 0, 0, 0);
    }/*www  . j  a v  a  2s.  c o m*/

    mCenterRect.set(0, 0, 0, 0);
    RectF rect = getBitmapRect(supportMatrix);
    float height = rect.height();
    float width = rect.width();
    float deltaX = 0, deltaY = 0;
    if (vertical) {
        if (height < mViewPort.height()) {
            deltaY = (mViewPort.height() - height) / 2 - (rect.top - mViewPort.top);
        } else if (rect.top > mViewPort.top) {
            deltaY = -(rect.top - mViewPort.top);
        } else if (rect.bottom < mViewPort.bottom) {
            deltaY = mViewPort.bottom - rect.bottom;
        }
    }
    if (horizontal) {
        if (width < mViewPort.width()) {
            deltaX = (mViewPort.width() - width) / 2 - (rect.left - mViewPort.left);
        } else if (rect.left > mViewPort.left) {
            deltaX = -(rect.left - mViewPort.left);
        } else if (rect.right < mViewPort.right) {
            deltaX = mViewPort.right - rect.right;
        }
    }
    mCenterRect.set(deltaX, deltaY, 0, 0);
    return mCenterRect;
}

From source file:de.vanita5.twittnuker.view.ColorPickerView.java

private float[] pointToSatVal(float x, float y) {

    final RectF rect = mSatValRect;
    final float[] result = new float[2];

    final float width = rect.width();
    final float height = rect.height();

    if (x < rect.left) {
        x = 0f;/* w ww .  java 2s.  c om*/
    } else if (x > rect.right) {
        x = width;
    } else {
        x = x - rect.left;
    }

    if (y < rect.top) {
        y = 0f;
    } else if (y > rect.bottom) {
        y = height;
    } else {
        y = y - rect.top;
    }

    result[0] = 1.f / width * x;
    result[1] = 1.f - 1.f / height * y;

    return result;
}

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  w w  .j a va2 s.  c om*/

    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:org.stockchart.StockChartView.java

public void resetPositions() {
    float y = 0f;
    float pxAutoHeight = this.getAreaAutoHeightInPixels();
    float pxWidth = this.getWidth();
    float pxHeight = this.getHeight();

    final float[] lr = getLeftRightMargins();

    for (Area a : fAreas) {
        if (!a.isVisible())
            continue;

        float height = a.isAutoHeight() ? pxAutoHeight : a.getHeightInPercents() * pxHeight;

        RectF rect = new RectF(0, y, pxWidth, y + height);

        a.setGlobalMargins(lr[0], lr[1]);

        a.setBounds(0f, rect.top, rect.width(), rect.height());

        y += height;/*from   ww w .  j  ava 2 s. c o  m*/
    }
}

From source file:it.configure.imageloader.zoom.PhotoViewAttacher.java

private void checkMatrixBounds() {
    final ImageView imageView = getImageView();
    if (null == imageView) {
        return;//from w ww . j a va 2 s .co  m
    }

    final RectF rect = getDisplayRect(getDisplayMatrix());
    if (null == rect) {
        return;
    }

    final float height = rect.height(), width = rect.width();
    float deltaX = 0, deltaY = 0;

    final int viewHeight = imageView.getHeight();
    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 = imageView.getWidth();
    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);
}

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;//from w  ww  .  j  a v  a2 s.  c om
    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.cosmicsubspace.nerdyaudio.visuals.PlayControlsView.java

protected void parseMusicInformation(final MusicInformation mi) {
    if (mi == null)
        return;//from   w ww  .  jav  a  2s  .  c o  m

    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.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.ja  va  2s  .c  om*/
    }
    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();
}