List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable
private BitmapDrawable(BitmapState state, Resources res)
From source file:com.jackleeentertainment.oq.ui.layout.fragment.util.ImageLoader.java
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView The ImageView to set the bitmap to. * @param bitmap The new bitmap to set./*from ww w. j a v a 2 s. co m*/ */ private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable to fade from loading bitmap to final bitmap final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(App.getContext().getResources().getColor(android.R.color.transparent)), new BitmapDrawable(mResources, bitmap) }); imageView.setBackgroundDrawable(imageView.getDrawable()); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageBitmap(bitmap); } }
From source file:com.faayda.imageloader.ImageLoader.java
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView The ImageView to set the bitmap to. * @param bitmap The new bitmap to set./*from www . j a v a 2s . c om*/ */ @SuppressLint("NewApi") @SuppressWarnings("deprecation") private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable to fade from loading bitmap to final bitmap final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(mResources.getColor(R.color.transparent)), new BitmapDrawable(mResources, bitmap) }); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { imageView.setBackground(imageView.getDrawable()); } else { imageView.setBackgroundDrawable(imageView.getDrawable()); } imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageBitmap(bitmap); } }
From source file:com.mallapp.utils.ImageLoader.java
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView The ImageView to set the bitmap to. * @param bitmap The new bitmap to set.// w ww . java 2 s . c o m */ private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable to fade from loading bitmap to final bitmap final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); imageView.setBackground(imageView.getDrawable()); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { bitmap = getCroppedBitmap(bitmap); imageView.setImageBitmap(bitmap); } }
From source file:com.fatelon.partyphotobooth.setup.fragments.EventInfoSetupFragment.java
/** * Creates and stores a new event logo from an image {@link Uri}. Update ui when the operation completes. * * @param srcUri the {@link Uri} to the source image. *//* w w w .j a v a 2 s .com*/ private void newLogo(final Uri srcUri) { if (TextHelper.isValid(srcUri.toString())) { final ContentResolver resolver = getActivity().getContentResolver(); final Handler workerHandler = new Handler(MyApplication.getWorkerLooper()); workerHandler.post(new Runnable() { @Override public void run() { // Load and create new logo. final Bitmap newLogo = ImageHelper.getScaledBitmap(resolver, srcUri, BaseTitleHeader.EVENT_LOGO_MAX_WIDTH, BaseTitleHeader.EVENT_LOGO_MAX_HEIGHT); if (newLogo != null) { // Store new logo in cache. mBitmapCache.asyncPut(BaseTitleHeader.EVENT_LOGO_CACHE_KEY, newLogo, new PersistedBitmapCache.IAsyncPutCallbacks() { @Override public void onSuccess(String key) { if (isActivityAlive()) { mLogoUri.setText(srcUri.toString()); // tryGet() should always succeed since the cache has just been populated. final Bitmap logo = mBitmapCache.tryGet(key); if (logo != null) { // Set thumb as compound drawable, fitted to the text height. final BitmapDrawable thumb = new BitmapDrawable(getResources(), logo); int thumbSize = (int) getResources() .getDimension(R.dimen.text_size_normal); Point drawableSize = ImageHelper.getAspectFitSize(thumbSize, thumbSize, logo.getWidth(), logo.getHeight()); thumb.setBounds(0, 0, drawableSize.x, drawableSize.y); mLogoUri.setCompoundDrawables(null, null, thumb, null); } mLogoClear.setVisibility(View.VISIBLE); } } @Override public void onFailure(String key) { postLogoError(); } }); } else { postLogoError(); } } }); } else { postLogoError(); } }
From source file:com.intuit.qboecoui.feeds.util.ImageWorker.java
/** * This will load and return the bitmap after downloading and adding to the cache. * This should be normally called from an Async task so that it doesn't block the UI but if * the image is a local file, could be called in a blocking fashion * @param task AsyncTask that is calling this method * @param data Uri to fetch the image//from w ww.jav a 2 s . co m * @param key Key to cache the image * @return */ public BitmapDrawable loadBitmap(BitmapWorkerTask task, Object data, Object key) { BitmapDrawable drawable = null; if (BuildConfig.DEBUG) { CustomLog.logDebug(TAG, "[Feed] ImageWorker:doInBackground - starting work for : " + key); } Bitmap bitmap = null; // If the image cache is available and this task has not been cancelled by another // thread and the ImageView that was originally bound to this task is still bound back // to this task and our "exit early" flag is not set then try and fetch the bitmap from // the cache if (mImageCache != null && (task == null || (!task.isCancelled() && task.getAttachedImageView() != null)) && !mExitTasksEarly) { bitmap = mImageCache.getBitmapFromDiskCache(String.valueOf(key)); } // If the bitmap was not found in the cache and this task has not been cancelled by // another thread and the ImageView that was originally bound to this task is still // bound back to this task and our "exit early" flag is not set, then call the main // process method (as implemented by a subclass) if (bitmap == null && (task == null || (!task.isCancelled() && task.getAttachedImageView() != null)) && !mExitTasksEarly) { if (data == null) { return null; } if (!AttachableDataAccessor.isAttachbaleUrlExpired(String.valueOf(data), -1)) { bitmap = processBitmap(data, key); } else { //QB Mobile - No point in trying to download the image if it is already expired CustomLog.logDebug(TAG, "[Feed] ImageWorker:doInBackground - aborting work(expired) for : " + key); } } // If the bitmap was processed and the image cache is available, then add the processed // bitmap to the cache for future use. Note we don't check if the task was cancelled // here, if it was, and the thread is still running, we may as well add the processed // bitmap to our cache as it might be used again in the future if (bitmap != null) { if (Utils.hasHoneycomb()) { // Running on Honeycomb or newer, so wrap in a standard BitmapDrawable drawable = new BitmapDrawable(mResources, bitmap); } else { // Running on Gingerbread or older, so wrap in a RecyclingBitmapDrawable // which will recycle automagically drawable = new RecyclingBitmapDrawable(mResources, bitmap); } if (mImageCache != null) { mImageCache.addBitmapToCache(String.valueOf(key), drawable); } } if (BuildConfig.DEBUG) { CustomLog.logDebug(TAG, "[Feed] ImageWorker:doInBackground - finished work for : " + key); } return drawable; }
From source file:com.cw.litenote.util.video.UtilVideo.java
static BitmapDrawable getBitmapDrawableByPath(Activity mAct, String picPathStr) { String path = Uri.parse(picPathStr).getPath(); Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Video.Thumbnails.FULL_SCREEN_KIND); BitmapDrawable bitmapDrawable = new BitmapDrawable(mAct.getResources(), bmThumbnail); return bitmapDrawable; }
From source file:com.app.chasebank.contactslist.util.ImageLoader.java
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView The ImageView to set the bitmap to. * @param bitmap The new bitmap to set.//w w w. j av a 2 s . co m */ private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable to fade from loading bitmap to final bitmap final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); imageView.setBackgroundDrawable(imageView.getDrawable()); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageBitmap(bitmap); } }
From source file:com.distantfuture.castcompanionlibrary.lib.cast.player.VideoCastControllerActivity.java
@Override public void setImage(Bitmap bitmap) { if (null != bitmap) { mPageView.setBackground(new BitmapDrawable(getResources(), bitmap)); } }
From source file:com.flym.echo24.activity.HomeActivity.java
private void selectDrawerItem(int position) { mCurrentDrawerPos = position;/*w ww .ja v a 2 s. co m*/ mIcon = null; Uri newUri; boolean showFeedInfo = true; switch (position) { case SEARCH_DRAWER_POSITION: newUri = EntryColumns.SEARCH_URI(mEntriesFragment.getCurrentSearch()); break; case 0: newUri = EntryColumns.ALL_ENTRIES_CONTENT_URI; break; case 1: newUri = EntryColumns.FAVORITES_CONTENT_URI; break; default: long feedOrGroupId = mDrawerAdapter.getItemId(position); if (mDrawerAdapter.isItemAGroup(position)) { newUri = EntryColumns.ENTRIES_FOR_GROUP_CONTENT_URI(feedOrGroupId); } else { byte[] iconBytes = mDrawerAdapter.getItemIcon(position); Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24); if (bitmap != null) { mIcon = new BitmapDrawable(getResources(), bitmap); } newUri = EntryColumns.ENTRIES_FOR_FEED_CONTENT_URI(feedOrGroupId); showFeedInfo = false; } mTitle = mDrawerAdapter.getItemName(position); break; } if (!newUri.equals(mEntriesFragment.getUri())) { mEntriesFragment.setData(newUri, showFeedInfo); } mDrawerList.setItemChecked(position, true); // First open => we open the drawer for you if (PrefUtils.getBoolean(PrefUtils.FIRST_OPEN, true)) { PrefUtils.putBoolean(PrefUtils.FIRST_OPEN, false); if (mDrawerLayout != null) { mDrawerLayout.postDelayed(new Runnable() { @Override public void run() { mDrawerLayout.openDrawer(mLeftDrawer); } }, 500); } FeedDataContentProvider.addFeed(this, "http://echo24.cz/rss/s/domov", "Domov", true); FeedDataContentProvider.addFeed(this, "http://echo24.cz/rss/s/svet", "Svt", true); FeedDataContentProvider.addFeed(this, "http://echo24.cz/rss/s/byznys", "Byznys", true); FeedDataContentProvider.addFeed(this, "http://echo24.cz/rss/s/panorama", "Panorama", true); FeedDataContentProvider.addFeed(this, "http://echo24.cz/rss/s/nazory", "Nzory", true); FeedDataContentProvider.addFeed(this, "http://echo24.cz/rss/s/blogy", "Blogy", true); /* AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.welcome_title) .setItems(new CharSequence[]{getString(R.string.google_news_title), getString(R.string.add_custom_feed)}, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (which == 1) { startActivity(new Intent(Intent.ACTION_INSERT).setData(FeedColumns.CONTENT_URI)); } else { startActivity(new Intent(HomeActivity.this, AddGoogleNewsActivity.class)); } } }); builder.show(); */ } // Set title & icon switch (mCurrentDrawerPos) { case SEARCH_DRAWER_POSITION: getSupportActionBar().setTitle(android.R.string.search_go); getSupportActionBar().setIcon(R.drawable.action_search); break; default: getSupportActionBar().setTitle(mTitle); if (mIcon != null) { getSupportActionBar().setIcon(mIcon); } else { getSupportActionBar().setIcon(null); } break; } // Put the good menu invalidateOptionsMenu(); }
From source file:com.dunrite.xpaper.utility.Utils.java
/** * TODO: DEPRECATE/*from w ww . j a v a2 s.c o m*/ * Combines two images into one while also coloring each separate image * * @param background the main background drawable * @param foreground the drawable in the front of the background] * @param context current context * @return colorized and combined drawable * * can add a 3rd parameter 'String loc' if you want to save the new image. * left some code to do that at the bottom */ public static Drawable combineImages(Drawable background, Drawable foreground, Drawable deviceMisc, int color1, int color2, String type, Context context) { Bitmap cs; Bitmap device = null; int width; int height; //convert from drawable to bitmap Bitmap back = ((BitmapDrawable) background).getBitmap(); back = back.copy(Bitmap.Config.ARGB_8888, true); Bitmap x = ((BitmapDrawable) foreground).getBitmap(); x = x.copy(Bitmap.Config.ARGB_8888, true); if (type.equals("device")) { device = ((BitmapDrawable) deviceMisc).getBitmap(); device = device.copy(Bitmap.Config.ARGB_8888, true); } //initialize Canvas if (type.equals("preview") || type.equals("device")) { width = back.getWidth() / 2; height = back.getHeight() / 2; } else { width = back.getWidth(); height = back.getHeight(); } cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas comboImage = new Canvas(cs); //Filter for Background Paint paint1 = new Paint(); paint1.setFilterBitmap(false); paint1.setColorFilter(new PorterDuffColorFilter(color1, PorterDuff.Mode.SRC_ATOP)); //Filter for Foreground Paint paint2 = new Paint(); paint2.setFilterBitmap(false); paint2.setColorFilter(new PorterDuffColorFilter(color2, PorterDuff.Mode.SRC_ATOP)); //Draw both images if (type.equals("preview") || type.equals("device")) { if (type.equals("device")) comboImage.drawBitmap( Bitmap.createScaledBitmap(device, device.getWidth() / 2, device.getHeight() / 2, true), 0, 0, null); comboImage.drawBitmap(Bitmap.createScaledBitmap(back, back.getWidth() / 2, back.getHeight() / 2, true), 0, 0, paint1); comboImage.drawBitmap(Bitmap.createScaledBitmap(x, x.getWidth() / 2, x.getHeight() / 2, true), 0, 0, paint2); } else { comboImage.drawBitmap(back, 0, 0, paint1); comboImage.drawBitmap(x, 0, 0, paint2); } return new BitmapDrawable(context.getResources(), cs); }