diff options
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/camera/PhotoModule.java | 4 | ||||
-rw-r--r-- | src/com/android/camera/ui/TimeIntervalPopup.java | 20 | ||||
-rw-r--r-- | src/com/android/camera/util/CameraUtil.java | 52 |
3 files changed, 72 insertions, 4 deletions
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index 150b6e822..938a0766f 100644 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -1524,8 +1524,8 @@ public class PhotoModule private void updateCameraParametersInitialize() { // Reset preview frame rate to the maximum because it may be lowered by // video camera application. - int[] fpsRange = CameraUtil.getMaxPreviewFpsRange(mParameters); - if (fpsRange.length > 0) { + int[] fpsRange = CameraUtil.getPhotoPreviewFpsRange(mParameters); + if (fpsRange != null && fpsRange.length > 0) { mParameters.setPreviewFpsRange( fpsRange[Parameters.PREVIEW_FPS_MIN_INDEX], fpsRange[Parameters.PREVIEW_FPS_MAX_INDEX]); diff --git a/src/com/android/camera/ui/TimeIntervalPopup.java b/src/com/android/camera/ui/TimeIntervalPopup.java index f35f24193..10e256ad1 100644 --- a/src/com/android/camera/ui/TimeIntervalPopup.java +++ b/src/com/android/camera/ui/TimeIntervalPopup.java @@ -30,6 +30,9 @@ import com.android.camera.IconListPreference; import com.android.camera.ListPreference; import com.android.camera2.R; +import java.text.NumberFormat; +import java.util.Locale; + /** * This is a popup window that allows users to turn on/off time lapse feature, * and to select a time interval for taking a time lapse video. @@ -60,8 +63,21 @@ public class TimeIntervalPopup extends AbstractSettingPopup { Resources res = context.getResources(); mUnits = res.getStringArray(R.array.pref_video_time_lapse_frame_interval_units); - mDurations = res - .getStringArray(R.array.pref_video_time_lapse_frame_interval_duration_values); + mDurations = localizeNumbers(res + .getStringArray(R.array.pref_video_time_lapse_frame_interval_duration_values)); + } + + /** + * Localizes an array of US formatted numbers. + */ + private static String[] localizeNumbers(String[] mDurations) { + NumberFormat format = NumberFormat.getInstance(Locale.getDefault()); + String[] result = new String[mDurations.length]; + for (int i = 0; i < mDurations.length; ++i) { + double value = Double.valueOf(mDurations[i]); + result[i] = format.format(value); + } + return result; } public void initialize(IconListPreference preference) { diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java index d90110f9f..7c1a415da 100644 --- a/src/com/android/camera/util/CameraUtil.java +++ b/src/com/android/camera/util/CameraUtil.java @@ -72,6 +72,10 @@ import java.util.StringTokenizer; public class CameraUtil { private static final String TAG = "Util"; + // For calculate the best fps range for still image capture. + private final static int MAX_PREVIEW_FPS_TIMES_1000 = 400000; + private final static int PREFERRED_PREVIEW_FPS_TIMES_1000 = 30000; + // For creating crop intents. public static final String KEY_RETURN_DATA = "return-data"; public static final String KEY_SHOW_WHEN_LOCKED = "showWhenLocked"; @@ -746,6 +750,54 @@ public class CameraUtil { } } + /** + * For still image capture, we need to get the right fps range such that the + * camera can slow down the framerate to allow for less-noisy/dark + * viewfinder output in dark conditions. + * + * @param params Camera's parameters. + * @return null if no appropiate fps range can't be found. Otherwise, return + * the right range. + */ + public static int[] getPhotoPreviewFpsRange(Parameters params) { + List<int[]> frameRates = params.getSupportedPreviewFpsRange(); + if (frameRates.size() == 0) { + Log.e(TAG, "No suppoted frame rates returned!"); + return null; + } + + // Find the lowest min rate in supported ranges who can cover 30fps. + int lowestMinRate = MAX_PREVIEW_FPS_TIMES_1000; + for (int[] rate : frameRates) { + int minFps = rate[Parameters.PREVIEW_FPS_MIN_INDEX]; + int maxFps = rate[Parameters.PREVIEW_FPS_MAX_INDEX]; + if (maxFps >= PREFERRED_PREVIEW_FPS_TIMES_1000 && + minFps <= PREFERRED_PREVIEW_FPS_TIMES_1000 && + minFps < lowestMinRate) { + lowestMinRate = minFps; + } + } + + // Find all the modes with the lowest min rate found above, the pick the + // one with highest max rate. + int resultIndex = -1; + int highestMaxRate = 0; + for (int i = 0; i < frameRates.size(); i++) { + int[] rate = frameRates.get(i); + int minFps = rate[Parameters.PREVIEW_FPS_MIN_INDEX]; + int maxFps = rate[Parameters.PREVIEW_FPS_MAX_INDEX]; + if (minFps == lowestMinRate && highestMaxRate < maxFps) { + highestMaxRate = maxFps; + resultIndex = i; + } + } + + if (resultIndex >= 0) { + return frameRates.get(resultIndex); + } + Log.e(TAG, "Can't find an appropiate frame rate range!"); + return null; + } public static int[] getMaxPreviewFpsRange(Parameters params) { List<int[]> frameRates = params.getSupportedPreviewFpsRange(); |