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.odoo.followup.orm.widgets.BezelImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;/*from  w  ww  .  j a  v  a 2 s .c  o m*/
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just
            // erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            // noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        if (mMaskDrawable != null) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // Draw from cache
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

From source file:com.heqi.kharazim.ui.fragment.tab.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from www  .  j av a2 s .  c  o m*/
    }
    final int height = getHeight();
    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.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);
    }
    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, 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:com.dream.yzbb.wolfkiller.widget.BezelImageView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;/*from  w  w w.ja va2s.c  o  m*/
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache.
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        if (mMaskDrawable != null) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed())
                    ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // Draw from cache.
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

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

@SuppressLint("DrawAllocation")
@Override//  ww  w  .  j  a v  a 2 s. com
public void onDraw(Canvas canvas) {
    if (cameraManager == null) {
        return; // not ready yet, early draw before done configuring
    }
    Rect frame = cameraManager.getFramingRect();
    Rect previewFrame = cameraManager.getFramingRectInPreview();
    if (frame == null || previewFrame == null) {
        return;
    }
    int width = canvas.getWidth();
    int height = canvas.getHeight();

    // Draw the exterior (i.e. outside the framing rect) darkened
    paint.setColor(resultBitmap != null ? resultColor : maskColor);
    canvas.drawRect(0, 0, width, frame.top, paint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom, paint);
    canvas.drawRect(frame.right, frame.top, width, frame.bottom, paint);
    canvas.drawRect(0, frame.bottom, width, height, paint);

    ///
    // 
    paint.setColor(getResources().getColor(R.color.encode_view));
    int w = 16;
    int h = 2;
    int margin = 2;
    // 
    canvas.drawRect(frame.left - margin - h, frame.top - margin - h, frame.left - margin + w - h,
            frame.top - margin + h - h, paint);
    canvas.drawRect(frame.left - margin - h, frame.top - margin - h, frame.left - margin + h - h,
            frame.top - margin + w - h, paint);
    // ?
    canvas.drawRect(frame.right + margin - w + h, frame.top - margin - h, frame.right + margin + h,
            frame.top - margin + h - h, paint);
    canvas.drawRect(frame.right + margin - h + h, frame.top - margin - h, frame.right + margin + h,
            frame.top - margin + w - h, paint);
    // 
    canvas.drawRect(frame.left - margin - h, frame.bottom + margin - h + h, frame.left - margin + w - h,
            frame.bottom + margin + h, paint);
    canvas.drawRect(frame.left - margin - h, frame.bottom + margin - w + h, frame.left - margin + h - h,
            frame.bottom + margin + h, paint);
    // ?
    canvas.drawRect(frame.right + margin - w + h, frame.bottom + margin - h + h, frame.right + margin + h,
            frame.bottom + margin + h, paint);
    canvas.drawRect(frame.right + margin - h + h, frame.bottom + margin - w + h, frame.right + margin + h,
            frame.bottom + margin + h, paint);
    ///?
    drawLineRound(canvas, frame, paint);
    if (statusText != null) {
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) statusText.getLayoutParams();
        lp.topMargin = frame.top - statusText.getMeasuredHeight() - 28;
        statusText.setLayoutParams(lp);
        statusText.setVisibility(View.VISIBLE);
    }
    if (resultBitmap != null) {
        // Draw the opaque result bitmap over the scanning rectangle
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            paint.setAlpha(CURRENT_POINT_OPACITY);
        }
        canvas.drawBitmap(resultBitmap, null, frame, paint);
    } else {
        // ??
        if ((i += 5) < frame.bottom - frame.top) {
            /* ?? */
            mRect.set(frame.left, frame.top + i - 1, frame.right, frame.top + i + 1);
            lineDrawable.setBounds(mRect);
            lineDrawable.draw(canvas);
            // 
            invalidate();
        } else {
            i = 0;
        }

        float scaleX = frame.width() / (float) previewFrame.width();
        float scaleY = frame.height() / (float) previewFrame.height();

        List<ResultPoint> currentPossible = possibleResultPoints;
        List<ResultPoint> currentLast = lastPossibleResultPoints;
        int frameLeft = frame.left;
        int frameTop = frame.top;
        if (currentPossible.isEmpty()) {
            lastPossibleResultPoints = null;
        } else {
            possibleResultPoints = new ArrayList<>(5);
            lastPossibleResultPoints = currentPossible;
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                paint.setAlpha(CURRENT_POINT_OPACITY);
            }
            paint.setColor(resultPointColor);
            synchronized (currentPossible) {
                for (ResultPoint point : currentPossible) {
                    canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
                            frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint);
                }
            }
        }
        if (currentLast != null) {
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                paint.setAlpha(CURRENT_POINT_OPACITY / 2);
            }
            paint.setColor(resultPointColor);
            synchronized (currentLast) {
                float radius = POINT_SIZE / 2.0f;
                for (ResultPoint point : currentLast) {
                    canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
                            frameTop + (int) (point.getY() * scaleY), radius, paint);
                }
            }
        }

        // Request another update at the animation interval, but only repaint the laser line,
        // not the entire viewfinder mask.
        postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE,
                frame.right + POINT_SIZE, frame.bottom + POINT_SIZE);
    }
}

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

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, state);
    final float left = parent.getPaddingLeft();
    final float right = parent.getWidth() - parent.getPaddingRight();
    final int childCount = parent.getChildCount();

    final RecyclerView.LayoutManager manager = parent.getLayoutManager();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        if (params.getViewLayoutPosition() == 0) {
            continue;
        }//from  w w w .  j ava  2 s .  co m
        final float top = manager.getDecoratedTop(child) - params.topMargin
                + Math.round(ViewCompat.getTranslationY(child));
        final float bottom = top + dividerHeight;
        c.drawRect(left, top, right, bottom, paint);
    }
}

