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.dastanapps.camera2.view.Cam2AutoFitTextureView.java

@Nullable
private Boolean touchTofocus2(MotionEvent event) {
    MotionEvent motionEvent = event;/*from   w w w.  jav  a  2  s.  c  o  m*/
    final int actionMasked = motionEvent.getActionMasked();
    if (actionMasked != MotionEvent.ACTION_DOWN) {
        return false;
    }
    if (mManualFocusEngaged) {
        Log.d(TAG, "Manual focus already engaged");
        return true;
    }

    final Rect sensorArraySize = mCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);

    //TODO: here I just flip x,y, but this needs to correspond with the sensor orientation (via SENSOR_ORIENTATION)
    final int y = (int) ((motionEvent.getX() / (float) getWidth()) * (float) sensorArraySize.height());
    final int x = (int) ((motionEvent.getY() / (float) getHeight()) * (float) sensorArraySize.width());
    final int halfTouchWidth = 150; //(int)motionEvent.getTouchMajor(); //TODO: this doesn't represent actual touch size in pixel. Values range in [3, 10]...
    final int halfTouchHeight = 150; //(int)motionEvent.getTouchMinor();
    MeteringRectangle focusAreaTouch = new MeteringRectangle(Math.max(x - halfTouchWidth, 0),
            Math.max(y - halfTouchHeight, 0), halfTouchWidth * 2, halfTouchHeight * 2,
            MeteringRectangle.METERING_WEIGHT_MAX - 1);

    CameraCaptureSession.CaptureCallback captureCallbackHandler = new CameraCaptureSession.CaptureCallback() {
        @Override
        public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
                TotalCaptureResult result) {
            super.onCaptureCompleted(session, request, result);
            mManualFocusEngaged = false;

            if (request.getTag() == "FOCUS_TAG") {
                //the focus trigger is complete -
                //resume repeating (preview surface will get frames), clear AF trigger
                mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, null);
                try {
                    mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), null, null);
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request,
                CaptureFailure failure) {
            super.onCaptureFailed(session, request, failure);
            Log.e(TAG, "Manual AF failure: " + failure);
            mManualFocusEngaged = false;
        }
    };

    //first stop the existing repeating request
    try {
        mPreviewSession.stopRepeating();
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }

    //cancel any existing AF trigger (repeated touches, etc.)
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
    try {
        mPreviewSession.capture(mPreviewBuilder.build(), captureCallbackHandler, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }

    //Now add a new AF trigger with focus region
    if (isMeteringAreaAFSupported()) {
        mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[] { focusAreaTouch });
    }
    mPreviewBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
    mPreviewBuilder.setTag("FOCUS_TAG"); //we'll capture this later for resuming the preview

    //            //then we ask for a single request (not repeating!)
    //            mPreviewSession.capture(mPreviewBuilder.build(), captureCallbackHandler, mBackgroundHandler);
    return null;
}

From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java

protected void constrainTranslation(Point translation, float scale) {
    int currentEdgeEffect = 0;
    if (scale <= 1) {
        finishEdgeEffect();//  w w w  .  j a  v  a 2s  .  com
        return;
    }
    Rect originalBounds = mMasterImage.getOriginalBounds();
    Matrix originalToScreen = mMasterImage.getImageToScreenMatrix(originalBounds.width(),
            originalBounds.height(), getWidth(), getHeight());
    if (originalToScreen == null) {
        finishEdgeEffect();
        return;
    }
    RectF screenPos = new RectF(originalBounds);
    originalToScreen.mapRect(screenPos);
    boolean rightConstraint = screenPos.right < getWidth();
    boolean leftConstraint = screenPos.left > 0;
    boolean topConstraint = screenPos.top > 0;
    boolean bottomConstraint = screenPos.bottom < getHeight();
    if (screenPos.width() > getWidth()) {
        if (rightConstraint && !leftConstraint) {
            float tx = screenPos.right - translation.x * scale;
            translation.x = (int) ((getWidth() - tx) / scale);
            currentEdgeEffect = EDGE_RIGHT;
        } else if (leftConstraint && !rightConstraint) {
            float tx = screenPos.left - translation.x * scale;
            translation.x = (int) ((-tx) / scale);
            currentEdgeEffect = EDGE_LEFT;
        }
    } else {
        float tx = screenPos.right - translation.x * scale;
        float dx = (getWidth() - screenPos.width()) / 2f;
        translation.x = (int) ((getWidth() - tx - dx) / scale);
    }
    if (screenPos.height() > getHeight()) {
        if (bottomConstraint && !topConstraint) {
            float ty = screenPos.bottom - translation.y * scale;
            translation.y = (int) ((getHeight() - ty) / scale);
            currentEdgeEffect = EDGE_BOTTOM;
        } else if (topConstraint && !bottomConstraint) {
            float ty = screenPos.top - translation.y * scale;
            translation.y = (int) ((-ty) / scale);
            currentEdgeEffect = EDGE_TOP;
        }
    } else {
        float ty = screenPos.bottom - translation.y * scale;
        float dy = (getHeight() - screenPos.height()) / 2f;
        translation.y = (int) ((getHeight() - ty - dy) / scale);
    }
    if (mCurrentEdgeEffect != currentEdgeEffect) {
        if (mCurrentEdgeEffect == 0 || currentEdgeEffect != 0) {
            mCurrentEdgeEffect = currentEdgeEffect;
            mEdgeEffect.finish();
        }
        mEdgeEffect.setSize(getWidth(), mEdgeSize);
    }
    if (currentEdgeEffect != 0) {
        mEdgeEffect.onPull(mEdgeSize);
    }
}

