Java Code Examples for com.bumptech.glide.load.resource.drawable.GlideDrawable#setLoopCount()

The following examples show how to use com.bumptech.glide.load.resource.drawable.GlideDrawable#setLoopCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlideDrawableImageViewTarget.java    From giffun with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * If no {@link GlideAnimation} is given or if the animation does not set the
 * {@link android.graphics.drawable.Drawable} on the view, the drawable is set using
 * {@link ImageView#setImageDrawable(android.graphics.drawable.Drawable)}.
 *
 * @param resource {@inheritDoc}
 * @param animation {@inheritDoc}
 */
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) {
    if (!resource.isAnimated()) {
        //TODO: Try to generalize this to other sizes/shapes.
        // This is a dirty hack that tries to make loading square thumbnails and then square full images less costly
        // by forcing both the smaller thumb and the larger version to have exactly the same intrinsic dimensions.
        // If a drawable is replaced in an ImageView by another drawable with different intrinsic dimensions,
        // the ImageView requests a layout. Scrolling rapidly while replacing thumbs with larger images triggers
        // lots of these calls and causes significant amounts of jank.
        float viewRatio = view.getWidth() / (float) view.getHeight();
        float drawableRatio = resource.getIntrinsicWidth() / (float) resource.getIntrinsicHeight();
        if (Math.abs(viewRatio - 1f) <= SQUARE_RATIO_MARGIN
                && Math.abs(drawableRatio - 1f) <= SQUARE_RATIO_MARGIN) {
            resource = new SquaringDrawable(resource, view.getWidth());
        }
    }
    super.onResourceReady(resource, animation);
    this.resource = resource;
    resource.setLoopCount(maxLoopCount);
    resource.start();
}
 
Example 2
Source File: BindingUtil.java    From CompositionAvatar with MIT License 5 votes vote down vote up
@Override
public void onResourceReady(GlideDrawable resource,
                            GlideAnimation<? super GlideDrawable> glideAnimation) {
    this.mResource = resource;
    setDrawable(resource);
    resource.setLoopCount(GlideDrawable.LOOP_FOREVER);
    resource.start();
}
 
Example 3
Source File: GlideDrawableTarget.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
    if (container != null && container.get() != null) {
        TextView textView = container.get();
        float width;
        float height;
        if (resource.getIntrinsicWidth() >= this.width) {
            float downScale = (float) resource.getIntrinsicWidth() / this.width;
            width = (float) (resource.getIntrinsicWidth() / downScale / 1.3);
            height = (float) (resource.getIntrinsicHeight() / downScale / 1.3);
        } else {
            float multiplier = (float) this.width / resource.getIntrinsicWidth();
            width = (float) resource.getIntrinsicWidth() * multiplier;
            height = (float) resource.getIntrinsicHeight() * multiplier;
        }
        Rect rect = new Rect(0, 0, Math.round(width), Math.round(height));
        resource.setBounds(rect);
        urlDrawable.setBounds(rect);
        urlDrawable.setDrawable(resource);
        if (resource.isAnimated() && !PrefGetter.isGistDisabled()) {
            urlDrawable.setCallback((Drawable.Callback) textView.getTag(R.id.drawable_callback));
            resource.setLoopCount(GlideDrawable.LOOP_FOREVER);
            resource.start();
        }
        textView.setText(textView.getText());
        textView.invalidate();
    }
}
 
Example 4
Source File: AbstractIconTarget.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
    if (!resource.isAnimated()) {
        resource = new SquaringDrawable(resource, size);
    }
    if (glideAnimation == null || !glideAnimation.animate(resource, this)) {
        setDrawableForTarget(resource);
    }
    this.resource = resource;
    resource.setLoopCount(GlideDrawable.LOOP_FOREVER);
    resource.start();
}
 
Example 5
Source File: WrapperTarget.java    From glide-support with The Unlicense 4 votes vote down vote up
@Override public void onResourceReady(GlideDrawable glideDrawable, GlideAnimation<? super GlideDrawable> glideAnimation) {
	// start GlideDrawable, even if it's not animated (these methods are No-op in that case)
	glideDrawable.setLoopCount(GlideDrawable.LOOP_FOREVER);
	glideDrawable.start();
	setDrawable(glideDrawable);
}
 
Example 6
Source File: GlideDrawableViewBackgroundTarget.java    From glide-support with The Unlicense 4 votes vote down vote up
@Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) {
	super.onResourceReady(resource, animation);
	this.resource = resource;
	resource.setLoopCount(maxLoopCount);
	resource.start();
}