List of usage examples for android.view Display getHeight
@Deprecated public int getHeight()
From source file:Main.java
/** * Get a BitmapDrawable from a local file that is scaled down * to fit the current Window size./*from ww w . j a v a 2 s .c o m*/ */ @SuppressWarnings("deprecation") public static BitmapDrawable getScaledDrawable(Activity a, String path) { Display display = a.getWindowManager().getDefaultDisplay(); float destWidth = display.getWidth(); float destHeight = display.getHeight(); // read in the dimensions of the image on disk BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, options); float srcWidth = options.outWidth; float srcHeight = options.outHeight; int inSampleSize = 1; if (srcHeight > destHeight || srcWidth > destWidth) { if (srcWidth > srcHeight) { inSampleSize = Math.round((float) srcHeight / ((float) destHeight) * 3); } else { inSampleSize = Math.round((float) srcWidth / ((float) destWidth) * 3); } } options = new BitmapFactory.Options(); options.inSampleSize = inSampleSize; Bitmap bitmap = BitmapFactory.decodeFile(path, options); return new BitmapDrawable(a.getResources(), bitmap); }
From source file:Main.java
public static int getScreenOrientation(Activity activity) { Display getOrient = activity.getWindowManager().getDefaultDisplay(); int orientation = Configuration.ORIENTATION_UNDEFINED; if (getOrient.getWidth() == getOrient.getHeight()) { orientation = Configuration.ORIENTATION_SQUARE; } else {/*from w w w . j a v a2s . co m*/ if (getOrient.getWidth() < getOrient.getHeight()) { orientation = Configuration.ORIENTATION_PORTRAIT; } else { orientation = Configuration.ORIENTATION_LANDSCAPE; } } return orientation; }
From source file:Main.java
/** * <pre>//from w w w.j a v 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
@SuppressWarnings("deprecation") public static String getDisplayMetrics(Context ctx) { String metrics = ""; try {/*from w w w .j av a2s .com*/ Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); metrics += width; metrics += "x"; metrics += height; } catch (Exception e) { } return metrics; }
From source file:Main.java
public static void showAsPopup(Activity activity) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { return;/*from ww w . j a va2s. c om*/ } activity.requestWindowFeature(Window.FEATURE_ACTION_BAR); //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest Window window = activity.getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND); Display display = activity.getWindowManager().getDefaultDisplay(); WindowManager.LayoutParams params = window.getAttributes(); params.height = (int) (display.getHeight() * 0.95); params.width = Math.min((int) (display.getWidth() * 0.9), (int) (params.height * 0.85)); params.gravity = Gravity.BOTTOM; params.alpha = 1.0f; params.dimAmount = 0.5f; window.setAttributes(params); }
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 w w.j av a 2 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
/** * Get a BitmapDrawable from a local file that is scaled down * to fit the current Window size./* w w w .java2 s . c o m*/ */ @SuppressWarnings("deprecation") static BitmapDrawable getScaledBitmap(String path, Activity a) { Display display = a.getWindowManager().getDefaultDisplay(); float destWidth = display.getWidth(); float destHeight = display.getHeight(); // read in the dimensions of the image on disk BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, options); float srcWidth = options.outWidth; float srcHeight = options.outHeight; int inSampleSize = 1; if (srcHeight > destHeight || srcWidth > destWidth) { if (srcWidth > srcHeight) { inSampleSize = Math.round(srcHeight / destHeight); } else { inSampleSize = Math.round(srcWidth / destWidth); } } options = new BitmapFactory.Options(); options.inSampleSize = inSampleSize; Bitmap bitmap = BitmapFactory.decodeFile(path, options); return new BitmapDrawable(a.getResources(), bitmap); }
From source file:com.gitstudy.rili.liarbry.YearViewSelectLayout.java
/** * /*w w w .ja v a 2 s.com*/ * * @param context context * @param view view * @return ? */ private static int getHeight(Context context, View view) { WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); assert manager != null; Display display = manager.getDefaultDisplay(); int h = display.getHeight(); int[] location = new int[2]; view.getLocationInWindow(location); view.getLocationOnScreen(location); return h - location[1]; }
From source file:Main.java
public static int screenHeightInPix(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 www . j a v a 2s . c o m*/ return size.y; } else { return display.getHeight(); } }
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); }