List of usage examples for android.content Context WINDOW_SERVICE
String WINDOW_SERVICE
To view the source code for android.content Context WINDOW_SERVICE.
Click Source Link
From source file:Main.java
/** * Returns the size of the screen// w w w .j a va 2s . c om * * @param activity The {@link Activity} to use * @return Point where x=width and y=height */ public static Point getScreenSize(Activity activity) { if (activity != null) { WindowManager service = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); service.getDefaultDisplay().getSize(mScreenSize); } return mScreenSize; }
From source file:Main.java
public static int getScreenWidth(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size);/* w ww.j av a 2s. c om*/ return size.x; }
From source file:Main.java
public static Point libgdxToScreenCoordinates(Context context, float x, float y) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size);/*from w ww. j av a 2 s .c om*/ // Log.d(CucumberInstrumentation.TAG, String.format("center: [%d/%d]", size.x / 2, size.y / 2)); Point point = new Point(); point.x = Math.round((size.x / 2f) + x); point.y = Math.round((size.y / 2f) + y); // Log.d(CucumberInstrumentation.TAG, String.format("coords: [%d/%d]", point.x, point.y)); return point; }
From source file:Main.java
/** * Set Camera orientation to correct one * @param context app context/*w ww.j a va2s. c o m*/ * @param camera camera to set orientation */ public static void setCameraDisplayOrientation(Context context, Camera camera) { if (camera == null) { return; } Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(getCameraInformationId(), info); WindowManager winManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); int rotation = winManager.getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); }
From source file:Main.java
/** * Resamples the captured photo to fit the screen for better memory usage. * * @param context The application context. * @param imagePath The path of the photo to be resampled. * @return The resampled bitmap/*from www . j av a2s . c o m*/ */ static Bitmap resamplePic(Context context, String imagePath) { // Get device screen size information DisplayMetrics metrics = new DisplayMetrics(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); manager.getDefaultDisplay().getMetrics(metrics); int targetH = metrics.heightPixels; int targetW = metrics.widthPixels; // Get the dimensions of the original bitmap BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(imagePath, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image int scaleFactor = Math.min(photoW / targetW, photoH / targetH); // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; return BitmapFactory.decodeFile(imagePath); }
From source file:Main.java
/** * Calculate displey size./*from w w w.ja v a 2 s .c om*/ * @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
public static float getScreenDensity(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics);//from ww w. j a v a 2 s. c om return metrics.density; }
From source file:Main.java
public static void getDisplayDpi(Context ctx) { DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); double x = Math.pow(dm.widthPixels / dm.xdpi, 2); double y = Math.pow(dm.heightPixels / dm.ydpi, 2); double screenInches = Math.sqrt(x + y); int screenInch = (int) Math.round(screenInches); Log.d("screeninch", String.valueOf(screenInch)); int dapi = dm.densityDpi; Log.d("dapi", String.valueOf(dapi)); try {/*w w w. j ava2 s .c om*/ switch (dm.densityDpi) { case DisplayMetrics.DENSITY_LOW: UI_DENSITY = 120; if (screenInch <= 7) { UI_SIZE = 4; } else { UI_SIZE = 10; } break; case DisplayMetrics.DENSITY_MEDIUM: UI_DENSITY = 160; if (screenInch <= 7) { UI_SIZE = 4; } else { UI_SIZE = 10; } break; case DisplayMetrics.DENSITY_HIGH: UI_DENSITY = 240; if (screenInch <= 7) { UI_SIZE = 4; } else { UI_SIZE = 10; } break; default: break; } } catch (Exception e) { // Caught exception here } }
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 . ja va 2 s .c om * @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
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); }