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:com.abcs.sociax.gimgutil.ImageWorker.java

public void loadImage(Object data, ImageView imageView) {

    if (data == null) {
        return;//from   w  w  w  .  java 2  s  .  c  o m
    }

    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.appbase.androidquery.callback.BitmapAjaxCallback.java

private void setBitmap(String url, ImageView iv, Bitmap bm, boolean isPreset) {

    if (bm == null) {
        iv.setImageDrawable(null);
        return;/*www  .j a v  a 2 s  . co  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.appbase.androidquery.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);/*  ww  w.j  a  va  2s.  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.fivehundredpxdemo.android.storage.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#addImageCache}. If the image is found in the memory cache, it
 * is set immediately, otherwise an {@link android.os.AsyncTask} will be created to asynchronously load the
 * bitmap./*  ww  w .  j  a  v 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(Object data, ImageView imageView, Bitmap loadingBitmap) {
    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, loadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            // On HC+ we execute on a quad thread executor. There really isn't much extra
            // benefit to having a really large pool of threads. Having more than one will
            // likely benefit network bottlenecks though.
            task.executeOnExecutor(QUAD_THREAD_EXECUTOR, data);
        } else {
            // Otherwise pre-HC the default is a thread pool executor (not ideal, serial
            // execution or a smaller number of threads would be better).
            task.execute(data);
        }
    }
}

From source file:com.google.android.apps.iosched.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#addImageCache}. 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 . ja va  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(Object data, ImageView imageView, Bitmap loadingBitmap) {
    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, loadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);

        if (UIUtils.hasHoneycomb()) {
            // On HC+ we execute on a dual thread executor. There really isn't much extra
            // benefit to having a really large pool of threads. Having more than one will
            // likely benefit network bottlenecks though.
            task.executeOnExecutor(DUAL_THREAD_EXECUTOR, data);
        } else {
            // Otherwise pre-HC the default is a thread pool executor (not ideal, serial
            // execution or a smaller number of threads would be better).
            task.execute(data);
        }
    }
}

From source file:com.appgeneration.magmanager.imagefetcher.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#addImageCache}. 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.//  w  w w  .  j av 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, Bitmap loadingBitmap) {
    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, loadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);

        if (UIUtils.hasHoneycomb()) {
            // On HC+ we execute on a dual thread executor. There really isn't much extra
            // benefit to having a really large pool of threads. Having more than one will
            // likely benefit network bottlenecks though.
            task.executeOnExecutor(DUAL_THREAD_EXECUTOR, data);
        } else {
            // Otherwise pre-HC the default is a thread pool executor (not ideal, serial
            // execution or a smaller number of threads would be better).
            task.execute(data);
        }
    }
}

From source file:com.lastorder.pushnotifications.data.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. ja  v a  2  s  . co  m*/
private void forceDownload(String url, ImageView imageView, ProgressBar bar) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null || !url.contains(".") || url.length() <= 6 || url.contains("null")) {
        bar.setVisibility(8);
        imageView.setImageResource(R.drawable.ic_launcher);
        imageView.setVisibility(0);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView, bar);
        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
        imageView.setImageDrawable(downloadedDrawable);
        imageView.setMinimumHeight(156);
        task.execute(url);
    }
}

From source file:com.zhihuigu.sosoOffice.utils.ImageDownloaderId.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  . ja  v  a 2 s. c o  m
private void forceDownload(File file, String sql, String id, String pixelswidth, String pixelsheight,
        String request_name, ImageView imageView, String x, String y, String width, String height) {
    // State sanity: url is guaranteed to never be null in
    // DownloadedDrawable and cache keys.
    if (file.getAbsolutePath() == null) {
        //         imageView.setImageResource(resid);
        return;
    }
    Log.i("", imageView.toString() + "-----" + file.getAbsolutePath());
    if (cancelPotentialDownload(file.getAbsolutePath(), imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, context, resid);
        imageView.setImageDrawable(downloadedDrawable);

        task.execute(file, sql, id, pixelswidth, pixelsheight, request_name, x, y, width, height);
    }
}

From source file:com.elephant.ediyou.imagecache.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 .co  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.closeTimer();
        imageView.setImageBitmap(bitmap);
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        //            imageView.closeTimer();
        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.elephant.ediyou.imagecache2.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 .  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.closeTimer();
        imageView.setImageBitmap(bitmap);
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        //            imageView.closeTimer();
        imageView.setImageDrawable(asyncDrawable);
        //            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        // 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);
    }
}