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 float pixelsToDp(Context ctx, float px) {
    WindowManager wm = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE));
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    float logicalDensity = metrics.density;
    return (float) Math.ceil(px * logicalDensity);
}

From source file:Main.java

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

From source file:Main.java

public static float getScreenHight(Context context) {
    windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return windowManager.getDefaultDisplay().getHeight();
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getDeviceWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return manager.getDefaultDisplay().getWidth();
}

From source file:Main.java

public static int getWindowWidth(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

public static float getScreenWeigh(Context context) {
    windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return windowManager.getDefaultDisplay().getWidth();
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getDeviceHeight(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return manager.getDefaultDisplay().getHeight();
}