OSDN Git Service

Set default video quality to the highest
authorDoris Liu <tianliu@google.com>
Wed, 31 Jul 2013 18:25:09 +0000 (11:25 -0700)
committerDoris Liu <tianliu@google.com>
Wed, 31 Jul 2013 21:23:37 +0000 (14:23 -0700)
Bug: 9886141

Change-Id: I4741d5c898ac666923cfc12abc78d5d3517cb05f

gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
res/xml/video_preferences.xml
src/com/android/camera/CameraSettings.java
src/com/android/camera/VideoModule.java

index f580450..f4de5c9 100644 (file)
@@ -125,9 +125,6 @@ public class ApiHelper {
     public static final boolean HAS_CAMERA_METERING_AREA =
             Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH;
 
-    public static final boolean HAS_FINE_RESOLUTION_QUALITY_LEVELS =
-            Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB;
-
     public static final boolean HAS_MOTION_EVENT_TRANSFORM =
             Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB;
 
index faf5f65..79154e6 100644 (file)
@@ -19,7 +19,6 @@
         camera:title="@string/pref_camcorder_settings_category">
     <ListPreference
             camera:key="pref_video_quality_key"
-            camera:defaultValue="@string/pref_video_quality_default"
             camera:title="@string/pref_video_quality_title"
             camera:entries="@array/pref_video_quality_entries"
             camera:entryValues="@array/pref_video_quality_entryvalues"/>
index 4e9a5dd..3558014 100644 (file)
@@ -93,16 +93,16 @@ public class CameraSettings {
         return group;
     }
 
-    @TargetApi(ApiHelper.VERSION_CODES.HONEYCOMB)
-    public static String getDefaultVideoQuality(int cameraId,
+    public static String getSupportedHighestVideoQuality(int cameraId,
             String defaultQuality) {
-        if (ApiHelper.HAS_FINE_RESOLUTION_QUALITY_LEVELS) {
-            if (CamcorderProfile.hasProfile(
-                    cameraId, Integer.valueOf(defaultQuality))) {
-                return defaultQuality;
-            }
-        }
-        return Integer.toString(CamcorderProfile.QUALITY_HIGH);
+        // When launching the camera app first time, we will set the video quality
+        // to the first one (i.e. highest quality) in the supported list
+        List<String> supported = getSupportedVideoQuality(cameraId);
+        if (supported == null) {
+            Log.e(TAG, "No supported video quality is found");
+            return defaultQuality;
+        }
+        return supported.get(0);
     }
 
     public static void initialCameraPictureSize(
@@ -177,7 +177,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) {
-            filterUnsupportedOptions(group, videoQuality, getSupportedVideoQuality());
+            filterUnsupportedOptions(group, videoQuality, getSupportedVideoQuality(mCameraId));
         }
 
         if (pictureSize != null) {
@@ -532,37 +532,19 @@ public class CameraSettings {
         writePreferredCameraId(preferences, currentCameraId);
     }
 
-    private ArrayList<String> getSupportedVideoQuality() {
+    private static ArrayList<String> getSupportedVideoQuality(int cameraId) {
         ArrayList<String> supported = new ArrayList<String>();
         // Check for supported quality
-        if (ApiHelper.HAS_FINE_RESOLUTION_QUALITY_LEVELS) {
-            getFineResolutionQuality(supported);
-        } else {
-            supported.add(Integer.toString(CamcorderProfile.QUALITY_HIGH));
-            CamcorderProfile high = CamcorderProfile.get(
-                    mCameraId, CamcorderProfile.QUALITY_HIGH);
-            CamcorderProfile low = CamcorderProfile.get(
-                    mCameraId, CamcorderProfile.QUALITY_LOW);
-            if (high.videoFrameHeight * high.videoFrameWidth >
-                    low.videoFrameHeight * low.videoFrameWidth) {
-                supported.add(Integer.toString(CamcorderProfile.QUALITY_LOW));
-            }
-        }
-
-        return supported;
-    }
-
-    @TargetApi(ApiHelper.VERSION_CODES.HONEYCOMB)
-    private void getFineResolutionQuality(ArrayList<String> supported) {
-        if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_1080P)) {
+        if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) {
             supported.add(Integer.toString(CamcorderProfile.QUALITY_1080P));
         }
-        if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_720P)) {
+        if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
             supported.add(Integer.toString(CamcorderProfile.QUALITY_720P));
         }
-        if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_480P)) {
+        if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
             supported.add(Integer.toString(CamcorderProfile.QUALITY_480P));
         }
+        return supported;
     }
 
     private void initVideoEffect(PreferenceGroup group, ListPreference videoEffect) {
index e3efa22..956890e 100644 (file)
@@ -472,20 +472,10 @@ public class VideoModule implements CameraModule,
         if (effectsActive()) {
             mUI.overrideSettings(
                     CameraSettings.KEY_VIDEO_QUALITY,
-                    Integer.toString(getLowVideoQuality()));
+                    Integer.toString(CamcorderProfile.QUALITY_480P));
         }
     }
 
-    @TargetApi(ApiHelper.VERSION_CODES.HONEYCOMB)
-    private static int getLowVideoQuality() {
-        if (ApiHelper.HAS_FINE_RESOLUTION_QUALITY_LEVELS) {
-            return CamcorderProfile.QUALITY_480P;
-        } else {
-            return CamcorderProfile.QUALITY_LOW;
-        }
-    }
-
-
     @Override
     public void onOrientationChanged(int orientation) {
         // We keep the last known orientation. So if the user first orient
@@ -565,7 +555,7 @@ public class VideoModule implements CameraModule,
                 // back to use SurfaceTexture for preview and we need to stop then start
                 // the preview. This will cause the preview flicker since the preview
                 // will not be continuous for a short period of time.
-                // TODO: need to get the capture animation to work 
+                // TODO: need to get the capture animation to work
                 // ((CameraScreenNail) mActivity.mCameraScreenNail).animateCapture(mDisplayRotation);
 
                 mUI.enablePreviewThumb(true);
@@ -613,11 +603,14 @@ public class VideoModule implements CameraModule,
     private void readVideoPreferences() {
         // The preference stores values from ListPreference and is thus string type for all values.
         // We need to convert it to int manually.
-        String defaultQuality = CameraSettings.getDefaultVideoQuality(mCameraId,
-                mActivity.getResources().getString(R.string.pref_video_quality_default));
-        String videoQuality =
-                mPreferences.getString(CameraSettings.KEY_VIDEO_QUALITY,
-                        defaultQuality);
+        String videoQuality = mPreferences.getString(CameraSettings.KEY_VIDEO_QUALITY,
+                        null);
+        if (videoQuality == null) {
+            // check for highest quality before setting default value
+            videoQuality = CameraSettings.getSupportedHighestVideoQuality(mCameraId,
+                    mActivity.getResources().getString(R.string.pref_video_quality_default));
+            mPreferences.edit().putString(CameraSettings.KEY_VIDEO_QUALITY, videoQuality);
+        }
         int quality = Integer.valueOf(videoQuality);
 
         // Set video quality.
@@ -649,7 +642,7 @@ public class VideoModule implements CameraModule,
             // Set quality to be no higher than 480p.
             CamcorderProfile profile = CamcorderProfile.get(mCameraId, quality);
             if (profile.videoFrameHeight > 480) {
-                quality = getLowVideoQuality();
+                quality = CamcorderProfile.QUALITY_480P;
             }
         } else {
             mEffectParameter = null;