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 int getStatusBarHeight(View v) {
    if (v == null) {
        return 0;
    }// w w  w. j  av a 2 s . c  o  m

    Rect frame = new Rect();
    v.getWindowVisibleDisplayFrame(frame);
    return frame.top;
}

From source file:Main.java

/**
 * Check whether is keyboard showing or hiding
 * @param rootView//from   w  ww  . j a  v  a 2s  .c om
 * @return
 */
public static boolean isKeyboardShown(View rootView) {
    Rect rect = new Rect();
    rootView.getWindowVisibleDisplayFrame(rect);
    /* 
     * 128dp = 32dp * 4
     * Minimum button height 32dp and generic 4 rows soft keyboard (can be more than 4 rows)
     */
    final int SOFT_KEYBOARD_HEIGHT_DP_THRESHOLD = 128;
    DisplayMetrics dm = rootView.getResources().getDisplayMetrics();
    return dm.heightPixels - rect.bottom > SOFT_KEYBOARD_HEIGHT_DP_THRESHOLD * dm.density;
}

From source file:Main.java

public static void drawTextCenter(Canvas canvas, RectF rectf, String s, Paint paint) {
    Rect rect = new Rect();
    paint.getTextBounds(s, 0, s.length(), rect);
    canvas.drawText(s, rectf.left + (rectf.width() - (float) rect.width()) / 2.0F,
            rectf.top + (rectf.height() + (float) rect.height()) / 2.0F, paint);
}

From source file:Main.java

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

From source file:Main.java

public static int getStatusBarHeight(Activity activity) {

    if (statusBarHeight > 0) {
        return statusBarHeight;
    }/*from  ww w  .  jav a2s .  co m*/
    Rect rectgle = new Rect();
    Window window = activity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
    statusBarHeight = rectgle.top;
    return statusBarHeight;

}

From source file:Main.java

/**
 * @param context//from  w ww.  j av a2 s. c  om
 * @return
 */
public static int getStatusHeight(Context context) {
    int statusHeight = 0;
    Rect localRect = new Rect();
    ((Activity) context).getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
    statusHeight = localRect.top;
    if (0 == statusHeight) {
        Class<?> localClass;
        try {
            localClass = Class.forName("com.android.internal.R$dimen");
            Object localObject = localClass.newInstance();
            int i5 = Integer.parseInt(localClass.getField("status_bar_height").get(localObject).toString());
            statusHeight = context.getResources().getDimensionPixelSize(i5);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return statusHeight;
}

From source file:Main.java

public static float setTextSizeForWidth(Paint paint, float desiredWidth, String text, float max, float min) {
    final float textSize = 12.0f;

    paint.setTextSize(textSize);//from   w  w w . j av a  2  s. c o  m
    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    float desiredTextSize = textSize * desiredWidth / bounds.width();
    if (desiredTextSize > max) {
        desiredTextSize = max;
    } else if (desiredTextSize < min) {
        desiredTextSize = min;
    }
    paint.setTextSize(desiredTextSize);
    return desiredTextSize;
}

From source file:Main.java

/**
 * calculates the approximate height of a text, depending on a demo text
 * avoid repeated calls (e.g. inside drawing methods)
 *
 * @param paint/*from ww w.  j  av  a  2 s .co m*/
 * @param demoText
 * @return
 */
public static int calcTextHeight(Paint paint, String demoText) {

    Rect r = new Rect();
    paint.getTextBounds(demoText, 0, demoText.length(), r);
    return r.height();
}

From source file:Main.java

public static Bitmap takeScreenShot(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);/*w  w w  . ja v  a 2s . com*/
    view.buildDrawingCache();
    Bitmap b1 = view.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;
    int width = activity.getWindowManager().getDefaultDisplay().getWidth();
    int height = activity.getWindowManager().getDefaultDisplay().getHeight();

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

From source file:Main.java

public static int getStatusBarHeight(Activity activity) {
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    return frame.top;
}