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(Context context) {
    Rect clientRect = new Rect();
    if (context instanceof Activity) {
        ((Activity) context).getWindow().getDecorView().getWindowVisibleDisplayFrame(clientRect);
        return clientRect.top;
    }/*from w w w. j a  va 2 s.c o  m*/

    return 0;
}

From source file:Main.java

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

From source file:Main.java

public static Rect getAppMatchWidthHeight(Activity activity) {
    Rect appMatchRect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(appMatchRect);
    return appMatchRect;
}

From source file:Main.java

public static Rect getTextBounds(float textSize, String text) {
    Rect bounds = new Rect();
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(textSize);/*from w ww  .  j  a va 2  s . c  o  m*/

    paint.getTextBounds(text, 0, text.length(), bounds);

    bounds.height();
    return bounds;
}

From source file:Main.java

public static int getStatusBarHeight(Context context) {
    Rect rectgle = new Rect();
    Window window = ((Activity) context).getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
    return rectgle.top;
}

From source file:Main.java

public static void drawText(String text, float x, float y, Canvas canvas, Paint paint) {
    Rect rect = new Rect();
    paint.getTextBounds(text, 0, 1, rect);
    float halfW = paint.measureText(text) / 2;
    canvas.drawText(text, x - halfW, y + halfW, paint);
}

From source file:Main.java

public static Rect getTextRect(String text, float size) {
    Paint pFont = new Paint();
    pFont.setTextSize(size);//from  w  w  w  .ja  va 2 s.c om
    Rect rect = new Rect();
    pFont.getTextBounds(text, 0, text.length(), rect);
    return rect;
}

From source file:Main.java

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

From source file:Main.java

public static int getStatusHeight(Activity activity) {
    int statusHeight = 0;
    Rect localRect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
    statusHeight = localRect.top;// ww  w .  j  a  v  a 2 s. c o  m
    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 = activity.getResources().getDimensionPixelSize(i5);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
    return statusHeight;
}

From source file:Main.java

public static int getTitleBarHeight(Activity activity) {
    Rect rect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
    int sbh = rect.top;
    int contentTop = activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
    int titleBarTop = contentTop - sbh;
    return titleBarTop;
}