Example usage for android.graphics Rect width

List of usage examples for android.graphics Rect width

Introduction

In this page you can find the example usage for android.graphics Rect width.

Prototype

public final int width() 

Source Link

Usage

From source file:com.breakout.main.GameState.java

/**
 * Renders debug features./*w ww  .j  av a  2 s .  c om*/
 * <p>
 * This function is allowed to violate the "don't allocate objects" rule.
 */
void drawDebugStuff() {

    // Draw a red outline rectangle around the ball.  This shows the area that was
    // examined for collisions during the "coarse" pass.
    OutlineAlignedRect.prepareToDraw();
    mDebugCollisionRect.draw();
    OutlineAlignedRect.finishedDrawing();

    // Draw the entire message texture so we can see what it looks like.
    if (true) {
        int textureWidth = mTextRes.getTextureWidth();
        int textureHeight = mTextRes.getTextureHeight();
        float scale = (ARENA_WIDTH * STATUS_MESSAGE_WIDTH_PERC) / textureWidth;

        // Draw an orange rect around the texture.
        OutlineAlignedRect outline = new OutlineAlignedRect();
        outline.setPosition(ARENA_WIDTH / 2, ARENA_HEIGHT / 2);
        outline.setScale(textureWidth * scale + 2, textureHeight * scale + 2);
        outline.setColor(1.0f, 0.65f, 0.0f);
        OutlineAlignedRect.prepareToDraw();
        outline.draw();
        OutlineAlignedRect.finishedDrawing();

        // Draw the full texture.  Note you can set the background to opaque white in
        // TextResources to see what the drop shadow looks like.
        Rect boundsRect = new Rect(0, 0, textureWidth, textureHeight);
        TexturedAlignedRect msgBox = mGameStatusMessages;
        msgBox.setTextureCoords(boundsRect);
        msgBox.setScale(textureWidth * scale, textureHeight * scale);
        TexturedAlignedRect.prepareToDraw();
        msgBox.draw();
        TexturedAlignedRect.finishedDrawing();

        // Draw a rectangle around each individual text item.  We draw a different one each
        // time to get a flicker effect, so it doesn't fully obscure the text.
        if (true) {
            outline.setColor(1.0f, 1.0f, 1.0f);
            int stringNum = mDebugFramedString;
            mDebugFramedString = (mDebugFramedString + 1) % TextResources.getNumStrings();
            boundsRect = mTextRes.getTextureRect(stringNum);
            // The bounds rect is in bitmap coordinates, with (0,0) in the top left.  Translate
            // it to an offset from the center of the bitmap, and find the center of the rect.
            float boundsCenterX = boundsRect.exactCenterX() - (textureWidth / 2);
            float boundsCenterY = boundsRect.exactCenterY() - (textureHeight / 2);
            // Now scale it to arena coordinates, using the same scale factor we used to
            // draw the texture with all the messages, and translate it to the center of
            // the arena.  We need to invert Y to match GL conventions.
            boundsCenterX = ARENA_WIDTH / 2 + (boundsCenterX * scale);
            boundsCenterY = ARENA_HEIGHT / 2 - (boundsCenterY * scale);
            // Set the values and draw the rect.
            outline.setPosition(boundsCenterX, boundsCenterY);
            outline.setScale(boundsRect.width() * scale, boundsRect.height() * scale);
            OutlineAlignedRect.prepareToDraw();
            outline.draw();
            OutlineAlignedRect.finishedDrawing();
        }
    }
}

From source file:com.android.launcher3.CellLayout.java

