diff options
author | Angus Kong <shkong@google.com> | 2011-09-23 18:08:00 +0800 |
---|---|---|
committer | Angus Kong <shkong@google.com> | 2011-09-23 20:25:41 +0800 |
commit | 05999715cc38365aa4751a2a355eb1af284573ab (patch) | |
tree | 8fbafe767f4d64bfb57f62feec5b72eaf8b21295 /src/com | |
parent | 022d6d7e809fcd47ebc751deaea84e2d3639069a (diff) | |
download | LegacyCamera-05999715cc38365aa4751a2a355eb1af284573ab.zip LegacyCamera-05999715cc38365aa4751a2a355eb1af284573ab.tar.gz LegacyCamera-05999715cc38365aa4751a2a355eb1af284573ab.tar.bz2 |
Show the real resolution for quality settings.
1. Change the assets.
2. Change the strings from high/low/mms to 1080p/720p/480p.
3. Change the preference from customized string to the real values of
CamcorderProfile.QUALITY_[1080|720|480]P
bug:5141068
Change-Id: I294799bda8e873f828bbf4bd21330591f0859632
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/camera/CameraSettings.java | 88 | ||||
-rw-r--r-- | src/com/android/camera/ListPreference.java | 2 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 100 |
3 files changed, 60 insertions, 130 deletions
diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index a465a19..eb0161a 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -54,14 +54,10 @@ public class CameraSettings { public static final String EXPOSURE_DEFAULT_VALUE = "0"; - public static final int CURRENT_VERSION = 4; + public static final int CURRENT_VERSION = 5; public static final int CURRENT_LOCAL_VERSION = 1; - // max video duration in seconds for youtube. - private static final int YOUTUBE_VIDEO_DURATION = 15 * 60; // 15 mins - private static final int DEFAULT_VIDEO_DURATION = 0; // no limit - - public static final String DEFAULT_VIDEO_QUALITY_VALUE = "high"; + public static final int DEFAULT_VIDEO_DURATION = 0; // no limit private static final String TAG = "CameraSettings"; @@ -86,6 +82,14 @@ public class CameraSettings { return group; } + public String getDefaultVideoQuality(String defaultQuality) { + int quality = Integer.valueOf(defaultQuality); + if (CamcorderProfile.hasProfile(mCameraId, quality)) { + return defaultQuality; + } + return Integer.toString(CamcorderProfile.QUALITY_HIGH); + } + public static void initialCameraPictureSize( Context context, Parameters parameters) { // When launching the camera app first time, we will set the picture @@ -117,7 +121,7 @@ public class CameraSettings { if (index == NOT_FOUND) return false; int width = Integer.parseInt(candidate.substring(0, index)); int height = Integer.parseInt(candidate.substring(index + 1)); - for (Size size: supported) { + for (Size size : supported) { if (size.width == width && size.height == height) { parameters.setPictureSize(width, height); return true; @@ -136,7 +140,7 @@ public class CameraSettings { ListPreference focusMode = group.findPreference(KEY_FOCUS_MODE); ListPreference exposure = group.findPreference(KEY_EXPOSURE); IconListPreference cameraIdPref = - (IconListPreference)group.findPreference(KEY_CAMERA_ID); + (IconListPreference) group.findPreference(KEY_CAMERA_ID); ListPreference videoFlashMode = group.findPreference(KEY_VIDEOCAMERA_FLASH_MODE); ListPreference videoEffect = group.findPreference(KEY_VIDEO_EFFECT); @@ -144,7 +148,7 @@ public class CameraSettings { // Since the screen could be loaded from different resources, we need // to check if the preference is available here if (videoQuality != null) { - initVideoQuality(videoQuality); + filterUnsupportedOptions(group, videoQuality, getSupportedVideoQuality()); } if (pictureSize != null) { @@ -220,7 +224,7 @@ public class CameraSettings { } CharSequence[] entryValues = new CharSequence[2]; - for (int i = 0 ; i < mCameraInfo.length ; ++i) { + for (int i = 0; i < mCameraInfo.length; ++i) { int index = (mCameraInfo[i].facing == CameraInfo.CAMERA_FACING_FRONT) ? CameraInfo.CAMERA_FACING_FRONT @@ -338,27 +342,18 @@ public class CameraSettings { // ignore the current settings. editor.remove("pref_camera_videoquality_key"); editor.remove("pref_camera_video_duration_key"); + version = 4; + } + if (version == 4) { + // We use numbers to represent the quality now. The quality definition is identical to + // that of CamcorderProfile.java. + editor.remove("pref_video_quality_key"); } + editor.putInt(KEY_VERSION, CURRENT_VERSION); editor.apply(); } - public static boolean getVideoQuality(Context context, String quality) { - return context.getString(R.string.pref_video_quality_youtube).equals(quality) - || context.getString(R.string.pref_video_quality_high).equals(quality); - } - - public static int getVideoDurationInMillis(Context context, String quality, int cameraId) { - if (context.getString(R.string.pref_video_quality_mms).equals(quality)) { - int mmsVideoDuration = CamcorderProfile.get(cameraId, - CamcorderProfile.QUALITY_LOW).duration; - return mmsVideoDuration * 1000; - } else if (context.getString(R.string.pref_video_quality_youtube).equals(quality)) { - return YOUTUBE_VIDEO_DURATION * 1000; - } - return DEFAULT_VIDEO_DURATION; - } - public static int readPreferredCameraId(SharedPreferences pref) { return Integer.parseInt(pref.getString(KEY_CAMERA_ID, "0")); } @@ -462,38 +457,27 @@ public class CameraSettings { writePreferredCameraId(preferences, currentCameraId); } - private void initVideoQuality(ListPreference videoQuality) { - CharSequence[] entries = videoQuality.getEntries(); - CharSequence[] values = videoQuality.getEntryValues(); - if (Util.isMmsCapable(mContext)) { - int mmsVideoDuration = CamcorderProfile.get(mCameraId, - CamcorderProfile.QUALITY_LOW).duration; - // We need to fill in the device-dependent value (in seconds). - for (int i = 0; i < entries.length; ++i) { - if (mContext.getString(R.string.pref_video_quality_mms).equals(values[i])) { - entries[i] = entries[i].toString().replace( - "30", Integer.toString(mmsVideoDuration)); - break; - } - } - } else { - // The device does not support mms. Remove it. Using - // filterUnsupported is not efficient but adding a new method - // for remove is not worth it. - ArrayList<String> supported = new ArrayList<String>(); - for (int i = 0; i < entries.length; ++i) { - if (!mContext.getString(R.string.pref_video_quality_mms).equals(values[i])) { - supported.add(values[i].toString()); - } - } - videoQuality.filterUnsupported(supported); + private ArrayList<String> getSupportedVideoQuality() { + ArrayList<String> supported = new ArrayList<String>(); + // Check for supported quality + if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_1080P)) { + supported.add(Integer.toString(CamcorderProfile.QUALITY_1080P)); + } + if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_720P)) { + supported.add(Integer.toString(CamcorderProfile.QUALITY_720P)); } + if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_480P)) { + supported.add(Integer.toString(CamcorderProfile.QUALITY_480P)); + } + + return supported; } private void initVideoEffect(PreferenceGroup group, ListPreference videoEffect) { CharSequence[] values = videoEffect.getEntryValues(); - boolean goofyFaceSupported = EffectsRecorder.isEffectSupported(EffectsRecorder.EFFECT_GOOFY_FACE); + boolean goofyFaceSupported = + EffectsRecorder.isEffectSupported(EffectsRecorder.EFFECT_GOOFY_FACE); boolean backdropperSupported = EffectsRecorder.isEffectSupported(EffectsRecorder.EFFECT_BACKDROPPER) && mParameters.isAutoExposureLockSupported() && diff --git a/src/com/android/camera/ListPreference.java b/src/com/android/camera/ListPreference.java index 288c875..6885a37 100644 --- a/src/com/android/camera/ListPreference.java +++ b/src/com/android/camera/ListPreference.java @@ -22,8 +22,6 @@ import android.content.res.TypedArray; import android.util.AttributeSet; import android.util.Log; -import com.android.camera.R; - import java.util.ArrayList; import java.util.List; diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 8b6c328..74e217b 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -48,7 +48,6 @@ import android.os.ParcelFileDescriptor; import android.os.SystemClock; import android.provider.MediaStore; import android.provider.MediaStore.Video; -import android.provider.Settings; import android.util.Log; import android.view.GestureDetector; import android.view.Gravity; @@ -196,11 +195,6 @@ public class VideoCamera extends ActivityBase private ContentValues mCurrentVideoValues; private CamcorderProfile mProfile; - // The array of video quality profiles supported by each camera(s). Here the - // cameraId is the index of the array to get the profile map which contain - // the set of quality string and its real quality of a camera. - private HashMap<String, Integer>[] mProfileQuality; - private HashMap<String, Integer>[] mTimeLapseProfileQuality; // The video duration limit. 0 menas no limit. private int mMaxVideoDurationInMs; @@ -365,9 +359,9 @@ public class VideoCamera extends ActivityBase mCameraDevice = Util.openCamera(VideoCamera.this, mCameraId); readVideoPreferences(); startPreview(); - } catch(CameraHardwareException e) { + } catch (CameraHardwareException e) { mOpenCameraFail = true; - } catch(CameraDisabledException e) { + } catch (CameraDisabledException e) { mCameraDisabled = true; } } @@ -643,11 +637,14 @@ public class VideoCamera extends ActivityBase } private void readVideoPreferences() { - String quality = mPreferences.getString( + CameraSettings settings = new CameraSettings(this, mParameters, + mCameraId, CameraHolder.instance().getCameraInfo()); + // The preference stores values from ListPreference and is thus string type for all values. + // We need to convert it to int manually. + int quality = Integer.valueOf(mPreferences.getString( CameraSettings.KEY_VIDEO_QUALITY, - CameraSettings.DEFAULT_VIDEO_QUALITY_VALUE); - boolean videoQualityHigh = - CameraSettings.getVideoQuality(this, quality); + settings.getDefaultVideoQuality( + getResources().getString(R.string.pref_video_quality_default)))); // Set video quality. Intent intent = getIntent(); @@ -655,9 +652,9 @@ public class VideoCamera extends ActivityBase int extraVideoQuality = intent.getIntExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); if (extraVideoQuality > 0) { - quality = getString(R.string.pref_video_quality_high); + quality = CamcorderProfile.QUALITY_HIGH; } else { // 0 is mms. - quality = getString(R.string.pref_video_quality_mms); + quality = CamcorderProfile.QUALITY_LOW; } } @@ -668,8 +665,7 @@ public class VideoCamera extends ActivityBase intent.getIntExtra(MediaStore.EXTRA_DURATION_LIMIT, 0); mMaxVideoDurationInMs = 1000 * seconds; } else { - mMaxVideoDurationInMs = - CameraSettings.getVideoDurationInMillis(this, quality, mCameraId); + mMaxVideoDurationInMs = CameraSettings.DEFAULT_VIDEO_DURATION; } // Read time lapse recording interval. @@ -679,8 +675,9 @@ public class VideoCamera extends ActivityBase mTimeBetweenTimeLapseFrameCaptureMs = Integer.parseInt(frameIntervalStr); mCaptureTimeLapse = (mTimeBetweenTimeLapseFrameCaptureMs != 0); - int profileQuality = getProfileQuality(mCameraId, quality, mCaptureTimeLapse); - mProfile = CamcorderProfile.get(mCameraId, profileQuality); + // TODO: This should be checked instead directly +1000. + if (mCaptureTimeLapse) quality += 1000; + mProfile = CamcorderProfile.get(mCameraId, quality); getDesiredPreviewSize(); // Set effect @@ -706,55 +703,6 @@ public class VideoCamera extends ActivityBase } - int getProfileQuality(int cameraId, String quality, boolean captureTimeLapse) { - HashMap<String, Integer>[] qualityMap; - if (captureTimeLapse) { - if (mTimeLapseProfileQuality == null) { - mTimeLapseProfileQuality = new HashMap[ - CameraHolder.instance().getNumberOfCameras()]; - } - qualityMap = mTimeLapseProfileQuality; - if (qualityMap[cameraId] == null) { - qualityMap[cameraId] = buildProfileQuality(cameraId, TIME_LAPSE_VIDEO_QUALITY); - } - } else { - if (mProfileQuality == null) { - mProfileQuality = new HashMap[ - CameraHolder.instance().getNumberOfCameras()]; - } - qualityMap = mProfileQuality; - if (qualityMap[cameraId] == null) { - qualityMap[cameraId] = buildProfileQuality(cameraId, VIDEO_QUALITY); - } - } - return qualityMap[cameraId].get(quality); - } - - HashMap<String, Integer> buildProfileQuality(int cameraId, - int qualityList[]) { - HashMap<String, Integer> qualityMap = new HashMap<String, Integer>(); - int highestQuality = -1, secondHighestQuality = -1, - lastEffectiveQuality = -1; - for (int i = 0; i < qualityList.length; i++) { - if (CamcorderProfile.hasProfile(cameraId, qualityList[i])) { - if (highestQuality == -1) { - highestQuality = qualityList[i]; - } else if (secondHighestQuality == -1) { - secondHighestQuality = qualityList[i]; - } - lastEffectiveQuality = qualityList[i]; - } - } - if (secondHighestQuality == -1) { - secondHighestQuality = highestQuality; - } - qualityMap.put(getString(R.string.pref_video_quality_high), highestQuality); - qualityMap.put(getString(R.string.pref_video_quality_low), secondHighestQuality); - qualityMap.put(getString(R.string.pref_video_quality_youtube), highestQuality); - qualityMap.put(getString(R.string.pref_video_quality_mms), lastEffectiveQuality); - return qualityMap; - } - private void getDesiredPreviewSize() { mParameters = mCameraDevice.getParameters(); if (mParameters.getSupportedVideoSizes() == null) { @@ -804,10 +752,10 @@ public class VideoCamera extends ActivityBase readVideoPreferences(); resizeForPreviewAspectRatio(); startPreview(); - } catch(CameraHardwareException e) { + } catch (CameraHardwareException e) { Util.showErrorAndFinish(this, R.string.cannot_connect_camera); return; - } catch(CameraDisabledException e) { + } catch (CameraDisabledException e) { Util.showErrorAndFinish(this, R.string.camera_disabled); return; } @@ -1247,7 +1195,7 @@ public class VideoCamera extends ActivityBase mSurfaceHeight); if (mEffectType == EffectsRecorder.EFFECT_BACKDROPPER && - ((String)mEffectParameter).equals(EFFECT_BG_FROM_GALLERY) ) { + ((String) mEffectParameter).equals(EFFECT_BG_FROM_GALLERY)) { mEffectsRecorder.setEffect(mEffectType, mEffectUriFromGallery); } else { mEffectsRecorder.setEffect(mEffectType, mEffectParameter); @@ -1881,7 +1829,7 @@ public class VideoCamera extends ActivityBase if (resultCode == RESULT_OK) { // onActivityResult() runs before onResume(), so this parameter will be // seen by startPreview from onResume() - mEffectUriFromGallery = ((Uri)data.getData()).toString(); + mEffectUriFromGallery = ((Uri) data.getData()).toString(); Log.v(TAG, "Received URI from gallery: " + mEffectUriFromGallery); } break; @@ -2005,15 +1953,15 @@ public class VideoCamera extends ActivityBase if (mEffectType == EffectsRecorder.EFFECT_NONE) return false; if (mEffectParameter.equals(currentEffectParameter)) return false; } - Log.v(TAG, "New effect selection: " + mPreferences.getString(CameraSettings.KEY_VIDEO_EFFECT, "none") ); + Log.v(TAG, "New effect selection: " + mPreferences.getString(CameraSettings.KEY_VIDEO_EFFECT, "none")); - if ( mEffectType == EffectsRecorder.EFFECT_NONE ) { + if (mEffectType == EffectsRecorder.EFFECT_NONE) { // Stop effects and return to normal preview mEffectsRecorder.stopPreview(); return true; } if (mEffectType == EffectsRecorder.EFFECT_BACKDROPPER && - ((String)mEffectParameter).equals(EFFECT_BG_FROM_GALLERY)) { + ((String) mEffectParameter).equals(EFFECT_BG_FROM_GALLERY)) { // Request video from gallery to use for background Intent i = new Intent(Intent.ACTION_PICK); i.setDataAndType(Video.Media.EXTERNAL_CONTENT_URI, @@ -2114,7 +2062,7 @@ public class VideoCamera extends ActivityBase mZoomControl.setZoomMax(mZoomMax); mZoomControl.setZoomIndex(mParameters.getZoom()); mZoomControl.setSmoothZoomSupported(mSmoothZoomSupported); - mZoomControl.setOnZoomChangeListener(new ZoomChangeListener() ); + mZoomControl.setOnZoomChangeListener(new ZoomChangeListener()); mCameraDevice.setZoomChangeListener(mZoomListener); } @@ -2122,7 +2070,7 @@ public class VideoCamera extends ActivityBase implements android.hardware.Camera.OnZoomChangeListener { @Override public void onZoomChange(int value, boolean stopped, android.hardware.Camera camera) { - Log.v(TAG, "Zoom changed: value=" + value + ". stopped="+ stopped); + Log.v(TAG, "Zoom changed: value=" + value + ". stopped=" + stopped); mZoomValue = value; // Update the UI when we get zoom value. |