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

Commit 7c9cdb5a authored by Edgar Wang's avatar Edgar Wang Committed by Automerger Merge Worker
Browse files

Merge "Add new attribute to support lottie dynamic color" into tm-qpr-dev am:...

Merge "Add new attribute to support lottie dynamic color" into tm-qpr-dev am: e02788c4 am: c72d15df

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21154778



Change-Id: Id627c3433ea03bcdbdb5ff59694e4a595100e687
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 72fcde1b c72d15df
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();
    }
}