Example usage for android.graphics Point Point

List of usage examples for android.graphics Point Point

Introduction

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

Prototype

public Point() 

Source Link

Usage

From source file:Main.java

private static Point getScreenSizeInternal(final Context context) {
    Point size = null;//w w w. j a  va 2s  .c o  m
    final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    if (windowManager != null) {
        final Display display = windowManager.getDefaultDisplay();
        if (display != null) {
            // only works if Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2
            size = new Point();
            display.getSize(size);
        }
    }
    return size;
}

From source file:Main.java

public static int[] getScreenSize(Context context) {

    int[] size = new int[2];

    WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display d = w.getDefaultDisplay();//ww w .jav  a 2  s.co  m
    DisplayMetrics metrics = new DisplayMetrics();
    d.getMetrics(metrics);
    // since SDK_INT = 1;
    int widthPixels = metrics.widthPixels;
    int heightPixels = metrics.heightPixels;
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17)
        try {
            widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d);
            heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
        } catch (Exception ignored) {
        }
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 17)
        try {
            Point realSize = new Point();
            Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize);
            widthPixels = realSize.x;
            heightPixels = realSize.y;
        } catch (Exception ignored) {
        }
    size[0] = widthPixels;
    size[1] = heightPixels;
    return size;
}

From source file:Main.java

public static int[] getRealScreenSize(Activity activity) {
    int[] size = new int[2];
    int screenWidth = 0, screenHeight = 0;
    WindowManager w = activity.getWindowManager();
    Display d = w.getDefaultDisplay();/*ww w . jav  a2  s  .c  om*/
    DisplayMetrics metrics = new DisplayMetrics();
    d.getMetrics(metrics);
    // since SDK_INT = 1;
    screenWidth = metrics.widthPixels;
    screenHeight = metrics.heightPixels;
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17)
        try {
            screenWidth = (Integer) Display.class.getMethod("getRawWidth").invoke(d);
            screenHeight = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
        } catch (Exception ignored) {
        }
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 17)
        try {
            Point realSize = new Point();
            Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize);
            screenWidth = realSize.x;
            screenHeight = realSize.y;
        } catch (Exception ignored) {
        }
    size[0] = screenWidth;
    size[1] = screenHeight;
    return size;
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
// Whole Screen includes StatusBar and ActionBar
public static int getHeight(Context context) {

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        Point size = new Point();
        display.getSize(size);/*from   w  w  w  . j  a  v a  2s. c o  m*/
        return size.y;
    } else
        return display.getHeight();
}

From source file:Main.java

/**
 * Gets the screen size in pixels in a backwards compatible way
 *
 * @param caller        Activity calling; needed to get access to the {@link android.view.WindowManager}
 * @return              Size in pixels of the screen, or default {@link Point} if caller is null
 *//*from  w w w .j  a  va  2 s . com*/
public static Point getScreenSize(Activity caller) {
    Point size = new Point();
    if (caller != null) {
        Display display = caller.getWindowManager().getDefaultDisplay();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
            display.getSize(size);
        } else {
            size.set(display.getWidth(), display.getHeight());
        }
    }
    return size;
}

From source file:Main.java

/**
 * Determining the smallest size of the screen to detect "real small devices",
 * the dpi modifier is not reliable on Samsung devices
 *
 * @param activity - current activity/*from w w  w . j  a  va2 s . c  o  m*/
 * @return the size of the smallest edge of default display in pixels
 */
private static int getSmallestScreenSize(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);
    return Math.min(point.x, point.y);
}

From source file:Main.java

public static Point getScreenDimensions(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point dimensions = new Point();
    display.getSize(dimensions);/*  w  ww.j av a 2s.com*/
    return dimensions;
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);/* w w  w.j a va 2 s .c o  m*/
    return size.x;
}

From source file:Main.java

public static Point libgdxToScreenCoordinates(Context context, float x, float y) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);//from   ww w  .jav a2 s.c o  m
    //      Log.d(CucumberInstrumentation.TAG, String.format("center: [%d/%d]", size.x / 2, size.y / 2));
    Point point = new Point();
    point.x = Math.round((size.x / 2f) + x);
    point.y = Math.round((size.y / 2f) + y);
    //      Log.d(CucumberInstrumentation.TAG, String.format("coords: [%d/%d]", point.x, point.y));
    return point;
}

From source file:Main.java

public static int[] getScreenSize(Context context, boolean useDeviceSize) {

    int[] size = new int[2];

    WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display d = w.getDefaultDisplay();/* w  ww.j a  v a2 s.c o m*/
    DisplayMetrics metrics = new DisplayMetrics();
    d.getMetrics(metrics);
    // since SDK_INT = 1;
    int widthPixels = metrics.widthPixels;
    int heightPixels = metrics.heightPixels;

    if (!useDeviceSize) {
        size[0] = widthPixels;
        size[1] = heightPixels;
        return size;
    }

    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17)
        try {
            widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d);
            heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
        } catch (Exception ignored) {
        }
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 17)
        try {
            Point realSize = new Point();
            Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize);
            widthPixels = realSize.x;
            heightPixels = realSize.y;
        } catch (Exception ignored) {
        }
    size[0] = widthPixels;
    size[1] = heightPixels;
    return size;
}