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:com.lovejjfg.zhifou.ui.widget.ParallaxScrimageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (imageOffset != 0) {
        canvas.save();//from w w w.  j  av a  2 s .c  o m
        canvas.translate(0f, imageOffset);
        Log.i("imageOffset", "onDraw: " + 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.richtodd.android.quiltdesign.block.PaperPiecedBlock.java

void draw(Canvas canvas, RenderOptions renderOptions) {
    Paint paint = renderOptions.getRenderStyle() == RenderStyles.Color ? m_backgroundPaint
            : m_backgroundPaintWhite;/*w  ww  .ja v a 2s . c  o m*/
    canvas.drawRect(renderOptions.getLeft(), renderOptions.getTop(), renderOptions.getRight(),
            renderOptions.getBottom(), paint);

    for (PaperPiecedBlockPiece piece : getPieces()) {
        piece.draw(canvas, renderOptions);
    }
}

From source file:com.silentcircle.contacts.ContactPhotoManager.java

/**
 * If necessary, decodes bytes stored in the holder to Bitmap.  As long as the
 * bitmap is held either by {@link #mBitmapCache} or by a soft reference in
 * the holder, it will not be necessary to decode the bitmap.
 *//*from www  . j  a  v  a2s.  c  om*/
private static void inflateBitmap(BitmapHolder holder, int requestedExtent) {
    final int sampleSize = BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent, requestedExtent);
    byte[] bytes = holder.bytes;
    if (bytes == null || bytes.length == 0) {
        return;
    }

    if (sampleSize == holder.decodedSampleSize) {
        // Check the soft reference.  If will be retained if the bitmap is also
        // in the LRU cache, so we don't need to check the LRU cache explicitly.
        if (holder.bitmapRef != null) {
            holder.bitmap = holder.bitmapRef.get();
            if (holder.bitmap != null) {
                return;
            }
        }
    }

    try {
        Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(bytes, sampleSize);

        // make bitmap mutable and draw size onto it
        if (DEBUG_SIZES) {
            Bitmap original = bitmap;
            bitmap = bitmap.copy(bitmap.getConfig(), true);
            original.recycle();
            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.setTextSize(16);
            paint.setColor(Color.BLUE);
            paint.setStyle(Style.FILL);
            canvas.drawRect(0.0f, 0.0f, 50.0f, 20.0f, paint);
            paint.setColor(Color.WHITE);
            paint.setAntiAlias(true);
            canvas.drawText(bitmap.getWidth() + "/" + sampleSize, 0, 15, paint);
        }

        holder.decodedSampleSize = sampleSize;
        holder.bitmap = bitmap;
        holder.bitmapRef = new SoftReference<Bitmap>(bitmap);
        if (DEBUG) {
            int bCount = (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1)
                    ? bitmap.getRowBytes() * bitmap.getHeight()
                    : bitmap.getByteCount();
            Log.d(TAG, "inflateBitmap " + btk(bytes.length) + " -> " + bitmap.getWidth() + "x"
                    + bitmap.getHeight() + ", " + btk(bCount));
        }
    } catch (OutOfMemoryError e) {
        // Do nothing - the photo will appear to be missing
    }
}

From source file:com.astuetz.viewpager.extensions.IndicatorLineView.java

protected synchronized void onDraw(Canvas canvas) {

    super.onDraw(canvas);

    final Paint linePaint = mLinePaint;

    final int color = Color.argb(mAlpha, Color.red(mLineColor), Color.green(mLineColor),
            Color.blue(mLineColor));

    linePaint.setColor(color);//from w  w  w . jav a  2 s  .  c  om

    // draw the line
    canvas.drawRect(mLineLeft, 0, mLineLeft + mLineWidth, getMeasuredHeight(), linePaint);

}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewWithMiniKeyboard.java

@Override
protected void onBufferDraw(Canvas canvas, Paint paint) {
    super.onBufferDraw(canvas, paint);

    // Overlay a dark rectangle to dim the keyboard
    if (mMiniKeyboardPopup.isShowing()) {
        paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24);
        canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
    }// w  w w .j a  v  a2s . c  o  m
}

From source file:com.b44t.ui.Components.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from ww w  .j a va 2  s  .  c  o m*/
    }

    final int height = getHeight();

    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    // draw indicator line
    rectPaint.setColor(indicatorColor);
    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
}

From source file:com.orange.ocara.ui.view.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from  w w w .  j av  a  2  s .  c  o  m
    }

    final int height = getHeight();

    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, getWidth(), height, rectPaint);

    // draw indicator line
    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    float tabsLeft = tabsContainer.getLeft();
    canvas.drawRect(lineLeft + tabsLeft, height - indicatorHeight, lineRight + tabsLeft, height, rectPaint);
    // draw divider
    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:angeloid.dreamnarae.SwipeyTabs.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);

    // draw the bottom bar
    final int bottomBarTop = getHeight() - getPaddingBottom() - mBottomBarHeight;
    mCachedTabPaint.setAlpha(0xff);/*from www .java 2s .  co  m*/
    canvas.drawRect(0, bottomBarTop, getWidth(), bottomBarTop + mBottomBarHeight, mCachedTabPaint);
}

From source file:com.crs4.roodin.moduletester.CustomView.java

/**
 * @param canvasContent//from  w w  w  . ja  v a2s.c o m
 * @param paintContent
 */
private void paintBoxList(Canvas canvasContent, Paint paintContent) {
    for (Box b : boxList) {
        paintContent.setColor(Color.GREEN);
        paintContent.setStyle(Style.FILL);
        paintContent.setAlpha(50);

        for (int i = b.getNorthWest().getX(); i < b.getSouthEast().getX(); i++) {
            for (int j = b.getNorthWest().getY(); j < b.getSouthEast().getY(); j++) {
                canvasContent.drawRect(cellDimension * i, cellDimension * j, cellDimension * i + cellDimension,
                        cellDimension * j + cellDimension, paintContent);
            }
        }
    }

}

From source file:com.chess.genesis.view.SwipeTabs.java

@Override
public void draw(final Canvas canvas) {
    super.draw(canvas);

    // draw the bottom bar
    final int bottomBarTop = getHeight() - getPaddingBottom() - mBottomBarHeight;
    mCachedTabPaint.setAlpha(0xff);/*w  ww .  j a  v a  2 s . c  o  m*/
    canvas.drawRect(0, bottomBarTop, getWidth(), bottomBarTop + mBottomBarHeight, mCachedTabPaint);
}