List of usage examples for android.view Display getSize
public void getSize(Point outSize)
From source file:Main.java
private static Point getScreenSizeInternal(final Context context) { Point size = null;//w ww . j a va 2 s . c o m final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); if (windowManager != null) { final Display display = windowManager.getDefaultDisplay(); if (display != null) { // only works if Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2 size = new Point(); display.getSize(size); } } return size; }
From source file:Main.java
/** * <pre>//from w w w .j a v a 2s.c om * 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
/** * Compute the minimum cache size for a view. When the cache is created we do not actually * know the size of the mapview, so the screenRatio is an approximation of the required size. * * @param c the context//from w w w . j av a 2s . co m * @param tileSize the tile size * @param overdrawFactor the overdraw factor applied to the mapview * @param screenRatio the part of the screen the view covers * @return the minimum cache size for the view */ @SuppressWarnings("deprecation") @TargetApi(13) public static int getMinimumCacheSize(Context c, int tileSize, double overdrawFactor, float screenRatio) { WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int height; int width; if (android.os.Build.VERSION.SDK_INT >= 13) { Point p = new Point(); display.getSize(p); height = p.y; width = p.x; } else { // deprecated since Android 13 height = display.getHeight(); width = display.getWidth(); } // height * overdrawFactor / tileSize calculates the number of tiles that would cover // the view port, adding 1 is required since we can have part tiles on either side, // adding 2 adds another row/column as spare and ensures that we will generally have // a larger number of tiles in the cache than a TileLayer will render for a view. // Multiplying by screenRatio adjusts this somewhat inaccurately for MapViews on only part // of a screen (the result can be too low if a MapView is very narrow). // For any size we need a minimum of 4 (as the intersection of 4 tiles can always be in the // middle of a view. return (int) Math.max(4, screenRatio * (2 + (height * overdrawFactor / tileSize)) * (2 + (width * overdrawFactor / tileSize))); }
From source file:Main.java
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) public static int getScreenHeight(Context ctx) { WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int height;//from www . j ava 2 s.co m if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) { height = display.getHeight(); // deprecated } else { Point size = new Point(); display.getSize(size); height = size.y; } return height; }
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); return size;/*from ww w . j a v a 2 s. c om*/ }
From source file:io.digibyte.tools.qrcode.QRUtils.java
public static boolean generateQR(Context ctx, String bitcoinURL, ImageView qrcode) { if (qrcode == null || bitcoinURL == null || bitcoinURL.isEmpty()) return false; WindowManager manager = (WindowManager) ctx.getSystemService(Activity.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point point = new Point(); display.getSize(point); int width = point.x; int height = point.y; int smallerDimension = width < height ? width : height; smallerDimension = (int) (smallerDimension * 0.45f); Bitmap bitmap = null;//from w w w . ja v a 2 s. c o m bitmap = QRUtils.encodeAsBitmap(bitcoinURL, smallerDimension); //qrcode.setPadding(1, 1, 1, 1); //qrcode.setBackgroundResource(R.color.gray); if (bitmap == null) return false; qrcode.setImageBitmap(bitmap); return true; }
From source file:com.asburymotors.android.disneysocal.common.Utils.java
/** * Calculates the square insets on a round device. If the system insets are not set * (set to 0) then the inner square of the circle is applied instead. * * @param display device default display * @param systemInsets the system insets * @return adjusted square insets for use on a round device *//*from ww w . j a va 2 s . c o m*/ public static Rect calculateBottomInsetsOnRoundDevice(Display display, Rect systemInsets) { Point size = new Point(); display.getSize(size); int width = size.x + systemInsets.left + systemInsets.right; int height = size.y + systemInsets.top + systemInsets.bottom; // Minimum inset to use on a round screen, calculated as a fixed percent of screen height int minInset = (int) (height * Constants.WEAR_ROUND_MIN_INSET_PERCENT); // Use system inset if it is larger than min inset, otherwise use min inset int bottomInset = systemInsets.bottom > minInset ? systemInsets.bottom : minInset; // Calculate left and right insets based on bottom inset double radius = width / 2; double apothem = radius - bottomInset; double chord = Math.sqrt(Math.pow(radius, 2) - Math.pow(apothem, 2)) * 2; int leftRightInset = (int) ((width - chord) / 2); Log.d(TAG, "calculateBottomInsetsOnRoundDevice: " + bottomInset + ", " + leftRightInset); return new Rect(leftRightInset, 0, leftRightInset, bottomInset); }
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 w w. j a v a 2 s . co 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:com.hangulo.powercontact.util.Utils.java
public static int getScreenHeightSize(Activity activity) { Display display = activity.getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); //int width = size.x; return (size.y); }
From source file:com.hangulo.powercontact.util.Utils.java
public static int getScreenWidthtSize(Activity activity) { Display display = activity.getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); //int width = size.x; return (size.x); }