Example usage for android.graphics Point Point

List of usage examples for android.graphics Point Point

Introduction

In this page you can find the example usage for android.graphics Point Point.

Prototype

public Point() 

Source Link

Usage

From source file:Main.java

public static Point getScreenSize(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);/*from  w ww .ja  va2s. c  om*/
    return size;
}

From source file:Main.java

public static Point getScreenSize(Context applicationContext) {

    WindowManager wm = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
        display.getSize(size);//from w w  w.  j  ava  2  s.c o m
    else {
        size.x = display.getWidth();
        size.y = display.getHeight();
    }
    return size;
}

From source file:Main.java

/**
 * Gets device's display resolution.// w  w w . j  a  v a 2  s  .  c  om
 * @since   0.1.0
 * @param   aActivity The activity from which the window's information is retrieved.
 * @return   The struct of Point with x attribute contains the width and y attribute contains the height.
 */
public static Point getDisplayResolution(Activity aActivity) {
    Point p = new Point();
    aActivity.getWindowManager().getDefaultDisplay().getSize(p);
    return p;
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);//from w w  w. j  a v a 2s  . c o  m
    return point.x;
}

From source file:Main.java

public static int getScreenHeight(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);/*from   www.  j  a v a  2  s . c om*/
    return point.y;
}

From source file:Main.java

@Nullable
private static Rect getRecyclerViewRect(ViewParent parent) {
    if (parent == null) { // view is not attached to RecyclerView
        return null;
    }/* ww w. j a v a 2s . co m*/

    if (!(parent instanceof View)) {
        return null;
    }

    Rect rect = new Rect();
    Point offset = new Point();
    ((View) parent).getGlobalVisibleRect(rect, offset);
    return rect;
}

From source file:Main.java

public static Size getOptimalPreviewSize(Activity currentActivity, List<Size> sizes, double targetRatio) {
    // Use a very small tolerance because we want an exact match.
    final double ASPECT_TOLERANCE = 0.001;
    if (sizes == null)
        return null;
    Size optimalSize = null;/*from w  ww  .j  a  va2s . co m*/
    double minDiff = Double.MAX_VALUE;
    // Because of bugs of overlay and layout, we sometimes will try to
    // layout the viewfinder in the portrait orientation and thus get the
    // wrong size of preview surface. When we change the preview size, the
    // new overlay will be created before the old one closed, which causes
    // an exception. For now, just get the screen size.
    Point point = getDefaultDisplaySize(currentActivity, new Point());
    int targetHeight = Math.min(point.x, point.y);
    // Try to find an size match aspect ratio and size
    for (Size size : sizes) {
        double ratio = (double) size.width / size.height;
        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
            continue;
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }
    // Cannot find the one match the aspect ratio. This should not happen.
    // Ignore the requirement.
    if (optimalSize == null) {
        Log.w(TAG, "No preview size match the aspect ratio");
        minDiff = Double.MAX_VALUE;
        for (Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}

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 w w w.j  a va2s  .co  m*/
    return size;
}

From source file:Main.java

public static HashMap<String, Integer> parseImageSizeWithUrl(Activity activity, String imageUrl) {

    int widthPx = DEFAULT_POST_IMAGE_WIDTH;
    int heightPx = DEFAULT_POST_IMAGE_HEIGHT;

    String[] file = imageUrl.split("\\.");
    int index = file.length - 2;
    String[] snippet = file[index].split("_");

    int snippetCount = snippet.length;
    if (snippetCount >= 3) {

        if (null != snippet[1]) {
            widthPx = Integer.parseInt(snippet[1]);
        }//from   w  ww .ja v a2  s  . c  o m

        if (null != snippet[2]) {
            heightPx = Integer.parseInt(snippet[2]);
        }
    }
    WindowManager windowManager = activity.getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    int screenWidth = 0;
    int screenHeight = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
    } else {
        screenWidth = display.getWidth();
        screenHeight = display.getHeight();
    }

    if (widthPx > screenWidth) {
        widthPx = screenWidth;
    } else if (widthPx < DEFAULT_POST_IMAGE_WIDTH) {
        widthPx = DEFAULT_POST_IMAGE_WIDTH;
    }

    if (heightPx > screenHeight) {
        heightPx = screenHeight;
    } else if (heightPx < DEFAULT_POST_IMAGE_HEIGHT) {
        heightPx = DEFAULT_POST_IMAGE_HEIGHT;
    }

    HashMap<String, Integer> imageSize = new HashMap<String, Integer>();
    imageSize.put("widthPx", widthPx);
    imageSize.put("heightPx", heightPx);
    return imageSize;
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static int getWidth(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.j  ava2  s .c om*/
        return size.x;
    } else
        return display.getWidth();
}