Example usage for android.graphics Rect Rect

List of usage examples for android.graphics Rect Rect

Introduction

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

Prototype

public Rect(int left, int top, int right, int bottom) 

Source Link

Document

Create a new rectangle with the specified coordinates.

Usage

From source file:com.c4mprod.utils.ImageManager.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 20;

    paint.setAntiAlias(true);//w w  w.j a v  a  2s. c  o  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    if (output != bitmap) {
        bitmap.recycle();
    }
    return output;
}

From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java

private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;
    paint.setAntiAlias(true);//w  ww. java  2 s.c om
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java

private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);//from w w w.  j a v  a2  s  .c  o m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}

From source file:ac.robinson.paperchains.PaperChainsActivity.java

public void audioSaveCompleted(final Rect audioRect, final long trackId) {
    // convert back to grid-based coordinates
    final PointF rectLeftTop = QRImageParser.getGridPosition(mImageParameters,
            new PointF(audioRect.left, audioRect.top));
    final PointF rectRightBottom = QRImageParser.getGridPosition(mImageParameters,
            new PointF(audioRect.right, audioRect.bottom));

    // account for image rotation/inversion by making sure to use the min/max values of each coordinate
    int left = Math.round(rectLeftTop.x);
    int top = Math.round(rectLeftTop.y);
    int right = Math.round(rectRightBottom.x);
    int bottom = Math.round(rectRightBottom.y);
    final int leftmost = Math.min(left, right);
    final int topmost = Math.min(top, bottom);
    final int rightmost = Math.max(left, right);
    final int bottommost = Math.max(top, bottom);

    RequestParams params = new RequestParams("newaudio", 1); // 1 reserved for possible future use as box ID
    params.put("left", leftmost);
    params.put("top", topmost);
    params.put("right", rightmost);
    params.put("bottom", bottommost);
    params.put("soundCloudId", trackId);
    params.put("pageId", mPageId);

    // update on the server
    new AsyncHttpClient().get(CODE_SERVER_URL, params, new JsonHttpResponseHandler() {
        @Override/* w  w w  .  j a va 2  s.c  om*/
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                if ("ok".equals(response.getString("status"))) {
                    AudioAreaHolder holder = new AudioAreaHolder(trackId,
                            new Rect(leftmost, topmost, rightmost, bottommost));
                    holder.setImageRect(new Rect(audioRect));
                    mAudioAreas.add(holder);
                    mImageView.addAudioAreaRect(holder.imageRect);

                    mSaveButton.clearAnimation();
                    mSaveButton.setImageResource(R.drawable.ic_done_white_24dp);
                    delayedResetRecordingInterface();
                } else {
                    audioSaveFailed(R.string.hint_audio_save_failed);
                }
            } catch (JSONException e) {
                audioSaveFailed(R.string.hint_audio_save_failed);
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            audioSaveFailed(R.string.hint_audio_save_failed);
        }
    });
}

From source file:org.artoolkit.ar.samples.ARMovie.ARMovieActivity.java

private Rect calculateFocusArea(float x, float y) {
    int left = clamp(Float.valueOf((x / camSurface.getWidth()) * 2000 - 1000).intValue(), FOCUS_AREA_SIZE);
    int top = clamp(Float.valueOf((y / camSurface.getHeight()) * 2000 - 1000).intValue(), FOCUS_AREA_SIZE);

    return new Rect(left, top, left + FOCUS_AREA_SIZE, top + FOCUS_AREA_SIZE);
}

From source file:com.skytree.epubtest.BookViewActivity.java

