diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-09 11:52:14 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-09 11:52:14 -0700 |
commit | 9a379bd668227d3dcea30312025f304fd248f6e3 (patch) | |
tree | 4698e1642401ea7efab9cfd9e959ed9d0b32fc81 /src | |
parent | d7e9d1916fbabaecd4be9dacb4472fa3ffe62ed4 (diff) | |
download | LegacyCamera-9a379bd668227d3dcea30312025f304fd248f6e3.zip LegacyCamera-9a379bd668227d3dcea30312025f304fd248f6e3.tar.gz LegacyCamera-9a379bd668227d3dcea30312025f304fd248f6e3.tar.bz2 |
auto import from //branches/cupcake/...@137197
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/Camera.java | 163 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 56 | ||||
-rw-r--r-- | src/com/android/camera/ViewImage.java | 155 |
3 files changed, 81 insertions, 293 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 56e048a..3564508 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -92,7 +92,6 @@ public class Camera extends Activity implements View.OnClickListener, private static final boolean DEBUG_TIME_OPERATIONS = DEBUG && false; private static final int CROP_MSG = 1; - private static final int KEEP = 2; private static final int RESTART_PREVIEW = 3; private static final int CLEAR_SCREEN_DELAY = 4; @@ -115,7 +114,6 @@ public class Camera extends Activity implements View.OnClickListener, public static final int MENU_SAVE_CAMERA_DONE = 36; public static final int MENU_SAVE_CAMERA_VIDEO_DONE = 37; - private Toast mToast; private OrientationEventListener mOrientationListener; private int mLastOrientation = OrientationEventListener.ORIENTATION_UNKNOWN; private SharedPreferences mPreferences; @@ -156,8 +154,6 @@ public class Camera extends Activity implements View.OnClickListener, private ArrayList<MenuItem> mGalleryItems = new ArrayList<MenuItem>(); - private boolean mMenuSelectionMade; - private ImageView mLastPictureButton; private LayerDrawable mVignette; private Animation mShowLastPictureButtonAnimation = new AlphaAnimation(0F, 1F); @@ -193,22 +189,11 @@ public class Camera extends Activity implements View.OnClickListener, private Handler mHandler = new MainHandler(); - private ProgressDialog mSavingProgress; private interface Capturer { Uri getLastCaptureUri(); void onSnap(); - void dismissFreezeFrame(boolean keep); - void cancelSave(); - void cancelAutoDismiss(); - void setDone(boolean wait); - } - - private void cancelSavingNotification() { - if (mToast != null) { - mToast.cancel(); - mToast = null; - } + void dismissFreezeFrame(); } /** This Handler is used to post message back onto the main thread of the application */ @@ -216,21 +201,6 @@ public class Camera extends Activity implements View.OnClickListener, @Override public void handleMessage(Message msg) { switch (msg.what) { - case KEEP: { - keep(); - if (mSavingProgress != null) { - mSavingProgress.cancel(); - mSavingProgress = null; - } - - mKeepAndRestartPreview = true; - - if (msg.obj != null) { - mHandler.post((Runnable)msg.obj); - } - break; - } - case RESTART_PREVIEW: { if (mStatus == SNAPSHOT_IN_PROGRESS) { // We are still in the processing of taking the picture, wait. @@ -238,7 +208,7 @@ public class Camera extends Activity implements View.OnClickListener, // TODO remove polling mHandler.sendEmptyMessageDelayed(RESTART_PREVIEW, 100); } else if (mStatus == SNAPSHOT_COMPLETED){ - mCaptureObject.dismissFreezeFrame(true); + mCaptureObject.dismissFreezeFrame(); hidePostCaptureAlert(); } break; @@ -436,26 +406,7 @@ public class Camera extends Activity implements View.OnClickListener, mCapturing = capturing; } - /* - * Tell the ImageCapture thread to exit when possible. - */ - public void setDone(boolean wait) { - } - - /* - * Tell the image capture thread to not "dismiss" the current - * capture when the current image is stored, etc. - */ - public void cancelAutoDismiss() { - } - - public void dismissFreezeFrame(boolean keep) { - if (keep) { - cancelSavingNotification(); - } else { - Toast.makeText(Camera.this, R.string.camera_tossing, Toast.LENGTH_SHORT).show(); - } - + public void dismissFreezeFrame() { if (mStatus == SNAPSHOT_IN_PROGRESS) { // If we are still in the process of taking a picture, then just post a message. mHandler.sendEmptyMessage(RESTART_PREVIEW); @@ -522,7 +473,7 @@ public class Camera extends Activity implements View.OnClickListener, storeImage(data, loc); sendBroadcast(new Intent("com.android.camera.NEW_PICTURE", mLastContentUri)); setLastPictureThumb(data, mCaptureObject.getLastCaptureUri()); - dismissFreezeFrame(true); + dismissFreezeFrame(); } else { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; @@ -552,23 +503,6 @@ public class Camera extends Activity implements View.OnClickListener, } /* - * Tells the image capture thread to abort the capture of the - * current image. - */ - public void cancelSave() { - if (!mCapturing) { - return; - } - - mCancel = true; - - if (mAddImageCancelable != null) { - mAddImageCancelable.cancel(); - } - dismissFreezeFrame(false); - } - - /* * Initiate the capture of an image. */ public void initiate(boolean captureOnly) { @@ -675,6 +609,13 @@ public class Camera extends Activity implements View.OnClickListener, mImageCapture.initiate(false); } } + + private void clearLastBitmap() { + if (mCaptureOnlyBitmap != null) { + mCaptureOnlyBitmap.recycle(); + mCaptureOnlyBitmap = null; + } + } } private void setLastPictureThumb(byte[] data, Uri uri) { @@ -750,19 +691,6 @@ public class Camera extends Activity implements View.OnClickListener, return m; } - private void postAfterKeep(final Runnable r) { - Resources res = getResources(); - - if (mSavingProgress != null) { - mSavingProgress = ProgressDialog.show(this, res.getString(R.string.savingImage), - res.getString(R.string.wait)); - } - - Message msg = mHandler.obtainMessage(KEEP); - msg.obj = r; - msg.sendToTarget(); - } - /** Called with the activity is first created. */ @Override public void onCreate(Bundle icicle) { @@ -896,7 +824,6 @@ public class Camera extends Activity implements View.OnClickListener, private void doAttach() { Bitmap bitmap = mImageCapture.getLastBitmap(); - mCaptureObject.setDone(true); String cropValue = null; Uri saveUri = null; @@ -1196,6 +1123,13 @@ public class Camera extends Activity implements View.OnClickListener, mStorageHint.cancel(); mStorageHint = null; } + + // If we are in an image capture intent and has taken + // a picture, we just clear it in onPause. + mImageCapture.clearLastBitmap(); + mImageCapture = null; + hidePostCaptureAlert(); + super.onPause(); } @@ -1601,16 +1535,8 @@ public class Camera extends Activity implements View.OnClickListener, } void keep() { - cancelSavingNotification(); if (mCaptureObject != null) { - mCaptureObject.dismissFreezeFrame(true); - } - }; - - void toss() { - cancelSavingNotification(); - if (mCaptureObject != null) { - mCaptureObject.cancelSave(); + mCaptureObject.dismissFreezeFrame(); } }; @@ -1686,7 +1612,7 @@ public class Camera extends Activity implements View.OnClickListener, @Override public void onOptionsMenuClosed(Menu menu) { super.onOptionsMenuClosed(menu); - if (mImageSavingItem && !mMenuSelectionMade) { + if (mImageSavingItem) { // save the image if we presented the "advanced" menu // which happens if "menu" is pressed while in // SNAPSHOT_IN_PROGRESS or SNAPSHOT_COMPLETED modes @@ -1700,7 +1626,6 @@ public class Camera extends Activity implements View.OnClickListener, if (featureId == Window.FEATURE_OPTIONS_PANEL) { if (mStatus == SNAPSHOT_IN_PROGRESS) { cancelAutomaticPreviewRestart(); - mMenuSelectionMade = false; } } return super.onMenuOpened(featureId, menu); @@ -1710,8 +1635,6 @@ public class Camera extends Activity implements View.OnClickListener, public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - mMenuSelectionMade = false; - for (int i = 1; i <= MenuHelper.MENU_ITEM_MAX; i++) { if (i != MenuHelper.GENERIC_ITEM) { menu.setGroupVisible(i, false); @@ -1726,9 +1649,6 @@ public class Camera extends Activity implements View.OnClickListener, mImageSavingItem = false; } - if (mCaptureObject != null) - mCaptureObject.cancelAutoDismiss(); - return true; } @@ -1771,49 +1691,6 @@ public class Camera extends Activity implements View.OnClickListener, return false; } else { addBaseMenuItems(menu); - MenuHelper.addImageMenuItems( - menu, - MenuHelper.INCLUDE_ALL & ~MenuHelper.INCLUDE_ROTATE_MENU, - true, - Camera.this, - mHandler, - - // Handler for deletion - new Runnable() { - public void run() { - if (mCaptureObject != null) { - mCaptureObject.cancelSave(); - Uri uri = mCaptureObject.getLastCaptureUri(); - if (uri != null) { - mContentResolver.delete(uri, null, null); - } - } - } - }, - new MenuHelper.MenuInvoker() { - public void run(final MenuHelper.MenuCallback cb) { - mMenuSelectionMade = true; - postAfterKeep(new Runnable() { - public void run() { - cb.run(mSelectedImageGetter.getCurrentImageUri(), mSelectedImageGetter.getCurrentImage()); - if (mCaptureObject != null) - mCaptureObject.dismissFreezeFrame(true); - } - }); - } - }); - - MenuItem gallery = menu.add(MenuHelper.IMAGE_SAVING_ITEM, MENU_SAVE_GALLERY_PHOTO, 0, R.string.camera_gallery_photos_text).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - public boolean onMenuItemClick(MenuItem item) { - postAfterKeep(new Runnable() { - public void run() { - gotoGallery(); - } - }); - return true; - } - }); - gallery.setIcon(android.R.drawable.ic_menu_gallery); } return true; } diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index e9ffbe4..70b1646 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -85,6 +85,10 @@ public class VideoCamera extends Activity implements View.OnClickListener, private static final long CANNOT_STAT_ERROR = -2L; private static final long LOW_STORAGE_THRESHOLD = 512L * 1024L; + private static final int STORAGE_STATUS_OK = 0; + private static final int STORAGE_STATUS_LOW = 1; + private static final int STORAGE_STATUS_NONE = 2; + public static final int MENU_SETTINGS = 6; public static final int MENU_GALLERY_PHOTOS = 7; public static final int MENU_GALLERY_VIDEOS = 8; @@ -102,6 +106,8 @@ public class VideoCamera extends Activity implements View.OnClickListener, ImageView mVideoFrame; Bitmap mVideoFrameBitmap; + private int mStorageStatus = STORAGE_STATUS_OK; + private MediaRecorder mMediaRecorder; private boolean mMediaRecorderRecording = false; private long mRecordingStartTime; @@ -193,20 +199,19 @@ public class VideoCamera extends Activity implements View.OnClickListener, public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_EJECT)) { - updateStorageHint(false); + updateAndShowStorageHint(false); stopVideoRecording(); initializeVideo(); } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { - updateStorageHint(true); + updateAndShowStorageHint(true); initializeVideo(); } else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) { // SD card unavailable - updateStorageHint(false); - releaseMediaRecorder(); + // handled in ACTION_MEDIA_EJECT } else if (action.equals(Intent.ACTION_MEDIA_SCANNER_STARTED)) { Toast.makeText(VideoCamera.this, getResources().getString(R.string.wait), 5000); } else if (action.equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) { - updateStorageHint(true); + updateAndShowStorageHint(true); } } }; @@ -345,12 +350,18 @@ public class VideoCamera extends Activity implements View.OnClickListener, private OnScreenHint mStorageHint; - private void updateStorageHint(boolean mayHaveSd) { - long remaining = mayHaveSd ? getAvailableStorage() : NO_STORAGE_ERROR; + private void updateAndShowStorageHint(boolean mayHaveSd) { + mStorageStatus = getStorageStatus(mayHaveSd); + showStorageHint(); + } + + private void showStorageHint() { String errorMessage = null; - if (remaining == NO_STORAGE_ERROR) { + switch (mStorageStatus) { + case STORAGE_STATUS_NONE: errorMessage = getString(R.string.no_storage); - } else if (remaining < LOW_STORAGE_THRESHOLD) { + break; + case STORAGE_STATUS_LOW: errorMessage = getString(R.string.spaceIsLow_content); } if (errorMessage != null) { @@ -366,6 +377,15 @@ public class VideoCamera extends Activity implements View.OnClickListener, } } + private int getStorageStatus(boolean mayHaveSd) { + long remaining = mayHaveSd ? getAvailableStorage() : NO_STORAGE_ERROR; + if (remaining == NO_STORAGE_ERROR) { + return STORAGE_STATUS_NONE; + } + return remaining < LOW_STORAGE_THRESHOLD + ? STORAGE_STATUS_LOW : STORAGE_STATUS_OK; + } + @Override public void onResume() { if (DEBUG_LOG_APP_LIFECYCLE) { @@ -385,7 +405,13 @@ public class VideoCamera extends Activity implements View.OnClickListener, intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); intentFilter.addDataScheme("file"); registerReceiver(mReceiver, intentFilter); - updateStorageHint(true); + mStorageStatus = getStorageStatus(true); + + mHandler.postDelayed(new Runnable() { + public void run() { + showStorageHint(); + } + }, 200); mBlackout.setVisibility(View.INVISIBLE); if (mVideoFrameBitmap == null) { @@ -647,7 +673,7 @@ public class VideoCamera extends Activity implements View.OnClickListener, mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); - if (mStorageHint != null) { + if (mStorageStatus != STORAGE_STATUS_OK) { mMediaRecorder.setOutputFile("/dev/null"); } else { // We try Uri in intent first. If it doesn't work, use our own instead. @@ -826,7 +852,7 @@ public class VideoCamera extends Activity implements View.OnClickListener, if (what == MediaRecorder.MEDIA_RECORDER_ERROR_UNKNOWN) { // We may have run out of space on the sdcard. stopVideoRecording(); - updateStorageHint(true); + updateAndShowStorageHint(true); } } @@ -847,7 +873,7 @@ public class VideoCamera extends Activity implements View.OnClickListener, Log.v(TAG, "startVideoRecording"); if (!mMediaRecorderRecording) { - if (mStorageHint != null) { + if (mStorageStatus != STORAGE_STATUS_OK) { Log.v(TAG, "Storage issue, ignore the start request"); return; } @@ -950,7 +976,9 @@ public class VideoCamera extends Activity implements View.OnClickListener, mRecordingTimeView.setVisibility(View.GONE); setScreenTimeoutLong(); } - if (needToRegisterRecording && mStorageHint == null) registerVideo(); + if (needToRegisterRecording && mStorageStatus == STORAGE_STATUS_OK) { + registerVideo(); + } mCameraVideoFilename = null; mCameraVideoFileDescriptor = null; diff --git a/src/com/android/camera/ViewImage.java b/src/com/android/camera/ViewImage.java index 254cd60..a5a3821 100644 --- a/src/com/android/camera/ViewImage.java +++ b/src/com/android/camera/ViewImage.java @@ -49,7 +49,6 @@ import android.widget.LinearLayout; import android.widget.Scroller; import android.widget.Toast; import android.widget.ZoomButtonsController; -import android.widget.ZoomRingController; import com.android.camera.ImageManager.IImage; @@ -232,130 +231,8 @@ public class ViewImage extends Activity implements View.OnClickListener private GestureDetector mGestureDetector; private static int TOUCH_AREA_WIDTH = 60; - - // The zoom ring setup: - // We limit the thumb on the zoom ring in the range 0 to 5/3*PI. The - // last PI/3 of the ring is left as a region that the thumb can't go in. - // The 5/3*PI range is divided into 60 steps. Each step scales the image - // by mScaleRate. We make mScaleRate^60 = maxZoom(). - - // This is the max step value we can have for the zoom ring. - private static int MAX_STEP = 60; - // This is the angle we used to separate each step. - private static float STEP_ANGLE = (5 * (float) Math.PI / 3) / MAX_STEP; - // The scale rate for each step. - private float mScaleRate; - - // Returns current scale step (numbered from 0 to MAX_STEP). - private int getCurrentStep() { - float s = getScale(); - float b = mScaleRate; - int step = (int)Math.round(Math.log(s) / Math.log(b)); - return Math.max(0, Math.min(MAX_STEP, step)); - } - - // Limit the thumb on the zoom ring in the range 0 to 5/3*PI. (clockwise - // angle is negative, and we need to mod 2*PI for the API to work.) - private void setZoomRingBounds() { - mScaleRate = (float) Math.pow(maxZoom(), 1.0 / MAX_STEP); - float limit = (2 - 5 / 3F) * (float) Math.PI; - mZoomRingController.setThumbClockwiseBound(limit); - mZoomRingController.setThumbCounterclockwiseBound(0); - } private ZoomButtonsController mZoomButtonsController; - - // The zoom ring is set to visible by a double tap. - private ZoomRingController mZoomRingController; - private ZoomRingController.OnZoomListener mZoomListener = - new ZoomRingController.OnZoomListener() { - public void onCenter(int x, int y) { - } - - public void onBeginPan() { - } - - public boolean onPan(int deltaX, int deltaY) { - postTranslate(-deltaX, -deltaY, sUseBounce); - ImageViewTouch.this.center(true, true, false); - return true; - } - - public void onEndPan() { - } - - // The clockwise angle is negative, so we need to mod 2*PI - private float stepToAngle(int step) { - float angle = step * STEP_ANGLE; - angle = (float) Math.PI * 2 - angle; - return angle; - } - - private int angleToStep(double angle) { - angle = Math.PI * 2 - angle; - int step = (int)Math.round(angle / STEP_ANGLE); - return step; - } - - public void onVisibilityChanged(boolean visible) { - if (visible) { - int step = getCurrentStep(); - float angle = stepToAngle(step); - mZoomRingController.setThumbAngle(angle); - } - } - - public void onBeginDrag() { - setZoomRingBounds(); - } - - public void onEndDrag() { - } - - public boolean onDragZoom(int deltaZoomLevel, int centerX, - int centerY, float startAngle, float curAngle) { - setZoomRingBounds(); - int deltaStep = angleToStep(curAngle) - getCurrentStep(); - if ((deltaZoomLevel > 0) && (deltaStep < 0)) return false; - if ((deltaZoomLevel < 0) && (deltaStep > 0)) return false; - if ((deltaZoomLevel == 0) || (deltaStep == 0)) return false; - - float oldScale = getScale(); - - // First move centerX/centerY to the center of the view. - int deltaX = getWidth() / 2 - centerX; - int deltaY = getHeight() / 2 - centerY; - panBy(deltaX, deltaY); - - // Do zoom in/out. - if (deltaStep > 0) { - zoomIn((float) Math.pow(mScaleRate, deltaStep)); - } else if (deltaStep < 0) { - zoomOut((float) Math.pow(mScaleRate, -deltaStep)); - } - - // Reverse the first centering. - panBy(-deltaX, -deltaY); - - // Return true if the zoom succeeds. - return (oldScale != getScale()); - } - - public void onSimpleZoom(boolean zoomIn, int centerX, int centerY) { - // First move centerX/centerY to the center of the view. - int deltaX = getWidth() / 2 - centerX; - int deltaY = getHeight() / 2 - centerY; - panBy(deltaX, deltaY); - - if (zoomIn) { - zoomIn(); - } else { - zoomOut(); - } - - panBy(-deltaX, -deltaY); - } - }; public ImageViewTouch(Context context) { super(context); @@ -369,29 +246,37 @@ public class ViewImage extends Activity implements View.OnClickListener private void setup(Context context) { mViewImage = (ViewImage) context; - mZoomRingController = new ZoomRingController(context, this); - mZoomRingController.setVibration(false); - mZoomRingController.setTickDelta(STEP_ANGLE); - mZoomRingController.setCallback(mZoomListener); mGestureDetector = new GestureDetector(getContext(), new MyGestureListener()); mGestureDetector.setOnDoubleTapListener(new MyDoubleTapListener()); mZoomButtonsController = new ZoomButtonsController(context, this); mZoomButtonsController.setOverviewVisible(false); mZoomButtonsController.setCallback(new ZoomButtonsController.OnZoomListener() { - public void onCenter(int x, int y) { - mZoomListener.onCenter(x, y); } public void onOverview() { } public void onVisibilityChanged(boolean visible) { - mZoomListener.onVisibilityChanged(visible); + if (visible) { + updateButtonsEnabled(); + } } public void onZoom(boolean zoomIn) { - mZoomListener.onSimpleZoom(zoomIn, getWidth()/2, getHeight()/2); + if (zoomIn) { + zoomIn(); + } else { + zoomOut(); + } + + updateButtonsEnabled(); + } + + private void updateButtonsEnabled() { + float scale = getScale(); + mZoomButtonsController.setZoomInEnabled(scale < mMaxZoom); + mZoomButtonsController.setZoomOutEnabled(scale > 1); } }); } @@ -450,10 +335,9 @@ public class ViewImage extends Activity implements View.OnClickListener return true; } - // On double tap, we show the zoom ring control. + // On double tap, we show the zoom controls. public boolean onDoubleTapEvent(MotionEvent e) { mViewImage.setMode(MODE_NORMAL); - mZoomRingController.handleDoubleTapEvent(e); mZoomButtonsController.handleDoubleTapEvent(e); return true; } @@ -564,7 +448,6 @@ public class ViewImage extends Activity implements View.OnClickListener @Override protected void onDetachedFromWindow() { - mZoomRingController.setVisible(false); mZoomButtonsController.setVisible(false); } @@ -1562,7 +1445,7 @@ public class ViewImage extends Activity implements View.OnClickListener setOrientation(); // Show a tutorial for the new zoom interaction (the method ensure we only show it once) - ZoomRingController.showZoomTutorialOnce(this); + ZoomButtonsController.showZoomTutorialOnce(this); } @Override @@ -1586,7 +1469,7 @@ public class ViewImage extends Activity implements View.OnClickListener iv.recycleBitmaps(); iv.setImageBitmap(null, true); } - ZoomRingController.finishZoomTutorial(this, false); + ZoomButtonsController.finishZoomTutorial(this, false); } @Override |