List of usage examples for android.widget ImageView getTag
@ViewDebug.ExportedProperty
public Object getTag()
From source file:im.neon.util.VectorUtils.java
/** * Set the default vector avatar for a member. * * @param imageView the imageView to set. * @param userId the member userId. * @param displayName the member display name. */// w ww. j a v a 2 s . com private static void setDefaultMemberAvatar(final ImageView imageView, final String userId, final String displayName) { // sanity checks if (null != imageView && !TextUtils.isEmpty(userId)) { final Bitmap bitmap = VectorUtils.getAvatar(imageView.getContext(), VectorUtils.getAvatarColor(userId), TextUtils.isEmpty(displayName) ? userId : displayName, true); if (Looper.getMainLooper().getThread() == Thread.currentThread()) { imageView.setImageBitmap(bitmap); } else { final String tag = userId + " - " + displayName; imageView.setTag(tag); mUIHandler.post(new Runnable() { @Override public void run() { if (TextUtils.equals(tag, (String) imageView.getTag())) { imageView.setImageBitmap(bitmap); } } }); } } }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.SessionDetailFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void setOrAnimateIconTo(final ImageView imageView, final int imageResId, boolean animate) { if (UIUtils.hasICS() && imageView.getTag() != null) { if (imageView.getTag() instanceof Animator) { Animator anim = (Animator) imageView.getTag(); anim.end();//from w w w .j av a2s. c om imageView.setAlpha(1f); } } animate = animate && UIUtils.hasICS(); if (animate) { int duration = getResources().getInteger(android.R.integer.config_shortAnimTime); Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f); outAnimator.setDuration(duration / 2); outAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setImageResource(imageResId); } }); AnimatorSet inAnimator = new AnimatorSet(); outAnimator.setDuration(duration); inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f), ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f), ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f)); AnimatorSet set = new AnimatorSet(); set.playSequentially(outAnimator, inAnimator); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setTag(null); } }); imageView.setTag(set); set.start(); } else { mHandler.post(new Runnable() { @Override public void run() { imageView.setImageResource(imageResId); } }); } }
From source file:com.inter.trade.imageframe.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 added using * {@link ImageWorker#addImageCache(FragmentManager, ImageCache.ImageCacheParams)}. 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. * * @param data The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. *//*from w w w . ja v a2 s.c o m*/ public void loadImage(Object data, ImageView imageView) { if (mLoadPause) { return; } if (data == null) { return; } BitmapDrawable value = null; if (mImageCache != null) { value = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (value != null) { // Bitmap found in memory cache imageView.setImageDrawable(value); RelativeLayout mLayout = (RelativeLayout) imageView.getTag(); if (mLayout != null) { mLayout.setVisibility(View.GONE); } } else if (cancelPotentialWork(data, 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. task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, data); // task.execute(data); } }
From source file:org.getlantern.firetweet.fragment.support.AccountsDashboardFragment.java
private void updateAccountOptionsSeparatorLabel(Drawable profileImageSnapshot) { final ParcelableAccount account = mAccountsAdapter.getSelectedAccount(); if (account == null) { return;/* www .j a v a 2 s .c o m*/ } mAccountProfileNameView.setText(account.name); mAccountProfileScreenNameView.setText("@" + account.screen_name); mImageLoader.displayDashboardProfileImage(mAccountProfileImageView, account.profile_image_url, profileImageSnapshot); mAccountProfileImageView.setBorderColors(account.color); final int bannerWidth = mAccountProfileBannerView.getWidth(); final Resources res = getResources(); final int defWidth = res.getDisplayMetrics().widthPixels; final int width = bannerWidth > 0 ? bannerWidth : defWidth; final String bannerUrl = Utils.getBestBannerUrl(account.profile_banner_url, width); final ImageView bannerView = mAccountProfileBannerView; if (bannerView.getDrawable() == null || !CompareUtils.objectEquals(bannerUrl, bannerView.getTag())) { mImageLoader.displayProfileBanner(mAccountProfileBannerView, bannerUrl, this); } }
From source file:com.skyousuke.ivtool.windows.MainWindow.java
private void updateImageResource(ImageView view, int resId) { Integer tag = (Integer) view.getTag(); if (tag == null || tag != resId) { view.setImageResource(resId);/*from w w w. j a va 2s . c om*/ view.setTag(resId); } }
From source file:org.mariotaku.twidere.fragment.support.AccountsDashboardFragment.java
private void updateAccountOptionsSeparatorLabel(Drawable profileImageSnapshot) { final ParcelableAccount account = mAccountsAdapter.getSelectedAccount(); if (account == null) { return;//from w ww . j a v a 2 s . c o m } mAccountProfileNameView.setText(account.name); mAccountProfileScreenNameView.setText("@" + account.screen_name); mImageLoader.displayDashboardProfileImage(mAccountProfileImageView, account.profile_image_url, profileImageSnapshot); mAccountProfileImageView.setBorderColors(account.color); final int bannerWidth = mAccountProfileBannerView.getWidth(); final Resources res = getResources(); final int defWidth = res.getDisplayMetrics().widthPixels; final int width = bannerWidth > 0 ? bannerWidth : defWidth; final String bannerUrl = Utils.getBestBannerUrl(account.profile_banner_url, width); final ImageView bannerView = mAccountProfileBannerView; if (bannerView.getDrawable() == null || !CompareUtils.objectEquals(bannerUrl, bannerView.getTag())) { mImageLoader.displayProfileBanner(mAccountProfileBannerView, bannerUrl, this); } else { mImageLoader.cancelDisplayTask(mAccountProfileBannerView); } }
From source file:cn.edu.szjm.support.images.remote.RemoteImageLoader.java
/** * Triggers the image loader for the given image and view. The image loading will be performed * concurrently to the UI main thread, using a fixed size thread pool. The loaded image will be * posted back to the given ImageView upon completion. While waiting, the dummyDrawable is * shown.// w w w.j a v a 2s . co m * * @param imageUrl * the URL of the image to download * @param imageView * the ImageView which should be updated with the new image * @param dummyDrawable * the Drawable to be shown while the image is being downloaded. * @param handler * the handler that will process the bitmap after completion */ public void loadImage(String imageUrl, ImageView imageView, Drawable dummyDrawable, RemoteImageLoaderHandler handler) { this.imageUrl = imageUrl; this.handler = handler; if (imageView != null) { if (imageUrl == null) { // In a ListView views are reused, so we must be sure to remove the tag that could // have been set to the ImageView to prevent that the wrong image is set. imageView.setTag(null); if (dummyDrawable != null) { imageView.setImageDrawable(dummyDrawable); } return; } String oldImageUrl = (String) imageView.getTag(); if (imageUrl.equals(oldImageUrl)) { // nothing to do return; } else { if (dummyDrawable != null) { // Set the dummy image while waiting for the actual image to be downloaded. imageView.setImageDrawable(dummyDrawable); } imageView.setTag(imageUrl); } } ImageCache cache = SharedImageCache.getSharedImageCache(); if (usingCache) { if (cache != null && cache.containsKeyInMemory(imageUrl)) { // do not go through message passing, handle directly instead handler.handleImageLoaded(cache.getBitmap(imageUrl), null); return; } } task.execute(); }
From source file:org.mariotaku.twidere.view.CardMediaContainer.java
public void displayMedia(@NonNull final MediaLoaderWrapper loader, @Nullable final ParcelableMedia[] mediaArray, final UserKey accountId, @Nullable final OnMediaClickListener mediaClickListener, @Nullable final MediaLoadingHandler loadingHandler, final long extraId, boolean withCredentials) { if (mediaArray == null || mMediaPreviewStyle == VALUE_MEDIA_PREVIEW_STYLE_CODE_NONE) { for (int i = 0, j = getChildCount(); i < j; i++) { final View child = getChildAt(i); child.setTag(null);//from ww w . j a v a 2 s . c om child.setVisibility(GONE); } return; } final View.OnClickListener clickListener = new ImageGridClickListener(mediaClickListener, accountId, extraId); for (int i = 0, j = getChildCount(), k = mediaArray.length; i < j; i++) { final View child = getChildAt(i); if (mediaClickListener != null) { child.setOnClickListener(clickListener); } final ImageView imageView = (ImageView) child.findViewById(R.id.mediaPreview); switch (mMediaPreviewStyle) { case VALUE_MEDIA_PREVIEW_STYLE_CODE_CROP: { imageView.setScaleType(ScaleType.CENTER_CROP); break; } case VALUE_MEDIA_PREVIEW_STYLE_CODE_SCALE: { imageView.setScaleType(ScaleType.FIT_CENTER); break; } } if (i < k) { final ParcelableMedia media = mediaArray[i]; final String url = TextUtils.isEmpty(media.preview_url) ? media.media_url : media.preview_url; if (ObjectUtils.notEqual(url, imageView.getTag()) || imageView.getDrawable() == null) { if (withCredentials) { loader.displayPreviewImageWithCredentials(imageView, url, accountId, loadingHandler); } else { loader.displayPreviewImage(imageView, url, loadingHandler); } } imageView.setTag(url); if (imageView instanceof MediaPreviewImageView) { ((MediaPreviewImageView) imageView) .setHasPlayIcon(ParcelableMediaUtils.hasPlayIcon(media.type)); } if (TextUtils.isEmpty(media.alt_text)) { child.setContentDescription(getContext().getString(R.string.media)); } else { child.setContentDescription(media.alt_text); } child.setTag(media); child.setVisibility(VISIBLE); } else { loader.cancelDisplayTask(imageView); imageView.setTag(null); child.setVisibility(GONE); } } }
From source file:org.matrix.androidsdk.db.MXMediaDownloadWorkerTask.java
@Override protected void onPostExecute(Void nothing) { if (null != mErrorAsJsonElement) { dispatchOnDownloadError(mErrorAsJsonElement); } else if (isDownloadCancelled()) { dispatchDownloadCancel();// www. j a va 2 s.c o m } else { dispatchOnDownloadComplete(); // image download // update the linked ImageViews. if (isBitmapDownloadTask()) { // retrieve the bitmap from the file s Bitmap bitmap = MXMediaDownloadWorkerTask.bitmapForURL(mApplicationContext, mDirectoryFile, mUrl, mRotation, mMimeType); if (null == bitmap) { bitmap = mDefaultBitmap; } // update the imageViews image if (bitmap != null) { for (WeakReference<ImageView> weakRef : mImageViewReferences) { final ImageView imageView = weakRef.get(); if (imageView != null && TextUtils.equals(mUrl, (String) imageView.getTag())) { imageView.setBackgroundColor(Color.TRANSPARENT); imageView.setImageBitmap(bitmap); } } } } } }
From source file:org.mariotaku.twidere.fragment.AccountsDashboardFragment.java
protected void displayAccountBanner(@NonNull ParcelableAccount account) { final int bannerWidth = mAccountProfileBannerView.getWidth(); final Resources res = getResources(); final int defWidth = res.getDisplayMetrics().widthPixels; final int width = bannerWidth > 0 ? bannerWidth : defWidth; final ImageView bannerView = (ImageView) mAccountProfileBannerView.getNextView(); if (bannerView.getDrawable() == null || !CompareUtils.objectEquals(account, bannerView.getTag())) { mMediaLoader.displayProfileBanner(bannerView, account, width); bannerView.setTag(account);// w ww . j a v a 2 s . co m } else { mMediaLoader.cancelDisplayTask(bannerView); } }