List of usage examples for android.widget ImageView setImageDrawable
public void setImageDrawable(@Nullable Drawable drawable)
From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java
public static void setImageTintList(ImageView imageView, ColorStateList colorStateList) { if (isApi_21_OrHigher()) { imageView.setImageTintList(colorStateList); } else {//from ww w.j av a 2 s . c o m Drawable drawable = imageView.getDrawable(); if (drawable != null) { Drawable wrapped = DrawableCompat.wrap(drawable); DrawableCompat.setTintList(wrapped, colorStateList); imageView.setImageDrawable(wrapped); } } }
From source file:com.drextended.rvdbsample.util.Converters.java
@BindingAdapter(value = { "glidePath", "glidePlaceholder", "glideSignature", "glideCacheStrategy", "glideCrossFadeDisabled", "glideAnimation", "glideTransform" }, requireAll = false) public static void setImageUri(ImageView imageView, String path, Drawable placeholder, String glideSignature, String glideCacheStrategy, boolean crossFadeDisabled, Integer animationResId, String glideTransform) { Context context = imageView.getContext(); if (context instanceof Activity && ((Activity) context).isFinishing()) return;/*from w ww . j a v a2s.c o m*/ if (context instanceof ContextWrapper) { final Context baseContext = ((ContextWrapper) context).getBaseContext(); if (baseContext instanceof Activity && ((Activity) baseContext).isFinishing()) return; } boolean isEmptyPath = TextUtils.isEmpty(path); if (isEmptyPath) { if (placeholder != null) { imageView.setImageDrawable(placeholder); } return; } try { RequestManager glide = Glide.with(context); DrawableRequestBuilder request = glide.load(path); if (placeholder != null) { if (!crossFadeDisabled && animationResId == null) request.crossFade(); request.placeholder(placeholder); } if (animationResId != null) { request.animate(animationResId); } if (!TextUtils.isEmpty(glideSignature)) { request.signature(new StringSignature(glideSignature)); } if (glideTransform != null) { switch (glideTransform) { case "CIRCLE": request.bitmapTransform( new CircleBorderedTransform(Glide.get(context).getBitmapPool(), Color.WHITE)); break; case "BLUR": break; } } if (!TextUtils.isEmpty(glideCacheStrategy)) { request.diskCacheStrategy(DiskCacheStrategy.valueOf(glideCacheStrategy)); } request.into(imageView); } catch (IllegalArgumentException e) { e.printStackTrace(); } }
From source file:com.example.util.ImageUtils.java
/** * ICON/* w w w . j ava 2 s . c om*/ */ public static void download(Context context, String url, ImageView imageView) { CacheManager cache = CacheManager.getInstance(); if (cache.existsDrawable(url)) { imageView.setImageBitmap(cache.getDrawableFromCache(url)); return; } Drawable defaultDrawable = context.getResources().getDrawable(R.drawable.loading_icon); if (cancelPotentialBitmapDownload(url, imageView)) { BitmapDownloaderTask task = new BitmapDownloaderTask(imageView); DownloadedDrawable1 downloadedDrawable = new DownloadedDrawable1(defaultDrawable, task); imageView.setImageDrawable(downloadedDrawable); task.execute(context, url, TYPE_NORAML); } }
From source file:it.cdpaf.helper.DrawableManager.java
public static ImageView fetchIvOnThread(String imagepath, int nthImage, final Context ctx) { final String urlString = Const.IMAGE_URL + imagepath; final Drawable resultDrawable; final ImageView imageView = new ImageView(ctx); String urlStringValid = ""; if (nthImage == 0) urlStringValid = urlString;/*from w w w. ja v a 2 s. co m*/ else { String url = urlString + "_" + nthImage; String[] result = urlString.split(".j"); String prima = result[0]; String seconda = result[1]; String jpg = ".j" + seconda; urlStringValid = prima + "_" + nthImage + jpg; } final String finalURl = urlStringValid; if (drawableMap.containsKey(urlStringValid)) { Log.d("ALL DRAWABLE", "INDIVIDUATO UN RIUSO : " + urlStringValid); resultDrawable = (drawableMap.get(urlStringValid)); imageView.setImageDrawable(resultDrawable); } else { final Handler handler = new Handler() { @Override public void handleMessage(Message message) { Drawable resDrawable = ((Drawable) message.obj); imageView.setImageDrawable(resDrawable); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(finalURl, ctx); Message messageb = handler.obtainMessage(1, drawable); handler.sendMessage(messageb); } }; Log.d("ALL DRAWABLE", "LANCIO UNA RICERCA : " + finalURl); thread.start(); } return imageView; }
From source file:fi.tuukka.weather.utils.Utils.java
public static void showImage(Activity activity, View view, Bitmap bmp) { final Dialog imageDialog = new Dialog(activity); imageDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); imageDialog.setContentView(R.layout.showimage); imageDialog.setCancelable(true);/*from w w w. ja va2 s. co m*/ ImageView imageView = (ImageView) imageDialog.findViewById(R.id.imageView); // Getting width & height of the given image. DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics(); int wn = displayMetrics.widthPixels; int hn = displayMetrics.heightPixels; int wo = bmp.getWidth(); int ho = bmp.getHeight(); Matrix mtx = new Matrix(); // Setting rotate to 90 mtx.preRotate(90); // Setting resize mtx.postScale(((float) 1.3 * wn) / ho, ((float) 1.3 * hn) / wo); // Rotating Bitmap Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, wo, ho, mtx, true); BitmapDrawable bmd = new BitmapDrawable(rotatedBMP); imageView.setImageDrawable(bmd); imageView.setOnClickListener(new View.OnClickListener() { public void onClick(View button) { imageDialog.dismiss(); } }); imageDialog.show(); }
From source file:Main.java
public static void unbindImageView(ImageView imageView) { if (imageView == null) { return;/*w ww . j av a 2s .co m*/ } if (imageView.getBackground() != null) { imageView.getBackground().setCallback(null); } if (imageView.getDrawable() == null) return; if (!(imageView.getDrawable() instanceof BitmapDrawable)) return; if (((BitmapDrawable) imageView.getDrawable()).getBitmap() == null) return; BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); try { if (drawable != null && imageView.getTag() != null && !drawable.getBitmap().isRecycled()) { if (!imageView.getTag().toString().equalsIgnoreCase("resource") && !usingMemoryCache) { drawable.getBitmap().recycle(); } } } catch (RuntimeException e) { e.printStackTrace(); } drawable.setCallback(null); imageView.setImageBitmap(null); imageView.setImageDrawable(null); }
From source file:com.finchuk.clock2.timepickers.Utils.java
/** * Mutates the given drawable, applies the specified tint list, and sets this tinted * drawable on the target ImageView.//w w w . j a v a 2 s .c o m * * @param target the ImageView that should have the tinted drawable set on * @param drawable the drawable to tint * @param tintList Color state list to use for tinting this drawable, or null to clear the tint */ public static void setTintList(ImageView target, Drawable drawable, ColorStateList tintList) { // TODO: What is the VectorDrawable counterpart for this process? // Use a mutable instance of the drawable, so we only affect this instance. // This is especially useful when you need to modify properties of drawables loaded from // resources. By default, all drawables instances loaded from the same resource share a // common state; if you modify the state of one instance, all the other instances will // receive the same modification. // Wrap drawable so that it may be used for tinting across the different // API levels, via the tinting methods in this class. drawable = DrawableCompat.wrap(drawable.mutate()); DrawableCompat.setTintList(drawable, tintList); target.setImageDrawable(drawable); }
From source file:com.bytecode.project12.ShareImageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.image_slide_view, container, false); if (mImageId != 0) { ImageView image = (ImageView) rootView.findViewById(R.id.share_image); image.setImageDrawable(getResources().getDrawable(mImageId)); }//from www . j a v a 2s . c o m return rootView; }
From source file:com.handlerexploit.prime.example.activities.RemoteStateListExample.java
@Override public void onLoadFinished(Loader<RemoteStateListDrawable> arg0, RemoteStateListDrawable arg1) { findViewById(R.id.exampleContainer).setVisibility(View.VISIBLE); findViewById(R.id.progressContainer).setVisibility(View.GONE); ImageView icon = (ImageView) findViewById(R.id.icon); icon.setImageDrawable(arg1); }
From source file:com.android.volley.cache.plus.SimpleImageLoader.java
/** * Sets a {@link android.graphics.Bitmap} to an {@link android.widget.ImageView} using a * fade-in animation. If there is a {@link android.graphics.drawable.Drawable} already set on * the ImageView then use that as the image to fade from. Otherwise fade in from a transparent * Drawable.//w w w .j a v a2 s . co m */ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) private static void setImageBitmap(final ImageView imageView, final BitmapDrawable bitmapDrawable, Resources resources, boolean fadeIn) { // If we're fading in and on HC MR1+ if (fadeIn && Utils.hasHoneycombMR1()) { // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the // ImageView imageView.animate().scaleY(0.95f).scaleX(0.95f).alpha(0f) .setDuration(imageView.getDrawable() == null ? 0 : HALF_FADE_IN_TIME) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setImageDrawable(bitmapDrawable); imageView.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(HALF_FADE_IN_TIME) .setListener(null); } }); } else if (fadeIn) { // Otherwise use a TransitionDrawable to fade in Drawable initialDrawable; if (imageView.getDrawable() != null) { initialDrawable = imageView.getDrawable(); } else { initialDrawable = transparentDrawable; } // Use TransitionDrawable to fade in final TransitionDrawable td = new TransitionDrawable( new Drawable[] { initialDrawable, bitmapDrawable }); imageView.setImageDrawable(td); td.startTransition(Utils.ANIMATION_FADE_IN_TIME); } else { // No fade in, just set bitmap directly imageView.setImageDrawable(bitmapDrawable); } }