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.coco.rolldigitaltextview.RollDigitalTextView.java

private boolean isCompleteShown() {
    if (isShown()) {
        final Rect visibleRect = new Rect();
        if (getLocalVisibleRect(visibleRect) && visibleRect.width() == getWidth()
                && visibleRect.height() == getHeight()) {
            return true;
        }//  w ww  .j a v a2s.c o  m
    }
    return false;
}

From source file:Main.java

/**
 * Special crop of bitmap rotated by not stright angle, in this case the original crop bitmap contains parts
 * beyond the required crop area, this method crops the already cropped and rotated bitmap to the final
 * rectangle.<br>//www .j  a v  a2s. c o m
 * Note: rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping.
 */
private static Bitmap cropForRotatedImage(Bitmap bitmap, float[] points, Rect rect, int degreesRotated,
        boolean fixAspectRatio, int aspectRatioX, int aspectRatioY) {
    if (degreesRotated % 90 != 0) {

        int adjLeft = 0, adjTop = 0, width = 0, height = 0;
        double rads = Math.toRadians(degreesRotated);
        int compareTo = degreesRotated < 90 || (degreesRotated > 180 && degreesRotated < 270) ? rect.left
                : rect.right;
        for (int i = 0; i < points.length; i += 2) {
            if (points[i] >= compareTo - 1 && points[i] <= compareTo + 1) {
                adjLeft = (int) Math.abs(Math.sin(rads) * (rect.bottom - points[i + 1]));
                adjTop = (int) Math.abs(Math.cos(rads) * (points[i + 1] - rect.top));
                width = (int) Math.abs((points[i + 1] - rect.top) / Math.sin(rads));
                height = (int) Math.abs((rect.bottom - points[i + 1]) / Math.cos(rads));
                break;
            }
        }

        rect.set(adjLeft, adjTop, adjLeft + width, adjTop + height);
        if (fixAspectRatio) {
            fixRectForAspectRatio(rect, aspectRatioX, aspectRatioY);
        }

        Bitmap bitmapTmp = bitmap;
        bitmap = Bitmap.createBitmap(bitmap, rect.left, rect.top, rect.width(), rect.height());
        if (bitmapTmp != bitmap) {
            bitmapTmp.recycle();
        }
    }
    return bitmap;
}

From source file:pl.mg6.newmaps.demo.MarkersExampleActivity.java

private Bitmap prepareBitmap() {
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_left);
    bitmap = bitmap.copy(Config.ARGB_8888, true);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);// w w w  . ja v a  2s. co  m
    paint.setColor(Color.WHITE);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(getResources().getDimension(R.dimen.text_size));
    String text = "mg6";
    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    float x = bitmap.getWidth() / 2.0f;
    float y = (bitmap.getHeight() - bounds.height()) / 2.0f - bounds.top;
    canvas.drawText(text, x, y, paint);
    return bitmap;
}

From source file:im.neon.util.VectorUtils.java

/**
 * Create an avatar bitmap from a text.//from   w ww  .j  a v  a2s  .  co  m
 *
 * @param backgroundColor the background color.
 * @param text            the text to display.
 * @param pixelsSide      the avatar side in pixels
 * @return the generated bitmap
 */
private static Bitmap createAvatar(int backgroundColor, String text, int pixelsSide) {
    android.graphics.Bitmap.Config bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;

    Bitmap bitmap = Bitmap.createBitmap(pixelsSide, pixelsSide, bitmapConfig);
    Canvas canvas = new Canvas(bitmap);

    canvas.drawColor(backgroundColor);

    // prepare the text drawing
    Paint textPaint = new Paint();
    textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
    textPaint.setColor(Color.WHITE);
    // the text size is proportional to the avatar size.
    // by default, the avatar size is 42dp, the text size is 28 dp (not sp because it has to be fixed).
    textPaint.setTextSize(pixelsSide * 2 / 3);

    // get its size
    Rect textBounds = new Rect();
    textPaint.getTextBounds(text, 0, text.length(), textBounds);

    // draw the text in center
    canvas.drawText(text, (canvas.getWidth() - textBounds.width() - textBounds.left) / 2,
            (canvas.getHeight() + textBounds.height() - textBounds.bottom) / 2, textPaint);

    // Return the avatar
    return bitmap;
}

From source file:com.ruesga.rview.widget.MergedStatusChart.java

