From 4f59c38d83223d8c9f851425cd99213040324925 Mon Sep 17 00:00:00 2001 From: Stanley Wang Date: Tue, 15 Jun 2021 20:37:27 +0800 Subject: [PATCH] Update the IllustrationPreference of SettingsLib. - Adjust the frame size of the LottieView. We set the frame height to 300dp and set the length of the short side of the screen to the width of the frame. In this way, LottieView has a fixed size to solve the problem of incorrect illustration spec. - Set the importantForAccessibility value to noHideDescendants to avoid the a11y issue. Bug: 190807662 Test: robotest and see the UI. Change-Id: Ib48f9c65e0dfbf36b7ebb70718fa5423c918a7a9 --- .../res/layout/illustration_preference.xml | 39 ++++++++++--------- .../widget/IllustrationPreference.java | 20 ++++++++++ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml b/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml index 3f8439c2db47c..efcd41c2778bc 100644 --- a/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml +++ b/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml @@ -20,35 +20,38 @@ android:layout_height="wrap_content" android:layout_width="match_parent" android:background="?android:attr/colorBackground" + android:importantForAccessibility="noHideDescendants" android:gravity="center" android:orientation="horizontal"> - + + + - + android:layout_gravity="center" /> + + + - diff --git a/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java b/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java index 8e6c5799da676..e91dd94c715df 100644 --- a/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java +++ b/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java @@ -21,6 +21,7 @@ import android.content.res.TypedArray; import android.util.AttributeSet; import android.util.Log; import android.view.View; +import android.view.ViewGroup.LayoutParams; import android.widget.FrameLayout; import android.widget.ImageView; @@ -68,6 +69,18 @@ public class IllustrationPreference extends Preference { Log.w(TAG, "Invalid illustration resource id."); return; } + + // To solve the problem of non-compliant illustrations, we set the frame height + // to 300dp and set the length of the short side of the screen to + // the width of the frame. + final int screenWidth = getContext().getResources().getDisplayMetrics().widthPixels; + final int screenHeight = getContext().getResources().getDisplayMetrics().heightPixels; + final FrameLayout illustrationFrame = (FrameLayout) holder.findViewById( + R.id.illustration_frame); + final LayoutParams lp = (LayoutParams) illustrationFrame.getLayoutParams(); + lp.width = screenWidth < screenHeight ? screenWidth : screenHeight; + illustrationFrame.setLayoutParams(lp); + mMiddleGroundLayout = (FrameLayout) holder.findViewById(R.id.middleground_layout); mIllustrationView = (LottieAnimationView) holder.findViewById(R.id.lottie_view); mIllustrationView.setAnimation(mAnimationId); @@ -124,6 +137,13 @@ public class IllustrationPreference extends Preference { mIsAutoScale ? ImageView.ScaleType.CENTER_CROP : ImageView.ScaleType.CENTER_INSIDE); } + /** + * Set the lottie illustration resource id. + */ + public void setLottieAnimationResId(int resId) { + mAnimationId = resId; + } + private void enableMiddleGroundView() { mMiddleGroundLayout.removeAllViews(); mMiddleGroundLayout.addView(mMiddleGroundView);