Example usage for android.graphics RectF RectF

List of usage examples for android.graphics RectF RectF

Introduction

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

Prototype

public RectF() 

Source Link

Document

Create a new empty RectF.

Usage

From source file:arun.com.chromer.browsing.article.view.ElasticDragDismissFrameLayout.java

private void dragScale(int scroll) {
    if (scroll == 0)
        return;//www .ja  v  a 2  s  . c  o m

    totalDrag += scroll;
    View child = getChildAt(0);

    // track the direction & set the pivot point for scaling
    // don't double track i.e. if play dragging down and then reverse, keep tracking as
    // dragging down until they reach the 'natural' position
    if (scroll < 0 && !draggingUp && !draggingDown) {
        draggingDown = true;
        if (shouldScale)
            child.setPivotY(getHeight());
    } else if (scroll > 0 && !draggingDown && !draggingUp) {
        draggingUp = true;
        if (shouldScale)
            child.setPivotY(0f);
    }
    // how far have we dragged relative to the distance to perform a dismiss
    // (01 where 1 = dismiss distance). Decreasing logarithmically as we approach the limit
    float dragFraction = (float) Math.log10(1 + (Math.abs(totalDrag) / dragDismissDistance));

    // calculate the desired translation given the drag fraction
    float dragTo = dragFraction * dragDismissDistance * dragElasticity;

    if (draggingUp) {
        // as we use the absolute magnitude when calculating the drag fraction, need to
        // re-apply the drag direction
        dragTo *= -1;
    }
    child.setTranslationY(dragTo);

    if (draggingBackground == null) {
        draggingBackground = new RectF();
        draggingBackground.left = 0;
        draggingBackground.right = getWidth();
    }

    if (shouldScale) {
        final float scale = 1 - ((1 - dragDismissScale) * dragFraction);
        child.setScaleX(scale);
        child.setScaleY(scale);
    }

    // if we've reversed direction and gone past the settle point then clear the flags to
    // allow the list to get the scroll events & reset any transforms
    if ((draggingDown && totalDrag >= 0) || (draggingUp && totalDrag <= 0)) {
        totalDrag = dragTo = dragFraction = 0;
        draggingDown = draggingUp = false;
        child.setTranslationY(0f);
        child.setScaleX(1f);
        child.setScaleY(1f);
    }

    // draw the background above or below the view where it has scrolled at
    if (draggingUp) {
        draggingBackground.bottom = getHeight();
        draggingBackground.top = getHeight() + dragTo;
        invalidate();
    } else if (draggingDown) {
        draggingBackground.top = 0;
        draggingBackground.bottom = dragTo;
        invalidate();
    }

    dispatchDragCallback(dragFraction, dragTo, Math.min(1f, Math.abs(totalDrag) / dragDismissDistance),
            totalDrag);
}

From source file:com.ffmpegtest.VideoActivity.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void swapScaleType() {
    FFmpegSurfaceView view = (FFmpegSurfaceView) mVideoView;
    FFmpegSurfaceView.ScaleType scaleType = view.getScaleType();
    ScaleType newScaleType;/* w  w  w  .  jav a2 s  .c  o m*/
    if (ScaleType.CENTER_INSIDE.equals(scaleType)) {
        newScaleType = ScaleType.CENTER_CROP;
    } else if (ScaleType.CENTER_CROP.equals(scaleType)) {
        newScaleType = ScaleType.FIT_XY;
    } else {
        newScaleType = ScaleType.CENTER_INSIDE;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        view.setScaleType(newScaleType, true);
        RectF dst = new RectF();
        view.calculateRect(dst, newScaleType);
        ObjectAnimator anim = ObjectAnimator.ofObject(view, "destinationRect", new RectEvaluator(), dst);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.start();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        view.setScaleType(newScaleType, true);
        RectF dst = new RectF();
        view.calculateRect(dst, newScaleType);
        ObjectAnimator anim = ObjectAnimator.ofObject(view, new PropertyDestinationRect(), new RectEvaluator(),
                dst);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.start();
    } else {
        view.setScaleType(newScaleType, false);
    }
}

From source file:com.raspi.chatapp.util.Notification.java

private Bitmap getLargeIcon(int bgColor, char letter, float width, boolean round) {
    Bitmap b = Bitmap.createBitmap((int) width, (int) width, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);

    RectF mInnerRectF = new RectF();
    mInnerRectF.set(0, 0, width, width);
    mInnerRectF.offset(0, 0);//from  www  . jav a  2s. c o  m

    Paint mBgPaint = new Paint();
    mBgPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mBgPaint.setStyle(Paint.Style.FILL);
    mBgPaint.setColor(bgColor);

    TextPaint mTitleTextPaint = new TextPaint();
    mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mTitleTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    mTitleTextPaint.setTextAlign(Paint.Align.CENTER);
    mTitleTextPaint.setLinearText(true);
    mTitleTextPaint.setColor(Color.WHITE);
    mTitleTextPaint.setTextSize(width * 0.8f);

    float centerX = mInnerRectF.centerX();
    float centerY = mInnerRectF.centerY();

    int xPos = (int) centerX;
    int yPos = (int) (centerY - (mTitleTextPaint.descent() + mTitleTextPaint.ascent()) / 2);

    if (round)
        c.drawOval(mInnerRectF, mBgPaint);
    else
        c.drawRect(mInnerRectF, mBgPaint);
    c.drawText(String.valueOf(letter), xPos, yPos, mTitleTextPaint);

    return b;
}

