Example usage for android.graphics Rect Rect

List of usage examples for android.graphics Rect Rect

Introduction

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

Prototype

public Rect() 

Source Link

Document

Create a new empty Rect.

Usage

From source file:android.support.design.internal.ScrimInsetsFrameLayout.java

public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrimInsetsFrameLayout, defStyleAttr,
            R.style.Widget_Design_ScrimInsetsFrameLayout);
    mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsFrameLayout_insetForeground);
    a.recycle();/*from  w  w w  .  j  a v  a  2  s .c  o  m*/
    setWillNotDraw(true); // No need to draw until the insets are adjusted

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            if (null == mInsets) {
                mInsets = new Rect();
            }
            mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
            onInsetsChanged(insets);
            setWillNotDraw(!insets.hasSystemWindowInsets() || mInsetForeground == null);
            ViewCompat.postInvalidateOnAnimation(ScrimInsetsFrameLayout.this);
            return insets.consumeSystemWindowInsets();
        }
    });
}

From source file:andoridhost.imczy.com.activitymaterial.custom.ChangePosition.java

private void captureValues(TransitionValues values) {
    values.values.put(PROPNAME_POSITION, values.view.getBackground());

    Rect rect = new Rect();
    values.view.getGlobalVisibleRect(rect);
    values.values.put(PROPNAME_POSITION, rect);
}

From source file:com.bytebit.classicbyte.ScreenMainMenu.java

public void draw(Canvas c) {
    this.parent.standard_paint.setColor(Color.WHITE);

    for (int i = 0; i != 9; i++) {
        for (int k = 0; k != 10; k++) {
            c.drawBitmap(TextureManager.getBitmap(3), k * (this.parent.renderer.width / 10),
                    (i + 1) * (this.parent.renderer.width / 10), this.parent.standard_paint);
        }//from w  w w  . j  av  a 2s  . c  om
    }

    if (this.menu_current_tab == 1) {
        Rect bounds = new Rect();
        String g;
        for (int k = 0; k != this.server_list_name.size(); k++) {
            if (k >= this.server_list_name.size()) {
                break;
            }
            if ((this.parent.renderer.width * 0.12F + this.parent.renderer.width * 0.1F * k
                    + this.server_list_y_offset) >= 0
                    && (this.parent.renderer.width * 0.12F + this.parent.renderer.width * 0.1F * k
                            + this.server_list_y_offset) <= this.parent.renderer.height) {
                this.parent.standard_paint.setColor(Color.WHITE);
                this.parent.standard_paint.setTextSize(this.parent.renderer.width * 0.04F);
                c.drawBitmap(TextureManager.getBitmap(10),
                        (this.parent.renderer.width - TextureManager.getBitmap(10).getWidth()) / 2,
                        this.parent.renderer.width * 0.02F + this.parent.renderer.width * 0.12F
                                + this.parent.renderer.width * 0.1F * k + this.server_list_y_offset,
                        this.parent.standard_paint);
                g = this.server_list_name.get(k);
                this.parent.standard_paint.getTextBounds(this.server_list_name.get(k), 0,
                        this.server_list_name.get(k).length(), bounds);
                if (bounds.width() > TextureManager.getBitmap(10).getWidth() * 0.85F) {
                    while (bounds.width() > TextureManager.getBitmap(10).getWidth() * 0.85F) {
                        this.parent.standard_paint.getTextBounds(g + " ..", 0, (g + " ..").length(), bounds);
                        g = g.substring(0, g.length() - 1);
                    }
                    g = g + " ..";
                }
                c.drawText(g,
                        (this.parent.renderer.width - TextureManager.getBitmap(10).getWidth()) / 2
                                + this.parent.renderer.width * 0.02F,
                        this.parent.renderer.width * 0.08F + this.parent.renderer.width * 0.12F
                                + this.parent.renderer.width * 0.1F * k + this.server_list_y_offset,
                        this.parent.standard_paint);
                this.parent.standard_paint.setColor(Color.YELLOW);
                this.parent.standard_paint.getTextBounds(this.server_list_online_data.get(k), 0,
                        this.server_list_online_data.get(k).length(), bounds);
                c.drawText(this.server_list_online_data.get(k),
                        this.parent.renderer.width
                                - (this.parent.renderer.width - TextureManager.getBitmap(10).getWidth()) / 2
                                - this.parent.renderer.width * 0.02F - bounds.width(),
                        this.parent.renderer.width * 0.08F + this.parent.renderer.width * 0.12F
                                + this.parent.renderer.width * 0.1F * k + this.server_list_y_offset,
                        this.parent.standard_paint);
            }
        }
        c.drawBitmap(
                TextureManager.getBitmap(26), 0, TextureManager.getBitmap(2).getHeight()
                        + TextureManager.getBitmap(22).getHeight() + this.scrollbar_offset,
                this.parent.standard_paint);
        if (this.menu_button_highlighted == 3) {
            c.drawBitmap(TextureManager.getBitmap(25), 0, TextureManager.getBitmap(2).getHeight(),
                    this.parent.standard_paint);
        } else {
            c.drawBitmap(TextureManager.getBitmap(24), 0, TextureManager.getBitmap(2).getHeight(),
                    this.parent.standard_paint);
        }
        if (this.menu_button_highlighted == 4) {
            c.drawBitmap(TextureManager.getBitmap(23), 0,
                    this.parent.renderer.height - TextureManager.getBitmap(22).getHeight(),
                    this.parent.standard_paint);
        } else {
            c.drawBitmap(TextureManager.getBitmap(22), 0,
                    this.parent.renderer.height - TextureManager.getBitmap(22).getHeight(),
                    this.parent.standard_paint);
        }
    }
    if (this.menu_current_tab == 2) {
        Rect bounds = new Rect();
        this.parent.standard_paint.setColor(Color.WHITE);
        this.parent.standard_paint.setTextSize(this.parent.renderer.height * 0.25F);
        this.parent.standard_paint.getTextBounds("Nothing here", 0, "Nothing here".length(), bounds);
        c.drawText("Nothing here", (this.parent.renderer.width - bounds.width()) / 2,
                this.parent.renderer.height * 0.5F, this.parent.standard_paint);
    }

    for (int k = 0; k != 10; k++) {
        c.drawBitmap(TextureManager.getBitmap(2), k * TextureManager.getBitmap(2).getWidth(), 0,
                this.parent.standard_paint);
    }

    c.drawBitmap(TextureManager.getBitmap(4), this.parent.renderer.width * 0.05F, 0,
            this.parent.standard_paint);
    if (this.menu_button_highlighted == 1) {
        c.drawBitmap(TextureManager.getBitmap(8), this.parent.renderer.width * 0.1F * 6.5F,
                this.parent.renderer.width * 0.01F, this.parent.standard_paint);
    } else {
        c.drawBitmap(TextureManager.getBitmap(7), this.parent.renderer.width * 0.1F * 6.5F,
                this.parent.renderer.width * 0.01F, this.parent.standard_paint);
    }
    if (this.menu_button_highlighted == 2) {
        c.drawBitmap(TextureManager.getBitmap(6), this.parent.renderer.width * 0.1F * 8.75F,
                this.parent.renderer.width * 0.01F, this.parent.standard_paint);
    } else {
        c.drawBitmap(TextureManager.getBitmap(5), this.parent.renderer.width * 0.1F * 8.75F,
                this.parent.renderer.width * 0.01F, this.parent.standard_paint);
    }

    //c.drawBitmap(TextureManager.getBitmap(9), this.parent.renderer.width-TextureManager.getBitmap(9).getWidth(), this.parent.renderer.height-TextureManager.getBitmap(9).getHeight(), this.parent.standard_paint);
}