private boolean addViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop, int[] direction,
        View dragView, ItemConfiguration currentState) {
    if (views.size() == 0)
        return true;

    boolean success = false;
    Rect boundingRect = null;
    // We construct a rect which represents the entire group of views passed in
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        if (boundingRect == null) {
            boundingRect = new Rect(c.x, c.y, c.x + c.spanX, c.y + c.spanY);
        } else {// ww  w  .  j  a v a  2 s. com
            boundingRect.union(c.x, c.y, c.x + c.spanX, c.y + c.spanY);
        }
    }

    // Mark the occupied state as false for the group of views we want to move.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        markCellsForView(c.x, c.y, c.spanX, c.spanY, mTmpOccupied, false);
    }

    boolean[][] blockOccupied = new boolean[boundingRect.width()][boundingRect.height()];
    int top = boundingRect.top;
    int left = boundingRect.left;
    // We mark more precisely which parts of the bounding rect are truly occupied, allowing
    // for interlocking.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        markCellsForView(c.x - left, c.y - top, c.spanX, c.spanY, blockOccupied, true);
    }

    markCellsForRect(rectOccupiedByPotentialDrop, mTmpOccupied, true);

    findNearestArea(boundingRect.left, boundingRect.top, boundingRect.width(), boundingRect.height(), direction,
            mTmpOccupied, blockOccupied, mTempLocation);

    // If we successfuly found a location by pushing the block of views, we commit it
    if (mTempLocation[0] >= 0 && mTempLocation[1] >= 0) {
        int deltaX = mTempLocation[0] - boundingRect.left;
        int deltaY = mTempLocation[1] - boundingRect.top;
        for (View v : views) {
            CellAndSpan c = currentState.map.get(v);
            c.x += deltaX;
            c.y += deltaY;
        }
        success = true;
    }

    // In either case, we set the occupied array as marked for the location of the views
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        markCellsForView(c.x, c.y, c.spanX, c.spanY, mTmpOccupied, true);
    }
    return success;
}

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

@SuppressLint("DrawAllocation")
@Override/*w w  w .j  ava2 s .c o m*/
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.android.launcher2.Workspace.java

public int[] estimateItemSize(int hSpan, int vSpan, ItemInfo itemInfo, boolean springLoaded) {
    int[] size = new int[2];
    if (getChildCount() > 0) {
        CellLayout cl = (CellLayout) mLauncher.getWorkspace().getChildAt(0);
        Rect r = estimateItemPosition(cl, itemInfo, 0, 0, hSpan, vSpan);
        size[0] = r.width();
        size[1] = r.height();/*from w  ww  . j a v a2  s  .  c o m*/
        if (springLoaded) {
            size[0] *= mSpringLoadedShrinkFactor;
            size[1] *= mSpringLoadedShrinkFactor;
        }
        return size;
    } else {
        size[0] = Integer.MAX_VALUE;
        size[1] = Integer.MAX_VALUE;
        return size;
    }
}

From source file:android.support.designox.widget.CoordinatorLayout.java

/**
 * Calculate the desired child rect relative to an anchor rect, respecting both
 * gravity and anchorGravity./*from  w  ww .j av  a2s. c o  m*/
 *
 * @param child child view to calculate a rect for
 * @param layoutDirection the desired layout direction for the CoordinatorLayout
 * @param anchorRect rect in CoordinatorLayout coordinates of the anchor view area
 * @param out rect to set to the output values
 */
void getDesiredAnchoredChildRect(View child, int layoutDirection, Rect anchorRect, Rect out) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final int absGravity = GravityCompat.getAbsoluteGravity(resolveAnchoredChildGravity(lp.gravity),
            layoutDirection);
    final int absAnchorGravity = GravityCompat.getAbsoluteGravity(resolveGravity(lp.anchorGravity),
            layoutDirection);

    final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int anchorHgrav = absAnchorGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int anchorVgrav = absAnchorGravity & Gravity.VERTICAL_GRAVITY_MASK;

    final int childWidth = child.getMeasuredWidth();
    final int childHeight = child.getMeasuredHeight();

    int left;
    int top;

    // Align to the anchor. This puts us in an assumed right/bottom child view gravity.
    // If this is not the case we will subtract out the appropriate portion of
    // the child size below.
    switch (anchorHgrav) {
    default:
    case Gravity.LEFT:
        left = anchorRect.left;
        break;
    case Gravity.RIGHT:
        left = anchorRect.right;
        break;
    case Gravity.CENTER_HORIZONTAL:
        left = anchorRect.left + anchorRect.width() / 2;
        break;
    }

    switch (anchorVgrav) {
    default:
    case Gravity.TOP:
        top = anchorRect.top;
        break;
    case Gravity.BOTTOM:
        top = anchorRect.bottom;
        break;
    case Gravity.CENTER_VERTICAL:
        top = anchorRect.top + anchorRect.height() / 2;
        break;
    }

    // Offset by the child view's gravity itself. The above assumed right/bottom gravity.
    switch (hgrav) {
    default:
    case Gravity.LEFT:
        left -= childWidth;
        break;
    case Gravity.RIGHT:
        // Do nothing, we're already in position.
        break;
    case Gravity.CENTER_HORIZONTAL:
        left -= childWidth / 2;
        break;
    }

    switch (vgrav) {
    default:
    case Gravity.TOP:
        top -= childHeight;
        break;
    case Gravity.BOTTOM:
        // Do nothing, we're already in position.
        break;
    case Gravity.CENTER_VERTICAL:
        top -= childHeight / 2;
        break;
    }

    final int width = getWidth();
    final int height = getHeight();

    // Obey margins and padding
    left = Math.max(getPaddingLeft() + lp.leftMargin,
            Math.min(left, width - getPaddingRight() - childWidth - lp.rightMargin));
    top = Math.max(getPaddingTop() + lp.topMargin,
            Math.min(top, height - getPaddingBottom() - childHeight - lp.bottomMargin));

    out.set(left, top, left + childWidth, top + childHeight);
}

