Example usage for android.graphics.drawable TransitionDrawable TransitionDrawable

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

Introduction

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

Prototype

public TransitionDrawable(Drawable[] layers) 

Source Link

Document

Create a new transition drawable with the specified list of layers.

Usage

From source file:com.airad.zhonghan.ui.components.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView./*from w  w w  .java  2  s.  c om*/
 * 
 * @param imageView
 * @param bitmap
 */
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(android.R.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:arun.com.chromer.webheads.ui.views.BaseWebHead.java

/**
 * Applies a cross fade animation to transform the current favicon to an X icon. Ensures favicon
 * is visible by hiding indicators.//  ww w  . j  av  a 2 s  . co m
 */
void crossFadeFaviconToX() {
    favicon.setVisibility(VISIBLE);
    favicon.clearAnimation();
    favicon.setScaleType(CENTER);
    final TransitionDrawable icon = new TransitionDrawable(
            new Drawable[] { new ColorDrawable(TRANSPARENT), xDrawable });
    favicon.setImageDrawable(icon);
    icon.setCrossFadeEnabled(true);
    icon.startTransition(50);
    favicon.animate().withLayer().rotation(180).setDuration(250)
            .setInterpolator(new LinearOutSlowInInterpolator()).start();
}

From source file:github.daneren2005.dsub.util.ImageLoader.java

private void setImage(View view, final Drawable drawable, boolean crossfade) {
    if (view instanceof TextView) {
        // Cross-fading is not implemented for TextView since it's not in use.  It would be easy to add it, though.
        TextView textView = (TextView) view;
        textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
    } else if (view instanceof ImageView) {
        final ImageView imageView = (ImageView) view;
        if (crossfade && drawable != null) {
            Drawable existingDrawable = imageView.getDrawable();
            if (existingDrawable == null) {
                Bitmap emptyImage;/*from   ww  w .j  a  v  a  2s  . c  o m*/
                if (drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) {
                    emptyImage = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
                } else {
                    emptyImage = Bitmap.createBitmap(imageSizeDefault, imageSizeDefault,
                            Bitmap.Config.ARGB_8888);
                }
                existingDrawable = new BitmapDrawable(context.getResources(), emptyImage);
            } else if (existingDrawable instanceof TransitionDrawable) {
                // This should only ever be used if user is skipping through many songs quickly
                TransitionDrawable tmp = (TransitionDrawable) existingDrawable;
                existingDrawable = tmp.getDrawable(tmp.getNumberOfLayers() - 1);
            }
            if (existingDrawable != null && drawable != null) {
                Drawable[] layers = new Drawable[] { existingDrawable, drawable };
                final TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
                imageView.setImageDrawable(transitionDrawable);
                transitionDrawable.startTransition(250);

                // Get rid of transition drawable after transition occurs
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // Only execute if still on same transition drawable
                        if (imageView.getDrawable() == transitionDrawable) {
                            imageView.setImageDrawable(drawable);
                        }
                    }
                }, 500L);
            } else {
                imageView.setImageDrawable(drawable);
            }
        } else {
            imageView.setImageDrawable(drawable);
        }
    }
}

From source file:com.z.wechatjssdk.utils.bitmapfun.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView//w w w  .j a v a  2 s. com
 * @param bitmap
 * @param imgLoaderListener
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap, ImgLoaderListener imgLoaderListener) {
    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
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
        if (null != imgLoaderListener) {
            imgLoaderListener.onLoadingFailed(imageView);
        }
    } else {
        imageView.setImageBitmap(bitmap);
        if (null != imgLoaderListener) {
            imgLoaderListener.onLoadingComplete(imageView, bitmap);
        }
    }
}

From source file:com.androguide.apkreator.MainActivity.java

/**
 * Method to set the color scheme according to the color defined in
 * config.xml//from w w w. ja  va 2s. c  o  m
 *
 * @param newColor : the color retrieved from config.xml
 */
public void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);
    Drawable colorDrawable = new ColorDrawable(newColor);
    Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom);
    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
            getSupportActionBar().setBackgroundDrawable(ld);

    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
            td.setCallback(drawableCallback);
        else
            getSupportActionBar().setBackgroundDrawable(td);
        td.startTransition(200);
    }
    oldBackground = ld;
    currentColor = newColor;

    /**
     * The following is a work-around to avoid NPE, see the following
     * thread:
     *
     * @see http://stackoverflow.com/questions/11002691/actionbar-
     *      setbackgrounddrawable-nulling-background-from-thread-handler
     */
    try {
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
    } catch (NullPointerException e) {
        Log.e("NPE", e.getMessage());
    }

}

