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 getScreenHight(Activity activity) {
    WindowManager manager = activity.getWindowManager();
    DisplayMetrics outMetrics = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(outMetrics);
    int height = outMetrics.heightPixels;
    //int width2 = outMetrics.widthPixels;
    return height;
}

From source file:Main.java

public static float getDPI() {
    if (sContext != null) {
        DisplayMetrics metrics = new DisplayMetrics();
        WindowManager wm = ((Activity) sContext).getWindowManager();
        if (wm != null) {
            Display d = wm.getDefaultDisplay();
            if (d != null) {
                d.getMetrics(metrics);/* w w  w .j  a va2 s. c om*/
                return (metrics.density * 160.0f);
            }
        }
    }
    return -1.0f;
}

From source file:Main.java

public static Bitmap decodeSampledBitmapByPath(Context context, String path) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(displayMetrics);
    final int height = displayMetrics.heightPixels;
    final int width = displayMetrics.widthPixels;

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;//  ww  w .  j a  v a2 s.c om
    BitmapFactory.decodeFile(path, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, width, height);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(path, options);
}

From source file:Main.java

@SuppressWarnings("deprecation")
/**//from   w  w w  .j  a va2s.c  o  m
 * Returns the screen/display size
 *
 * @param ctx
 * @return
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    return new Point(width, height);
}

From source file:Main.java

public static DisplayMetrics getScreenSize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(dm);
    return dm;/*w ww  . j a  v a  2  s.c om*/
}

From source file:Main.java

public static Display getScreenDisplay(Context context) {
    WindowManager wm;
    try {/*  ww w.j a  v a  2  s  . c om*/
        wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        return wm.getDefaultDisplay();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static DisplayMetrics getScreenMetrics(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(dm);
    return dm;/* ww w . j  av a  2  s  . co  m*/
}

From source file:Main.java

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

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static int getWidth(Context context) {

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        Point size = new Point();
        display.getSize(size);//from   w w  w  . j a v  a 2s  .  co  m
        return size.x;
    } else
        return display.getWidth();
}

From source file:Main.java

public static DisplayMetrics getScreenInfo(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(dm);
    return dm;//w  w w . j  av  a 2s .  c  o  m
}