From source file:com.collcloud.frame.viewpager.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//  www . j  a v a 2 s  .  com
    }

    final int height = getHeight();

    // draw underline

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.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);
    }

    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, 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:com.yktx.check.widget.OldPagerSlidingTabStrip.java

@SuppressLint("DrawAllocation")
@Override// w  w w.  ja  v  a2 s.  c om
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;
    }

    final int height = getHeight();

    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.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);
    }

    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
    // Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
    // R.drawable.xinjian_tuijian_huakuai);
    // canvas.drawBitmap(bitmap, lineLeft, height - indicatorHeight,
    // 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:com.github.shareme.gwsmaterialuikit.library.material.widget.TabIndicatorView.java

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

    int x = mIndicatorOffset;
    int y = mIndicatorAtTop ? 0 : getHeight() - mIndicatorHeight;
    canvas.drawRect(x, y, x + mIndicatorWidth, y + mIndicatorHeight, mPaint);

    //TODO: handle it

    //        if(isInEditMode())
    //            canvas.drawRect(getPaddingLeft(), y, getPaddingLeft() + mTabContainer.getChildAt(0).getWidth(), y + mIndicatorHeight, mPaint);
}

From source file:com.benefit.buy.library.viewpagerindicator.PagerSlidingTabStrip.java

@SuppressLint("NewApi")
@Override/*from  ww  w. j av a  2  s .  c o  m*/
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode() || (tabCount == 0)) {
        return;
    }
    final int height = getHeight();
    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.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));
    }
    if (currentTab.findViewById(R.id.img_click) != null) {
        int counts = tabsContainer.getChildCount();
        View vNow = currentTab.findViewById(R.id.tab_name);
        ImageView imgNowOn = (ImageView) currentTab.findViewById(R.id.img_click);
        View tabViewNext;
        View vNext;
        ImageView imgNextOn;
        if ((currentPosition + 1) == counts) {
            tabViewNext = tabsContainer.getChildAt(0);
            vNext = tabViewNext.findViewById(R.id.tab_name);
            imgNextOn = (ImageView) tabViewNext.findViewById(R.id.img_click);
        } else {
            tabViewNext = tabsContainer.getChildAt(currentPosition + 1);
            vNext = tabViewNext.findViewById(R.id.tab_name);
            imgNextOn = (ImageView) tabViewNext.findViewById(R.id.img_click);
        }
        int colorTo = ToolColor.getChangeColor(80, 84, 98, 255, 0, 0, currentPositionOffset);
        int colorRe = ToolColor.getChangeColor(255, 0, 0, 80, 84, 98, currentPositionOffset);
        TextView tab = (TextView) vNext;
        TextView tab2 = (TextView) vNow;
        tab.setTextColor(colorTo);
        tab2.setTextColor(colorRe);
        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
            imgNextOn.setAlpha(currentPositionOffset);
            imgNowOn.setAlpha(1 - currentPositionOffset);
        }
    } else {
    }
    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, 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:com.example.firstocr.ViewfinderView.java

