Example usage for android.graphics Canvas getWidth

List of usage examples for android.graphics Canvas getWidth

Introduction

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

Prototype

public int getWidth() 

Source Link

Document

Returns the width of the current drawing layer

Usage

From source file:com.freshdigitable.udonroad.MediaImageView.java

public MediaImageView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setContentDescription(getResources().getString(R.string.tweet_media_descs));
    setVisibility(GONE);//from w  ww .  ja  va  2s.c  o m

    if (playIcon == null) {
        final Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.ld_play_icon);
        playIcon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(playIcon);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    }
}

From source file:app.philm.in.view.BackdropImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mOffset != 0) {
        canvas.save();//from   ww  w.  j a va 2  s.c o m
        canvas.translate(0f, mOffset);
        canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + mOffset);
        super.onDraw(canvas);
        canvas.restore();
    } else {
        super.onDraw(canvas);
    }
}

From source file:com.creationgroundmedia.nytimessearch.adapters.ArticlesAdapter.java

private Bitmap bitmapFromResource(int resId) {
    Drawable sendIcon = ContextCompat.getDrawable(mContext, resId);
    Bitmap bitmap = Bitmap.createBitmap(sendIcon.getIntrinsicWidth(), sendIcon.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);/* ww  w.j av  a2  s.  com*/
    Canvas canvas = new Canvas(bitmap);
    sendIcon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    sendIcon.draw(canvas);
    return bitmap;
}

From source file:android.support.car.ui.CircleBitmapDrawable.java

/**
 * Convert the drawable to a bitmap./*ww w  .  j  a  va2  s .co  m*/
 * @param size The target size of the bitmap in pixels.
 * @return A bitmap representation of the drawable.
 */
public Bitmap toBitmap(int size) {
    Bitmap largeIcon = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(largeIcon);
    Rect bounds = getBounds();
    setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    draw(canvas);
    setBounds(bounds);
    return largeIcon;
}

From source file:org.mariotaku.twidere.view.TintedStatusFrameLayout.java

@Override
protected void dispatchDraw(@NonNull Canvas canvas) {
    super.dispatchDraw(canvas);
    canvas.drawRect(0, 0, canvas.getWidth(), mStatusBarHeight, mColorPaint);
}

From source file:org.telegram.ui.Cells.BotHelpCell.java

@Override
protected void onDraw(Canvas canvas) {
    int x = (canvas.getWidth() - width) / 2;
    int y = AndroidUtilities.dp(4);
    Theme.backgroundMediaDrawableIn.setBounds(x, y, width + x, height + y);
    Theme.backgroundMediaDrawableIn.draw(canvas);
    canvas.save();//from  w ww  .j a  va  2s  .c  o  m
    canvas.translate(textX = AndroidUtilities.dp(2 + 9) + x, textY = AndroidUtilities.dp(2 + 9) + y);
    if (pressedLink != null) {
        canvas.drawPath(urlPath, urlPaint);
    }
    if (textLayout != null) {
        textLayout.draw(canvas);
    }
    canvas.restore();
}

From source file:com.keylesspalace.tusky.view.ProgressImageView.java

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

    float angle = (progress / 100f) * 360 - 90;
    float halfWidth = canvas.getWidth() / 2;
    float halfHeight = canvas.getHeight() / 2;
    progressRect.set(halfWidth * 0.75f, halfHeight * 0.75f, halfWidth * 1.25f, halfHeight * 1.25f);
    biggerRect.set(progressRect);//  w  w  w  .j  a v a2 s. com
    int margin = 8;
    biggerRect.set(progressRect.left - margin, progressRect.top - margin, progressRect.right + margin,
            progressRect.bottom + margin);
    canvas.saveLayer(biggerRect, null, Canvas.ALL_SAVE_FLAG);
    if (progress != -1) {
        canvas.drawOval(progressRect, circlePaint);
        canvas.drawArc(biggerRect, angle, 360 - angle - 90, true, clearPaint);
    }
    canvas.restore();

    int circleRadius = Utils.dpToPx(getContext(), 14);
    int circleMargin = Utils.dpToPx(getContext(), 14);

    int circleY = canvas.getHeight() - circleMargin - circleRadius / 2;
    int circleX = canvas.getWidth() - circleMargin - circleRadius / 2;

    canvas.drawCircle(circleX, circleY, circleRadius, markBgPaint);

    captionDrawable.setBounds(canvas.getWidth() - circleMargin - circleRadius,
            canvas.getHeight() - circleMargin - circleRadius, canvas.getWidth() - circleMargin,
            canvas.getHeight() - circleMargin);
    DrawableCompat.setTint(captionDrawable, Color.WHITE);
    captionDrawable.draw(canvas);
}

