List of usage examples for android.view WindowManager getDefaultDisplay
public Display getDefaultDisplay();
From source file:com.fairphone.fplauncher3.oobe.animation.MenuTutorialAnimationView.java
private void init() { WindowManager windowMananger = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); mDisplayMetrics = new DisplayMetrics(); windowMananger.getDefaultDisplay().getMetrics(mDisplayMetrics); SCREEN_HEIGHT = mDisplayMetrics.heightPixels; SCREEN_WIDTH = mDisplayMetrics.widthPixels; if (getBackground() == null) { setBackgroundColor(0x00000000);//w ww .j a v a 2 s .com } spritePaint = new Paint(); spritePaint.setColor(0xffffffff); spriteRoot = new KWSprite(); spriteArrow = new KWSprite(); spriteHand = new KWSprite(); spriteHandShadow = new KWSprite(); spriteMenu = new KWSprite(); spriteAppIcon = new KWSprite(); spriteAppIconSelected = new KWSprite(); spriteArrow.drawable = ContextCompat.getDrawable(getContext(), R.drawable.arrow_gradient_oobe); spriteArrow.applySizeFromDrawable(); spriteHand.drawable = ContextCompat.getDrawable(getContext(), R.drawable.icn_hand_oobe); spriteHand.applySizeFromDrawable(); spriteHandShadow.drawable = ContextCompat.getDrawable(getContext(), R.drawable.oobe_hand_shadow); spriteHandShadow.applySizeFromDrawable(); spriteMenu.drawable = ContextCompat.getDrawable(getContext(), R.drawable.oobe_menu); spriteMenu.applySizeFromDrawable(); spriteAppIcon.drawable = ContextCompat.getDrawable(getContext(), R.drawable.icn_circle_oobe); spriteAppIcon.applySizeFromDrawable(); spriteAppIconSelected.drawable = ContextCompat.getDrawable(getContext(), R.drawable.icn_circle_glow_oobe); spriteAppIconSelected.applySizeFromDrawable(); spriteRoot.addChild(spriteArrow); spriteRoot.addChild(spriteHand); //spriteRoot.addChild(spriteHandShadow); spriteRoot.addChild(spriteMenu); spriteMenu.addChild(spriteAppIcon); //spriteMenu.addChild(spriteAppIconSelected); spriteRoot.alpha = 0; spriteAppIconSelected.alpha = 0; // Animation setup animationManager = new KWAnimationManager(); animationGroupSwipe = new KWAnimationGroup(animationManager); animationGroupSelectApp = new KWAnimationGroup(animationManager); mHandStopPointXinDP = SCREEN_WIDTH - DynamicGrid.pxFromDp(100, mDisplayMetrics); mArrowStopPointXinDP = SCREEN_WIDTH - DynamicGrid.pxFromDp(120, mDisplayMetrics); setupSwipeAnimation(); setupAppOpenAnimation(); }
From source file:com.dsdar.thosearoundme.util.MemberAddContactsListFragment.java
@SuppressLint("NewApi") public static int getWidth(Context mContext) { int width = 0; WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (Build.VERSION.SDK_INT > 12) { Point size = new Point(); display.getSize(size);//from www .j a v a 2 s .c om width = size.x; } else { width = display.getWidth(); // Deprecated } return width; }
From source file:com.dsdar.thosearoundme.util.MemberAddContactsListFragment.java
@SuppressLint("NewApi") public static int getHeight(Context mContext) { int height = 0; WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (Build.VERSION.SDK_INT > 12) { Point size = new Point(); display.getSize(size);/*ww w .j a va 2s . co m*/ height = size.y; } else { height = display.getHeight(); // Deprecated } return height; }
From source file:com.nikola.despotoski.drawerlayoutedgetoggle.DrawerLayoutEdgeToggle.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") private int getScreenWidth() { Point size = new Point(); WindowManager w = mActivity.getWindowManager(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { w.getDefaultDisplay().getSize(size); return size.x; } else {//from w w w . j av a 2 s . co m Display d = w.getDefaultDisplay(); return d.getWidth(); } }
From source file:com.joanzapata.PDFViewActivity.java
public void convertQrCode(String _message) { // TODO Auto-generated method stub // Find screen size WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point point = new Point(); display.getSize(point);/* ww w .j a va2 s.c om*/ int width = point.x; int height = point.y; int smallerDimension = width < height ? width : height; smallerDimension = smallerDimension * 3 / 4; // Encode with a QR Code image QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(_message, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), smallerDimension); try { Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream.toByteArray(); bitmapQrcode = Base64.encodeToString(byteArray, Base64.DEFAULT); } catch (WriterException e) { e.printStackTrace(); } }
From source file:com.example.android.navigationdrawer.QRCode.java
public void onQR(View v) { switch (v.getId()) { case R.id.button1: String qrInputText = MidiFile.readString; //Find screen size WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point point = new Point(); display.getSize(point);/*from w ww. j a v a 2 s. co m*/ int width = point.x; int height = point.y; int smallerDimension = width < height ? width : height; smallerDimension = smallerDimension * 3 / 4; //Encode with a QR Code image QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrInputText, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), smallerDimension); try { Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); ImageView myImage = (ImageView) findViewById(R.id.imageView1); myImage.setImageBitmap(bitmap); // Get screen size Display display1 = this.getWindowManager().getDefaultDisplay(); Point size = new Point(); display1.getSize(size); int screenWidth = size.x; int screenHeight = size.y; // Get target image size Bitmap bitmap1 = qrCodeEncoder.encodeAsBitmap(); int bitmapHeight = bitmap1.getHeight(); int bitmapWidth = bitmap1.getWidth(); // Scale the image down to fit perfectly into the screen // The value (250 in this case) must be adjusted for phone/tables displays while (bitmapHeight > (screenHeight - 250) || bitmapWidth > (screenWidth - 250)) { bitmapHeight = bitmapHeight / 2; bitmapWidth = bitmapWidth / 2; } // Create resized bitmap image BitmapDrawable resizedBitmap = new BitmapDrawable(this.getResources(), Bitmap.createScaledBitmap(bitmap, bitmapWidth, bitmapHeight, false)); // Create dialog Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.thumbnail); ImageView image = (ImageView) dialog.findViewById(R.id.imageview); // !!! Do here setBackground() instead of setImageDrawable() !!! // image.setBackground(resizedBitmap); // Without this line there is a very small border around the image (1px) // In my opinion it looks much better without it, so the choice is up to you. dialog.getWindow().setBackgroundDrawable(null); dialog.show(); } catch (WriterException e) { e.printStackTrace(); } break; } }
From source file:com.rockerhieu.emojicon.EmojiconsPopup.java
private int getUsableScreenHeight() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); return metrics.heightPixels; } else {//from w w w .j av a 2 s . com return rootView.getRootView().getHeight(); } }
From source file:com.bamobile.fdtks.util.Tools.java
public static Bitmap decodeByteArray(byte[] data, int index, int length) { try {// ww w. j a v a2 s. c om WindowManager wm = (WindowManager) SplashActivity.getInstance() .getSystemService(Context.WINDOW_SERVICE); //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; o.inInputShareable = true; o.inPurgeable = true; o.inDither = false; BitmapFactory.decodeByteArray(data, index, length, o); //The new size we want to scale to final int IMAGE_MAX_SIZE = wm.getDefaultDisplay().getWidth(); //Find the correct scale value. It should be the power of 2. int scale = 1; if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) { scale = (int) Math.pow(2, (int) Math.ceil( Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } //Decode with inSampleSize o.inSampleSize = scale; o.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray(data, index, length, o); } catch (Exception e) { Log.e("Tools.decodeByteArray", e.getMessage(), e); } return null; }
From source file:com.phonegap.customcamera.NativeCameraLauncher.java
@Override public void run() { WindowManager windowManager = (WindowManager) this.cordova.getActivity().getApplicationContext() .getSystemService(this.cordova.getActivity().getApplicationContext().WINDOW_SERVICE); int rotation = windowManager.getDefaultDisplay().getRotation(); // Read in bitmap of captured image Bitmap bitmap;/*from w w w.j av a 2 s.com*/ ExifHelper exif = new ExifHelper(); //Log.i("orientation", rotation+" rotation"); int rotate = rotation; try { // Create an ExifHelper to save the exif data that is lost // during compression exif.createInFile(getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic-" + this.date + ".jpg"); exif.readExifData(); /*Auskommentiert weil es immer auf Querformat gedreht hat*/ // rotate = exif.getOrientation(); Log.i("orientation", rotate + " "); // rotate = 90; try { bitmap = android.provider.MediaStore.Images.Media .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri); Log.i("orientation", bitmap.getWidth() + " " + bitmap.getHeight()); if (bitmap.getWidth() > bitmap.getHeight()) { rotate = rotate + 90; } } catch (FileNotFoundException e) { Uri uri = resultIntent.getData(); android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver(); bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); } // If bitmap cannot be decoded, this may return null if (bitmap == null) { this.failPicture("Error decoding image."); return; } bitmap = scaleBitmap(bitmap); // Add compressed version of captured image to returned media // store Uri bitmap = getRotatedBitmap(rotate, bitmap, exif); //Log.i(LOG_TAG, "URI: " + this.imageUri.toString()); OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(this.imageUri); // ByteArrayOutputStream outStream = new ByteArrayOutputStream(); // bitmap.compress(CompressFormat.JPEG, this.mQuality, outStream); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); // String imgString = Base64.encodeToString(outStream.toByteArray(), Base64.NO_WRAP); os.close(); // Restore exif data to file exif.createOutFile(this.imageUri.getPath()); exif.writeExifData(); // Send Uri back to JavaScript for viewing image this.callbackContext .sendPluginResult(new PluginResult(PluginResult.Status.OK, this.imageUri.getPath())); // this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, imgString)); bitmap.recycle(); bitmap = null; System.gc(); } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } }
From source file:com.byteshaft.medicosperuanos.utils.Helper.EmojiconsPopup.java
private int getUsableScreenHeight() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); return metrics.heightPixels; } else {/*from w w w.j ava 2 s. c o m*/ return rootView.getRootView().getHeight(); } }