From source file:com.android.launcher2.Workspace.java

private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, DragView dragView, CellLayout layout,
        ItemInfo info, int[] targetCell, boolean external, boolean scale) {
    // Now we animate the dragView, (ie. the widget or shortcut preview) into its final
    // location and size on the home screen.
    int spanX = info.spanX;
    int spanY = info.spanY;

    Rect r = estimateItemPosition(layout, info, targetCell[0], targetCell[1], spanX, spanY);
    loc[0] = r.left;//from   w  w  w  . j av a  2s . co  m
    loc[1] = r.top;

    setFinalTransitionTransform(layout);
    float cellLayoutScale = mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(layout, loc);
    resetTransitionTransform(layout);

    float dragViewScaleX;
    float dragViewScaleY;
    if (scale) {
        dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth();
        dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight();
    } else {
        dragViewScaleX = 1f;
        dragViewScaleY = 1f;
    }

    // The animation will scale the dragView about its center, so we need to center about
    // the final location.
    loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2;
    loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2;

    scaleXY[0] = dragViewScaleX * cellLayoutScale;
    scaleXY[1] = dragViewScaleY * cellLayoutScale;
}

From source file:com.android.launcher3.Workspace.java

private static Rect getDrawableBounds(Drawable d) {
    Rect bounds = new Rect();
    d.copyBounds(bounds);/*from w w w  .j a v  a2  s  .co m*/
    if (bounds.width() == 0 || bounds.height() == 0) {
        bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    } else {
        bounds.offsetTo(0, 0);
    }
    if (d instanceof PreloadIconDrawable) {
        int inset = -((PreloadIconDrawable) d).getOutset();
        bounds.inset(inset, inset);
    }
    return bounds;
}

From source file:com.android.launcher3.Workspace.java

/**
 * Draw the View v into the given Canvas.
 *
 * @param v the view to draw//from  w ww. ja v a2  s . c  o m
 * @param destCanvas the canvas to draw on
 * @param padding the horizontal and vertical padding to use when drawing
 */
private static void drawDragView(View v, Canvas destCanvas, int padding) {
    final Rect clipRect = sTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView) {
        Drawable d = ((TextView) v).getCompoundDrawables()[1];
        Rect bounds = getDrawableBounds(d);
        clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding);
        destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so we need to
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}

From source file:android.support.design.widget.CoordinatorLayout.java

