Git Product home page Git Product logo

Comments (6)

zjupure avatar zjupure commented on June 23, 2024

public ImageSpan(@NonNull Drawable drawable)

You can pass the decoded WebpDrawable to build an ImageSpan and work with SpannableString

from glidewebpdecoder.

hushijian0 avatar hushijian0 commented on June 23, 2024

public ImageSpan(@NonNull Drawable drawable)

You can pass the decoded WebpDrawable to build an ImageSpan and work with SpannableString

It's must target TextView. But I want build many SpannableString on background thread without View, use anytime, anywhere.
It's there any idea?

from glidewebpdecoder.

zjupure avatar zjupure commented on June 23, 2024

public ImageSpan(@NonNull Drawable drawable)
You can pass the decoded WebpDrawable to build an ImageSpan and work with SpannableString

It's must target TextView. But I want build many SpannableString on background thread without View, use anytime, anywhere. It's there any idea?

You can sync get a WebpDrawable without ImageView/TextView in background.

Drawable drawable = Glide.with(context)
                .load(url)
                .asDrawable()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                .get(); // get a webpdrawable instance
SpannableString string = new SpannableString("Bottom: span.\nBaseline: span.");
 // using the default alignment: ALIGN_BOTTOM
 string.setSpan(new ImageSpan(drawable), 7, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 string.setSpan(new ImageSpan(drawable, DynamicDrawableSpan.ALIGN_BASELINE),
 22, 23, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

from glidewebpdecoder.

hushijian0 avatar hushijian0 commented on June 23, 2024

public ImageSpan(@NonNull Drawable drawable)
You can pass the decoded WebpDrawable to build an ImageSpan and work with SpannableString

It's must target TextView. But I want build many SpannableString on background thread without View, use anytime, anywhere. It's there any idea?

You can sync get a WebpDrawable without ImageView/TextView in background.

Drawable drawable = Glide.with(context)
                .load(url)
                .asDrawable()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                .get(); // get a webpdrawable instance
SpannableString string = new SpannableString("Bottom: span.\nBaseline: span.");
 // using the default alignment: ALIGN_BOTTOM
 string.setSpan(new ImageSpan(drawable), 7, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 string.setSpan(new ImageSpan(drawable, DynamicDrawableSpan.ALIGN_BASELINE),
 22, 23, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

It doesn't work fine, also PNG isn't. Get drawable successfully and build SpannableString successfully, but neither ImageSpan is show nor its Span text is show when used in TextView. It's work fine if PNG is used asBitmap.
I am using it in the live broadcast public screen as RecycleView Item.

from glidewebpdecoder.

zjupure avatar zjupure commented on June 23, 2024

You should start and refresh animation by yourself when used in TextView not ImageView. The following sample code would work and I have tested in sample project. (864a505)

Drawable drawable = GlideApp.with(MainActivity.this)
                        .load(webpUrl)
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                        .get(); // get a webp drawable instance
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
if (drawable instanceof WebpDrawable) {
    ((WebpDrawable) drawable).start();  // start animation
}
mCallback = new Drawable.Callback() {
    @Override
    public void invalidateDrawable(@NonNull Drawable who) {
        // drive TextView to redraw and draw ImageSpan again
        mTextView.postInvalidate();
    }

    @Override
    public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {

    }

    @Override
    public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) {

    }
};
drawable.setCallback(mCallback);
SpannableString ss = new SpannableString("This is a webp span ");
// using the default alignment: ALIGN_BOTTOM
ss.setSpan(new ImageSpan(drawable, DynamicDrawableSpan.ALIGN_BOTTOM), ss.length() - 1, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextView.setText(ss);

To show WebpDrawable in ImageSpan and TextView, you should bind a Drawable.Callback and it is the key step. For another way, you can rewrite a custom TextView to support this feature and it will be more complicated.

from glidewebpdecoder.

hushijian0 avatar hushijian0 commented on June 23, 2024

You should start and refresh animation by yourself when used in TextView not ImageView. The following sample code would work and I have tested in sample project. (864a505)

Drawable drawable = GlideApp.with(MainActivity.this)
                        .load(webpUrl)
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                        .get(); // get a webp drawable instance
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
if (drawable instanceof WebpDrawable) {
    ((WebpDrawable) drawable).start();  // start animation
}
mCallback = new Drawable.Callback() {
    @Override
    public void invalidateDrawable(@NonNull Drawable who) {
        // drive TextView to redraw and draw ImageSpan again
        mTextView.postInvalidate();
    }

    @Override
    public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {

    }

    @Override
    public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) {

    }
};
drawable.setCallback(mCallback);
SpannableString ss = new SpannableString("This is a webp span ");
// using the default alignment: ALIGN_BOTTOM
ss.setSpan(new ImageSpan(drawable, DynamicDrawableSpan.ALIGN_BOTTOM), ss.length() - 1, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextView.setText(ss);

To show WebpDrawable in ImageSpan and TextView, you should bind a Drawable.Callback and it is the key step. For another way, you can rewrite a custom TextView to support this feature and it will be more complicated.

In this way, it still needs to bind a TextView when build the SpannableString, this is terrible, not what I want. Maybe rewrite a custom TextView is the way to go.
Thanks a lot.

from glidewebpdecoder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.