List of usage examples for android.graphics.drawable TransitionDrawable TransitionDrawable
public TransitionDrawable(Drawable[] layers)
From source file:com.ccz.viewimages.displayingbitmaps.util.ImageWorker.java
private void setImageDrawable(ImageView imageView, Drawable drawable, Bitmap transbitmap) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(mResources.getColor(android.R.color.transparent)), drawable }); // Set background to loading bitmap if (null != transbitmap) { imageView.setBackgroundDrawable(new BitmapDrawable(mResources, transbitmap)); }//from w w w . java 2 s . com imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation, float ratio, float anchor, int source) { bm = filter(iv, bm, fallback);// w w w . j a v a 2 s . com if (bm == null) { iv.setImageBitmap(null); return; } Drawable d = makeDrawable(iv, bm, ratio, anchor); Animation anim = null; if (fadeIn(animation, source)) { if (preset == null) { anim = new AlphaAnimation(0, 1); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(FADE_DUR); } else { Drawable pd = makeDrawable(iv, preset, ratio, anchor); Drawable[] ds = new Drawable[] { pd, d }; TransitionDrawable td = new TransitionDrawable(ds); td.setCrossFadeEnabled(true); td.startTransition(FADE_DUR); d = td; } } else if (animation > 0) { anim = AnimationUtils.loadAnimation(iv.getContext(), animation); } iv.setImageDrawable(d); if (anim != null) { anim.setStartTime(AnimationUtils.currentAnimationTimeMillis()); iv.startAnimation(anim); } else { iv.setAnimation(null); } }
From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java
private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation, float ratio, float anchor, int source) { bm = filter(iv, bm, fallback);//from www . j a v a2 s. c o m if (bm == null) { iv.setImageBitmap(null); return; } Drawable d = makeDrawable(iv, bm, ratio, anchor); Animation anim = null; if (fadeIn(animation, source)) { if (preset == null) { anim = new AlphaAnimation(0, 1); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(FADE_DUR); } else { Drawable pd = makeDrawable(iv, preset, ratio, anchor); Drawable[] ds = new Drawable[] { pd, d }; TransitionDrawable td = new TransitionDrawable(ds); td.setCrossFadeEnabled(true); td.startTransition(FADE_DUR); d = td; } } else if (animation > 0) { anim = AnimationUtils.loadAnimation(iv.getContext(), animation); } iv.setImageDrawable(d); if (anim != null) { anim.setStartTime(AnimationUtils.currentAnimationTimeMillis()); iv.startAnimation(anim); } else { iv.setAnimation(null); } }
From source file:haipeng.myalbum.imageload.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set * on the ImageView.// w w w . j a va 2 s . com * * @param imageView * @param bitmap */ @SuppressWarnings("deprecation") 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(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:cn.com.wo.bitmap.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView./*from ww w.java 2 s .c o m*/ * * @param imageView * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable, boolean isBackground) { if (mFadeInBitmap && !isBackground) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable }); // Set background to loading bitmap int index = 0; if (imageView.getTag() != null) index = (Integer) imageView.getTag(); imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap[index])); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); if (ImageFetcher.isDebug) Log.i(ImageFetcher.TAG, "setImageDrawable src"); } else { if (isBackground) { if (ImageFetcher.isDebug) Log.i(ImageFetcher.TAG, "setImageDrawable isBackground"); imageView.setBackgroundDrawable(null); imageView.setBackgroundDrawable(drawable); } else { if (ImageFetcher.isDebug) Log.i(ImageFetcher.TAG, "setImageDrawable src"); imageView.setImageDrawable(drawable); } } }
From source file:com.ifeng.util.imagecache.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView./*from w ww .j a va 2s. c o m*/ * * @param imageView * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { // Bug fix by XuWei 2013-09-09 // Drawable?bug?ViewDrawable??Drawable Drawable copyDrawable = new BitmapDrawable(mResources, ((BitmapDrawable) drawable).getBitmap()); if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final // drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), copyDrawable }); // Set background to loading bitmap imageView.setImageDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(copyDrawable); } }
From source file:com.fastbootmobile.encore.app.fragments.PlaylistViewFragment.java
private void loadArt() { new Thread() { public void run() { AlbumArtHelper.retrieveAlbumArt(getResources(), new AlbumArtHelper.AlbumArtListener() { @Override/*from w w w. j ava2 s . co m*/ public void onArtLoaded(RecyclingBitmapDrawable output, BoundEntity request) { if (output != null) { Drawable originalDrawable = mIvHero.getDrawable(); if (originalDrawable == null) { originalDrawable = getResources().getDrawable(R.drawable.album_placeholder); } final TransitionDrawable transition = new TransitionDrawable( new Drawable[] { originalDrawable, output }); // Make sure the transition happens after the activity animation is done, // otherwise weird sliding occurs. mHandler.postDelayed(new Runnable() { @Override public void run() { mIvHero.setImageDrawable(transition); transition.startTransition(500); } }, 600); } } }, mPlaylist, -1, false); } }.start(); }
From source file:com.silentcircle.contacts.ContactPhotoManager.java
/** * Checks if the photo is present in cache. If so, sets the photo on the view. * * @return false if the photo needs to be (re)loaded from the provider. *//* w ww . j a va 2 s. c om*/ private boolean loadCachedPhoto(ImageView view, Request request, boolean fadeIn) { BitmapHolder holder = mBitmapHolderCache.get(request.getKey()); if (holder == null) { // The bitmap has not been loaded ==> show default avatar request.applyDefaultImage(view); return false; } if (holder.bytes == null) { request.applyDefaultImage(view); return holder.fresh; } Bitmap cachedBitmap = holder.bitmapRef == null ? null : holder.bitmapRef.get(); if (cachedBitmap == null) { if (holder.bytes.length < 8 * 1024) { // Small thumbnails are usually quick to inflate. Let's do that on the UI thread inflateBitmap(holder, request.getRequestedExtent()); cachedBitmap = holder.bitmap; if (cachedBitmap == null) return false; } else { // This is bigger data. Let's send that back to the Loader so that we can // inflate this in the background request.applyDefaultImage(view); return false; } } final Drawable previousDrawable = view.getDrawable(); if (fadeIn && previousDrawable != null) { final Drawable[] layers = new Drawable[2]; // Prevent cascade of TransitionDrawables. if (previousDrawable instanceof TransitionDrawable) { final TransitionDrawable previousTransitionDrawable = (TransitionDrawable) previousDrawable; layers[0] = previousTransitionDrawable .getDrawable(previousTransitionDrawable.getNumberOfLayers() - 1); } else { layers[0] = previousDrawable; } layers[1] = new BitmapDrawable(mContext.getResources(), cachedBitmap); TransitionDrawable drawable = new TransitionDrawable(layers); view.setImageDrawable(drawable); drawable.startTransition(FADE_TRANSITION_DURATION); } else { view.setImageBitmap(cachedBitmap); } // Put the bitmap in the LRU cache. But only do this for images that are small enough // (we require that at least six of those can be cached at the same time) int byteCount = (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) ? cachedBitmap.getRowBytes() * cachedBitmap.getHeight() : cachedBitmap.getByteCount(); if (byteCount < mBitmapCache.maxSize() / 6) { mBitmapCache.put(request.getKey(), cachedBitmap); } holder.bitmap = null; // Soften the reference return holder.fresh; }
From source file:com.fastbootmobile.encore.app.fragments.ArtistFragment.java
private void loadArt(final boolean materialTransition) { AlbumArtHelper.retrieveAlbumArt(getResources(), new AlbumArtHelper.AlbumArtListener() { @Override/*from ww w . j av a 2 s . c o m*/ public void onArtLoaded(RecyclingBitmapDrawable output, BoundEntity request) { try { if (output != null && !isDetached()) { mHeroImage = output.getBitmap(); if (materialTransition) { MaterialTransitionDrawable mtd = new MaterialTransitionDrawable( (BitmapDrawable) getResources().getDrawable(R.drawable.ic_cloud_offline), (BitmapDrawable) getResources().getDrawable(R.drawable.album_placeholder)); mtd.transitionTo(output); mHeroImageView.setImageDrawable(mtd); } else { final TransitionDrawable transition = new TransitionDrawable( new Drawable[] { mHeroImageView.getDrawable(), output }); // Make sure the transition happens after the activity animation is done, // otherwise weird sliding occurs. mHandler.postDelayed(new Runnable() { @Override public void run() { mHeroImageView.setImageDrawable(transition); transition.startTransition(500); } }, 600); } generateHeroPalette(); } } catch (IllegalStateException ignore) { // We might have left the activity, so go on } } }, mArtist, -1, false); }
From source file:uk.org.ngo.squeezer.util.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 a2 s. c o m * @param bitmap */ private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable between the pending image and the final bitmap. final TransitionDrawable td = new TransitionDrawable( new Drawable[] { imageView.getDrawable(), new BitmapDrawable(mResources, bitmap) }); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(new BitmapDrawable(mResources, bitmap)); } }