Example usage for android.util DisplayMetrics DisplayMetrics

List of usage examples for android.util DisplayMetrics DisplayMetrics

Introduction

In this page you can find the example usage for android.util DisplayMetrics DisplayMetrics.

Prototype

public DisplayMetrics() 

Source Link

Usage

From source file:Main.java

public static DisplayMetrics getDisplayMetrics(Activity context) {
    DisplayMetrics displayMetrics = null;
    if (displayMetrics == null) {
        displayMetrics = new DisplayMetrics();
    }/* w  ww .j  a  v a2 s  .c  o  m*/
    context.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    return displayMetrics;
}

From source file:Main.java

public static int getScreenWidth(@NonNull Context context) {
    Display display = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);/*from  w  w  w . j  a v  a  2  s  .c o  m*/
    return metrics.widthPixels;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    Display display = wm.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);//from w ww.  j a v a2  s  .com

    return metrics.heightPixels;
}

From source file:Main.java

/**
 * @param context/* w ww. j ava  2 s.com*/
 * @return DisplayMetrics.
 */
public static DisplayMetrics getDisplayMetrics(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    return metrics;
}

From source file:Main.java

public static int getScreeWH(Context context) {

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);/*from  w  w w  .  j av  a2  s  . c  o m*/
    return outMetrics.heightPixels;

}

From source file:Main.java

public static int px2dp(Context context, int px) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    DisplayMetrics displaymetrics = new DisplayMetrics();
    display.getMetrics(displaymetrics);/*ww  w  .jav  a  2 s.  com*/

    return (int) (px / displaymetrics.density + 0.5f);
}

From source file:Main.java

public static int getScreenWidth(Activity context) {
    if (screenWidth == 0 || screenHeight == 0) {
        DisplayMetrics dm = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(dm);
        screenDensity = dm.density;/*  www  .  j  a  v a2 s  .c o m*/
        screenHeight = dm.heightPixels;
        screenWidth = dm.widthPixels;
    }
    return screenWidth;
}

From source file:Main.java

public static int getScreenHeight(Activity context) {
    if (screenWidth == 0 || screenHeight == 0) {
        DisplayMetrics dm = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(dm);
        screenDensity = dm.density;/*from   www  . j a  va2s .  c om*/
        screenHeight = dm.heightPixels;
        screenWidth = dm.widthPixels;
    }
    return screenHeight;
}

From source file:Main.java

public static DisplayMetrics getScreenSizeInPx(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);/* w  ww .j  a  va2  s.c  o  m*/
    return metrics;
}

From source file:Main.java

private static void initScreen(Activity mActivity) {
    DisplayMetrics metric = new DisplayMetrics();
    mActivity.getWindowManager().getDefaultDisplay().getMetrics(metric);
    screenW = metric.widthPixels;//w  ww . j  ava 2  s.  co  m
    screenH = metric.heightPixels;
}