Example usage for android.widget ImageView setImageDrawable

List of usage examples for android.widget ImageView setImageDrawable

Introduction

In this page you can find the example usage for android.widget ImageView setImageDrawable.

Prototype

public void setImageDrawable(@Nullable Drawable drawable) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:it.cdpaf.helper.DrawableManager.java

public static void fetchDrawableOnThread(final Macrocategory mac, final ImageView imageView,
        final Context ctx) {
    final String urlString = Const.IMAGE_URL + mac.getNomeImmagine();
    if (drawableMap.containsKey(urlString)) {
        imageView.setImageDrawable(drawableMap.get(urlString));
        //product.setImmagine(drawableMap.get(urlString));
    }/*  ww  w .  j  av a  2 s . c  om*/

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            Drawable dr = (Drawable) message.obj;
            imageView.setImageDrawable(dr);
            mac.setImmagine(dr);
        }
    };

    Thread thread = new Thread() {
        @Override
        public void run() {
            //TODO : set imageView to a "pending" image
            Drawable d = ctx.getResources().getDrawable(R.drawable.ic_launcher);
            Message messagea = handler.obtainMessage(1, d);
            handler.sendMessage(messagea);
            Drawable drawable = fetchDrawable(urlString, ctx);
            Message messageb = handler.obtainMessage(1, drawable);
            handler.sendMessage(messageb);
        }
    };
    thread.start();
}

From source file:com.mattermost.service.Promise.java

public static PopupWindow show() {
    Activity currentActivity = AppActivity.current;
    PopupWindow pw = new PopupWindow(currentActivity);
    pw.setFocusable(false);/*from w  w w  . j ava  2  s.  c om*/
    pw.setBackgroundDrawable(new ColorDrawable(0));
    ImageView img = new ImageView(currentActivity);
    pw.setContentView(img);
    View view = currentActivity.getWindow().getDecorView();
    pw.setWidth(60);
    pw.setHeight(60);
    AnimatedCircleDrawable a = new AnimatedCircleDrawable(Color.RED, 5, Color.TRANSPARENT, 30);
    img.setImageDrawable(a);
    pw.showAtLocation(view, Gravity.LEFT | Gravity.TOP, view.getWidth() / 2 - 30, view.getHeight() / 2 - 30);
    a.start();

    return pw;
}

From source file:com.ahmadrosid.lib.baseapp.helper.ImageViewHelper.java

public static void createRounded(Context context, String url, ImageView imageView) {
    try {/*from   www .  j  a v  a 2  s  .c o  m*/
        Glide.with(context).load(url).asBitmap().centerCrop().into(new BitmapImageViewTarget(imageView) {
            @Override
            protected void setResource(Bitmap resource) {
                RoundedBitmapDrawable rounded = RoundedBitmapDrawableFactory.create(context.getResources(),
                        resource);
                rounded.setCircular(true);
                imageView.setImageDrawable(rounded);
                Log.d(TAG, "setResource: " + url);
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "createRounded: ", e);
    }
}

From source file:it.cdpaf.helper.DrawableManager.java

public static void fetchDrawableOnThread(final Product product, final ImageView imageView, final Context ctx) {
    final String urlString = Const.IMAGE_URL + product.getPercorsoImmagine();
    if (drawableMap.containsKey(urlString)) {
        Log.d(ctx.getClass().getSimpleName(), "DRAWABLE MANAGER FDOT:" + "RIUSO, Size:" + drawableMap.size());
        imageView.setImageDrawable(drawableMap.get(urlString));
        return;/*from  w ww  .j  av  a  2 s.c  om*/
        //product.setImmagine(drawableMap.get(urlString));
    }

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            Drawable dr = (Drawable) message.obj;
            imageView.setImageDrawable(dr);
            product.setImmagine(dr);
        }
    };

    Thread thread = new Thread() {
        @Override
        public void run() {
            //TODO : set imageView to a "pending" image
            Drawable d = ctx.getResources().getDrawable(R.drawable.blank);
            Message messagea = handler.obtainMessage(1, d);
            handler.sendMessage(messagea);
            Drawable drawable = fetchDrawable(urlString, ctx);

            Message messageb = handler.obtainMessage(1, drawable);
            handler.sendMessage(messageb);
        }
    };
    Log.i("DRAWABLE MANAGER:", "LANCIO FDOT, Size:" + drawableMap.size());
    thread.start();
}

From source file:com.example.util.ImageUtils.java

/**
 * //  w w  w .  jav  a  2  s. c  om
 */
public static void downloadHomeTopDrawable(Context context, String url, ImageView imageView) {

    CacheManager cache = CacheManager.getInstance();
    if (cache.existsDrawable(url)) {
        BitmapDrawable background = new BitmapDrawable(cache.getDrawableFromCache(url));
        StateListDrawable foreground = getMaskDrawable(context);
        imageView.setImageDrawable(foreground);
        imageView.setBackgroundDrawable(background);
        return;
    }

    Drawable defaultDrawable = context.getResources().getDrawable(R.drawable.banner_loading);
    if (cancelPotentialBitmapDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
        DownloadedDrawable1 downloadedDrawable = new DownloadedDrawable1(defaultDrawable, task);
        imageView.setImageDrawable(downloadedDrawable);
        task.execute(context, url, TYPE_TOP);
    }
}

From source file:com.example.util.ImageUtils.java

/**
 * /*  w ww  .jav a 2  s  .  c  om*/
 */
public static void downloadDeatilScreenshot(Context context, String url, ImageView imageView) {

    Drawable defaultDrawable = new BitmapDrawable();
    if (cancelPotentialBitmapDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
        DownloadedDrawable1 downloadedDrawable = new DownloadedDrawable1(defaultDrawable, task);
        imageView.setImageDrawable(downloadedDrawable);
        task.execute(context, url, TYPE_SCREENSHOT);
    }
}

From source file:com.conferenceengineer.android.iosched.util.ImageLoader.java

private static ImageListener getImageListener(final Resources resources, final ImageView imageView,
        final Drawable placeHolder, final boolean fadeInImage) {
    return new ImageListener() {
        @Override/*from w ww .  ja v  a 2s. com*/
        public void onResponse(ImageContainer response, boolean isImmediate) {
            imageView.setTag(null);
            if (response.getBitmap() != null) {
                setImageBitmap(imageView, response.getBitmap(), resources, fadeInImage && !isImmediate);
            } else {
                imageView.setImageDrawable(placeHolder);
            }
        }

        @Override
        public void onErrorResponse(VolleyError volleyError) {
        }
    };
}

From source file:com.DGSD.DGUtils.ImageDownloader.ImageLoader.java

private static void start(String imageUrl, ImageView imageView, ImageLoaderHandler handler,
        Drawable dummyDrawable, Drawable errorDrawable) {
    if (imageView != null) {
        if (imageUrl == null) {
            // In a ListView views are reused, so we must be sure to remove the tag that could
            // have been set to the ImageView to prevent that the wrong image is set.
            imageView.setTag(null);//from w  w w  .j  a  v a  2 s .  c  o m
            imageView.setImageDrawable(dummyDrawable);
            return;
        }
        String oldImageUrl = (String) imageView.getTag();
        if (imageUrl.equals(oldImageUrl)) {
            // nothing to do
            return;
        } else {
            // Set the dummy image while waiting for the actual image to be downloaded.
            imageView.setImageDrawable(dummyDrawable);
            imageView.setTag(imageUrl);
        }
    }

    if (imageCache.containsKeyInMemory(imageUrl)) {
        // do not go through message passing, handle directly instead
        handler.handleImageLoaded(imageCache.getBitmap(imageUrl), null);
    } else {
        executor.execute(new ImageLoader(imageUrl, handler));
    }
}

From source file:com.dm.material.dashboard.candybar.helpers.ViewHelper.java

public static void removeSearchViewSearchIcon(@Nullable View view) {
    if (view != null) {
        ImageView searchIcon = (ImageView) view;
        ViewGroup linearLayoutSearchView = (ViewGroup) view.getParent();
        if (linearLayoutSearchView != null) {
            linearLayoutSearchView.removeView(searchIcon);
            linearLayoutSearchView.addView(searchIcon);

            searchIcon.setAdjustViewBounds(true);
            searchIcon.setMaxWidth(0);/*  ww w  . j  av  a 2 s. co m*/
            searchIcon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            searchIcon.setImageDrawable(null);
        }
    }
}

From source file:com.example.util.ImageUtils.java

/**
 * // w  w  w .  j ava  2  s .c om
 */
public static void downloadScreenShot(Context context, String url, ImageView imageView) {

    AnimationDrawable loadingDrawable = new LoadingDrawable(context);
    if (cancelPotentialImageDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);

        DownloadedDrawable2 downloadedDrawable = new DownloadedDrawable2(loadingDrawable, task);
        // clear the old image
        imageView.setImageDrawable(null);
        imageView.setBackgroundDrawable(downloadedDrawable);
        downloadedDrawable.start();
        task.execute(context, url, TYPE_IMAGE);
    }
}