From source file:MainActivity.java

private void zoomFromThumbnail(final ImageView imageViewThumb) {
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();//from  w w  w  .j  a  v a2s.  c o m
    }

    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    imageViewThumb.getGlobalVisibleRect(startBounds);
    findViewById(R.id.frameLayout).getGlobalVisibleRect(finalBounds, globalOffset);
    mImageViewExpanded
            .setImageBitmap(loadSampledResource(R.drawable.image, finalBounds.height(), finalBounds.width()));

    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

    float startScale;
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width()
            / startBounds.height()) {
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    imageViewThumb.setVisibility(View.GONE);
    mImageViewExpanded.setVisibility(View.VISIBLE);
    mImageViewExpanded.setPivotX(0f);
    mImageViewExpanded.setPivotY(0f);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(ObjectAnimator.ofFloat(mImageViewExpanded, View.X, startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.Y, startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.SCALE_X, startScale, 1f))
            .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.SCALE_Y, startScale, 1f));
    animatorSet.setDuration(1000);
    animatorSet.setInterpolator(new AccelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });
    animatorSet.start();
    mCurrentAnimator = animatorSet;
}

From source file:android.support.v7.internal.widget.ListViewCompat.java

@Override
public void setSelector(Drawable sel) {
    mSelector = sel != null ? new GateKeeperDrawable(sel) : null;
    super.setSelector(mSelector);

    final Rect padding = new Rect();
    if (sel != null) {
        sel.getPadding(padding);/*from   w  w  w  . j av  a 2  s  . c  o m*/
    }

    mSelectionLeftPadding = padding.left;
    mSelectionTopPadding = padding.top;
    mSelectionRightPadding = padding.right;
    mSelectionBottomPadding = padding.bottom;
}

