Example usage for android.widget ImageView setImageBitmap

List of usage examples for android.widget ImageView setImageBitmap

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setImageBitmap(Bitmap bm) 

Source Link

Document

Sets a Bitmap as the content of this ImageView.

Usage

From source file:com.app.chasebank.contactslist.util.ImageLoader.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView The ImageView to set the bitmap to.
 * @param bitmap The new bitmap to set.//from w ww.  ja  v  a 2 s .co m
 */
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) });

        imageView.setBackgroundDrawable(imageView.getDrawable());
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.life.wuhan.util.ImageDownloader.java

private void forceDownload(String url, ImageView imageView) {
    if (url == null) {
        imageView.setImageDrawable(null);
        return;/*w ww .  j av a  2  s  .c o  m*/
    }

    if (cancelPotentialDownload(url, imageView)) {
        switch (mode) {
        case NO_ASYNC_TASK:
            Bitmap bitmap = downloadBitmap(url);
            addBitmapToCache(url, bitmap);
            imageView.setImageBitmap(bitmap);
            break;

        case NO_DOWNLOADED_DRAWABLE:
            imageView.setMinimumHeight(156);
            BitmapDownloaderTask task = null;

            task = new BitmapDownloaderTask(imageView);

            task.execute(url);
            break;

        case CORRECT:

            task = new BitmapDownloaderTask(imageView);
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(imageView.getResources(), task);
            imageView.setImageDrawable(downloadedDrawable);
            imageView.setMinimumHeight(156);
            task.execute(url);
            break;
        }
    }
}

From source file:se.dw.okhttpwrapper.ImageRequest.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.
 */// w  w  w  .  j  a  va2s .  c  o  m
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {

        switch (mode) {
        case NO_ASYNC_TASK:
            Bitmap bitmap = downloadBitmap(url);
            addBitmapToCache(url, bitmap);
            imageView.setImageBitmap(bitmap);
            break;

        case CORRECT:
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
            imageView.setImageDrawable(downloadedDrawable);
            imageView.setMinimumHeight(156);
            task.execute(url);
            break;
        }

    }
}

From source file:com.gokuai.yunkuandroidsdk.imageutils.ImageWorker.java

public void loadImage(Object data, ImageView imageView, boolean isRound) {
    if (data == null) {
        return;// w  ww.  j  a v  a2s. c o m
    }

    isRoundDrawable = isRound;

    BitmapDrawable value = null;

    if (mImageCache != null) {
        value = mImageCache.getBitmapFromMemCache(String.valueOf(data));
    }

    if (value != null) {
        // Bitmap found in memory cache
        //            Util.makeRoundDrawable(value, GKApplication.getInstance(),false);
        if (isRound) {
            imageView.setImageBitmap(Util.makeRoundDrawable(value, GKApplication.getInstance(), false));

        } else {
            imageView.setImageDrawable(value);
        }
    } 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:net.exclaimindustries.geohashdroid.wiki.WikiPictureEditor.java

private void setThumbnail() {
    // SET!//from w  ww . java2s  .  c  o  m
    ImageView thumbView = (ImageView) findViewById(R.id.ThumbnailImage);

    if (mCurrentThumbnail != null) {
        // If we have a thumbnail, by all means, put it in!
        thumbView.setImageBitmap(mCurrentThumbnail);
        thumbView.setVisibility(View.VISIBLE);
    } else {
        // Otherwise, make it vanish entirely.  This is handy for, say,
        // clearing the thumbnail after an upload.
        thumbView.setVisibility(View.GONE);
    }
}

From source file:com.lastorder.pushnotifications.data.ImageDownloader.java

/**
 * Download the specified image from the Internet and binds it to the provided ImageView. The
 * binding is immediate if the image is found in the cache and will be done asynchronously
 * otherwise. A null bitmap will be associated to the ImageView if an error occurs.
 *
 * @param url The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 *//*from   w ww. ja va2s  .co m*/

public void download(String url, ImageView imageView, Context context, ProgressBar bar) {
    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);
    myWeakContext = new WeakReference<Context>(context);

    if (bitmap == null) {
        bar.setVisibility(0);
        imageView.setVisibility(8);
        forceDownload(url, imageView, bar);
    } else {
        bar.setVisibility(8);
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
        imageView.setVisibility(0);
        imageView.bringToFront();
    }
}

