Example usage for android.graphics Canvas drawRect

List of usage examples for android.graphics Canvas drawRect

Introduction

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

Prototype

public void drawRect(float left, float top, float right, float bottom, @NonNull Paint paint) 

Source Link

Document

Draw the specified Rect using the specified paint.

Usage

From source file:foam.jellyfish.StarwispCanvas.java

@Override
public void onDraw(Canvas canvas) {
    float sx = getWidth() / 320.0f;
    float sy = getHeight() / 200.0f;

    Paint myPaint = new Paint();
    myPaint.setStrokeWidth(0);//w  ww  .  j  a  va 2s  . c o m
    myPaint.setColor(Color.rgb(127, 127, 127));
    canvas.drawRect(0, 0, getWidth(), getHeight(), myPaint);

    try {
        for (int i = 0; i < m_Drawlist.length(); i++) {
            JSONArray prim = m_Drawlist.getJSONArray(i);
            if (prim.getString(0).equals("line")) {
                DrawLine(canvas, prim, sx, sy);
            }
            if (prim.getString(0).equals("text")) {
                DrawText(canvas, prim, sx, sy);
            }
        }
    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing data " + e.toString());
    }
}

From source file:com.google.zxing.client.android.ViewfinderView.java

/**
 * ?//from ww  w. jav  a  2  s  .c o m
 * @param canvas
 * @param frame
 * @param paint2
 */
private void drawLineRound(Canvas canvas, Rect frame, Paint paint2) {
    paint2.setColor(Color.parseColor("#38FFFFFF"));
    //left
    canvas.drawRect(frame.left, frame.top, frame.left + 1, frame.bottom, paint2);
    //right
    canvas.drawRect(frame.right - 1, frame.top, frame.right, frame.bottom, paint2);
    //top
    canvas.drawRect(frame.left, frame.top, frame.right, frame.top + 1, paint2);
    //bottom
    canvas.drawRect(frame.left, frame.bottom - 1, frame.right, frame.bottom, paint2);
}

From source file:com.forrestguice.suntimeswidget.LightMapView.java

private void drawRect(Canvas c, Paint p) {
    int w = c.getWidth();
    int h = c.getHeight();
    c.drawRect(0, 0, w, h, p);
}

From source file:com.xycode.xylibrary.uiKit.recyclerview.FloatingBarItemDecoration.java

private void drawTitleArea(Canvas c, int left, int right, View child, RecyclerView.LayoutParams params,
        int position) {
    final int rectBottom = child.getTop() - params.topMargin;
    c.drawRect(left, rectBottom - mTitleHeight, right, rectBottom, mBackgroundPaint);
    c.drawText(headerList.get(position), child.getPaddingLeft() + mTextStartMargin,
            rectBottom - (mTitleHeight - mTextHeight) / 2 - mTextBaselineOffset, mTextPaint);
}

From source file:com.kth.baasio.baassample.BaseActivity.java

/**
 * Sets the icon color using some fancy blending mode trickery.
 *///ww  w .  j av  a2s .c  o m
protected void setActionBarColor(int color) {
    if (color == 0) {
        color = 0xffffffff;
    }

    final Resources res = getResources();
    Drawable maskDrawable = res.getDrawable(R.drawable.actionbar_icon_mask);
    if (!(maskDrawable instanceof BitmapDrawable)) {
        return;
    }

    Bitmap maskBitmap = ((BitmapDrawable) maskDrawable).getBitmap();
    final int width = maskBitmap.getWidth();
    final int height = maskBitmap.getHeight();

    Bitmap outBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(outBitmap);
    canvas.drawBitmap(maskBitmap, 0, 0, null);

    Paint maskedPaint = new Paint();
    maskedPaint.setColor(color);
    maskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));

    canvas.drawRect(0, 0, width, height, maskedPaint);

    BitmapDrawable outDrawable = new BitmapDrawable(res, outBitmap);
    getSupportActionBar().setIcon(outDrawable);
}

From source file:com.github.barteksc.pdfviewpager.view.ScrollBar.java

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

    if (isInEditMode()) {
        canvas.drawRect(0, 0, getWidth(), Util.getDP(getContext(), 40), handlePaint);
        return;//from w ww  .  j  a  va2 s .c om
    } else if (!isViewPagerReady()) {
        return;
    }

    calculateHandleHeight();

    canvas.drawRect(handlePos.x, handlePos.y, getWidth(), handlePos.y + handleHeight, handlePaint);

}

