diff options
author | mbansal <mayank.bansal@sri.com> | 2011-09-07 20:04:58 -0400 |
---|---|---|
committer | Wei-Ta Chen <weita@google.com> | 2011-09-09 10:39:01 -0700 |
commit | e1178a73fd5756771d25d0b8375452450f509e99 (patch) | |
tree | a5b77b36515e498f221b2427819efa651587fab1 /src/com/android | |
parent | b332a22d55a38ee35008d98da3519730d1fa086b (diff) | |
download | LegacyCamera-e1178a73fd5756771d25d0b8375452450f509e99.zip LegacyCamera-e1178a73fd5756771d25d0b8375452450f509e99.tar.gz LegacyCamera-e1178a73fd5756771d25d0b8375452450f509e99.tar.bz2 |
Updates to allow cancellation of mosaic computation from a UI trigger.
1) reportProgress now takes a new boolean parameter that can be used to break out of the mosaic computation loop at the library level.
2) Added a cancel button to the progressDialog and a new Handler message to handle the button click so that the user can be taken back to the capture stage.
3) Updates to address the code review.
Change-Id: I0768da55dd6ccd9b1464d456ab41973779734c65
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/camera/panorama/Mosaic.java | 15 | ||||
-rw-r--r-- | src/com/android/camera/panorama/MosaicFrameProcessor.java | 8 | ||||
-rw-r--r-- | src/com/android/camera/panorama/PanoramaActivity.java | 76 |
3 files changed, 73 insertions, 26 deletions
diff --git a/src/com/android/camera/panorama/Mosaic.java b/src/com/android/camera/panorama/Mosaic.java index ef9d367..b586aad 100644 --- a/src/com/android/camera/panorama/Mosaic.java +++ b/src/com/android/camera/panorama/Mosaic.java @@ -67,6 +67,13 @@ public class Mosaic { */ public static final int BLENDTYPE_HORIZONTAL =3; + /** + * Return flags returned by createMosaic() are one of the following. + */ + public static final int MOSAIC_RET_OK = 1; + public static final int MOSAIC_RET_ERROR = -1; + public static final int MOSAIC_RET_CANCELLED = -2; + static { System.loadLibrary("jni_mosaic"); } @@ -129,8 +136,10 @@ public class Mosaic { * which is based on the original images set in setSourceImage(). * False means generating a low-resolution version - * which is based on 1/4 downscaled images from the original images. + * @return Returns a status code suggesting if the mosaic building was + * successful, in error, or was cancelled by the user. */ - public native void createMosaic(boolean value); + public native int createMosaic(boolean value); /** * Get the data for the created mosaic. @@ -161,8 +170,10 @@ public class Mosaic { * Get the progress status of the mosaic computation process. * @param hires Boolean flag to select whether to report progress of the * low-res or high-res mosaicer. + * @param cancelComputation Boolean flag to allow cancelling the + * mosaic computation when needed from the GUI end. * @return Returns a number from 0-100 where 50 denotes that the mosaic * computation is 50% done. */ - public native int reportProgress(boolean hires); + public native int reportProgress(boolean hires, boolean cancelComputation); } diff --git a/src/com/android/camera/panorama/MosaicFrameProcessor.java b/src/com/android/camera/panorama/MosaicFrameProcessor.java index c67508f..dde4a22 100644 --- a/src/com/android/camera/panorama/MosaicFrameProcessor.java +++ b/src/com/android/camera/panorama/MosaicFrameProcessor.java @@ -78,8 +78,8 @@ public class MosaicFrameProcessor { mProgressListener = listener; } - public int reportProgress(boolean hires) { - return mMosaicer.reportProgress(hires); + public int reportProgress(boolean hires, boolean cancel) { + return mMosaicer.reportProgress(hires, cancel); } public void initialize() { @@ -126,8 +126,8 @@ public class MosaicFrameProcessor { mMosaicer.reset(); } - public void createMosaic(boolean highRes) { - mMosaicer.createMosaic(highRes); + public int createMosaic(boolean highRes) { + return mMosaicer.createMosaic(highRes); } public byte[] getFinalMosaicNV21() { diff --git a/src/com/android/camera/panorama/PanoramaActivity.java b/src/com/android/camera/panorama/PanoramaActivity.java index c2cb837..0aefb07 100644 --- a/src/com/android/camera/panorama/PanoramaActivity.java +++ b/src/com/android/camera/panorama/PanoramaActivity.java @@ -53,6 +53,8 @@ import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; +import android.hardware.Camera.Parameters; +import android.hardware.Camera.Size; import android.net.Uri; import android.os.Bundle; import android.os.Handler; @@ -62,6 +64,7 @@ import android.view.Gravity; import android.view.OrientationEventListener; import android.view.View; import android.view.WindowManager; +import android.widget.Button; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; @@ -84,6 +87,7 @@ public class PanoramaActivity extends Activity implements private static final int MSG_RESET_TO_PREVIEW_WITH_THUMBNAIL = 2; private static final int MSG_GENERATE_FINAL_MOSAIC_ERROR = 3; private static final int MSG_DISMISS_ALERT_DIALOG_AND_RESET_TO_PREVIEW = 4; + private static final int MSG_GENERATE_FINAL_MOSAIC_CANCELLED = 5; private static final String TAG = "PanoramaActivity"; private static final int PREVIEW_STOPPED = 0; @@ -155,6 +159,8 @@ public class PanoramaActivity extends Activity implements private Handler mMainHandler; private SurfaceTexture mSurfaceTexture; private boolean mThreadRunning; + private boolean mCancelComputation; + private int mMosaicComputationStatus; private float[] mTransformMatrix; private float mHorizontalViewAngle; @@ -247,6 +253,9 @@ public class PanoramaActivity extends Activity implements mAlertDialog = null; resetToPreview(); break; + case MSG_GENERATE_FINAL_MOSAIC_CANCELLED: + onBackgroundThreadFinished(); + resetToPreview(); } clearMosaicFrameProcessorIfNeeded(); } @@ -469,12 +478,15 @@ public class PanoramaActivity extends Activity implements @Override public void run() { MosaicJpeg jpeg = generateFinalMosaic(false); - Bitmap bitmap = null; - if (jpeg != null) { - bitmap = BitmapFactory.decodeByteArray(jpeg.data, 0, jpeg.data.length); + + if (mMosaicComputationStatus == Mosaic.MOSAIC_RET_OK) { + Bitmap bitmap = null; + if (jpeg != null) { + bitmap = BitmapFactory.decodeByteArray(jpeg.data, 0, jpeg.data.length); + } + mMainHandler.sendMessage(mMainHandler.obtainMessage( + MSG_LOW_RES_FINAL_MOSAIC_READY, bitmap)); } - mMainHandler.sendMessage(mMainHandler.obtainMessage( - MSG_LOW_RES_FINAL_MOSAIC_READY, bitmap)); } }); reportProgress(false); @@ -561,7 +573,8 @@ public class PanoramaActivity extends Activity implements @Override public void run() { while (mThreadRunning) { - final int progress = mMosaicFrameProcessor.reportProgress(highRes); + final int progress = mMosaicFrameProcessor.reportProgress( + highRes, mCancelComputation); try { Thread.sleep(50); @@ -591,20 +604,27 @@ public class PanoramaActivity extends Activity implements @Override public void run() { MosaicJpeg jpeg = generateFinalMosaic(true); - if (jpeg == null) { - mMainHandler.sendEmptyMessage(MSG_GENERATE_FINAL_MOSAIC_ERROR); + + if (mMosaicComputationStatus == Mosaic.MOSAIC_RET_CANCELLED) { + mMainHandler.sendEmptyMessage(MSG_GENERATE_FINAL_MOSAIC_CANCELLED); } else { - int orientation = Exif.getOrientation(jpeg.data); - Uri uri = savePanorama(jpeg.data, orientation); - if (uri != null) { - // Create a thumbnail whose width is equal or bigger than the entire screen. - int ratio = (int) Math.ceil((double) jpeg.width / mPanoLayout.getWidth()); - int inSampleSize = Integer.highestOneBit(ratio); - mThumbnail = Thumbnail.createThumbnail( - jpeg.data, orientation, inSampleSize, uri); + if (jpeg == null) { + mMainHandler.sendEmptyMessage(MSG_GENERATE_FINAL_MOSAIC_ERROR); + } else { + int orientation = Exif.getOrientation(jpeg.data); + Uri uri = savePanorama(jpeg.data, orientation); + if (uri != null) { + // Create a thumbnail whose width is equal or bigger + // than the entire screen. + int ratio = (int) Math.ceil((double) jpeg.width / + mPanoLayout.getWidth()); + int inSampleSize = Integer.highestOneBit(ratio); + mThumbnail = Thumbnail.createThumbnail( + jpeg.data, orientation, inSampleSize, uri); + } + mMainHandler.sendMessage( + mMainHandler.obtainMessage(MSG_RESET_TO_PREVIEW_WITH_THUMBNAIL)); } - mMainHandler.sendMessage( - mMainHandler.obtainMessage(MSG_RESET_TO_PREVIEW_WITH_THUMBNAIL)); } } }); @@ -622,7 +642,17 @@ public class PanoramaActivity extends Activity implements mProgressDialog.setMax(100); mProgressDialog.setMessage(str); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - mProgressDialog.setCancelable(false); // Don't allow back key to dismiss this dialog. + // TODO: update the UI according to specs. +// mProgressDialog.setCancelable(false); // Don't allow back key to dismiss this dialog. + mProgressDialog.setCancelable(true); + + mProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, + int whichButton) { + mCancelComputation = true; + } + }); mProgressDialog.show(); } else { mPanoramaPrepareDialogFadeIn.start(); @@ -669,6 +699,7 @@ public class PanoramaActivity extends Activity implements private void resetToPreview() { mCaptureState = CAPTURE_STATE_VIEWFINDER; + mCancelComputation = false; mReviewLayout.setVisibility(View.GONE); mShutterButton.setBackgroundResource(R.drawable.btn_shutter_pan); @@ -804,7 +835,12 @@ public class PanoramaActivity extends Activity implements }; public MosaicJpeg generateFinalMosaic(boolean highRes) { - mMosaicFrameProcessor.createMosaic(highRes); + int ret = mMosaicFrameProcessor.createMosaic(highRes); + + mMosaicComputationStatus = ret; + + if (ret == Mosaic.MOSAIC_RET_CANCELLED) + return null; byte[] imageData = mMosaicFrameProcessor.getFinalMosaicNV21(); if (imageData == null) { |