List of usage examples for android.widget ImageView setImageBitmap
@android.view.RemotableViewMethod public void setImageBitmap(Bitmap bm)
From source file:com.gh4a.utils.ImageDownloader.java
public void download(String gravatarId, ImageView ivImage, int size) { String url = "http://www.gravatar.com/avatar.php?gravatar_id=" + gravatarId + "&size=" + size + "&d=mm"; resetPurgeTimer();//from w w w .j a v a 2 s .c o m Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { if (cancelPotentialDownload(url, ivImage)) { BitmapDownloaderTask task = new BitmapDownloaderTask(ivImage); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task); ivImage.setImageDrawable(downloadedDrawable); task.execute(url); } } else { cancelPotentialDownload(url, ivImage); ivImage.setImageBitmap(bitmap); } }
From source file:com.roger.lineselectionwebview.LSWebView.java
/** * ?/* w w w . j a va2 s .c o m*/ */ private void drawImage() { int size = rectList.size(); Rect endRect = rectList.get(size - 1); Rect realEndRect = endRect; // ?left???,,? if (size > 2) { Rect endPreRect = rectList.get(size - 2); if (endRect.left == endPreRect.left) { if (endRect.width() > endPreRect.width()) { realEndRect = endPreRect; } else { realEndRect = endRect; } } } Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.del); ImageView imageView = new ImageView(mContext); imageView.setImageBitmap(bitmap); imageView.setScaleType(ScaleType.CENTER); imageView.setTag(selectContext); MyAbsoluteLayout.LayoutParams lp = new MyAbsoluteLayout.LayoutParams( MyAbsoluteLayout.LayoutParams.WRAP_CONTENT, MyAbsoluteLayout.LayoutParams.WRAP_CONTENT, realEndRect.right, realEndRect.bottom); imageView.setLayoutParams(lp); imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String tag = (String) v.getTag(); lineView.remove(tag); myLayout.removeView(v); if (onTextSelectListener != null) { onTextSelectListener.cancle(tag.split(SELECT_SPLIT)[0]); } } }); myLayout.addView(imageView, lp); }
From source file:android.support.asy.image.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set * on the ImageView.//from ww w .j av a 2 s . c o m * * @param imageView * @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.goliathonline.android.kegbot.ui.DrinkDetailFragment.java
private void onUsersQueryComplete(Cursor cursor) { try {/*from w w w.j a v a2 s .co m*/ mSpeakersCursor = true; // TODO: remove any existing speakers from layout, since this cursor // might be from a data change notification. final ViewGroup speakersGroup = (ViewGroup) mRootView.findViewById(R.id.drink_user_block); final LayoutInflater inflater = getActivity().getLayoutInflater(); boolean hasSpeakers = false; while (cursor.moveToNext()) { final String userName = cursor.getString(UserQuery.USER_ID); if (TextUtils.isEmpty(userName)) { continue; } final String speakerImageUrl = cursor.getString(UserQuery.USER_IMAGE_URL); String speakerHeader = userName; final View speakerView = inflater.inflate(R.layout.user_detail, speakersGroup, false); final TextView speakerHeaderView = (TextView) speakerView.findViewById(R.id.user_header); final ImageView speakerImgView = (ImageView) speakerView.findViewById(R.id.user_image); if (!TextUtils.isEmpty(speakerImageUrl)) { BitmapUtils.fetchImage(getActivity(), speakerImageUrl, null, null, new BitmapUtils.OnFetchCompleteListener() { public void onFetchComplete(Object cookie, Bitmap result) { if (result != null) { speakerImgView.setImageBitmap(result); } } }); } speakerHeaderView.setText(speakerHeader); speakersGroup.addView(speakerView); hasSpeakers = true; mHasSummaryContent = true; } speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE); // Show empty message when all data is loaded, and nothing to show if (mSessionCursor && !mHasSummaryContent) { mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } } finally { if (null != cursor) { cursor.close(); } } }
From source file:com.andreaszeiser.bob.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 ava 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, Bitmap loadingBitmap, ImageWorkerListener listener) { Bitmap bitmap = null; if (data == null) { // no valid url, set loading image instead bitmap = loadingBitmap; } if (bitmap == null && mImageCache != null) { bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (bitmap != null) { // Bitmap found in memory cache if (listener == null || !listener.onImageLoaded(imageView, bitmap)) { imageView.setImageBitmap(bitmap); } } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView, listener); 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.eutectoid.dosomething.picker.GraphObjectAdapter.java
protected void populateGraphObjectView(View view, JSONObject graphObject) { String id = getIdOfGraphObject(graphObject); view.setTag(id);/*from ww w . j a va2 s.co m*/ CharSequence title = getTitleOfGraphObject(graphObject); TextView titleView = (TextView) view.findViewById(R.id.com_facebook_picker_title); if (titleView != null) { titleView.setText(title, TextView.BufferType.SPANNABLE); } CharSequence subtitle = getSubTitleOfGraphObject(graphObject); TextView subtitleView = (TextView) view.findViewById(R.id.picker_subtitle); if (subtitleView != null) { if (subtitle != null) { subtitleView.setText(subtitle, TextView.BufferType.SPANNABLE); subtitleView.setVisibility(View.VISIBLE); } else { subtitleView.setVisibility(View.GONE); } } if (getShowCheckbox()) { CheckBox checkBox = (CheckBox) view.findViewById(R.id.com_facebook_picker_checkbox); updateCheckboxState(checkBox, isGraphObjectSelected(id)); } if (getShowPicture()) { Uri pictureURI = getPictureUriOfGraphObject(graphObject); if (pictureURI != null) { ImageView profilePic = (ImageView) view.findViewById(R.id.com_facebook_picker_image); // See if we have already pre-fetched this; if not, download it. if (prefetchedPictureCache.containsKey(id)) { ImageResponse response = prefetchedPictureCache.get(id); profilePic.setImageBitmap(response.getBitmap()); profilePic.setTag(response.getRequest().getImageUri()); } else { downloadProfilePicture(id, pictureURI, profilePic); } } } }
From source file:com.slava.android.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. * @param url The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. *///w w w. j a va 2 s .c om public void download(String url, ImageView imageView, int cornersRadius) { resetPurgeTimer(); // Get image from hash map if it is there Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { File file = mExternalCache.checkExternalCache(url); if (file != null) { // Image is in external cache externalDownload(url, imageView, cornersRadius, file); } else { // Image must be downloaded from server forceDownload(url, imageView, cornersRadius); } } else { // Image is in hash map cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); } }
From source file:com.trk.aboutme.facebook.widget.GraphObjectAdapter.java
protected void populateGraphObjectView(View view, T graphObject) { String id = getIdOfGraphObject(graphObject); view.setTag(id);/*from w w w . j a va 2 s .co m*/ CharSequence title = getTitleOfGraphObject(graphObject); TextView titleView = (TextView) view.findViewById(R.id.com_facebook_picker_title); if (titleView != null) { titleView.setText(title, TextView.BufferType.SPANNABLE); } CharSequence subtitle = getSubTitleOfGraphObject(graphObject); TextView subtitleView = (TextView) view.findViewById(R.id.picker_subtitle); if (subtitleView != null) { if (subtitle != null) { subtitleView.setText(subtitle, TextView.BufferType.SPANNABLE); subtitleView.setVisibility(View.VISIBLE); } else { subtitleView.setVisibility(View.GONE); } } if (getShowCheckbox()) { CheckBox checkBox = (CheckBox) view.findViewById(R.id.com_facebook_picker_checkbox); updateCheckboxState(checkBox, isGraphObjectSelected(id)); } if (getShowPicture()) { URL pictureURL = getPictureUrlOfGraphObject(graphObject); if (pictureURL != null) { ImageView profilePic = (ImageView) view.findViewById(R.id.com_facebook_picker_image); // See if we have already pre-fetched this; if not, download it. if (prefetchedPictureCache.containsKey(id)) { ImageResponse response = prefetchedPictureCache.get(id); profilePic.setImageBitmap(response.getBitmap()); profilePic.setTag(response.getRequest().getImageUrl()); } else { downloadProfilePicture(id, pictureURL, profilePic); } } } }
From source file:com.itime.team.itime.fragments.QRCodeFragment.java
@NonNull @Override/*ww w . ja v a 2 s .c o m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { final Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.fragment_profile_qrcode); ImageView imageView = (ImageView) dialog.findViewById(R.id.setting_profile_qrcode_img); final Bundle arguments = getArguments(); if (!arguments.isEmpty()) { mUserId = arguments.getString(QRCODE_STRING); } Bitmap qrCodeBitmap; // method1: change a fix dip to pixel //final int dim = DensityUtil.dip2px(getContext(), 600); // method2: get the display size and scale into 7/8 // This assumes the view is full screen, which is a good assumption WindowManager manager = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point displaySize = new Point(); display.getSize(displaySize); int width = displaySize.x; int height = displaySize.y; int smallerDimension = width < height ? width : height; final int dim = smallerDimension * 7 / 8; try { qrCodeBitmap = barcodeEncoder.encodeBitmap(mUserId, BarcodeFormat.QR_CODE, dim, dim); imageView.setImageBitmap(qrCodeBitmap); } catch (WriterException e) { Toast.makeText(getActivity(), "QRCode text can not be empty", Toast.LENGTH_SHORT).show(); } return dialog; }
From source file:com.example.gtuandroid.component.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/*from ww w .j av a2s. c om*/ * The URL of the image to download. * @param imageView * The ImageView to bind the downloaded image to. */ public void download(final String url, final ImageView imageView) { Thread thread = new Thread(new Runnable() { @Override public void run() { resetPurgeTimer(); final Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { forceDownload(url, imageView); } else { cancelPotentialDownload(url, imageView); // imageView.setImageBitmap(bitmap); handler.post(new Runnable() { @Override public void run() { imageView.setImageBitmap(bitmap); } }); } } }); thread.start(); // ThreadPoolManager.getInstance().addSelectPhotoTask(thread); }