From 5446813ac58eb28f907495782f540f4091a5153a Mon Sep 17 00:00:00 2001 From: shaoweishen Date: Wed, 13 Dec 2023 08:56:32 +0000 Subject: [PATCH] [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 --- .../keyboard_review_layout_background.xml | 22 ++++++++++++++++ res/layout/keyboard_layout_picker.xml | 26 ++++++++++++++++--- res/values-land/dimens.xml | 3 +++ res/values/dimens.xml | 7 +++++ .../NewKeyboardLayoutPickerFragment.java | 25 +++++++++++++++++- 5 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 res/drawable/keyboard_review_layout_background.xml diff --git a/res/drawable/keyboard_review_layout_background.xml b/res/drawable/keyboard_review_layout_background.xml new file mode 100644 index 00000000000..7f93f80b57a --- /dev/null +++ b/res/drawable/keyboard_review_layout_background.xml @@ -0,0 +1,22 @@ + + + + + + + diff --git a/res/layout/keyboard_layout_picker.xml b/res/layout/keyboard_layout_picker.xml index b25c228bf34..5e62a2c0412 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"> - + android:background="@drawable/keyboard_review_layout_background"> + + + 24dp 24dp + + + 106dp diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 6c03955c1e4..3e0b8d93381 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -165,6 +165,13 @@ 1.0 0dp + + 68dp + 24dp + 16dp + 28dp + 16sp + 40dp 14sp diff --git a/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java b/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java index f583971cf67..85ba5fb3270 100644 --- a/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java +++ b/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java @@ -26,10 +26,14 @@ import android.os.Bundle; 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 @@ public class NewKeyboardLayoutPickerFragment extends Fragment { 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 @@ public class NewKeyboardLayoutPickerFragment extends Fragment { 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 @@ public class NewKeyboardLayoutPickerFragment extends Fragment { .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); + } }