diff options
6 files changed, 81 insertions, 4 deletions
diff --git a/packages/SettingsLib/IllustrationPreference/res/drawable/protection_background_tablet.xml b/packages/SettingsLib/IllustrationPreference/res/drawable/protection_background_tablet.xml new file mode 100644 index 000000000000..31714b7ff902 --- /dev/null +++ b/packages/SettingsLib/IllustrationPreference/res/drawable/protection_background_tablet.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2025 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. +--> + +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> + <item> + <shape android:shape="rectangle"> + <solid android:color="@color/settingslib_protection_color"/> + <corners android:radius="28dp"/> + <size android:width="@dimen/settingslib_illustration_width_tablet" + android:height="@dimen/settingslib_illustration_height_tablet"/> + </shape> + </item> +</layer-list> diff --git a/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml b/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml index 0ae9c2674bc7..fcc2a04201dd 100644 --- a/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml +++ b/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml @@ -40,6 +40,15 @@ android:adjustViewBounds="true" android:src="@drawable/protection_background"/> + <ImageView + android:id="@+id/background_view_tablet" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:adjustViewBounds="true" + android:src="@drawable/protection_background_tablet" + android:visibility="gone"/> + <com.airbnb.lottie.LottieAnimationView android:id="@+id/lottie_view" android:layout_width="wrap_content" diff --git a/packages/SettingsLib/IllustrationPreference/res/values/dimens.xml b/packages/SettingsLib/IllustrationPreference/res/values/dimens.xml index fc273dc7403b..7b5012efd783 100644 --- a/packages/SettingsLib/IllustrationPreference/res/values/dimens.xml +++ b/packages/SettingsLib/IllustrationPreference/res/values/dimens.xml @@ -21,4 +21,7 @@ <dimen name="settingslib_illustration_width">412dp</dimen> <dimen name="settingslib_illustration_height">300dp</dimen> + + <dimen name="settingslib_illustration_width_tablet">498dp</dimen> + <dimen name="settingslib_illustration_height_tablet">362dp</dimen> </resources> 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 bc4f1f942dc0..4b407c50bbd5 100644 --- a/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java +++ b/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java @@ -72,6 +72,7 @@ public class IllustrationPreference extends Preference implements GroupSectionDi private OnBindListener mOnBindListener; private boolean mLottieDynamicColor; private CharSequence mContentDescription; + private boolean mIsTablet; /** * Interface to listen in on when {@link #onBindViewHolder(PreferenceViewHolder)} occurs. @@ -127,8 +128,17 @@ public class IllustrationPreference extends Preference implements GroupSectionDi final FrameLayout illustrationFrame = (FrameLayout) holder.findViewById( R.id.illustration_frame); - final ImageView backgroundView = + ImageView backgroundView = (ImageView) holder.findViewById(R.id.background_view); + ImageView backgroundViewTablet = + (ImageView) holder.findViewById(R.id.background_view_tablet); + + backgroundView.setVisibility(mIsTablet ? View.GONE : View.VISIBLE); + backgroundViewTablet.setVisibility(mIsTablet ? View.VISIBLE : View.GONE); + if (mIsTablet) { + backgroundView = backgroundViewTablet; + } + final FrameLayout middleGroundLayout = (FrameLayout) holder.findViewById(R.id.middleground_layout); final LottieAnimationView illustrationView = @@ -413,7 +423,7 @@ public class IllustrationPreference extends Preference implements GroupSectionDi final Resources res = backgroundView.getResources(); final int frameWidth = res.getDimensionPixelSize(R.dimen.settingslib_illustration_width); final int frameHeight = res.getDimensionPixelSize(R.dimen.settingslib_illustration_height); - final int restrictedMaxHeight = Math.min(mMaxHeight, frameHeight); + final int restrictedMaxHeight = mMaxHeight; backgroundView.setMaxHeight(restrictedMaxHeight); illustrationView.setMaxHeight(restrictedMaxHeight); @@ -505,5 +515,11 @@ public class IllustrationPreference extends Preference implements GroupSectionDi a.recycle(); } + mIsTablet = SettingsThemeHelper.isExpressiveTheme(context) + && SettingsThemeHelper.isTablet(context); + if (mIsTablet) { + setMaxHeight(context.getResources().getDimensionPixelSize( + R.dimen.settingslib_illustration_height_tablet)); + } } } diff --git a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsThemeHelper.kt b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsThemeHelper.kt index 74f5441f6760..6794cd0e30a2 100644 --- a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsThemeHelper.kt +++ b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsThemeHelper.kt @@ -21,6 +21,7 @@ import android.os.Build object SettingsThemeHelper { private const val IS_EXPRESSIVE_DESIGN_ENABLED = "is_expressive_design_enabled" + private const val RO_BUILD_CHARACTERISTICS = "ro.build.characteristics" private var expressiveThemeState: ExpressiveThemeState = ExpressiveThemeState.UNKNOWN enum class ExpressiveThemeState { @@ -41,6 +42,12 @@ object SettingsThemeHelper { return expressiveThemeState == ExpressiveThemeState.ENABLED } + @JvmStatic + fun isTablet(context: Context): Boolean { + val result = getPropString(context, RO_BUILD_CHARACTERISTICS, "").split(',') + return result.contains("tablet") + } + private fun tryInit(context: Context) { if (expressiveThemeState != ExpressiveThemeState.UNKNOWN) { return @@ -73,4 +80,19 @@ object SettingsThemeHelper { def } } + + private fun getPropString(context: Context, property: String, def: String): String { + return try { + val systemProperties = context.classLoader.loadClass("android.os.SystemProperties") + + val paramTypes = + arrayOf<Class<*>?>(String::class.java, String::class.java) + val get = systemProperties.getMethod("get", *paramTypes) + get.invoke(systemProperties, property, def) as String + } catch (iae: IllegalArgumentException) { + throw iae + } catch (exception: Exception) { + def + } + } } diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java index 3f3e1b280850..c8738ae0c8eb 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java @@ -251,8 +251,8 @@ public class IllustrationPreferenceTest { mPreference.setMaxHeight(maxHeight); mPreference.onBindViewHolder(mViewHolder); - assertThat(mBackgroundView.getMaxHeight()).isEqualTo(restrictedHeight); - assertThat(mAnimationView.getMaxHeight()).isEqualTo(restrictedHeight); + assertThat(mBackgroundView.getMaxHeight()).isEqualTo(maxHeight); + assertThat(mAnimationView.getMaxHeight()).isEqualTo(maxHeight); } @Test |