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 paramContext) {
    WindowManager localWindowManager = (WindowManager) paramContext.getSystemService("window");
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    localWindowManager.getDefaultDisplay().getMetrics(localDisplayMetrics);
    return localDisplayMetrics.heightPixels;
}

From source file:Main.java

public static DisplayMetrics getDisplayMetrices(Context context) {
    WindowManager windowManger = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    windowManger.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics;
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    int screenWidth;
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(dm);
    screenWidth = dm.widthPixels;/*from   www .  ja v a 2s.co m*/
    return screenWidth;
}

From source file:Main.java

public static int[] getScreenPixels(Context context) {
    DisplayMetrics displaysMetrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) (context.getSystemService(Context.WINDOW_SERVICE));
    windowManager.getDefaultDisplay().getMetrics(displaysMetrics);
    int[] widthAndHeight = new int[2];
    widthAndHeight[0] = displaysMetrics.widthPixels;
    widthAndHeight[1] = displaysMetrics.heightPixels;
    return widthAndHeight;
}

From source file:Main.java

/**
 * use for getting device width/*from   w w w.  ja  va 2  s .  c  om*/
 *
 * @param mContext
 * @return width of your device
 */
public static int getDeviceWidth(Context mContext) {
    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    return displaymetrics.widthPixels;
}

From source file:Main.java

/**
 * This method is responsible to get width of the screen
 * /*from  w  w  w. jav a2  s .  c o  m*/
 * @param context
 * @return
 */
public static int getWidthOfScreen(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    try {
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return dm.widthPixels;
}

From source file:Main.java

public static int getScreenWidth(Activity context) {
    //        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    //        return wm.getDefaultDisplay().getWidth();

    DisplayMetrics dpMetrics = new DisplayMetrics();
    context.getWindowManager().getDefaultDisplay().getMetrics(dpMetrics);
    return dpMetrics.widthPixels;
}

From source file:Main.java

public static float getDensity(Activity activity) {
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm.density;
}

From source file:Main.java

public static int getWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(outMetrics);

    return outMetrics.widthPixels;
}

From source file:Main.java

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