List of usage examples for android.widget ImageView setImageBitmap
@android.view.RemotableViewMethod public void setImageBitmap(Bitmap bm)
From source file:com.makotosan.vimeodroid.common.ImageDownloader.java
/** * Download the specified image from the Internet and binds it to the * provided ImageView. The binding is immediate if the image is found in the * cache and will be done asynchronously otherwise. A null bitmap will be * associated to the ImageView if an error occurs. * /*ww w . j a va 2 s . co m*/ * @param url * The URL of the image to download. * @param imageView * The ImageView to bind the downloaded image to. */ public void download(String url, ImageView imageView) { resetPurgeTimer(); Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { // Now try from storage bitmap = getBitmapFromStorage(url); } if (bitmap == null) { // If still not there, download forceDownload(url, imageView); } else { cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); } }
From source file:com.cloverstudio.spika.utils.BitmapManager.java
public void queueJob(final String url, final ImageView imageView, final ProgressBar pbLoading) { /* Create handler in UI thread. */ final Handler handler = new Handler() { @Override//from w ww . j a v a 2 s .c o m public void handleMessage(Message msg) { String tag = imageViews.get(imageView); if (tag != null && tag.equals(url)) { if (msg.obj != null) { if (smallImg) { imageView.setScaleType(ImageView.ScaleType.CENTER); } else { imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); } imageView.setImageBitmap((Bitmap) msg.obj); if (pbLoading != null) pbLoading.setVisibility(View.GONE); } else { // imageView.setImageBitmap(placeholder); imageView.setImageResource(R.drawable.image_stub); if (pbLoading != null) pbLoading.setVisibility(View.GONE); } } } }; pool.submit(new Runnable() { @Override public void run() { final Bitmap bmp = downloadBitmap(url); Message message = Message.obtain(); message.obj = bmp; handler.sendMessage(message); } }); }
From source file:com.bxduan.apps.secretgallery.ImageDownloader.java
private void forceDownload(String url, ImageView imageView) { // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys. if (url == null) { imageView.setImageDrawable(null); return;/*w w w . j a v a 2s .com*/ } if (cancelPotentialDownload(url, imageView)) { switch (mode) { case NO_ASYNC_TASK: Bitmap bitmap = downloadBitmap(url); addBitmapToCache(url, bitmap); imageView.setImageBitmap(bitmap); break; case NO_DOWNLOADED_DRAWABLE: imageView.setMinimumHeight(156); BitmapDownloaderTask task = new BitmapDownloaderTask(imageView); task.execute(url); break; case CORRECT: task = new BitmapDownloaderTask(imageView); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task); imageView.setImageDrawable(downloadedDrawable); imageView.setMinimumHeight(156); task.execute(url); break; } } }
From source file:org.everyuse.android.util.ImageDownloader.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. *///w w w . j a va 2 s.c o m private void forceDownload(String url, ImageView imageView) { // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys. if (url == null) { imageView.setImageDrawable(null); return; } if (cancelPotentialDownload(url, imageView)) { switch (mode) { case NO_ASYNC_TASK: Bitmap bitmap = downloadBitmap(url); addBitmapToCache(url, bitmap); imageView.setImageBitmap(bitmap); break; case NO_DOWNLOADED_DRAWABLE: imageView.setMinimumHeight(156); BitmapDownloaderTask task = new BitmapDownloaderTask(imageView); task.execute(url); break; case CORRECT: task = new BitmapDownloaderTask(imageView); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task); imageView.setImageDrawable(downloadedDrawable); imageView.setMinimumHeight(156); task.execute(url); break; } } }
From source file:com.wanpaijie.www.http.ImageDownloader.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. *//*w w w. jav a2s . co m*/ private void forceDownload(String url, ImageView imageView) { // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys. if (url == null) { imageView.setImageDrawable(null); return; } if (cancelPotentialDownload(url, imageView)) { switch (mode) { case NO_ASYNC_TASK: Bitmap bitmap = downloadBitmap(url); addBitmapToCache(url, bitmap); imageView.setImageBitmap(bitmap); break; case NO_DOWNLOADED_DRAWABLE: imageView.setMinimumHeight(156); BitmapDownloaderTask task = new BitmapDownloaderTask(imageView); task.execute(url); break; case CORRECT: task = new BitmapDownloaderTask(imageView); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task); imageView.setImageDrawable(downloadedDrawable); //imageView.setImageDrawable(this.current.getResources().getDrawable(R.drawable.index_topic_default)); imageView.setMinimumHeight(225); imageView.setMinimumHeight(130); task.execute(url); break; } } }
From source file:pk.onlinebazaar.helpers.ImageDownloader.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. *//*from w ww .j av a2s. c om*/ private void forceDownload(String url, ImageView imageView) { // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys. if (url == null) { imageView.setImageDrawable(null); return; } if (cancelPotentialDownload(url, imageView)) { switch (mode) { case NO_ASYNC_TASK: Bitmap bitmap = downloadBitmap(url); addBitmapToCache(url, bitmap); imageView.setImageBitmap(bitmap); break; case NO_DOWNLOADED_DRAWABLE: imageView.setMinimumHeight(156); BitmapDownloaderTask task = new BitmapDownloaderTask(imageView); task.execute(url); break; case NO_DOWNLOADED_DRAWABLE_WITHOUT_IMAGEVIEW: BitmapDownloaderTask taskNull = new BitmapDownloaderTask(null); taskNull.execute(url); break; case CORRECT: task = new BitmapDownloaderTask(imageView); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task); imageView.setImageDrawable(downloadedDrawable); imageView.setMinimumHeight(156); task.execute(url); break; } } }
From source file:com.haipeng.libraryforandroid.cacheormemory.imageload.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 set using {@link ImageWorker#setImageCache(ImageCache)}. 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. * //from ww w . j a va 2 s . c o m * @param data * The URL of the image to download. * @param imageView * The ImageView to bind the downloaded image to. * @param loadImgViaMobile * ?true */ public void loadImage(Object data, ImageView imageView, boolean loadImgViaMobile) { if (data == null || TextUtils.isEmpty(data.toString().trim())) { if (mLoadingBitmap != null && imageView != null) imageView.setImageBitmap(mLoadingBitmap); return; } Bitmap bitmap = null; if (mImageCache != null) { bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (bitmap != null) { // Bitmap found in memory cache notifyLoadComplete(String.valueOf(data), bitmap, imageView); imageView.setImageBitmap(bitmap); } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView, loadImgViaMobile); 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.nookdevs.market.NookMarket.java
private void loadWallpaper() { String wallPaperFile = getWallpaperFile(); if (wallPaperFile != null) { try {//from w w w.ja v a2 s.co m ImageView img = (ImageView) findViewById(R.id.mainimage); wallPaperFile = wallPaperFile.substring(7); Bitmap bMap = BitmapFactory.decodeFile(wallPaperFile); img.setImageBitmap(bMap); } catch (Exception ex) { Log.e(LOGTAG, ex.getMessage(), ex); } } }
From source file:com.esource42.whyapp.utility.ImageDownloader.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. *//*from w w w. j a v a 2 s. c o m*/ private void forceDownload(String url, ImageView imageView, ProgressBar progress) { // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys. if (url == null) { imageView.setImageDrawable(null); return; } if (cancelPotentialDownload(url, imageView)) { switch (mode) { case NO_ASYNC_TASK: Bitmap bitmap = downloadBitmap(url); addBitmapToCache(url, bitmap); imageView.setImageBitmap(bitmap); break; case NO_DOWNLOADED_DRAWABLE: imageView.setMinimumHeight(156); BitmapDownloaderTask task = new BitmapDownloaderTask(imageView, progress); task.execute(url); break; case CORRECT: task = new BitmapDownloaderTask(imageView, progress); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task); imageView.setImageDrawable(downloadedDrawable); imageView.setMinimumHeight(156); task.execute(url); break; } } }
From source file:com.oasis.sdk.activity.OasisSdkPayEpinActivity.java
private void initImage(List<String> imgUrls) { if (imgUrls == null || imgUrls.size() <= 0) return;//w ww . ja v a2 s . co m int size = imgUrls.size(); if (size > 4)// 4 size = 4; Rect r = new Rect(); et_code.getGlobalVisibleRect(r); int width = r.right - r.left; int singWidth = width / size; int imgWidth = DisplayUtil.dip2px(70, BaseUtils.getDensity()); int imgHeight = DisplayUtil.dip2px(30, BaseUtils.getDensity()); double l = singWidth / (double) imgWidth; if (l <= 1) { imgWidth = singWidth; } else { l = Math.round(l * 100) * 0.01d;// ?2?? imgWidth *= l; imgHeight *= l; } for (int i = 0; i < size; i++) { // ? 105*45 final ImageView img = new ImageView(this.getApplicationContext()); img.setLayoutParams(new LayoutParams(imgWidth, imgHeight)); img.setImageResource(BaseUtils.getResourceValue("drawable", "oasisgames_sdk_payway_mob_epin")); ImageRequest iq = new ImageRequest(imgUrls.get(i), new Response.Listener<Bitmap>() { @Override public void onResponse(final Bitmap arg0) { if (arg0 == null) return; img.setImageBitmap(arg0); img.postInvalidate(); } }, imgWidth, // ??? imgHeight, Config.ARGB_8888, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError arg0) { setWaitScreen(false); } }); iq.setRetryPolicy(new DefaultRetryPolicy(60000, 2, 1)); ApplicationContextManager.getInstance().getVolleyRequestQueue().add(iq); ll_images.addView(img); } if (ll_images.getChildCount() > 0) { ll_images.setVisibility(View.VISIBLE); } }