From source file:org.chromium.chrome.browser.widget.MaterialProgressBar.java

private void drawDeterminateBar(Canvas canvas) {
    int width = canvas.getWidth();
    drawRect(canvas, mBackgroundPaint, 0, width);

    if (mProgress > 0) {
        float percentage = mProgress / 100.0f;
        drawRect(canvas, mProgressPaint, 0, width * percentage);
    }/*from   w w w .  ja va  2s .  c  om*/

    if (mSecondaryProgress > 0) {
        float percentage = mSecondaryProgress / 100.0f;
        drawRect(canvas, mSecondaryProgressPaint, 0, width * percentage);
    }
}

From source file:org.chromium.chrome.browser.widget.MaterialProgressBar.java

private void drawIndeterminateBar(Canvas canvas) {
    int width = canvas.getWidth();
    drawRect(canvas, mBackgroundPaint, 0, width);

    // The first pulse fires off at the beginning of the animation.
    float value = (Float) mIndeterminateAnimator.getAnimatedValue();
    float left = width * (float) (Math.pow(value, 1.5f) - 0.5f);
    float right = width * value;
    drawRect(canvas, mProgressPaint, left, right);

    // The second pulse fires off at some point after the first pulse has been fired.
    final float secondPulseStart = 1.1f;
    final float secondPulseLength = 1.0f;
    if (value >= secondPulseStart) {
        float percentage = (value - secondPulseStart) / secondPulseLength;
        left = width * (float) (Math.pow(percentage, 2.5f) - 0.1f);
        right = width * percentage;/*from  w  w  w  .jav  a2s  .  c  o  m*/
        drawRect(canvas, mProgressPaint, left, right);
    }
}

From source file:org.stockchart.core.Crosshair.java

public void draw(Plot plot, Canvas c, Rect clipRect) {
    float xxx = fX * c.getWidth();
    float yyy = fY * c.getHeight();

    PointF p = plot.getRelativePosition(xxx, yyy);

    this.fAppearance.applyOutline(fPaint);

    if (this.fDrawVertical)
        PaintUtils.drawLine(c, p.x, clipRect.top, p.x, clipRect.bottom, fPaint);

    if (this.fDrawHorizontal)
        PaintUtils.drawLine(c, clipRect.left, p.y, clipRect.right, p.y, fPaint);

    Area parent = (Area) plot.getParent();
    Axis hAxis = parent.getAxis(fHorizontalAxis);
    Axis vAxis = parent.getAxis(fVerticalAxis);

    double realXValue = hAxis.getValueByCoordinate(p.x, false);
    double realYValue = vAxis.getValueByCoordinate(p.y, false);

    String text = null;/*  ww w  .ja v a2 s .com*/

    if (fLabelFormatProvider != null)
        text = fLabelFormatProvider.getLabel(this, plot, realXValue, realYValue);
    else
        text = String.format("X: %.2f, Y: %.2f", realXValue, realYValue);

    if (null != text) {
        fAppearance.applyText(fPaint);
        SizeF f = fAppearance.measureTextSize(text, fPaint, false);

        float ow = fAppearance.getOutlineWidth() + 1f;

        float textX = clipRect.right - p.x > p.x ? p.x + ow : p.x - f.width - ow;
        float textY = clipRect.bottom - p.y > p.y ? p.y + f.height + ow : p.y - f.height;

        if (!fDrawVertical)
            textX = 1f;

        if (!fDrawHorizontal)
            textY = f.height + 1f;

        c.drawText(text, textX, textY, fPaint);
    }
}