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.codingPower.framework.worker.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView/*www. j  av a  2 s.  com*/
 * @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.geeker.door.imgcache.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.  j  av  a2s .c  om*/
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.thx.bizcat.util.ImageDownloader.java

public void imageViewProcessing(String localImgUrl, String ServerImgUrl, ImageView imageView) {
    //1.Cache Memory?  ? 
    Bitmap bitmap = getBitmapFromCache(localImgUrl);

    if (bitmap == null) {

        //? ?  ?  ?
        File file = new File(localImgUrl);
        if (file.exists()) {
            Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath());
            if (bm != null)
                imageView.setImageBitmap(bm);
            else//from  ww w.  j  a  v  a 2 s  .  c  om
                file.delete();
        } else {
            try {
                //? ?   
                URL url = new URL(ServerImgUrl);

                HttpURLConnection conn = (HttpURLConnection) url.openConnection();

                //? : Input Stream? ? ??  ? (?    ? ? )
                InputStream is = conn.getInputStream();

                FileOutputStream fos = new FileOutputStream(localImgUrl);

                int len = conn.getContentLength();
                byte[] raster = new byte[len];

                int Read = 0;
                while (true) {
                    Read = is.read(raster);
                    if (Read <= 0) {
                        break;
                    }
                    fos.write(raster, 0, Read);
                }

                is.close();
                fos.close();
                conn.disconnect();

                //? ? 
                Bitmap bm = BitmapFactory.decodeFile(localImgUrl);
                if (bm != null)
                    imageView.setImageBitmap(bm);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:ca.ualberta.cmput301w14t08.geochan.managers.ThreadManager.java

/**
 * Private constructor due to singleton pattern.
 *///  w ww. j a v a  2s .co  m
private ThreadManager() {
    commentListCache = new LruCache<String, CommentList>(MAXIMUM_CACHE_SIZE);
    getImageCache = new LruCache<String, Bitmap>(MAXIMUM_CACHE_SIZE);
    getPOICache = new LruCache<String, String>(MAXIMUM_CACHE_SIZE);

    getCommentListRunnableQueue = new LinkedBlockingQueue<Runnable>();
    getCommentsRunnableQueue = new LinkedBlockingQueue<Runnable>();
    postImageRunnableQueue = new LinkedBlockingQueue<Runnable>();
    postRunnableQueue = new LinkedBlockingQueue<Runnable>();
    updateRunnableQueue = new LinkedBlockingQueue<Runnable>();
    getImageRunnableQueue = new LinkedBlockingQueue<Runnable>();
    getThreadCommentsRunnableQueue = new LinkedBlockingQueue<Runnable>();
    getPOIRunnableQueue = new LinkedBlockingQueue<Runnable>();

    getCommentsTaskQueue = new LinkedBlockingQueue<GetCommentsTask>();
    postTaskQueue = new LinkedBlockingQueue<PostTask>();
    getImageTaskQueue = new LinkedBlockingQueue<GetImageTask>();
    getThreadCommentsTaskQueue = new LinkedBlockingQueue<GetThreadCommentsTask>();
    getPOITaskQueue = new LinkedBlockingQueue<GetPOITask>();

    getCommentListPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, getCommentListRunnableQueue);
    getCommentsPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, getCommentsRunnableQueue);
    postImagePool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, postImageRunnableQueue);
    postPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT,
            postRunnableQueue);
    updatePool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, updateRunnableQueue);
    getImagePool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, getImageRunnableQueue);
    getThreadCommentsPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, getThreadCommentsRunnableQueue);
    getPOIPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, getPOIRunnableQueue);

    handler = new Handler(Looper.getMainLooper()) {

        @Override
        public void handleMessage(Message inputMessage) {
            switch (inputMessage.what) {
            case POST_TASK_COMPLETE:
                PostTask postTaskComplete = (PostTask) inputMessage.obj;
                if (postTaskComplete.getDialog() != null) {
                    postTaskComplete.getDialog().dismiss();
                }
                ThreadComment threadComment = postTaskComplete.getThreadComment();
                if (threadComment != null) {
                    if (!postTaskComplete.isEdit()) {
                        // Update the model and sort accordingly
                        ThreadList.addThread(threadComment);
                        SortUtil.sortThreads(PreferencesManager.getInstance().getThreadSort(),
                                ThreadList.getThreads());
                    }
                    FragmentActivity activity = (FragmentActivity) context;
                    ThreadListFragment fragment = (ThreadListFragment) activity.getSupportFragmentManager()
                            .findFragmentByTag("threadListFrag");
                    if (fragment != null) {
                        fragment.finishReload();
                    }
                }
                break;

            case GET_THREADS_COMPLETE:
                GetThreadCommentsTask threadTask = (GetThreadCommentsTask) inputMessage.obj;
                threadTask.getFragment().finishReload();
                recycleGetThreadCommentsTask(threadTask);
                break;

            case GET_THREADS_FAILED:
                GetThreadCommentsTask threadTaskFail = (GetThreadCommentsTask) inputMessage.obj;
                threadTaskFail.getFragment().finishReload();
                recycleGetThreadCommentsTask(threadTaskFail);
                break;

            case GET_COMMENTS_COMPLETE:
                GetCommentsTask task = (GetCommentsTask) inputMessage.obj;
                task.getFragment().finishReload();
                recycleCommentsTask(task);
                break;

            case GET_COMMENTS_FAILED:
                GetCommentsTask taskFail = (GetCommentsTask) inputMessage.obj;
                taskFail.getFragment().finishReload();
                recycleCommentsTask(taskFail);
                break;

            case GET_COMMENT_LIST_RUNNING:
                break;

            case GET_COMMENT_LIST_FAILED:
                GetCommentsTask taskListFail = (GetCommentsTask) inputMessage.obj;
                taskListFail.getFragment().finishReload();
                recycleCommentsTask(taskListFail);
                break;

            case GET_IMAGE_RUNNING:
                GetImageTask imageTask = (GetImageTask) inputMessage.obj;
                if (imageTask.getDialog() != null) {
                    imageTask.getDialog().show();
                }
                break;

            case GET_IMAGE_FAILED:
                GetImageTask imageTaskFail = (GetImageTask) inputMessage.obj;
                if (imageTaskFail.getDialog() != null) {
                    imageTaskFail.getDialog().dismiss();
                }
                recycleGetImageTask(imageTaskFail);
                break;

            case GET_IMAGE_COMPLETE:
                GetImageTask imageTaskComplete = (GetImageTask) inputMessage.obj;
                if (imageTaskComplete.getDialog() != null) {
                    imageTaskComplete.getDialog().dismiss();
                }
                Bitmap bitmap = imageTaskComplete.getImageCache();
                String id = imageTaskComplete.getId();
                ImageView view = imageTaskComplete.getmImageWeakRef().get();
                if (view != null) {
                    view.setImageBitmap(bitmap);
                }
                CacheManager.getInstance().serializeImage(bitmap, id);
                recycleGetImageTask(imageTaskComplete);
                break;

            case GET_POI_RUNNING:
                GetPOITask poiTaskRunning = (GetPOITask) inputMessage.obj;
                if (poiTaskRunning.getDialog() != null) {
                    poiTaskRunning.getDialog().show();
                }
                break;

            case GET_POI_COMPLETE:
                GetPOITask poiTaskComplete = (GetPOITask) inputMessage.obj;
                if (poiTaskComplete.getDialog() != null) {
                    poiTaskComplete.getDialog().dismiss();
                }
                if (poiTaskComplete.getMarker() != null) {
                    poiTaskComplete.getMarker().setSubDescription((poiTaskComplete.getPOICache()));
                    poiTaskComplete.getMarker().showInfoWindow();

                }
                poiTaskComplete.getLocation().setLocationDescription(poiTaskComplete.getPOICache());
                recycleGetPOITask(poiTaskComplete);
                break;

            case GET_POI_FAILED:
                GetPOITask poiTaskFailed = (GetPOITask) inputMessage.obj;
                if (poiTaskFailed.getDialog() != null) {
                    poiTaskFailed.getDialog().dismiss();
                }
                if (poiTaskFailed.getMarker() != null) {
                    poiTaskFailed.getMarker().setSubDescription(("Unknown Location"));
                    poiTaskFailed.getMarker().showInfoWindow();
                }
                poiTaskFailed.getLocation().setLocationDescription("Unknown Location");
                recycleGetPOITask(poiTaskFailed);
                break;

            case POST_GET_POI_RUNNING:
                PostTask postPoiTaskRunning = (PostTask) inputMessage.obj;
                if (postPoiTaskRunning.getDialog() != null) {
                    postPoiTaskRunning.getDialog().show();
                }
                break;

            case POST_GET_POI_COMPLETE:
                PostTask postPoiTaskComplete = (PostTask) inputMessage.obj;
                if (postPoiTaskComplete.getDialog() != null) {
                    postPoiTaskComplete.getDialog().setMessage("Posting to Server");
                }
                break;

            case POST_GET_POI_FAILED:
                PostTask postPoiTaskFailed = (PostTask) inputMessage.obj;
                if (postPoiTaskFailed.getDialog() != null) {
                    postPoiTaskFailed.getDialog().dismiss();
                }
                break;

            case UPDATE_FAILED:
                PostTask postTaskUpdateFailed = (PostTask) inputMessage.obj;
                if (postTaskUpdateFailed.getDialog() != null) {
                    postTaskUpdateFailed.getDialog().dismiss();
                }
                break;

            case POST_FAILED:
                PostTask postTaskFailed = (PostTask) inputMessage.obj;
                if (postTaskFailed.getDialog() != null) {
                    postTaskFailed.getDialog().dismiss();
                }
                break;

            case POST_RUNNING:
                PostTask postTaskRun = (PostTask) inputMessage.obj;
                if (postTaskRun.getDialog() != null && !postTaskRun.getDialog().isShowing()) {
                    postTaskRun.getDialog().show();
                }
                break;

            case POST_IMAGE_FAILED:
                PostTask postTaskImageFailed = (PostTask) inputMessage.obj;
                if (postTaskImageFailed.getDialog() != null) {
                    postTaskImageFailed.getDialog().dismiss();
                }
                break;

            default:
                super.handleMessage(inputMessage);
                break;
            }
        }
    };
}

