Example usage for android.view Display getSize

List of usage examples for android.view Display getSize

Introduction

In this page you can find the example usage for android.view Display getSize.

Prototype

public void getSize(Point outSize) 

Source Link

Document

Gets the size of the display, in pixels.

Usage

From source file:org.acra.collector.DisplayManagerCollector.java

@NonNull
private static String collectSize(@NonNull Display display) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        final Point size = new Point();
        display.getSize(size);
        return display.getDisplayId() + ".size=[" + size.x + ',' + size.y + ']' + '\n';
    }/*from  w w w.  j  av a2  s  .co  m*/
    return "";
}

From source file:Main.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static void resizeImageView(Context ctx, ImageView imgView) {
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width;//from w ww .  ja va2  s  . co m
    // int height;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        width = display.getWidth(); // deprecated
        // height = display.getHeight(); // deprecated
    } else {
        Point size = new Point();
        display.getSize(size);
        width = size.x;
        // height = size.y;
    }

    imgView.setMinimumHeight(width);
    imgView.setMinimumWidth(width);
    imgView.getLayoutParams().height = width;
    imgView.getLayoutParams().width = width;
}

From source file:com.activiti.android.ui.utils.UIUtils.java

/**
 * Retrieve screen dimension.//w ww .j ava  2 s  .co  m
 *
 * @param activity
 * @return
 */
public static int[] getScreenDimension(Activity activity) {
    int width = 0;
    int height = 0;

    Display display = activity.getWindowManager().getDefaultDisplay();
    if (AndroidVersion.isHCMR2OrAbove()) {
        Point size = new Point();
        display.getSize(size);
        width = size.x;
        height = size.y;
    } else {
        width = display.getWidth(); // deprecated
        height = display.getHeight(); // deprecated
    }

    return new int[] { width, height };
}

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

/**
 * Returns the screen/display size/*from  w w  w . ja v a  2s  .  c  o  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:me.wimanacra.collector.DisplayManagerCollector.java

private static void collectSize(@NonNull Display display, JSONObject container) throws JSONException {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        final Point size = new Point();
        display.getSize(size);
        container.put("size", new JSONArray(Arrays.asList(size.x, size.y)));
    }/*from  ww w  . j a va 2s  .c om*/
}

From source file:org.alfresco.mobile.android.ui.utils.UIUtils.java

/**
 * Retrieve screen dimension.//  w w w .  j  a v a2  s . c  om
 * 
 * @param activity
 * @return
 */
public static int[] getScreenDimension(FragmentActivity activity) {
    int width = 0;
    int height = 0;

    Display display = activity.getWindowManager().getDefaultDisplay();
    if (AndroidVersion.isHCMR2OrAbove()) {
        Point size = new Point();
        display.getSize(size);
        width = size.x;
        height = size.y;
    } else {
        width = display.getWidth(); // deprecated
        height = display.getHeight(); // deprecated
    }

    return new int[] { width, height };
}

From source file:com.amazon.android.utils.Helpers.java

/**
 * Returns the screen/display size./*from  www .ja v a 2  s.c o  m*/
 *
 * @param context The context.
 * @return The display size.
 */
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);
    return size;
}

From source file:Main.java

/**
 * @Thach Feb 21, 2014//  w ww . ja v  a2s  .  c  o  m
 * @Desc lock Orientation
 * @param b
 */
@SuppressWarnings("deprecation")
public static void lockOrientation(Activity act, boolean isLock) {
    if (act == null) {
        return;
    }
    if (isLock) {
        Display display = act.getWindowManager().getDefaultDisplay();
        int rotation = display.getRotation();
        int height;
        int width;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
            height = display.getHeight();
            width = display.getWidth();
        } else {
            Point size = new Point();
            display.getSize(size);
            height = size.y;
            width = size.x;
        }
        switch (rotation) {
        case Surface.ROTATION_90:
            if (width > height)
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            else
                act.setRequestedOrientation(9/* reversePortait */);
            break;
        case Surface.ROTATION_180:
            if (height > width)
                act.setRequestedOrientation(9/* reversePortait */);
            else
                act.setRequestedOrientation(8/* reverseLandscape */);
            break;
        case Surface.ROTATION_270:
            if (width > height)
                act.setRequestedOrientation(8/* reverseLandscape */);
            else
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        default:
            if (height > width)
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            else
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    } else {
        act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }
}

From source file:fr.cph.chicago.util.Util.java

public static int[] getScreenSize(@NonNull final Context context) {
    final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    final Display display = wm.getDefaultDisplay();
    final Point size = new Point();
    display.getSize(size);
    return new int[] { size.x, size.y };
}

From source file:org.bottiger.podcast.utils.UIUtils.java

public static int getScreenHeight(@NonNull Context argContext) {
    WindowManager windowManager = (WindowManager) argContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    return height;
}