Add content descriptions to the avatar picker.
This adds content descriptions for all the options in the avatar picker, including take a photo and choose a photo. An array is added so that content descriptions can be provided for preselected images. Bug: 215134398 Test: Manual, use picker with talkback enabled Change-Id: Ic317d0e8f841c31c2d4a14e1d037163d9a19a0c4
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -1551,4 +1551,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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user