summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorWu-cheng Li <wuchengli@google.com>2011-09-07 15:34:17 +0800
committerWu-cheng Li <wuchengli@google.com>2011-09-08 02:50:09 +0800
commita93a4d60eacee4e12471b45f8691c14114e113a4 (patch)
tree8d924a9924c8238d2d74238c73d94710f2bd3aee /src/com/android
parent03e53d81e5d64542fba64565962b9c0049525f71 (diff)
downloadpackages_apps_LegacyCamera-a93a4d60eacee4e12471b45f8691c14114e113a4.zip
packages_apps_LegacyCamera-a93a4d60eacee4e12471b45f8691c14114e113a4.tar.gz
packages_apps_LegacyCamera-a93a4d60eacee4e12471b45f8691c14114e113a4.tar.bz2
Set rotation and gps in video snapshot.
bug:5187868 Change-Id: I1092e3d37dba78073b42aa9107e7cc326d67decc
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/camera/Camera.java80
-rw-r--r--src/com/android/camera/LocationManager.java47
-rw-r--r--src/com/android/camera/Util.java56
-rw-r--r--src/com/android/camera/VideoCamera.java41
4 files changed, 131 insertions, 93 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index 5237c51..6012c8d 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -193,7 +193,6 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
private boolean mPausing;
private boolean mFirstTimeInitialized;
private boolean mIsImageCaptureIntent;
- private boolean mRecordLocation;
private static final int PREVIEW_STOPPED = 0;
private static final int IDLE = 1; // preview is active
@@ -207,7 +206,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
private final ArrayList<MenuItem> mGalleryItems = new ArrayList<MenuItem>();
- private LocationManager mLocationManager = null;
+ private LocationManager mLocationManager;
private final ShutterCallback mShutterCallback = new ShutterCallback();
private final PostViewPictureCallback mPostViewPictureCallback =
@@ -357,10 +356,10 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
mOrientationListener.enable();
// Initialize location sevice.
- mRecordLocation = RecordLocationPreference.get(
+ boolean recordLocation = RecordLocationPreference.get(
mPreferences, getContentResolver());
initOnScreenIndicator();
- if (mRecordLocation) mLocationManager.startReceivingLocationUpdates();
+ mLocationManager.recordLocation(recordLocation);
keepMediaProviderInstance();
checkStorage();
@@ -434,9 +433,9 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
mOrientationListener.enable();
// Start location update if needed.
- mRecordLocation = RecordLocationPreference.get(
+ boolean recordLocation = RecordLocationPreference.get(
mPreferences, getContentResolver());
- if (mRecordLocation) mLocationManager.startReceivingLocationUpdates();
+ mLocationManager.recordLocation(recordLocation);
installIntentFilter();
mFocusManager.initializeToneGenerator();
@@ -804,56 +803,10 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
enableCameraControls(false);
mJpegImageData = null;
- // See android.hardware.Camera.Parameters.setRotation for
- // documentation.
- int rotation = 0;
- if (mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
- CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
- if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
- rotation = (info.orientation - mOrientation + 360) % 360;
- } else { // back-facing camera
- rotation = (info.orientation + mOrientation) % 360;
- }
- }
- mParameters.setRotation(rotation);
-
- // Clear previous GPS location from the parameters.
- mParameters.removeGpsData();
-
- // We always encode GpsTimeStamp
- mParameters.setGpsTimestamp(System.currentTimeMillis() / 1000);
-
- // Set GPS location.
- Location loc = mRecordLocation ? mLocationManager.getCurrentLocation() : null;
- if (loc != null) {
- double lat = loc.getLatitude();
- double lon = loc.getLongitude();
- boolean hasLatLon = (lat != 0.0d) || (lon != 0.0d);
-
- if (hasLatLon) {
- Log.d(TAG, "Set gps location");
- mParameters.setGpsLatitude(lat);
- mParameters.setGpsLongitude(lon);
- mParameters.setGpsProcessingMethod(loc.getProvider().toUpperCase());
- if (loc.hasAltitude()) {
- mParameters.setGpsAltitude(loc.getAltitude());
- } else {
- // for NETWORK_PROVIDER location provider, we may have
- // no altitude information, but the driver needs it, so
- // we fake one.
- mParameters.setGpsAltitude(0);
- }
- if (loc.getTime() != 0) {
- // Location.getTime() is UTC in milliseconds.
- // gps-timestamp is UTC in seconds.
- long utcTimeSeconds = loc.getTime() / 1000;
- mParameters.setGpsTimestamp(utcTimeSeconds);
- }
- } else {
- loc = null;
- }
- }
-
+ // Set rotation and gps data.
+ Util.setRotationParameter(mParameters, mCameraId, mOrientation);
+ Location loc = mLocationManager.getCurrentLocation();
+ Util.setGpsParameters(mParameters, loc);
mCameraDevice.setParameters(mParameters);
mCameraDevice.takePicture(mShutterCallback, mRawPictureCallback,
@@ -1345,7 +1298,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
unregisterReceiver(mReceiver);
mDidRegister = false;
}
- mLocationManager.stopReceivingLocationUpdates();
+ mLocationManager.recordLocation(false);
updateExposureOnScreenIndicator(0);
mFocusManager.releaseToneGenerator();
@@ -1936,19 +1889,10 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
// ignore the events after "onPause()"
if (mPausing) return;
- boolean recordLocation;
-
- recordLocation = RecordLocationPreference.get(
+ boolean recordLocation = RecordLocationPreference.get(
mPreferences, getContentResolver());
+ mLocationManager.recordLocation(recordLocation);
- if (mRecordLocation != recordLocation) {
- mRecordLocation = recordLocation;
- if (mRecordLocation) {
- mLocationManager.startReceivingLocationUpdates();
- } else {
- mLocationManager.stopReceivingLocationUpdates();
- }
- }
int cameraId = CameraSettings.readPreferredCameraId(mPreferences);
if (mCameraId != cameraId) {
// Restart the activity to have a crossfade animation.
diff --git a/src/com/android/camera/LocationManager.java b/src/com/android/camera/LocationManager.java
index 56bd812..fcf21b6 100644
--- a/src/com/android/camera/LocationManager.java
+++ b/src/com/android/camera/LocationManager.java
@@ -48,8 +48,30 @@ public class LocationManager {
mListener = listener;
}
- public void startReceivingLocationUpdates() {
- mRecordLocation = true;
+ public Location getCurrentLocation() {
+ if (!mRecordLocation) return null;
+
+ // go in best to worst order
+ for (int i = 0; i < mLocationListeners.length; i++) {
+ Location l = mLocationListeners[i].current();
+ if (l != null) return l;
+ }
+ Log.d(TAG, "No location received yet.");
+ return null;
+ }
+
+ public void recordLocation(boolean recordLocation) {
+ if (mRecordLocation != recordLocation) {
+ mRecordLocation = recordLocation;
+ if (recordLocation) {
+ startReceivingLocationUpdates();
+ } else {
+ stopReceivingLocationUpdates();
+ }
+ }
+ }
+
+ private void startReceivingLocationUpdates() {
if (mLocationManager == null) {
mLocationManager = (android.location.LocationManager)
mContext.getSystemService(Context.LOCATION_SERVICE);
@@ -72,7 +94,7 @@ public class LocationManager {
1000,
0F,
mLocationListeners[0]);
- mListener.showGpsOnScreenIndicator(false);
+ if (mListener != null) mListener.showGpsOnScreenIndicator(false);
} catch (SecurityException ex) {
Log.i(TAG, "fail to request location update, ignore", ex);
} catch (IllegalArgumentException ex) {
@@ -82,8 +104,7 @@ public class LocationManager {
}
}
- public void stopReceivingLocationUpdates() {
- mRecordLocation = false;
+ private void stopReceivingLocationUpdates() {
if (mLocationManager != null) {
for (int i = 0; i < mLocationListeners.length; i++) {
try {
@@ -94,17 +115,7 @@ public class LocationManager {
}
Log.d(TAG, "stopReceivingLocationUpdates");
}
- mListener.hideGpsOnScreenIndicator();
- }
-
- public Location getCurrentLocation() {
- // go in best to worst order
- for (int i = 0; i < mLocationListeners.length; i++) {
- Location l = mLocationListeners[i].current();
- if (l != null) return l;
- }
- Log.d(TAG, "No location received yet.");
- return null;
+ if (mListener != null) mListener.hideGpsOnScreenIndicator();
}
private class LocationListener
@@ -127,7 +138,7 @@ public class LocationManager {
}
// If GPS is available before start camera, we won't get status
// update so update GPS indicator when we receive data.
- if (mRecordLocation &&
+ if (mListener != null && mRecordLocation &&
android.location.LocationManager.GPS_PROVIDER.equals(mProvider)) {
mListener.showGpsOnScreenIndicator(true);
}
@@ -154,7 +165,7 @@ public class LocationManager {
case LocationProvider.OUT_OF_SERVICE:
case LocationProvider.TEMPORARILY_UNAVAILABLE: {
mValid = false;
- if (mRecordLocation &&
+ if (mListener != null && mRecordLocation &&
android.location.LocationManager.GPS_PROVIDER.equals(provider)) {
mListener.showGpsOnScreenIndicator(false);
}
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index a4aac7d..ca4bb42 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -28,8 +28,10 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.hardware.Camera;
+import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
+import android.location.Location;
import android.net.Uri;
import android.os.Build;
import android.os.ParcelFileDescriptor;
@@ -37,6 +39,7 @@ import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
+import android.view.OrientationEventListener;
import android.view.Surface;
import android.view.View;
import android.view.WindowManager;
@@ -519,4 +522,57 @@ public class Util {
animation.setDuration(500);
view.startAnimation(animation);
}
+
+ public static void setRotationParameter(Parameters parameters, int cameraId, int orientation) {
+ // See android.hardware.Camera.Parameters.setRotation for
+ // documentation.
+ int rotation = 0;
+ if (orientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
+ CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
+ if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
+ rotation = (info.orientation - orientation + 360) % 360;
+ } else { // back-facing camera
+ rotation = (info.orientation + orientation) % 360;
+ }
+ }
+ parameters.setRotation(rotation);
+ }
+
+ public static void setGpsParameters(Parameters parameters, Location loc) {
+ // Clear previous GPS location from the parameters.
+ parameters.removeGpsData();
+
+ // We always encode GpsTimeStamp
+ parameters.setGpsTimestamp(System.currentTimeMillis() / 1000);
+
+ // Set GPS location.
+ if (loc != null) {
+ double lat = loc.getLatitude();
+ double lon = loc.getLongitude();
+ boolean hasLatLon = (lat != 0.0d) || (lon != 0.0d);
+
+ if (hasLatLon) {
+ Log.d(TAG, "Set gps location");
+ parameters.setGpsLatitude(lat);
+ parameters.setGpsLongitude(lon);
+ parameters.setGpsProcessingMethod(loc.getProvider().toUpperCase());
+ if (loc.hasAltitude()) {
+ parameters.setGpsAltitude(loc.getAltitude());
+ } else {
+ // for NETWORK_PROVIDER location provider, we may have
+ // no altitude information, but the driver needs it, so
+ // we fake one.
+ parameters.setGpsAltitude(0);
+ }
+ if (loc.getTime() != 0) {
+ // Location.getTime() is UTC in milliseconds.
+ // gps-timestamp is UTC in seconds.
+ long utcTimeSeconds = loc.getTime() / 1000;
+ parameters.setGpsTimestamp(utcTimeSeconds);
+ }
+ } else {
+ loc = null;
+ }
+ }
+ }
}
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index d5bfe4c..432404b 100644
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -63,7 +63,6 @@ import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
-import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@@ -132,7 +131,6 @@ public class VideoCamera extends ActivityBase
"android.intent.extra.quickCapture";
private boolean mSnapshotInProgress = false;
- private PictureCallback mJpegPictureCallback;
private final static String EFFECT_BG_FROM_GALLERY =
"gallery";
@@ -224,6 +222,8 @@ public class VideoCamera extends ActivityBase
private ContentResolver mContentResolver;
+ private LocationManager mLocationManager;
+
private final ArrayList<MenuItem> mGalleryItems = new ArrayList<MenuItem>();
private final Handler mHandler = new MainHandler();
@@ -426,6 +426,8 @@ public class VideoCamera extends ActivityBase
mBgLearningMessage = (TextView) findViewById(R.id.bg_replace_message);
+ mLocationManager = new LocationManager(this, null);
+
// Make sure preview is started.
try {
startPreviewThread.join();
@@ -452,7 +454,6 @@ public class VideoCamera extends ActivityBase
if ("true".equals(mParameters.get("video-snapshot-supported")) &&
!mIsVideoCaptureIntent) {
preview.setOnTouchListener(this);
- mJpegPictureCallback = new JpegPictureCallback();
}
}
@@ -511,7 +512,6 @@ public class VideoCamera extends ActivityBase
@Override
public void onOrientationChanged(int orientation) {
- if (mMediaRecorderRecording) return;
// We keep the last known orientation. So if the user first orient
// the camera then point the camera to floor or sky, we still have
// the correct orientation.
@@ -521,9 +521,14 @@ public class VideoCamera extends ActivityBase
// calculate the up-to-date orientationCompensation.
int orientationCompensation = mOrientation
+ Util.getDisplayRotation(VideoCamera.this);
+
if (mOrientationCompensation != orientationCompensation) {
mOrientationCompensation = orientationCompensation;
- setOrientationIndicator(mOrientationCompensation);
+ // Do not rotate the icons during recording because the video
+ // orientation is fixed after recording.
+ if (!mMediaRecorderRecording) {
+ setOrientationIndicator(mOrientationCompensation);
+ }
}
}
}
@@ -836,6 +841,11 @@ public class VideoCamera extends ActivityBase
}
}, 200);
+ // Initialize location sevice.
+ boolean recordLocation = RecordLocationPreference.get(
+ mPreferences, getContentResolver());
+ mLocationManager.recordLocation(recordLocation);
+
if (!mIsVideoCaptureIntent) {
updateThumbnailButton(); // Update the last video thumbnail.
mModePicker.setCurrentMode(ModePicker.MODE_VIDEO);
@@ -960,6 +970,7 @@ public class VideoCamera extends ActivityBase
}
mOrientationListener.disable();
+ mLocationManager.recordLocation(false);
mHandler.removeMessages(CHECK_DISPLAY_ROTATION);
}
@@ -1942,6 +1953,10 @@ public class VideoCamera extends ActivityBase
// startPreview().
if (mCameraDevice == null) return;
+ boolean recordLocation = RecordLocationPreference.get(
+ mPreferences, getContentResolver());
+ mLocationManager.recordLocation(recordLocation);
+
// Check if the current effects selection has changed
if (updateEffectSelection()) return;
@@ -2160,18 +2175,30 @@ public class VideoCamera extends ActivityBase
return false;
}
+ // Set rotation and gps data.
+ Util.setRotationParameter(mParameters, mCameraId, mOrientation);
+ Location loc = mLocationManager.getCurrentLocation();
+ Util.setGpsParameters(mParameters, loc);
+ mCameraDevice.setParameters(mParameters);
+
Log.v(TAG, "Video snapshot start");
- mCameraDevice.takePicture(null, null, null, mJpegPictureCallback);
+ mCameraDevice.takePicture(null, null, null, new JpegPictureCallback(loc));
mSnapshotInProgress = true;
return true;
}
private final class JpegPictureCallback implements PictureCallback {
+ Location mLocation;
+
+ public JpegPictureCallback(Location loc) {
+ mLocation = loc;
+ }
+
@Override
public void onPictureTaken(byte [] jpegData, android.hardware.Camera camera) {
Log.v(TAG, "onPictureTaken");
mSnapshotInProgress = false;
- storeImage(jpegData, null);
+ storeImage(jpegData, mLocation);
}
}