public void applyThemeToRV(int themeIndex) {
    this.themeIndex = themeIndex;
    // set BackgroundImage
    // the first  Rect should be the rect of background image itself
    // the second Rect is used to define the inner client area which the real contentView will reside. 
    if (this.isDoublePagedForLandscape) {
        rv.setBackgroundForLandscape(this.getBackgroundForLandscape(), new Rect(0, 0, 2004, 1506),
                new Rect(32, 0, 2004 - 32, 1506)); // Android Rect - left,top,right,bottom
    } else {//  w ww. j a v  a  2 s  . c o  m
        rv.setBackgroundForLandscape(this.getBackgroundForLandscape(), new Rect(0, 0, 2004, 1506),
                new Rect(0, 0, 2004 - 32, 1506)); // Android Rect - left,top,right,bottom
    }
    rv.setBackgroundForPortrait(this.getBackgroundForPortrait(), new Rect(0, 0, 1002, 1506),
            new Rect(0, 0, 1002 - 32, 1506)); // Android Rect - left,top,right,bottom

    // setBackgroundColor is used to set the background color in initial time.
    // changeBackgroundColor is used to set the background color in run time.
    // both are effective only when background image is not set or null.      
    if (!this.isInitialized) {
        rv.setBackgroundColor(getCurrentTheme().backgroundColor);
        rv.setForegroundColor(getCurrentTheme().foregroundColor);
    } else {
        rv.changeBackgroundColor(getCurrentTheme().backgroundColor);
        rv.changeForegroundColor(getCurrentTheme().foregroundColor);
        rv.recalcLayout();

        new Handler().postDelayed(new Runnable() {
            public void run() {
                rv.repaint();
            }
        }, 1000);
    }
}

From source file:com.ktouch.kdc.launcher4.camera.CameraManager.java

/**
 * Defines the main focus point of the camera to the provided x and y values.
 * Those values must between -1000 and 1000, where -1000 is the top/left, and 1000 the bottom/right
 *
 * @param x The X position of the focus point
 * @param y The Y position of the focus point
 *//*from   w  w w . j a va  2s  .co m*/
public void setFocusPoint(int x, int y) {
    if (x < -1000 || x > 1000 || y < -1000 || y > 1000) {
        Log.e(TAG, "setFocusPoint: values are not ideal " + "x= " + x + " y= " + y);
        return;
    }
    Camera.Parameters params = getParameters();

    if (params != null && params.getMaxNumFocusAreas() > 0) {
        List<Camera.Area> focusArea = new ArrayList<Camera.Area>();
        focusArea.add(new Camera.Area(new Rect(x, y, x + FOCUS_WIDTH, y + FOCUS_HEIGHT), 1000));

        params.setFocusAreas(focusArea);

        try {
            mCamera.setParameters(params);
        } catch (Exception e) {
            // Ignore, we might be setting it too
            // fast since previous attempt
        }
    }
}

From source file:com.freerdp.freerdpcore.presentation.SessionActivity.java

@Override
public void OnGraphicsUpdate(int x, int y, int width, int height) {
    LibFreeRDP.updateGraphics(session.getInstance(), bitmap, x, y, width, height);

    sessionView.addInvalidRegion(new Rect(x, y, x + width, y + height));

    /* since sessionView can only be modified from the UI thread
     * any modifications to it need to be scheduled */

    uiHandler.sendEmptyMessage(UIHandler.REFRESH_SESSIONVIEW);
}

From source file:com.ktouch.kdc.launcher4.camera.CameraManager.java

/**
 * Defines the exposure metering point of the camera to the provided x and y values.
 * Those values must between -1000 and 1000, where -1000 is the top/left, and 1000 the bottom/right
 *
 * @param x The X position of the exposure metering point
 * @param y The Y position of the exposure metering point
 *///from w  ww. j  ava2 s  .  c  o m
public void setExposurePoint(int x, int y) {
    Camera.Parameters params = getParameters();

    if (params != null && params.getMaxNumMeteringAreas() > 0) {
        List<Camera.Area> exposureArea = new ArrayList<Camera.Area>();
        exposureArea.add(new Camera.Area(new Rect(x, y, x + FOCUS_WIDTH, y + FOCUS_HEIGHT), 1000));

        params.setMeteringAreas(exposureArea);

        try {
            mCamera.setParameters(params);
        } catch (Exception e) {
            // Ignore, we might be setting it too
            // fast since previous attempt
        }
    }
}