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 getScreenHeight(Activity activity) {
    if (mScreenHeight == 0) {
        DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        mScreenHeight = dm.heightPixels;
    }//from w w w  . java2 s  . c  o m
    return mScreenHeight;
}

From source file:Main.java

public static Point getScreenResolution(Activity activity) {
    // get the layout width/height
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    // create point
    Point p = new Point();
    p.set(dm.widthPixels, dm.heightPixels);

    return p;/*from w  ww .  j  ava 2  s  .  c  o m*/
}

From source file:Main.java

public static int getCameraDisplayOrientation(@NonNull Activity activity, @NonNull CameraInfo info) {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    DisplayMetrics dm = new DisplayMetrics();

    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;//w  w  w  .  j av a2  s. co m
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        return (360 - ((info.orientation + degrees) % 360)) % 360;
    } else {
        return (info.orientation - degrees + 360) % 360;
    }
}

From source file:Main.java

public static int getHeight(Activity activity) {
    if (mScreenHeight == 0) {
        DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        mScreenHeight = dm.heightPixels;
    }//from w  ww  . ja v  a2s  .  c om
    return mScreenHeight - getActionBarHeight(activity);
}

From source file:Main.java

public static int getWindowWidth(Activity activity) {
    if (mWidthPixels < 0) {
        DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        mWidthPixels = dm.widthPixels;/* ww  w.j  av a 2  s  . c  o  m*/
        mHeightPixels = dm.heightPixels;
    }
    return mWidthPixels;
}

From source file:Main.java

private static DisplayMetrics getDisplayMetrics(final Activity activity) {
    final DisplayMetrics metrics = new DisplayMetrics();
    final Display display = activity.getWindowManager().getDefaultDisplay();
    display.getMetrics(metrics);// w  w  w .ja v  a 2s . co m
    return metrics;
}

From source file:Main.java

public static int[] getDeviceResolution(Activity activity) {
    int[] args = new int[2];
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    args[0] = dm.widthPixels;//from w w  w  . j a v  a  2 s.com
    args[1] = dm.heightPixels;
    return args;
}

From source file:Main.java

public static DisplayMetrics getScreenSize(Activity activity) {
    DisplayMetrics result = null;// ww  w .j  ava2s  .  c om
    try {
        result = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(result);
    } catch (Exception e) {
    }
    return result;
}

From source file:Main.java

public static float calculatorRatioScreen(Activity activity, boolean portrait) {
    DisplayMetrics disp = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(disp);
    int screenWidth, screenHeight;
    screenWidth = disp.widthPixels;/*w ww .  ja  va 2  s .c o  m*/
    screenHeight = disp.heightPixels;
    Log.d("", "ratio screenWidth " + screenWidth + " screenHeight " + screenHeight);
    int defaultWidth = 480;
    int defaultHeight = 320;
    if (portrait) {
        defaultWidth = DEFAULT_SCREEN_WIDTH_PORTRAIT;
        defaultHeight = DEFAULT_SCREEN_HEIGHT_PORTRAIT;
    } else {
        defaultWidth = DEFAULT_SCREEN_WIDTH_LANSCAPE;
        defaultHeight = DEFAULT_SCREEN_HEIGHT_LANSCAPE;
    }
    float ratioByWidth = (float) screenWidth / defaultWidth;
    float ratioByHeight = (float) screenHeight / defaultHeight;
    float ratioReturn = Math.min(ratioByWidth, ratioByHeight);
    // isAlReady = true;
    return ratioReturn;
}

From source file:Main.java

@TargetApi(4)
public static boolean isTabletDevice(android.content.Context activityContext) {
    // Verifies if the Generalized Size of the device is XLARGE to be
    // considered a Tablet
    boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= //Changed this from == to >= because my tablet was returning 8 instead of 4.
    Configuration.SCREENLAYOUT_SIZE_LARGE);

    // If XLarge, checks if the Generalized Density is at least MDPI (160dpi)
    if (xlarge) {
        android.util.DisplayMetrics metrics = new android.util.DisplayMetrics();
        Activity activity = (Activity) activityContext;
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        //This next block lets us get constants that are not available in lower APIs.
        // If they aren't available, it's safe to assume that the device is not a tablet.
        // If you have a tablet or TV running Android 1.5, what the fuck is wrong with you.
        int xhigh = -1, tv = -1;
        try {/*from   w w  w . j ava  2s  .c  om*/
            Field f = android.util.DisplayMetrics.class.getDeclaredField("DENSITY_XHIGH");
            xhigh = (Integer) f.get(null);
            f = android.util.DisplayMetrics.class.getDeclaredField("DENSITY_TV");
            xhigh = (Integer) f.get(null);
        } catch (Exception e) {
        }

        // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160, DENSITY_TV=213, DENSITY_XHIGH=320
        if (metrics.densityDpi == android.util.DisplayMetrics.DENSITY_DEFAULT
                || metrics.densityDpi == android.util.DisplayMetrics.DENSITY_HIGH
                || metrics.densityDpi == android.util.DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == tv
                || metrics.densityDpi == xhigh) {
            return true;
        }
    }
    return false;
}