From source file:com.andreaszeiser.bob.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView./*from  www .  jav a2 s . c  om*/
 * 
 * @param imageView
 * @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.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.wanpaijie.www.http.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  . ja v a  2s  . co  m
public void download(String url, ImageView imageView, Context context) {
    resetPurgeTimer();
    if (url.length() > 0) {
        url = Http.imageHost + url;
    }
    Bitmap bitmap = getBitmapFromCache(url);
    this.current = context;
    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        LayoutParams lp = imageView.getLayoutParams();
        lp.height = Util.DiptoPx(this.current, bitmap.getHeight());
        lp.width = Util.DiptoPx(this.current, bitmap.getWidth());
        imageView.setLayoutParams(lp);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.geeker.door.imgcache.ImageDownloader.java

public void download(String url, ImageView imageView, ScaleType scaleType, boolean isDownload) {

    if (isDownload) {

        download(url, imageView, scaleType);

    } else {//  w w  w . jav a  2 s  . c  om

        if (scaleType != null) {

            imageView.setScaleType(scaleType);

        }

        imageView.setImageBitmap(getDefaultBitmap(mContext));

    }

}

From source file:com.crazyapk.util.bitmap.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView/*from w w w . j  a  v  a  2  s .  c  o m*/
 * @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.hackensack.umc.activity.ProfileActivity.java

private void setPhotoToImageView(String urlString, ImageView mImageView) {
    try {//from   ww  w .  ja  v a2s  .c  o m
        Bitmap bitmap = decodeUri(urlString, ProfileActivity.this);
        bitmap = CameraFunctionality.checkImageOrientation(bitmap, urlString.toString(), ProfileActivity.this);
        mImageView.setImageBitmap(bitmap);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.elephant.ediyou.imagecache.ImageWorker.java

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