summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-05 14:34:37 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-05 14:34:37 -0800
commit9c9be2eb4a86fc3468dbba1ec5f7bfdb37d22c74 (patch)
tree23c58341cb4a777455178feab15d34fecc11050a /src
parentb64d345c9d51cabce43b5191532a0c185d2a70a5 (diff)
downloadLegacyCamera-9c9be2eb4a86fc3468dbba1ec5f7bfdb37d22c74.zip
LegacyCamera-9c9be2eb4a86fc3468dbba1ec5f7bfdb37d22c74.tar.gz
LegacyCamera-9c9be2eb4a86fc3468dbba1ec5f7bfdb37d22c74.tar.bz2
auto import from //depot/cupcake/@136594
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/Camera.java122
-rw-r--r--src/com/android/camera/ImageGallery2.java15
-rwxr-xr-xsrc/com/android/camera/ImageManager.java8
-rw-r--r--src/com/android/camera/MenuHelper.java1
-rw-r--r--src/com/android/camera/VideoCamera.java75
-rw-r--r--src/com/android/camera/ViewImage.java21
6 files changed, 123 insertions, 119 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index da4c41c..9717d5e 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -144,10 +144,12 @@ public class Camera extends Activity implements View.OnClickListener,
private boolean mPausing = false;
- private boolean mIsFocusing = false;
- private boolean mIsFocused = false;
- private boolean mIsFocusButtonPressed = false;
- private boolean mCaptureOnFocus = false;
+ private static final int FOCUS_NOT_STARTED = 0;
+ private static final int FOCUSING = 1;
+ private static final int FOCUSING_SNAP_ON_FINISH = 2;
+ private static final int FOCUS_SUCCESS = 3;
+ private static final int FOCUS_FAIL = 4;
+ private int mFocusState = FOCUS_NOT_STARTED;
private static ContentResolver mContentResolver;
private boolean mDidRegister = false;
@@ -381,20 +383,27 @@ public class Camera extends Activity implements View.OnClickListener,
Log.v(TAG, "Auto focus took " + (mFocusCallbackTime - mFocusStartTime) + " ms.");
}
- mIsFocusing = false;
- mIsFocused = focused;
- if (focused) {
- if (mCaptureOnFocus && mCaptureObject != null) {
- // No need to play the AF sound if we're about to play the shutter sound
- mCaptureObject.onSnap();
- clearFocus();
- } else {
- ToneGenerator tg = mFocusToneGenerator;
- if (tg != null)
- tg.startTone(ToneGenerator.TONE_PROP_BEEP2);
+ if (mFocusState == FOCUSING_SNAP_ON_FINISH && mCaptureObject != null) {
+ // Take the picture no matter focus succeeds or fails.
+ // No need to play the AF sound if we're about to play the shutter sound.
+ mCaptureObject.onSnap();
+ clearFocusState();
+ } else if (mFocusState == FOCUSING) {
+ // User is half-pressing the focus key. Play the focus tone.
+ // Do not take the picture now.
+ ToneGenerator tg = mFocusToneGenerator;
+ if (tg != null)
+ tg.startTone(ToneGenerator.TONE_PROP_BEEP2);
+ if (focused) {
+ mFocusState = FOCUS_SUCCESS;
}
- mCaptureOnFocus = false;
- }
+ else {
+ mFocusState = FOCUS_FAIL;
+ }
+ } else if (mFocusState == FOCUS_NOT_STARTED) {
+ // User has released the focus key before focus completes.
+ // Do nothing.
+ }
updateFocusIndicator();
}
};
@@ -769,7 +778,11 @@ public class Camera extends Activity implements View.OnClickListener,
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mOrientationListener = new OrientationEventListener(Camera.this) {
public void onOrientationChanged(int orientation) {
- mLastOrientation = orientation;
+ // We keep the last known orientation. So if the user
+ // first orient the camera then point the camera to
+ // floor/sky, we still have the correct orientation.
+ if (orientation != ORIENTATION_UNKNOWN)
+ mLastOrientation = orientation;
}
};
}
@@ -993,7 +1006,7 @@ public class Camera extends Activity implements View.OnClickListener,
public void onShutterButtonClick(ShutterButton button) {
switch (button.getId()) {
case R.id.shutter_button:
- doSnap(false);
+ doSnap();
break;
}
}
@@ -1204,38 +1217,33 @@ public class Camera extends Activity implements View.OnClickListener,
private void autoFocus() {
updateFocusIndicator();
- if (!mIsFocusing) {
+ if (mFocusState != FOCUSING && mFocusState != FOCUSING_SNAP_ON_FINISH) {
if (mCameraDevice != null) {
- mIsFocusing = true;
- mIsFocused = false;
- mCameraDevice.autoFocus(mAutoFocusCallback);
if (DEBUG_TIME_OPERATIONS) {
mFocusStartTime = System.currentTimeMillis();
}
+ mFocusState = FOCUSING;
+ mCameraDevice.autoFocus(mAutoFocusCallback);
}
}
}
- private void clearFocus() {
- mIsFocusing = false;
- mIsFocused = false;
- mIsFocusButtonPressed = false;
+ private void clearFocusState() {
+ mFocusState = FOCUS_NOT_STARTED;
}
private void updateFocusIndicator() {
mHandler.post(new Runnable() {
public void run() {
- if (mIsFocusing || !mIsFocusButtonPressed) {
- mFocusIndicator.setVisibility(View.GONE);
+ if (mFocusState == FOCUS_SUCCESS) {
+ mFocusIndicator.setVisibility(View.VISIBLE);
mFocusIndicator.clearAnimation();
+ } else if (mFocusState == FOCUS_FAIL) {
+ mFocusIndicator.setVisibility(View.VISIBLE);
+ mFocusIndicator.startAnimation(mFocusBlinkAnimation);
} else {
- if (mIsFocused) {
- mFocusIndicator.setVisibility(View.VISIBLE);
- mFocusIndicator.clearAnimation();
- } else {
- mFocusIndicator.setVisibility(View.VISIBLE);
- mFocusIndicator.startAnimation(mFocusBlinkAnimation);
- }
+ mFocusIndicator.setVisibility(View.GONE);
+ mFocusIndicator.clearAnimation();
}
}
});
@@ -1261,7 +1269,7 @@ public class Camera extends Activity implements View.OnClickListener,
return true;
case KeyEvent.KEYCODE_CAMERA:
if (event.getRepeatCount() == 0) {
- doSnap(false);
+ doSnap();
}
return true;
case KeyEvent.KEYCODE_DPAD_CENTER:
@@ -1294,43 +1302,39 @@ public class Camera extends Activity implements View.OnClickListener,
return super.onKeyUp(keyCode, event);
}
- private void doSnap(boolean needAutofocus) {
- // The camera operates in focus-priority mode, meaning that we take a picture
- // when focusing completes, and only if it completes successfully. If the user
- // has half-pressed the shutter and already locked focus, we can take the photo
- // right away, otherwise we need to start AF.
- if (mIsFocused || !mPreviewing) {
+ private void doSnap() {
+ // If the user has half-pressed the shutter and focus is completed, we
+ // can take the photo right away.
+ if ((mFocusState == FOCUS_SUCCESS || mFocusState == FOCUS_FAIL)
+ || !mPreviewing) {
// doesn't get set until the idler runs
if (mCaptureObject != null) {
mCaptureObject.onSnap();
}
- clearFocus();
+ clearFocusState();
updateFocusIndicator();
} else {
- // Half pressing the shutter (i.e. the focus button event) will already have
- // requested AF for us, so just request capture on focus here. If AF has
- // already failed, we don't want to trigger it again.
- mCaptureOnFocus = true;
- if (needAutofocus && !mIsFocusButtonPressed) {
- // But we do need to start AF for DPAD_CENTER
- autoFocus();
- }
+ // Half pressing the shutter (i.e. the focus button event) will
+ // already have requested AF for us, so just request capture on
+ // focus here.
+ mFocusState = FOCUSING_SNAP_ON_FINISH;
}
}
private void doFocus(boolean pressed) {
- if (pressed) {
- mIsFocusButtonPressed = true;
- mCaptureOnFocus = false;
+ if (pressed) { // Focus key down.
if (mPreviewing) {
autoFocus();
} else if (mCaptureObject != null) {
// Save and restart preview
mCaptureObject.onSnap();
}
- } else {
- clearFocus();
- updateFocusIndicator();
+ } else { // Focus key up.
+ if (mFocusState != FOCUSING_SNAP_ON_FINISH) {
+ // User releases half-pressed focus key.
+ clearFocusState();
+ updateFocusIndicator();
+ }
}
}
@@ -1414,7 +1418,7 @@ public class Camera extends Activity implements View.OnClickListener,
// let the user take a picture, and delete that file if needed to save the new photo.
calculatePicturesRemaining();
- if (!isLastPictureValid()) {
+ if (!isImageCaptureIntent() && !isLastPictureValid()) {
updateLastImage();
}
diff --git a/src/com/android/camera/ImageGallery2.java b/src/com/android/camera/ImageGallery2.java
index 008eb21..365be0f 100644
--- a/src/com/android/camera/ImageGallery2.java
+++ b/src/com/android/camera/ImageGallery2.java
@@ -254,6 +254,10 @@ public class ImageGallery2 extends Activity {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (mGvs.mCurrentSpec == null) {
+ // View.onLayout hasn't been called so we can't handle onKeyDown event yet.
+ return false;
+ }
boolean handled = true;
int sel = mGvs.mCurrentSelection;
int columns = mGvs.mCurrentSpec.mColumns;
@@ -332,7 +336,13 @@ public class ImageGallery2 extends Activity {
private void launchCropperOrFinish(ImageManager.IImage img) {
Bundle myExtras = getIntent().getExtras();
- if (MenuHelper.getImageFileSize(img) > mVideoSizeLimit) {
+ long size = MenuHelper.getImageFileSize(img);
+ if (size < 0) {
+ // return if there image file is not available.
+ return;
+ }
+
+ if (size > mVideoSizeLimit) {
DialogInterface.OnClickListener buttonListener =
new DialogInterface.OnClickListener() {
@@ -1553,7 +1563,8 @@ public class ImageGallery2 extends Activity {
}
if (ImageManager.isVideo(image)) {
Drawable overlay = null;
- if (MenuHelper.getImageFileSize(image) <= mVideoSizeLimit) {
+ long size = MenuHelper.getImageFileSize(image);
+ if (size >= 0 && size <= mVideoSizeLimit) {
if (mVideoOverlay == null) {
mVideoOverlay = getResources().getDrawable(
R.drawable.ic_gallery_video_overlay);
diff --git a/src/com/android/camera/ImageManager.java b/src/com/android/camera/ImageManager.java
index 99e5366..6c3472b 100755
--- a/src/com/android/camera/ImageManager.java
+++ b/src/com/android/camera/ImageManager.java
@@ -73,7 +73,7 @@ public class ImageManager {
public static String getBucketId(String path) {
return String.valueOf(path.toLowerCase().hashCode());
}
-
+
/**
* OSX requires plugged-in USB storage to have path /DCIM/NNNAAAAA to be imported.
* This is a temporary fix for bug#1655552.
@@ -4123,12 +4123,14 @@ public class ImageManager {
}
static public boolean hasStorage(boolean requireWriteAccess) {
+ //TODO: After fix the bug, add "if (VERBOSE)" before logging errors.
String state = Environment.getExternalStorageState();
- if (VERBOSE) Log.v(TAG, "state is " + state);
+ Log.v(TAG, "storage state is " + state);
+
if (Environment.MEDIA_MOUNTED.equals(state)) {
if (requireWriteAccess) {
boolean writable = checkFsWritable();
- if (VERBOSE) Log.v(TAG, "writable is " + writable);
+ Log.v(TAG, "storage writable is " + writable);
return writable;
} else {
return true;
diff --git a/src/com/android/camera/MenuHelper.java b/src/com/android/camera/MenuHelper.java
index 7148cd6..2bb532e 100644
--- a/src/com/android/camera/MenuHelper.java
+++ b/src/com/android/camera/MenuHelper.java
@@ -112,6 +112,7 @@ public class MenuHelper {
public static long getImageFileSize(ImageManager.IImage image) {
java.io.InputStream data = image.fullSizeImageData();
+ if (data == null) return -1;
try {
return data.available();
} catch (java.io.IOException ex) {
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index 37e1dcb..e9ffbe4 100644
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -119,13 +119,11 @@ public class VideoCamera extends Activity implements View.OnClickListener,
boolean mPausing = false;
static ContentResolver mContentResolver;
- boolean mDidRegister = false;
int mCurrentZoomIndex = 0;
private ShutterButton mShutterButton;
private TextView mRecordingTimeView;
- private boolean mHasSdCard;
ArrayList<MenuItem> mGalleryItems = new ArrayList<MenuItem>();
@@ -195,25 +193,20 @@ 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)) {
- mHasSdCard = false;
+ updateStorageHint(false);
stopVideoRecording();
initializeVideo();
} else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
- // SD card available
- // TODO put up a "please wait" message
- // TODO also listen for the media scanner finished message
- updateStorageHint();
- mHasSdCard = true;
+ updateStorageHint(true);
initializeVideo();
} else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) {
// SD card unavailable
- updateStorageHint();
- mHasSdCard = false;
+ updateStorageHint(false);
releaseMediaRecorder();
} 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();
+ updateStorageHint(true);
}
}
};
@@ -266,29 +259,6 @@ public class VideoCamera extends Activity implements View.OnClickListener,
mVideoFrame = (ImageView) findViewById(R.id.video_frame);
}
- @Override
- public void onStart() {
- if (DEBUG_LOG_APP_LIFECYCLE) {
- Log.v(TAG, "onStart " + this.hashCode());
- }
- super.onStart();
-
- Thread t = new Thread(new Runnable() {
- public void run() {
- final boolean storageOK = getAvailableStorage() >= LOW_STORAGE_THRESHOLD;
-
- if (!storageOK) {
- mHandler.post(new Runnable() {
- public void run() {
- updateStorageHint();
- }
- });
- }
- }
- });
- t.start();
- }
-
public void onClick(View v) {
switch (v.getId()) {
@@ -375,17 +345,13 @@ public class VideoCamera extends Activity implements View.OnClickListener,
private OnScreenHint mStorageHint;
- private void updateStorageHint() {
- long remaining = getAvailableStorage();
+ private void updateStorageHint(boolean mayHaveSd) {
+ long remaining = mayHaveSd ? getAvailableStorage() : NO_STORAGE_ERROR;
String errorMessage = null;
if (remaining == NO_STORAGE_ERROR) {
errorMessage = getString(R.string.no_storage);
} else if (remaining < LOW_STORAGE_THRESHOLD) {
errorMessage = getString(R.string.spaceIsLow_content);
- if (mStorageHint != null) {
- mStorageHint.cancel();
- mStorageHint = null;
- }
}
if (errorMessage != null) {
if (mStorageHint == null) {
@@ -419,8 +385,7 @@ public class VideoCamera extends Activity implements View.OnClickListener,
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
intentFilter.addDataScheme("file");
registerReceiver(mReceiver, intentFilter);
- mDidRegister = true;
- mHasSdCard = ImageManager.hasStorage();
+ updateStorageHint(true);
mBlackout.setVisibility(View.INVISIBLE);
if (mVideoFrameBitmap == null) {
@@ -452,10 +417,7 @@ public class VideoCamera extends Activity implements View.OnClickListener,
mPausing = true;
- if (mDidRegister) {
- unregisterReceiver(mReceiver);
- mDidRegister = false;
- }
+ unregisterReceiver(mReceiver);
mBlackout.setVisibility(View.VISIBLE);
setScreenTimeoutSystemDefault();
@@ -685,7 +647,7 @@ public class VideoCamera extends Activity implements View.OnClickListener,
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
- if (!mHasSdCard) {
+ if (mStorageHint != null) {
mMediaRecorder.setOutputFile("/dev/null");
} else {
// We try Uri in intent first. If it doesn't work, use our own instead.
@@ -864,10 +826,23 @@ 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();
+ updateStorageHint(true);
}
}
+ /*
+ * Make sure we're not recording music playing in the background, ask
+ * the MediaPlaybackService to pause playback.
+ */
+ private void pauseAudioPlayback() {
+ // Shamelessly copied from MediaPlaybackService.java, which
+ // should be public, but isn't.
+ Intent i = new Intent("com.android.music.musicservicecommand");
+ i.putExtra("command", "pause");
+
+ sendBroadcast(i);
+ }
+
private void startVideoRecording() {
Log.v(TAG, "startVideoRecording");
if (!mMediaRecorderRecording) {
@@ -883,6 +858,8 @@ public class VideoCamera extends Activity implements View.OnClickListener,
return;
}
+ pauseAudioPlayback();
+
try {
mMediaRecorder.setOnErrorListener(this);
mMediaRecorder.start(); // Recording is now started
@@ -973,7 +950,7 @@ public class VideoCamera extends Activity implements View.OnClickListener,
mRecordingTimeView.setVisibility(View.GONE);
setScreenTimeoutLong();
}
- if (needToRegisterRecording && mHasSdCard) registerVideo();
+ if (needToRegisterRecording && mStorageHint == null) registerVideo();
mCameraVideoFilename = null;
mCameraVideoFileDescriptor = null;
diff --git a/src/com/android/camera/ViewImage.java b/src/com/android/camera/ViewImage.java
index 07d396f..f6d0744 100644
--- a/src/com/android/camera/ViewImage.java
+++ b/src/com/android/camera/ViewImage.java
@@ -341,9 +341,19 @@ public class ViewImage extends Activity implements View.OnClickListener
return (oldScale != getScale());
}
- public void onSimpleZoom(boolean zoomIn) {
- if (zoomIn) zoomIn();
- else zoomOut();
+ 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);
}
};
@@ -361,8 +371,7 @@ public class ViewImage extends Activity implements View.OnClickListener
mViewImage = (ViewImage) context;
mZoomRingController = new ZoomRingController(context, this);
mZoomRingController.setVibration(false);
- mZoomRingController.setZoomCallbackThreshold(STEP_ANGLE);
- mZoomRingController.setResetThumbAutomatically(false);
+ mZoomRingController.setTickDelta(STEP_ANGLE);
mZoomRingController.setCallback(mZoomListener);
mGestureDetector = new GestureDetector(getContext(), new MyGestureListener());
mGestureDetector.setOnDoubleTapListener(new MyDoubleTapListener());
@@ -382,7 +391,7 @@ public class ViewImage extends Activity implements View.OnClickListener
}
public void onZoom(boolean zoomIn) {
- mZoomListener.onSimpleZoom(zoomIn);
+ mZoomListener.onSimpleZoom(zoomIn, getWidth()/2, getHeight()/2);
}
});
}