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:com.android.camera.one.v2.OneCameraZslImpl.java

/**
 * Calculate the aspect ratio of the full size capture on this device.
 *
 * @param characteristics the characteristics of the camera device.
 * @return The aspect ration, in terms of width/height of the full capture
 *         size.//www . j  a va  2s .  c  om
 */
private static float calculateFullSizeAspectRatio(CameraCharacteristics characteristics) {
    Rect activeArraySize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
    return ((float) activeArraySize.width()) / activeArraySize.height();
}

From source file:io.plaidapp.ui.widget.CutoutTextView.java

private void calculateTextPosition() {
    float targetWidth = getWidth() / PHI;
    textSize = ViewUtils.getSingleLineTextSize(text, textPaint, targetWidth, 0f, maxTextSize, 0.5f,
            getResources().getDisplayMetrics());
    textPaint.setTextSize(textSize);// w w w.  ja va 2  s. c o m

    // measuring text is fun :] see: https://chris.banes.me/2014/03/27/measuring-text/
    textX = (getWidth() - textPaint.measureText(text)) / 2;
    Rect textBounds = new Rect();
    textPaint.getTextBounds(text, 0, text.length(), textBounds);
    float textHeight = textBounds.height();
    textY = (getHeight() + textHeight) / 2;
}

From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.CircularBorderDrawable.java

/**
 * Creates a vertical {@link LinearGradient}
 * @return/*from  w  w  w.java  2s. c  o m*/
 */
private Shader createGradientShader() {
    final Rect rect = mRect;
    copyBounds(rect);

    final float borderRatio = mBorderWidth / rect.height();

    final int[] colors = new int[6];
    colors[0] = ColorUtils.compositeColors(mTopOuterStrokeColor, mTintColor);
    colors[1] = ColorUtils.compositeColors(mTopInnerStrokeColor, mTintColor);
    colors[2] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mTopInnerStrokeColor, 0), mTintColor);
    colors[3] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mBottomInnerStrokeColor, 0),
            mTintColor);
    colors[4] = ColorUtils.compositeColors(mBottomInnerStrokeColor, mTintColor);
    colors[5] = ColorUtils.compositeColors(mBottomOuterStrokeColor, mTintColor);

    final float[] positions = new float[6];
    positions[0] = 0f;
    positions[1] = borderRatio;
    positions[2] = 0.5f;
    positions[3] = 0.5f;
    positions[4] = 1f - borderRatio;
    positions[5] = 1f;

    return new LinearGradient(0, rect.top, 0, rect.bottom, colors, positions, Shader.TileMode.CLAMP);
}

From source file:com.busdrone.android.ui.VehicleMarkerRenderer.java

private Bitmap render(int color, String text) {
    TextPaint textPaint = new TextPaint();
    textPaint.setColor(Color.WHITE);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setAntiAlias(true);//from ww  w.  j  a v  a  2  s .co m
    textPaint.setTextSize(mTextSize);

    Rect textBounds = new Rect();
    textPaint.getTextBounds(text, 0, text.length(), textBounds);

    int width = mPadding + textBounds.width() + mPadding;
    int height = mPadding + textBounds.height() + mPadding;

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(color);
    canvas.drawRoundRect(new RectF(0, 0, width, height), mCornerRadius, mCornerRadius, paint);

    canvas.drawText(text, (width / 2f) - (textBounds.width() / 2f), (height / 2f) + (textBounds.height() / 2f),
            textPaint);

    return bitmap;
}

From source file:com.tr4android.support.extension.drawable.IndeterminateProgressDrawable.java

/**
 * Helper that calculates the bounds and the stroke width of the progress arc
 *
 * @param bounds the bounds of the drawable
 *//*w ww . ja va  2  s  .c  om*/
