Example usage for android.graphics.drawable TransitionDrawable startTransition

List of usage examples for android.graphics.drawable TransitionDrawable startTransition

Introduction

In this page you can find the example usage for android.graphics.drawable TransitionDrawable startTransition.

Prototype

public void startTransition(int durationMillis) 

Source Link

Document

Begin the second layer on top of the first layer.

Usage

From source file:com.travel.ac.utils.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView.//from w  w  w. ja  va2  s . c  o  m
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    /*
     * ??
     */
    if (mFadeInBitmap && mCircleImageView == null) {
        // 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
        //

        if (mCircleImageView == null) {
            imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));
            imageView.setImageDrawable(td);
        } else {
            ((CircleImageView) imageView).setImage(new BitmapDrawable(mResources, mLoadingBitmap));
            ((CircleImageView) imageView).setImage(td);
        }
        td.startTransition(FADE_IN_TIME);
    } else {
        if (mCircleImageView == null) {
            imageView.setImageDrawable(drawable);
        } else {
            ((CircleImageView) imageView).setImage(drawable);
        }
    }
}

From source file:com.ksharkapps.musicnow.ui.activities.SearchActivity.java

public void changeActionBarColor(int newColor) {

    int color = newColor != 0 ? newColor : SettingsActivity.getActionBarColor(this);
    Drawable colorDrawable = new ColorDrawable(color);
    Drawable bottomDrawable = getResources().getDrawable(R.drawable.transparent_overlay);
    LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

    if (oldBackground == null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            ld.setCallback(drawableCallback);
        } else {//from w  w w  . j a v  a 2  s  .c om
            actionBar.setBackgroundDrawable(colorDrawable);
        }

    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        // workaround for broken ActionBarContainer drawable handling on
        // pre-API 17 builds
        // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            td.setCallback(drawableCallback);
        } else {
            actionBar.setBackgroundDrawable(td);
        }
        td.startTransition(200);
    }

    oldBackground = ld;

    // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowTitleEnabled(true);

}

From source file:com.fastbootmobile.encore.app.fragments.AlbumViewFragment.java

private void loadArt(final boolean materialTransition) {
    AlbumArtHelper.retrieveAlbumArt(getResources(), new AlbumArtHelper.AlbumArtListener() {
        @Override//from  w  ww  .  j  a  v a 2s  .c om
        public void onArtLoaded(RecyclingBitmapDrawable output, BoundEntity request) {
            if (output != null) {
                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);

                    mIvHero.setImageDrawable(mtd);
                } else {
                    final TransitionDrawable transition = new TransitionDrawable(
                            new Drawable[] { mIvHero.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() {
                            mIvHero.setImageDrawable(transition);
                            transition.startTransition(500);
                        }
                    }, 600);
                }

                try {
                    generateHeroPalette();
                } catch (IllegalArgumentException ignore) {
                }
            }
        }
    }, mAlbum, -1, false);
}

From source file:com.android.systemui.statusbar.phone.NavigationBarView.java

private void updateColor(boolean defaults) {
    Bitmap bm = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    Canvas cnv = new Canvas(bm);

    if (defaults) {
        cnv.drawColor(0xFF000000);//from w w w  . j ava2s . com
        setBackground(new BitmapDrawable(bm));
        return;
    }

    String setting = Settings.System.getString(mContext.getContentResolver(), Settings.System.NAV_BAR_COLOR);
    String[] colors = (setting == null || setting.equals("")
            ? ExtendedPropertiesUtils.PARANOID_COLORS_DEFAULTS[ExtendedPropertiesUtils.PARANOID_COLORS_NAVBAR]
            : setting).split(ExtendedPropertiesUtils.PARANOID_STRING_DELIMITER);
    String currentColor = colors[Integer.parseInt(colors[2])];

    cnv.drawColor(new BigInteger(currentColor, 16).intValue());

    TransitionDrawable transition = new TransitionDrawable(
            new Drawable[] { getBackground(), new BitmapDrawable(bm) });
    transition.setCrossFadeEnabled(true);
    setBackground(transition);
    transition.startTransition(1000);
}

From source file:com.gokuai.yunkuandroidsdk.imageutils.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView.// ww w .  ja  v a2  s  .c o  m
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    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),
                        isRoundDrawable
                                ? new BitmapDrawable(mResources,
                                        Util.makeRoundDrawable(drawable, GKApplication.getInstance(), false))
                                : drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(isRoundDrawable
                ? new BitmapDrawable(mResources,
                        Util.makeRoundDrawable(drawable, GKApplication.getInstance(), false))
                : new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        if (isRoundDrawable) {

            imageView.setImageBitmap(Util.makeRoundDrawable(drawable, GKApplication.getInstance(), false));
        } else {

            imageView.setImageDrawable(drawable);
        }
    }
}

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.
 *//*from   w w  w  .j  av a  2  s  .co  m*/
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.PlaylistViewFragment.java

private void loadArt() {
    new Thread() {
        public void run() {
            AlbumArtHelper.retrieveAlbumArt(getResources(), new AlbumArtHelper.AlbumArtListener() {
                @Override/*from  w ww  . jav  a  2s. com*/
                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.ifeng.util.imagecache.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView./*from ww w . ja va2s.  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.channelsoft.common.bitmapUtil.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView/* w ww  .  java  2  s . c o  m*/
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if ("0".equals(imageView.getTag())) {
        // ??
        bitmap = toGrayscale(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
        //TODO: miaolikui delete 20121229
        //            imageView.setBackgroundDrawable(
        //                    new BitmapDrawable(mResources, mLoadingBitmap));

        Log.d(TAG, tagStr + ":imageView.setImageDrawable:" + System.currentTimeMillis());
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        Log.d(TAG, tagStr + ":imageView.setImageBitmap:" + System.currentTimeMillis());
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.silentcircle.contacts.ContactPhotoManagerNew.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.
 *///from   w  w  w  .ja va  2 s . c o m
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, request.mIsCircular);
        return false;
    }

    if (holder.bytes == null) {
        request.applyDefaultImage(view, request.mIsCircular);
        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, request.mIsCircular);
            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] = getDrawableForBitmap(mContext.getResources(), cachedBitmap, request);
        TransitionDrawable drawable = new TransitionDrawable(layers);
        view.setImageDrawable(drawable);
        drawable.startTransition(FADE_TRANSITION_DURATION);
    } else {
        view.setImageDrawable(getDrawableForBitmap(mContext.getResources(), cachedBitmap, request));
    }

    // 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)
    if (cachedBitmap.getByteCount() < mBitmapCache.maxSize() / 6) {
        mBitmapCache.put(request.getKey(), cachedBitmap);
    }

    // hack: Don't allow resources from external requests to expire easily
    Uri uri = request.getUri();
    if (uri != null) {
        final String scheme = uri.getScheme();
        if (scheme.equals("http") || scheme.equals("https")) {
            holder.fresh = true;
        }
    }

    // Soften the reference
    holder.bitmap = null;

    return holder.fresh;
}