List of usage examples for android.graphics BitmapFactory decodeResource
public static Bitmap decodeResource(Resources res, int id)
From source file:Main.java
/** * Encodes an ImageView into a base-64 byte array representation. Encoding compression depends * on the quality parameter passed. 0 is the most compressed (lowest quality) and 100 is the * least compressed (highest quality)./*from ww w. j a v a 2 s . com*/ * * @param context * @param res the resource id of an ImageView * @param quality The amount of compression, where 0 is the lowest quality and 100 is the * highest * @return the raw base-64 image data compressed accordingly */ public static byte[] encodeBase64Image(Context context, int res, int quality) { // ensure quality is between 0 and 100 (inclusive) quality = Math.max(LOWEST_QUALITY, Math.min(HIGHEST_QUALITY, quality)); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), res); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, quality, stream); return stream.toByteArray(); }
From source file:Main.java
/** * Create bitmap with blur effect.//from w ww . j a v a 2s . c o m * * @param context * application context * @param resId * bitmap resource id * @param radius * the radius of the blur. Supported range 0 < radius <= 25 * @return bitmap that has been added blur effect */ public static Bitmap createBlurBitmap(Context context, int resId, int radius) { return addBlurEffect(context, BitmapFactory.decodeResource(context.getResources(), resId), radius); }
From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java
public static ArrayList<SocialItem> getTwitterItems(Context context, String tag, int maximum) { String twitterSearch = "http://search.twitter.com/search.json?q=" + tag; ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>(); // TODO Android 2.2 thinks that "Wed, 19 Sep 2012 16:35:43 +0000" is invalid // with this formatter SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); try {/*from w w w.jav a2 s . c o m*/ Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.twitter_icon); JSONObject result = HTTPWrapper.get(twitterSearch); JSONArray items = result.getJSONArray("results"); int len = items.length(); if ((len > 0) && (maximum > 0) && (len > maximum)) len = maximum; for (int i = 0; i < len; i++) { JSONObject jsonItem = items.getJSONObject(i); Bitmap image = HTTPWrapper.getImage(jsonItem.getString("profile_image_url")); Date formattedDate = new Date(); try { formattedDate = formatter.parse(jsonItem.getString("created_at")); } catch (ParseException e) { Log.d("SUSEConferences", "Invalid date string: " + jsonItem.getString("created_at")); e.printStackTrace(); } String user = jsonItem.getString("from_user"); SocialItem newItem = new SocialItem(SocialItem.TWITTER, user, jsonItem.getString("text"), formattedDate, DateUtils .formatDateTime(context, formattedDate.getTime(), DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE), image, icon); String link = "http://twitter.com/" + user + "/status/" + jsonItem.getString("id_str"); newItem.setLink(link); socialItems.add(newItem); } } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return socialItems; }
From source file:com.careme.apvereda.careme.DailyAlarm.java
@Override public void onReceive(Context context, Intent intent) { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_notifications); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_notsmall).setLargeIcon(bitmap) .setContentTitle(context.getResources().getText(R.string.notifTittle)) .setContentText(context.getResources().getText(R.string.notifBody)) .setVibrate(new long[] { 100, 250, 100, 500 }); Intent resultIntent = new Intent(context, MainActivity.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); int mNotificationId = 001; NotificationManager mNotifyMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotifyMgr.notify(mNotificationId, mBuilder.build()); }
From source file:com.midisheetmusic.ChooseSongActivity.java
@Override public void onCreate(Bundle state) { globalActivity = this; super.onCreate(state); Bitmap allFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.allfilesicon); Bitmap recentFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.recentfilesicon); Bitmap browseFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.browsefilesicon); final TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("All").setIndicator("All", new BitmapDrawable(allFilesIcon)) .setContent(new Intent(this, AllSongsActivity.class))); tabHost.addTab(tabHost.newTabSpec("Recent").setIndicator("Recent", new BitmapDrawable(recentFilesIcon)) .setContent(new Intent(this, RecentSongsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); tabHost.addTab(tabHost.newTabSpec("Browse").setIndicator("Browse", new BitmapDrawable(browseFilesIcon)) .setContent(new Intent(this, FileBrowserActivity.class))); }
From source file:com.achep.acdisplay.notifications.NotificationHelper.java
@NonNull public static Notification buildNotification(@NonNull Context context, final int id, @NonNull Object... objects) { final Resources res = context.getResources(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.stat_acdisplay).setColor(App.ACCENT_COLOR).setAutoCancel(true); PendingIntent pi = null;/*from www . j a va2s . c om*/ switch (id) { case App.ID_NOTIFY_TEST: { NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(res.getString(R.string.notification_test_message_large)); builder.setStyle(bts).setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.notification_test_message)) .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); break; } case App.ID_NOTIFY_BATH: { CharSequence contentText = (CharSequence) objects[0]; Intent contentIntent = (Intent) objects[1]; // Build notification pi = PendingIntent.getActivity(context, id, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentTitle(res.getString(R.string.service_bath)).setContentText(contentText) .setPriority(Notification.PRIORITY_MIN); break; } case App.ID_NOTIFY_INIT: { builder.setSmallIcon(R.drawable.stat_notify).setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.notification_init_text)) .setPriority(Notification.PRIORITY_MIN); break; } case App.ID_NOTIFY_APP_AUTO_DISABLED: { CharSequence summary = (CharSequence) objects[0]; NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(res.getString(R.string.permissions_auto_disabled)).setSummaryText(summary); builder.setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher)) .setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.permissions_auto_disabled)) .setPriority(Notification.PRIORITY_HIGH).setStyle(bts); break; } default: throw new IllegalArgumentException(); } if (pi == null) { pi = PendingIntent.getActivity(context, id, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); } return builder.setContentIntent(pi).build(); }
From source file:com.benext.thibault.appsample.notification.builder.NotificationBuilder.java
public static NotificationCompat.Builder buildNotificationSimpleNBackground(Context context) { Bitmap restoImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.resto); return (NotificationCompat.Builder) buildNotificationSimple(context) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(restoImg) .setBigContentTitle(context.getString(R.string.new_resto)) .setSummaryText(context.getString(R.string.new_resto_desc))); }
From source file:com.midisheetmusicmemo.ChooseSongActivity.java
@Override public void onCreate(Bundle state) { globalActivity = this; TommyConfig.init(this); super.onCreate(state); Bitmap allFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.allfilesicon); Bitmap recentFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.recentfilesicon); Bitmap browseFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.browsefilesicon); final TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("All").setIndicator("All", new BitmapDrawable(allFilesIcon)) .setContent(new Intent(this, AllSongsActivity.class))); tabHost.addTab(tabHost.newTabSpec("Recent").setIndicator("Recent", new BitmapDrawable(recentFilesIcon)) .setContent(new Intent(this, RecentSongsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); tabHost.addTab(tabHost.newTabSpec("Browse").setIndicator("Browse", new BitmapDrawable(browseFilesIcon)) .setContent(new Intent(this, FileBrowserActivity.class))); }
From source file:com.almalence.opencam.NotificationService.java
protected synchronized void showNotification() { notificationCount++;//w ww . j a v a2 s .c om // Notification already shown. if (notificationShown) return; if (notification == null) { Bitmap bigIcon = BitmapFactory.decodeResource(getResources(), R.drawable.icon); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notification = new Notification.Builder(this).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.string_processing_and_saving_image)) .setSmallIcon(getApplicationInfo().icon).setLargeIcon(bigIcon).build(); } else { notification = new NotificationCompat.Builder(this).setSmallIcon(getApplicationInfo().icon) .setLargeIcon(bigIcon).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.string_processing_and_saving_image)).build(); } } startForeground(NOTIFICATION_ID, notification); notificationShown = true; }
From source file:com.boc.lfj.httpdemo.powerrv.demo.NotificationUtil.java
/** * ??MainActivity?//from w w w. j a v a 2 s.c om */ public static void sendSimplestNotificationWithAction(Context context) { NotificationManager mNotifyManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //?PendingIntent Intent mainIntent = new Intent(context, NormalActivity.class); PendingIntent mainPendingIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Notification.Builder NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_launcher).setAutoCancel(true).setContentTitle("tittle") .setContentText("").setNumber(++NUMBER).setPriority(2) .setContentIntent(mainPendingIntent).setFullScreenIntent(mainPendingIntent, true); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String[] events = new String[] { "CCCCCCCCCCCCCCCCC", "DDDDDDDDDDDDDDDDDDDDD", "EEEEEEEEEEEEEEEEEEEE", "FFFFFFFFFFFFFFFFFFFF", "HHHHHHHHHHHHHHHHHHH" }; // Sets a title for the Inbox in expanded layout inboxStyle.setBigContentTitle("Event tracker details:"); // Moves events into the expanded layout for (String event : events) { inboxStyle.addLine(event); } NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle(); bigPictureStyle.bigPicture(BitmapFactory.decodeResource(context.getResources(), R.mipmap.about_bg)); bigPictureStyle.setSummaryText("DDDDDDDDDDDDDDDDDDDDD"); // Moves the expanded layout object into the notification object. // builder.setStyle(bigPictureStyle); //?? Notification build = builder.build(); mNotifyManager.notify(3, build); }