Search in sources :

Example 21 with GlideDrawable

use of com.bumptech.glide.load.resource.drawable.GlideDrawable in project Reader by TheKeeperOfPie.

the class ImageViewZoom method setImageDrawable.

@Override
public void setImageDrawable(final Drawable drawable) {
    if (drawable instanceof BitmapDrawable || drawable instanceof GlideDrawable) {
        contentWidth = drawable.getIntrinsicWidth();
        contentHeight = drawable.getIntrinsicHeight();
        UtilsImage.checkMaxTextureSize(getHandler(), () -> {
            if (contentWidth > UtilsImage.getMaxTextureSize() || contentHeight > UtilsImage.getMaxTextureSize()) {
                listener.onTextureSizeExceeded();
                return;
            }
            int startHeight = 0;
            int targetHeight = (int) (getWidth() * contentHeight / contentWidth);
            listener.onBeforeContentLoad(getWidth(), targetHeight);
            setScaleType(ScaleType.MATRIX);
            ImageViewZoom.super.setImageDrawable(drawable);
            scaleStart = getWidth() / contentWidth;
            translationX = (scaleCurrent - 1) * contentWidth / 2;
            translationY = (scaleCurrent - 1) * contentHeight / 2;
            setScaleFactor(0, 0, scaleStart);
            if (getParent() instanceof View) {
                startHeight = ((View) getParent()).getHeight();
            }
            ValueAnimator valueAnimator = ValueAnimator.ofInt(startHeight, targetHeight);
            valueAnimator.addUpdateListener(animation -> {
                getLayoutParams().height = (int) animation.getAnimatedValue();
                requestLayout();
            });
            valueAnimator.start();
        });
    } else {
        super.setImageDrawable(drawable);
    }
}
Also used : BitmapDrawable(android.graphics.drawable.BitmapDrawable) ValueAnimator(android.animation.ValueAnimator) ImageView(android.widget.ImageView) View(android.view.View) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Aggregations

GlideDrawable (com.bumptech.glide.load.resource.drawable.GlideDrawable)21 View (android.view.View)9 RequestListener (com.bumptech.glide.request.RequestListener)9 Target (com.bumptech.glide.request.target.Target)9 ObjectAnimator (android.animation.ObjectAnimator)6 ValueAnimator (android.animation.ValueAnimator)6 Animator (android.animation.Animator)5 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)5 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)5 TextView (android.widget.TextView)5 RecyclerView (android.support.v7.widget.RecyclerView)4 ImageView (android.widget.ImageView)4 BlurTransformation (jp.wasabeef.glide.transformations.BlurTransformation)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 Drawable (android.graphics.drawable.Drawable)3 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)3 DribbbleTarget (com.looklook.xinghongfei.looklook.util.DribbbleTarget)3 ObservableColorMatrix (com.looklook.xinghongfei.looklook.util.ObservableColorMatrix)3 BadgedFourThreeImageView (com.looklook.xinghongfei.looklook.widget.BadgedFourThreeImageView)3 Context (android.content.Context)2