List of usage examples for android.widget ImageView setImageBitmap
@android.view.RemotableViewMethod public void setImageBitmap(Bitmap bm)
From source file:com.nd.teacherplatform.util.ImageDownloader.java
/** * //w ww .j av a 2 s .co m * dDD{]?C * * @param url * @param imageView * imageview * @param width * * @param height * * @param loadingDrawable_ID * * @param failDrawable_ID * * @param isSaveLocal * * @param action * MyGoPlusV3 * * <pre> * * 2013-6-13 ? * </pre> */ public void download(String url, ImageView imageView, int width, int height, int loadingDrawable_ID, int failDrawable_ID, boolean isSaveLocal, ImageDownLoaderAction action) { // Bitmap bitmap = getBitmapFromCache(url); Bitmap bitmap = null; /* */ if (bitmap == null && isSaveLocal) { bitmap = getBitmapFromLocal(url, Constants.FILE_CACHE, width, height); } /* */ if (bitmap == null) { forceDownload(url, imageView, width, height, Constants.FILE_CACHE, loadingDrawable_ID, failDrawable_ID, isSaveLocal, action); } else { cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); if (action != null) { action.downFinish(); } } }
From source file:com.android.tv.settings.dialog.SettingsLayoutFragment.java
private void initializeContentView(View content) { TextView titleView = (TextView) content.findViewById(R.id.title); TextView breadcrumbView = (TextView) content.findViewById(R.id.breadcrumb); TextView descriptionView = (TextView) content.findViewById(R.id.description); titleView.setText(mTitle);//from www .j a v a2s . c om breadcrumbView.setText(mBreadcrumb); descriptionView.setText(mDescription); final ImageView iconImageView = (ImageView) content.findViewById(R.id.icon); iconImageView.setBackgroundColor(mIconBackgroundColor); // Force text fields to be focusable when accessibility is enabled. if (AccessibilityHelper.forceFocusableViews(getActivity())) { titleView.setFocusable(true); titleView.setFocusableInTouchMode(true); descriptionView.setFocusable(true); descriptionView.setFocusableInTouchMode(true); breadcrumbView.setFocusable(true); breadcrumbView.setFocusableInTouchMode(true); } if (mIcon != null) { iconImageView.setImageDrawable(mIcon); updateViewSize(iconImageView); } else if (mIconBitmap != null) { iconImageView.setImageBitmap(mIconBitmap); updateViewSize(iconImageView); } else if (mIconUri != null) { iconImageView.setVisibility(View.INVISIBLE); /* BitmapDownloader bitmapDownloader = BitmapDownloader.getInstance( content.getContext()); mBitmapCallBack = new BitmapCallback() { @Override public void onBitmapRetrieved(Bitmap bitmap) { if (bitmap != null) { mIconBitmap = bitmap; iconImageView.setVisibility(View.VISIBLE); iconImageView.setImageBitmap(bitmap); updateViewSize(iconImageView); } } }; bitmapDownloader.getBitmap(new BitmapWorkerOptions.Builder( content.getContext()).resource(mIconUri) .width(iconImageView.getLayoutParams().width).build(), mBitmapCallBack); */ } else { iconImageView.setVisibility(View.GONE); } content.setTag(R.id.title, titleView); content.setTag(R.id.breadcrumb, breadcrumbView); content.setTag(R.id.description, descriptionView); content.setTag(R.id.icon, iconImageView); }
From source file:com.nd.teacherplatform.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. *///from www. ja va 2s . c o m private void forceDownload(String url, ImageView imageView, int width, int height, String parentFullFileName, int loadingDrawable_ID, int failDrawable_ID, boolean isSaveLocal, ImageDownLoaderAction action) { // State sanity: url is guaranteed to never be null in // DownloadedDrawable and cache keys. if (url == null) { imageView.setImageResource(failDrawable_ID); return; } if (cancelPotentialDownload(url, imageView)) { /* modeCORRECT */ 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, failDrawable_ID, isSaveLocal, action); task.execute(url); break; case CORRECT: task = new BitmapDownloaderTask(imageView, width, height, parentFullFileName, failDrawable_ID, isSaveLocal, action); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, loadingDrawable_ID); imageView.setImageDrawable(downloadedDrawable); imageView.setMinimumHeight(156); try { task.execute(url); } catch (RejectedExecutionException localRejectedExecutionException) { } break; } } }
From source file:es.upv.riromu.arbre.main.MainActivity.java
private void rangeSeekBarChanged(int minValue, int maxValue) { {/*from w w w .ja va2 s.c o m*/ TextView imc = (TextView) findViewById(R.id.textView); imc.setVisibility(View.VISIBLE); ImageButton cropButton = (ImageButton) findViewById(R.id.button_crop); cropButton.setVisibility(View.GONE); ImageButton sendButton = (ImageButton) findViewById(R.id.button_send); sendButton.setVisibility(View.VISIBLE); ImageButton histButton = (ImageButton) findViewById(R.id.button_histogram); histButton.setVisibility(View.VISIBLE); ImageButton revertButton = (ImageButton) findViewById(R.id.button_revert); revertButton.setVisibility(View.VISIBLE); ImageView imagePalette = (ImageView) findViewById(R.id.palette); imagePalette.setVisibility(View.GONE); ImageWrapper imw = new ImageWrapper(); if (image_uri == null) image = Util.decodeSampledBitmapFromResource(getResources(), R.drawable.platanus_hispanica, MAX_SIZE, MAX_SIZE); if (image_uri != null) image = Util.decodeSampledBitmapFromUri(image_uri, MAX_SIZE, MAX_SIZE, this); // handle changed range values try { Log.i(TAG, "User selected new range values: MIN=" + minValue + ", MAX=" + maxValue); ImageView imv = (ImageView) findViewById(R.id.image_intro); if (state[CROP_IMAGE]) imw.setBitmap(croppedimage); else imw.setBitmap(image); imw.setMinV(minValue); imw.setMaxV(maxValue); ProcessImageTask pit = new ProcessImageTask(); imw = (ImageWrapper) pit.execute(imw).get(); treatedimage = imw.getBitmap(); imv.setImageBitmap(treatedimage); histogram = imw.getHistogram(); histograma = imw.getHist(); mascara = imw.getMask(); imc.setBackgroundColor( Color.rgb(imw.getR().intValue(), imw.getG().intValue(), imw.getB().intValue())); state[TREAT_IMAGE] = true; } catch (Exception e) { Log.e(TAG, "Error " + e.getMessage()); } } }
From source file:com.baijiahulian.common.crop.utils.FrescoImageLoader.java
/** * /*w w w . j a v a2 s .co m*/ * * @param url * @param imageSize */ private void displayImage(Uri url, ResizeOptions imageSize, final ImageView imageView, final DraweeHolder<GenericDraweeHierarchy> draweeHolder) { ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(url).setResizeOptions(imageSize)//? .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); final DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline .fetchDecodedImage(imageRequest, this); DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(draweeHolder.getController()).setImageRequest(imageRequest) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String s, ImageInfo imageInfo, Animatable animatable) { CloseableReference<CloseableImage> imageReference = null; try { imageReference = dataSource.getResult(); if (imageReference != null) { CloseableImage image = imageReference.get(); if (image != null && image instanceof CloseableStaticBitmap) { CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image; Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap(); if (bitmap != null && imageView != null) { imageView.setImageBitmap(bitmap); } } } } finally { dataSource.close(); CloseableReference.closeSafely(imageReference); } } }).setTapToRetryEnabled(true).build(); draweeHolder.setController(controller); }
From source file:behsaman.storytellerandroid.ScreenSlidePageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_screen_slide_page, container, false); // Set the title view to show the page number. ((TextView) rootView.findViewById(android.R.id.text1)).setText( //getString(R.string.title_template_step, mPageNumber + 1)); "Piece " + dataModel.getIndex()); ((TextView) rootView.findViewById(R.id.textview_fragment_textviewer)).setText(this.dataModel.getText_val()); final ImageView imgView = (ImageView) rootView.findViewById(R.id.imageViewComic); //Comics has picture as well if (storyType == STORY_TYPE.TEXT_ONLY) imgView.setVisibility(View.INVISIBLE); else {// w w w . jav a2 s. com //Load picture //dataModel.get // Start downloading piece one and show progress bar ServerIO.getInstance().download(dataModel.getPicture_file_addr(), new MyBinaryHttpResponseHandler() { @Override public void onFailure(int statusCode, Header[] headers, byte[] binaryData, Throwable error) { Log.e(TAG, "FAILLLEEEDDD:" + error.getMessage() + "\tStatusCode:" + statusCode + "\tBinaryData:" + binaryData); ServerIO.getInstance().connectionError(parentContext); } @Override public void onSuccess(int statusCode, Header[] headers, byte[] binaryData) { String dir = Utils.getCacheDir(parentContext).getAbsolutePath(); File f = new File( dir + "/" + dataModel.getStory_id().toString() + dataModel.getId().toString()); try { FileOutputStream writer = new FileOutputStream(f); writer.write(binaryData); writer.close(); FileInputStream inStream = new FileInputStream(f); Bitmap bitmap_skip = BitmapFactory.decodeStream(inStream); imgView.setImageBitmap(bitmap_skip); } catch (Exception e) { Log.e(TAG, e.getMessage()); } } }); } return rootView; }
From source file:com.eutectoid.dosomething.picker.GraphObjectAdapter.java
private void processImageResponse(ImageResponse response, String graphObjectId, ImageView imageView) { pendingRequests.remove(graphObjectId); if (response.getError() != null) { callOnErrorListener(response.getError()); }/*from w w w . j av a2 s . com*/ if (imageView == null) { // This was a pre-fetch request. if (response.getBitmap() != null) { // Is the cache too big? if (prefetchedPictureCache.size() >= MAX_PREFETCHED_PICTURES) { // Find the oldest one and remove it. String oldestId = prefetchedProfilePictureIds.remove(0); prefetchedPictureCache.remove(oldestId); } prefetchedPictureCache.put(graphObjectId, response); } } else if (graphObjectId.equals(imageView.getTag())) { Exception error = response.getError(); Bitmap bitmap = response.getBitmap(); if (error == null && bitmap != null) { imageView.setImageBitmap(bitmap); imageView.setTag(response.getRequest().getImageUri()); } } }
From source file:com.trk.aboutme.facebook.widget.GraphObjectAdapter.java
private void processImageResponse(ImageResponse response, String graphObjectId, ImageView imageView) { pendingRequests.remove(graphObjectId); if (response.getError() != null) { callOnErrorListener(response.getError()); }/*from w ww .j a va2 s .c o m*/ if (imageView == null) { // This was a pre-fetch request. if (response.getBitmap() != null) { // Is the cache too big? if (prefetchedPictureCache.size() >= MAX_PREFETCHED_PICTURES) { // Find the oldest one and remove it. String oldestId = prefetchedProfilePictureIds.remove(0); prefetchedPictureCache.remove(oldestId); } prefetchedPictureCache.put(graphObjectId, response); } } else if (imageView != null && graphObjectId.equals(imageView.getTag())) { Exception error = response.getError(); Bitmap bitmap = response.getBitmap(); if (error == null && bitmap != null) { imageView.setImageBitmap(bitmap); imageView.setTag(response.getRequest().getImageUrl()); } } }
From source file:com.fastbootmobile.encore.app.fragments.RecognitionFragment.java
private void loadAlbumArt(final String urlString, final ImageView iv) { new Thread() { public void run() { URL url;//from www .ja v a2 s.c o m try { url = new URL(urlString); } catch (MalformedURLException e) { // Too bad mHandler.post(new Runnable() { @Override public void run() { mIvArt.setImageResource(R.drawable.album_placeholder); } }); return; } Log.d(TAG, "Loading album art: " + urlString); try { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is = conn.getInputStream(); byte[] buffer = new byte[8192]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); int read; while ((read = is.read(buffer)) > 0) { baos.write(buffer, 0, read); } final Bitmap bmp = BitmapFactory.decodeByteArray(baos.toByteArray(), 0, baos.size()); if (bmp != null) { mHandler.post(new Runnable() { @Override public void run() { iv.setImageBitmap(bmp); iv.setVisibility(View.VISIBLE); } }); } else { Log.e(TAG, "Null bitmap from image"); } } catch (IOException e) { Log.e(TAG, "Error downloading album art", e); mHandler.post(new Runnable() { @Override public void run() { iv.setImageResource(R.drawable.album_placeholder); iv.setVisibility(View.VISIBLE); } }); } } }.start(); }
From source file:com.xiaoyu.DoctorHelp.chat.chatuidemo.adapter.MessageAdapter.java
/** * // ww w. j ava 2 s .c o m * * @param localThumb * @param iv * @param thumbnailUrl * @param message */ private void showVideoThumbView(String localThumb, ImageView iv, String thumbnailUrl, final EMMessage message) { // first check if the thumbnail image already loaded into cache Bitmap bitmap = ImageCache.getInstance().get(localThumb); if (bitmap != null) { // thumbnail image is already loaded, reuse the drawable iv.setImageBitmap(bitmap); iv.setClickable(true); iv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { VideoMessageBody videoBody = (VideoMessageBody) message.getBody(); EMLog.d(TAG, "video view is on click"); Intent intent = new Intent(activity, ShowVideoActivity.class); intent.putExtra("localpath", videoBody.getLocalUrl()); intent.putExtra("secret", videoBody.getSecret()); intent.putExtra("remotepath", videoBody.getRemoteUrl()); if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked && message.getChatType() != ChatType.GroupChat && message.getChatType() != ChatType.ChatRoom) { message.isAcked = true; try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (Exception e) { e.printStackTrace(); } } activity.startActivity(intent); } }); } else { new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv, activity, message, this); } }