Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. private void sendBitmap(Bitmap bitmap) {
  2. // TODO - I'm in the pojo where I want to send the bitmap
  3. }
  4.  
  5. import android.graphics.Bitmap;
  6.  
  7. public class MyActivity {
  8.  
  9. // protected void whateverOtherMethods (Bundle savedInstanceState)
  10. // {
  11. // .
  12. // .
  13. // .
  14. // .
  15. // .
  16. // .
  17. //
  18. // }
  19.  
  20. /**
  21. * Callback interface used to supply a bitmap.
  22. */
  23. public interface MyCallback {
  24. public void onBitmapReady(Bitmap bitmap);
  25. }
  26. }
  27.  
  28. private final MyCallback myCallback = new MyCallback() {
  29.  
  30. @Override
  31. public void onBitmapReady(Bitmap bitmap) {
  32. // TODO - do something with the bitmap
  33. }
  34. };
  35.  
  36. public class ProcessImage implements BitmapCallback {
  37.  
  38. /**
  39. * pojo method to return bitmap
  40. */
  41. private void sendBitmap() {
  42. this.onBitmapReady(bitmap);
  43. }
  44.  
  45. @Override
  46. public void onBitmapReady(Bitmap bitmap) {
  47. // we still need to send the bitmap to cusomer App.
  48.  
  49. }
  50.  
  51. public interface BitmapCallback {
  52.  
  53. public void onBitmapReady(Bitmap processedBitmapy);
  54. }
  55.  
  56. private final BitmapCallback bitmapCallback = new BitmapCallback()
  57. {
  58.  
  59. @Override
  60. public void onBitmapReady(Bitmap bitmap) {
  61. // TODO Auto-generated method stub
  62. }
  63. };
  64.  
  65. public interface BitmapCallback {
  66. public void onBitmapReady(Bitmap processedBitmap);
  67. }
  68.  
  69. public Activity MyActivity extends Activity implements BitmapCallback {
  70. Handler mHandler; // initialize this in onCreate
  71. . . .
  72.  
  73. public void onRequestImage() {
  74. ProcessImage processor = new ProcessImage();
  75. getImage(this /* , other actual args */);
  76. }
  77.  
  78. @Override
  79. public void onBitmapReady(final Bitmap processedBitmap) {
  80. // since this may be called from a non-UI thread, we can't update
  81. // the UI directly.
  82. mHandler.post(new Runnable() {
  83. @Override
  84. public void run() {
  85. // handle the bitmap (update the UI, etc.)
  86. }
  87. });
  88. }
  89. }
  90.  
  91. public class ProcessImage {
  92. public void getAnImage(final BitmapCallback callback /* , other formal args */) {
  93. new Thread() {
  94. @Override
  95. public void run() {
  96. Bitmap bitmap;
  97. . . . // do the work
  98. // then deliver the results
  99. callback.onBitmapReady(bitmap);
  100. }
  101. }.start();
  102. }
  103. }
  104.  
  105. MyCallback callback;
  106.  
  107. private void sendBitmap(Bitmap bitmap) {
  108. // TODO - I'm in the pojo where I want to send the bitmap
  109. callback.onBitmapReady();
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement