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.mobicage.rogerthat.FriendDetailActivity.java

@SuppressWarnings("WrongConstant")
private Friend showFriend(Intent intent) {
    T.UI();//from  w  ww  .j a va 2  s  . c  o  m

    final Friend friend = loadFriend(intent);
    if (friend == null) {
        return null;
    }

    mServiceArea.setVisibility(getServiceAreaVisibility());
    mPokeArea.setVisibility(getPokeVisibility());
    mFriendArea.setVisibility(getFriendAreaVisibility());
    mHeader.setVisibility(getHeaderVisibility());

    final ImageView image = (ImageView) findViewById(R.id.friend_avatar);
    if (friend.avatar == null) {
        image.setImageBitmap(mFriendsPlugin.getMissingFriendAvatarBitmap());
    } else {
        final Bitmap avatarBitmap = BitmapFactory.decodeByteArray(friend.avatar, 0, friend.avatar.length);
        image.setImageBitmap(ImageHelper.getRoundedCornerAvatar(avatarBitmap));
    }

    final TextView nameView = (TextView) findViewById(R.id.friend_name);
    mFriendName = friend.getDisplayName();
    nameView.setText(mFriendName);
    nameView.setTextColor(ContextCompat.getColor(this, android.R.color.primary_text_light));

    final TextView emailView = (TextView) findViewById(R.id.email);
    emailView.setText(friend.getDisplayEmail());
    emailView.setTextColor(nameView.getTextColors());

    if (friend.existenceStatus == Friend.NOT_FOUND || friend.existenceStatus == Friend.INVITE_PENDING) {
        final Button pokeBtn = (Button) findViewById(R.id.poke_button);
        pokeBtn.setText(R.string.follow);
        pokeBtn.setOnClickListener(new SafeViewOnClickListener() {
            @Override
            public void safeOnClick(View v) {
                if (mFriendsPlugin.inviteService(mFriend)) {
                    finish();
                }
            }
        });
    } else if (TextUtils.isEmptyOrWhitespace(friend.pokeDescription)) {
        findViewById(R.id.poke_area).setVisibility(View.GONE);
    } else {
        findViewById(R.id.poke_area).setVisibility(View.VISIBLE);
        final Button pokeBtn = (Button) findViewById(R.id.poke_button);
        pokeBtn.setText(friend.pokeDescription);
        pokeBtn.setOnClickListener(new SafeViewOnClickListener() {
            @Override
            public void safeOnClick(View v) {
                T.UI();
                poke();
            }
        });
    }

    mDescriptionView.setText(friend.description);

    if (friend.descriptionBranding != null) {
        boolean available = false;
        try {
            available = mFriendsPlugin.getBrandingMgr().isBrandingAvailable(friend.descriptionBranding);
        } catch (BrandingFailureException e) {
            // ignore
        }
        if (available) {
            showBrandedDescription(friend);
        } else {
            mFriendsPlugin.getBrandingMgr().queue(friend);
        }
    } else {
        mDescriptionView.setVisibility(View.VISIBLE);
        mServiceArea.findViewById(R.id.webview).setVisibility(View.GONE);
        mTopArea.setBackgroundResource(R.color.mc_background_color);
    }

    final CheckBox iShareLocationCheckBox = (CheckBox) findViewById(R.id.share_location);
    iShareLocationCheckBox.setOnCheckedChangeListener(null);
    iShareLocationCheckBox.setChecked(friend.shareLocation);
    iShareLocationCheckBox.setText(getString(R.string.friend_share_location));

    iShareLocationCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            T.UI();
            mFriendsPlugin.updateFriendShareLocation(friend.email, isChecked);
        }
    });

    dismissDialogs();

    return friend;
}

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.  j  a  va2s  .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, 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.//from w  w  w  .j a  va  2  s  . c  om
 *
 * @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:br.com.ettore.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 . j  ava2  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) {
        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 NO_DOWNLOADED_DRAWABLE:
            imageView.setMinimumHeight(156);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.execute(url);
            break;

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

From source file:com.test.weatherapp.adapters.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.
 *//* www  .  j  a va 2 s  . 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 NO_DOWNLOADED_DRAWABLE:
            imageView.setMinimumHeight(156);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.execute(url);
            break;

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

From source file:com.quipmate.loadingBitmaps.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.
 *///from   w  w w . j  ava2 s  .  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 NO_DOWNLOADED_DRAWABLE:
            imageView.setMinimumHeight(minHeight);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.execute(url);
            break;

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

From source file:cn.huaxingtan.util.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  . j a  v  a 2 s.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 NO_DOWNLOADED_DRAWABLE:
            imageView.setMinimumHeight(156);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
            break;

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

From source file:by.lykashenko.interfaces.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.
 */// w w  w  .  j a  v  a 2 s. co m
public void download(String url, ImageView imageView) {
    resetPurgeTimer();
    state = NewsActivity.state;
    path = NewsActivity.path;
    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        Log.d(LOG_TAG, "bitmap no");
        forceDownload(url, imageView);
    } else {
        Log.d(LOG_TAG, "bitmap ok");
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.cms.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.
 *///from   www  .ja  v  a2 s  .  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 NO_DOWNLOADED_DRAWABLE:
            imageView.setMinimumHeight(156);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.execute(url);
            break;

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

From source file:fr.gotorennes.AbstractMapActivity.java

protected void populateItineraireDetails(Itineraire itineraire) {
    LinearLayout details = (LinearLayout) findViewById(R.id.details);
    for (final Etape etape : itineraire.etapes) {
        addEtapeOverlay(etape);//  w  ww  .  j a  va 2 s  .  co m

        RelativeLayout view = (RelativeLayout) getLayoutInflater().inflate(R.layout.itineraire_listitem, null);

        ImageView lineIcon = (ImageView) view.findViewById(R.id.icon);
        if (etape.bitmapIcon != null) {
            lineIcon.setImageBitmap(etape.bitmapIcon);
        } else {
            lineIcon.setImageResource(etape.type.icon);
        }

        TextView name = (TextView) view.findViewById(R.id.name);
        name.setText(Html.fromHtml(Arret.getTime(etape.depart) + " : " + etape.adresseDepart + "<br />"
                + Arret.getTime(etape.arrivee) + " : " + etape.adresseArrivee));

        TextView duree = (TextView) view.findViewById(R.id.duree);
        duree.setText(etape.getDuree() + "min");

        TextView distance = (TextView) view.findViewById(R.id.distance);
        distance.setText(getFormattedDistance(etape.locationDepart, etape.locationArrivee));
        distance.setVisibility(
                etape.type == TypeEtape.PIETON || etape.type == TypeEtape.VELO ? View.VISIBLE : View.GONE);

        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Location depart = etape.locationDepart;
                centerMap(depart.latitude, depart.longitude);
            }
        });
        details.addView(view);
    }
    Location first = itineraire.etapes.get(0).locationDepart;
    centerMap(first.latitude, first.longitude);
}