List of usage examples for android.view Display getWidth
@Deprecated public int getWidth()
From source file:com.google.sample.cast.refplayer.utils.Utils.java
@SuppressWarnings("deprecation") /**//from ww w .j a v a 2s .c om * Returns the screen/display size * */ public static Point getDisplaySize(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); return new Point(width, height); }
From source file:io.lqd.sdk.model.LQDevice.java
@SuppressWarnings("deprecation") private static String getScreenSize(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); int width = display.getWidth(); // deprecated int height = display.getHeight(); // deprecated return width + "x" + height; }
From source file:Main.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") public static int[] getScreenWidthHeight(Context context) { int[] widthAndHeight = new int[2]; WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT >= 13) { Point size = new Point(); display.getSize(size);// w ww . j av a2s. c o m widthAndHeight[0] = size.x; widthAndHeight[1] = size.y; } else { widthAndHeight[0] = display.getWidth(); widthAndHeight[1] = display.getHeight(); } return widthAndHeight; }
From source file:Main.java
/** * Method that get the Screen Size//www.j av a 2 s . co m * @param activity Actual Activity * @return array type int */ public static int[] getScreenSize(Activity activity) { //Obtain default display Display display = activity.getWindowManager().getDefaultDisplay(); Point size = new Point(); //Set Size in case of ICS if (android.os.Build.VERSION.SDK_INT >= 13) { display.getSize(size); return new int[] { size.x, size.y }; } else { return new int[] { display.getWidth(), display.getHeight() }; } }
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./* w ww . j a v a 2 s . c o 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
/** * Calculate displey size./* w ww .j av a2 s . c o m*/ * @param context Context. */ @SuppressLint("NewApi") @SuppressWarnings("deprecation") private static void calculateDisplaySize(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); Point screenSize = new Point(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { display.getSize(screenSize); displayWidth = screenSize.x; displayHeight = screenSize.y; } else { displayWidth = display.getWidth(); displayHeight = display.getHeight(); } }
From source file:Main.java
/** * @Thach Feb 21, 2014/* w w w .j a 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:org.solovyev.android.calculator.App.java
@SuppressWarnings("deprecation") public static int getScreenOrientation(@Nonnull Activity activity) { final android.view.Display display = activity.getWindowManager().getDefaultDisplay(); if (display.getWidth() <= display.getHeight()) { return Configuration.ORIENTATION_PORTRAIT; } else {//from w ww .j a v a2s . c o m return Configuration.ORIENTATION_LANDSCAPE; } }
From source file:com.ichi2.anki.Whiteboard.java
private static int getDisplayWidth() { Display display = ((WindowManager) AnkiDroidApp.getInstance().getApplicationContext() .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); return display.getWidth(); }
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 ava2 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; }