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

static Rect getViewAbsRect(View view, int parentX, int parentY) {
    int[] loc = new int[2];
    view.getLocationInWindow(loc);//w  w  w .  jav a 2  s .  co  m
    Rect rect = new Rect();
    rect.set(loc[0], loc[1], loc[0] + view.getMeasuredWidth(), loc[1] + view.getMeasuredHeight());
    rect.offset(-parentX, -parentY);
    return rect;
}

From source file:Main.java

public static Rect getTextRect(String text, Paint paint) {
    Rect rect = new Rect();
    if (!TextUtils.isEmpty(text)) {
        paint.getTextBounds(text, 0, text.length(), rect);
    }//from  w w w  . j ava2s  .c o  m
    return rect;
}

From source file:Main.java

public static Rect getAppWrapWidthHeight(Activity activity) {
    Rect appWrapRect = new Rect();
    activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(appWrapRect);
    return appWrapRect;
}

From source file:Main.java

public static int getStatusBarHeight(View v) {
    if (v == null) {
        return 0;
    }//  www .j  a va 2  s  .co  m
    Rect frame = new Rect();
    v.getWindowVisibleDisplayFrame(frame);
    return frame.top;
}

From source file:Main.java

public static boolean isMotionFocusOnView(View view, MotionEvent event) {
    Rect focusBound = new Rect();
    view.getFocusedRect(focusBound);//from  ww w  . j a  v  a 2  s.  com
    return focusBound.contains((int) event.getX(), (int) event.getY());
}

From source file:Main.java

public static int getButtonTextWidth(Button button, String text) {
    Rect bounds = new Rect();
    Paint buttonPaint = button.getPaint();
    buttonPaint.getTextBounds(text, 0, text.length(), bounds);
    return bounds.width();
}

From source file:Main.java

public static int[] sizeActivity(Activity activity) {
    int[] size = new int[2];
    Rect outRect = new Rect();
    activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(outRect);
    size[0] = outRect.width();//  w  w  w.  j  a v  a  2  s  . c o  m
    size[1] = outRect.height();
    return size;
}

From source file:Main.java

public static int getStatusBarHeight(Activity context) {
    int statusHeight = 0;
    Rect frame = new Rect();
    context.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    statusHeight = frame.top;//from  w  w w.j av  a2 s  .  co  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 = context.getResources().getDimensionPixelSize(i5);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return statusHeight;
}

From source file:Main.java

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

From source file:Main.java

private static void setTextSizeForWidth(String text, Paint paint, float desiredWidth) {

    final float testTextSize = 48f;
    paint.setTextSize(testTextSize);//from   w  w w  .  j  a va2  s . co m
    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    float desiredTextSize = testTextSize * desiredWidth / bounds.width();
    paint.setTextSize(desiredTextSize);
}