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 void getScreenMetric(Context cxt) {
    WindowManager wm = (WindowManager) cxt.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);/*from   w  w  w . ja v a 2 s.co  m*/
    mScreenWidth = size.x;
    mScreenHeight = size.y;
}

From source file:Main.java

public static JsonObject getCustomClientData(final Activity activity) {
    JsonObject data = new JsonObject();

    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);// w  w w .ja v  a  2 s. c om
    int screenWidth = size.x;
    int screenHeight = size.y;

    data.add("ScreenWidth", new JsonPrimitive(screenWidth));
    data.add("ScreenHeight", new JsonPrimitive(screenHeight));

    JsonObject locale = new JsonObject();
    try {
        locale.add("Default", new JsonPrimitive(Locale.getDefault().toString()));
        locale.add("DefaultDisplayLanguage", new JsonPrimitive(Locale.getDefault().getDisplayLanguage()));
        locale.add("DefaultDisplayCountry", new JsonPrimitive(Locale.getDefault().getDisplayCountry()));
        locale.add("DefaultDisplayName", new JsonPrimitive(Locale.getDefault().getDisplayName()));
    } catch (Exception exc) {
    }

    data.add("locale", locale);

    return data;
}

From source file:Main.java

public static int getWindowWidth(Context context) {
    if (screenSize == null) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        screenSize = new Point();
        display.getSize(screenSize);//w  w  w  .  j  a  v a2  s  .  c  o m
    }
    if (screenSize != null)
        return screenSize.x;
    else
        return 0;
}

From source file:Main.java

public static int getWindowHeight(Context context) {
    if (screenSize == null) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        screenSize = new Point();
        display.getSize(screenSize);/* w ww .j  av a 2  s . c  o  m*/
    }
    if (screenSize != null)
        return screenSize.y;
    else
        return 0;
}

From source file:Main.java

/**
 * Gets screen width./*ww w .ja va2  s . c  o  m*/
 *
 * @param context the context
 * @return the screen width in pixels
 */
public static int getScreenWidth(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.x;
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static Point getScreenSize(Context mContext) {
    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);/*from   w  ww.  j  a va  2s  . c o  m*/
        return size;
    } else {
        size.x = display.getWidth();
        size.y = display.getHeight();
        return size;
    }
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static Point getFullDisplaySize(Context context) {
    Point point = new Point();

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    Display display = wm.getDefaultDisplay();
    Method mGetRawH = null, mGetRawW = null;

    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);//from  ww w.  jav a 2s  .  co  m

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        display.getRealMetrics(outMetrics);
        point.x = outMetrics.widthPixels;
        point.y = outMetrics.heightPixels;
    } else {
        try {
            mGetRawH = Display.class.getMethod("getRawHeight");
            mGetRawW = Display.class.getMethod("getRawWidth");
            point.x = (Integer) mGetRawW.invoke(display);
            point.y = (Integer) mGetRawH.invoke(display);
        } catch (Exception e) {
            display.getMetrics(outMetrics);
            point.x = display.getWidth();
            point.y = display.getHeight();
            e.printStackTrace();
        }
    }

    return point;
}

From source file:Main.java

/**
 * Get a value by percentage of the Screen.
 *
 * @param activity - Current Activity/*from w  ww.  j a v a 2s .com*/
 * @param value    - The percentage
 * @return - A value represent the percentage
 */
public static int getYPercentageFromScreen(Activity activity, float value) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return (int) (size.y * value) / 100;
}

From source file:Main.java

/**
 * Getter for the screen width in pixels.
 *
 * @param context a reference to the context.
 * @return the screen width in pixels./* www  .j  a  v a  2s .  com*/
 */
public static int getScreenWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.x;
}

From source file:Main.java

/**
 * <p>/*from  ww w  .j ava 2 s  .  co  m*/
 * This method takes in the WindowManager and returns the Screen Dimensions in pixels.</br></br>
 * </p>
 * <p>To get width (getWindowDisplaySize(wm).x) or height (getWindowDisplaySize(wm).y)</p>
 *
 * @return WindowDisplaySize
 */
public static Point getWindowDisplaySize(WindowManager wm) {
    Display display;
    Point WindowDisplaySize = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        display = wm.getDefaultDisplay();
        display.getSize(WindowDisplaySize);
    } else {
        DisplayMetrics displaymetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(displaymetrics);
        int height = displaymetrics.heightPixels;
        int width = displaymetrics.widthPixels;
        WindowDisplaySize.set(width, height);
    }
    return WindowDisplaySize;
}