private void calculateArcMetrics(Rect bounds) {
    float size = Math.min(bounds.height(), bounds.width());
    float yOffset = (bounds.height() - size) / 2f;
    float xOffset = (bounds.width() - size) / 2f;

    float strokeWidth;
    float padding;
    if (mArcStrokeWidth == -1f && mArcPadding == -1f) {
        // auto calculate bounds
        strokeWidth = 4f / 48f * size;
        padding = 5f / 48f * size;
    } else if (mArcStrokeWidth == -1f) {
        // auto calculate stroke width
        strokeWidth = 4f / 48f * size;
        padding = mArcPadding + strokeWidth / 2;
    } else if (mArcPadding == -1f) {
        // auto calculate padding
        strokeWidth = mArcStrokeWidth;
        padding = 3f / 48f * size + strokeWidth / 2;
    } else {
        strokeWidth = mArcStrokeWidth;
        padding = mArcPadding + strokeWidth / 2;
    }
    mArcPaint.setStrokeWidth(strokeWidth);
    mArcRect.set(bounds.left + padding + xOffset, bounds.top + padding + yOffset,
            bounds.right - padding - xOffset, bounds.bottom - padding - yOffset);
}

From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.AlmostRippleDrawable.java

@Override
public void doDraw(Canvas canvas, Paint paint) {
    Rect bounds = getBounds();
    int size = Math.min(bounds.width(), bounds.height());
    float scale = mCurrentScale;
    int rippleColor = mRippleColor;
    int bgColor = mRippleBgColor;
    float radius = (size / 2);
    float radiusAnimated = radius * scale;
    if (scale > INACTIVE_SCALE) {
        if (bgColor != 0) {
            paint.setColor(bgColor);//from  w  w w .j a v a  2  s . c  o m
            paint.setAlpha(decreasedAlpha(Color.alpha(bgColor)));
            canvas.drawCircle(bounds.centerX(), bounds.centerY(), radius, paint);
        }
        if (rippleColor != 0) {
            paint.setColor(rippleColor);
            paint.setAlpha(modulateAlpha(Color.alpha(rippleColor)));
            canvas.drawCircle(bounds.centerX(), bounds.centerY(), radiusAnimated, paint);
        }
    }
}

From source file:com.android.gallery3d.filtershow.info.InfoPanel.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getDialog() != null) {
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    }// ww w  . j av a 2 s .  c  o m

    mMainView = (LinearLayout) inflater.inflate(R.layout.filtershow_info_panel, null, false);

    mImageThumbnail = (ImageView) mMainView.findViewById(R.id.imageThumbnail);
    Bitmap bitmap = MasterImage.getImage().getFilteredImage();
    mImageThumbnail.setImageBitmap(bitmap);

    mImageName = (TextView) mMainView.findViewById(R.id.imageName);
    mImageSize = (TextView) mMainView.findViewById(R.id.imageSize);
    mExifData = (TextView) mMainView.findViewById(R.id.exifData);
    TextView exifLabel = (TextView) mMainView.findViewById(R.id.exifLabel);

    HistogramView histogramView = (HistogramView) mMainView.findViewById(R.id.histogramView);
    histogramView.setBitmap(bitmap);

    Uri uri = MasterImage.getImage().getUri();
    String path = ImageLoader.getLocalPathFromUri(getActivity(), uri);
    Uri localUri = null;
    if (path != null) {
        localUri = Uri.parse(path);
    }

    if (localUri != null) {
        mImageName.setText(localUri.getLastPathSegment());
    }
    Rect originalBounds = MasterImage.getImage().getOriginalBounds();
    mImageSize.setText("" + originalBounds.width() + " x " + originalBounds.height());

    List<ExifTag> exif = MasterImage.getImage().getEXIF();
    String exifString = "";
    boolean hasExifData = false;
    if (exif != null) {
        for (ExifTag tag : exif) {
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_MODEL, R.string.filtershow_exif_model);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_APERTURE_VALUE,
                    R.string.filtershow_exif_aperture);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_FOCAL_LENGTH,
                    R.string.filtershow_exif_focal_length);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_ISO_SPEED_RATINGS,
                    R.string.filtershow_exif_iso);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_SUBJECT_DISTANCE,
                    R.string.filtershow_exif_subject_distance);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_DATE_TIME_ORIGINAL,
                    R.string.filtershow_exif_date);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_F_NUMBER,
                    R.string.filtershow_exif_f_stop);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_EXPOSURE_TIME,
                    R.string.filtershow_exif_exposure_time);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_COPYRIGHT,
                    R.string.filtershow_exif_copyright);
            hasExifData = true;
        }
    }
    if (hasExifData) {
        exifLabel.setVisibility(View.VISIBLE);
        mExifData.setText(Html.fromHtml(exifString));
    } else {
        exifLabel.setVisibility(View.GONE);
    }
    return mMainView;
}

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

