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

Commit ce63cde2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add content descriptions to the avatar picker."

parents 8dfa0b9f 735747fc
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -647,6 +647,11 @@
        <item>disabled</item>
    </array>

    <!-- Images offered as options in the avatar picker. If populated, the avatar_image_descriptions
         array must also be populated with a content description for each image. -->
    <array name="avatar_images"/>

    <!-- Content descriptions for each of the images in the avatar_images array. -->
    <string-array name="avatar_image_descriptions"/>

</resources>
+4 −0
Original line number Diff line number Diff line
@@ -1562,4 +1562,8 @@

    <!-- Title for a screen allowing the user to choose a profile picture. [CHAR LIMIT=NONE] -->
    <string name="avatar_picker_title">Choose a profile picture</string>

    <!-- Content description for a default user icon. [CHAR LIMIT=NONE] -->
    <string name="default_user_icon_description">Default user icon</string>

</resources>
+26 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.google.android.setupdesign.GlifLayout;
import com.google.android.setupdesign.util.ThemeHelper;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
@@ -180,6 +181,7 @@ public class AvatarPickerActivity extends Activity {
        private final int mPreselectedImageStartPosition;

        private final List<Drawable> mImageDrawables;
        private final List<String> mImageDescriptions;
        private final TypedArray mPreselectedImages;
        private final int[] mUserIconColors;
        private int mSelectedPosition = NONE;
@@ -196,6 +198,7 @@ public class AvatarPickerActivity extends Activity {
            mPreselectedImages = getResources().obtainTypedArray(R.array.avatar_images);
            mUserIconColors = UserIcons.getUserIconColors(getResources());
            mImageDrawables = buildDrawableList();
            mImageDescriptions = buildDescriptionsList();
        }

        @NonNull
@@ -210,15 +213,24 @@ public class AvatarPickerActivity extends Activity {
        public void onBindViewHolder(@NonNull AvatarViewHolder viewHolder, int position) {
            if (position == mTakePhotoPosition) {
                viewHolder.setDrawable(getDrawable(R.drawable.avatar_take_photo_circled));
                viewHolder.setContentDescription(getString(R.string.user_image_take_photo));
                viewHolder.setClickListener(view -> mAvatarPhotoController.takePhoto());

            } else if (position == mChoosePhotoPosition) {
                viewHolder.setDrawable(getDrawable(R.drawable.avatar_choose_photo_circled));
                viewHolder.setContentDescription(getString(R.string.user_image_choose_photo));
                viewHolder.setClickListener(view -> mAvatarPhotoController.choosePhoto());

            } else if (position >= mPreselectedImageStartPosition) {
                int index = indexFromPosition(position);
                viewHolder.setSelected(position == mSelectedPosition);
                viewHolder.setDrawable(mImageDrawables.get(indexFromPosition(position)));
                viewHolder.setDrawable(mImageDrawables.get(index));
                if (mImageDescriptions != null) {
                    viewHolder.setContentDescription(mImageDescriptions.get(index));
                } else {
                    viewHolder.setContentDescription(
                            getString(R.string.default_user_icon_description));
                }
                viewHolder.setClickListener(view -> {
                    if (mSelectedPosition == position) {
                        deselect(position);
@@ -256,6 +268,15 @@ public class AvatarPickerActivity extends Activity {
            return result;
        }

        private List<String> buildDescriptionsList() {
            if (mPreselectedImages.length() > 0) {
                return Arrays.asList(
                        getResources().getStringArray(R.array.avatar_image_descriptions));
            }

            return null;
        }

        private Drawable circularDrawableFrom(BitmapDrawable drawable) {
            Bitmap bitmap = drawable.getBitmap();

@@ -323,6 +344,10 @@ public class AvatarPickerActivity extends Activity {
            mImageView.setImageDrawable(drawable);
        }

        public void setContentDescription(String desc) {
            mImageView.setContentDescription(desc);
        }

        public void setClickListener(View.OnClickListener listener) {
            mImageView.setOnClickListener(listener);
        }