Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32521fd2 authored by Edgar Wang's avatar Edgar Wang Committed by Android (Google) Code Review
Browse files

Merge "[Expressive design] support large lottie size on tablet" into main

parents 7c580912 c3d30628
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
<?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>
+9 −0
Original line number Diff line number Diff line
@@ -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"
+3 −0
Original line number Diff line number Diff line
@@ -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>
+18 −2
Original line number Diff line number Diff line
@@ -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));
        }
    }
}
+22 −0
Original line number Diff line number Diff line
@@ -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
        }
    }
}
Loading