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

Commit 3ff637f7 authored by Randy Pfohl's avatar Randy Pfohl
Browse files

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
parent dacd60d4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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">

+21 −3
Original line number Diff line number Diff line
@@ -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.
@@ -207,6 +212,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.
     */