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

Commit 1bf86e7f authored by Randy Pfohl's avatar Randy Pfohl Committed by Android (Google) Code Review
Browse files

Merge changes from topic "AccessibilitySupport" into main

* changes:
  adding in a method to set content description based on string resource id
  Updating IllustrationPreference to support content description and accessibility
parents 56503897 2a6c849e
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">

+32 −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;
@@ -33,16 +34,18 @@ import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.annotation.RawRes;
import androidx.annotation.StringRes;
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 +65,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 +126,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 +213,29 @@ 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 CharSequence of the content description.
     */
    public void setContentDescription(CharSequence contentDescription) {
        if (!TextUtils.equals(mContentDescription, contentDescription)) {
            mContentDescription = contentDescription;
            notifyChanged();
        }
    }

    /**
     * To set content description of the {@link Illustration Preference}. This can use for talkback
     * environment if developer wants to have a customization content.
     *
     * @param contentDescriptionResId The resource id of the content description.
     */
    public void setContentDescription(@StringRes int contentDescriptionResId) {
        setContentDescription(getContext().getText(contentDescriptionResId));
    }

    /**
     * Gets the lottie illustration resource id.
     */