private void getDesiredAnchoredChildRectWithoutConstraints(View child, int layoutDirection, Rect anchorRect,
        Rect out, LayoutParams lp, int childWidth, int childHeight) {
    final int absGravity = GravityCompat.getAbsoluteGravity(resolveAnchoredChildGravity(lp.gravity),
            layoutDirection);// w  w w.j a v a2 s.  c om
    final int absAnchorGravity = GravityCompat.getAbsoluteGravity(resolveGravity(lp.anchorGravity),
            layoutDirection);

    final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int anchorHgrav = absAnchorGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int anchorVgrav = absAnchorGravity & Gravity.VERTICAL_GRAVITY_MASK;

    int left;
    int top;

    // Align to the anchor. This puts us in an assumed right/bottom child view gravity.
    // If this is not the case we will subtract out the appropriate portion of
    // the child size below.
    switch (anchorHgrav) {
    default:
    case Gravity.LEFT:
        left = anchorRect.left;
        break;
    case Gravity.RIGHT:
        left = anchorRect.right;
        break;
    case Gravity.CENTER_HORIZONTAL:
        left = anchorRect.left + anchorRect.width() / 2;
        break;
    }

    switch (anchorVgrav) {
    default:
    case Gravity.TOP:
        top = anchorRect.top;
        break;
    case Gravity.BOTTOM:
        top = anchorRect.bottom;
        break;
    case Gravity.CENTER_VERTICAL:
        top = anchorRect.top + anchorRect.height() / 2;
        break;
    }

    // Offset by the child view's gravity itself. The above assumed right/bottom gravity.
    switch (hgrav) {
    default:
    case Gravity.LEFT:
        left -= childWidth;
        break;
    case Gravity.RIGHT:
        // Do nothing, we're already in position.
        break;
    case Gravity.CENTER_HORIZONTAL:
        left -= childWidth / 2;
        break;
    }

    switch (vgrav) {
    default:
    case Gravity.TOP:
        top -= childHeight;
        break;
    case Gravity.BOTTOM:
        // Do nothing, we're already in position.
        break;
    case Gravity.CENTER_VERTICAL:
        top -= childHeight / 2;
        break;
    }

    out.set(left, top, left + childWidth, top + childHeight);
}

From source file:net.robotmedia.acv.ui.widget.OcrLayout.java

