Example usage for android.graphics Rect height

List of usage examples for android.graphics Rect height

Introduction

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

Prototype

public final int height() 

Source Link

Usage

From source file:org.caojun.library.cropimage.HighlightView.java

protected void draw(Canvas canvas) {

    if (mHidden) {
        return;/*from ww  w . j ava  2 s  . co  m*/
    }

    Path path = new Path();
    if (!hasFocus()) {
        mOutlinePaint.setColor(0xFF000000);
        canvas.drawRect(mDrawRect, mOutlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        mView.getDrawingRect(viewDrawingRect);
        if (mCircle) {

            canvas.save();

            float width = mDrawRect.width();
            float height = mDrawRect.height();
            path.addCircle(mDrawRect.left + (width / 2), mDrawRect.top + (height / 2), width / 2,
                    Path.Direction.CW);
            mOutlinePaint.setColor(0xFFEF04D6);

            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint);

            canvas.restore();

        } else {

            Rect topRect = new Rect(viewDrawingRect.left, viewDrawingRect.top, viewDrawingRect.right,
                    mDrawRect.top);
            if (topRect.width() > 0 && topRect.height() > 0) {
                canvas.drawRect(topRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect bottomRect = new Rect(viewDrawingRect.left, mDrawRect.bottom, viewDrawingRect.right,
                    viewDrawingRect.bottom);
            if (bottomRect.width() > 0 && bottomRect.height() > 0) {
                canvas.drawRect(bottomRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect leftRect = new Rect(viewDrawingRect.left, topRect.bottom, mDrawRect.left, bottomRect.top);
            if (leftRect.width() > 0 && leftRect.height() > 0) {
                canvas.drawRect(leftRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect rightRect = new Rect(mDrawRect.right, topRect.bottom, viewDrawingRect.right, bottomRect.top);
            if (rightRect.width() > 0 && rightRect.height() > 0) {
                canvas.drawRect(rightRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }

            path.addRect(new RectF(mDrawRect), Path.Direction.CW);

            mOutlinePaint.setColor(0xFFFF8A00);

        }

        canvas.drawPath(path, mOutlinePaint);

        if (mMode == ModifyMode.Grow) {
            if (mCircle) {
                int width = mResizeDrawableDiagonal.getIntrinsicWidth();
                int height = mResizeDrawableDiagonal.getIntrinsicHeight();

                int d = (int) Math.round(Math.cos(/*45deg*/Math.PI / 4D) * (mDrawRect.width() / 2D));
                int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2;
                int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2;
                mResizeDrawableDiagonal.setBounds(x, y, x + mResizeDrawableDiagonal.getIntrinsicWidth(),
                        y + mResizeDrawableDiagonal.getIntrinsicHeight());
                mResizeDrawableDiagonal.draw(canvas);
            } else {
                int left = mDrawRect.left + 1;
                int right = mDrawRect.right + 1;
                int top = mDrawRect.top + 4;
                int bottom = mDrawRect.bottom + 3;

                int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2;
                int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2;
                int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2;
                int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2;

                int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2);
                int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2);

                mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth,
                        yMiddle + widthHeight);
                mResizeDrawableWidth.draw(canvas);

                mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth,
                        yMiddle + widthHeight);
                mResizeDrawableWidth.draw(canvas);

                mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top - heightHeight,
                        xMiddle + heightWidth, top + heightHeight);
                mResizeDrawableHeight.draw(canvas);

                mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom - heightHeight,
                        xMiddle + heightWidth, bottom + heightHeight);
                mResizeDrawableHeight.draw(canvas);
            }
        }
    }
}

From source file:com.example.gatsu.theevent.HighlightView.java

void handleMotion(int edge, float dx, float dy) {

    Rect r = computeLayout();
    if (edge == GROW_NONE) {
        return;/*from   ww  w  . j a v  a 2 s  .  co m*/
    } else if (edge == MOVE) {
        // Convert to image space before sending to moveBy().
        moveBy(dx * (mCropRect.width() / r.width()), dy * (mCropRect.height() / r.height()));
    } else {
        if (((GROW_LEFT_EDGE | GROW_RIGHT_EDGE) & edge) == 0) {
            dx = 0;
        }

        if (((GROW_TOP_EDGE | GROW_BOTTOM_EDGE) & edge) == 0) {
            dy = 0;
        }

        // Convert to image space before sending to growBy().
        float xDelta = dx * (mCropRect.width() / r.width());
        float yDelta = dy * (mCropRect.height() / r.height());
        growBy((((edge & GROW_LEFT_EDGE) != 0) ? -1 : 1) * xDelta,
                (((edge & GROW_TOP_EDGE) != 0) ? -1 : 1) * yDelta);
    }
}

From source file:org.sufficientlysecure.keychain.gm.GmAccessibilityService.java

@SuppressLint("RtlHardcoded")
private void drawOverlay(AccessibilityNodeInfo node, View.OnClickListener onClickListener) {

    mOverlay = new FrameLayout(this);

    // must be encapsulated into FrameLayout for animation
    FrameLayout mAnimatedChild = new FrameLayout(this);
    LayoutInflater systemInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final Context contextThemeWrapper = new ContextThemeWrapper(this, R.style.FixedBottomSheetTheme);
    LayoutInflater inflater = systemInflater.cloneInContext(contextThemeWrapper);

    View child = inflater.inflate(R.layout.fixed_bottom_sheet, null);
    mAnimatedChild.addView(child);// www . ja va  2s .c o  m

    Button b = (Button) child.findViewById(R.id.fixed_bottom_sheet_button);
    b.setText(R.string.decrypt_with_openkeychain);
    b.setOnClickListener(onClickListener);

    ImageButton close = (ImageButton) child.findViewById(R.id.fixed_bottom_sheet_close);
    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            closeOverlay();
        }
    });

    Rect webviewRect = new Rect();
    node.getBoundsInScreen(webviewRect);

    Display display = mWindowManager.getDefaultDisplay();
    Rect displayRect = new Rect();
    display.getRectSize(displayRect);

    int xpos = webviewRect.left;
    int ypos = webviewRect.top - getStatusBarHeight() < getToolbarHeight() ? getToolbarHeight()
            : webviewRect.top - getStatusBarHeight();

    int width = webviewRect.width();
    int height = webviewRect.bottom < displayRect.height()
            ? webviewRect.bottom - getToolbarHeight() - getStatusBarHeight()
            : displayRect.height() - ypos - getStatusBarHeight();

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(width, height, xpos, ypos,
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.windowAnimations = R.style.OverlayAnimation;
    mWindowManager.addView(mOverlay, params);
    mOverlay.addView(mAnimatedChild);
}

