summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/Util.java
diff options
context:
space:
mode:
authorNipun Kwatra <nkwatra@google.com>2010-08-05 21:17:04 -0700
committerNipun Kwatra <nkwatra@google.com>2010-08-10 16:13:31 -0700
commit6227fa641518492a6b660c78463da18d9ec8fcd8 (patch)
tree5a1e119ce65e88fb8a04a8f0f2e235973344d448 /src/com/android/camera/Util.java
parent80a188c1743205093794a81b021b2ca232423d36 (diff)
downloadLegacyCamera-6227fa641518492a6b660c78463da18d9ec8fcd8.tar.gz
LegacyCamera-6227fa641518492a6b660c78463da18d9ec8fcd8.tar.bz2
LegacyCamera-6227fa641518492a6b660c78463da18d9ec8fcd8.zip
Added support for time lapse video capture.
Changes in individual files: VideoCamera.java: - Added swith to time lapse option in Menu. - initializeHeadUpDisplay(): sets up display according to the current mode (timelapse/no timelapse). - readTimeLapseVideoPreferences(): sets parameters according to the chosen quality. Eventually this should move to CamcorderProfile through media_profiles.xml files. - switchTimeLapseMode(): handles switching between time lapse mode normal mode. - Since preview size may be different from video size for HD time lapse capture, we save the desired preview size in mDesiredPreviewWidth, mDesiredPreviewHeight and use it for comparison in resetCameraParameters(). - Time lapse mode is enabled/disabled by calling mMediaRecorder.setTimeLapseParameters(). CamcorderHeadUpDisplay.java: Constructor now takes in a boolean (captureTimeLapse) telling whether to enable time lapse quality options or the normal camcorder quality options. Camera.java: Moved getOptimalPreviewSize() to Util.java to enable use from VideoCamera.java. Also needed to pass activity, so that can use getWindowManager(), getSystemService(). CameraSettings.java: added support for time lapse parameters. The function getVideoTimeLapseQuality() returns the quality identifier from the passed in string. res/: added string, array values for time lapse. res/xml/video_time_lapse_preferences.xml: contains all the preferences for time lapse mode. Change-Id: I194e7bc0b6218aa742d91c859a122de2b953a314
Diffstat (limited to 'src/com/android/camera/Util.java')
-rw-r--r--src/com/android/camera/Util.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index de995621..2af46fdd 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -22,7 +22,9 @@ import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
+import android.hardware.Camera.Size;
import android.util.Log;
+import android.view.Display;
import android.view.Surface;
import android.view.View;
import android.view.animation.Animation;
@@ -31,6 +33,7 @@ import android.view.animation.TranslateAnimation;
import com.android.camera.gallery.IImage;
import com.android.camera.R;
+import java.util.List;
import java.io.Closeable;
/**
@@ -298,4 +301,50 @@ public class Util {
int result = (info.mOrientation - degrees + 360) % 360;
camera.setDisplayOrientation(result);
}
+
+ public static Size getOptimalPreviewSize(Activity currentActivity,
+ List<Size> sizes, double targetRatio) {
+ final double ASPECT_TOLERANCE = 0.05;
+ if (sizes == null) return null;
+
+ Size optimalSize = null;
+ double minDiff = Double.MAX_VALUE;
+
+ // Because of bugs of overlay and layout, we sometimes will try to
+ // layout the viewfinder in the portrait orientation and thus get the
+ // wrong size of mSurfaceView. When we change the preview size, the
+ // new overlay will be created before the old one closed, which causes
+ // an exception. For now, just get the screen size
+
+ Display display = currentActivity.getWindowManager().getDefaultDisplay();
+ int targetHeight = Math.min(display.getHeight(), display.getWidth());
+
+ if (targetHeight <= 0) {
+ // We don't know the size of SurfaceView, use screen height
+ targetHeight = display.getHeight();
+ }
+
+ // Try to find an size match aspect ratio and size
+ for (Size size : sizes) {
+ double ratio = (double) size.width / size.height;
+ if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
+ if (Math.abs(size.height - targetHeight) < minDiff) {
+ optimalSize = size;
+ minDiff = Math.abs(size.height - targetHeight);
+ }
+ }
+
+ // Cannot find the one match the aspect ratio, ignore the requirement
+ if (optimalSize == null) {
+ Log.v(TAG, "No preview size match the aspect ratio");
+ minDiff = Double.MAX_VALUE;
+ for (Size size : sizes) {
+ if (Math.abs(size.height - targetHeight) < minDiff) {
+ optimalSize = size;
+ minDiff = Math.abs(size.height - targetHeight);
+ }
+ }
+ }
+ return optimalSize;
+ }
}