Created
April 28, 2017 17:27
-
-
Save rajeefmk/beb1b79363c12041da7fd540bcf27765 to your computer and use it in GitHub Desktop.
ImageGetter used for loading remote urls from <img> tag when loaded inside textview.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
App().get ...what ?