From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java

/**
 * This function calculates a screen to image Transformation matrix.
 *
 * @param reflectRotation//w w  w  . java  2s.  c  o  m
 *            set true if you want the rotation encoded.
 *            TODO useless, to be removed.
 * @return Screen to Image transformation matrix
 */
protected Matrix getScreenToImageMatrix(boolean reflectRotation) {
    Rect originalBounds = mMasterImage.getOriginalBounds();
    int imgWidth = originalBounds.width();
    int imgHeight = originalBounds.height();

    Matrix m = mMasterImage.getImageToScreenMatrix(imgWidth, imgHeight, getWidth(), getHeight());
    Matrix invert = new Matrix();
    m.invert(invert);
    return invert;
}

From source file:com.mikelau.croperino.HighlightView.java

protected void draw(Canvas canvas) {

    if (mHidden) {
        return;//from   w ww.ja va2  s  .co  m
    }

    Path path = new Path();
    if (!hasFocus()) {
        mOutlinePaint.setColor(0xFF000000);
        canvas.drawRect(mDrawRect, mOutlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        mContext.getDrawingRect(viewDrawingRect);
        if (mCircle) {

            canvas.save();

            float width = mDrawRect.width();
            float height = mDrawRect.height();
            path.addCircle(mDrawRect.left + (width / 2), mDrawRect.top + (height / 2), width / 2,
                    Path.Direction.CW);
            mOutlinePaint.setColor(0xFFEF04D6);

            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint);

            canvas.restore();

        } else if (mOvalo) {
            canvas.save();

            RectF r = new RectF(mDrawRect.left, mDrawRect.top, mDrawRect.right, mDrawRect.bottom);

            path.addOval(r, Path.Direction.CW);
            mOutlinePaint.setColor(0xFFEF04D6);

            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint);

            canvas.restore();
        } else {

            Rect topRect = new Rect(viewDrawingRect.left, viewDrawingRect.top, viewDrawingRect.right,
                    mDrawRect.top);
            if (topRect.width() > 0 && topRect.height() > 0) {
                canvas.drawRect(topRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect bottomRect = new Rect(viewDrawingRect.left, mDrawRect.bottom, viewDrawingRect.right,
                    viewDrawingRect.bottom);
            if (bottomRect.width() > 0 && bottomRect.height() > 0) {
                canvas.drawRect(bottomRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect leftRect = new Rect(viewDrawingRect.left, topRect.bottom, mDrawRect.left, bottomRect.top);
            if (leftRect.width() > 0 && leftRect.height() > 0) {
                canvas.drawRect(leftRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }
            Rect rightRect = new Rect(mDrawRect.right, topRect.bottom, viewDrawingRect.right, bottomRect.top);
            if (rightRect.width() > 0 && rightRect.height() > 0) {
                canvas.drawRect(rightRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
            }

            path.addRect(new RectF(mDrawRect), Path.Direction.CW);

            mOutlinePaint.setColor(0xFFFF8A00);

        }

        canvas.drawPath(path, mOutlinePaint);

        if (mMode == ModifyMode.Grow) {
            if (mCircle) {
                int width = mResizeDrawableDiagonal.getIntrinsicWidth();
                int height = mResizeDrawableDiagonal.getIntrinsicHeight();

                int d = (int) Math.round(Math.cos(/*45deg*/Math.PI / 4D) * (mDrawRect.width() / 2D));
                int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2;
                int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2;
                mResizeDrawableDiagonal.setBounds(x, y, x + mResizeDrawableDiagonal.getIntrinsicWidth(),
                        y + mResizeDrawableDiagonal.getIntrinsicHeight());
                mResizeDrawableDiagonal.draw(canvas);
            } else {
                int left = mDrawRect.left + 1;
                int right = mDrawRect.right + 1;
                int top = mDrawRect.top + 4;
                int bottom = mDrawRect.bottom + 3;

                int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2;
                int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2;
                int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2;
                int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2;

                int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2);
                int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2);

                mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth,
                        yMiddle + widthHeight);
                mResizeDrawableWidth.draw(canvas);

                mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth,
                        yMiddle + widthHeight);
                mResizeDrawableWidth.draw(canvas);

                mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top - heightHeight,
                        xMiddle + heightWidth, top + heightHeight);
                mResizeDrawableHeight.draw(canvas);

                mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom - heightHeight,
                        xMiddle + heightWidth, bottom + heightHeight);
                mResizeDrawableHeight.draw(canvas);
            }
        }
    }
}

