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.musenkishi.wally.util.PaletteLoader.java

private static void applyColorToView(final PaletteTarget target, int color, boolean fromCache) {
    if (target.getView() instanceof TextView) {
        applyColorToView((TextView) target.getView(), color, fromCache);
        return;/*from  w w  w .ja  v a2 s .co m*/
    }
    if (fromCache) {
        if (target.getView() instanceof ImageView && target.shouldMaskDrawable()) {
            ((ImageView) target.getView()).getDrawable().mutate().setColorFilter(color,
                    PorterDuff.Mode.MULTIPLY);
        } else {
            target.getView().setBackgroundColor(color);
        }
    } else {
        if (target.getView() instanceof ImageView && target.shouldMaskDrawable()) {
            Integer colorFrom;
            ValueAnimator.AnimatorUpdateListener imageAnimatorUpdateListener = new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    ((ImageView) target.getView()).getDrawable().mutate().setColorFilter(
                            (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                }
            };
            ValueAnimator.AnimatorUpdateListener animatorUpdateListener;

            PaletteTag paletteTag = (PaletteTag) target.getView().getTag();
            animatorUpdateListener = imageAnimatorUpdateListener;
            colorFrom = paletteTag.getColor();
            target.getView().setTag(new PaletteTag(paletteTag.getId(), color));

            Integer colorTo = color;
            ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
            colorAnimation.addUpdateListener(animatorUpdateListener);
            colorAnimation.setDuration(300);
            colorAnimation.start();
        } else {

            Drawable preDrawable;

            if (target.getView().getBackground() == null) {
                preDrawable = new ColorDrawable(Color.TRANSPARENT);
            } else {
                preDrawable = target.getView().getBackground();
            }

            TransitionDrawable transitionDrawable = new TransitionDrawable(
                    new Drawable[] { preDrawable, new ColorDrawable(color) });
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                target.getView().setBackground(transitionDrawable);
            } else {
                target.getView().setBackgroundDrawable(transitionDrawable);
            }
            transitionDrawable.startTransition(300);
        }
    }
}

From source file:com.musenkishi.atelier.Atelier.java

private static void applyColorToView(final PaletteTarget target, int color, boolean fromCache) {
    if (target.getView() instanceof TextView) {
        applyColorToView((TextView) target.getView(), color, fromCache);
    } else if (target.getView() instanceof CardView) {
        applyColorToView((CardView) target.getView(), color, fromCache);
    } else if (target.getView() instanceof FloatingActionButton) {
        applyColorToView((FloatingActionButton) target.getView(), color, fromCache,
                target.shouldMaskDrawable());
    } else if (target.getView() instanceof ImageView) {
        applyColorToView((ImageView) target.getView(), color, fromCache, target.shouldMaskDrawable());
    } else {//from  www . j a  va 2 s .c  om
        if (fromCache) {
            target.getView().setBackgroundColor(color);
        } else {
            Drawable preDrawable;

            if (target.getView().getBackground() == null) {
                preDrawable = new ColorDrawable(Color.TRANSPARENT);
            } else {
                preDrawable = target.getView().getBackground();
            }

            TransitionDrawable transitionDrawable = new TransitionDrawable(
                    new Drawable[] { preDrawable, new ColorDrawable(color) });
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                target.getView().setBackground(transitionDrawable);
            } else {
                target.getView().setBackgroundDrawable(transitionDrawable);
            }
            transitionDrawable.startTransition(300);
        }
    }
}

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);/*from w w  w . j a v  a  2s. c om*/
    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.musenkishi.atelier.Atelier.java

