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:eu.janmuller.android.simplecropimage.CropImage.java

private void onSaveClicked() throws Exception {
    // TODO this code needs to change to use the decode/crop/encode single
    // step api so that we don't require that the whole (possibly large)
    // bitmap doesn't have to be read into memory
    if (mSaving)//  www .  j a va  2 s.com
        return;

    if (mCrop == null) {

        return;
    }

    mSaving = true;

    Rect r = mCrop.getCropRect();

    int width = r.width();
    int height = r.height();

    // If we are circle cropping, we want alpha channel, which is the
    // third param here.
    Bitmap croppedImage;
    try {

        croppedImage = Bitmap.createBitmap(width, height,
                mCircleCrop ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } catch (Exception e) {
        throw e;
    }
    if (croppedImage == null) {

        return;
    }

    {
        Canvas canvas = new Canvas(croppedImage);
        Rect dstRect = new Rect(0, 0, width, height);
        canvas.drawBitmap(mBitmap, r, dstRect, null);
    }

    if (mCircleCrop) {

        // OK, so what's all this about?
        // Bitmaps are inherently rectangular but we want to return
        // something that's basically a circle.  So we fill in the
        // area around the circle with alpha.  Note the all important
        // PortDuff.Mode.CLEAR.
        Canvas c = new Canvas(croppedImage);
        Path p = new Path();
        p.addCircle(width / 2F, height / 2F, width / 2F, Path.Direction.CW);
        c.clipPath(p, Region.Op.DIFFERENCE);
        c.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
    }

    /* If the output is required to a specific size then scale or fill */
    if (mOutputX != 0 && mOutputY != 0) {

        if (mScale) {

            /* Scale the image to the required dimensions */
            Bitmap old = croppedImage;
            croppedImage = Util.transform(new Matrix(), croppedImage, mOutputX, mOutputY, mScaleUp);
            if (old != croppedImage) {

                old.recycle();
            }
        } else {

            /* Don't scale the image crop it to the size requested.
                 * Create an new image with the cropped image in the center and
             * the extra space filled.
             */

            // Don't scale the image but instead fill it so it's the
            // required dimension
            Bitmap b = Bitmap.createBitmap(mOutputX, mOutputY, Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(b);

            Rect srcRect = mCrop.getCropRect();
            Rect dstRect = new Rect(0, 0, mOutputX, mOutputY);

            int dx = (srcRect.width() - dstRect.width()) / 2;
            int dy = (srcRect.height() - dstRect.height()) / 2;

            /* If the srcRect is too big, use the center part of it. */
            srcRect.inset(Math.max(0, dx), Math.max(0, dy));

            /* If the dstRect is too big, use the center part of it. */
            dstRect.inset(Math.max(0, -dx), Math.max(0, -dy));

            /* Draw the cropped bitmap in the center */
            canvas.drawBitmap(mBitmap, srcRect, dstRect, null);

            /* Set the cropped bitmap as the new bitmap */
            croppedImage.recycle();
            croppedImage = b;
        }
    }

    // Return the cropped image directly or save it to the specified URI.
    Bundle myExtras = getIntent().getExtras();
    if (myExtras != null && (myExtras.getParcelable("data") != null || myExtras.getBoolean(RETURN_DATA))) {

        Bundle extras = new Bundle();
        extras.putParcelable(RETURN_DATA_AS_BITMAP, croppedImage);
        setResult(RESULT_OK, (new Intent()).setAction(ACTION_INLINE_DATA).putExtras(extras));
        finish();
    } else {
        final Bitmap b = croppedImage;
        Util.startBackgroundJob(this, null, getString(R.string.saving_image), new Runnable() {
            public void run() {

                saveOutput(b);
            }
        }, mHandler);
    }
}

From source file:com.futurologeek.smartcrossing.crop.CropImageActivity.java

private void onSaveClicked() {
    if (cropView == null || isSaving) {
        return;// w w w .j a v  a  2 s  .  c  o  m
    }
    isSaving = true;

    Bitmap croppedImage;
    Rect r = cropView.getScaledCropRect(sampleSize);
    int width = r.width();
    int height = r.height();

    int outWidth = width;
    int outHeight = height;
    if (maxX > 0 && maxY > 0 && (width > maxX || height > maxY)) {
        float ratio = (float) width / (float) height;
        if ((float) maxX / (float) maxY > ratio) {
            outHeight = maxY;
            outWidth = (int) ((float) maxY * ratio + .5f);
        } else {
            outWidth = maxX;
            outHeight = (int) ((float) maxX / ratio + .5f);
        }
    }

    try {
        croppedImage = decodeRegionCrop(r, outWidth, outHeight);
    } catch (IllegalArgumentException e) {
        setResultException(e);
        finish();
        return;
    }

    if (croppedImage != null) {
        imageView.setImageRotateBitmapResetBase(new RotateBitmap(croppedImage, exifRotation), true);
        imageView.center();
        imageView.highlightViews.clear();
    }
    saveImage(croppedImage);
}

From source file:foam.starwisp.DrawableMap.java

public Marker AddText(final LatLng location, final String text, final int padding, final int fontSize,
        int colour) {
    Marker marker = null;/*from   w w w.  j  a v  a 2 s  .  c o m*/

    final TextView textView = new TextView(m_Context);
    textView.setText(text);
    textView.setTextSize(fontSize);
    textView.setTypeface(m_Context.m_Typeface);

    final Paint paintText = textView.getPaint();

    final Rect boundsText = new Rect();
    paintText.getTextBounds(text, 0, textView.length(), boundsText);
    paintText.setTextAlign(Paint.Align.CENTER);

    final Bitmap.Config conf = Bitmap.Config.ARGB_8888;
    final Bitmap bmpText = Bitmap.createBitmap(boundsText.width() + 2 * padding,
            boundsText.height() + 2 * padding, conf);

    final Canvas canvasText = new Canvas(bmpText);
    paintText.setColor(Color.BLACK);

    canvasText.drawText(text, (canvasText.getWidth() / 2) + 3,
            (canvasText.getHeight() - padding - boundsText.bottom) + 3, paintText);

    paintText.setColor(colour);

    canvasText.drawText(text, canvasText.getWidth() / 2, canvasText.getHeight() - padding - boundsText.bottom,
            paintText);

    final MarkerOptions markerOptions = new MarkerOptions().position(location)
            .icon(BitmapDescriptorFactory.fromBitmap(bmpText)).anchor(0.5f, 1);

    marker = map.addMarker(markerOptions);

    return marker;
}

From source file:com.dgnt.dominionCardPicker.view.DynamicListView.java

/**
 * This method is in charge of determining if the hover cell is above
 * or below the bounds of the listview. If so, the listview does an appropriate
 * upward or downward smooth scroll so as to reveal new items.
 *///w ww.  ja v  a  2  s  . c  o  m
public boolean handleMobileCellScroll(Rect r) {
    int offset = computeVerticalScrollOffset();
    int height = getHeight();
    int extent = computeVerticalScrollExtent();
    int range = computeVerticalScrollRange();
    int hoverViewTop = r.top;
    int hoverHeight = r.height();

    if (hoverViewTop <= 0 && offset > 0) {
        smoothScrollBy(-mSmoothScrollAmountAtEdge, 0);
        return true;
    }

    if (hoverViewTop + hoverHeight >= height && (offset + extent) < range) {
        smoothScrollBy(mSmoothScrollAmountAtEdge, 0);
        return true;
    }

    return false;
}

From source file:com.pixby.texo.MainActivity.java

private void startSaveService(int folderLocation, int outputSizeFlag, int outputDestination) {

    String path = ImageUtil.getOutputFolder(this, mSourceImage.getFileName(), folderLocation);
    Rect outputSize = ImageUtil.calcTargetSize(mSourceImage.getWidth(), mSourceImage.getHeight(),
            outputSizeFlag);// www  .  j ava 2s  .  c om

    Intent intent = new Intent(this, SaveImageService.class);
    intent.putExtra(SaveImageService.SOURCE_IMAGE_URI, mSourceImage.getUri());
    intent.putExtra(SaveImageService.WATERMARK_JSON, mWatermark.toJson());
    intent.putExtra(SaveImageService.OUTPUT_PATH, path);
    intent.putExtra(SaveImageService.OUTPUT_WIDTH, outputSize.width());
    intent.putExtra(SaveImageService.OUTPUT_HEIGHT, outputSize.height());
    intent.putExtra(SaveImageService.OUTPUT_DESTINATION, outputDestination);
    startService(intent);
}

From source file:net.sf.fakenames.dispatcher.MaterialProgressDrawable.java

@Override
protected void onBoundsChange(Rect bounds) {
    super.onBoundsChange(bounds);

    mWidth = bounds.width();//w  w w.  j  a v a 2s . c  o m
    mHeight = bounds.height();

    invalidateSelf();
}

From source file:com.slushpupie.deskclock.DeskClock.java

private float fitTextToRect(Typeface font, String text, Rect fitRect) {

    int width = fitRect.width();
    int height = fitRect.height();

    int minGuess = 0;
    int maxGuess = 640;
    int guess = 320;

    Rect r;/*from  ww  w  . j a va  2  s  .c om*/
    boolean lastGuessTooSmall = true;

    for (int i = 0; i < 32; i++) {

        if (minGuess + 1 == maxGuess) {
            Log.d(LOG_TAG, "Discovered font size " + minGuess);
            r = getBoundingBox(text, font, guess);
            return minGuess;
        }

        r = getBoundingBox(text, font, guess);
        if (r.width() > width || r.height() > height) {
            maxGuess = guess;
            lastGuessTooSmall = false;

        } else {
            minGuess = guess;
            lastGuessTooSmall = true;
        }
        guess = (minGuess + maxGuess) / 2;
    }

    Log.d(LOG_TAG, "Unable to discover font size");
    if (lastGuessTooSmall)
        return maxGuess;
    else
        return minGuess;

}

From source file:com.coreform.open.android.formidablevalidation.SetErrorHandler.java

/**
  * Sets the Drawables (if any) to appear to the left of, above,
  * to the right of, and below the text.  Use null if you do not
  * want a Drawable there.  The Drawables must already have had
  * {@link Drawable#setBounds} called.//from   w  w  w.  j av  a  2s . c o m
  *
  * @attr ref android.R.styleable#TextView_drawableLeft
  * @attr ref android.R.styleable#TextView_drawableTop
  * @attr ref android.R.styleable#TextView_drawableRight
  * @attr ref android.R.styleable#TextView_drawableBottom
  */
public void setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom) {
    Drawables dr = mDrawables;

    final boolean drawables = left != null || top != null || right != null || bottom != null;

    if (!drawables) {
        // Clearing drawables...  can we free the data structure?
        if (dr != null) {
            if (dr.mDrawablePadding == 0) {
                mDrawables = null;
            } else {
                // We need to retain the last set padding, so just clear
                // out all of the fields in the existing structure.
                dr.mDrawableLeft = null;
                dr.mDrawableTop = null;
                dr.mDrawableRight = null;
                dr.mDrawableBottom = null;
                dr.mDrawableSizeLeft = dr.mDrawableHeightLeft = 0;
                dr.mDrawableSizeRight = dr.mDrawableHeightRight = 0;
                dr.mDrawableSizeTop = dr.mDrawableWidthTop = 0;
                dr.mDrawableSizeBottom = dr.mDrawableWidthBottom = 0;
            }
        }
    } else {
        if (dr == null) {
            mDrawables = dr = new Drawables();
        }

        dr.mDrawableLeft = left;
        dr.mDrawableTop = top;
        dr.mDrawableRight = right;
        dr.mDrawableBottom = bottom;

        final Rect compoundRect = dr.mCompoundRect;
        int[] state = null;

        state = mView.getDrawableState();

        if (left != null) {
            left.setState(state);
            left.copyBounds(compoundRect);
            dr.mDrawableSizeLeft = compoundRect.width();
            dr.mDrawableHeightLeft = compoundRect.height();
        } else {
            dr.mDrawableSizeLeft = dr.mDrawableHeightLeft = 0;
        }

        if (right != null) {
            right.setState(state);
            right.copyBounds(compoundRect);
            dr.mDrawableSizeRight = compoundRect.width();
            dr.mDrawableHeightRight = compoundRect.height();
        } else {
            dr.mDrawableSizeRight = dr.mDrawableHeightRight = 0;
        }

        if (top != null) {
            top.setState(state);
            top.copyBounds(compoundRect);
            dr.mDrawableSizeTop = compoundRect.height();
            dr.mDrawableWidthTop = compoundRect.width();
        } else {
            dr.mDrawableSizeTop = dr.mDrawableWidthTop = 0;
        }

        if (bottom != null) {
            bottom.setState(state);
            bottom.copyBounds(compoundRect);
            dr.mDrawableSizeBottom = compoundRect.height();
            dr.mDrawableWidthBottom = compoundRect.width();
        } else {
            dr.mDrawableSizeBottom = dr.mDrawableWidthBottom = 0;
        }
    }

    mView.invalidate();
    mView.requestLayout();
}

From source file:com.waz.zclient.pages.main.drawing.DrawingFragment.java

private ImageAsset getFinalSketchImage() {
    Bitmap finalBitmap = getBitmapDrawing();
    try {/* w ww  .j av  a2  s . co  m*/
        Rect bitmapTrim = drawingCanvasView.getImageTrimValues();
        MemoryImageCache.reserveImageMemory(bitmapTrim.width(), bitmapTrim.height());
        finalBitmap = Bitmap.createBitmap(finalBitmap, bitmapTrim.left, bitmapTrim.top, bitmapTrim.width(),
                bitmapTrim.height());
    } catch (Throwable t) {
        // ignore
    }
    return ImageAssetFactory.getImageAsset(finalBitmap, ExifInterface.ORIENTATION_NORMAL);
}

From source file:org.mozilla.search.MainActivity.java

/**
 * Animates search suggestion to search bar. This animation has 2 main parts:
 *
 *   1) Vertically translate query text from suggestion card to search bar.
 *   2) Expand suggestion card to fill the results view area.
 *
 * @param query/* ww w. j  ava2s . c o  m*/
 * @param suggestionAnimation
 */
private void animateSuggestion(final String query, final SuggestionAnimation suggestionAnimation) {
    animationText.setText(query);

    final Rect startBounds = suggestionAnimation.getStartBounds();
    final Rect endBounds = new Rect();
    animationCard.getGlobalVisibleRect(endBounds, null);

    // Vertically translate the animated card to align with the start bounds.
    final float cardStartY = startBounds.centerY() - endBounds.centerY();

    // Account for card background padding when calculating start scale.
    final float startScaleX = (float) (startBounds.width() - cardPaddingX * 2) / endBounds.width();
    final float startScaleY = (float) (startBounds.height() - cardPaddingY * 2) / endBounds.height();

    animationText.setVisibility(View.VISIBLE);
    animationCard.setVisibility(View.VISIBLE);

    final AnimatorSet set = new AnimatorSet();
    set.playTogether(ObjectAnimator.ofFloat(animationText, "translationY", startBounds.top, textEndY),
            ObjectAnimator.ofFloat(animationCard, "translationY", cardStartY, 0),
            ObjectAnimator.ofFloat(animationCard, "alpha", 0.5f, 1),
            ObjectAnimator.ofFloat(animationCard, "scaleX", startScaleX, 1f),
            ObjectAnimator.ofFloat(animationCard, "scaleY", startScaleY, 1f));

    set.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            setEditState(EditState.WAITING);
            setSearchState(SearchState.POSTSEARCH);

            editText.setText(query);

            // We need to manually clear the animation for the views to be hidden on gingerbread.
            animationText.clearAnimation();
            animationCard.clearAnimation();

            animationText.setVisibility(View.INVISIBLE);
            animationCard.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });

    set.setDuration(SUGGESTION_TRANSITION_DURATION);
    set.setInterpolator(SUGGESTION_TRANSITION_INTERPOLATOR);

    set.start();
}