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.mallapp.utils.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.// ww w  .j ava2 s  . c o  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.setBackground(imageView.getDrawable());
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        bitmap = getCroppedBitmap(bitmap);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.kiddobloom.bucketlist.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.  ja v a  2s  .  com*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in
    // DownloadedDrawable and cache keys.
    //Log.d("tag", "download " + url + " imageView: " + imageView);

    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:cat.joronya.utils.image.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 w w.jav  a2 s .c o m*/
public void download(String url, ImageView imageView, Drawable defaultDrawable) {
    this.defaultDrawable = defaultDrawable;
    resetPurgeTimer();

    // esta a notFounds?
    if (notFounds.contains(url)) {
        imageView.setImageDrawable(defaultDrawable);
        return;
    }

    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:net.idlesoft.android.apps.github.activities.Commit.java

protected void buildUi() {
    // Get the commit data for that commit ID so that we can get the
    // tree ID and filename.
    try {//from w w  w  . j a  v  a2 s  .  co m
        final ImageView authorImage = (ImageView) findViewById(R.id.commit_view_author_gravatar);
        final ImageView committerImage = (ImageView) findViewById(R.id.commit_view_committer_gravatar);

        // If the committer is the author then just show them as the
        // author, otherwise show
        // both people
        ((TextView) findViewById(R.id.commit_view_author_name)).setText(mAuthorName);
        if (mAuthorGravatar != null) {
            authorImage.setImageBitmap(mAuthorGravatar);
        } else {
            authorImage.setImageBitmap(Commit.loadGravatarByLoginName(Commit.this, mAuthor));
        }

        // Set the commit message
        ((TextView) findViewById(R.id.commit_view_message)).setText(mJson.getString("message"));

        final SimpleDateFormat dateFormat = new SimpleDateFormat(Hubroid.GITHUB_TIME_FORMAT);
        Date commit_time;
        Date current_time;
        String authorDate = "";

        try {
            commit_time = dateFormat.parse(mJson.getString("authored_date"));
            current_time = dateFormat.parse(dateFormat.format(new Date()));
            ((TextView) findViewById(R.id.commit_view_author_time))
                    .setText(Commit.getHumanDate(current_time, commit_time));

            commit_time = dateFormat.parse(mJson.getString("committed_date"));
            authorDate = Commit.getHumanDate(current_time, commit_time);

        } catch (final ParseException e) {
            e.printStackTrace();
        }

        if (!mAuthor.equals(mCommitter)) {
            // They are not the same person, make the author visible and
            // fill in the details
            ((LinearLayout) findViewById(R.id.commit_view_author_layout)).setVisibility(View.VISIBLE);
            ((TextView) findViewById(R.id.commit_view_committer_name)).setText(mCommitterName);
            ((TextView) findViewById(R.id.commit_view_committer_time)).setText(authorDate);
            if (mCommitterGravatar != null) {
                committerImage.setImageBitmap(mCommitterGravatar);
            } else {
                committerImage.setImageBitmap(Commit.loadGravatarByLoginName(Commit.this, mCommitter));
            }
        }

        final OnClickListener onGravatarClick = new OnClickListener() {
            public void onClick(final View v) {
                final Intent i = new Intent(Commit.this, Profile.class);
                if (v.getId() == authorImage.getId()) {
                    i.putExtra("username", mAuthor);
                } else if (v.getId() == committerImage.getId()) {
                    i.putExtra("username", mCommitter);
                } else {
                    return;
                }
                startActivity(i);
            }
        };

        if ((mAuthor != null) && !mAuthor.equals("")) {
            authorImage.setOnClickListener(onGravatarClick);
        }
        if ((mCommitter != null) && !mCommitter.equals("")) {
            committerImage.setOnClickListener(onGravatarClick);
        }

        int filesAdded, filesRemoved, filesChanged;

        try {
            filesAdded = mJson.getJSONArray("added").length();
        } catch (final JSONException e) {
            filesAdded = 0;
        }
        try {
            filesRemoved = mJson.getJSONArray("removed").length();
        } catch (final JSONException e) {
            filesRemoved = 0;
        }
        try {
            filesChanged = mJson.getJSONArray("modified").length();
        } catch (final JSONException e) {
            filesChanged = 0;
        }

        final Button filesAddedButton = (Button) findViewById(R.id.btn_commit_addedFiles);
        final Button filesRemovedButton = (Button) findViewById(R.id.btn_commit_removedFiles);
        final Button filesChangedButton = (Button) findViewById(R.id.btn_commit_changedFiles);

        Log.d("debug", filesAdded + " " + filesRemoved + " " + filesChanged);
        if (filesAdded > 0) {
            filesAddedButton.setText(filesAdded + " files added");
        } else {
            filesAddedButton.setVisibility(View.GONE);
        }
        if (filesRemoved > 0) {
            filesRemovedButton.setText(filesRemoved + " files removed");
        } else {
            filesRemovedButton.setVisibility(View.GONE);
        }
        if (filesChanged > 0) {
            filesChangedButton.setText(filesChanged + " files changed");
        } else {
            filesChangedButton.setVisibility(View.GONE);
        }

        filesAddedButton.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
                final Intent i = new Intent(Commit.this, DiffFilesList.class);
                i.putExtra("type", "added");
                i.putExtra("json", mJson.toString());
                i.putExtra("repo_owner", mRepositoryOwner);
                i.putExtra("repo_name", mRepositoryName);
                startActivity(i);
            }
        });
        filesRemovedButton.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
                final Intent i = new Intent(Commit.this, DiffFilesList.class);
                i.putExtra("type", "removed");
                i.putExtra("json", mJson.toString());
                i.putExtra("repo_owner", mRepositoryOwner);
                i.putExtra("repo_name", mRepositoryName);
                startActivity(i);
            }
        });
        filesChangedButton.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
                final Intent i = new Intent(Commit.this, DiffFilesList.class);
                i.putExtra("type", "modified");
                i.putExtra("json", mJson.toString());
                i.putExtra("repo_owner", mRepositoryOwner);
                i.putExtra("repo_name", mRepositoryName);
                startActivity(i);
            }
        });
    } catch (final JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.fivehundredpxdemo.android.storage.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView/*from www.  ja  va2  s .c  o  m*/
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Use TransitionDrawable to fade in
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        //noinspection deprecation
        imageView.setBackgroundDrawable(imageView.getDrawable());
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.linhnv.apps.funnybox.utils.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView//from w  w w  .jav a2  s  .c om
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        imageView.setImageDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
        imageView.setBackgroundColor(Color.BLACK);
    }
}