public boolean createTriggerCaptureBox(Point pt) {
    final int IDEAL_CAP_WIDTH = 100;
    final int IDEAL_CAP_HALF_WIDTH = IDEAL_CAP_WIDTH / 2;
    final int IDEAL_CAP_HEIGHT = 450;
    final int IDEAL_CAP_ABOVE_PT = 35;
    final int IDEAL_LOOKAHEAD = 30;
    final int FALLBACK_WIDTH = 70;
    final int FALLBACK_HEIGHT = 200;
    final int FALLBACK_ABOVE_PT = 10;

    View v = this.comicView;

    if (v != null) {
        try {/*from   www .j a va 2 s.  c  o  m*/
            // Only create the bitmap that contains the entire screen once
            if (this.lastScreenshot == null) {
                this.lastScreenshot = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
                this.captureCanvas = new Canvas(this.lastScreenshot);
            }

            v.layout(0, 0, v.getWidth(), v.getHeight());

            // Draw the comic view to the lastScreenshot bitmap
            v.draw(this.captureCanvas);

            Rect cropRect = new Rect();

            if (this.textOrientation == TEXT_ORIENTATION_HORIZONTAL) {
                cropRect.left = Math.max(0, pt.x - IDEAL_CAP_ABOVE_PT);
                cropRect.top = Math.max(0, pt.y - IDEAL_CAP_HALF_WIDTH);
                cropRect.right = Math.min(v.getWidth(), pt.x + IDEAL_CAP_HEIGHT);
                cropRect.bottom = Math.min(v.getHeight(), pt.y + IDEAL_CAP_HALF_WIDTH);
            } else // Vertical or Auto
            {
                cropRect.left = Math.max(0, pt.x - IDEAL_CAP_HALF_WIDTH);
                cropRect.top = Math.max(0, pt.y - IDEAL_CAP_ABOVE_PT);
                cropRect.right = Math.min(v.getWidth(), pt.x + IDEAL_CAP_HALF_WIDTH);
                cropRect.bottom = Math.min(v.getHeight(), pt.y + IDEAL_CAP_HEIGHT);
            }

            // Get bitmap that contains the area to crop
            Bitmap cropBmp = Bitmap.createBitmap(this.lastScreenshot, cropRect.left, cropRect.top,
                    cropRect.width(), cropRect.height());

            // Get the click point relative to the cropped area
            Point ptInCropRect = new Point(pt.x - cropRect.left, pt.y - cropRect.top);

            // Crop
            Pix pixs = ReadFile.readBitmap(cropBmp);

            if (pixs == null) {
                return false;
            }

            cropBmp.recycle();

            // Convert to grayscale
            pixs = Convert.convertTo8(pixs);

            if (pixs == null) {
                return false;
            }

            Pix tempOtsu = Binarize.otsuAdaptiveThreshold(pixs, 2000, 2000, 0, 0, 0.0f);

            if (tempOtsu == null) {
                return false;
            }

            float ave = 0.0f;

            // Get the average intensity of the pixels around the click point
            if (this.textOrientation == TEXT_ORIENTATION_HORIZONTAL) {
                ave = Pix.averageInRect(tempOtsu, (int) (ptInCropRect.x * 0.9),
                        (int) (ptInCropRect.y - (tempOtsu.getHeight() * 0.95) / 2.0),
                        (int) (tempOtsu.getWidth() * 0.25), (int) (tempOtsu.getHeight() * 0.95));
            } else // Vertical or Auto
            {
                ave = Pix.averageInRect(tempOtsu, (int) (ptInCropRect.x - (tempOtsu.getWidth() * 0.95) / 2.0),
                        (int) (ptInCropRect.y * 0.9), (int) (tempOtsu.getWidth() * 0.95),
                        (int) (tempOtsu.getHeight() * 0.25));
            }

            tempOtsu.recycle();

            // If background is dark
            if (ave >= 0.51f) {
                // Negate image
                boolean invertStatus = pixs.invert();

                if (!invertStatus) {
                    return false;
                }
            }

            // Blur to reduce noise
            pixs = Convolve.blockconvGray(pixs, 1, 1);

            if (pixs == null) {
                return false;
            }

            // Apply unsharp mask
            pixs = Enhance.unsharpMasking(pixs, 5, 2.5f);

            if (pixs == null) {
                return false;
            }

            // Binarize
            pixs = Binarize.otsuAdaptiveThreshold(pixs, 2000, 2000, 0, 0, 0.0f);

            if (pixs == null) {
                return false;
            }

            // Remove black pixels connected to the border.
            // This eliminates annoying things like text bubbles.
            pixs = Seedfill.removeBorderConnComps(pixs, 8);

            if (pixs == null) {
                return false;
            }

            // Find the black pixel closest to the click point
            Point nearestPixel = LeptUtils.findNearestBlackPixel(pixs, ptInCropRect.x, ptInCropRect.y, 40);

            // Get a bounding box surrounding the clicked text
            Rect boundingBox = BoundingTextRect.getBoundingRect(pixs, nearestPixel.x, nearestPixel.y,
                    (this.textOrientation != TEXT_ORIENTATION_HORIZONTAL), IDEAL_LOOKAHEAD);

            // Form the capture box size and position based on click point and bounding box
            this.captureBox = new Rect();
            this.captureBox.left = pt.x - ptInCropRect.x + boundingBox.left;
            this.captureBox.top = pt.y - ptInCropRect.y + boundingBox.top;
            this.captureBox.right = this.captureBox.left + boundingBox.width();
            this.captureBox.bottom = this.captureBox.top + boundingBox.height();

            // If could not find adequate bounding rectangle, fallback to a default size
            if (this.captureBox.width() <= 2 || this.captureBox.height() <= 2) {
                if (this.textOrientation == TEXT_ORIENTATION_HORIZONTAL) {
                    this.captureBox = new Rect();
                    this.captureBox.left = Math.max(0, pt.x - FALLBACK_ABOVE_PT);
                    this.captureBox.top = Math.max(0, pt.y - FALLBACK_WIDTH / 2);
                    this.captureBox.right = Math.min(v.getWidth(), pt.x + FALLBACK_HEIGHT);
                    this.captureBox.bottom = Math.min(v.getHeight(), pt.y + FALLBACK_WIDTH / 2);
                } else // Vertical or Auto
                {
                    this.captureBox = new Rect();
                    this.captureBox.left = Math.max(0, pt.x - FALLBACK_WIDTH / 2);
                    this.captureBox.top = Math.max(0, pt.y - FALLBACK_ABOVE_PT);
                    this.captureBox.right = Math.min(v.getWidth(), pt.x + FALLBACK_WIDTH / 2);
                    this.captureBox.bottom = Math.min(v.getHeight(), pt.y + FALLBACK_HEIGHT);
                }
            }

            pixs.recycle();
        } catch (Exception e) {
            // If we're here, it's probably an out-of-memory exception
            Log.e(LOG_TAG, "Exception in processTriggerCapture()! " + e);
            return false;
        }
    }

    this.isTriggerCapture = true;

    return true;
}