Example usage for android.view WindowManager getDefaultDisplay

List of usage examples for android.view WindowManager getDefaultDisplay

Introduction

In this page you can find the example usage for android.view WindowManager getDefaultDisplay.

Prototype

public Display getDefaultDisplay();

Source Link

Document

Returns the Display upon which this WindowManager instance will create new windows.

Usage

From source file:com.dm.material.dashboard.candybar.helpers.ViewHelper.java

private static Point getAppUsableScreenSize(@NonNull Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);// ww  w.  j  a v a 2 s .c  o  m
    return size;
}

From source file:com.dm.material.dashboard.candybar.helpers.ViewHelper.java

public static Point getRealScreenSize(@NonNull Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        display.getRealSize(size);/*from   w  w  w  . j a  va  2s .com*/
    } else {
        try {
            size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
            size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
        } catch (Exception e) {
            size.x = display.getWidth();
            size.y = display.getHeight();
        }
    }
    return size;
}

From source file:com.android.leanlauncher.LauncherAppState.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
static DynamicGrid createDynamicGrid(Context context, DynamicGrid dynamicGrid) {
    // Determine the dynamic grid properties
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point realSize = new Point();
    display.getRealSize(realSize);/*w w  w  .ja va  2s . c  om*/
    DisplayMetrics dm = new DisplayMetrics();
    display.getMetrics(dm);

    if (dynamicGrid == null) {
        Point smallestSize = new Point();
        Point largestSize = new Point();
        display.getCurrentSizeRange(smallestSize, largestSize);

        dynamicGrid = new DynamicGrid(context, context.getResources(), Math.min(smallestSize.x, smallestSize.y),
                Math.min(largestSize.x, largestSize.y), realSize.x, realSize.y, dm.widthPixels,
                dm.heightPixels);
    }

    // Update the icon size
    DeviceProfile grid = dynamicGrid.getDeviceProfile();
    grid.updateFromConfiguration(context, context.getResources(), realSize.x, realSize.y, dm.widthPixels,
            dm.heightPixels);
    return dynamicGrid;
}

From source file:com.wwtv.player.utils.Utils.java

@SuppressWarnings("deprecation")
/**//from ww  w .j a v a 2  s. com
 * Returns the screen/display size
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    return new Point(width, height);
}

From source file:com.google.sample.cast.refplayer.utils.Utils.java

@SuppressWarnings("deprecation")
/**/*from  w w  w  .j a v a  2 s  .c o m*/
 * Returns the screen/display size
 *
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    return new Point(width, height);
}

From source file:io.lqd.sdk.model.LQDevice.java

@SuppressWarnings("deprecation")
private static String getScreenSize(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    int width = display.getWidth(); // deprecated
    int height = display.getHeight(); // deprecated
    return width + "x" + height;
}

From source file:count.ly.messaging.DeviceInfo.java

/**
 * Returns the non-scaled pixel resolution of the current default display being used by the
 * WindowManager in the specified context.
 * @param context context to use to retrieve the current WindowManager
 * @return a string in the format "WxH", or the empty string "" if resolution cannot be determined
 *///from   ww w. j  ava 2s . c om
static String getResolution(final Context context) {
    // user reported NPE in this method; that means either getSystemService or getDefaultDisplay
    // were returning null, even though the documentation doesn't say they should do so; so now
    // we catch Throwable and return empty string if that happens
    String resolution = "";
    try {
        final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        final Display display = wm.getDefaultDisplay();
        final DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        resolution = metrics.widthPixels + "x" + metrics.heightPixels;
    } catch (Throwable t) {
        if (Countly.sharedInstance().isLoggingEnabled()) {
            Log.i(Countly.TAG, "Device resolution cannot be determined");
        }
    }
    return resolution;
}

From source file:com.jerrellmardis.amphitheatre.util.Utils.java

/**
 * Returns the screen/display size//from   w w w  .  j  a  v  a 2s .co m
 *
 * @param context
 * @return
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    return new Point(width, height);
}

From source file:com.bobomee.android.common.util.ScreenUtil.java

/**
 * ?/*w ww.j  a v a2  s.  c om*/
 */
public static int getScreenWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics.widthPixels;
}

From source file:com.cloverstudio.spika.SpikaApp.java

/**
 * Sets sliding transport based on screen density and required offset width
 * <p>/*from  ww  w . j  a v a  2s. c  o m*/
 * Depends on width of side offset in dp
 * 
 * @param sideWidthInDp
 */
public static void setTransportBasedOnScreenDensity(int sideWidthInDp) {
    WindowManager wm = (WindowManager) sInstance.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);

    double sideWidthInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sideWidthInDp,
            sInstance.getResources().getDisplayMetrics());

    double transportRate = 1 - sideWidthInPx / metrics.widthPixels;
    sInstance.mTransport = (int) Math.floor(metrics.widthPixels * transportRate);
}