[PK Setting] Refine layout for Keyboard review

1. add background for keyboard review
2. add text for showing selected keyboard's name

Test: Verified on device
Bug: 305588594
Change-Id: Icf0f2b7798cc5cbddefc1b3a95480b48271b276f
diff --git a/res/drawable/keyboard_review_layout_background.xml b/res/drawable/keyboard_review_layout_background.xml
new file mode 100644
index 0000000..7f93f80
--- /dev/null
+++ b/res/drawable/keyboard_review_layout_background.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2023 The Android Open Source Project
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+       android:shape="rectangle">
+    <solid android:color="@color/settingslib_colorSurface"/>
+    <corners android:radius="@dimen/keyboard_picker_radius"/>
+</shape>
diff --git a/res/layout/keyboard_layout_picker.xml b/res/layout/keyboard_layout_picker.xml
index b25c228..5e62a2c 100644
--- a/res/layout/keyboard_layout_picker.xml
+++ b/res/layout/keyboard_layout_picker.xml
@@ -17,15 +17,33 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    android:layout_marginHorizontal="@dimen/keyboard_picker_margin"
     android:id="@+id/keyboard_layout_picker_container"
     android:orientation="vertical">
 
-    <ImageView
-        android:id="@+id/keyboard_layout_preview"
+    <FrameLayout
+        android:id="@+id/keyboard_layout_preview_container"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:adjustViewBounds="true"
-        android:scaleType="fitCenter"/>
+        android:background="@drawable/keyboard_review_layout_background">
+        <ImageView
+            android:id="@+id/keyboard_layout_preview"
+            android:layout_marginTop="@dimen/keyboard_picker_margin_small"
+            android:layout_marginBottom="@dimen/keyboard_picker_margin_large"
+            android:layout_marginHorizontal="@dimen/keyboard_picker_margin_small"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:adjustViewBounds="true"
+            android:scaleType="fitCenter" />
+        <TextView
+            android:id="@+id/keyboard_layout_preview_name"
+            android:layout_width="match_parent"
+            android:layout_height="@dimen/keyboard_picker_margin_large"
+            android:textSize="@dimen/keyboard_picker_text_size"
+            android:textColor="?android:attr/textColorPrimary"
+            android:layout_gravity="bottom"
+            android:gravity="center" />
+    </FrameLayout>
 
     <FrameLayout
         android:id="@+id/keyboard_layout_title"
diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml
index 647ba6c..6421e3e 100644
--- a/res/values-land/dimens.xml
+++ b/res/values-land/dimens.xml
@@ -27,4 +27,7 @@
 
     <dimen name="text_reading_preview_layout_padding_horizontal_min_suw">24dp</dimen>
     <dimen name="text_reading_preview_background_padding_horizontal_min_suw">24dp</dimen>
+
+    <!-- Keyboard -->
+    <dimen name="keyboard_picker_margin">106dp</dimen>
 </resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 6c03955..3e0b8d9 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -165,6 +165,13 @@
     <item name="face_preview_scale" format="float" type="dimen">1.0</item>
     <dimen name="face_enroll_intro_illustration_margin_bottom">0dp</dimen>
 
+    <!-- Keyboard -->
+    <dimen name="keyboard_picker_margin_large">68dp</dimen>
+    <dimen name="keyboard_picker_margin">24dp</dimen>
+    <dimen name="keyboard_picker_margin_small">16dp</dimen>
+    <dimen name="keyboard_picker_radius">28dp</dimen>
+    <dimen name="keyboard_picker_text_size">16sp</dimen>
+
     <!-- RemoteAuth-->
     <dimen name="remoteauth_fragment_padding_horizontal">40dp</dimen>
     <dimen name="remoteauth_fragment_subtitle_text_size">14sp</dimen>
diff --git a/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java b/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java
index f583971..85ba5fb 100644
--- a/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java
+++ b/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java
@@ -26,10 +26,14 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.FrameLayout;
 import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
 
 import androidx.fragment.app.Fragment;
 
+import com.android.hardware.input.Flags;
 import com.android.settings.R;
 
 //TODO: b/316243168 - [Physical Keyboard Setting] Refactor NewKeyboardLayoutPickerFragment
@@ -38,19 +42,25 @@
     private static final int DEFAULT_KEYBOARD_PREVIEW_HEIGHT = 540;
 
     private ImageView mKeyboardLayoutPreview;
+    private TextView mKeyboardLayoutPreviewText;
     private InputManager mInputManager;
     private final NewKeyboardLayoutPickerController.KeyboardLayoutSelectedCallback
             mKeyboardLayoutSelectedCallback =
             new NewKeyboardLayoutPickerController.KeyboardLayoutSelectedCallback() {
                 @Override
                 public void onSelected(KeyboardLayout keyboardLayout) {
-                    if (mInputManager != null && mKeyboardLayoutPreview != null) {
+                    if (mInputManager != null
+                            && mKeyboardLayoutPreview != null
+                            && mKeyboardLayoutPreviewText != null && keyboardLayout != null) {
                         Drawable previewDrawable = mInputManager.getKeyboardLayoutPreview(
                                 keyboardLayout,
                                 DEFAULT_KEYBOARD_PREVIEW_WIDTH, DEFAULT_KEYBOARD_PREVIEW_HEIGHT);
                         mKeyboardLayoutPreview.setVisibility(
                                 previewDrawable == null ? GONE : VISIBLE);
+                        mKeyboardLayoutPreviewText.setVisibility(
+                                previewDrawable == null ? GONE : VISIBLE);
                         if (previewDrawable != null) {
+                            mKeyboardLayoutPreviewText.setText(keyboardLayout.getLabel());
                             mKeyboardLayoutPreview.setImageDrawable(previewDrawable);
                         }
                     }
@@ -73,6 +83,10 @@
         ViewGroup fragmentView = (ViewGroup) inflater.inflate(
                 R.layout.keyboard_layout_picker, container, false);
         mKeyboardLayoutPreview = fragmentView.findViewById(R.id.keyboard_layout_preview);
+        mKeyboardLayoutPreviewText = fragmentView.findViewById(R.id.keyboard_layout_preview_name);
+        if (!Flags.keyboardLayoutPreviewFlag()) {
+            updateViewMarginForPreviewFlagOff(fragmentView);
+        }
         getActivity().getSupportFragmentManager()
                 .beginTransaction()
                 .replace(R.id.keyboard_layout_title, new NewKeyboardLayoutPickerTitle())
@@ -87,4 +101,13 @@
                 .commit();
         return fragmentView;
     }
+
+    private void updateViewMarginForPreviewFlagOff(ViewGroup fragmentView) {
+        LinearLayout previewContainer = fragmentView.findViewById(
+                R.id.keyboard_layout_picker_container);
+        FrameLayout.LayoutParams previewContainerLayoutParams =
+                (FrameLayout.LayoutParams) previewContainer.getLayoutParams();
+        previewContainerLayoutParams.setMargins(0, 0, 0, 0);
+        previewContainer.setLayoutParams(previewContainerLayoutParams);
+    }
 }