private static void applyColorToView(final ImageView imageView, int color, boolean fromCache,
        boolean shouldMask) {
    if (fromCache) {
        if (shouldMask) {
            if (imageView.getDrawable() != null) {
                imageView.getDrawable().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
            } else if (imageView.getBackground() != null) {
                imageView.getBackground().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
            }/*from   w  w  w . j a  v a 2  s .  co m*/
        } else {
            imageView.setBackgroundColor(color);
        }
    } else {
        if (shouldMask) {
            Integer colorFrom;
            ValueAnimator.AnimatorUpdateListener imageAnimatorUpdateListener = new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    if (imageView.getDrawable() != null) {
                        imageView.getDrawable().mutate().setColorFilter(
                                (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                    } else if (imageView.getBackground() != null) {
                        imageView.getBackground().mutate().setColorFilter(
                                (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                    }
                }
            };
            ValueAnimator.AnimatorUpdateListener animatorUpdateListener;

            PaletteTag paletteTag = (PaletteTag) imageView.getTag(viewTagKey);
            animatorUpdateListener = imageAnimatorUpdateListener;
            colorFrom = paletteTag.getColor();
            imageView.setTag(viewTagKey, new PaletteTag(paletteTag.getId(), color));

            Integer colorTo = color;
            ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
            colorAnimation.addUpdateListener(animatorUpdateListener);
            colorAnimation.setDuration(300);
            colorAnimation.start();
        } else {
            Drawable preDrawable;

            if (imageView.getBackground() == null) {
                preDrawable = new ColorDrawable(Color.TRANSPARENT);
            } else {
                preDrawable = imageView.getBackground();
            }

            TransitionDrawable transitionDrawable = new TransitionDrawable(
                    new Drawable[] { preDrawable, new ColorDrawable(color) });
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                imageView.setBackground(transitionDrawable);
            } else {
                imageView.setBackgroundDrawable(transitionDrawable);
            }
            transitionDrawable.startTransition(300);
        }
    }
}

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  w  w w.  ja v a  2 s . co  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:org.getlantern.firetweet.view.MessageCardItemFrameLayout.java

@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = getBackground();
    if (d != null && d.isStateful()) {
        final int[] state = getDrawableState();
        d.setState(state);/*from ww w  . j  a  va2s  .c o m*/
        final Drawable current = d.getCurrent();
        if (current instanceof TransitionDrawable) {
            final TransitionDrawable td = (TransitionDrawable) current;
            if (ArrayUtils.contains(state, android.R.attr.state_pressed)) {
                td.startTransition(ViewConfiguration.getLongPressTimeout());
            } else {
                td.resetTransition();
            }
        }
    }
}

From source file:com.romelapj.appvercine.activity.MainActivity.java

private void changeColor(int newColor) {
    tabs.setBackgroundColor(newColor);// w  w  w . j  a v  a  2 s.c  o  m
    mTintManager.setTintColor(newColor);
    Drawable colorDrawable = new ColorDrawable(newColor);
    Drawable bottomDrawable = new ColorDrawable(getResources().getColor(android.R.color.transparent));
    LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });
    if (oldBackground == null) {
        getSupportActionBar().setBackgroundDrawable(ld);
    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        getSupportActionBar().setBackgroundDrawable(td);
        td.startTransition(200);
    }

}

From source file:com.ifeng.util.imagecache.ImageWorker.java

/**
 * //from ww w  .jav  a  2  s  .c  om
 * 
 * @param imageView
 * @param drawable
 */
public static void setFadeInDrawable(ImageView imageView, Drawable drawable) {
    // Bug fix by XuWei 2013-09-09
    // Drawable?bug?ViewDrawable??Drawable
    Drawable copyDrawable = new BitmapDrawable(imageView.getContext().getResources(),
            ((BitmapDrawable) drawable).getBitmap());

    // Transition drawable with a transparent drawable and the final
    // drawable
    final TransitionDrawable td = new TransitionDrawable(
            new Drawable[] { new ColorDrawable(android.R.color.transparent), copyDrawable });

    imageView.setImageDrawable(td);
    td.startTransition(FADE_IN_TIME);
}

From source file:com.eccyan.widget.sample.MainActivity.java

private void changeColor(int newColor) {
    tabs.setBackgroundColor(newColor);//  w  ww  . jav a2 s .  c  o  m
    mTintManager.setTintColor(newColor);
    // change ActionBar color just if an ActionBar is available
    Drawable colorDrawable = new ColorDrawable(newColor);
    Drawable bottomDrawable = new ColorDrawable(getResources().getColor(android.R.color.transparent));
    LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });
    if (oldBackground == null) {
        getSupportActionBar().setBackgroundDrawable(ld);
    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        getSupportActionBar().setBackgroundDrawable(td);
        td.startTransition(200);
    }

    oldBackground = ld;
    currentColor = newColor;
}

From source file:me.priyesh.chromasample.MainActivity.java

private void updateToolbar(int oldColor, int newColor) {
    final TransitionDrawable transition = new TransitionDrawable(
            new ColorDrawable[] { new ColorDrawable(oldColor), new ColorDrawable(newColor) });

    mToolbar.setBackground(transition);/*from  w  w  w.j  ava  2 s .  c  o  m*/
    transition.startTransition(300);
}