diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-13 01:32:10 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-13 01:32:10 +0000 |
commit | a2330bcc4a26130b9d2b44a377c026d8f566698c (patch) | |
tree | e76ffe4c398686600f5370565d5b0c785e3d9b02 | |
parent | 4286e767878938fa73796e0c71e303491d58ec6a (diff) | |
parent | b04a6e0072dc9a597587dd2e0ac1c1ef8d0d73b0 (diff) | |
download | systemlibs-android14-platform-release.tar.gz |
Snap for 10127524 from b04a6e0072dc9a597587dd2e0ac1c1ef8d0d73b0 to udc-releaseandroid-vts-14.0_r4android-vts-14.0_r3android-vts-14.0_r2android-vts-14.0_r1android-security-14.0.0_r8android-security-14.0.0_r7android-security-14.0.0_r6android-security-14.0.0_r5android-security-14.0.0_r4android-security-14.0.0_r3android-security-14.0.0_r2android-security-14.0.0_r1android-platform-14.0.0_r7android-platform-14.0.0_r6android-platform-14.0.0_r5android-platform-14.0.0_r4android-platform-14.0.0_r3android-platform-14.0.0_r2android-platform-14.0.0_r1android-cts-14.0_r4android-cts-14.0_r3android-cts-14.0_r2android-cts-14.0_r1android-14.0.0_r28android-14.0.0_r2android-14.0.0_r15android-14.0.0_r14android-14.0.0_r13android-14.0.0_r1android14-tests-releaseandroid14-security-releaseandroid14-s2-releaseandroid14-s1-releaseandroid14-releaseandroid14-platform-release
Change-Id: I5942dba26421c09cd8f2f0aac2a1f7a6e7226cfa
3 files changed, 55 insertions, 10 deletions
diff --git a/car-qc-lib/src/com/android/car/qc/QCActionItem.java b/car-qc-lib/src/com/android/car/qc/QCActionItem.java index c476e09..b7b9cd1 100644 --- a/car-qc-lib/src/com/android/car/qc/QCActionItem.java +++ b/car-qc-lib/src/com/android/car/qc/QCActionItem.java @@ -17,11 +17,13 @@ package com.android.car.qc; import android.app.PendingIntent; +import android.content.Context; import android.graphics.drawable.Icon; import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.StringRes; /** * Quick Control Action that are includes as either start or end actions in {@link QCRow} @@ -32,14 +34,17 @@ public class QCActionItem extends QCItem { private Icon mIcon; private PendingIntent mAction; private PendingIntent mDisabledClickAction; + private String mContentDescription; public QCActionItem(@NonNull @QCItemType String type, boolean isChecked, boolean isEnabled, boolean isAvailable, boolean isClickableWhileDisabled, @Nullable Icon icon, - @Nullable PendingIntent action, @Nullable PendingIntent disabledClickAction) { + @Nullable String contentDescription, @Nullable PendingIntent action, + @Nullable PendingIntent disabledClickAction) { super(type, isEnabled, isClickableWhileDisabled); mIsChecked = isChecked; mIsAvailable = isAvailable; mIcon = icon; + mContentDescription = contentDescription; mAction = action; mDisabledClickAction = disabledClickAction; } @@ -52,6 +57,10 @@ public class QCActionItem extends QCItem { if (hasIcon) { mIcon = Icon.CREATOR.createFromParcel(in); } + boolean hasContentDescription = in.readBoolean(); + if (hasContentDescription) { + mContentDescription = in.readString(); + } boolean hasAction = in.readBoolean(); if (hasAction) { mAction = PendingIntent.CREATOR.createFromParcel(in); @@ -72,6 +81,11 @@ public class QCActionItem extends QCItem { if (includeIcon) { mIcon.writeToParcel(dest, flags); } + boolean hasContentDescription = mContentDescription != null; + dest.writeBoolean(hasContentDescription); + if (hasContentDescription) { + dest.writeString(mContentDescription); + } boolean hasAction = mAction != null; dest.writeBoolean(hasAction); if (hasAction) { @@ -107,6 +121,11 @@ public class QCActionItem extends QCItem { return mIcon; } + @Nullable + public String getContentDescription() { + return mContentDescription; + } + public static Creator<QCActionItem> CREATOR = new Creator<QCActionItem>() { @Override public QCActionItem createFromParcel(Parcel source) { @@ -131,6 +150,7 @@ public class QCActionItem extends QCItem { private Icon mIcon; private PendingIntent mAction; private PendingIntent mDisabledClickAction; + private String mContentDescription; public Builder(@NonNull @QCItemType String type) { if (!isValidType(type)) { @@ -180,6 +200,23 @@ public class QCActionItem extends QCItem { } /** + * Sets the content description + */ + public Builder setContentDescription(@Nullable String contentDescription) { + mContentDescription = contentDescription; + return this; + } + + /** + * Sets the string resource to use for content description + */ + public Builder setContentDescription(@NonNull Context context, + @StringRes int contentDescriptionResId) { + mContentDescription = context.getString(contentDescriptionResId); + return this; + } + + /** * Sets the PendingIntent to be sent when the action item is clicked. */ public Builder setAction(@Nullable PendingIntent action) { @@ -200,7 +237,8 @@ public class QCActionItem extends QCItem { */ public QCActionItem build() { return new QCActionItem(mType, mIsChecked, mIsEnabled, mIsAvailable, - mIsClickableWhileDisabled, mIcon, mAction, mDisabledClickAction); + mIsClickableWhileDisabled, mIcon, mContentDescription, mAction, + mDisabledClickAction); } private boolean isValidType(String type) { diff --git a/car-qc-lib/src/com/android/car/qc/view/QCRowView.java b/car-qc-lib/src/com/android/car/qc/view/QCRowView.java index c374602..2b6b7a5 100644 --- a/car-qc-lib/src/com/android/car/qc/view/QCRowView.java +++ b/car-qc-lib/src/com/android/car/qc/view/QCRowView.java @@ -314,6 +314,7 @@ public class QCRowView extends FrameLayout { switchView.setThumbTintList(getContext().getColorStateList( R.color.qc_switch_thumb_selector)); switchView.setChecked(action.isChecked()); + switchView.setContentDescription(action.getContentDescription()); switchView.setOnTouchListener((v, event) -> { if (!action.isEnabled()) { if (event.getActionMasked() == MotionEvent.ACTION_UP) { @@ -347,6 +348,7 @@ public class QCRowView extends FrameLayout { toggleButton.setOnCheckedChangeListener(null); Drawable icon = QCViewUtils.getInstance(mContext).getToggleIcon( action.getIcon(), action.isAvailable()); + toggleButton.setContentDescription(action.getContentDescription()); toggleButton.setButtonDrawable(icon); toggleButton.setChecked(action.isChecked()); toggleButton.setEnabled(shouldEnableView); diff --git a/car-qc-lib/tests/unit/src/com/android/car/qc/QCActionItemTest.java b/car-qc-lib/tests/unit/src/com/android/car/qc/QCActionItemTest.java index ff70540..c945301 100644 --- a/car-qc-lib/tests/unit/src/com/android/car/qc/QCActionItemTest.java +++ b/car-qc-lib/tests/unit/src/com/android/car/qc/QCActionItemTest.java @@ -33,32 +33,34 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public class QCActionItemTest extends QCItemTestCase<QCActionItem> { + private static final String TEST_CONTENT_DESCRIPTION = "test_content_description"; @Test public void onCreate_invalidType_throwsException() { assertThrows(IllegalArgumentException.class, () -> createAction("INVALID_TYPE", /* action= */ null, - /* disabledAction= */ null, /* icon= */ null)); + /* disabledAction= */ null, /* icon= */ null, /* contentDescription=*/ + null)); } @Test public void onCreateSwitch_hasCorrectType() { QCActionItem action = createAction(QC_TYPE_ACTION_SWITCH, /* action= */ null, - /* disabledAction= */ null, /* icon= */null); + /* disabledAction= */ null, /* icon= */null, /* contentDescription=*/ null); assertThat(action.getType()).isEqualTo(QC_TYPE_ACTION_SWITCH); } @Test public void onCreateToggle_hasCorrectType() { QCActionItem action = createAction(QC_TYPE_ACTION_TOGGLE, /* action= */ null, - /* disabledAction= */ null, /* icon= */ null); + /* disabledAction= */ null, /* icon= */ null, /* contentDescription=*/ null); assertThat(action.getType()).isEqualTo(QC_TYPE_ACTION_TOGGLE); } @Test public void onBundle_nullActions_noCrash() { QCActionItem action = createAction(QC_TYPE_ACTION_TOGGLE, /* action= */ null, - /* disabledAction= */ null, mDefaultIcon); + /* disabledAction= */ null, mDefaultIcon, /* contentDescription=*/ null); writeAndLoadFromBundle(action); // Test passes if this doesn't crash } @@ -66,7 +68,7 @@ public class QCActionItemTest extends QCItemTestCase<QCActionItem> { @Test public void onBundle_nullIcon_noCrash() { QCActionItem action = createAction(QC_TYPE_ACTION_TOGGLE, mDefaultAction, - mDefaultDisabledAction, /* icon= */ null); + mDefaultDisabledAction, /* icon= */ null, /* contentDescription=*/ null); writeAndLoadFromBundle(action); // Test passes if this doesn't crash } @@ -74,7 +76,7 @@ public class QCActionItemTest extends QCItemTestCase<QCActionItem> { @Test public void onBundle_switch_accurateData() { QCActionItem action = createAction(QC_TYPE_ACTION_SWITCH, mDefaultAction, - mDefaultDisabledAction, /* icon= */ null); + mDefaultDisabledAction, /* icon= */ null, TEST_CONTENT_DESCRIPTION); QCActionItem newAction = writeAndLoadFromBundle(action); assertThat(newAction.getType()).isEqualTo(QC_TYPE_ACTION_SWITCH); assertThat(newAction.isChecked()).isTrue(); @@ -82,12 +84,13 @@ public class QCActionItemTest extends QCItemTestCase<QCActionItem> { assertThat(newAction.isClickableWhileDisabled()).isFalse(); assertThat(newAction.getPrimaryAction()).isNotNull(); assertThat(newAction.getIcon()).isNull(); + assertThat(newAction.getContentDescription()).isEqualTo(TEST_CONTENT_DESCRIPTION); } @Test public void onBundle_toggle_accurateDate() { QCActionItem action = createAction(QC_TYPE_ACTION_TOGGLE, mDefaultAction, - mDefaultDisabledAction, mDefaultIcon); + mDefaultDisabledAction, mDefaultIcon, TEST_CONTENT_DESCRIPTION); QCActionItem newAction = writeAndLoadFromBundle(action); assertThat(newAction.getType()).isEqualTo(QC_TYPE_ACTION_TOGGLE); assertThat(newAction.isChecked()).isTrue(); @@ -95,16 +98,18 @@ public class QCActionItemTest extends QCItemTestCase<QCActionItem> { assertThat(newAction.isClickableWhileDisabled()).isFalse(); assertThat(newAction.getPrimaryAction()).isNotNull(); assertThat(newAction.getIcon()).isNotNull(); + assertThat(newAction.getContentDescription()).isEqualTo(TEST_CONTENT_DESCRIPTION); } private QCActionItem createAction(String type, PendingIntent action, - PendingIntent disabledAction, Icon icon) { + PendingIntent disabledAction, Icon icon, String contentDescription) { return new QCActionItem.Builder(type) .setChecked(true) .setEnabled(true) .setAction(action) .setDisabledClickAction(disabledAction) .setIcon(icon) + .setContentDescription(contentDescription) .build(); } } |