List of usage examples for android.widget ImageView setImageDrawable
public void setImageDrawable(@Nullable Drawable drawable)
From source file:com.ccz.viewimages.displayingbitmaps.util.ImageWorker.java
public void loadImageWithDoubleThumb(Object data, ImageView imageView, boolean needDoubleThumb) { if (data == null) { return;// www.j av a2 s . c o m } BitmapDrawable value = null; if (mImageCache != null) { value = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (value != null) { // Bitmap found in memory cache imageView.setImageDrawable(value); } else if (cancelPotentialWork(data, imageView)) { //BEGIN_INCLUDE(execute_background_task) final BitmapWorkerTask task = new BitmapWorkerTask(data, imageView); if (needDoubleThumb) { task.enableDoubleThumb(); } final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); imageView.setImageDrawable(asyncDrawable); // NOTE: This uses a custom version of CustomAsyncTask that has been pulled from the // framework and slightly modified. Refer to the docs at the top of the class // for more info on what was changed. task.executeOnExecutor(CustomAsyncTask.DUAL_THREAD_EXECUTOR); //END_INCLUDE(execute_background_task) } }
From source file:com.corebase.android.bitmap.util.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView./*w w w . j a v a2 s . c om*/ * * @param imageView * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final // drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable }); // Set background to loading bitmap imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); imageView.setBackgroundDrawable(null); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:org.jinzora.util.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (urlString == null) { if (DBG)/*from w w w . ja v a2 s .co m*/ Log.d(TAG, "Null image url."); synchronized (pendingViews) { pendingViews.remove(imageView); } return; } synchronized (pendingViews) { pendingViews.put(imageView, urlString); } if (drawableMap.containsKey(urlString)) { SoftReference<Drawable> reference = drawableMap.get(urlString); Drawable drawable = reference.get(); if (drawable != null) { if (DBG) Log.d(TAG, "Image cached in memory."); imageView.setImageDrawable(drawable); return; } else { if (DBG) Log.d(TAG, "Soft reference cleared."); drawableMap.remove(urlString); } } File localFile = getLocalFile(urlString); if (localFile != null && localFile.exists()) { if (DBG) Log.d(TAG, "Image from disk."); imageView.setImageDrawable(fetchDrawable(urlString)); return; } final Handler handler = new Handler() { @Override public void handleMessage(Message message) { synchronized (pendingViews) { String latest = pendingViews.get(imageView); if (urlString.equals(latest)) { imageView.setImageDrawable((Drawable) message.obj); } } } }; new Thread() { @Override public void run() { Drawable drawable = fetchDrawable(urlString); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }.start(); }
From source file:com.image.cache.util.ImageWorker.java
/** * Load an image specified by the data parameter into an ImageView (override * {@link ImageWorker#processBitmap(Object)} to define the processing logic). A memory and * disk cache will be used if an {@link ImageCache} has been added using * {@link ImageWorker#addImageCache(FragmentManager, ImageCache.ImageCacheParams)}. If the * image is found in the memory cache, it is set immediately, otherwise an {@link AsyncTask} * will be created to asynchronously load the bitmap. * * @param data The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. *//* ww w . jav a2 s . c om*/ public void loadImage(Object data, ImageView imageView) { if (data == null) { return; } BitmapDrawable value = null; BORDER_THICKNESS = -1; BORDER_RADIUS = -1; COLOR = -1; if (mImageCache != null) { value = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (value != null) { // Bitmap found in memory cache imageView.setImageDrawable(value); } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView); final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); imageView.setImageDrawable(asyncDrawable); // NOTE: This uses a custom version of AsyncTask that has been pulled from the // framework and slightly modified. Refer to the docs at the top of the class // for more info on what was changed. task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, data); } }
From source file:com.example.photoutil.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView./*ww w .java 2 s .c o m*/ * * @param imageView * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable }); // Set background to loading bitmap // *****Bo doan nay***** //imageView.setBackgroundDrawable( // new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.intuit.qboecoui.feeds.util.ImageWorker.java
/** * Load an image specified by the data parameter into an ImageView (override * {@link ImageWorker#processBitmap(Object, Object)} to define the processing logic). A memory and * disk cache will be used if an {@link ImageCache} has been added using * {@link ImageWorker#addImageCache(FragmentManager, ImageCache.ImageCacheParams)}. If the * image is found in the memory cache, it is set immediately, otherwise an {@link AsyncTask} * will be created to asynchronously load the bitmap. * * @param data The URL of the image to download. * @param key key that is used to cache the image * @param imageView The ImageView to bind the downloaded image to. * @param linkedItemType The item type of the entity that has a attachable , see attachable_association table. * @param linkedItemId The item id of the entity that has a attachable , see attachable_association table. . *//*from ww w.j ava2s.c o m*/ public boolean loadImage(Object data, Object key, ImageView imageView, TaskCompletedHandler listener) { CustomLog.logDebug(TAG, "[Feed] loadImage request - data[" + data + "] with key [" + key + "]"); BitmapDrawable value = null; boolean bFound = false; if (mImageCache != null) { value = mImageCache.getBitmapFromMemCache(String.valueOf(key)); } if (value != null) { // Bitmap found in memory cache imageView.setImageDrawable(value); bFound = true; } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView, listener); if (imageView != null) { final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); imageView.setImageDrawable(asyncDrawable); } task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, data, key); } return bFound; }
From source file:com.androidpi.bricks.gallery.lru.cache.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be set on the ImageView. * * @param imageView/*from w w w .ja v a 2s .co m*/ * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final // drawable final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(imageView.getResources().getColor(android.R.color.transparent)), drawable }); // Set background to loading bitmap imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.example.image.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView//from w w w . j a va2 s. co m * @param bitmap */ private void setImageBitmap(final ImageView imageView, final Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable with a transparent drwabale and the final bitmap final TransitionDrawable td = new TransitionDrawable(new Drawable[] { mLoadingBitmap != null ? getLoadingDrawable() : new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); // Set background to loading bitmap //imageView.setBackgroundDrawable(getLoadingDrawable()); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); imageView.postDelayed(new Runnable() { @Override public void run() { imageView.setImageBitmap(bitmap); } }, FADE_IN_TIME); } else { imageView.setImageBitmap(bitmap); } }
From source file:com.example.mohmurtu.registration.imagesUtil.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView./*from www. j a va 2s.c om*/ * * @param imageView * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { System.out.println("Doing some thing here"); // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable }); // Set background to loading bitmap imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { System.out.println("Bitmap is getting drawable"); imageView.setImageDrawable(drawable); } }
From source file:com.chinaLife.claimAssistant.tools.sc_ImageDownloaderId.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. *//* ww w . j a v a 2s . c o m*/ private void forceDownload(File file, String id, ImageView imageView) { // State sanity: url is guaranteed to never be null in // DownloadedDrawable and cache keys. if (file.getAbsolutePath() == null) { // imageView.setImageResource(resid); return; } Log.i("", imageView.toString() + "-----" + file.getAbsolutePath()); if (cancelPotentialDownload(file.getAbsolutePath(), imageView)) { BitmapDownloaderTask task = new BitmapDownloaderTask(imageView); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, context, resid); imageView.setImageDrawable(downloadedDrawable); task.execute(file, id); } }