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() 

Source Link

Document

Create a new empty Rect.

Usage

From source file:Main.java

public static Rect rectF2Rect(RectF rectF) {
    Rect rect = new Rect();
    rect.set((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom);
    return rect;/*from  w w w . ja  va2 s .  c om*/
}

From source file:Main.java

public static void prepare(Activity activity, int id, int width) {
    if (sCoverBitmap != null) {
        sCoverBitmap.recycle();//from  ww w  .  j  a v a 2 s.c  o  m
    }
    Rect rectgle = new Rect();
    Window window = activity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
    int statusBarHeight = rectgle.top;

    ViewGroup v1 = (ViewGroup) activity.findViewById(id).getRootView();
    v1.setDrawingCacheEnabled(true);
    Bitmap source = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);
    if (statusBarHeight != 0) {
        sCoverBitmap = Bitmap.createBitmap(source, 0, statusBarHeight, source.getWidth(),
                source.getHeight() - statusBarHeight);
        source.recycle();
    } else {
        sCoverBitmap = source;
    }
    sWidth = width;
}

From source file:Main.java

public static int getSystemUiStatusBarHeight(Activity activity) {
    final int statusBarResId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (statusBarResId > 0) {
        return activity.getResources().getDimensionPixelSize(statusBarResId);
    } else {//  w  ww .  ja v  a2 s .c  om
        final Rect rect = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
        return rect.top;
    }
}

From source file:Main.java

/**
 * Method getTextWith() used to get the TextView's Content
 * //from w  w  w. j a v a  2 s. c  o m
 * @param textView
 *            The processed TextView.
 * @param text
 *            The Content of TextView
 * @return
 */
public static int getTextWidth(TextView textView, String text) {
    Rect bounds = new Rect();
    Paint textPaint = textView.getPaint();
    textPaint.getTextBounds(text, 0, text.length(), bounds);
    return bounds.width();
}

From source file:Main.java

public static Rect getBoundsInParent(AccessibilityNodeInfoCompat nodeInfo) {
    Rect rect = new Rect();
    nodeInfo.getBoundsInParent(rect);
    return rect;
}

From source file:Main.java

public static Bitmap snapShotWithoutStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);/*from  w  w  w.j a v  a2s  . co m*/
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;

    int width = getScreenWidth(activity);
    int height = getScreenHeight(activity);
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return bp;

}

From source file:Main.java

public static int getTextViewMeasureWidth(TextView textView, String text) {
    if (textView == null)
        return 0;
    TextPaint paint = textView.getPaint();
    Rect rect = new Rect();
    paint.getTextBounds(text, 0, text.length(), rect);
    return Math.abs(rect.right - rect.left);
}

From source file:Main.java

public static Bitmap snapShotWithoutStatusBar(Activity activity) {
    View decorView = activity.getWindow().getDecorView();
    decorView.setDrawingCacheEnabled(true);
    decorView.buildDrawingCache();//from   w  w w  . j a va2s .  co  m
    Bitmap bmp = decorView.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;

    int width = getScreenWidth(activity);
    int height = getScreenHeight(activity);
    Bitmap bitMap = null;
    bitMap = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight);
    decorView.destroyDrawingCache();
    return bitMap;
}

From source file:Main.java

/**
 * This method finds location of the view on the screen.
 * /*from w  w  w.j av  a  2s. co m*/
 * @param view
 * @return rect
 */
public static Rect locateView(View view) {
    int[] loc_int = new int[2];
    if (view == null)
        return null;
    try {
        view.getLocationOnScreen(loc_int);
    } catch (NullPointerException npe) {
        // Happens when the view doesn't exist on screen anymore.
        return null;
    }
    Rect location = new Rect();
    location.left = loc_int[0];
    location.top = loc_int[1];
    location.right = location.left + view.getWidth();
    location.bottom = location.top + view.getHeight();
    return location;
}

From source file:Main.java

/**
 * Take screenshot without status bar.// ww w.  ja  v a  2s.c om
 *
 * @param activity
 * @return screenshot bitmap.
 */
public static Bitmap takeScreenshot(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bitmap = view.getDrawingCache();
    Rect rect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
    int statusBarHeight = rect.top;

    int width = activity.getWindowManager().getDefaultDisplay().getWidth();
    int height = activity.getWindowManager().getDefaultDisplay().getHeight();

    Bitmap bitmap2 = Bitmap.createBitmap(bitmap, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return bitmap2;
}