List of usage examples for android.widget ImageView setImageDrawable
public void setImageDrawable(@Nullable Drawable drawable)
From source file:com.manning.androidhacks.hack040.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 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 av a2 s. c o m * @param data * The URL of the image to download. * @param imageView * The ImageView to bind the downloaded image to. */ public void loadImage(Object data, ImageView imageView) { Bitmap bitmap = null; if (mImageCache != null) { bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (bitmap != null) { // Bitmap found in memory cache imageView.setImageBitmap(bitmap); } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = makeTask(imageView, data); final AsyncDrawable asyncDrawable = new AsyncDrawable(mActivity.getResources(), mLoadingBitmap, task); imageView.setImageDrawable(asyncDrawable); NetworkThreadPool.submitTask(task); } }
From source file:com.dnielfe.manager.adapters.BrowserListAdapter.java
private void loadFromRes(final File file, final ImageView icon) { Drawable mimeIcon = null;/* www .j ava2 s. c o m*/ if (file != null && file.isDirectory()) { if (file.canRead() && file.list().length > 0) mimeIcon = mResources.getDrawable(R.drawable.type_folder); else mimeIcon = mResources.getDrawable(R.drawable.type_folder_empty); } else { final String fileExt = FilenameUtils.getExtension(file.getName()); mimeIcon = mMimeTypeIconCache.get(fileExt); if (mimeIcon == null) { final int mimeIconId = MimeTypes.getIconForExt(fileExt); if (mimeIconId != 0) { mimeIcon = mResources.getDrawable(mimeIconId); mMimeTypeIconCache.put(fileExt, mimeIcon); } } } if (mimeIcon != null) { icon.setImageDrawable(mimeIcon); } else { // default icon icon.setImageResource(R.drawable.type_unknown); } }
From source file:android.support.asy.image.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set * on the ImageView./*ww w . ja v a 2 s. c om*/ * * @param imageView * @param bitmap */ private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable with a transparent drwabale and the final // bitmap final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); // Set background to loading bitmap // imageView.setBackgroundDrawable(new BitmapDrawable(mResources, // mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageBitmap(bitmap); } }
From source file:cn.mimail.sdk.net.image.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 w ww. j av a 2s . com * * @param data The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. */ public void loadImage(Object data, ImageView imageView) { if (data == null) { return; } Bitmap bitmap = null; if (mImageCache != null) { bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (bitmap != null) { // Bitmap found in memory cache imageView.setImageBitmap(bitmap); } 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.pongme.utils.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. */// ww w .j a v a2 s.co m private BitmapDownloaderTask forceDownload(String url, ImageView imageView, BitmapDrawable tempImage) { // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys. BitmapDownloaderTask task = null; if (url == null) { imageView.setImageDrawable(null); // imageView.setImageResource(R.drawable.home_img_download); return null; } int w = 0, h = 0; LayoutParams params = imageView.getLayoutParams(); if (params != null) { w = params.width; h = params.height; } // Change Task attributes if exist intead of Cancel if (refactorPotentialDownload(url, imageView, w, h)) { switch (mode) { case NO_ASYNC_TASK: Bitmap bitmap = downloadBitmap(url, w, h); addBitmapToCache(url, bitmap); imageView.setImageBitmap(bitmap); break; case NO_DOWNLOADED_DRAWABLE: imageView.setMinimumHeight(96); imageView.setMinimumWidth(128); task = new BitmapDownloaderTask(imageView, w, h); task.execute(url); break; case CORRECT: task = new BitmapDownloaderTask(imageView, w, h); DownloadedDrawable downloadedDrawable = null; if (tempImage != null) { downloadedDrawable = new DownloadedDrawable(task, tempImage); } else { downloadedDrawable = new DownloadedDrawable(task); } int minWith = 0; int minheight = 0; if (params != null) { minWith = params.width; minheight = params.height; } imageView.setImageDrawable(downloadedDrawable); imageView.setMinimumWidth(minWith); imageView.setMinimumHeight(minheight); task.execute(url); break; } } return task; }
From source file:com.android.settings.users.RestrictedProfileSettings.java
@Override public Dialog onCreateDialog(int dialogId) { if (dialogId == DIALOG_ID_EDIT_USER_INFO) { if (mEditUserInfoDialog != null) { return mEditUserInfoDialog; }/*from www . j a v a 2 s .co m*/ LayoutInflater inflater = getActivity().getLayoutInflater(); View content = inflater.inflate(R.layout.edit_user_info_dialog_content, null); UserInfo info = mUserManager.getUserInfo(mUser.getIdentifier()); final EditText userNameView = (EditText) content.findViewById(R.id.user_name); userNameView.setText(info.name); final ImageView userPhotoView = (ImageView) content.findViewById(R.id.user_photo); Drawable drawable = null; if (mSavedPhoto != null) { drawable = CircleFramedDrawable.getInstance(getActivity(), mSavedPhoto); } else { drawable = mUserIconView.getDrawable(); if (drawable == null) { drawable = getCircularUserIcon(); } } userPhotoView.setImageDrawable(drawable); mEditUserPhotoController = new EditUserPhotoController(this, userPhotoView, mSavedPhoto, drawable, mWaitingForActivityResult); mEditUserInfoDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.profile_info_settings_title) .setIconAttribute(R.drawable.ic_settings_multiuser).setView(content).setCancelable(true) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { // Update the name if changed. CharSequence userName = userNameView.getText(); if (!TextUtils.isEmpty(userName)) { CharSequence oldUserName = mUserNameView.getText(); if (oldUserName == null || !userName.toString().equals(oldUserName.toString())) { ((TextView) mHeaderView.findViewById(android.R.id.title)) .setText(userName.toString()); mUserManager.setUserName(mUser.getIdentifier(), userName.toString()); } } // Update the photo if changed. Drawable drawable = mEditUserPhotoController.getNewUserPhotoDrawable(); Bitmap bitmap = mEditUserPhotoController.getNewUserPhotoBitmap(); if (drawable != null && bitmap != null && !drawable.equals(mUserIconView.getDrawable())) { mUserIconView.setImageDrawable(drawable); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { mUserManager.setUserIcon(mUser.getIdentifier(), mEditUserPhotoController.getNewUserPhotoBitmap()); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null); } removeDialog(DIALOG_ID_EDIT_USER_INFO); } clearEditUserInfoDialog(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { clearEditUserInfoDialog(); } }).create(); // Make sure the IME is up. mEditUserInfoDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); return mEditUserInfoDialog; } return null; }
From source file:com.greendev.image.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./* ww w .j a v a 2 s . c o m*/ * * @param data The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. */ public void loadImage(Object data, ImageView imageView) { if (data == null) { return; } Bitmap bitmap = null; if (mImageCache != null) { bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (bitmap != null) { // Bitmap found in memory cache imageView.setImageBitmap(bitmap); } 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.itsherpa.andg.imageloader.ContactImageLoader.java
/** * Called when the processing is complete and the final bitmap should be set * on the ImageView.// w w w . j ava 2s . co m * * @param imageView * The ImageView to set the bitmap to. * @param bitmap * The new bitmap to set. */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @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(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); if (Build.VERSION.SDK_INT >= 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.cupfish.music.cache.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 w w w. jav a 2s . c o m * * @param data The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. */ public void loadImage(ImageInfo info, ImageView imageView) { if (info == null) { return; } String data = info.encode(); Bitmap bitmap = null; if (mImageCache != null) { bitmap = mImageCache.getBitmapFromMemCache(data); } if (bitmap != null) { // Bitmap found in memory cache imageView.setImageBitmap(bitmap); } 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, info); } }
From source file:android.com.example.contactslist.util.ImageLoader.java
/** * Load an image specified by the data parameter into an ImageView (override * {@link ImageLoader#processBitmap(Object)} to define the processing logic). 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. */// w w w.java 2s. co m public void loadImage(Object data, ImageView imageView) { if (data == 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 imageView.setImageBitmap(bitmap); } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView); final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); imageView.setImageDrawable(asyncDrawable); task.execute(data); } }