From source file:com.google.blockly.android.ui.VirtualWorkspaceView.java

/**
 * Set scroll position for the {@link WorkspaceView} wrapped by this instance.
 * <p/>/*from  ww  w  . j  a va2  s .c  o  m*/
 * The given scroll position specifies the absolute offset of the displayed area within the
 * virtual workspace. Inside this method, the given scroll coordinates are clamped to their
 * valid ranges determined from the bounding box of all blocks in the virtual workspace, and
 * allowing for overscroll of half the width (or height, respectively) of this view.
 *
 * @param x The horizontal scroll position in pixel units of this view.
 * @param y The vertical scroll position in pixel units of this view.
 */
@Override
public void scrollTo(int x, int y) {
    if (!mScrollable) {
        return;
    }

    // Clamp x and y to the scroll range that will allow for 1/2 the view (or more, for smaller
    // views) being outside the range use by blocks. This matches the computations in
    // computeHorizontalScrollOffset and computeVerticalScrollOffset, respectively.
    Rect blocksBounds = getViewScaledBlockBounds();
    int blocksWidth = blocksBounds.width();
    int blocksHeight = blocksBounds.height();

    int viewWidth = getMeasuredWidth();
    int halfViewWidth = viewWidth / 2;
    int viewHeight = getMeasuredHeight();
    int halfViewHeight = viewHeight / 2;

    int horzMargin = halfViewWidth; // Default margin is half the scrollable view width.
    if (blocksWidth < halfViewWidth) {
        horzMargin = viewWidth - blocksWidth;
    }

    int vertMargin = halfViewHeight;
    if (blocksHeight < halfViewHeight) {
        vertMargin = viewHeight - blocksHeight;
    }

    final int xMin = blocksBounds.left - horzMargin;
    final int xMax = blocksBounds.right + horzMargin - viewWidth;
    x = clampToRange(x, xMin, xMax);

    final int yMin = blocksBounds.top - vertMargin;
    final int yMax = blocksBounds.bottom + vertMargin - viewHeight;
    y = clampToRange(y, yMin, yMax);

    // Update and show scroll bars.
    super.scrollTo(x, y);

    // Set view offset in the virtual workspace and request layout of the WorkspaceView with the
    // new offset. The view offset is the location of the top-left pixel displayed in this view
    // in virtual workspace coordinates, regardless of RTL vs. LTR mode.
    mWorkspaceView.getWorkspaceHelper().setVirtualWorkspaceViewOffset(
            (int) (x / mViewScale), /* virtual coords. */
            (int) (y / mViewScale));
    mWorkspaceView.requestLayout();
}

From source file:com.dirkgassen.wator.ui.view.RollingGraphView.java

/**
 * Paints the data points of one series horizontally.
 *
 * @param c canvas to paint to/*from  w w w  .  j  a  v a2 s. c o  m*/
 * @param nameBounds bounds of the label
 * @param seriesNo index of the series to paint
 * @param width width of the view
 * @param height height of the view
 * @param maxValue calculated possible maximum data value
 */