From source file:com.example.conallcurran.quick_click.English_Infants.java

private void zoomImageFromThumb(final View thumbView, int imageResId) {

    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();//www . j a v a  2  s .  c  o m
    }

    final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image);
    expandedImageView.setImageResource(imageResId);
    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    thumbView.getGlobalVisibleRect(startBounds);
    findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset);
    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 {
        // Extend start bounds vertically
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    thumbView.setAlpha(0f);
    expandedImageView.setVisibility(View.VISIBLE);

    expandedImageView.setPivotX(0f);
    expandedImageView.setPivotY(0f);

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

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

    final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mCurrentAnimator != null) {
                mCurrentAnimator.cancel();
            }

            // Animate the four positioning/sizing properties in parallel, back to their
            // original values.
            AnimatorSet set = new AnimatorSet();
            set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal));
            set.setDuration(mShortAnimationDuration);
            set.setInterpolator(new DecelerateInterpolator());
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }
            });
            set.start();
            mCurrentAnimator = set;
        }
    });
}

From source file:de.madvertise.android.sdk.MadView.java

/**
 * Convenicence method for a shiny background for text ads
 * /*www. ja v a2s. co  m*/
 * @param rect
 * @param backgroundColor
 * @param textColor
 * @return
 */
private BitmapDrawable generateBackgroundDrawable(Rect rect, int backgroundColor, int shineColor) {
    try {
        Bitmap bitmap = Bitmap.createBitmap(rect.width(), rect.height(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawTextBannerBackground(canvas, rect, backgroundColor, shineColor);
        return new BitmapDrawable(bitmap);
    } catch (Throwable t) {
        return null;
    }
}

From source file:com.android.contacts.activities.PhotoSelectionActivity.java

/**
 * Compute the adjusted expanded photo size to fit within the enclosing view with the same
 * aspect ratio./*from w  w w  .j a v  a  2s.c om*/
 * @param enclosingView This is the view that the photo must fit within.
 * @param heightOffset This is the amount of height to leave open for the photo action popup.
 */
private int getAdjustedExpandedPhotoSize(View enclosingView, int heightOffset) {
    // pull out the bounds of the backdrop
    final Rect bounds = new Rect();
    enclosingView.getDrawingRect(bounds);
    final int boundsWidth = bounds.width();
    final int boundsHeight = bounds.height() - heightOffset;

    // ensure that the new expanded photo size can fit within the backdrop
    final float alpha = Math.min((float) boundsHeight / (float) mExpandedPhotoSize,
            (float) boundsWidth / (float) mExpandedPhotoSize);
    if (alpha < 1.0f) {
        // need to shrink width and height while maintaining aspect ratio
        return (int) (alpha * mExpandedPhotoSize);
    } else {
        return mExpandedPhotoSize;
    }
}

From source file:com.duy.pascal.ui.editor.view.CodeSuggestsEditText.java

/**
 * this method will be change size of popup window
 *//*from w  ww.  j a  v a 2  s .  c  om*/
protected void onDropdownChangeSize(int w, int h) {

    Rect rect = new Rect();
    getWindowVisibleDisplayFrame(rect);

    DLog.d(TAG, "onDropdownChangeSize: " + rect);
    w = rect.width();
    h = rect.height();

    // 1/2 width of screen
    setDropDownWidth((int) (w * 0.7f));

    // 0.5 height of screen
    setDropDownHeight((int) (h * 0.5f));

    //change position
    onPopupChangePosition();
}

From source file:com.googlecode.eyesfree.example.bargraph.BarGraphView.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final int widthSize = MeasureSpec.getSize(widthMeasureSpec);

    int measuredHeight = heightSize;
    int measuredWidth = widthSize;

    final Rect contentBounds = mTempRect;
    getContentBounds(contentBounds);//from  w  w  w. j ava  2  s  . co  m

    if (heightMode != MeasureSpec.EXACTLY) {
        measuredHeight = contentBounds.height();

        if (heightMode == MeasureSpec.AT_MOST) {
            if (measuredHeight > heightSize) {
                measuredHeight = heightSize;
            }
        }
    }

    if (widthMode == MeasureSpec.UNSPECIFIED) {
        measuredWidth = contentBounds.width();
    }

    setMeasuredDimension(measuredWidth, measuredHeight);
}