From source file:com.crazyapk.util.bitmap.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.//  w  w  w.  j av a  2 s .  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, int corner) {
    mCorner = corner;
    if (data == null) {
        return;
    }
    Bitmap bitmap = null;
    if (mImageCache != null) {
        bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data));
    }
    //+    LogUtil.v("Bitmap Corner", ""+mCorner);
    if (bitmap != null) {
        // Bitmap found in memory cache
        if (corner > 0)
            bitmap = toRoundCorner(bitmap, mCorner);
        imageView.setImageBitmap(bitmap);
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView, mCorner);
        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.baksu.screenbroadcast2.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.
 *//*w w w . j av  a  2  s. co m*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        Log.i("imageUp", "URL? ?");
        imageView.setImageDrawable(null);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {
        switch (mode) {
        case NO_ASYNC_TASK:
            Log.i("imageUp", "NO_ASYNC_TASK");
            Bitmap bitmap = downloadBitmap(url);
            addBitmapToCache(url, bitmap);
            imageView.setImageBitmap(bitmap);
            break;

        case NO_DOWNLOADED_DRAWABLE:
            Log.i("imageUp", "NO_DOWNLOADED_DRAWABLE");
            imageView.setMinimumHeight(156);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.execute(url);
            break;

        case CORRECT:
            Log.i("imageUp", "CORRECT");
            task = new BitmapDownloaderTask(imageView);
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
            imageView.setImageDrawable(downloadedDrawable);
            imageView.setMinimumHeight(156);
            task.execute(url);
            break;
        }
    }
}

From source file:com.chinaLife.claimAssistant.tools.sc_ImageDownloaderId.java

/**
 * Download the specified image from the Internet and binds it to the
 * provided ImageView. The binding is immediate if the image is found in the
 * cache and will be done asynchronously otherwise. A null bitmap will be
 * associated to the ImageView if an error occurs.
 * /*w ww.  j  ava2  s  .c o m*/
 * @param url
 *            The URL of the image to download.
 * @param imageView
 *            The ImageView to bind the downloaded image to.
 */
public void download(File file, String id, ImageView imageView) {
    resetPurgeTimer(); // ?
    Bitmap bitmap = getBitmapFromCache(file.getAbsolutePath());
    if (id == null || id.trim().equals("") || id.trim().equals("0")) {
        return;
    }
    if (connection_count > connection_count_totle) {
        return;
    }
    if (bitmap == null) {
        System.out.println("1");
        forceDownload(file, id, imageView);
    } else {
        System.out.println("2");
        cancelPotentialDownload(file.getAbsolutePath(), imageView);

        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.microsoft.projectoxford.face.samples.ui.IdentificationActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == MY_DATA_CHECK_CODE) {
        myTTS = new TextToSpeech(this, this);
    }/*from  www  . j  ava 2 s. c o m*/

    switch (requestCode) {
    case REQUEST_SELECT_IMAGE:
        if (resultCode == RESULT_OK) {
            detected = false;

            // If image is selected successfully, set the image URI and bitmap.
            Uri imageUri = data.getData();
            if (mBitmap == null) {
                mBitmap = ImageHelper.loadSizeLimitedBitmapFromUri(imageUri, getContentResolver());
                if (mBitmap != null) {
                    // Show the image on screen.
                    ImageView imageView = (ImageView) findViewById(R.id.image);
                    imageView.setImageBitmap(mBitmap);
                }
            }

            // Clear the identification result.
            FaceListAdapter faceListAdapter = new FaceListAdapter(null);
            ListView listView = (ListView) findViewById(R.id.list_identified_faces);
            listView.setAdapter(faceListAdapter);

            // Clear the information panel.
            setInfo("");

            // TODO -> Load image from Firebase, and save it as a Bitmap Object here.

            // Start detecting in image.
            detect(mBitmap);
        }
        break;
    default:
        break;
    }
}