From source file:cn.mimail.sdk.net.image.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView//  w w  w. j  a v a  2  s  .  c om
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

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

From source file:com.c4mprod.utils.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 a  v  a  2  s  .c  om
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);
            imageView.setBackgroundDrawable((default_img));
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
            imageView.setImageDrawable(downloadedDrawable);

            imageView.setMinimumHeight(156);
            task.execute(url);
            break;
        }
    }
}

From source file:com.listviewaddheader.cache.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  a  v  a 2  s  .  c  o m
private void forceDownload(String url, ImageView imageView, String cookie, int defaultPicType) {
    try {

        // State sanity: url is guaranteed to never be null in
        if (url == null && imageView != null) {
            // 
            imageView.setImageBitmap(getDefaultBitmap(mContext));
            return;
        }

        if (cancelPotentialDownload(url, imageView)) {

            // mBitmapDownloaderTaskCache.remove(url);

            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);

            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, mContext, defaultPicType);

            // imageView.setImageDrawable(downloadedDrawable);

            imageView.setTag(downloadedDrawable);

            task.execute(url, cookie);

            // 
            // mBitmapDownloaderTaskCache.put(url, task);
        }

    } catch (RejectedExecutionException localRejectedExecutionException) {
        Logger.w(TAG, "localRejectedExecutionException");
    }
}

From source file:com.poloniumarts.utils.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.
 * /*from  w  ww  . j  a  v a  2s .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(String url, ImageView imageView) {
    if (bitmapCachePath == null) {
        if (imageView.getContext().getExternalFilesDir(null) != null) {
            bitmapCachePath = imageView.getContext().getExternalFilesDir(null).getAbsolutePath()
                    + "/ImageDownloaderCache";
        }
    }
    resetPurgeTimer();

    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
    }
}