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

@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;// w ww  . ja v a  2s. com
    // 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:Main.java

/**
 * This method calculates maximum size of both width and height of bitmap.
 * It is twice the device screen diagonal for default implementation (extra quality to zoom image).
 * Size cannot exceed max texture size./*from   www. j  a v a  2  s  .co m*/
 *
 * @return - max bitmap size in pixels.
 */
@SuppressWarnings({ "SuspiciousNameCombination", "deprecation" })
public static int calculateMaxBitmapSize(@NonNull Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point size = new Point();
    int width, height;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        width = size.x;
        height = size.y;
    } else {
        width = display.getWidth();
        height = display.getHeight();
    }

    int screenDiagonal = (int) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));

    Canvas canvas = new Canvas();
    return Math.min(screenDiagonal * 2,
            Math.min(canvas.getMaximumBitmapWidth(), canvas.getMaximumBitmapHeight()));
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static ImageReader createImageReader(Activity c) {
    DisplayMetrics metrics = c.getResources().getDisplayMetrics();
    int density = metrics.densityDpi;
    int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; //DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;
    Display display = c.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);/*w w  w .  j  a  va  2s . c  o  m*/

    return ImageReader.newInstance(size.x, size.y, PixelFormat.RGB_565, 2);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static int getRealHeight(Display display) {
    int height;/*w w  w .j  a va  2  s .  c  om*/
    try {
        Point size = new Point();
        display.getRealSize(size);
        height = size.y;
    } catch (NoSuchMethodError e) {
        height = display.getHeight();
    }
    return height;
}

From source file:Main.java

/**
 * <pre>/*ww w  .  j av  a 2 s .c  o  m*/
 * Get sizes of screen in pixels.
 * </pre>
 * @return interger array with 2 elements: width and height
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
@SuppressWarnings("deprecation")
public static int[] getDisplaySizes() {
    Context context = getCurrentContext();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    if (Build.VERSION.SDK_INT < 13) {
        return new int[] { display.getWidth(), display.getHeight() };
    } else {
        Point point = new Point();
        display.getSize(point);
        return new int[] { point.x, point.y };
    }
}

From source file:Main.java

/**
 * @Thach Feb 21, 2014//w  ww  .java 2 s.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: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 {//w ww  .j  a v a 2  s  . co  m
        sAnimationDuration = ANIMATION_SHORT_DURATION;
    }
}

From source file:Main.java

/**
 * Returns the screen/display size//  w w  w .  j  a  v a2 s .  co  m
 */
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

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

From source file:Main.java

public static Camera.Size getOptimalPreviewSize(Activity currentActivity, List<Camera.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;

    Camera.Size optimalSize = null;//from  www . j ava  2  s  .  c  o 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 (Camera.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) {
        minDiff = Double.MAX_VALUE;
        for (Camera.Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}