/**
 * Creates a vertical {@link LinearGradient}
 * @return/*  w w w  .  j  a  v  a 2 s.  c  om*/
 */
private Shader createGradientShader() {
    final Rect rect = mRect;
    copyBounds(rect);

    final float borderRatio = mBorderWidth / rect.height();

    final int[] colors = new int[6];
    colors[0] = ColorUtils.compositeColors(mTopOuterStrokeColor, mCurrentBorderTintColor);
    colors[1] = ColorUtils.compositeColors(mTopInnerStrokeColor, mCurrentBorderTintColor);
    colors[2] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mTopInnerStrokeColor, 0),
            mCurrentBorderTintColor);
    colors[3] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mBottomInnerStrokeColor, 0),
            mCurrentBorderTintColor);
    colors[4] = ColorUtils.compositeColors(mBottomInnerStrokeColor, mCurrentBorderTintColor);
    colors[5] = ColorUtils.compositeColors(mBottomOuterStrokeColor, mCurrentBorderTintColor);

    final float[] positions = new float[6];
    positions[0] = 0f;
    positions[1] = borderRatio;
    positions[2] = 0.5f;
    positions[3] = 0.5f;
    positions[4] = 1f - borderRatio;
    positions[5] = 1f;

    return new LinearGradient(0, rect.top, 0, rect.bottom, colors, positions, Shader.TileMode.CLAMP);
}

From source file:org.chromium.chrome.browser.ntp.cards.ImpressionTracker.java

@Override
public boolean onPreDraw() {
    ViewParent parent = mView.getParent();
    if (parent != null) {
        Rect rect = new Rect(0, 0, mView.getWidth(), mView.getHeight());
        parent.getChildVisibleRect(mView, rect, null);
        // Track impression if at least one third of the view is visible.
        if (rect.height() >= mView.getHeight() / 3) {
            mTriggered = true;//from  w w  w  .j  av a 2s.c o  m
            mListener.onImpression();
        }
    }
    // Proceed with the current drawing pass.
    return true;
}

From source file:net.exclaimindustries.geohashdroid.wiki.WikiPictureEditor.java

private static void drawStrings(String[] strings, Canvas c, Paint textPaint, Paint backgroundPaint) {
    // FIXME: The math here is ugly and blunt and probably not too
    // efficient or flexible.  It might even fail.  This needs to be
    // fixed and made less-ugly later.

    // We need SOME strings.  If we've got nothing, bail out.
    if (strings.length < 1)
        return;//www . j a  v  a2  s  . c  o m

    // First, init our variables.  This is as good a place as any to do so.
    Rect textBounds = new Rect();
    int[] heights = new int[strings.length];
    int totalHeight = INFOBOX_MARGIN * 2;
    int longestWidth = 0;

    // Now, loop through the strings, adding to the height and keeping track
    // of the longest width.
    int i = 0;
    for (String s : strings) {
        textPaint.getTextBounds(s, 0, s.length(), textBounds);
        if (textBounds.width() > longestWidth)
            longestWidth = textBounds.width();
        totalHeight += textBounds.height();
        heights[i] = textBounds.height();
        i++;
    }

    // Now, we have us a rectangle.  Draw that.
    Rect drawBounds = new Rect(c.getWidth() - longestWidth - (INFOBOX_MARGIN * 2), 0, c.getWidth(),
            totalHeight);

    c.drawRect(drawBounds, backgroundPaint);

    // Now, place each of the strings.  We'll assume the topmost one is in
    // index 0.  They should all be left-justified, too.
    i = 0;
    int curHeight = 0;
    for (String s : strings) {
        Log.d(DEBUG_TAG, "Drawing " + s + " at " + (drawBounds.left + INFOBOX_MARGIN) + ","
                + (INFOBOX_MARGIN + (INFOBOX_PADDING * (i + 1)) + curHeight));
        c.drawText(s, drawBounds.left + INFOBOX_MARGIN,
                INFOBOX_MARGIN + (INFOBOX_PADDING * (i + 1)) + curHeight, textPaint);
        curHeight += heights[i];
        i++;
    }
}