private void paintSeriesHorizontal(Canvas c, Rect nameBounds, int seriesNo, int width, int height,
        float maxValue) {
    float paddingLeft = getPaddingLeft();
    float paddingTop = getPaddingTop();
    float paddingRight = getPaddingRight();
    float paddingBottom = getPaddingBottom();

    float x = width - nameBounds.width() - paddingRight;
    float y;
    if (currentValue == -1) {
        y = height - (height - paddingBottom - paddingTop) / (seriesNames.length + 1) * (seriesNo + 1)
                + paddingTop;
    } else {
        if (dataValues == null) {
            Log.e("Wa-Tor", "NO DATA VALUES although currentValue is " + currentValue);
        } else if (dataValues[currentValue] == null) {
            Log.e("Wa-Tor", "NO SERIES DATA although currentValue is " + currentValue);
        }
        y = height - paddingBottom
                - dataValues[currentValue][seriesNo] * (height - paddingBottom - paddingTop) / maxValue;
    }
    c.drawText(seriesNames[seriesNo], x, y + nameBounds.height() / 2, seriesPaints[seriesNo]);

    float scale = seriesPaints[seriesNo].getStrokeWidth();
    x -= 6f * scale;
    c.drawLine(x, y, x + 3f * scale, y, seriesPaints[seriesNo]);
    c.drawLine(x, y, x + 1.5f * scale, y + 1.5f * scale, seriesPaints[seriesNo]);
    c.drawLine(x, y, x + 1.5f * scale, y - 1.5f * scale, seriesPaints[seriesNo]);
    if (currentValue != -1) {
        int no = currentValue;
        do {
            if (dataValues[no] == null) {
                break;
            }
            float newX = x - 1;
            float newY = height - paddingBottom
                    - dataValues[no][seriesNo] * (height - paddingBottom - paddingTop) / maxValue;
            c.drawLine(x, y, newX, newY, seriesPaints[seriesNo]);
            x = newX;
            y = newY;
            no = no == 0 ? dataValues.length - 1 : no - 1;
        } while (no != oldestValue && x > paddingLeft);
    }
}

From source file:org.sufficientlysecure.keychain.gm.GmAccessibilityService.java

@SuppressLint("RtlHardcoded")
private void drawOverlay(AccessibilityNodeInfo node, View.OnClickListener onClickListener) {

    mOverlay = new FrameLayout(this);

    // must be encapsulated into FrameLayout for animation
    FrameLayout mAnimatedChild = new FrameLayout(this);
    LayoutInflater systemInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final Context contextThemeWrapper = new ContextThemeWrapper(this, R.style.FixedBottomSheetTheme);
    LayoutInflater inflater = systemInflater.cloneInContext(contextThemeWrapper);

    View child = inflater.inflate(R.layout.fixed_bottom_sheet, null);
    mAnimatedChild.addView(child);//w  ww.j a v  a 2s.c om

    Button b = (Button) child.findViewById(R.id.fixed_bottom_sheet_button);
    b.setText(R.string.decrypt_with_openkeychain);
    b.setOnClickListener(onClickListener);

    ImageButton close = (ImageButton) child.findViewById(R.id.fixed_bottom_sheet_close);
    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            closeOverlay();
        }
    });

    Rect webviewRect = new Rect();
    node.getBoundsInScreen(webviewRect);

    Display display = mWindowManager.getDefaultDisplay();
    Rect displayRect = new Rect();
    display.getRectSize(displayRect);

    int xpos = webviewRect.left;
    int ypos = webviewRect.top - getStatusBarHeight() < getToolbarHeight() ? getToolbarHeight()
            : webviewRect.top - getStatusBarHeight();

    int width = webviewRect.width();
    int height = webviewRect.bottom < displayRect.height()
            ? webviewRect.bottom - getToolbarHeight() - getStatusBarHeight()
            : displayRect.height() - ypos - getStatusBarHeight();

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(width, height, xpos, ypos,
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.windowAnimations = R.style.OverlayAnimation;
    mWindowManager.addView(mOverlay, params);
    mOverlay.addView(mAnimatedChild);
}

From source file:com.jafme.mobile.activity.CropImageActivity.java

