List of usage examples for android.graphics BitmapFactory decodeResource
public static Bitmap decodeResource(Resources res, int id)
From source file:com.channelsoft.common.bitmapUtil.ImageWorker.java
/** * Set placeholder bitmap that shows when the the background thread is running. * * @param resId/*from w ww. j a va 2 s. c o m*/ */ public void setLoadingImage(int resId) { if (!loadingBitmaps.containsKey(resId)) { // Store loading bitmap in a hash table to prevent continual decoding loadingBitmaps.put(resId, BitmapFactory.decodeResource(mResources, resId)); } mLoadingBitmap = loadingBitmaps.get(resId); }
From source file:com.tmm.android.facebook.HelloFacebookSampleActivity.java
private void postPhoto() { if (hasPublishPermission()) { Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon); Request request = Request.newUploadPhotoRequest(Session.getActiveSession(), image, new Request.Callback() { @Override/*w w w . jav a 2s .co m*/ public void onCompleted(Response response) { showPublishResult(getString(R.string.photo_post), response.getGraphObject(), response.getError()); } }); request.executeAsync(); } else { pendingAction = PendingAction.POST_PHOTO; } }
From source file:bytes.smart.shareonfacebook.MainActivity.java
private void postPhoto() { Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher); SharePhoto sharePhoto = new SharePhoto.Builder().setBitmap(image).build(); ArrayList<SharePhoto> photos = new ArrayList<>(); photos.add(sharePhoto);/* w w w. j av a2s . c om*/ SharePhotoContent sharePhotoContent = new SharePhotoContent.Builder().setPhotos(photos).build(); if (canPresentShareDialogWithPhotos) { shareDialog.show(sharePhotoContent); } else if (hasPublishPermission()) { ShareApi.share(sharePhotoContent, shareCallback); } else { pendingAction = PendingAction.POST_PHOTO; // We need to get new permissions, then complete the action when we get called back. LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList(PERMISSION_WRITE)); } }
From source file:com.bayapps.android.robophish.MediaNotificationManager.java
private Notification createNotification() { LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata); if (mMetadata == null || mPlaybackState == null) { return null; }/*from www .j av a2 s . c om*/ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService); int playPauseButtonPosition = 0; // If skip to previous action is enabled if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp, mService.getString(R.string.label_previous), mPreviousIntent); // If there is a "skip to previous" button, the play/pause button will // be the second one. We need to keep track of it, because the MediaStyle notification // requires to specify the index of the buttons (actions) that should be visible // when in compact view. playPauseButtonPosition = 1; } addPlayPauseAction(notificationBuilder); // If skip to next action is enabled if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp, mService.getString(R.string.label_next), mNextIntent); } MediaDescriptionCompat description = mMetadata.getDescription(); String fetchArtUrl = null; Bitmap art = null; if (description.getIconUri() != null) { // This sample assumes the iconUri will be a valid URL formatted String, but // it can actually be any valid Android Uri formatted String. // async fetch the album art icon String artUrl = description.getIconUri().toString(); art = AlbumArtCache.getInstance().getBigImage(artUrl); if (art == null) { fetchArtUrl = artUrl; // use a placeholder art while the remote art is being downloaded art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art); } } notificationBuilder .setStyle(new NotificationCompat.MediaStyle() .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view .setMediaSession(mSessionToken)) .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setUsesChronometer(true) .setContentIntent(createContentIntent(description)).setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()).setLargeIcon(art); if (mController != null && mController.getExtras() != null) { String castName = mController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST); if (castName != null) { String castInfo = mService.getResources().getString(R.string.casting_to_device, castName); notificationBuilder.setSubText(castInfo); notificationBuilder.addAction(R.drawable.ic_close_black_24dp, mService.getString(R.string.stop_casting), mStopCastIntent); } } setNotificationPlaybackState(notificationBuilder); if (fetchArtUrl != null) { fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder); } return notificationBuilder.build(); }
From source file:com.example.util.ImageUtils.java
/** * // w w w .j av a2 s. c o m */ private static StateListDrawable getMaskDrawable(Context context) { StateListDrawable stateDrawable = new StateListDrawable(); int statePressed = android.R.attr.state_pressed; final Resources res = context.getResources(); stateDrawable.addState(new int[] { statePressed }, new BitmapDrawable(res, BitmapFactory.decodeResource(res, R.drawable.banner_pressed))); return stateDrawable; }
From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java
private void populateBookmarkItem(Cursor cursor, BookmarkItem item, boolean isFolder) { item.setName(cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE)); if (isFolder) { item.setUrl(null);//w w w . ja v a2 s .co m Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_folder_holo_dark); item.setFavicon(bitmap); new LookupBookmarkCount(this, item).execute(cursor.getLong(BookmarksLoader.COLUMN_INDEX_ID)); } else { String url = cursor.getString(BookmarksLoader.COLUMN_INDEX_URL); item.setUrl(url); Bitmap bitmap = getBitmap(cursor, BookmarksLoader.COLUMN_INDEX_FAVICON); item.setFavicon(bitmap); } }
From source file:audio.lisn.service.MediaNotificationManager.java
private Notification createNotification() { // LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata); // if (mMetadata == null || mPlaybackState == null) { // return null; // }//ww w .ja v a2 s . c o m Notification.Builder notificationBuilder = new Notification.Builder(mService); int playPauseButtonPosition = 1; // If skip to previous action is enabled notificationBuilder.addAction(R.drawable.ic_play_skip_previous, mService.getString(R.string.label_previous), mPreviousIntent); /* if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN){ notificationBuilder.addAction(new Notification.Action( R.drawable.ic_play_skip_previous, mService.getString(R.string.label_previous), mPreviousIntent)); }else{ notificationBuilder.addAction(R.drawable.ic_play_skip_previous, mService.getString(R.string.label_previous), mPreviousIntent); } */ // If there is a "skip to previous" button, the play/pause button will // be the second one. We need to keep track of it, because the MediaStyle notification // requires to specify the index of the buttons (actions) that should be visible // when in compact view. // addPlayPauseAction(notificationBuilder); // If skip to next action is enabled notificationBuilder.addAction(R.drawable.ic_play_skip_next, mService.getString(R.string.label_next), mNextIntent); /* if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN) { notificationBuilder.addAction(new Notification.Action(R.drawable.ic_play_skip_next, mService.getString(R.string.label_next), mNextIntent)); }else{ notificationBuilder.addAction(R.drawable.ic_play_skip_next, mService.getString(R.string.label_next), mNextIntent); } */ AudioBook audioBook = AppController.getInstance().getCurrentAudioBook(); Bitmap art = null; /* String img_path = AppUtils.getDataDirectory(mService.getApplicationContext()) + audioBook.getBook_id()+ File.separator+"book_cover.jpg"; File imgFile = new File(img_path); if(imgFile.exists()) { BitmapFactory.Options bmOptions = new BitmapFactory.Options(); art = BitmapFactory.decodeFile(imgFile.getAbsolutePath(), bmOptions); }else{ art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ui_bg_logo); } */ art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_notification_large); notificationBuilder.setSmallIcon(R.drawable.ic_notification).setUsesChronometer(true) .setContentIntent(createContentIntent()).setContentTitle(audioBook.getEnglish_title()) .setDeleteIntent(mDeleteIntent) .setContentText(AppController.getInstance().getPlayerControllerTitle()).setLargeIcon(art); if (Build.VERSION.SDK_INT >= 21) { notificationBuilder.setStyle( new Notification.MediaStyle().setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view ).setVisibility(Notification.VISIBILITY_PUBLIC).setColor(mNotificationColor) ; } setNotificationPlaybackState(notificationBuilder); return notificationBuilder.build(); }
From source file:com.andrew.apollo.utils.ApolloUtils.java
/** * Used to create shortcuts for an artist, album, or playlist that is then * placed on the default launcher homescreen * // ww w . j a v a2 s . c om * @param displayName The shortcut name * @param id The ID of the artist, album, playlist, or genre * @param mimeType The MIME type of the shortcut * @param context The {@link Context} to use to */ public static void createShortcutIntent(final String displayName, final Long id, final String mimeType, final SherlockFragmentActivity context) { try { final ImageFetcher fetcher = getImageFetcher(context); Bitmap bitmap = null; if (mimeType.equals(MediaStore.Audio.Albums.CONTENT_TYPE)) { bitmap = fetcher.getCachedBitmap(displayName + Config.ALBUM_ART_SUFFIX); } else { bitmap = fetcher.getCachedBitmap(displayName); } if (bitmap == null) { bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.default_artwork); } // Intent used when the icon is touched final Intent shortcutIntent = new Intent(context, ShortcutActivity.class); shortcutIntent.setAction(Intent.ACTION_VIEW); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); shortcutIntent.putExtra(Config.ID, id); shortcutIntent.putExtra(Config.NAME, displayName); shortcutIntent.putExtra(Config.MIME_TYPE, mimeType); // Intent that actually sets the shortcut final Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapUtils.resizeAndCropCenter(bitmap, 96)); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); context.sendBroadcast(intent); Crouton.makeText(context, displayName + " " + context.getString(R.string.pinned_to_home_screen), Crouton.STYLE_CONFIRM).show(); } catch (final Exception e) { Log.e("ApolloUtils", "createShortcutIntent - " + e); Crouton.makeText(context, displayName + " " + context.getString(R.string.could_not_be_pinned_to_home_screen), Crouton.STYLE_ALERT).show(); } }
From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
public static Bitmap getMemoryCached(Context context, int resId) { String key = Integer.toString(resId); Bitmap bm = memGet(key, 0, 0);/* www . j a va2s.c o m*/ if (bm == null) { bm = BitmapFactory.decodeResource(context.getResources(), resId); if (bm != null) { memPut(key, 0, 0, bm, false); } } return bm; }
From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java
public static Bitmap getMemoryCached(Context context, int resId) { String key = Integer.toString(resId); Bitmap bm = memGet(key, 0, 0);/*from ww w.j ava 2 s. co m*/ if (bm == null) { bm = BitmapFactory.decodeResource(context.getResources(), resId); if (bm != null) { memPut(key, 0, 0, bm, false); } } return bm; }