diff options
| author | 2024-02-15 22:35:21 +0000 | |
|---|---|---|
| committer | 2024-03-13 21:12:31 +0000 | |
| commit | 3ff637f75f5ff1c9cb38f63b7c83db024b6ed2ac (patch) | |
| tree | f569342f933dfeaae6c61c9d1633cc5c8b678660 | |
| parent | dacd60d48a75408035aafff476b7ad435159ebfe (diff) | |
Updating IllustrationPreference to support content description and accessibility
Bug: 319747547
Test: Built and tested locally with additional CLs in topic
Flag: none
Change-Id: I33cbaa024d6ff110616aad2efa08be93941c08e0
2 files changed, 22 insertions, 4 deletions
diff --git a/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml b/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml index 685e2595119a..0ae9c2674bc7 100644 --- a/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml +++ b/packages/SettingsLib/IllustrationPreference/res/layout/illustration_preference.xml @@ -19,7 +19,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="match_parent" - android:importantForAccessibility="noHideDescendants" + android:importantForAccessibility="no" android:gravity="center" android:orientation="horizontal"> 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 f4d4dbadb37f..5947ef635be1 100644 --- a/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java +++ b/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java @@ -24,6 +24,7 @@ import android.graphics.drawable.Animatable2; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; import android.view.View; @@ -37,12 +38,13 @@ import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; import androidx.vectordrawable.graphics.drawable.Animatable2Compat; +import com.android.settingslib.widget.preference.illustration.R; + import com.airbnb.lottie.LottieAnimationView; import com.airbnb.lottie.LottieDrawable; import java.io.FileNotFoundException; import java.io.InputStream; -import com.android.settingslib.widget.preference.illustration.R; /** * IllustrationPreference is a preference that can play lottie format animation @@ -62,8 +64,8 @@ public class IllustrationPreference extends Preference { private Drawable mImageDrawable; private View mMiddleGroundView; private OnBindListener mOnBindListener; - private boolean mLottieDynamicColor; + private CharSequence mContentDescription; /** * Interface to listen in on when {@link #onBindViewHolder(PreferenceViewHolder)} occurs. @@ -123,7 +125,10 @@ public class IllustrationPreference extends Preference { (FrameLayout) holder.findViewById(R.id.middleground_layout); final LottieAnimationView illustrationView = (LottieAnimationView) holder.findViewById(R.id.lottie_view); - + if (illustrationView != null && !TextUtils.isEmpty(mContentDescription)) { + illustrationView.setContentDescription(mContentDescription); + illustrationView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); + } // 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. @@ -208,6 +213,19 @@ public class IllustrationPreference extends Preference { } /** + * To set content description of the {@link Illustration Preference}. This can use for talkback + * environment if developer wants to have a customization content. + * + * @param contentDescription The resource id of the content description. + */ + public void setContentDescription(CharSequence contentDescription) { + if (!TextUtils.equals(mContentDescription, contentDescription)) { + mContentDescription = contentDescription; + notifyChanged(); + } + } + + /** * Gets the lottie illustration resource id. */ public int getLottieAnimationResId() { |