From eb932b22a0a8be0a8a0830dec891a0013900aa0b Mon Sep 17 00:00:00 2001 From: Alex Stetson Date: Tue, 14 Nov 2023 15:50:25 -0800 Subject: Add clickable option to QC Add additional configuration option to set an action item as not clickable, which prevents click actions without affecting the visual state of the toggle. Bug: 260762437 Test: manual Change-Id: Ifc278848651a8b80b6163e7a44f6e145dc313d2d --- .../src/com/android/car/qc/QCActionItem.java | 26 ++++++++++++++++++---- .../src/com/android/car/qc/view/QCRowView.java | 6 +++-- 2 files changed, 26 insertions(+), 6 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 b7b9cd1..f4e92d1 100644 --- a/car-qc-lib/src/com/android/car/qc/QCActionItem.java +++ b/car-qc-lib/src/com/android/car/qc/QCActionItem.java @@ -31,18 +31,20 @@ import androidx.annotation.StringRes; public class QCActionItem extends QCItem { private final boolean mIsChecked; private final boolean mIsAvailable; + private final boolean mIsClickable; 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 String contentDescription, @Nullable PendingIntent action, - @Nullable PendingIntent disabledClickAction) { + boolean isAvailable, boolean isClickable, boolean isClickableWhileDisabled, + @Nullable Icon icon, @Nullable String contentDescription, + @Nullable PendingIntent action, @Nullable PendingIntent disabledClickAction) { super(type, isEnabled, isClickableWhileDisabled); mIsChecked = isChecked; mIsAvailable = isAvailable; + mIsClickable = isClickable; mIcon = icon; mContentDescription = contentDescription; mAction = action; @@ -53,6 +55,7 @@ public class QCActionItem extends QCItem { super(in); mIsChecked = in.readBoolean(); mIsAvailable = in.readBoolean(); + mIsClickable = in.readBoolean(); boolean hasIcon = in.readBoolean(); if (hasIcon) { mIcon = Icon.CREATOR.createFromParcel(in); @@ -76,6 +79,7 @@ public class QCActionItem extends QCItem { super.writeToParcel(dest, flags); dest.writeBoolean(mIsChecked); dest.writeBoolean(mIsAvailable); + dest.writeBoolean(mIsClickable); boolean includeIcon = getType().equals(QC_TYPE_ACTION_TOGGLE) && mIcon != null; dest.writeBoolean(includeIcon); if (includeIcon) { @@ -116,6 +120,10 @@ public class QCActionItem extends QCItem { return mIsAvailable; } + public boolean isClickable() { + return mIsClickable; + } + @Nullable public Icon getIcon() { return mIcon; @@ -146,6 +154,7 @@ public class QCActionItem extends QCItem { private boolean mIsChecked; private boolean mIsEnabled = true; private boolean mIsAvailable = true; + private boolean mIsClickable = true; private boolean mIsClickableWhileDisabled = false; private Icon mIcon; private PendingIntent mAction; @@ -183,6 +192,15 @@ public class QCActionItem extends QCItem { return this; } + /** + * Sets whether the action is clickable. This differs from available in that the style will + * remain as if it's enabled/available but click actions will not be processed. + */ + public Builder setClickable(boolean clickable) { + mIsClickable = clickable; + return this; + } + /** * Sets whether or not an action item should be clickable while disabled. */ @@ -236,7 +254,7 @@ public class QCActionItem extends QCItem { * Builds the final {@link QCActionItem}. */ public QCActionItem build() { - return new QCActionItem(mType, mIsChecked, mIsEnabled, mIsAvailable, + return new QCActionItem(mType, mIsChecked, mIsEnabled, mIsAvailable, mIsClickable, mIsClickableWhileDisabled, mIcon, mContentDescription, mAction, mDisabledClickAction); } 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 06a5fe2..2045fd2 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 @@ -308,7 +308,8 @@ public class QCRowView extends FrameLayout { CarUiUtils.makeAllViewsEnabled(switchView, action.isEnabled()); boolean shouldEnableView = - (action.isEnabled() || action.isClickableWhileDisabled()) && action.isAvailable(); + (action.isEnabled() || action.isClickableWhileDisabled()) && action.isAvailable() + && action.isClickable(); switchView.setOnCheckedChangeListener(null); switchView.setEnabled(shouldEnableView); switchView.setChecked(action.isChecked()); @@ -339,7 +340,8 @@ public class QCRowView extends FrameLayout { } DrawableStateToggleButton toggleButton = tmpToggleButton; // must be effectively final boolean shouldEnableView = - (action.isEnabled() || action.isClickableWhileDisabled()) && action.isAvailable(); + (action.isEnabled() || action.isClickableWhileDisabled()) && action.isAvailable() + && action.isClickable(); toggleButton.setText(null); toggleButton.setTextOn(null); toggleButton.setTextOff(null); -- cgit v1.2.3