private void done() {
    if (Network.isNetworkDisconnected(this)) {
        Toast.makeText(this, R.string.no_network_connection, Toast.LENGTH_SHORT).show();
        return;/*from ww  w .  j ava2  s .c  om*/
    }

    if (cropView == null || isSaving)
        return;
    isSaving = true;

    Bitmap croppedImage;
    Rect r = cropView.getScaledCropRect(sampleSize);
    int width = r.width();
    int height = r.height();

    int outWidth = width;
    int outHeight = height;
    if (maxX > 0 && maxY > 0 && (width > maxX || height > maxY)) {
        float ratio = (float) width / (float) height;
        if ((float) maxX / (float) maxY > ratio) {
            outHeight = maxY;
            outWidth = (int) ((float) maxY * ratio + .5f);
        } else {
            outWidth = maxX;
            outHeight = (int) ((float) maxX / ratio + .5f);
        }
    }

    try {
        croppedImage = decodeRegionCrop(r, outWidth, outHeight);
    } catch (IllegalArgumentException e) {
        setResultException(e);
        finish();
        return;
    }

    if (croppedImage != null) {
        imageView.setImageRotateBitmapResetBase(new RotateBitmap(croppedImage, exifRotation), true);
        imageView.center(true, true);
        imageView.highlightViews.clear();
    }

    saveImage(croppedImage);
}

From source file:org.jraf.android.hellomundo.app.welcome.WelcomeActivity.java

private void setShowCasePosition(View view, Rect r) {
    Log.d("r=" + r);
    Rect rect = new Rect(r);
    if (rect.top > 0) {
        int margin = getResources().getDimensionPixelSize(R.dimen.welcome_showCase_margin);
        rect.inset(-margin, -margin);/*from   ww w  . j a  v a 2 s  . com*/
    }

    View imgShowCase = view.findViewById(R.id.imgShowCase);
    LayoutParams layoutParams = imgShowCase.getLayoutParams();
    layoutParams.width = rect.width();
    layoutParams.height = rect.height();
    ((RelativeLayout.LayoutParams) layoutParams).topMargin = rect.top;
    ((RelativeLayout.LayoutParams) layoutParams).leftMargin = rect.left;
    imgShowCase.setLayoutParams(layoutParams);

    View imgShowCaseHide = view.findViewById(R.id.imgShowCase_hide);
    layoutParams = imgShowCaseHide.getLayoutParams();
    layoutParams.width = rect.width();
    layoutParams.height = rect.height();
    ((RelativeLayout.LayoutParams) layoutParams).topMargin = rect.top;
    ((RelativeLayout.LayoutParams) layoutParams).leftMargin = rect.left;
    imgShowCaseHide.setLayoutParams(layoutParams);

    View imgAbove = view.findViewById(R.id.imgAbove);
    layoutParams = imgAbove.getLayoutParams();
    layoutParams.height = rect.top;
    imgAbove.setLayoutParams(layoutParams);

    View imgLeft = view.findViewById(R.id.imgLeft);
    layoutParams = imgLeft.getLayoutParams();
    layoutParams.width = rect.left;
    imgLeft.setLayoutParams(layoutParams);
}

From source file:foam.starwisp.DrawableMap.java

public Marker AddText(final LatLng location, final String text, final int padding, final int fontSize,
        int colour) {
    Marker marker = null;// w  ww.j  av a 2 s  .c om

    final TextView textView = new TextView(m_Context);
    textView.setText(text);
    textView.setTextSize(fontSize);
    textView.setTypeface(m_Context.m_Typeface);

    final Paint paintText = textView.getPaint();

    final Rect boundsText = new Rect();
    paintText.getTextBounds(text, 0, textView.length(), boundsText);
    paintText.setTextAlign(Paint.Align.CENTER);

    final Bitmap.Config conf = Bitmap.Config.ARGB_8888;
    final Bitmap bmpText = Bitmap.createBitmap(boundsText.width() + 2 * padding,
            boundsText.height() + 2 * padding, conf);

    final Canvas canvasText = new Canvas(bmpText);
    paintText.setColor(Color.BLACK);

    canvasText.drawText(text, (canvasText.getWidth() / 2) + 3,
            (canvasText.getHeight() - padding - boundsText.bottom) + 3, paintText);

    paintText.setColor(colour);

    canvasText.drawText(text, canvasText.getWidth() / 2, canvasText.getHeight() - padding - boundsText.bottom,
            paintText);

    final MarkerOptions markerOptions = new MarkerOptions().position(location)
            .icon(BitmapDescriptorFactory.fromBitmap(bmpText)).anchor(0.5f, 1);

    marker = map.addMarker(markerOptions);

    return marker;
}

From source file:org.akop.crosswords.fragment.CrosswordFragment.java

