CTSVerifier: Fix incorrect playback sizing in Camera Video activity

On foldable devices, VideoView is sometimes resizing its width instead
of cropping vertically as the camera preview does. This patch fixes that
by setting the width of the VideoView as fixed and its scaleY to crop.

Change-Id: Icf2ff8a160c991f49e5d01033769493b7e453071
Merged-In: Icf2ff8a160c991f49e5d01033769493b7e453071
Bug: 255270462
Test: All resolutions x folded/unfolded x landscape/portrait x back/front camera
(cherry picked from commit f83905952064e7659f13a05294c8ebdf2cc702e1)
diff --git a/apps/CtsVerifier/res/layout-port/camera_video.xml b/apps/CtsVerifier/res/layout-port/camera_video.xml
index 2a90e67..ac71e1f 100644
--- a/apps/CtsVerifier/res/layout-port/camera_video.xml
+++ b/apps/CtsVerifier/res/layout-port/camera_video.xml
@@ -113,11 +113,25 @@
             android:layout_weight="3"
             android:gravity="center" >
 
-            <VideoView
-                android:id="@+id/video_playback"
-                android:layout_height="0dp"
+            <LinearLayout
+                android:orientation="vertical"
                 android:layout_width="fill_parent"
-                android:layout_weight="3" />
+                android:layout_height="0dp"
+                android:layout_weight="3"
+                android:gravity="center" >
+
+                <VideoView
+                    android:id="@+id/video_playback"
+                    android:layout_alignParentLeft="true"
+                    android:layout_alignParentRight="true"
+                    android:layout_centerInParent="true"
+                    android:layout_height="wrap_content"
+                    android:layout_width="match_parent"
+                    android:focusable="false"
+                    android:focusableInTouchMode="false" />
+
+            </LinearLayout>
+
             <TextView
                 android:id="@+id/camera_video_playback_label"
                 android:layout_height="wrap_content"
diff --git a/apps/CtsVerifier/res/layout/camera_video.xml b/apps/CtsVerifier/res/layout/camera_video.xml
index e38d9a7..66064a0e 100644
--- a/apps/CtsVerifier/res/layout/camera_video.xml
+++ b/apps/CtsVerifier/res/layout/camera_video.xml
@@ -55,11 +55,25 @@
             android:layout_weight="3"
             android:gravity="center" >
 
-            <VideoView
-                android:id="@+id/video_playback"
-                android:layout_height="0dp"
+            <LinearLayout
+                android:orientation="vertical"
                 android:layout_width="fill_parent"
-                android:layout_weight="3" />
+                android:layout_height="0dp"
+                android:layout_weight="3"
+                android:gravity="center" >
+
+                <VideoView
+                    android:id="@+id/video_playback"
+                    android:layout_alignParentLeft="true"
+                    android:layout_alignParentRight="true"
+                    android:layout_centerInParent="true"
+                    android:layout_height="wrap_content"
+                    android:layout_width="match_parent"
+                    android:focusable="false"
+                    android:focusableInTouchMode="false" />
+
+            </LinearLayout>
+
             <TextView
                 android:id="@+id/camera_video_playback_label"
                 android:layout_height="wrap_content"
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java
index d508f7a..a050323 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java
@@ -533,6 +533,26 @@
                                     releaseMediaRecorder();
 
                                     mPlaybackView.setVideoPath(outputVideoFile.getPath());
+
+                                    // Crop playback vertically if necessary
+                                    float videoWidth = (float) mNextPreviewSize.width;
+                                    float videoHeight = (float) mNextPreviewSize.height;
+                                    if (mVideoRotation == 90 || mVideoRotation == 270) {
+                                        videoWidth = (float) mNextPreviewSize.height;
+                                        videoHeight = (float) mNextPreviewSize.width;
+                                    }
+
+                                    float potentialHeight = mPlaybackView.getWidth()
+                                            * (videoHeight / videoWidth);
+                                    if (potentialHeight > mPreviewTexHeight) {
+                                        // Use mPreviewTexHeight as a reference as
+                                        // mPlaybackView.getHeight() is from the previous playback
+                                        float scaleY = potentialHeight / (float) mPreviewTexHeight;
+                                        mPlaybackView.setScaleY(scaleY);
+                                    } else {
+                                        mPlaybackView.setScaleY(1.0f);
+                                    }
+
                                     mPlaybackView.start();
                                     isRecording = false;
                                     isPlayingBack = true;