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 int[] getScreenSize(Context context) {
    int[] size = new int[2];
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    manager.getDefaultDisplay().getMetrics(dm);
    size[0] = dm.widthPixels;/*from w ww  .  j  a va  2s.co  m*/
    size[1] = dm.heightPixels;
    return size;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    return dm.heightPixels;
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    return dm.widthPixels;

}

From source file:Main.java

public static int getScreenMaxWidth(Context context, int paramInt) {
    Object localObject = new DisplayMetrics();
    try {//from   w  w  w  .  j  a  v a 2s  .  c  o m
        DisplayMetrics localDisplayMetrics = context.getApplicationContext().getResources().getDisplayMetrics();
        localObject = localDisplayMetrics;
        return ((DisplayMetrics) localObject).widthPixels - dip2px(context, paramInt);
    } catch (Exception localException) {
        while (true) {
            localException.printStackTrace();
            ((DisplayMetrics) localObject).widthPixels = 640;
        }
    }
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    DisplayMetrics metric = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metric);
    return metric.widthPixels;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    DisplayMetrics metric = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metric);
    return metric.heightPixels;
}

From source file:Main.java

public static int[] getScreenHeightAndWidth(Activity activity) {
    int[] result = new int[2];

    try {/*from  ww w .ja  v  a  2s .  com*/
        DisplayMetrics displayMetrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        result[0] = displayMetrics.widthPixels;
        result[1] = displayMetrics.heightPixels;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    if (SCREEN_HEIGHT == 0) {
        DisplayMetrics dm = new DisplayMetrics();
        dm = context.getResources().getDisplayMetrics();
        SCREEN_HEIGHT = dm.heightPixels;
    }/*from w  ww .  j  ava 2 s . co m*/
    return SCREEN_HEIGHT;
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int height = displaymetrics.heightPixels;
    int width = displaymetrics.widthPixels;

    return width;
}

From source file:Main.java

public static float getDensity(Context context) {
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE));
    wm.getDefaultDisplay().getMetrics(metrics);

    return metrics.density;
}