Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PicassoImageGetter implements Html.ImageGetter {
- private AppTextView textView = null;
- public PicassoImageGetter() {
- }
- public PicassoImageGetter(AppTextView target) {
- textView = target;
- }
- @Override
- public Drawable getDrawable(String source) {
- BitmapDrawablePlaceHolder drawable = new BitmapDrawablePlaceHolder();
- Picasso.with(App.get())
- .load(source)
- .placeholder(R.drawable.img_loading)
- .into(drawable);
- return drawable;
- }
- private class BitmapDrawablePlaceHolder extends BitmapDrawable implements Target {
- protected Drawable drawable;
- @Override
- public void draw(final Canvas canvas) {
- if (drawable != null) {
- drawable.draw(canvas);
- }
- }
- public void setDrawable(Drawable drawable) {
- this.drawable = drawable;
- int width = drawable.getIntrinsicWidth();
- int height = drawable.getIntrinsicHeight();
- drawable.setBounds(0, 0, width, height);
- setBounds(0, 0, width, height);
- if (textView != null) {
- textView.setText(textView.getText());
- }
- }
- @Override
- public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
- setDrawable(new BitmapDrawable(App.get().getResources(), bitmap));
- }
- @Override
- public void onBitmapFailed(Drawable errorDrawable) {
- }
- @Override
- public void onPrepareLoad(Drawable placeHolderDrawable) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement