Search in sources :

Example 86 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project glide by bumptech.

the class GifDrawableTest method onFrameReady_whenAttachedtoDrawableCallbackWithViewCallbackParent_doesNotStop.

@Test
public void onFrameReady_whenAttachedtoDrawableCallbackWithViewCallbackParent_doesNotStop() {
    TransitionDrawable topLevel = new TransitionDrawable(new Drawable[] { drawable });
    drawable.setCallback(topLevel);
    topLevel.setCallback(new View(context));
    drawable.start();
    drawable.onFrameReady();
    assertThat(drawable.isRunning()).isTrue();
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) View(android.view.View) Test(org.junit.Test)

Example 87 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project ultrasonic by ultrasonic.

the class ImageLoader method setImageBitmap.

private void setImageBitmap(View view, MusicDirectory.Entry entry, Bitmap bitmap, boolean crossFade) {
    if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;
        MusicDirectory.Entry tagEntry = (MusicDirectory.Entry) view.getTag();
        // Only apply image to the view if the view is intended for this entry
        if (entry != null && tagEntry != null && !entry.equals(tagEntry)) {
            Log.i(TAG, "View is no longer valid, not setting ImageBitmap");
            return;
        }
        if (crossFade) {
            Drawable existingDrawable = imageView.getDrawable();
            Drawable newDrawable = Util.createDrawableFromBitmap(this.context, bitmap);
            if (existingDrawable == null) {
                Bitmap emptyImage = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
                existingDrawable = new BitmapDrawable(context.getResources(), emptyImage);
            }
            Drawable[] layers = new Drawable[] { existingDrawable, newDrawable };
            TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
            imageView.setImageDrawable(transitionDrawable);
            transitionDrawable.startTransition(250);
        } else {
            imageView.setImageBitmap(bitmap);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) TransitionDrawable(android.graphics.drawable.TransitionDrawable) MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ImageView(android.widget.ImageView) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 88 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project ButterRemote-Android by se-bastiaan.

the class ActionBarBackground method fadeBackground.

/**
 * Fade the ActionBar background from oldDrawable to newDrawable
 * @param oldDrawable Drawable to be faded from
 * @param newDrawable Drawable to be faded to
 * @return Instance of this class
 */
private ActionBarBackground fadeBackground(Drawable oldDrawable, Drawable newDrawable) {
    if (oldDrawable == null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            newDrawable.setCallback(drawableCallback);
        } else {
            mActionBar.setBackgroundDrawable(newDrawable);
        }
    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldDrawable, newDrawable });
        td.setCrossFadeEnabled(true);
        // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            td.setCallback(drawableCallback);
        } else {
            int paddingTop = mToolbar.getPaddingTop();
            mActionBar.setBackgroundDrawable(td);
            // fix for fitSystemWindows
            mToolbar.setPadding(0, paddingTop, 0, 0);
        }
        td.startTransition(500);
    }
    mOldBackground = newDrawable;
    return this;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Example 89 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project KeepScore by nolanlawson.

the class PlayerView method makeBadgeVisible.

private void makeBadgeVisible() {
    synchronized (lock) {
        // show the badge, canceling the "fade out" animation if necessary
        TransitionDrawable transitionDrawable = (TransitionDrawable) badgeLinearLayout.getBackground();
        transitionDrawable.resetTransition();
        log.d("reset transition");
        if (badgeTextView.getAnimation() != null) {
            log.d("cleared animation");
            badgeTextView.clearAnimation();
            animationWasCanceled.set(true);
        }
        badgeTextView.setVisibility(View.VISIBLE);
        badgeLinearLayout.setVisibility(View.VISIBLE);
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Example 90 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project KeepScore by nolanlawson.

the class PlayerView method fadeOutBadge.

private void fadeOutBadge(final Runnable onAnimationComplete) {
    synchronized (lock) {
        if (// animation is already running, so shouldn't
        !animationRunning.get() && // start a new one
        lastIncremented.get() != // counter was reset, in which
        0 && // to fade
        badgeTextView.getVisibility() == View.VISIBLE) {
            // animation isn't already showing, and the badge is visible
            animationRunning.set(true);
            animationWasCanceled.set(false);
            badgeLinearLayout.setVisibility(View.VISIBLE);
            // show an animation for the badge with the textview and the
            // background linearlayout fading out
            Animation fadeOutAnimation = AnimationUtils.loadAnimation(context, android.R.anim.fade_out);
            fadeOutAnimation.setDuration(ANIMATION_TIME);
            fadeOutAnimation.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    synchronized (lock) {
                        log.d("onAnimationEnd, setting visiblity to invisible");
                        if (!animationWasCanceled.get()) {
                            badgeTextView.setVisibility(View.INVISIBLE);
                        }
                        // necessary to update again to set the history text
                        // view correctly
                        onAnimationComplete.run();
                        animationRunning.set(false);
                    }
                }
            });
            badgeTextView.setAnimation(fadeOutAnimation);
            fadeOutAnimation.start();
            TransitionDrawable transitionDrawable = (TransitionDrawable) badgeLinearLayout.getBackground();
            transitionDrawable.setCrossFadeEnabled(true);
            transitionDrawable.startTransition(ANIMATION_TIME);
        } else {
            // just don't show it - the animation might already be showing,
            // or maybe the badge is
            // already invisible
            badgeLinearLayout.setVisibility(View.INVISIBLE);
            badgeTextView.setVisibility(View.INVISIBLE);
            // this ensures that the history text view gets updated
            // properly, even if the user
            // exits the activity while the animation is in progress (e.g.
            // by going to the Settings)
            onAnimationComplete.run();
        }
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener)

Aggregations

TransitionDrawable (android.graphics.drawable.TransitionDrawable)96 Drawable (android.graphics.drawable.Drawable)61 ColorDrawable (android.graphics.drawable.ColorDrawable)35 BitmapDrawable (android.graphics.drawable.BitmapDrawable)31 View (android.view.View)28 VelocityTracker (android.view.VelocityTracker)11 ImageView (android.widget.ImageView)10 Rect (android.graphics.Rect)9 Handler (android.os.Handler)8 Test (org.junit.Test)6 Bitmap (android.graphics.Bitmap)5 LayerDrawable (android.graphics.drawable.LayerDrawable)5 GradientDrawable (android.graphics.drawable.GradientDrawable)3 RippleDrawable (android.graphics.drawable.RippleDrawable)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 ColorStateList (android.content.res.ColorStateList)2 Resources (android.content.res.Resources)2 ContentObserver (android.database.ContentObserver)2 Canvas (android.graphics.Canvas)2