public MergedStatusChart(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);

    final Resources res = getResources();
    mHeightBarPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, res.getDisplayMetrics());
    mMinBarWidth = 0f;/*from w  w w.ja  va  2s.c om*/
    int openColor = Color.DKGRAY;
    int mergedColor = Color.DKGRAY;
    int abandonedColor = Color.DKGRAY;
    int textColor = Color.WHITE;

    Resources.Theme theme = context.getTheme();
    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.MergedStatusChart, defStyleAttr, 0);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case R.styleable.MergedStatusChart_heightBarPadding:
            mHeightBarPadding = a.getDimension(attr, mHeightBarPadding);
            break;

        case R.styleable.MergedStatusChart_minBarWidth:
            mMinBarWidth = a.getDimension(attr, mMinBarWidth);
            break;

        case R.styleable.MergedStatusChart_openColor:
            openColor = a.getColor(attr, openColor);
            break;

        case R.styleable.MergedStatusChart_mergedColor:
            mergedColor = a.getColor(attr, mergedColor);
            break;

        case R.styleable.MergedStatusChart_abandonedColor:
            abandonedColor = a.getColor(attr, abandonedColor);
            break;

        case R.styleable.MergedStatusChart_statusLabelTextColor:
            textColor = a.getColor(attr, textColor);
            break;
        }
    }
    a.recycle();

    mOpenPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mOpenPaint.setStyle(Paint.Style.FILL);
    mMergedPaint = new Paint(mOpenPaint);
    mAbandonedPaint = new Paint(mOpenPaint);
    mOpenPaint.setColor(openColor);
    mMergedPaint.setColor(mergedColor);
    mAbandonedPaint.setColor(abandonedColor);

    mLabelPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mLabelPaint.setTextAlign(Paint.Align.LEFT);
    mLabelPaint.setFakeBoldText(true);
    mLabelPaint.setColor(textColor);
    mLabelPaint
            .setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 10f, res.getDisplayMetrics()));
    mLabelPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 2f, res.getDisplayMetrics());
    Rect bounds = new Rect();
    mLabelPaint.getTextBounds("0", 0, 1, bounds);
    mLabelHeight = bounds.height();

    if (getBackground() == null) {
        setBackgroundColor(Color.TRANSPARENT);
    }
}

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 v a 2  s. c o  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:com.vincestyling.traversaless_testcase.TopTabIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mViewPager == null)
        return;/*from  w ww . j a v a  2s  .c  o  m*/

    final int count = getCount();
    if (count == 0)
        return;

    Rect areaRect = new Rect();
    areaRect.left = getPaddingLeft();
    areaRect.right = getWidth() - getPaddingRight();
    areaRect.top = getPaddingTop();
    areaRect.bottom = getHeight() - getPaddingBottom();

    int btnWidth = areaRect.width() / count;

    Rect tabRect = new Rect(areaRect);
    tabRect.top = tabRect.height() - mUnderlineHeight;
    tabRect.left += (mScrollingToPage + mPageOffset) * btnWidth;
    tabRect.right = tabRect.left + btnWidth;
    mPaint.setColor(mUnderlineColor);
    canvas.drawRect(tabRect, mPaint);

    mPaint.setColor(mTextColor);
    mPaint.setTextSize(mTextSize);

    for (int pos = 0; pos < count; pos++) {
        tabRect.set(areaRect);
        tabRect.left += pos * btnWidth;
        tabRect.right = tabRect.left + btnWidth;

        String pageTitle = getPageTitle(pos);

        RectF bounds = new RectF(tabRect);
        bounds.right = mPaint.measureText(pageTitle, 0, pageTitle.length());
        bounds.bottom = mPaint.descent() - mPaint.ascent();

        bounds.left += (tabRect.width() - bounds.right) / 2.0f;
        bounds.top += (tabRect.height() - bounds.bottom) / 2.0f;

        canvas.drawText(pageTitle, bounds.left, bounds.top - mPaint.ascent(), mPaint);
    }
}

From source file:com.imczy.customactivitytransition.transition.ShareElemReturnChangePosition.java

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (null == startValues || null == endValues) {
        return null;
    }/*from ww  w .j av  a  2s  . c o m*/

    if (startValues.view.getId() > 0) {
        Rect startRect = (Rect) startValues.values.get(PROPNAME_POSITION);
        Rect endRect = (Rect) endValues.values.get(PROPNAME_POSITION);

        final View view = endValues.view;

        Path changePosPath = getPathMotion().getPath(startRect.centerX(), startRect.centerY(),
                endRect.centerX(), endRect.centerY() - endRect.height() / 2);

        ObjectAnimator objectAnimator = ObjectAnimator.ofObject(view, new PropPosition(PointF.class, "position",
                new PointF(startRect.centerX(), startRect.centerY())), null, changePosPath);
        objectAnimator.setInterpolator(new FastOutSlowInInterpolator());

        return objectAnimator;
    }
    return null;

}

From source file:vc908.stickerfactory.ui.advancedrecyclerview.swipeable.RemovingItemDecorator.java

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final long elapsedTime = getElapsedTime(mStartTime);

    final Rect bounds = mSwipingItemBounds;
    final float heightScale = determineBackgroundHeightScaleSwipeCompletedSuccessfully(elapsedTime);

    final int origHeight = bounds.height();
    final int actualHeight = (int) (heightScale * origHeight + 0.5f);

    fillSwipingItemBackground(c, mSwipeBackgroundDrawable, actualHeight);

    if (mSwipingItemId == mSwipingItem.getItemId()) {
        mTranslationY = (int) (ViewCompat.getTranslationY(mSwipingItem.itemView) + 0.5f);
    }//from w w  w.ja  v a 2 s  .c  om

    if (requiresContinuousAnimationAfterSwipeCompletedSuccessfully(elapsedTime)) {
        postInvalidateOnAnimation();
    }
}

From source file:vc908.stickerfactory.ui.advancedrecyclerview.swipeable.RemovingItemDecorator.java

private void fillSwipingItemBackground(Canvas c, Drawable drawable, int height) {
    final Rect bounds = mSwipingItemBounds;
    final int translationX = mInitialTranslationX;
    final int translationY = mTranslationY;

    if (height < 0) {
        height = bounds.height();
    }//  w  ww . j a  v  a 2 s .  c  o  m

    if ((height == 0) || (drawable == null)) {
        return;
    }

    final int savedCount = c.save();

    c.clipRect(bounds.left + translationX, bounds.top + translationY, bounds.right + translationX,
            bounds.top + translationY + height);

    // c.drawColor(0xffff0000); // <-- debug

    c.translate(bounds.left + translationX, bounds.top + translationY - (bounds.height() - height) / 2);
    drawable.setBounds(0, 0, bounds.width(), bounds.height());

    drawable.draw(c);

    c.restoreToCount(savedCount);
}