From source file:com.arbo.gaogao.widget.MyParallaxScrimageView.java

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

From source file:com.linkbubble.util.Util.java

/**
 * Returns a bitmap suitable for the all apps view.
 *//*  w ww .  ja  v a2 s  .com*/
static Bitmap createIconBitmap(Drawable icon, Context context) {
    synchronized (sCanvas) { // we share the statics :-(
        if (sIconWidth == -1) {
            initStatics(context);
        }

        int width = sIconWidth;
        int height = sIconHeight;

        if (icon instanceof PaintDrawable) {
            PaintDrawable painter = (PaintDrawable) icon;
            painter.setIntrinsicWidth(width);
            painter.setIntrinsicHeight(height);
        } else if (icon instanceof BitmapDrawable) {
            // Ensure the bitmap has a density.
            BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
                bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
            }
        }
        int sourceWidth = icon.getIntrinsicWidth();
        int sourceHeight = icon.getIntrinsicHeight();
        if (sourceWidth > 0 && sourceHeight > 0) {
            // There are intrinsic sizes.
            if (width < sourceWidth || height < sourceHeight) {
                // It's too big, scale it down.
                final float ratio = (float) sourceWidth / sourceHeight;
                if (sourceWidth > sourceHeight) {
                    height = (int) (width / ratio);
                } else if (sourceHeight > sourceWidth) {
                    width = (int) (height * ratio);
                }
            } else if (sourceWidth < width && sourceHeight < height) {
                // Don't scale up the icon
                width = sourceWidth;
                height = sourceHeight;
            }
        }

        // no intrinsic size --> use default size
        int textureWidth = sIconTextureWidth;
        int textureHeight = sIconTextureHeight;

        final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888);
        final Canvas canvas = sCanvas;
        canvas.setBitmap(bitmap);

        final int left = (textureWidth - width) / 2;
        final int top = (textureHeight - height) / 2;

        @SuppressWarnings("all") // suppress dead code warning
        final boolean debug = false;
        if (debug) {
            // draw a big box for the icon for debugging
            canvas.drawColor(sColors[sColorIndex]);
            if (++sColorIndex >= sColors.length)
                sColorIndex = 0;
            Paint debugPaint = new Paint();
            debugPaint.setColor(0xffcccc00);
            canvas.drawRect(left, top, left + width, top + height, debugPaint);
        }

        sOldBounds.set(icon.getBounds());
        icon.setBounds(left, top, left + width, top + height);
        icon.draw(canvas);
        icon.setBounds(sOldBounds);
        canvas.setBitmap(null);

        return bitmap;
    }
}

From source file:com.jasonchen.microlang.view.LinearViewPagerIndicator.java

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

    // Draw the indicator line
    int position = mCurrentPage * mTabWidth + (int) (mOffset * mTabWidth);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(mForeground);//  w  ww. j av  a  2  s  . co  m

    canvas.drawRect(position, (mHeight - mHeight / 18), position + mTabWidth, mHeight, paint);

    /*if (DEBUG) {
       Log.d(TAG, "mWidth = " + mWidth + "; mHeight = " + mHeight + "; mTabWidth = " + mTabWidth);
       Log.d(TAG, "mCurrentPage = " + mCurrentPage);
    }*/
}

From source file:com.appsummary.luoxf.myappsummary.recyclerView.fastscroll.Views.FastScroller.java

public void draw(Canvas canvas) {

    if (mThumbPosition.x < 0 || mThumbPosition.y < 0) {
        return;//from  w  ww.j a va2  s .c  o  m
    }

    //Background
    canvas.drawRect(mThumbPosition.x + mOffset.x, mThumbHeight / 2 + mOffset.y,
            mThumbPosition.x + mOffset.x + mWidth, mRecyclerView.getHeight() + mOffset.y - mThumbHeight / 2,
            mTrack);

    //Handle
    canvas.drawRect(mThumbPosition.x + mOffset.x, mThumbPosition.y + mOffset.y,
            mThumbPosition.x + mOffset.x + mWidth, mThumbPosition.y + mOffset.y + mThumbHeight, mThumb);

    //Popup
    mPopup.draw(canvas);
}