Comments (6)
public ImageSpan(@NonNull Drawable drawable)
You can pass the decoded WebpDrawable to build an ImageSpan and work with SpannableString
from glidewebpdecoder.
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.
public ImageSpan(@NonNull Drawable drawable)
You can pass the decoded WebpDrawable to build an ImageSpan and work with SpannableStringIt'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.
public ImageSpan(@NonNull Drawable drawable)
You can pass the decoded WebpDrawable to build an ImageSpan and work with SpannableStringIt'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.
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.
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)
- 加载webp动图,结果图片缩小了 HOT 1
- 使用协程好像会出现多线程问题 HOT 1
- 首帧预览 功能 HOT 2
- 在 onResourceReady call WebpDrawable#stop() 沒有辦法停下動畫 HOT 1
- 版本对应问题 HOT 1
- please release 2.3.4.15.1 HOT 1
- 有没有非androidX的版本引用 HOT 1
- 加载webp动图时,偶现会出现这种现象 HOT 3
- Question: is it possible to decode the frames of GIF/WEBP and get callbacks for playing them in specific threads? HOT 2
- Update glide version to 4.16.0 HOT 1
- Critical WebP bug: many apps, not just browsers, under threat HOT 6
- 升级libwebp到1.3.2 HOT 2
- so 出现报毒 HOT 1
- Drawable 转 WebpDrawable 失败,无法设置 动画次数 HOT 1
- so包体积太大了 HOT 1
- 加载webp动图的时候放大控件会导致动图闪烁,好像2层一样 HOT 1
- is this library supposed to help with preventing images rendering black background? HOT 2
- 列表同时加载多个webp动图卡顿
- how can i get all bitmap frame from animate webp HOT 1
- awebp 渲染出来的效果不太对 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glidewebpdecoder.