Example usage for android.view WindowManager getDefaultDisplay

List of usage examples for android.view WindowManager getDefaultDisplay

Introduction

In this page you can find the example usage for android.view WindowManager getDefaultDisplay.

Prototype

public Display getDefaultDisplay();

Source Link

Document

Returns the Display upon which this WindowManager instance will create new windows.

Usage

From source file:Main.java

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

From source file:Main.java

public static String getRelation(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager windowMgr = (WindowManager) context.getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE);
    windowMgr.getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    return String.valueOf(width) + "*" + String.valueOf(height);
}

From source file:Main.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static void resizeImageView(Context ctx, ImageView imgView) {
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width;//w w  w.  j av a2 s  . c o m
    // int height;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        width = display.getWidth(); // deprecated
        // height = display.getHeight(); // deprecated
    } else {
        Point size = new Point();
        display.getSize(size);
        width = size.x;
        // height = size.y;
    }

    imgView.setMinimumHeight(width);
    imgView.setMinimumWidth(width);
    imgView.getLayoutParams().height = width;
    imgView.getLayoutParams().width = width;
}

From source file:Main.java

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

From source file:Main.java

public static float pixelsToDp(Context ctx, float px) {
    WindowManager wm = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE));
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    float logicalDensity = metrics.density;
    return (float) Math.ceil(px * logicalDensity);
}

From source file:Main.java

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

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;/*w  w  w.  j a  v  a2s.  c  o m*/
    return screenWidth;
}

From source file:Main.java

public static int getDPI() {
    if (sActivity != null) {
        DisplayMetrics metrics = new DisplayMetrics();
        WindowManager wm = sActivity.getWindowManager();
        if (wm != null) {
            Display d = wm.getDefaultDisplay();
            if (d != null) {
                d.getMetrics(metrics);/*  w  ww.java  2  s .c  om*/
                return (int) (metrics.density * 160.0f);
            }
        }
    }
    return -1;
}

From source file:Main.java

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

From source file:Main.java

public static int getDpi(Activity activity) {
    WindowManager wm = activity.getWindowManager();
    //wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display dp = wm.getDefaultDisplay();
    DisplayMetrics dm = new DisplayMetrics();
    dp.getMetrics(dm);/* ww  w. j a v  a2  s. co  m*/
    return dm.densityDpi;
}