Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. public class PicassoImageGetter implements Html.ImageGetter {
  2.  
  3. private AppTextView textView = null;
  4.  
  5. public PicassoImageGetter() {
  6.  
  7. }
  8.  
  9. public PicassoImageGetter(AppTextView target) {
  10. textView = target;
  11. }
  12.  
  13. @Override
  14. public Drawable getDrawable(String source) {
  15. BitmapDrawablePlaceHolder drawable = new BitmapDrawablePlaceHolder();
  16. Picasso.with(App.get())
  17. .load(source)
  18. .placeholder(R.drawable.img_loading)
  19. .into(drawable);
  20. return drawable;
  21. }
  22.  
  23. private class BitmapDrawablePlaceHolder extends BitmapDrawable implements Target {
  24.  
  25. protected Drawable drawable;
  26.  
  27. @Override
  28. public void draw(final Canvas canvas) {
  29. if (drawable != null) {
  30. drawable.draw(canvas);
  31. }
  32. }
  33.  
  34. public void setDrawable(Drawable drawable) {
  35. this.drawable = drawable;
  36. int width = drawable.getIntrinsicWidth();
  37. int height = drawable.getIntrinsicHeight();
  38. drawable.setBounds(0, 0, width, height);
  39. setBounds(0, 0, width, height);
  40. if (textView != null) {
  41. textView.setText(textView.getText());
  42. }
  43. }
  44.  
  45. @Override
  46. public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
  47. setDrawable(new BitmapDrawable(App.get().getResources(), bitmap));
  48. }
  49.  
  50. @Override
  51. public void onBitmapFailed(Drawable errorDrawable) {
  52. }
  53.  
  54. @Override
  55. public void onPrepareLoad(Drawable placeHolderDrawable) {
  56.  
  57. }
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement