Example usage for android.view Display getWidth

List of usage examples for android.view Display getWidth

Introduction

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

Prototype

@Deprecated
public int getWidth() 

Source Link

Usage

From source file:Main.java

public static Point getScreenResolution(Context context) {

    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();

    int width = display.getWidth();
    int height = display.getHeight();

    return new Point(width, height);

}

From source file:Main.java

public static Point getScreenDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point point = new Point();
    if (Build.VERSION.SDK_INT >= 13) {
        display.getSize(point);//  w  w w  .  j  ava 2s. c  o  m
    } else {
        point = new Point(display.getWidth(), display.getHeight());
    }

    return point;
}

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 .jav  a  2  s. c o  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:Main.java

@SuppressLint("NewApi")
public static void getSize(Display display, Point outSize) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        display.getSize(outSize);//  ww w.  j a v  a2s. co  m
    } else {
        outSize.x = display.getWidth();
        outSize.y = display.getHeight();
    }
}

From source file:Main.java

public static int screenWidthInPix(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= 13) {
        display.getSize(size);//from  w ww .j  a v  a  2 s.c  om
        return size.x;
    } else {
        return display.getWidth();
    }

}

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;/*w w w. j av  a2 s.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 mSurfaceView. 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

    Display display = currentActivity.getWindowManager().getDefaultDisplay();
    int targetHeight = Math.min(display.getHeight(), display.getWidth());

    if (targetHeight <= 0) {
        // We don't know the size of SurfaceView, use screen height
        targetHeight = display.getHeight();
    }

    // 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 wm = (WindowManager) context.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 a  v  a2  s . co  m
    } else {
        size.set(display.getWidth(), display.getHeight());
    }

    return size;
}

From source file:Main.java

public static Point getScreenResolution(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point screenResolution = new Point();
    if (android.os.Build.VERSION.SDK_INT >= 13) {
        display.getSize(screenResolution);
    } else {/* w  ww . j  a v a 2  s. c  o  m*/
        screenResolution.set(display.getWidth(), display.getHeight());
    }
    return screenResolution;
}

From source file:Main.java

public static Point getScreenResolution(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point screenResolution = new Point();
    if (android.os.Build.VERSION.SDK_INT >= 13) {
        display.getSize(screenResolution);
    } else {//w w w .  ja v  a2s  . c o  m
        screenResolution.set(display.getWidth(), display.getHeight());
    }

    return screenResolution;
}

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);// w w  w.  j  ava  2s  . c om
    else {
        size.x = display.getWidth();
        size.y = display.getHeight();
    }
    return size;
}