From source file:com.android.volley.cache.plus.SimpleImageLoader.java

/**
 * Sets a {@link android.graphics.Bitmap} to an {@link android.widget.ImageView} using a
 * fade-in animation. If there is a {@link android.graphics.drawable.Drawable} already set on
 * the ImageView then use that as the image to fade from. Otherwise fade in from a transparent
 * Drawable./*  ww w.  j  a  v a2  s.c o m*/
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private static void setImageBitmap(final ImageView imageView, final BitmapDrawable bitmapDrawable,
        Resources resources, boolean fadeIn) {

    // If we're fading in and on HC MR1+
    if (fadeIn && Utils.hasHoneycombMR1()) {
        // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the
        // ImageView
        imageView.animate().scaleY(0.95f).scaleX(0.95f).alpha(0f)
                .setDuration(imageView.getDrawable() == null ? 0 : HALF_FADE_IN_TIME)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        imageView.setImageDrawable(bitmapDrawable);
                        imageView.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(HALF_FADE_IN_TIME)
                                .setListener(null);
                    }
                });
    } else if (fadeIn) {
        // Otherwise use a TransitionDrawable to fade in
        Drawable initialDrawable;
        if (imageView.getDrawable() != null) {
            initialDrawable = imageView.getDrawable();
        } else {
            initialDrawable = transparentDrawable;
        }
        // Use TransitionDrawable to fade in
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { initialDrawable, bitmapDrawable });
        imageView.setImageDrawable(td);
        td.startTransition(Utils.ANIMATION_FADE_IN_TIME);
    } else {
        // No fade in, just set bitmap directly
        imageView.setImageDrawable(bitmapDrawable);
    }
}

From source file:com.android.volley.cache.SimpleImageLoader.java

/**
 * Sets a {@link android.graphics.Bitmap} to an {@link android.widget.ImageView} using a
 * fade-in animation. If there is a {@link android.graphics.drawable.Drawable} already set on
 * the ImageView then use that as the image to fade from. Otherwise fade in from a transparent
 * Drawable.//from ww w .  j  a  v  a2  s.c  om
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private static void setImageBitmap(final ImageView imageView, final Bitmap bitmap, Resources resources,
        boolean fadeIn) {

    // If we're fading in and on HC MR1+
    if (fadeIn && Utils.hasHoneycombMR1()) {
        // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the
        // ImageView
        imageView.animate().scaleY(0.95f).scaleX(0.95f).alpha(0f)
                .setDuration(imageView.getDrawable() == null ? 0 : HALF_FADE_IN_TIME)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        imageView.setImageBitmap(bitmap);
                        imageView.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(HALF_FADE_IN_TIME)
                                .setListener(null);
                    }
                });
    } else if (fadeIn) {
        // Otherwise use a TransitionDrawable to fade in
        Drawable initialDrawable;
        if (imageView.getDrawable() != null) {
            initialDrawable = imageView.getDrawable();
        } else {
            initialDrawable = transparentDrawable;
        }
        BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap);
        // Use TransitionDrawable to fade in
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { initialDrawable, bitmapDrawable });
        imageView.setImageDrawable(td);
        td.startTransition(Utils.ANIMATION_FADE_IN_TIME);
    } else {
        // No fade in, just set bitmap directly
        imageView.setImageBitmap(bitmap);
    }
}

From source file:org.jhw.keep.cache.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView.//from ww  w  . j  a  v a  2 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), drawable });
        // Set background to loading bitmap
        //            imageView.setBackgroundDrawable(
        //                    new BitmapDrawable(mResources, mLoadingBitmap));

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

From source file:com.cnblogs.app.bitmap.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView.//  w  w w  . java 2  s  .c  om
 *
 * @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), drawable });
        // Set background to loading bitmap
        imageView.setBackground(new BitmapDrawable(mResources, mLoadingBitmap));

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

From source file:com.example.photoutil.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView./*from  w  ww  . j ava  2  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), drawable });
        // Set background to loading bitmap
        // *****Bo doan nay*****
        //imageView.setBackgroundDrawable(
        //       new BitmapDrawable(mResources, mLoadingBitmap));

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