@SuppressWarnings("unused")
@Override//from   www  . j a va  2s.com
public void onDraw(Canvas canvas) {
    Rect frame = cameraManager.getFramingRect();
    if (frame == null) {
        return;
    }
    int width = canvas.getWidth();
    int height = canvas.getHeight();

    // Draw the exterior (i.e. outside the framing rect) darkened
    paint.setColor(maskColor);
    canvas.drawRect(0, 0, width, frame.top, paint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
    canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
    canvas.drawRect(0, frame.bottom + 1, width, height, paint);

    // If we have an OCR result, overlay its information on the viewfinder.
    if (resultText != null) {

        // Only draw text/bounding boxes on viewfinder if it hasn't been resized since the OCR was requested.
        Point bitmapSize = resultText.getBitmapDimensions();
        previewFrame = cameraManager.getFramingRectInPreview();
        if (bitmapSize.x == previewFrame.width() && bitmapSize.y == previewFrame.height()) {

            float scaleX = frame.width() / (float) previewFrame.width();
            float scaleY = frame.height() / (float) previewFrame.height();

            if (DRAW_REGION_BOXES) {
                regionBoundingBoxes = resultText.getRegionBoundingBoxes();
                for (int i = 0; i < regionBoundingBoxes.size(); i++) {
                    paint.setAlpha(0xA0);
                    paint.setColor(Color.MAGENTA);
                    paint.setStyle(Style.STROKE);
                    paint.setStrokeWidth(1);
                    rect = regionBoundingBoxes.get(i);
                    canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY,
                            frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint);
                }
            }

            if (DRAW_TEXTLINE_BOXES) {
                // Draw each textline
                textlineBoundingBoxes = resultText.getTextlineBoundingBoxes();
                paint.setAlpha(0xA0);
                paint.setColor(Color.RED);
                paint.setStyle(Style.STROKE);
                paint.setStrokeWidth(1);
                for (int i = 0; i < textlineBoundingBoxes.size(); i++) {
                    rect = textlineBoundingBoxes.get(i);
                    canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY,
                            frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint);
                }
            }

            if (DRAW_STRIP_BOXES) {
                stripBoundingBoxes = resultText.getStripBoundingBoxes();
                paint.setAlpha(0xFF);
                paint.setColor(Color.YELLOW);
                paint.setStyle(Style.STROKE);
                paint.setStrokeWidth(1);
                for (int i = 0; i < stripBoundingBoxes.size(); i++) {
                    rect = stripBoundingBoxes.get(i);
                    canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY,
                            frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint);
                }
            }

            if (DRAW_WORD_BOXES || DRAW_WORD_TEXT) {
                // Split the text into words
                wordBoundingBoxes = resultText.getWordBoundingBoxes();
                //      for (String w : words) {
                //        Log.e("ViewfinderView", "word: " + w);
                //      }
                //Log.d("ViewfinderView", "There are " + words.length + " words in the string array.");
                //Log.d("ViewfinderView", "There are " + wordBoundingBoxes.size() + " words with bounding boxes.");
            }

            if (DRAW_WORD_BOXES) {
                paint.setAlpha(0xFF);
                paint.setColor(0xFF00CCFF);
                paint.setStyle(Style.STROKE);
                paint.setStrokeWidth(1);
                for (int i = 0; i < wordBoundingBoxes.size(); i++) {
                    // Draw a bounding box around the word
                    rect = wordBoundingBoxes.get(i);
                    canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY,
                            frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint);
                }
            }

            if (DRAW_WORD_TEXT) {
                words = resultText.getText().replace("\n", " ").split(" ");
                int[] wordConfidences = resultText.getWordConfidences();
                for (int i = 0; i < wordBoundingBoxes.size(); i++) {
                    boolean isWordBlank = true;
                    try {
                        if (!words[i].equals("")) {
                            isWordBlank = false;
                        }
                    } catch (ArrayIndexOutOfBoundsException e) {
                        e.printStackTrace();
                    }

                    // Only draw if word has characters
                    if (!isWordBlank) {
                        // Draw a white background around each word
                        rect = wordBoundingBoxes.get(i);
                        paint.setColor(Color.WHITE);
                        paint.setStyle(Style.FILL);
                        if (DRAW_TRANSPARENT_WORD_BACKGROUNDS) {
                            // Higher confidence = more opaque, less transparent background
                            paint.setAlpha(wordConfidences[i] * 255 / 100);
                        } else {
                            paint.setAlpha(255);
                        }
                        canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY,
                                frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint);

                        // Draw the word in black text
                        paint.setColor(Color.BLACK);
                        paint.setAlpha(0xFF);
                        paint.setAntiAlias(true);
                        paint.setTextAlign(Align.LEFT);

                        // Adjust text size to fill rect
                        paint.setTextSize(100);
                        paint.setTextScaleX(1.0f);
                        // ask the paint for the bounding rect if it were to draw this text
                        Rect bounds = new Rect();
                        paint.getTextBounds(words[i], 0, words[i].length(), bounds);
                        // get the height that would have been produced
                        int h = bounds.bottom - bounds.top;
                        // figure out what textSize setting would create that height of text
                        float size = (((float) (rect.height()) / h) * 100f);
                        // and set it into the paint
                        paint.setTextSize(size);
                        // Now set the scale.
                        // do calculation with scale of 1.0 (no scale)
                        paint.setTextScaleX(1.0f);
                        // ask the paint for the bounding rect if it were to draw this text.
                        paint.getTextBounds(words[i], 0, words[i].length(), bounds);
                        // determine the width
                        int w = bounds.right - bounds.left;
                        // calculate the baseline to use so that the entire text is visible including the descenders
                        int text_h = bounds.bottom - bounds.top;
                        int baseline = bounds.bottom + ((rect.height() - text_h) / 2);
                        // determine how much to scale the width to fit the view
                        float xscale = ((float) (rect.width())) / w;
                        // set the scale for the text paint
                        paint.setTextScaleX(xscale);
                        canvas.drawText(words[i], frame.left + rect.left * scaleX,
                                frame.top + rect.bottom * scaleY - baseline, paint);
                    }

                }
            }

            //        if (DRAW_CHARACTER_BOXES || DRAW_CHARACTER_TEXT) {
            //          characterBoundingBoxes = resultText.getCharacterBoundingBoxes();
            //        }
            //
            //        if (DRAW_CHARACTER_BOXES) {
            //          // Draw bounding boxes around each character
            //          paint.setAlpha(0xA0);
            //          paint.setColor(0xFF00FF00);
            //          paint.setStyle(Style.STROKE);
            //          paint.setStrokeWidth(1);
            //          for (int c = 0; c < characterBoundingBoxes.size(); c++) {
            //            Rect characterRect = characterBoundingBoxes.get(c);
            //            canvas.drawRect(frame.left + characterRect.left * scaleX,
            //                frame.top + characterRect.top * scaleY, 
            //                frame.left + characterRect.right * scaleX, 
            //                frame.top + characterRect.bottom * scaleY, paint);
            //          }
            //        }
            //
            //        if (DRAW_CHARACTER_TEXT) {
            //          // Draw letters individually
            //          for (int i = 0; i < characterBoundingBoxes.size(); i++) {
            //            Rect r = characterBoundingBoxes.get(i);
            //
            //            // Draw a white background for every letter
            //            int meanConfidence = resultText.getMeanConfidence();
            //            paint.setColor(Color.WHITE);
            //            paint.setAlpha(meanConfidence * (255 / 100));
            //            paint.setStyle(Style.FILL);
            //            canvas.drawRect(frame.left + r.left * scaleX,
            //                frame.top + r.top * scaleY, 
            //                frame.left + r.right * scaleX, 
            //                frame.top + r.bottom * scaleY, paint);
            //
            //            // Draw each letter, in black
            //            paint.setColor(Color.BLACK);
            //            paint.setAlpha(0xFF);
            //            paint.setAntiAlias(true);
            //            paint.setTextAlign(Align.LEFT);
            //            String letter = "";
            //            try {
            //              char c = resultText.getText().replace("\n","").replace(" ", "").charAt(i);
            //              letter = Character.toString(c);
            //
            //              if (!letter.equals("-") && !letter.equals("_")) {
            //
            //                // Adjust text size to fill rect
            //                paint.setTextSize(100);
            //                paint.setTextScaleX(1.0f);
            //
            //                // ask the paint for the bounding rect if it were to draw this text
            //                Rect bounds = new Rect();
            //                paint.getTextBounds(letter, 0, letter.length(), bounds);
            //
            //                // get the height that would have been produced
            //                int h = bounds.bottom - bounds.top;
            //
            //                // figure out what textSize setting would create that height of text
            //                float size  = (((float)(r.height())/h)*100f);
            //
            //                // and set it into the paint
            //                paint.setTextSize(size);
            //
            //                // Draw the text as is. We don't really need to set the text scale, because the dimensions
            //                // of the Rect should already be suited for drawing our letter. 
            //                canvas.drawText(letter, frame.left + r.left * scaleX, frame.top + r.bottom * scaleY, paint);
            //              }
            //            } catch (StringIndexOutOfBoundsException e) {
            //              e.printStackTrace();
            //            } catch (Exception e) {
            //              e.printStackTrace();
            //            }
            //          }
            //        }
        }

    }
    // Draw a two pixel solid border inside the framing rect
    paint.setAlpha(0);
    paint.setStyle(Style.FILL);
    paint.setColor(frameColor);
    canvas.drawRect(frame.left, frame.top, frame.right + 1, frame.top + 2, paint);
    canvas.drawRect(frame.left, frame.top + 2, frame.left + 2, frame.bottom - 1, paint);
    canvas.drawRect(frame.right - 1, frame.top, frame.right + 1, frame.bottom - 1, paint);
    canvas.drawRect(frame.left, frame.bottom - 1, frame.right + 1, frame.bottom + 1, paint);

    // Draw the framing rect corner UI elements
    paint.setColor(cornerColor);
    canvas.drawRect(frame.left - 15, frame.top - 15, frame.left + 15, frame.top, paint);
    canvas.drawRect(frame.left - 15, frame.top, frame.left, frame.top + 15, paint);
    canvas.drawRect(frame.right - 15, frame.top - 15, frame.right + 15, frame.top, paint);
    canvas.drawRect(frame.right, frame.top - 15, frame.right + 15, frame.top + 15, paint);
    canvas.drawRect(frame.left - 15, frame.bottom, frame.left + 15, frame.bottom + 15, paint);
    canvas.drawRect(frame.left - 15, frame.bottom - 15, frame.left, frame.bottom, paint);
    canvas.drawRect(frame.right - 15, frame.bottom, frame.right + 15, frame.bottom + 15, paint);
    canvas.drawRect(frame.right, frame.bottom - 15, frame.right + 15, frame.bottom + 15, paint);

    // Request another update at the animation interval, but don't repaint the entire viewfinder mask.
    //postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom);
}