@Override
public void onCellLongPressed(CrosswordView view, Crossword.Word word, int cell) {
    // Get the highlighted cell's rectangle
    Rect rect = view.getCellRect(word, cell);

    // Offset the placeholder to the same position as the cell
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(rect.width(), rect.height());
    lp.setMargins(rect.left, rect.top, 0, 0);
    mMenuPlaceholder.setLayoutParams(lp);

    // Save the word/cell associated with the popup
    mPopupWord = word;/*from   w w w  .jav  a 2  s  .  c om*/
    mPopupCell = cell;

    // Initialize and show the popup menu
    PopupMenu popup = new PopupMenu(getActivity(), mMenuPlaceholder);
    popup.setOnMenuItemClickListener(mCellPopupListener);

    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.fragment_crossword_popup_cell, popup.getMenu());

    popup.show();
}

From source file:eu.janmuller.android.simplecropimage.CropImage.java

private void onSaveClicked() throws Exception {
    // TODO this code needs to change to use the decode/crop/encode single
    // step api so that we don't require that the whole (possibly large)
    // bitmap doesn't have to be read into memory
    if (mSaving)/*www  . ja  v  a2s.c  o  m*/
        return;

    if (mCrop == null) {

        return;
    }

    mSaving = true;

    Rect r = mCrop.getCropRect();

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

    // If we are circle cropping, we want alpha channel, which is the
    // third param here.
    Bitmap croppedImage;
    try {

        croppedImage = Bitmap.createBitmap(width, height,
                mCircleCrop ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } catch (Exception e) {
        throw e;
    }
    if (croppedImage == null) {

        return;
    }

    {
        Canvas canvas = new Canvas(croppedImage);
        Rect dstRect = new Rect(0, 0, width, height);
        canvas.drawBitmap(mBitmap, r, dstRect, null);
    }

    if (mCircleCrop) {

        // OK, so what's all this about?
        // Bitmaps are inherently rectangular but we want to return
        // something that's basically a circle.  So we fill in the
        // area around the circle with alpha.  Note the all important
        // PortDuff.Mode.CLEAR.
        Canvas c = new Canvas(croppedImage);
        Path p = new Path();
        p.addCircle(width / 2F, height / 2F, width / 2F, Path.Direction.CW);
        c.clipPath(p, Region.Op.DIFFERENCE);
        c.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
    }

    /* If the output is required to a specific size then scale or fill */
    if (mOutputX != 0 && mOutputY != 0) {

        if (mScale) {

            /* Scale the image to the required dimensions */
            Bitmap old = croppedImage;
            croppedImage = Util.transform(new Matrix(), croppedImage, mOutputX, mOutputY, mScaleUp);
            if (old != croppedImage) {

                old.recycle();
            }
        } else {

            /* Don't scale the image crop it to the size requested.
                 * Create an new image with the cropped image in the center and
             * the extra space filled.
             */

            // Don't scale the image but instead fill it so it's the
            // required dimension
            Bitmap b = Bitmap.createBitmap(mOutputX, mOutputY, Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(b);

            Rect srcRect = mCrop.getCropRect();
            Rect dstRect = new Rect(0, 0, mOutputX, mOutputY);

            int dx = (srcRect.width() - dstRect.width()) / 2;
            int dy = (srcRect.height() - dstRect.height()) / 2;

            /* If the srcRect is too big, use the center part of it. */
            srcRect.inset(Math.max(0, dx), Math.max(0, dy));

            /* If the dstRect is too big, use the center part of it. */
            dstRect.inset(Math.max(0, -dx), Math.max(0, -dy));

            /* Draw the cropped bitmap in the center */
            canvas.drawBitmap(mBitmap, srcRect, dstRect, null);

            /* Set the cropped bitmap as the new bitmap */
            croppedImage.recycle();
            croppedImage = b;
        }
    }

    // Return the cropped image directly or save it to the specified URI.
    Bundle myExtras = getIntent().getExtras();
    if (myExtras != null && (myExtras.getParcelable("data") != null || myExtras.getBoolean(RETURN_DATA))) {

        Bundle extras = new Bundle();
        extras.putParcelable(RETURN_DATA_AS_BITMAP, croppedImage);
        setResult(RESULT_OK, (new Intent()).setAction(ACTION_INLINE_DATA).putExtras(extras));
        finish();
    } else {
        final Bitmap b = croppedImage;
        Util.startBackgroundJob(this, null, getString(R.string.saving_image), new Runnable() {
            public void run() {

                saveOutput(b);
            }
        }, mHandler);
    }
}