Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void sendBitmap(Bitmap bitmap) {
- // TODO - I'm in the pojo where I want to send the bitmap
- }
- import android.graphics.Bitmap;
- public class MyActivity {
- // protected void whateverOtherMethods (Bundle savedInstanceState)
- // {
- // .
- // .
- // .
- // .
- // .
- // .
- //
- // }
- /**
- * Callback interface used to supply a bitmap.
- */
- public interface MyCallback {
- public void onBitmapReady(Bitmap bitmap);
- }
- }
- private final MyCallback myCallback = new MyCallback() {
- @Override
- public void onBitmapReady(Bitmap bitmap) {
- // TODO - do something with the bitmap
- }
- };
- public class ProcessImage implements BitmapCallback {
- /**
- * pojo method to return bitmap
- */
- private void sendBitmap() {
- this.onBitmapReady(bitmap);
- }
- @Override
- public void onBitmapReady(Bitmap bitmap) {
- // we still need to send the bitmap to cusomer App.
- }
- public interface BitmapCallback {
- public void onBitmapReady(Bitmap processedBitmapy);
- }
- private final BitmapCallback bitmapCallback = new BitmapCallback()
- {
- @Override
- public void onBitmapReady(Bitmap bitmap) {
- // TODO Auto-generated method stub
- }
- };
- public interface BitmapCallback {
- public void onBitmapReady(Bitmap processedBitmap);
- }
- public Activity MyActivity extends Activity implements BitmapCallback {
- Handler mHandler; // initialize this in onCreate
- . . .
- public void onRequestImage() {
- ProcessImage processor = new ProcessImage();
- getImage(this /* , other actual args */);
- }
- @Override
- public void onBitmapReady(final Bitmap processedBitmap) {
- // since this may be called from a non-UI thread, we can't update
- // the UI directly.
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- // handle the bitmap (update the UI, etc.)
- }
- });
- }
- }
- public class ProcessImage {
- public void getAnImage(final BitmapCallback callback /* , other formal args */) {
- new Thread() {
- @Override
- public void run() {
- Bitmap bitmap;
- . . . // do the work
- // then deliver the results
- callback.onBitmapReady(bitmap);
- }
- }.start();
- }
- }
- MyCallback callback;
- private void sendBitmap(Bitmap bitmap) {
- // TODO - I'm in the pojo where I want to send the bitmap
- callback.onBitmapReady();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement