List of usage examples for android.graphics Bitmap createScaledBitmap
public static Bitmap createScaledBitmap(@NonNull Bitmap src, int dstWidth, int dstHeight, boolean filter)
From source file:com.google.android.apps.muzei.util.PanView.java
private void updateScaledImage() { if (mImage == null) { return;/*from www.j a v a2 s. c o m*/ } int width = mImage.getWidth(); int height = mImage.getHeight(); if (width > height) { float scalingFactor = mHeight * 1f / height; mScaledImage = Bitmap.createScaledBitmap(mImage, (int) (scalingFactor * width), mHeight, true); } else { float scalingFactor = mWidth * 1f / width; mScaledImage = Bitmap.createScaledBitmap(mImage, mWidth, (int) (scalingFactor * height), true); } ImageBlurrer blurrer = new ImageBlurrer(getContext()); mBlurredImage = blurrer.blurBitmap(mScaledImage, ImageBlurrer.MAX_SUPPORTED_BLUR_PIXELS, 0f); blurrer.destroy(); // Center the image mOffsetX = (mWidth - mScaledImage.getWidth()) / 2; mOffsetY = (mHeight - mScaledImage.getHeight()) / 2; invalidate(); }
From source file:at.flack.receiver.FacebookReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras();//from ww w. ja v a 2s . c om try { if (main instanceof FbMessageOverview && bundle.getString("type").equals("message")) { ((FbMessageOverview) main).addNewMessage( new FacebookMessage(bundle.getString("fb_name"), bundle.getString("fb_message"), bundle.getString("fb_img"), bundle.getLong("fb_id"), bundle.getString("fb_tid"))); } else if (main instanceof FbMessageOverview && bundle.getString("type").equals("readreceipt")) { ((FbMessageOverview) main).changeReadReceipt(bundle.getLong("fb_time"), bundle.getLong("fb_reader")); } else if (main instanceof FbMessageOverview && bundle.getString("type").equals("typ")) { ((FbMessageOverview) main).changeTypingStatus(bundle.getLong("my_id"), bundle.getLong("fb_id"), bundle.getBoolean("fb_from_mobile"), bundle.getInt("fb_status")); } else if (main instanceof FbMessageOverview && bundle.getString("type").equals("img_message")) { ((FbMessageOverview) main).addNewMessage(new FacebookImageMessage(bundle.getString("fb_name"), bundle.getString("fb_image"), bundle.getString("fb_preview"), bundle.getString("fb_img"), bundle.getLong("fb_id"), bundle.getString("fb_tid"))); } else if (bundle.getString("type").equals("read")) { killNotification(context, new MarkAsRead(bundle.getString("fb_tid"), bundle.getBoolean("fb_markas"))); } else if (bundle.getString("type").equals("message") || bundle.getString("type").equals("img_message")) { sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); if (!sharedPrefs.getBoolean("notification_fbs", true)) return; notify = sharedPrefs.getBoolean("notifications", true); vibrate = sharedPrefs.getBoolean("vibration", true); headsup = sharedPrefs.getBoolean("headsup", true); led_color = sharedPrefs.getInt("notification_light", -16776961); boolean all = sharedPrefs.getBoolean("all_fb", true); if (notify == false) return; if (bundle.getLong("fb_id") == bundle.getLong("my_id")) { return; } NotificationCompat.Builder mBuilder = null; boolean use_profile_picture = false; Bitmap profile_picture = null; String origin_name = bundle.getString("fb_name"); try { profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap( ProfilePictureCache.getInstance(context).get(origin_name), 200, 200, false), 300); use_profile_picture = true; } catch (Exception e) { use_profile_picture = false; } Resources res = context.getResources(); if (bundle.getString("type").equals("img_message")) { bundle.putString("fb_message", res.getString(R.string.fb_notification_new_image)); } int lastIndex = bundle.getString("fb_message").lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(bundle.getString("fb_message").substring(0, lastIndex))) { mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name) .setColor(0xFF175ea2) .setContentText(res.getString(R.string.sms_receiver_new_encrypted_fb)) .setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { // normal or handshake if (bundle.getString("fb_message").charAt(0) == '%' && (bundle.getString("fb_message").length() == 10 || bundle.getString("fb_message").length() == 9)) { if (lastIndex > 0 && Base64.isBase64(bundle.getString("fb_message").substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFF175ea2) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (bundle.getString("fb_message").charAt(0) == '%' && bundle.getString("fb_message").length() >= 120 && bundle.getString("fb_message").length() < 125) { if (lastIndex > 0 && Base64.isBase64(bundle.getString("fb_message").substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFF175ea2) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (all) { // normal message mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name) .setColor(0xFF175ea2).setContentText(bundle.getString("fb_message")) .setAutoCancel(true).setStyle(new NotificationCompat.BigTextStyle() .bigText(bundle.getString("fb_message"))); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } // } Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); mBuilder.setLights(led_color, 750, 4000); if (vibrate) { mBuilder.setVibrate(new long[] { 0, 100, 200, 300 }); } Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.putExtra("FACEBOOK_NAME", origin_name); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); if (Build.VERSION.SDK_INT >= 16 && headsup) mBuilder.setPriority(Notification.PRIORITY_HIGH); if (Build.VERSION.SDK_INT >= 21) mBuilder.setCategory(Notification.CATEGORY_MESSAGE); final NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (!MainActivity.isOnTop) mNotificationManager.notify(8, mBuilder.build()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:me.piebridge.prevent.ui.UserGuideActivity.java
private Drawable cropDrawable(Drawable icon) { int width = getPixel(0x20); if (icon.getMinimumWidth() > width && icon instanceof BitmapDrawable) { Bitmap bitmap = Bitmap.createScaledBitmap(((BitmapDrawable) icon).getBitmap(), width, width, false); return new BitmapDrawable(getResources(), bitmap); }// w ww. j a v a2s. co m return icon; }
From source file:com.open.file.manager.IconLoader.java
/** * Get icon from the apk file//from www . j a va2s . c o m * @param current apk to load icon from * @return icon bitmap */ private Bitmap getApkIcon(File current) { try { Bitmap icon = null; PackageInfo packageInfo = mycont.getPackageManager().getPackageArchiveInfo(current.getAbsolutePath(), PackageManager.GET_ACTIVITIES); if (packageInfo != null) { ApplicationInfo appInfo = packageInfo.applicationInfo; if (Build.VERSION.SDK_INT >= 8) { appInfo.sourceDir = current.getAbsolutePath(); appInfo.publicSourceDir = current.getAbsolutePath(); } Drawable apkico = appInfo.loadIcon(mycont.getPackageManager()); final float scale = mycont.getResources().getDisplayMetrics().density; final int targetHeight = Math.round(Consts.ICON_SIZE * scale); final int targetWidth = Math.round(Consts.ICON_SIZE * scale); icon = ((BitmapDrawable) apkico).getBitmap(); icon = Bitmap.createScaledBitmap(icon, targetWidth, targetHeight, false); } return icon; } catch (Exception exc) { return null; } }
From source file:com.github.piasy.rxqrcode.RxQrCode.java
/** * @Deprecated use {@link #generateQrCodeFile(Context, String, int, int)} to avoid bitmap * management./* w ww. ja v a 2 s .co m*/ */ @Deprecated public static Observable<Bitmap> generateQrCode(String content, int width, int height) { return Observable.fromEmitter(emitter -> { MultiFormatWriter writer = new MultiFormatWriter(); try { BitMatrix bm = writer.encode(content, BarcodeFormat.QR_CODE, QR_CODE_LENGTH, QR_CODE_LENGTH, Collections.singletonMap(EncodeHintType.MARGIN, 0)); Bitmap bitmap = Bitmap.createBitmap(QR_CODE_LENGTH, QR_CODE_LENGTH, Bitmap.Config.ARGB_8888); for (int i = 0; i < QR_CODE_LENGTH; i++) { for (int j = 0; j < QR_CODE_LENGTH; j++) { bitmap.setPixel(i, j, bm.get(i, j) ? Color.BLACK : Color.WHITE); } } emitter.onNext(Bitmap.createScaledBitmap(bitmap, width, height, true)); emitter.onCompleted(); } catch (WriterException e) { emitter.onError(e); } }, Emitter.BackpressureMode.BUFFER); }
From source file:com.kinvey.samples.statusshare.StatusShare.java
/** * This method will be called after the user either selects a photo from their gallery or takes a picture with their camera * * @param requestCode - either PICK_FROM_FILE or PICK_FROM_CAMERA * @param resultCode - hopefully it's RESULT_OK! * @param data - contains the Path to the selected image */// www . j a va 2s . com @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != RESULT_OK) { return; } if (requestCode == PICK_FROM_FILE) { mImageCaptureUri = data.getData(); path = getRealPathFromURI(data.getData()); //from Gallery if (path == null) { path = data.getData().getPath(); //from File Manager } if (path != null) { bitmap = BitmapFactory.decodeFile(path); } Log.i(Client.TAG, "activity result, bitmap from file is -> " + String.valueOf(bitmap == null)); } else if (requestCode == PICK_FROM_CAMERA) { path = mImageCaptureUri.getPath(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = true; options.inJustDecodeBounds = true; // First decode with inJustDecodeBounds=true to check dimensions bitmap = BitmapFactory.decodeFile(path, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, 200, 150); options.inJustDecodeBounds = false; // Decode bitmap with inSampleSize set int h = 512; // height in pixels int w = 512; // width in pixels bitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(path, options), h, w, false); Log.i(Client.TAG, "activity result, bitmap from camera is -> " + String.valueOf(bitmap == null)); Log.i(Client.TAG, "activity result, path from camera is -> " + String.valueOf(path == null)); } else { Log.e(TAG, "That's not a valid request code! -> " + requestCode); } }
From source file:com.snt.bt.recon.services.ActivityRecognitionService.java
private void showNotification() { mNotificationManager = (NotificationManager) this .getSystemService(getApplicationContext().NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);//PendingIntent.FLAG_CANCEL_CURRENT //PendingIntent.FLAG_UPDATE_CURRENT Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_activity); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setContentTitle("SnT BlueScanner").setTicker("SnT BlueScanner") .setStyle(new NotificationCompat.BigTextStyle().bigText("Activity Recognition Service")) .setContentText("Activity Recognition Service").setSmallIcon(R.drawable.ic_activity) .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setOngoing(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:io.github.dector.rkpi.views.AppViewPager.java
/** * Load, scale and setup background image * * @param context activity context//from w w w. java 2 s . c o m */ private void initBackground(Context context) { Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); Point displaySize = new Point(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { display.getSize(displaySize); } else { displaySize.set(display.getWidth(), display.getHeight()); } BitmapFactory.Options decodeOptions = new BitmapFactory.Options(); decodeOptions.inJustDecodeBounds = true; BitmapFactory.decodeResource(context.getResources(), R.drawable.background); decodeOptions.inJustDecodeBounds = false; decodeOptions.inSampleSize = DeviceTools.getSampleSize(decodeOptions, displaySize); Bitmap sourceBackground = BitmapFactory.decodeResource(context.getResources(), R.drawable.background, decodeOptions); Bitmap background = Bitmap.createScaledBitmap(sourceBackground, displaySize.x, displaySize.y, true); Drawable bitmapDrawable = new BitmapDrawable(context.getResources(), background); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { setBackground(bitmapDrawable); } else { setBackgroundDrawable(bitmapDrawable); } sourceBackground.recycle(); }
From source file:github.madmarty.madsonic.util.ImageLoader.java
private void createLargeUnknownImage(Context context) { BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(R.drawable.unknown_album); Bitmap bitmap = Bitmap.createScaledBitmap(drawable.getBitmap(), imageSizeLarge, imageSizeLarge, true); bitmap = createReflection(bitmap);/*w w w . j a v a 2 s . co m*/ largeUnknownImage = Util.createDrawableFromBitmap(context, bitmap); }