List of usage examples for android.view WindowManager getDefaultDisplay
public Display getDefaultDisplay();
From source file:com.almalence.util.Util.java
public static void initialize(Context context) { sIsTabletUI = false;/*w w w. j a va 2 s. com*/ DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(metrics); sPixelDensity = metrics.density; }
From source file:com.apptentive.android.sdk.util.Util.java
public static Point getScreenSize(Context context) { Point ret = new Point(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); // TODO: getWidth(), getHeight(), and getOrientation() are deprecated in API 13 in favor of getSize() and getRotation(). ret.set(display.getWidth(), display.getHeight()); return ret;//from w w w. j ava 2s . c om }
From source file:com.wbtech.ums.UmsAgent.java
private static JSONObject getClientDataJSONObject(Context context) { TelephonyManager tm = (TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE)); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displaysMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(displaysMetrics); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); JSONObject clientData = new JSONObject(); try {// w w w . ja v a2 s. c om clientData.put("os_version", CommonUtil.getOsVersion(context)); clientData.put("platform", "android"); clientData.put("language", Locale.getDefault().getLanguage()); clientData.put("deviceid", tm.getDeviceId() == null ? "" : tm.getDeviceId());// clientData.put("appkey", CommonUtil.getAppKey(context)); clientData.put("resolution", displaysMetrics.widthPixels + "x" + displaysMetrics.heightPixels); clientData.put("ismobiledevice", true); clientData.put("phonetype", tm.getPhoneType());// clientData.put("imsi", tm.getSubscriberId()); clientData.put("network", CommonUtil.getNetworkTypeWIFI2G3G(context)); clientData.put("time", CommonUtil.getTime()); clientData.put("version", CommonUtil.getVersion(context)); clientData.put(UserIdentifier, CommonUtil.getUserIdentifier(context)); SCell sCell = CommonUtil.getCellInfo(context); clientData.put("mccmnc", sCell != null ? "" + sCell.MCCMNC : ""); clientData.put("cellid", sCell != null ? sCell.CID + "" : ""); clientData.put("lac", sCell != null ? sCell.LAC + "" : ""); clientData.put("modulename", Build.PRODUCT); clientData.put("devicename", CommonUtil.getDeviceName()); clientData.put("wifimac", wifiManager.getConnectionInfo().getMacAddress()); clientData.put("havebt", adapter == null ? false : true); clientData.put("havewifi", CommonUtil.isWiFiActive(context)); clientData.put("havegps", locationManager == null ? false : true); clientData.put("havegravity", CommonUtil.isHaveGravity(context));// LatitudeAndLongitude coordinates = CommonUtil.getLatitudeAndLongitude(context, UmsAgent.mUseLocationService); clientData.put("latitude", coordinates.latitude); clientData.put("longitude", coordinates.longitude); CommonUtil.printLog("clientData---------->", clientData.toString()); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return clientData; }
From source file:xj.property.ums.UmsAgent.java
public static JSONObject getClientDataJSONObject(Context context) { TelephonyManager tm = (TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE)); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displaysMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(displaysMetrics); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); JSONObject clientData = new JSONObject(); try {/* www .j a va2 s . c om*/ clientData.put("os_version", CommonUtil.getOsVersion(context)); clientData.put("platform", "android"); clientData.put("language", Locale.getDefault().getLanguage()); clientData.put("deviceid", tm.getDeviceId() == null ? "" : tm.getDeviceId());// clientData.put("appkey", CommonUtil.getAppKey(context)); clientData.put("resolution", displaysMetrics.widthPixels + "x" + displaysMetrics.heightPixels); clientData.put("ismobiledevice", true); clientData.put("phonetype", tm.getPhoneType());// clientData.put("imsi", tm.getSubscriberId()); clientData.put("network", CommonUtil.getNetworkTypeWIFI2G3G(context)); clientData.put("time", CommonUtil.getTime()); clientData.put("version", CommonUtil.getVersion(context)); clientData.put(UserIdentifier, CommonUtil.getUserIdentifier(context)); SCell sCell = CommonUtil.getCellInfo(context); clientData.put("mccmnc", sCell != null ? "" + sCell.MCCMNC : ""); clientData.put("cellid", sCell != null ? sCell.CID + "" : ""); clientData.put("lac", sCell != null ? sCell.LAC + "" : ""); clientData.put("modulename", Build.PRODUCT); clientData.put("devicename", CommonUtil.getDeviceName()); clientData.put("wifimac", wifiManager.getConnectionInfo().getMacAddress()); clientData.put("havebt", adapter == null ? false : true); clientData.put("havewifi", CommonUtil.isWiFiActive(context)); clientData.put("havegps", locationManager == null ? false : true); clientData.put("havegravity", CommonUtil.isHaveGravity(context));// LatitudeAndLongitude coordinates = CommonUtil.getLatitudeAndLongitude(context, UmsAgent.mUseLocationService); clientData.put("latitude", coordinates.latitude); clientData.put("longitude", coordinates.longitude); CommonUtil.printLog("clientData---------->", clientData.toString()); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return clientData; }
From source file:com.farmerbb.secondscreen.util.U.java
public static boolean runDensityCommand(Context context, String requestedDpi) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display disp = wm.getDefaultDisplay(); disp.getRealMetrics(metrics);//w ww . j av a 2 s. c o m SharedPreferences prefMain = getPrefMain(context); String currentDpi; String nativeDpi = Integer .toString(SystemProperties.getInt("ro.sf.lcd_density", prefMain.getInt("density", 0))); if (prefMain.getBoolean("debug_mode", false)) { SharedPreferences prefCurrent = getPrefCurrent(context); currentDpi = prefCurrent.getString("density", "reset"); if ("reset".equals(currentDpi)) currentDpi = nativeDpi; } else currentDpi = Integer.toString(metrics.densityDpi); if (requestedDpi.equals("reset")) requestedDpi = nativeDpi; return !requestedDpi.equals(currentDpi); }
From source file:com.farmerbb.secondscreen.util.U.java
public static boolean runSizeCommand(Context context, String requestedRes) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display disp = wm.getDefaultDisplay(); disp.getRealMetrics(metrics);//from w w w.ja va 2 s . c o m SharedPreferences prefMain = getPrefMain(context); String currentRes = " "; String nativeRes; if (prefMain.getBoolean("landscape", false)) nativeRes = Integer.toString(prefMain.getInt("height", 0)) + "x" + Integer.toString(prefMain.getInt("width", 0)); else nativeRes = Integer.toString(prefMain.getInt("width", 0)) + "x" + Integer.toString(prefMain.getInt("height", 0)); if (prefMain.getBoolean("debug_mode", false)) { SharedPreferences prefCurrent = getPrefCurrent(context); currentRes = prefCurrent.getString("size", "reset"); if ("reset".equals(currentRes)) currentRes = nativeRes; } else { if ((context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT && !prefMain.getBoolean("landscape", false)) || (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && prefMain.getBoolean("landscape", false))) { currentRes = Integer.toString(metrics.widthPixels) + "x" + Integer.toString(metrics.heightPixels); } else if ((context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && !prefMain.getBoolean("landscape", false)) || (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT && prefMain.getBoolean("landscape", false))) { currentRes = Integer.toString(metrics.heightPixels) + "x" + Integer.toString(metrics.widthPixels); } } if (requestedRes.equals("reset")) requestedRes = nativeRes; return !requestedRes.equals(currentRes); }
From source file:gr.ioanpier.auth.users.memorypaintings.ImageDetails.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image_details); String imagePath;/*www . ja v a2 s .com*/ imagePath = getIntent().getStringExtra("IMAGE_ID"); ImageView imageView = ((ImageView) (findViewById(R.id.image))); if (imagePath == null) { ((findViewById(R.id.image))).setBackgroundColor( ContextCompat.getColor(this, getIntent().getIntExtra("COLOR_ID", R.color.black))); } else if (!imagePath.isEmpty()) { String drawableDesc = getIntent().getStringExtra("IMAGE_DESC"); ((TextView) (findViewById(R.id.text))).setText(drawableDesc); imageView.setImageBitmap(null); DisplayMetrics displayMetrics = new DisplayMetrics(); //WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); // the results will be higher than using the activity context object or the getWindowManager() shortcut WindowManager wm = getWindowManager(); wm.getDefaultDisplay().getMetrics(displayMetrics); int screenWidth = displayMetrics.widthPixels / 2; int screenHeight = displayMetrics.heightPixels / 2; imageView.setImageBitmap(Utility.decodeSampledBitmapFromPath(imagePath, screenWidth, screenHeight)); } else { int color = getIntent().getIntExtra("COLOR_ID", R.color.black); imageView.setBackgroundColor(ContextCompat.getColor(this, color)); } @SuppressWarnings("UnusedAssignment") PhotoViewAttacher mAttacher = new PhotoViewAttacher(imageView); }
From source file:net.genus.plugins.screensize.ScreenSize.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("getSize")) { Log.d("ScreenSizeDebug", "getSize"); DisplayMetrics metrics = new DisplayMetrics(); Context context = this.cordova.getActivity().getApplicationContext(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); Log.d("ScreenSizeDebug", "Pixles wide: " + metrics.widthPixels); Log.d("ScreenSizeDebug", "Pixels high: " + metrics.heightPixels); Log.d("ScreenSizeDebug", "DPI Density: " + metrics.densityDpi); int width = metrics.widthPixels; int height = metrics.heightPixels; int dens = metrics.densityDpi; double wi = (double) width / (double) dens; double hi = (double) height / (double) dens; Log.d("ScreenSizeDebug", "Width: " + wi); Log.d("ScreenSizeDebug", "Height: " + hi); double x = Math.pow(wi, 2); double y = Math.pow(hi, 2); double screenInches = Math.sqrt(x + y); Log.d("ScreenSizeDebug", "Screen size: " + screenInches); screenInches = screenInches * 1000; int result = (int) screenInches; Log.d("ScreenSizeDebug", "" + result); callbackContext.success(result); return true; }//from w ww . j ava2 s . c o m return false; }
From source file:com.itime.team.itime.fragments.QRCodeFragment.java
@NonNull @Override/*from w w w . ja v a 2s . c o m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { final Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.fragment_profile_qrcode); ImageView imageView = (ImageView) dialog.findViewById(R.id.setting_profile_qrcode_img); final Bundle arguments = getArguments(); if (!arguments.isEmpty()) { mUserId = arguments.getString(QRCODE_STRING); } Bitmap qrCodeBitmap; // method1: change a fix dip to pixel //final int dim = DensityUtil.dip2px(getContext(), 600); // method2: get the display size and scale into 7/8 // This assumes the view is full screen, which is a good assumption WindowManager manager = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point displaySize = new Point(); display.getSize(displaySize); int width = displaySize.x; int height = displaySize.y; int smallerDimension = width < height ? width : height; final int dim = smallerDimension * 7 / 8; try { qrCodeBitmap = barcodeEncoder.encodeBitmap(mUserId, BarcodeFormat.QR_CODE, dim, dim); imageView.setImageBitmap(qrCodeBitmap); } catch (WriterException e) { Toast.makeText(getActivity(), "QRCode text can not be empty", Toast.LENGTH_SHORT).show(); } return dialog; }
From source file:com.pimp.instincts.adapters.GalleryAdapter.java
public GalleryAdapter(Context context, ArrayList<String> imagesList) { this.context = context; this.imagesList = imagesList; WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size);//from w ww . j av a2 s .co m screenWidth = size.x; }