List of usage examples for android.widget ImageView setImageDrawable
public void setImageDrawable(@Nullable Drawable drawable)
From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation, float ratio, float anchor, int source) { bm = filter(iv, bm, fallback);// w w w . jav a 2 s .co m if (bm == null) { iv.setImageBitmap(null); return; } Drawable d = makeDrawable(iv, bm, ratio, anchor); Animation anim = null; if (fadeIn(animation, source)) { if (preset == null) { anim = new AlphaAnimation(0, 1); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(FADE_DUR); } else { Drawable pd = makeDrawable(iv, preset, ratio, anchor); Drawable[] ds = new Drawable[] { pd, d }; TransitionDrawable td = new TransitionDrawable(ds); td.setCrossFadeEnabled(true); td.startTransition(FADE_DUR); d = td; } } else if (animation > 0) { anim = AnimationUtils.loadAnimation(iv.getContext(), animation); } iv.setImageDrawable(d); if (anim != null) { anim.setStartTime(AnimationUtils.currentAnimationTimeMillis()); iv.startAnimation(anim); } else { iv.setAnimation(null); } }
From source file:com.image.cache.util.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView.//from w w w. j ava 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 imageView.setImageDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.cm.android.beercellar.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(android.support.v4.app.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. * @param listener A listener that will be called back once the image has been loaded. *//*from w w w .ja va 2 s .c o m*/ public void loadImage(Object data, ImageView imageView, OnImageLoadedListener listener) { if (data == null) { return; } BitmapDrawable value = null; if (mImageCache != null) { value = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (value != null) { // Bitmap found in memory cache imageView.setImageDrawable(value); if (listener != null) { listener.onImageLoaded(true); } } else if (cancelPotentialWork(data, imageView)) { //BEGIN_INCLUDE(execute_background_task) final BitmapWorkerTask task = new BitmapWorkerTask(data, imageView, listener); 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); //END_INCLUDE(execute_background_task) } }
From source file:com.crazyapk.util.bitmap.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView//w ww . ja v a 2s .co m * @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:com.gh4a.utils.ImageDownloader.java
public void download(String gravatarId, ImageView ivImage, int size) { String url = "http://www.gravatar.com/avatar.php?gravatar_id=" + gravatarId + "&size=" + size + "&d=mm"; resetPurgeTimer();//w w w. ja va 2s . c o m Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { if (cancelPotentialDownload(url, ivImage)) { BitmapDownloaderTask task = new BitmapDownloaderTask(ivImage); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task); ivImage.setImageDrawable(downloadedDrawable); task.execute(url); } } else { cancelPotentialDownload(url, ivImage); ivImage.setImageBitmap(bitmap); } }
From source file:com.example.nanchen.aiyaschoolpush.im.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView./* w w w .ja va 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(App.getAppContext().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.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
private void setBitmap(String url, ImageView iv, Bitmap bm, boolean isPreset) { if (bm == null) { iv.setImageDrawable(null); return;/*from w w w . j av a2 s .c o m*/ } if (isPreset) { iv.setImageDrawable(makeDrawable(iv, bm, ratio, anchor)); return; } if (status != null) { setBmAnimate(iv, bm, preset, fallback, animation, ratio, anchor, status.getSource()); } }
From source file:com.aware.ui.Plugins_Manager.java
private void drawUI() { //Clear previous states store_grid.removeAllViews();/* w w w. j a v a 2 s . c o m*/ //Build UI Cursor installed_plugins = getContentResolver().query(Aware_Plugins.CONTENT_URI, null, null, null, Aware_Plugins.PLUGIN_NAME + " ASC"); if (installed_plugins != null && installed_plugins.moveToFirst()) { do { final String package_name = installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_PACKAGE_NAME)); final String name = installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_NAME)); final String description = installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_DESCRIPTION)); final String developer = installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_AUTHOR)); final String version = installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_VERSION)); final int status = installed_plugins .getInt(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_STATUS)); final View pkg_view = inflater.inflate(R.layout.plugins_store_pkg_list_item, null, false); pkg_view.setTag(package_name); //each view has the package name as a tag for easier references try { ImageView pkg_icon = (ImageView) pkg_view.findViewById(R.id.pkg_icon); if (status != PLUGIN_NOT_INSTALLED) { ApplicationInfo appInfo = getPackageManager().getApplicationInfo(package_name, PackageManager.GET_META_DATA); pkg_icon.setImageDrawable(appInfo.loadIcon(getPackageManager())); } else { byte[] img = installed_plugins .getBlob(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_ICON)); if (img != null) pkg_icon.setImageBitmap(BitmapFactory.decodeByteArray(img, 0, img.length)); } TextView pkg_title = (TextView) pkg_view.findViewById(R.id.pkg_title); pkg_title.setText(installed_plugins .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_NAME))); ImageView pkg_state = (ImageView) pkg_view.findViewById(R.id.pkg_state); switch (status) { case PLUGIN_DISABLED: pkg_state.setVisibility(View.INVISIBLE); pkg_view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = getPluginInfoDialog(name, version, description, developer); if (isClassAvailable(package_name, "Settings")) { builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent open_settings = new Intent(); open_settings.setClassName(package_name, package_name + ".Settings"); startActivity(open_settings); } }); } builder.setPositiveButton("Activate", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Aware.startPlugin(getApplicationContext(), package_name); drawUI(); } }); builder.create().show(); } }); break; case PLUGIN_ACTIVE: pkg_state.setImageResource(R.drawable.ic_pkg_active); pkg_view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = getPluginInfoDialog(name, version, description, developer); if (isClassAvailable(package_name, "Settings")) { builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent open_settings = new Intent(); open_settings.setClassName(package_name, package_name + ".Settings"); startActivity(open_settings); } }); } builder.setPositiveButton("Deactivate", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Aware.stopPlugin(getApplicationContext(), package_name); drawUI(); } }); builder.create().show(); } }); break; case PLUGIN_UPDATED: pkg_state.setImageResource(R.drawable.ic_pkg_updated); pkg_view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = getPluginInfoDialog(name, version, description, developer); if (isClassAvailable(package_name, "Settings")) { builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent open_settings = new Intent(); open_settings.setClassName(package_name, package_name + ".Settings"); startActivity(open_settings); } }); } builder.setNeutralButton("Deactivate", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Aware.stopPlugin(getApplicationContext(), package_name); drawUI(); } }); builder.setPositiveButton("Update", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Aware.downloadPlugin(getApplicationContext(), package_name, true); } }); builder.create().show(); } }); break; case PLUGIN_NOT_INSTALLED: pkg_state.setImageResource(R.drawable.ic_pkg_download); pkg_view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = getPluginInfoDialog(name, version, description, developer); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setPositiveButton("Install", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Aware.downloadPlugin(getApplicationContext(), package_name, false); } }); builder.create().show(); } }); break; } store_grid.addView(pkg_view); } catch (NameNotFoundException e) { e.printStackTrace(); } } while (installed_plugins.moveToNext()); } if (installed_plugins != null && !installed_plugins.isClosed()) installed_plugins.close(); }
From source file:baselyous.com.copticsmedia.mediaTasks.tasks.ebsalmodiaTask.util.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView.//from w w w . ja va 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(mResources.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:br.org.fiscal65.bitmaps.ImageWorker.java
public void loadImage(Object data, ImageView imageView, ProgressBar progressBar) { if (data == null) { return;/*from w ww. ja v a 2 s .c om*/ } BitmapDrawable value = null; if (progressBar != null) progressBar.setVisibility(View.VISIBLE); if (mImageCache != null) { value = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (value != null) { // Bitmap found in memory cache imageView.setImageDrawable(value); if (progressBar != null) progressBar.setVisibility(View.GONE); } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(data, imageView, progressBar); 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); } }