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 float getDevScaledDensity(Activity mactivity) {
    DisplayMetrics metric = new DisplayMetrics();
    mactivity.getWindowManager().getDefaultDisplay().getMetrics(metric);
    float scaledDensity = metric.scaledDensity;
    return scaledDensity;
}

From source file:Main.java

public static int getDevDensityDpi(Activity mactivity) {
    DisplayMetrics metric = new DisplayMetrics();
    mactivity.getWindowManager().getDefaultDisplay().getMetrics(metric);
    int densityDpi = metric.densityDpi;
    return densityDpi;
}

From source file:Main.java

public static int GET_SCREEN_WIDTH(Activity a) {
    int screenWidth = 0;
    DisplayMetrics dm = new DisplayMetrics();

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

    screenWidth = dm.widthPixels;/*from  w ww.  j ava  2  s.c o m*/

    return screenWidth;
}

From source file:Main.java

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

From source file:Main.java

public static int getWidth(Activity activity) {
    if (dm == null) {
        dm = new DisplayMetrics();
    }//from w w  w .  j ava 2  s  .c om
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm.widthPixels;
}

From source file:Main.java

@SuppressWarnings("deprecation")
private static Point getDefaultDisplaySize(Activity activity, Point size) {
    Display d = activity.getWindowManager().getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        d.getSize(size);// w  w w. j  av a2 s.  c  o m
    } else {
        size.set(d.getWidth(), d.getHeight());
    }
    return size;
}

From source file:Main.java

/**
 * get screen height//from  ww w . j a v a  2 s. co m
 *
 * @param activity activity
 * @return screen height
 */
public static int getHeightPixels(Activity activity) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    return displayMetrics.heightPixels;
}

From source file:Main.java

/**
 * get screen width/*w ww. j ava  2  s  . c  o m*/
 *
 * @param activity activity
 * @return screen width
 */
public static int getWidthPixels(Activity activity) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    return displayMetrics.widthPixels;
}

From source file:Main.java

private static DisplayMetrics getDisplayMetrics(Activity activity) {
    DisplayMetrics metrics = new DisplayMetrics();
    Display display = activity.getWindowManager().getDefaultDisplay();
    display.getMetrics(metrics);//from  w  w w .  jav  a2s . c  om
    return metrics;
}

From source file:Main.java

public static float getScreenWidth(Activity activity) {
    if (mScreenWidth == 0) {
        Point size = new Point();
        activity.getWindowManager().getDefaultDisplay().getSize(size);
        mScreenWidth = size.x;/* ww  w . j a  v  a 2s. co  m*/
        Log.d(TAG, "screen size is " + size);
    }
    return mScreenWidth;
}