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.velia_systems.menuphoto.connection.ImageDownloader.java
/** * Same as download but the image is always downloaded and the cache is not used. * Kept private at the moment as its interest is not clear. *///www . ja v a2 s.c om private void forceDownload(String url, ImageView imageView, Bitmap bitmap, ProgressBar progress) { // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys. if (url == null) { imageView.setImageDrawable(null); return; } if (cancelPotentialDownload(url, imageView)) { switch (mode) { case NO_ASYNC_TASK: bitmap = downloadBitmap(url); // Log.d("ImageDownloader", "Sizes: " + bitmap.getWidth() + "x" + bitmap.getHeight()); int width = bitmap.getWidth(); int height = bitmap.getHeight(); int destHeight = 100 * height / width; Bitmap bmp1 = Bitmap.createScaledBitmap(bitmap, 100, destHeight, false); bitmap.recycle(); addBitmapToCache(url, bmp1); imageView.setImageBitmap(bmp1); progress.setVisibility(View.GONE); break; case NO_DOWNLOADED_DRAWABLE: imageView.setMinimumHeight(50); BitmapDownloaderTask task = new BitmapDownloaderTask(imageView, progress); task.execute(url); break; case CORRECT: task = new BitmapDownloaderTask(imageView, progress); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task); imageView.setImageDrawable(downloadedDrawable); imageView.setMinimumHeight(50); task.execute(url); break; } } }
From source file:at.flack.receiver.SmsReceiver.java
@Override public void onReceive(Context context, Intent intent) { sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); 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_sms", true); if (notify == false) return;//from www . ja va 2 s .co m Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); str += msgs[i].getMessageBody().toString(); str += "\n"; } NotificationCompat.Builder mBuilder; if (main != null) { main.addNewMessage(str); return; } boolean use_profile_picture = false; Bitmap profile_picture = null; String origin_name = null; try { origin_name = getContactName(context, msgs[0].getDisplayOriginatingAddress()); if (origin_name == null) origin_name = msgs[0].getDisplayOriginatingAddress(); } catch (Exception e) { } if (origin_name == null) origin_name = "Unknown"; try { profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap( fetchThumbnail(context, msgs[0].getDisplayOriginatingAddress()), 200, 200, false), 300); use_profile_picture = true; } catch (Exception e) { use_profile_picture = false; } Resources res = context.getResources(); int positionOfBase64End = str.lastIndexOf("="); if (positionOfBase64End > 0 && Base64.isBase64(str.substring(0, positionOfBase64End))) { mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.raven_notification_icon) .setContentTitle(origin_name).setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_new_encrypted)).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 if (str.toString().charAt(0) == '%' && (str.toString().length() == 10 || str.toString().length() == 9)) { int lastIndex = str.toString().lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.raven_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 (str.toString().charAt(0) == '%' && str.toString().length() >= 120 && str.toString().length() < 125) { // DH Handshake int lastIndex = str.toString().lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.raven_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 { // unencrypted messages if (all) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C).setContentText(str).setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(str)) .setSmallIcon(R.drawable.raven_notification_icon); 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.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); resultIntent.putExtra("CONTACT_NUMBER", msgs[0].getOriginatingAddress()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, 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 (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED") && !MainActivity.isOnTop) mNotificationManager.notify(7, mBuilder.build()); // Save SMS if default app if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && Telephony.Sms.getDefaultSmsPackage(context).equals(context.getPackageName())) { ContentValues values = new ContentValues(); values.put("address", msgs[0].getDisplayOriginatingAddress()); values.put("body", str.replace("\n", "").replace("\r", "")); if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) context.getContentResolver().insert(Telephony.Sms.Inbox.CONTENT_URI, values); } } }
From source file:com.diona.videoplugin.CameraUtil.java
/** * Get the bitmap returned via the camera utility. * //from w ww . ja va 2 s .c o m * @param activity * context used to access the file system. * @param data * Intent that contains the returned data from the camera utility * @return Bitmap the bitmap that is returned */ public static Bitmap getBitmap(final Activity activity, final Intent data) { try { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = SAMPLE_QUALITY; final File file = FileCacheUtil.getOutputMediaFile(); final Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options); final int nh = (int) (bitmap.getHeight() * (SCALED_HEIGHT / bitmap.getWidth())); final Bitmap scaled = Bitmap.createScaledBitmap(bitmap, (int) SCALED_HEIGHT, nh, true); // Delete the file once we have the bitmap FileUtils.deleteQuietly(file); return scaled; } catch (final NullPointerException e) { LogUtil.error(TAG, e); return null; } }
From source file:com.mobicage.rogerthat.NavigationItem.java
public Drawable getFooterIcon(Context context) { if (this.faIcon == null) { BitmapDrawable image = (BitmapDrawable) context.getResources().getDrawable(this.iconId); int w = UIUtils.convertDipToPixels(context, 34); Bitmap bitmapResized = Bitmap.createScaledBitmap(image.getBitmap(), w, w, false); return new BitmapDrawable(context.getResources(), bitmapResized); }//from www .j a v a2s .c o m return new IconicsDrawable(context, this.faIcon).color(ContextCompat.getColor(context, R.color.mc_white)) .sizeDp(20); }
From source file:co.nerdart.ourss.activity.EntriesListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UiUtils.setPreferenceTheme(this); super.onCreate(savedInstanceState); ActionBar actionBar = getActionBar(); if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true); Intent intent = getIntent();/*from w w w . java2s .c o m*/ long feedId = intent.getLongExtra(FeedColumns._ID, 0); String title = null; if (feedId > 0) { Cursor cursor = getContentResolver().query(FeedColumns.CONTENT_URI(feedId), FEED_PROJECTION, null, null, null); if (cursor.moveToFirst()) { title = cursor.isNull(0) ? cursor.getString(1) : cursor.getString(0); iconBytes = cursor.getBlob(2); } cursor.close(); } if (title != null) { setTitle(title); } if (savedInstanceState == null) { EntriesListFragment fragment = new EntriesListFragment(); Bundle args = new Bundle(); args.putParcelable(EntriesListFragment.ARG_URI, intent.getData()); fragment.setArguments(args); fragment.setHasOptionsMenu(true); getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment, "fragment").commit(); } if (iconBytes != null && iconBytes.length > 0) { int bitmapSizeInDip = UiUtils.dpToPixel(24); Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length); if (bitmap != null) { if (bitmap.getHeight() != bitmapSizeInDip) { bitmap = Bitmap.createScaledBitmap(bitmap, bitmapSizeInDip, bitmapSizeInDip, false); } getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } } if (MainActivity.mNotificationManager == null) { MainActivity.mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); } }
From source file:com.scanvine.android.util.SVDownloadManager.java
private boolean fetchDrawable(Context context, String urlString, File localFile) { try {/*from w w w. j a v a 2 s .c om*/ File tempFile = new File("" + localFile + "_tmp"); boolean fetched = fetchFile(context, urlString, tempFile); if (fetched) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile("" + tempFile, options); //Log.i(""+this, "Decoded file: size "+options.outHeight+"x"+options.outWidth); options.inSampleSize = calculateInSampleSize(options, 100, 100); options.inJustDecodeBounds = false; Bitmap bmp = BitmapFactory.decodeFile("" + tempFile, options); //Log.i(""+this, "Sampled file: size "+options.outHeight+"x"+options.outWidth); Bitmap resized = Bitmap.createScaledBitmap(bmp, 100, 100, true); FileOutputStream out = new FileOutputStream(localFile); resized.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); tempFile.delete(); } return true; } catch (Exception ex) { Log.e("" + this, "fetchDrawable failed", ex); return false; } }
From source file:org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkBookmarkRow.java
@Override public void onLargeIconAvailable(Bitmap icon, int fallbackColor) { if (icon == null) { mIconGenerator.setBackgroundColor(fallbackColor); icon = mIconGenerator.generateIconForUrl(mUrl); mIconImageView.setImageDrawable(new BitmapDrawable(getResources(), icon)); } else {//from w ww .j a v a 2 s. co m RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(getResources(), Bitmap.createScaledBitmap(icon, mDisplayedIconSize, mDisplayedIconSize, false)); roundedIcon.setCornerRadius(mCornerRadius); mIconImageView.setImageDrawable(roundedIcon); } }
From source file:com.vk.sdk.VKCaptchaDialog.java
private void loadImage() { VKHttpOperation imageOperation = new VKHttpOperation(new HttpGet(mCaptchaError.captchaImg)); imageOperation.setHttpOperationListener(new VKHTTPOperationCompleteListener() { @Override/*w w w .j a v a 2 s . co m*/ public void onComplete(VKHttpOperation operation, byte[] response) { Bitmap captchaImage = BitmapFactory.decodeByteArray(response, 0, response.length); captchaImage = Bitmap.createScaledBitmap(captchaImage, (int) (captchaImage.getWidth() * mDensity), (int) (captchaImage.getHeight() * mDensity), true); mCaptchaImage.setImageBitmap(captchaImage); mCaptchaImage.setVisibility(View.VISIBLE); mProgressBar.setVisibility(View.GONE); } @Override public void onError(VKHttpOperation operation, VKError error) { loadImage(); } }); VKHttpClient.enqueueOperation(imageOperation); }
From source file:com.quuzz.tbg.recyclerview.CustomAdapter.java
private static Bitmap resizeImageForImageView(Bitmap bitmap, boolean forThumbs) { View fragView = context.findViewById(R.id.recyclerView); Bitmap resizedBitmap = null;// w ww. j a va 2 s . c om int originalWidth = bitmap.getWidth(); int originalHeight = bitmap.getHeight(); int newWidth = fragView.getWidth(); int newHeight = fragView.getHeight(); if (forThumbs) { newWidth = newWidth / 3; } float multFactor = -1.0F; if (originalHeight < originalWidth) { multFactor = (float) originalWidth / (float) originalHeight; newWidth = (int) (newHeight * multFactor); } else { multFactor = (float) originalHeight / (float) originalWidth; newHeight = (int) (newWidth * multFactor); } resizedBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false); return resizedBitmap; }
From source file:com.truemind.selidpic_v20.ui.GalleryActivity.java
/**Android 6.0 ?? ??. * ?/*from w w w . ja va 2s .c om*/ * * @param ImageUri ? ImageSelect ?? Uri * @return Bitmap 1/4 ? ImageView * */ public Bitmap resizeBitmapWithURL(Uri ImageUri) { try { imageStream = getContentResolver().openInputStream(ImageUri); } catch (FileNotFoundException e) { e.printStackTrace(); } image_bitmap = BitmapFactory.decodeStream(imageStream); int dstWidth = image_bitmap.getWidth() / 2; int dstHeight = image_bitmap.getHeight() / 2; return Bitmap.createScaledBitmap(image_bitmap, dstWidth, dstHeight, true); }