Example usage for android.content Context WINDOW_SERVICE

List of usage examples for android.content Context WINDOW_SERVICE

Introduction

In this page you can find the example usage for android.content Context WINDOW_SERVICE.

Prototype

String WINDOW_SERVICE

To view the source code for android.content Context WINDOW_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.view.WindowManager for accessing the system's window manager.

Usage

From source file:Main.java

public static Point getScreenSize(Context context) {
    WindowManager window = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = window.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);//from   www  . ja v a  2  s  .  c om
    return size;
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
// Whole Screen includes StatusBar and ActionBar
public static int getHeight(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  .  ja  v  a 2  s.  c  o m
        return size.y;
    } else
        return display.getHeight();
}

From source file:Main.java

public static Bitmap createBitmap(Context context, ScrollView v) {
    int width = 0, height = 0;
    for (int i = 0; i < v.getChildCount(); i++) {
        width += v.getChildAt(i).getWidth();
        height += v.getChildAt(i).getHeight();
    }/*w  ww  .  j  ava  2 s .com*/
    if (width <= 0 || height <= 0) {
        return null;
    }
    int h = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight();
    if (height < h)
        height = h;
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);
    return bitmap;
}

From source file:Main.java

public static void initialize(Context context) {
    sDecelerateQuintInterpolator = AnimationUtils.loadInterpolator(context, interpolator.decelerate_quint);

    final Point size = new Point();
    ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getSize(size);
    final int screenHeight = size.y;

    if (screenHeight >= ANIMATION_LONG_SCREEN_SIZE) {
        sAnimationDuration = ANIMATION_LONG_DURATION;
    } else if (screenHeight >= ANIMATION_MED_SCREEN_SIZE) {
        sAnimationDuration = ANIMATION_MED_DURATION;
    } else {//from w  ww.  j  a  v  a 2s  .c om
        sAnimationDuration = ANIMATION_SHORT_DURATION;
    }
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static int getScreenRealH(Context context) {
    int h;/*from   w  ww .  j  a v a2 s . c o m*/
    WindowManager winMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = winMgr.getDefaultDisplay();
    DisplayMetrics dm = new DisplayMetrics();
    if (Build.VERSION.SDK_INT >= 17) {
        display.getRealMetrics(dm);
        h = dm.heightPixels;
    } else {
        try {
            Method method = Class.forName("android.view.Display").getMethod("getRealMetrics",
                    DisplayMetrics.class);
            method.invoke(display, dm);
            h = dm.heightPixels;
        } catch (Exception e) {
            display.getMetrics(dm);
            h = dm.heightPixels;
        }
    }
    return h;
}

From source file:Main.java

/**
 * @param ctx/*from w  w w  .  j a v a2  s  . c  o  m*/
 */
public static float getDensity(Context ctx) {
    if (mMetrics == null) {
        mMetrics = new DisplayMetrics();
        ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(mMetrics);
    }
    return mMetrics.density;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static int getSoftKeyBarHeight(Context context) {
    // getRealMetrics is only available with API 17 and +
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics metrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(metrics);
        int usableHeight = metrics.heightPixels;
        wm.getDefaultDisplay().getRealMetrics(metrics);
        int realHeight = metrics.heightPixels;
        if (realHeight > usableHeight) {
            return realHeight - usableHeight;
        } else {//from   w ww .j a  v  a  2  s  . c  o  m
            return 0;
        }
    }
    return 0;
}

From source file:Main.java

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

From source file:Main.java

public static int getRotation(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    return display.getRotation();
}

From source file:Main.java

public static Point getScreenDimensions(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point dimensions = new Point();
    display.getSize(dimensions);/*w  w w  .  j  a  v  a  2s.co  m*/
    return dimensions;
}