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

/**
 * get Screen Width/*from  w  w  w .  j a va2s  .c  o m*/
 *
 * @param context
 * @return
 */
public static int getScreenWidth(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm.widthPixels;
}

From source file:Main.java

public static <T extends Fragment> int getScreenWidth(T t) {
    DisplayMetrics metrics;/*from  w ww  .ja va2s. c  o m*/

    t.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics = new DisplayMetrics());

    return metrics.widthPixels;
}

From source file:Main.java

public static int getScreenWidth(Activity ctx) {
    Display display = ctx.getWindowManager().getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);//from w  w w.ja v  a 2s  .c o  m

    float density = ctx.getResources().getDisplayMetrics().density;
    return Math.round(outMetrics.widthPixels);

}

From source file:Main.java

public static int[] getPhone(Context context) {
    int[] xy = new int[2];
    DisplayMetrics dm = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
    xy[0] = dm.widthPixels;/*from w  w w.  ja  v a 2s .  c o  m*/
    xy[1] = dm.heightPixels;
    return xy;
}

From source file:Main.java

public static DisplayMetrics getScreenDisplayMetrics(Context context) {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
    return localDisplayMetrics;
}

From source file:Main.java

public static double getScreenSize(Activity activity) {
    if (dm == null) {
        dm = new DisplayMetrics();
    }//  ww w .  j a v  a2 s  . co  m
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    double x = Math.pow(dm.widthPixels / dm.densityDpi, 2);
    double y = Math.pow(dm.heightPixels / dm.densityDpi, 2);
    return Math.sqrt(x + y);
}

From source file:Main.java

public static int getMetricsDensity(Context context, float height) {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
            .getMetrics(localDisplayMetrics);
    return Math.round(height * localDisplayMetrics.densityDpi / 160.0F);
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    if (null == context) {
        return 0;
    }/*ww  w . j  ava 2 s .c  o m*/
    DisplayMetrics dm = new DisplayMetrics();
    dm = context.getApplicationContext().getResources().getDisplayMetrics();
    return dm.widthPixels;
}

From source file:Main.java

public static int getScreenHeight(Activity activity) {

    Display display = activity.getWindowManager().getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);//from w ww  . j ava  2s  .c  om

    return outMetrics.heightPixels;
}

From source file:Main.java

public static int[] getScreenSize(Activity activity) {
    int[] screens;
    // if (Constants.screenWidth > 0) {
    // return screens;
    // }/*  w w w  . ja  v  a 2s  .com*/
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    screens = new int[] { dm.widthPixels, dm.heightPixels };
    return screens;
}