Example usage for android.view Display getSize

List of usage examples for android.view Display getSize

Introduction

In this page you can find the example usage for android.view Display getSize.

Prototype

public void getSize(Point outSize) 

Source Link

Document

Gets the size of the display, in pixels.

Usage

From source file:com.silentcircle.common.util.ViewUtil.java

/**
 * Returns screen dimensions in passed Point structure
 *//* w  ww  .  ja v a2  s  .c  o m*/
public static void getScreenDimensions(final Context context, final Point size) {
    if (context == null || size == null) {
        return;
    }

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    display.getSize(size);
}

From source file:tv.ouya.sdk.OuyaUnityPlugin.java

private static int getDisplayWidth() {
    Activity activity = IOuyaActivity.GetActivity();
    WindowManager windowManager = activity.getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.x;
}

From source file:tv.ouya.sdk.OuyaUnityPlugin.java

private static int getDisplayHeight() {
    Activity activity = IOuyaActivity.GetActivity();
    WindowManager windowManager = activity.getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size.y;
}

From source file:Main.java

public static Point getSize(Display display) {
    if (Build.VERSION.SDK_INT >= 17) {
        Point outPoint = new Point();
        DisplayMetrics metrics = new DisplayMetrics();
        display.getRealMetrics(metrics);
        outPoint.x = metrics.widthPixels;
        outPoint.y = metrics.heightPixels;
        return outPoint;
    }/* w  w w . ja v a  2s. co m*/
    if (Build.VERSION.SDK_INT >= 14) {
        Point outPoint = getRealSize(display);
        if (outPoint != null)
            return outPoint;
    }
    Point outPoint = new Point();
    if (Build.VERSION.SDK_INT >= 13) {
        display.getSize(outPoint);
    } else {
        outPoint.x = display.getWidth();
        outPoint.y = display.getHeight();
    }
    return outPoint;
}

From source file:com.miz.utils.ViewUtils.java

public static int getNavigationDrawerWidth(Context context) {
    int drawerWidth;

    // The navigation drawer should have a width equal to
    // the screen width minus the Toolbar height - at least
    // on mobile devices. Tablets are accounted for below.
    int toolbarHeight = MizLib.getActionBarHeight(context);

    // Get the display size
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    Point size = new Point();
    display.getSize(size);

    // Get the smallest number
    int smallestDisplayWidth = Math.min(size.x, size.y);

    // Calculate the drawer width
    drawerWidth = smallestDisplayWidth - toolbarHeight;

    // Make sure that the calculated drawer width
    // isn't greater than the max width, i.e.
    // 5 times the standard increment (56dp for
    // mobile or 64dp for tablets).
    int maxWidth = MizLib.convertDpToPixels(context, 5 * (MizLib.isTablet(context) ? 64 : 56));

    if (drawerWidth > maxWidth)
        drawerWidth = maxWidth;/* w  ww  . j  a v  a  2  s  .  co m*/

    return drawerWidth;
}

From source file:org.kontalk.util.SystemUtils.java

@SuppressWarnings("deprecation")
public static Point getDisplaySize(Context context) {
    Point displaySize = null;//from ww  w .j  a  va  2 s.c  o m
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    if (display != null) {
        displaySize = new Point();
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
            displaySize.set(display.getWidth(), display.getHeight());
        } else {
            display.getSize(displaySize);
        }
    }

    return displaySize;
}

From source file:io.github.hidroh.materialistic.AppUtils.java

public static int getDisplayHeight(Context context) {
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        Point point = new Point();
        display.getSize(point);
        return point.y;
    } else {//w  ww .  j  av a 2 s  . c om
        //noinspection deprecation
        return display.getHeight();
    }
}

From source file:com.pdftron.pdf.utils.Utils.java

/**
 * Gets the size of the display, in pixels.
 *
 * @param context the Context/*from   ww  w.j a  va2s .  c  o  m*/
 * @param outSize A Point object to receive the size information
 */
public static void getDisplaySize(Context context, Point outSize) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (outSize == null) {
        outSize = new Point();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(outSize);
    } else {
        outSize.set(display.getWidth(), display.getHeight());
    }
}

From source file:com.sxnyodot.uefqvmio207964.Util.java

static String m965k(Context context) {
    String str = "";
    if (context == null) {
        return str;
    }//from   w w w  .jav a 2  s . c o m
    Display defaultDisplay = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
    if (VERSION.SDK_INT < NETWORK_TYPE_LTE) {
        return "" + defaultDisplay.getWidth() + "_" + defaultDisplay.getHeight();
    }
    Point point = new Point();
    defaultDisplay.getSize(point);
    return point.x + "_" + point.y;
}

From source file:me.kaidul.uhunt.MainActivity.java

@SuppressLint("NewApi")
static int getDeviceWidth(Activity activity) {
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        return size.x;
    } else {//from w w w  .j a  v a 2s .  c om
        Display display = activity.getWindowManager().getDefaultDisplay();
        return display.getWidth();
    }
}