From source file:com.apptentive.android.sdk.util.image.PreviewImageView.java

/**
 * Get image boundary from matrix//from   w w w . j a va  2s .  c  o m
 *
 * @return
 */
private RectF getMatrixRectF() {
    Matrix matrix = scaleMatrix;
    RectF rect = new RectF();
    Drawable d = getDrawable();
    if (null != d) {
        rect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        matrix.mapRect(rect);
    }
    return rect;
}

From source file:com.fanfou.app.opensource.ui.viewpager.TitlePageIndicator.java

/**
 * Calculate the bounds for a view's title
 * /*from  w  ww  .java  2 s  .co m*/
 * @param index
 * @param paint
 * @return
 */
private RectF calcBounds(final int index, final Paint paint) {
    // Calculate the text bounds
    final RectF bounds = new RectF();
    bounds.right = paint.measureText(this.mTitleProvider.getTitle(index));
    bounds.bottom = paint.descent() - paint.ascent();
    return bounds;
}

From source file:com.appunite.list.FastScroller.java

private void init(Context context) {
    // Get both the scrollbar states drawables
    TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS);
    useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE));
    mTrackDrawable = ta.getDrawable(TRACK_DRAWABLE);

    mOverlayDrawableLeft = ta.getDrawable(PREVIEW_BACKGROUND_LEFT);
    mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT);
    mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING);

    mScrollCompleted = true;/*from   w w  w.  ja  va  2  s  .c  o m*/

    getSectionsFromIndexer();

    mOverlaySize = context.getResources().getDimensionPixelSize(R.dimen.fastscroll_overlay_size);
    mOverlayPos = new RectF();
    mScrollFade = new ScrollFade();
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Paint.Align.CENTER);
    mPaint.setTextSize(mOverlaySize / 2);

    ColorStateList textColor = ta.getColorStateList(TEXT_COLOR);
    int textColorNormal = textColor.getDefaultColor();
    mPaint.setColor(textColorNormal);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);

    // to show mOverlayDrawable properly
    if (mList.getWidth() > 0 && mList.getHeight() > 0) {
        onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0);
    }

    mState = STATE_NONE;
    refreshDrawableState();

    ta.recycle();

    mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMatchDragPosition = context
            .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB;

    setScrollbarPosition(Compat.getVerticalScrollbarPosition(mList));
}

From source file:com.common.widget.hzlib.FastScroller.java

private void init(Context context) {
    // Get both the scrollbar states drawables
    TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS);
    useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE));
    mTrackDrawable = ta.getDrawable(TRACK_DRAWABLE);

    mOverlayDrawableLeft = ta.getDrawable(PREVIEW_BACKGROUND_LEFT);
    mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT);
    mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING);

    mScrollCompleted = true;/*ww w .  java 2  s  .  c  om*/

    getSectionsFromIndexer();

    mOverlaySize = context.getResources().getDimensionPixelSize(R.dimen.fastscroll_overlay_size);
    mOverlayPos = new RectF();
    mScrollFade = new ScrollFade();
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Paint.Align.CENTER);
    mPaint.setTextSize(mOverlaySize / 2);

    ColorStateList textColor = ta.getColorStateList(TEXT_COLOR);
    int textColorNormal = textColor.getDefaultColor();
    mPaint.setColor(textColorNormal);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);

    // to show mOverlayDrawable properly
    if (mList.getWidth() > 0 && mList.getHeight() > 0) {
        onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0);
    }

    mState = STATE_NONE;
    refreshDrawableState();

    ta.recycle();

    mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMatchDragPosition = context
            .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB;

    setScrollbarPosition(mList.getVerticalScrollbarPosition());
}

From source file:chinanurse.cn.nurse.list.WaveView.java

private void initView() {
    setUpPaint();
    setUpPath();
    resetAnimator();

    mDropRect = new RectF();
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

From source file:iSoron.HistoryChart.java

private void initRects() {
    baseLocation = new RectF();
}

From source file:com.guodong.sun.guodong.widget.ZoomImageView.java

/**
 * ???l,r,t,b/* w w w  . j av  a 2s  . co m*/
 *
 * @return
 */
private RectF getMatrixRectF() {

    Matrix matrix = mScaleMatrix;
    RectF rectF = new RectF();
    Drawable d = getDrawable();

    if (d != null) {

        rectF.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        matrix.mapRect(rectF);
    }
    return rectF;
}