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

Commit 5f47d30f authored by Edgar Wang's avatar Edgar Wang
Browse files

Add new attribute to support lottie dynamic color

Bug: 243889662
Test: manual
Change-Id: Iba35e69ec18d8582358e16069e86f060797ad1bf
parent e37a7d5e
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
<?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.
-->

<resources>
    <declare-styleable name="IllustrationPreference">
        <attr name="dynamicColor" format="boolean" />
    </declare-styleable>
</resources>
 No newline at end of file
+28 −1
Original line number Diff line number Diff line
@@ -61,6 +61,8 @@ public class IllustrationPreference extends Preference {
    private View mMiddleGroundView;
    private OnBindListener mOnBindListener;

    private boolean mLottieDynamicColor;

    /**
     * Interface to listen in on when {@link #onBindViewHolder(PreferenceViewHolder)} occurs.
     */
@@ -146,6 +148,10 @@ public class IllustrationPreference extends Preference {
            ColorUtils.applyDynamicColors(getContext(), illustrationView);
        }

        if (mLottieDynamicColor) {
            LottieColorUtils.applyDynamicColors(getContext(), illustrationView);
        }

        if (mOnBindListener != null) {
            mOnBindListener.onBind(illustrationView);
        }
@@ -262,6 +268,21 @@ public class IllustrationPreference extends Preference {
        }
    }

    /**
     * Sets the lottie illustration apply dynamic color.
     */
    public void applyDynamicColor() {
        mLottieDynamicColor = true;
        notifyChanged();
    }

    /**
     * Return if the lottie illustration apply dynamic color or not.
     */
    public boolean isApplyDynamicColor() {
        return mLottieDynamicColor;
    }

    private void resetImageResourceCache() {
        mImageDrawable = null;
        mImageUri = null;
@@ -403,9 +424,15 @@ public class IllustrationPreference extends Preference {

        mIsAutoScale = false;
        if (attrs != null) {
            final TypedArray a = context.obtainStyledAttributes(attrs,
            TypedArray a = context.obtainStyledAttributes(attrs,
                    R.styleable.LottieAnimationView, 0 /*defStyleAttr*/, 0 /*defStyleRes*/);
            mImageResId = a.getResourceId(R.styleable.LottieAnimationView_lottie_rawRes, 0);

            a = context.obtainStyledAttributes(attrs,
                    R.styleable.IllustrationPreference, 0 /*defStyleAttr*/, 0 /*defStyleRes*/);
            mLottieDynamicColor = a.getBoolean(R.styleable.IllustrationPreference_dynamicColor,
                    false);

            a.recycle();
        }
    }
+16 −0
Original line number Diff line number Diff line
@@ -215,4 +215,20 @@ public class IllustrationPreferenceTest {

        assertThat(mOnBindListenerAnimationView).isNull();
    }

    @Test
    public void onBindViewHolder_default_shouldNotApplyDynamicColor() {
        mPreference.onBindViewHolder(mViewHolder);

        assertThat(mPreference.isApplyDynamicColor()).isFalse();
    }

    @Test
    public void onBindViewHolder_applyDynamicColor_shouldReturnTrue() {
        mPreference.applyDynamicColor();

        mPreference.onBindViewHolder(mViewHolder);

        assertThat(mPreference.isApplyDynamicColor()).isTrue();
    }
}