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 getScreenHeight(Context context) {
    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int height = displaymetrics.heightPixels;
    int width = displaymetrics.widthPixels;

    return height;
}

From source file:Main.java

public static int getScreenMaxHeight(Context paramContext, int paramInt) {
    Object localObject = new DisplayMetrics();
    try {/*from w  w  w  .  j  a  v a 2s  .  c om*/
        DisplayMetrics localDisplayMetrics = paramContext.getApplicationContext().getResources()
                .getDisplayMetrics();
        localObject = localDisplayMetrics;
        return ((DisplayMetrics) localObject).heightPixels - dip2px(paramContext, paramInt);
    } catch (Exception localException) {
        while (true) {
            localException.printStackTrace();
            ((DisplayMetrics) localObject).heightPixels = 960;
        }
    }
}

From source file:Main.java

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

From source file:Main.java

public static DisplayMetrics getDisplayMetrics(Context ctx) {
    DisplayMetrics dm = new DisplayMetrics();
    ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(dm);
    return dm;/*  w w w.ja  v a 2s .c  o  m*/
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
    return localDisplayMetrics.heightPixels - getStatusBarHeight(context);
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static void getDensity(Activity activity) {
    if (DEVICE_DENSITY == 0) {
        DisplayMetrics metrics = new DisplayMetrics();
        float density = metrics.density;

        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        DEVICE_DENSITY = metrics.density;
    }/*from  ww w .ja  v a 2 s .co  m*/
}