From source file:android.support.transition.FragmentTransitionSupport.java

@Override
public void setEpicenter(Object transitionObj, View view) {
    if (view != null) {
        Transition transition = (Transition) transitionObj;
        final Rect epicenter = new Rect();
        getBoundsOnScreen(view, epicenter);

        transition.setEpicenterCallback(new Transition.EpicenterCallback() {
            @Override/*from  w  w w. j  a va2  s . co  m*/
            public Rect onGetEpicenter(@NonNull Transition transition) {
                return epicenter;
            }
        });
    }
}

From source file:com.sebible.cordova.videosnapshot.VideoSnapshot.java

private void drawTimestamp(Bitmap bm, String prefix, long timeMs, int textSize) {
    float w = bm.getWidth(), h = bm.getHeight();
    float size = (float) (textSize * bm.getWidth()) / 1280;
    float margin = (float) (w < h ? w : h) * 0.05f;

    Canvas c = new Canvas(bm);
    Paint p = new Paint();
    p.setColor(Color.WHITE);/*w  w w  .  j a va2  s . co m*/
    p.setStrokeWidth((int) (size / 10));
    p.setTextSize((int) size); // Text Size
    p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text Overlapping Pattern

    long second = (timeMs / 1000) % 60;
    long minute = (timeMs / (1000 * 60)) % 60;
    long hour = (timeMs / (1000 * 60 * 60)) % 24;

    String text = String.format("%s %02d:%02d:%02d", prefix, hour, minute, second);
    Rect r = new Rect();
    p.getTextBounds(text, 0, text.length(), r);
    //c.drawBitmap(originalBitmap, 0, 0, paint);
    c.drawText(text, bm.getWidth() - r.width() - margin, bm.getHeight() - r.height() - margin, p);
}

From source file:android.support.transition.ChangeClipBounds.java

@Override
public Animator createAnimator(@NonNull final ViewGroup sceneRoot, TransitionValues startValues,
        TransitionValues endValues) {/*  w ww.  j a va  2  s.c om*/
    if (startValues == null || endValues == null || !startValues.values.containsKey(PROPNAME_CLIP)
            || !endValues.values.containsKey(PROPNAME_CLIP)) {
        return null;
    }
    Rect start = (Rect) startValues.values.get(PROPNAME_CLIP);
    Rect end = (Rect) endValues.values.get(PROPNAME_CLIP);
    final boolean endIsNull = end == null;
    if (start == null && end == null) {
        return null; // No animation required since there is no clip.
    }

    if (start == null) {
        start = (Rect) startValues.values.get(PROPNAME_BOUNDS);
    } else if (end == null) {
        end = (Rect) endValues.values.get(PROPNAME_BOUNDS);
    }
    if (start.equals(end)) {
        return null;
    }

    ViewCompat.setClipBounds(endValues.view, start);
    RectEvaluator evaluator = new RectEvaluator(new Rect());
    ObjectAnimator animator = ObjectAnimator.ofObject(endValues.view, ViewUtils.CLIP_BOUNDS, evaluator, start,
            end);
    if (endIsNull) {
        final View endView = endValues.view;
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                ViewCompat.setClipBounds(endView, null);
            }
        });
    }
    return animator;
}

From source file:android.support.design.widget.BasicBehavior.java

private boolean updateFabVisibility(CoordinatorLayout parent, AppBarLayout appBarLayout, T child) {
    final CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
    if (lp.getAnchorId() != appBarLayout.getId()) {
        // The anchor ID doesn't match the dependency, so we won't automatically
        // show/hide the FAB
        return false;
    }/*from www .  j  a va  2 s  . c  o m*/

    if (child.getVisibility() != View.VISIBLE) {
        // The view isn't set to be visible so skip changing it's visibility
        return false;
    }

    if (mTmpRect == null) {
        mTmpRect = new Rect();
    }

    // First, let's get the visible rect of the dependency
    final Rect rect = mTmpRect;
    ViewGroupUtils.getDescendantRect(parent, appBarLayout, rect);

    if (rect.bottom <= appBarLayout.getMinimumHeightForVisibleOverlappingContent()) {
        if (listenerAnimatorEndBuild.isFinish())
            // If the anchor's bottom is below the seam, we'll animate our FAB out
            scaleHide(child, listenerAnimatorEndBuild.build());
    } else {
        // Else, we'll animate our FAB back in
        scaleShow(child, null);
    }
    return true;
}

From source file:android.support.design.widget.CollapsingTextHelper.java

public CollapsingTextHelper(View view) {
    mView = view;//www.jav a  2 s  .  c  o  m

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    mCollapsedBounds = new Rect();
    mExpandedBounds = new Rect();
    mCurrentBounds = new RectF();
}