Example usage for android.app Activity getWindowManager

List of usage examples for android.app Activity getWindowManager

Introduction

In this page you can find the example usage for android.app Activity getWindowManager.

Prototype

public WindowManager getWindowManager() 

Source Link

Document

Retrieve the window manager for showing custom windows.

Usage

From source file:Main.java

public static int calculateInSampleSize(Activity context, int outWidth, int outHeight) {
    int screenWidth = context.getWindowManager().getDefaultDisplay().getWidth();
    int screenHeight = context.getWindowManager().getDefaultDisplay().getHeight();
    int be;/*from  w ww .  ja  va2  s  .c  o  m*/
    if (outWidth > screenWidth || outHeight > 1.5 * screenHeight) {
        int heightRatio = Math.round(((float) outHeight) / ((float) 1.5 * screenHeight));
        int widthRatio = Math.round(((float) outWidth) / ((float) screenWidth));
        int sample = heightRatio > widthRatio ? heightRatio : widthRatio;
        if (sample < 3)
            be = sample;
        else if (sample < 6.5)
            be = 4;
        else if (sample < 8)
            be = 8;
        else
            be = sample;
    } else {
        be = 1;
    }
    if (be <= 0) {
        be = 1;
    }
    return be;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getScreenWidth(Activity activity) {
    int Measuredwidth = 0;
    Point size = new Point();
    WindowManager wm = activity.getWindowManager();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        wm.getDefaultDisplay().getSize(size);
        Measuredwidth = size.x;/* w ww  . ja v a 2  s.  c o  m*/
    } else {
        Display d = wm.getDefaultDisplay();
        Measuredwidth = d.getWidth();
    }

    return Measuredwidth;
}

From source file:Main.java

/**
 * Determine the rotation to apply for the preview for a given camera
 * @param mirror whether to account for profile camera mirroring or not
 *///  w  ww . jav a2 s  .com
public static int getRotationDegrees(Activity activity, int cameraId, boolean mirror) {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;

    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);

    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {

        degrees = (info.orientation + degrees) % 360;
        // compensate for mirrored image, useful for previews on front facing cameras
        if (mirror) {
            degrees = (360 - degrees) % 360;
        }
    } else {
        degrees = (info.orientation - degrees + 360) % 360;
    }

    return degrees;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getScreenHeight(Activity activity) {
    int Measuredheight = 0;
    Point size = new Point();
    WindowManager wm = activity.getWindowManager();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        wm.getDefaultDisplay().getSize(size);
        Measuredheight = size.y;/*from www.  j  ava 2 s.  com*/
    } else {
        Display d = wm.getDefaultDisplay();
        Measuredheight = d.getWidth();
    }

    return Measuredheight;
}

From source file:Main.java

public static JsonObject getCustomClientData(final Activity activity) {
    JsonObject data = new JsonObject();

    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);//  w  ww . j  a va 2 s .com
    int screenWidth = size.x;
    int screenHeight = size.y;

    data.add("ScreenWidth", new JsonPrimitive(screenWidth));
    data.add("ScreenHeight", new JsonPrimitive(screenHeight));

    JsonObject locale = new JsonObject();
    try {
        locale.add("Default", new JsonPrimitive(Locale.getDefault().toString()));
        locale.add("DefaultDisplayLanguage", new JsonPrimitive(Locale.getDefault().getDisplayLanguage()));
        locale.add("DefaultDisplayCountry", new JsonPrimitive(Locale.getDefault().getDisplayCountry()));
        locale.add("DefaultDisplayName", new JsonPrimitive(Locale.getDefault().getDisplayName()));
    } catch (Exception exc) {
    }

    data.add("locale", locale);

    return data;
}

From source file:Main.java

public static void initDiplaySize(Activity context) {
    if (screenWidth > 0 && screenHeight > 0)
        return;//from   w  ww  . jav a2s .c  om

    Display dis = context.getWindowManager().getDefaultDisplay();
    Point outSize = new Point(0, 0);
    dis.getSize(outSize);
    if (outSize != null) {
        screenWidth = outSize.x;
        screenHeight = outSize.y;
    }
}

From source file:Main.java

/**
 * Get current {@link Activity} screen width.
 * /*from   w ww  .  j  a v  a2  s.  c  o  m*/
 * @param activity Object of {@link Activity}
 * @return Screen width, failed will return 0.
 */
public final static int getScreenWidth(Activity activity) {
    if (null == activity) {
        return 0;
    }

    try {
        Display d = activity.getWindowManager().getDefaultDisplay();
        return d.getWidth();
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

/**
 * Get current {@link Activity} screen height.
 * //from w w w.j  a v a  2s.  c om
 * @param activity Object of {@link Activity}
 * @return Screen height, failed will return 0.
 */
public final static int getScreenHeight(Activity activity) {
    if (null == activity) {
        return 0;
    }

    try {
        Display d = activity.getWindowManager().getDefaultDisplay();
        return d.getHeight();
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

public static int getScreenHeightPixels(Activity activity) {
    if (activity == null) {
        return 0;
    }//w  w w.j a va2s. c o  m
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm.heightPixels;
}

From source file:Main.java

public static int getScreenWidthPixels(Activity activity) {
    if (activity == null) {
        return 0;
    }/*from www  .  j a  v  a  2  s .  co  m*/

    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm.widthPixels;
}