List of usage examples for android.widget ImageView getTag
@ViewDebug.ExportedProperty
public Object getTag()
From source file:com.channelsoft.common.bitmapUtil.ImageWorker.java
private void loadImage(ImageView imageView, ImageParams params) { if (imageView == null) { return;//from w w w .ja v a 2 s . c o m } Bitmap bitmap = null; if (mImageCache != null) { // if (params.loadType == ImageParams.LOAD_TYPE_LOCAL) { bitmap = mImageCache.getBitmapFromMemCache(params.path + params.reqWidth + params.reqHeight); } else if (params.loadType == ImageParams.LOAD_TYPE_THUMB_ID) { bitmap = mImageCache.getBitmapFromMemCache(params.thumbType + params.thumbId); } else if (params.loadType == ImageParams.LOAD_TYPE_THUMB_PATH) { bitmap = mImageCache.getBitmapFromMemCache(params.path); } else if (params.loadType == ImageParams.LOAD_TYPE_HTTP) { bitmap = mImageCache.getBitmapFromMemCache(params.path + params.reqWidth + params.reqHeight); } } if (bitmap != null) { if ("0".equals(imageView.getTag())) { // ?? bitmap = toGrayscale(bitmap); } imageView.setImageBitmap(bitmap); if (params.loadAfterListener != null) { params.loadAfterListener.onImgLoadAfter(true); } } else if (cancelPotentialWork(TextUtils.isEmpty(params.path) ? params.thumbId : params.path, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView); final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); imageView.setImageDrawable(asyncDrawable); // NOTE: This uses a custom version of AsyncTask that has been pulled from the // framework and slightly modified. Refer to the docs at the top of the class // for more info on what was changed. if (params.loadType == ImageParams.LOAD_TYPE_HTTP) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); } else { task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, params); } } }
From source file:uk.org.ngo.squeezer.util.ImageWorker.java
/** * Load an image specified by the data parameter into an ImageView (override {@link * ImageWorker#processBitmap(BitmapWorkerTaskParams)} to define the processing logic). A memory and disk cache * will be used if an {@link ImageCache} has been set using {@link * ImageWorker#setImageCache(ImageCache)}. 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 . ja v a 2 s . c o m * * @param data The URL of the image to download * @param imageView The ImageView to bind the downloaded image to */ public void loadImage(final Object data, final ImageView imageView) { if (data == null) { return; } int width = imageView.getWidth(); int height = imageView.getHeight(); // If the dimensions aren't known yet then the view hasn't been measured. Get a // ViewTreeObserver and listen for the PreDraw message. Using a GlobalLayoutListener // does not work for views that are in the list but drawn off-screen, possibly due // to the convertview. See http://stackoverflow.com/a/14325365 for some discussion. // The solution there, of posting a runnable, does not appear to reliably work on // devices running (at least) API 7. An OnPreDrawListener appears to work, and will // be called after measurement is complete. if (width == 0 || height == 0) { // Store the URL in the imageView's tag, in case the URL assigned to is changed. imageView.setTag(data); imageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { imageView.getViewTreeObserver().removeOnPreDrawListener(this); // If the imageView is still assigned to the URL then we can load in to it. if (data.equals(imageView.getTag())) { loadImage(data, imageView); } return true; } }); return; } loadImage(data, imageView, width, height); }
From source file:com.nttec.everychan.cache.BitmapCache.java
/** * ? ? ImageView.<br>//w w w .j a va 2 s . co m * ? ImageView ??? ?:<ul> * <li>? ? ? , ? (? ??, )</li> * <li> {@link Boolean#TRUE}, ?</li> * <li> {@link Boolean#FALSE}, ( ? downloadFromInternet == false)</li></ul> * @param hash ? ( ? ) * @param url ? URL (? ?) * @param maxSize ? ??, , 0, ? ?? ? ? * @param chan ? ?? * @param zipFile - - ? ? ? ( null) * @param task ?? * @param imageView {@link ImageView}, * @param executor ? ? * @param handler Handler UI * @param downloadFromInternet * @param defaultResId ID ?? ? , ? ( ? downloadFromInternet == false), * 0 - ? */ public void asyncGet(String hash, String url, int maxSize, ChanModule chan, ReadableContainer zipFile, CancellableTask task, ImageView imageView, Executor executor, Handler handler, boolean downloadFromInternet, int defaultResId) { if (hash == null) { Logger.e(TAG, "received null hash for url: " + url); imageView.setTag(Boolean.FALSE); imageView.setImageResource(defaultResId); return; } Bitmap fromLru = getFromMemory(hash); if (fromLru != null) { imageView.setTag(Boolean.TRUE); imageView.setImageBitmap(fromLru); return; } else { imageView.setImageBitmap(EMPTY_BMP); } class ImageDownloader implements Runnable { private final String hash; private final String url; private final int maxSize; private final ChanModule chan; private final ReadableContainer zipFile; private final CancellableTask task; private final ImageView imageView; private final Handler handler; private final boolean downloadFromInternet; private final int defaultResId; public ImageDownloader(String hash, String url, int maxSize, ChanModule chan, ReadableContainer zipFile, CancellableTask task, ImageView imageView, Handler handler, boolean downloadFromInternet, int defaultResId) { this.hash = hash; this.url = url; this.maxSize = maxSize; this.chan = chan; this.zipFile = zipFile; this.task = task; this.imageView = imageView; this.handler = handler; this.downloadFromInternet = downloadFromInternet; this.defaultResId = defaultResId; } private Bitmap bmp; @Override public void run() { bmp = getFromCache(hash); if (bmp == null && zipFile != null) bmp = getFromContainer(hash, zipFile); if (bmp == null && downloadFromInternet) { bmp = download(hash, url, maxSize, chan, task); } if (task != null && task.isCancelled()) return; if (imageView.getTag() == null || !imageView.getTag().equals(hash)) return; if (bmp == null) { if (defaultResId == 0) { imageView.setTag(Boolean.FALSE); return; } } handler.post(new Runnable() { @Override public void run() { try { if (imageView.getTag() == null || !imageView.getTag().equals(hash)) return; if (bmp != null) { imageView.setTag(Boolean.TRUE); imageView.setImageBitmap(bmp); } else { imageView.setTag(Boolean.FALSE); imageView.setImageResource(defaultResId); } } catch (OutOfMemoryError oom) { MainApplication.freeMemory(); Logger.e(TAG, oom); } } }); } } if (task != null && task.isCancelled()) return; imageView.setTag(hash); executor.execute(new ImageDownloader(hash, url, maxSize, chan, zipFile, task, imageView, handler, downloadFromInternet, defaultResId)); }
From source file:com.mdlive.sav.MDLiveProviderDetails.java
/** * Successful Response Handler for getting the Affillitations and the provider image. * This method will give the successful response of the Provider's affilitations. * This response is for the Affilations Purpose.The image can be placed one below the other * *//*w ww .j av a2s . co m*/ private void getProviderImageArrayResponse(JsonObject providerdetObj) { JsonArray ProviderImageArray = providerdetObj.get("provider_groups").getAsJsonArray(); if (ProviderImageArray.size() != 0) { providerImageCollectionHolder.removeAllViews(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100); params.setMargins(5, 10, 5, 10); for (int i = 0; i < ProviderImageArray.size(); i++) { try { if (!ProviderImageArray.get(i).getAsJsonObject().get("logo").isJsonNull()) { final ImageView imageView = new ImageView(MDLiveProviderDetails.this); //imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setLayoutParams(params); ImageRequest request = new ImageRequest( ProviderImageArray.get(i).getAsJsonObject().get("logo").getAsString(), new Response.Listener<Bitmap>() { @Override public void onResponse(Bitmap bitmap) { imageView.setImageBitmap(bitmap); } }, 0, 0, null, new Response.ErrorListener() { public void onErrorResponse(VolleyError error) { } }); ApplicationController.getInstance().getRequestQueue(this).add(request); imageView.setTag(ProviderImageArray.get(i).getAsJsonObject().get("url").getAsString()); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MDLiveProviderDetails.this, MDLiveProviderGroupDetailsAffiliations.class); intent.putExtra("affurl", (imageView.getTag() != null) ? imageView.getTag().toString() : ""); startActivity(intent); MdliveUtils.startActivityAnimation(MDLiveProviderDetails.this); } }); providerImageCollectionHolder.addView(imageView); } } catch (Exception e) { e.printStackTrace(); } } } else { if (!isCignaCoachUser) findViewById(R.id.providerGroupAffiliation).setVisibility(View.GONE); } }
From source file:com.haomee.chat.activity.ChatActivity.java
/** * // ww w . j av a2 s . com */ private void init_new_emotions(final String path) { File file = new File(emotions_base_path); File[] files = file.listFiles();// ? for (File f : files) { if (path == null) { return; } if (f == null) { return; } if (!file.exists() || !file.isDirectory()) { return; } // if (f.listFiles().length == 0) { // return; // } if (path.equals(f.getName())) {// ?? File[] file_image_list = f.listFiles(); image_path = new ArrayList<String>(); image_name = new ArrayList<String>(); if (file_image_list == null) { return; } for (int j = 0; j < file_image_list.length; j++) { File file_image = file_image_list[j]; try { String newFileName = new String(file_image.getName().getBytes(), "UTF-8"); if (newFileName.contains(big_cover_name) || newFileName.contains(simall_cover_name)) { // final ImageView iv_bottom_emotion = new ImageView(ChatActivity.this); Bitmap decodeFile = BitmapFactory.decodeFile(file_image.getAbsolutePath()); iv_bottom_emotion.setImageBitmap(decodeFile); int screen_width = ViewUtil.getScreenWidth(ChatActivity.this); layoutParams.width = screen_width / 8; layoutParams.height = screen_width / 8; iv_bottom_emotion.setLayoutParams(layoutParams); iv_bottom_emotion.setBackgroundResource(R.drawable.grid_line); iv_bottom_emotion.setTag(path); // imag_list.add(iv_bottom_emotion); imag_list.add(0, iv_bottom_emotion); iv_bottom_emotion.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub selected_pager = (String) iv_bottom_emotion.getTag(); iv_expression_emoji.setBackgroundResource(R.drawable.grid_line); for (ImageView iv : imag_list) { if (selected_pager.equals(iv.getTag())) { iv.setBackgroundResource(R.drawable.grid_line_press); } else { iv.setBackgroundResource(R.drawable.grid_line); } } search_selected_emotions((String) iv_bottom_emotion.getTag()); } }); ll_emotions_content.addView(iv_bottom_emotion); viewpager.setTag(tab_emotions_tag);// ? } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }