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(Context pContext) {

    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) pContext).getWindowManager().getDefaultDisplay().getMetrics(metrics);
    return metrics;
}

From source file:Main.java

public static DisplayMetrics getScreenWidth(Context mContext) {
    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    return displaymetrics;
}

From source file:Main.java

public static float dip2px2(Activity context, float dipValue) {
    DisplayMetrics dm = new DisplayMetrics();
    context.getWindowManager().getDefaultDisplay().getMetrics(dm);
    final float screen = (float) dm.widthPixels / (float) 240;
    return screen;
}

From source file:Main.java

public static int getDisplayWidth(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 DisplayMetrics getWindowsDisplayMetrics(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm;//from  w w w  . j  av a2  s.  c om
}

From source file:Main.java

public static int getScreenWidth(Context paramContext) {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((Activity) paramContext).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
    return localDisplayMetrics.widthPixels;
}

From source file:Main.java

public static int getDisplayHeight(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(Activity activity) {
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    int result = 0;
    int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = activity.getResources().getDimensionPixelSize(resourceId);
    }//w  ww  .jav a  2s.  c o  m
    int screenHeight = dm.heightPixels - result;
    return screenHeight;
}

From source file:Main.java

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

From source file:Main.java

private static int getDensityOfDevice(Context densityOfDeviceContext) {
    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) densityOfDeviceContext).getWindowManager().getDefaultDisplay().getMetrics(metrics);
    return metrics.densityDpi;
}