List of usage examples for android.graphics BitmapFactory decodeResource
public static Bitmap decodeResource(Resources res, int id)
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static Bitmap getImage(Context context, String screenname) { BitmapLruCache mCache = App.getInstance(context).getBitmapCache(); String url;/* w ww . j av a 2s . c o m*/ try { url = Utils.getTwitter(context, AppSettings.getInstance(context)).showUser(screenname) .getBiggerProfileImageURL(); CacheableBitmapDrawable wrapper = mCache.get(url + "_notification"); if (wrapper == null) { // The bitmap isn't cached so download from the web HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); InputStream is = new BufferedInputStream(conn.getInputStream()); Bitmap image = BitmapFactory.decodeStream(is); image = ImageUtils.notificationResize(context, image); mCache.put(url + "_notification", image); return image; } else { return wrapper.getBitmap(); } } catch (Exception e) { return BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } }
From source file:com.VVTeam.ManHood.Fragment.HistogramFragment.java
private List<PolarPlotData> plotDataForSelfUserData(SelfUserData _usersData) { Bitmap orgBmp = BitmapFactory.decodeResource(getResources(), R.drawable.g_circle_b); float width = orgBmp.getWidth() * 50.0f / 100.0f; float height = width; PolarPlotData base = new PolarPlotData(1, Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_b), (int) width, (int) height, true), _usersData.getBasePoint());/* w ww.j a v a2s .co m*/ PolarPlotData mid = new PolarPlotData(3, Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_m), (int) width, (int) height, true), // BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_m), _usersData.getMidPoint()); PolarPlotData upper = new PolarPlotData(5, Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_s), (int) width, (int) height, true), // BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_s), _usersData.getUpperPoint()); PolarPlotData tip = new PolarPlotData(7, // BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_smaller), Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.b_circle_smaller), (int) width, (int) height, true), _usersData.getTipPoint()); List<PolarPlotData> list = new ArrayList<PolarPlotData>(); list.add(base); list.add(mid); list.add(upper); list.add(tip); return list; }
From source file:edu.sfsu.cs.orange.ocr.CaptureActivity.java
/** * Displays information relating to the result of OCR, and requests a translation if necessary. * /* ww w. j a v a 2 s .c o m*/ * @param ocrResult Object representing successful OCR results * @return True if a non-null result was received for OCR */ boolean handleOcrDecode(OcrResult ocrResult) { lastResult = ocrResult; // Test whether the result is null if (ocrResult.getText() == null || ocrResult.getText().equals("")) { Toast toast = Toast.makeText(this, "OCR failed. Please try again.", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); return false; } // Turn off capture-related UI elements shutterButton.setVisibility(View.GONE); statusViewBottom.setVisibility(View.GONE); statusViewTop.setVisibility(View.GONE); cameraButtonView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView bitmapImageView = (ImageView) findViewById(R.id.image_view); lastBitmap = ocrResult.getBitmap(); if (lastBitmap == null) { bitmapImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); } else { bitmapImageView.setImageBitmap(lastBitmap); } // Display the recognized text TextView sourceLanguageTextView = (TextView) findViewById(R.id.source_language_text_view); sourceLanguageTextView.setText(sourceLanguageReadable); TextView ocrResultTextView = (TextView) findViewById(R.id.ocr_result_text_view); ocrResultTextView.setText(ocrResult.getText()); String rawText = ocrResult.getText(); rawText.split("\n"); String[] beerNames = rawText.split("\n"); for (String beer : beerNames) { beerQuery.asyncBeerFetch(beer, aq); } ocrResultTextView.setText(aq.getText()); // Crudely scale betweeen 22 and 32 -- bigger font for shorter text int scaledSize = Math.max(22, 32 - ocrResult.getText().length() / 4); ocrResultTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView translationLanguageLabelTextView = (TextView) findViewById( R.id.translation_language_label_text_view); TextView translationLanguageTextView = (TextView) findViewById(R.id.translation_language_text_view); TextView translationTextView = (TextView) findViewById(R.id.translation_text_view); translationLanguageLabelTextView.setVisibility(View.GONE); translationLanguageTextView.setVisibility(View.GONE); translationTextView.setVisibility(View.GONE); progressView.setVisibility(View.GONE); setProgressBarVisibility(false); return true; }
From source file:com.undatech.opaque.RemoteCanvas.java
void initializeSoftCursor() { Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.cursor); int w = bm.getWidth(); int h = bm.getHeight(); int[] tempPixels = new int[w * h]; bm.getPixels(tempPixels, 0, w, 0, 0, w, h); // Set cursor rectangle as well. myDrawable.setCursorRect(pointer.getX(), pointer.getY(), w, h, 0, 0); // Set softCursor to whatever the resource is. myDrawable.setSoftCursor(tempPixels); bm.recycle();//from w w w.j ava 2 s. c o m }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void notifySecondDMs(Context context, int secondAccount) { DMDataSource data = DMDataSource.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int numberNew = sharedPrefs.getInt("dm_unread_" + secondAccount, 0); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;//from w w w . j av a2s .c o m Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); String name; String message; String messageLong; NotificationCompat.InboxStyle inbox = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; messageLong = "<b>@" + name + "</b>: " + data.getNewestMessage(secondAccount); largeIcon = getImage(context, name); } else { // more than one dm message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); inbox = getDMInboxStyle(numberNew, secondAccount, context, message); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setAutoCancel(true) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:com.android.messaging.datamodel.BugleNotifications.java
private static void fireOffNotification(final NotificationState notificationState, final Bitmap attachmentBitmap, final Bitmap avatarBitmap, Bitmap avatarHiResBitmap) { if (notificationState.mCanceled) { if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) { LogUtil.v(TAG, "Firing off notification, but notification already canceled"); }//from www. ja v a2 s . c o m return; } final Context context = Factory.get().getApplicationContext(); if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) { LogUtil.v(TAG, "MMS picture loaded, bitmap: " + attachmentBitmap); } final NotificationCompat.Builder notifBuilder = notificationState.mNotificationBuilder; notifBuilder.setStyle(notificationState.mNotificationStyle); notifBuilder.setColor(context.getResources().getColor(R.color.notification_accent_color)); final WearableExtender wearableExtender = new WearableExtender(); setWearableGroupOptions(notifBuilder, notificationState); if (avatarHiResBitmap != null) { wearableExtender.setBackground(avatarHiResBitmap); } else if (avatarBitmap != null) { // Nothing to do here; we already set avatarBitmap as the notification icon } else { final Bitmap defaultBackground = BitmapFactory.decodeResource(context.getResources(), R.drawable.bg_sms); wearableExtender.setBackground(defaultBackground); } if (notificationState instanceof MultiMessageNotificationState) { if (attachmentBitmap != null) { // When we've got a picture attachment, we do some switcheroo trickery. When // the notification is expanded, we show the picture as a bigPicture. The small // icon shows the sender's avatar. When that same notification is collapsed, the // picture is shown in the location where the avatar is normally shown. The lines // below make all that happen. // Here we're taking the picture attachment and making a small, scaled, center // cropped version of the picture we can stuff into the place where the avatar // goes when the notification is collapsed. final Bitmap smallBitmap = ImageUtils.scaleCenterCrop(attachmentBitmap, sIconWidth, sIconHeight); ((NotificationCompat.BigPictureStyle) notificationState.mNotificationStyle) .bigPicture(attachmentBitmap).bigLargeIcon(avatarBitmap); notificationState.mNotificationBuilder.setLargeIcon(smallBitmap); // Add a wearable page with no visible card so you can more easily see the photo. final NotificationCompat.Builder photoPageNotifBuilder = new NotificationCompat.Builder( Factory.get().getApplicationContext()); final WearableExtender photoPageWearableExtender = new WearableExtender(); photoPageWearableExtender.setHintShowBackgroundOnly(true); if (attachmentBitmap != null) { final Bitmap wearBitmap = ImageUtils.scaleCenterCrop(attachmentBitmap, sWearableImageWidth, sWearableImageHeight); photoPageWearableExtender.setBackground(wearBitmap); } photoPageNotifBuilder.extend(photoPageWearableExtender); wearableExtender.addPage(photoPageNotifBuilder.build()); } maybeAddWearableConversationLog(wearableExtender, (MultiMessageNotificationState) notificationState); addDownloadMmsAction(notifBuilder, wearableExtender, notificationState); addWearableVoiceReplyAction(wearableExtender, notificationState); } // Apply the wearable options and build & post the notification notifBuilder.extend(wearableExtender); doNotify(notifBuilder.build(), notificationState); }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java
private static Bitmap getDefaultArtwork(Context context) { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; return BitmapFactory.decodeResource(context.getResources(), R.drawable.albumart_mp_unknown); }
From source file:com.aegiswallet.actions.MainActivity.java
public void notifyCoinsReceivedOrSent(Double amount, boolean received) { final NotificationCompat.Builder notification = new NotificationCompat.Builder(MainActivity.this); String eventTitle = ""; String eventLocation = ""; String eventDescription = ""; int wearIcon = 0; BigDecimal decimal = BigDecimal.valueOf(amount); BigInteger amountBigInt = decimal.toBigInteger(); if (received) { notification.setSmallIcon(R.drawable.aegis_receive_icon); notification.setContentText(getString(R.string.received_string) + " " + BasicUtils.satoshiToBTC(amountBigInt) + getString(R.string.btc_string)); eventTitle = "Aegis Receive"; eventLocation = "Aegis Wallet"; eventDescription = getString(R.string.received_string) + " " + BasicUtils.satoshiToBTC(amountBigInt) + getString(R.string.btc_string); wearIcon = R.drawable.aegis_receive_icon; } else if (!received) { notification.setSmallIcon(R.drawable.aegis_send_icon); notification.setContentText(getString(R.string.sent_string) + " " + BasicUtils.satoshiToBTC(amountBigInt) + getString(R.string.btc_string)); eventTitle = "Aegis Send"; eventLocation = "Aegis Wallet"; eventDescription = getString(R.string.sent_string) + " " + BasicUtils.satoshiToBTC(amountBigInt) + getString(R.string.btc_string); wearIcon = R.drawable.aegis_send_icon; }/* w w w . j ava 2 s .com*/ notification.setContentTitle(getString(R.string.app_name)); PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, new Intent(MainActivity.this, MainActivity.class), 0); notification.setContentIntent(pendingIntent); notification.setOngoing(false); notificationManager.notify(1, notification.getNotification()); NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle(); bigStyle.bigText(eventDescription); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.initpageicon)) .setContentTitle(eventTitle).setContentText(eventLocation).setContentIntent(pendingIntent) .setStyle(bigStyle); }