Revert "Create radio button and checkbox action specific classes for CarUiContentListItem"
This reverts commit 6b2322aad181d310513619a6af898ac3d08d018a.
Reason for revert: Broken build b/149066575
Change-Id: I383a7cd04aec1d167ba8e7f6a507a892199a6cb9
diff --git a/car-ui-lib/src/com/android/car/ui/AlertDialogBuilder.java b/car-ui-lib/src/com/android/car/ui/AlertDialogBuilder.java
index 9b4d578..0cbda42 100644
--- a/car-ui-lib/src/com/android/car/ui/AlertDialogBuilder.java
+++ b/car-ui-lib/src/com/android/car/ui/AlertDialogBuilder.java
@@ -37,7 +37,6 @@
import androidx.annotation.StringRes;
import com.android.car.ui.recyclerview.CarUiListItemAdapter;
-import com.android.car.ui.recyclerview.CarUiRadioButtonListItemAdapter;
import com.android.car.ui.recyclerview.RecyclerViewToListAdapter;
/**
@@ -501,8 +500,7 @@
/**
* This was not supposed to be in the Chassis API because it allows custom views.
*
- * @deprecated Use {@link #setSingleChoiceItems(CarUiRadioButtonListItemAdapter,
- * DialogInterface.OnClickListener)} instead.
+ * @deprecated Use {@link #setAdapter(CarUiListItemAdapter)} instead.
*/
@Deprecated
public AlertDialogBuilder setSingleChoiceItems(ListAdapter adapter, int checkedItem,
@@ -512,24 +510,6 @@
}
/**
- * Set a list of items to be displayed in the dialog as the content, you will be notified of
- * the selected item via the supplied listener. The list will have a check mark displayed to
- * the right of the text for the checked item. Clicking on an item in the list will not
- * dismiss the dialog. Clicking on a button will dismiss the dialog.
- *
- * @param adapter The {@link CarUiRadioButtonListItemAdapter} to supply the list of items
- * @param listener notified when an item on the list is clicked. The dialog will not be
- * dismissed when an item is clicked. It will only be dismissed if clicked on a
- * button, if no buttons are supplied it's up to the user to dismiss the dialog.
- * @return This Builder object to allow for chaining of calls to set methods
- */
- public AlertDialogBuilder setSingleChoiceItems(CarUiRadioButtonListItemAdapter adapter,
- final DialogInterface.OnClickListener listener) {
- mBuilder.setAdapter(new RecyclerViewToListAdapter<>(adapter), listener);
- return this;
- }
-
- /**
* Sets a listener to be invoked when an item in the list is selected.
*
* @param listener the listener to be invoked
diff --git a/car-ui-lib/src/com/android/car/ui/preference/ListPreferenceFragment.java b/car-ui-lib/src/com/android/car/ui/preference/ListPreferenceFragment.java
index 2543fb5..a213a11 100644
--- a/car-ui-lib/src/com/android/car/ui/preference/ListPreferenceFragment.java
+++ b/car-ui-lib/src/com/android/car/ui/preference/ListPreferenceFragment.java
@@ -109,8 +109,8 @@
for (int i = 0; i < entries.length; i++) {
String entry = entries[i].toString();
- CarUiContentListItem item = new CarUiContentListItem(
- CarUiContentListItem.Action.RADIO_BUTTON);
+ CarUiContentListItem item = new CarUiContentListItem();
+ item.setAction(CarUiContentListItem.Action.RADIO_BUTTON);
item.setTitle(entry);
if (i == selectedEntryIndex) {
@@ -118,7 +118,7 @@
mSelectedItem = item;
}
- item.setOnCheckedChangeListener((listItem, isChecked) -> {
+ item.setOnCheckedChangedListener((listItem, isChecked) -> {
if (mSelectedItem != null) {
mSelectedItem.setChecked(false);
adapter.notifyItemChanged(listItems.indexOf(mSelectedItem));
diff --git a/car-ui-lib/src/com/android/car/ui/preference/MultiSelectListPreferenceFragment.java b/car-ui-lib/src/com/android/car/ui/preference/MultiSelectListPreferenceFragment.java
index c445142..e505708 100644
--- a/car-ui-lib/src/com/android/car/ui/preference/MultiSelectListPreferenceFragment.java
+++ b/car-ui-lib/src/com/android/car/ui/preference/MultiSelectListPreferenceFragment.java
@@ -114,11 +114,11 @@
for (int i = 0; i < entries.length; i++) {
String entry = entries[i].toString();
String entryValue = entryValues[i].toString();
- CarUiContentListItem item = new CarUiContentListItem(
- CarUiContentListItem.Action.CHECK_BOX);
+ CarUiContentListItem item = new CarUiContentListItem();
+ item.setAction(CarUiContentListItem.Action.CHECK_BOX);
item.setTitle(entry);
item.setChecked(selectedItems[i]);
- item.setOnCheckedChangeListener((listItem, isChecked) -> {
+ item.setOnCheckedChangedListener((listItem, isChecked) -> {
if (isChecked) {
mNewValues.add(entryValue);
} else {
diff --git a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiCheckBoxListItem.java b/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiCheckBoxListItem.java
deleted file mode 100644
index 76cbae0..0000000
--- a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiCheckBoxListItem.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.ui.recyclerview;
-
-/**
- * A {@link CarUiContentListItem} that is configured to have a check box action.
- */
-public class CarUiCheckBoxListItem extends CarUiContentListItem {
-
- public CarUiCheckBoxListItem() {
- super(Action.CHECK_BOX);
- }
-}
diff --git a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiContentListItem.java b/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiContentListItem.java
index 05c4bfc..ee4e490 100644
--- a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiContentListItem.java
+++ b/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiContentListItem.java
@@ -30,7 +30,7 @@
/**
* Callback to be invoked when the checked state of a list item changed.
*/
- public interface OnCheckedChangeListener {
+ public interface OnCheckedChangedListener {
/**
* Called when the checked state of a list item has changed.
*
@@ -86,8 +86,8 @@
*/
CHECK_BOX,
/**
- * For an action value of RADIO_BUTTON, a radio button is shown for the action element of
- * the list item.
+ * For an action value of CHECK_BOX, a radio button is shown for the action element of the
+ * list item.
*/
RADIO_BUTTON,
/**
@@ -106,12 +106,11 @@
private boolean mIsActionDividerVisible;
private boolean mIsChecked;
private OnClickListener mOnClickListener;
- private OnCheckedChangeListener mOnCheckedChangeListener;
+ private OnCheckedChangedListener mOnCheckedChangedListener;
private View.OnClickListener mSupplementalIconOnClickListener;
-
- public CarUiContentListItem(Action action) {
- mAction = action;
+ public CarUiContentListItem() {
+ mAction = Action.NONE;
mPrimaryIconType = IconType.STANDARD;
}
@@ -196,18 +195,10 @@
* @param checked the checked state for the item.
*/
public void setChecked(boolean checked) {
- if (checked == mIsChecked) {
- return;
- }
-
// Checked state can only be set when action type is checkbox, radio button or switch.
if (mAction == Action.CHECK_BOX || mAction == Action.SWITCH
|| mAction == Action.RADIO_BUTTON) {
mIsChecked = checked;
-
- if (mOnCheckedChangeListener != null) {
- mOnCheckedChangeListener.onCheckedChanged(this, mIsChecked);
- }
}
}
@@ -235,6 +226,22 @@
}
/**
+ * Sets the action type for the item.
+ *
+ * @param action the action type for the item.
+ */
+ public void setAction(Action action) {
+ mAction = action;
+
+ // Cannot have checked state be true when there action type is not checkbox, radio button or
+ // switch.
+ if (mAction != Action.CHECK_BOX && mAction != Action.SWITCH
+ && mAction != Action.RADIO_BUTTON) {
+ mIsChecked = false;
+ }
+ }
+
+ /**
* Returns the supplemental icon for the item.
*/
@Nullable
@@ -263,18 +270,16 @@
*/
public void setSupplementalIcon(@Nullable Drawable icon,
@Nullable View.OnClickListener listener) {
- if (mAction != Action.ICON) {
- throw new IllegalStateException(
- "Cannot set supplemental icon on list item that does not have an action of "
- + "type ICON");
- }
+ mAction = Action.ICON;
+
+ // Cannot have checked state when action type is {@code Action.ICON}.
+ mIsChecked = false;
mSupplementalIcon = icon;
mSupplementalIconOnClickListener = listener;
}
- @Nullable
- public View.OnClickListener getSupplementalIconOnClickListener() {
+ View.OnClickListener getSupplementalIconOnClickListener() {
return mSupplementalIconOnClickListener;
}
@@ -287,11 +292,8 @@
mOnClickListener = listener;
}
- /**
- * Returns the {@link OnClickListener} registered for this item.
- */
@Nullable
- public OnClickListener getOnClickListener() {
+ OnClickListener getOnClickListener() {
return mOnClickListener;
}
@@ -303,16 +305,13 @@
*
* @param listener callback to be invoked when the checked state shown in the UI changes.
*/
- public void setOnCheckedChangeListener(
- @Nullable OnCheckedChangeListener listener) {
- mOnCheckedChangeListener = listener;
+ public void setOnCheckedChangedListener(
+ @Nullable OnCheckedChangedListener listener) {
+ mOnCheckedChangedListener = listener;
}
- /**
- * Returns the {@link OnCheckedChangeListener} registered for this item.
- */
@Nullable
- public OnCheckedChangeListener getOnCheckedChangeListener() {
- return mOnCheckedChangeListener;
+ OnCheckedChangedListener getOnCheckedChangedListener() {
+ return mOnCheckedChangedListener;
}
}
diff --git a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiListItemAdapter.java b/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiListItemAdapter.java
index 522980c..765d21d 100644
--- a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiListItemAdapter.java
+++ b/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiListItemAdapter.java
@@ -22,14 +22,12 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
-import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import com.android.car.ui.R;
@@ -44,16 +42,17 @@
* <li> Implements {@link CarUiRecyclerView.ItemCap} - defaults to unlimited item count.
* </ul>
*/
-public class CarUiListItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements
+public final class CarUiListItemAdapter extends
+ RecyclerView.Adapter<RecyclerView.ViewHolder> implements
CarUiRecyclerView.ItemCap {
- static final int VIEW_TYPE_LIST_ITEM = 1;
- static final int VIEW_TYPE_LIST_HEADER = 2;
+ private static final int VIEW_TYPE_LIST_ITEM = 1;
+ private static final int VIEW_TYPE_LIST_HEADER = 2;
- private List<? extends CarUiListItem> mItems;
+ private List<CarUiListItem> mItems;
private int mMaxItems = CarUiRecyclerView.ItemCap.UNLIMITED;
- public CarUiListItemAdapter(List<? extends CarUiListItem> items) {
+ public CarUiListItemAdapter(List<CarUiListItem> items) {
this.mItems = items;
}
@@ -82,7 +81,7 @@
* appropriate notify method for the adapter.
*/
@NonNull
- public List<? extends CarUiListItem> getItems() {
+ public List<CarUiListItem> getItems() {
return mItems;
}
@@ -150,21 +149,22 @@
*/
static class ListItemViewHolder extends RecyclerView.ViewHolder {
- final TextView mTitle;
- final TextView mBody;
- final ImageView mIcon;
- final ImageView mContentIcon;
- final ImageView mAvatarIcon;
- final ViewGroup mIconContainer;
- final ViewGroup mActionContainer;
- final View mActionDivider;
- final Switch mSwitch;
- final CheckBox mCheckBox;
- final RadioButton mRadioButton;
- final ImageView mSupplementalIcon;
- final View mTouchInterceptor;
- final View mReducedTouchInterceptor;
- final View mActionContainerTouchInterceptor;
+ private final TextView mTitle;
+ private final TextView mBody;
+ private final ImageView mIcon;
+ private final ImageView mContentIcon;
+ private final ImageView mAvatarIcon;
+ private final ViewGroup mIconContainer;
+ private final ViewGroup mActionContainer;
+ private final View mActionDivider;
+ private final Switch mSwitch;
+ private final CheckBox mCheckBox;
+ private final RadioButton mRadioButton;
+ private final ImageView mSupplementalIcon;
+ private final View mTouchInterceptor;
+ private final View mReducedTouchInterceptor;
+ private final View mActionContainerTouchInterceptor;
+
ListItemViewHolder(@NonNull View itemView) {
super(itemView);
@@ -186,7 +186,7 @@
R.id.action_container_touch_interceptor);
}
- void bind(@NonNull CarUiContentListItem item) {
+ private void bind(@NonNull CarUiContentListItem item) {
CharSequence title = item.getTitle();
CharSequence body = item.getBody();
Drawable icon = item.getIcon();
@@ -256,13 +256,91 @@
mActionContainerTouchInterceptor.setVisibility(View.GONE);
break;
case SWITCH:
- bindCompoundButton(item, mSwitch, itemOnClickListener);
+ mSwitch.setVisibility(View.VISIBLE);
+ mSwitch.setOnCheckedChangeListener(null);
+ mSwitch.setChecked(item.isChecked());
+ mSwitch.setOnCheckedChangeListener(
+ (buttonView, isChecked) -> {
+ item.setChecked(isChecked);
+ CarUiContentListItem.OnCheckedChangedListener itemListener =
+ item.getOnCheckedChangedListener();
+ if (itemListener != null) {
+ itemListener.onCheckedChanged(item, isChecked);
+ }
+ });
+
+ // Clicks anywhere on the item should toggle the switch state. Use full touch
+ // interceptor.
+ mTouchInterceptor.setVisibility(View.VISIBLE);
+ mTouchInterceptor.setOnClickListener(v -> {
+ mSwitch.toggle();
+ if (itemOnClickListener != null) {
+ itemOnClickListener.onClick(item);
+ }
+ });
+ mReducedTouchInterceptor.setVisibility(View.GONE);
+ mActionContainerTouchInterceptor.setVisibility(View.GONE);
+
+ mActionContainer.setVisibility(View.VISIBLE);
+ mActionContainer.setClickable(false);
break;
case CHECK_BOX:
- bindCompoundButton(item, mCheckBox, itemOnClickListener);
+ mCheckBox.setVisibility(View.VISIBLE);
+ mCheckBox.setOnCheckedChangeListener(null);
+ mCheckBox.setChecked(item.isChecked());
+ mCheckBox.setOnCheckedChangeListener(
+ (buttonView, isChecked) -> {
+ item.setChecked(isChecked);
+ CarUiContentListItem.OnCheckedChangedListener itemListener =
+ item.getOnCheckedChangedListener();
+ if (itemListener != null) {
+ itemListener.onCheckedChanged(item, isChecked);
+ }
+ });
+
+ // Clicks anywhere on the item should toggle the checkbox state. Use full touch
+ // interceptor.
+ mTouchInterceptor.setVisibility(View.VISIBLE);
+ mTouchInterceptor.setOnClickListener(v -> {
+ mCheckBox.toggle();
+ if (itemOnClickListener != null) {
+ itemOnClickListener.onClick(item);
+ }
+ });
+ mReducedTouchInterceptor.setVisibility(View.GONE);
+ mActionContainerTouchInterceptor.setVisibility(View.GONE);
+
+ mActionContainer.setVisibility(View.VISIBLE);
+ mActionContainer.setClickable(false);
break;
case RADIO_BUTTON:
- bindCompoundButton(item, mRadioButton, itemOnClickListener);
+ mRadioButton.setVisibility(View.VISIBLE);
+ mRadioButton.setOnCheckedChangeListener(null);
+ mRadioButton.setChecked(item.isChecked());
+ mRadioButton.setOnCheckedChangeListener(
+ (buttonView, isChecked) -> {
+ item.setChecked(isChecked);
+ CarUiContentListItem.OnCheckedChangedListener itemListener =
+ item.getOnCheckedChangedListener();
+ if (itemListener != null) {
+ itemListener.onCheckedChanged(item, isChecked);
+ }
+ });
+
+ // Clicks anywhere on the item should toggle the switch state. Use full touch
+ // interceptor.
+ mTouchInterceptor.setVisibility(View.VISIBLE);
+ mTouchInterceptor.setOnClickListener(v -> {
+ mRadioButton.toggle();
+ if (itemOnClickListener != null) {
+ itemOnClickListener.onClick(item);
+ }
+ });
+ mReducedTouchInterceptor.setVisibility(View.GONE);
+ mActionContainerTouchInterceptor.setVisibility(View.GONE);
+
+ mActionContainer.setVisibility(View.VISIBLE);
+ mActionContainer.setClickable(false);
break;
case ICON:
mSupplementalIcon.setVisibility(View.VISIBLE);
@@ -306,31 +384,6 @@
throw new IllegalStateException("Unknown secondary action type.");
}
}
-
- void bindCompoundButton(@NonNull CarUiContentListItem item,
- @NonNull CompoundButton compoundButton,
- @Nullable CarUiContentListItem.OnClickListener itemOnClickListener) {
- compoundButton.setVisibility(View.VISIBLE);
- compoundButton.setOnCheckedChangeListener(null);
- compoundButton.setChecked(item.isChecked());
- compoundButton.setOnCheckedChangeListener(
- (buttonView, isChecked) -> item.setChecked(isChecked));
-
- // Clicks anywhere on the item should toggle the checkbox state. Use full touch
- // interceptor.
- mTouchInterceptor.setVisibility(View.VISIBLE);
- mTouchInterceptor.setOnClickListener(v -> {
- compoundButton.toggle();
- if (itemOnClickListener != null) {
- itemOnClickListener.onClick(item);
- }
- });
- mReducedTouchInterceptor.setVisibility(View.GONE);
- mActionContainerTouchInterceptor.setVisibility(View.GONE);
-
- mActionContainer.setVisibility(View.VISIBLE);
- mActionContainer.setClickable(false);
- }
}
/**
diff --git a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiListItemLayoutManager.java b/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiListItemLayoutManager.java
index 14eb808..5575dee 100644
--- a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiListItemLayoutManager.java
+++ b/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiListItemLayoutManager.java
@@ -150,7 +150,7 @@
}
mAdapter = (CarUiListItemAdapter) adapter;
- List<? extends CarUiListItem> itemList = mAdapter.getItems();
+ List<CarUiListItem> itemList = mAdapter.getItems();
mListItemHeights = new ArrayList<>();
int cumulativeHeight = 0;
diff --git a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiRadioButtonListItem.java b/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiRadioButtonListItem.java
deleted file mode 100644
index b6f3043..0000000
--- a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiRadioButtonListItem.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.ui.recyclerview;
-
-/**
- * A {@link CarUiContentListItem} that is configured to have a radio button action.
- */
-public class CarUiRadioButtonListItem extends CarUiContentListItem {
-
- public CarUiRadioButtonListItem() {
- super(Action.RADIO_BUTTON);
- }
-}
diff --git a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiRadioButtonListItemAdapter.java b/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiRadioButtonListItemAdapter.java
deleted file mode 100644
index ed248c1..0000000
--- a/car-ui-lib/src/com/android/car/ui/recyclerview/CarUiRadioButtonListItemAdapter.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.ui.recyclerview;
-
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.recyclerview.widget.RecyclerView;
-
-import com.android.car.ui.R;
-
-import java.util.List;
-
-/**
- * Adapter for {@link CarUiRecyclerView} to display {@link CarUiRadioButtonListItem}. This adapter
- * allows for at most one item to be selected at a time.
- *
- * <ul>
- * <li> Implements {@link CarUiRecyclerView.ItemCap} - defaults to unlimited item count.
- * </ul>
- */
-public class CarUiRadioButtonListItemAdapter extends CarUiListItemAdapter {
-
- private int mSelectedIndex = -1;
-
- public CarUiRadioButtonListItemAdapter(List<CarUiRadioButtonListItem> items) {
- super(items);
- for (int i = 0; i < items.size(); i++) {
- CarUiRadioButtonListItem item = items.get(i);
- if (item.isChecked() && mSelectedIndex >= 0) {
- throw new IllegalStateException(
- "At most one item in a CarUiRadioButtonListItemAdapter can be checked");
- }
-
- if (item.isChecked()) {
- mSelectedIndex = i;
- }
- }
- }
-
- @NonNull
- @Override
- public RecyclerView.ViewHolder onCreateViewHolder(
- @NonNull ViewGroup parent, int viewType) {
- LayoutInflater inflater = LayoutInflater.from(parent.getContext());
-
- if (viewType == VIEW_TYPE_LIST_ITEM) {
- return new RadioButtonListItemViewHolder(
- inflater.inflate(R.layout.car_ui_list_item, parent, false));
- }
- return super.onCreateViewHolder(parent, viewType);
- }
-
- @Override
- public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
- if (holder.getItemViewType() == VIEW_TYPE_LIST_ITEM) {
- if (!(holder instanceof RadioButtonListItemViewHolder)) {
- throw new IllegalStateException("Incorrect view holder type for list item.");
- }
-
- CarUiListItem item = getItems().get(position);
- if (!(item instanceof CarUiRadioButtonListItem)) {
- throw new IllegalStateException(
- "Expected item to be bound to viewholder to be instance of "
- + "CarUiRadioButtonListItem.");
- }
-
- RadioButtonListItemViewHolder actualHolder = ((RadioButtonListItemViewHolder) holder);
- actualHolder.bind((CarUiRadioButtonListItem) item);
- actualHolder.setOnCheckedChangeListener(isChecked -> {
- if (isChecked && mSelectedIndex >= 0) {
- CarUiRadioButtonListItem previousSelectedItem =
- (CarUiRadioButtonListItem) getItems().get(mSelectedIndex);
- previousSelectedItem.setChecked(false);
- notifyItemChanged(mSelectedIndex);
- }
-
- if (isChecked) {
- mSelectedIndex = position;
- CarUiRadioButtonListItem currentSelectedItem =
- (CarUiRadioButtonListItem) getItems().get(mSelectedIndex);
- currentSelectedItem.setChecked(true);
- notifyItemChanged(mSelectedIndex);
- }
- });
-
- } else {
- super.onBindViewHolder(holder, position);
- }
- }
-
- static class RadioButtonListItemViewHolder extends ListItemViewHolder {
- /**
- * Callback to be invoked when the checked state of a {@link RadioButtonListItemViewHolder}
- * changed.
- */
- public interface OnCheckedChangeListener {
- /**
- * Called when the checked state of a {@link RadioButtonListItemViewHolder} has changed.
- *
- * @param isChecked new checked state of list item.
- */
- void onCheckedChanged(boolean isChecked);
- }
-
- @Nullable
- private OnCheckedChangeListener mListener;
-
- RadioButtonListItemViewHolder(@NonNull View itemView) {
- super(itemView);
- }
-
- void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener) {
- mListener = listener;
- }
-
- @Override
- void bind(@NonNull CarUiContentListItem item) {
- super.bind(item);
- mRadioButton.setOnCheckedChangeListener(
- (buttonView, isChecked) -> {
- item.setChecked(isChecked);
- if (mListener != null) {
- mListener.onCheckedChanged(isChecked);
- }
- });
- }
- }
-}
diff --git a/car-ui-lib/tests/paintbooth/res/values/strings.xml b/car-ui-lib/tests/paintbooth/res/values/strings.xml
index cd45f77..1022731 100644
--- a/car-ui-lib/tests/paintbooth/res/values/strings.xml
+++ b/car-ui-lib/tests/paintbooth/res/values/strings.xml
@@ -248,9 +248,6 @@
<!-- Button that shows a dialog with a subtitle and icon [CHAR_LIMIT=50]-->
<string name="dialog_show_subtitle_and_icon">Show Dialog with title, subtitle, and icon</string>
- <!-- Text to show Dialog with single choice items-->
- <string name="dialog_show_single_choice">Show with single choice items</string>
-
<!--This section is for widget attributes -->
<eat-comment/>
<!-- Text for checkbox [CHAR_LIMIT=16]-->
diff --git a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/caruirecyclerview/CarUiListItemActivity.java b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/caruirecyclerview/CarUiListItemActivity.java
index 3a3f562..10aef44 100644
--- a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/caruirecyclerview/CarUiListItemActivity.java
+++ b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/caruirecyclerview/CarUiListItemActivity.java
@@ -56,87 +56,89 @@
CarUiHeaderListItem header = new CarUiHeaderListItem("First header");
mData.add(header);
- CarUiContentListItem item = new CarUiContentListItem(CarUiContentListItem.Action.NONE);
+ CarUiContentListItem item = new CarUiContentListItem();
item.setTitle("Test title");
item.setBody("Test body");
mData.add(item);
- item = new CarUiContentListItem(CarUiContentListItem.Action.NONE);
+ item = new CarUiContentListItem();
item.setTitle("Test title with no body");
mData.add(item);
header = new CarUiHeaderListItem("Random header", "with header body");
mData.add(header);
- item = new CarUiContentListItem(CarUiContentListItem.Action.NONE);
+ item = new CarUiContentListItem();
item.setBody("Test body with no title");
mData.add(item);
- item = new CarUiContentListItem(CarUiContentListItem.Action.NONE);
+ item = new CarUiContentListItem();
item.setTitle("Test Title");
item.setIcon(getDrawable(R.drawable.ic_launcher));
mData.add(item);
- item = new CarUiContentListItem(CarUiContentListItem.Action.NONE);
+ item = new CarUiContentListItem();
item.setTitle("Test Title");
item.setBody("Test body text");
item.setIcon(getDrawable(R.drawable.ic_launcher));
mData.add(item);
- item = new CarUiContentListItem(CarUiContentListItem.Action.NONE);
+ item = new CarUiContentListItem();
item.setTitle("Test Title -- with content icon");
item.setPrimaryIconType(CarUiContentListItem.IconType.CONTENT);
item.setIcon(getDrawable(R.drawable.ic_sample_logo));
mData.add(item);
- item = new CarUiContentListItem(CarUiContentListItem.Action.NONE);
+ item = new CarUiContentListItem();
item.setTitle("Test Title");
item.setBody("With avatar icon.");
item.setIcon(getDrawable(R.drawable.ic_sample_logo));
item.setPrimaryIconType(CarUiContentListItem.IconType.AVATAR);
- item = new CarUiContentListItem(CarUiContentListItem.Action.NONE);
+ item = new CarUiContentListItem();
item.setTitle("Test Title");
item.setBody("Displays toast on click");
item.setIcon(getDrawable(R.drawable.ic_launcher));
item.setOnItemClickedListener(item1 -> {
- Toast.makeText(context, "Item clicked", Toast.LENGTH_SHORT).show();
+ Toast.makeText(context, "Item clicked" , Toast.LENGTH_SHORT).show();
});
mData.add(item);
- item = new CarUiContentListItem(CarUiContentListItem.Action.CHECK_BOX);
+ item = new CarUiContentListItem();
item.setIcon(getDrawable(R.drawable.ic_launcher));
item.setTitle("Title -- Item with checkbox");
item.setBody("Will present toast on change of selection state.");
- item.setOnCheckedChangeListener(
+ item.setOnCheckedChangedListener(
(listItem, isChecked) -> Toast.makeText(context,
"Item checked state is: " + isChecked, Toast.LENGTH_SHORT).show());
+ item.setAction(CarUiContentListItem.Action.CHECK_BOX);
mData.add(item);
- item = new CarUiContentListItem(CarUiContentListItem.Action.SWITCH);
+ item = new CarUiContentListItem();
item.setIcon(getDrawable(R.drawable.ic_launcher));
item.setBody("Body -- Item with switch -- with click listener");
+ item.setAction(CarUiContentListItem.Action.SWITCH);
item.setOnItemClickedListener(item1 -> {
- Toast.makeText(context, "Click on item with switch", Toast.LENGTH_SHORT).show();
+ Toast.makeText(context, "Click on item with switch" , Toast.LENGTH_SHORT).show();
});
mData.add(item);
- item = new CarUiContentListItem(CarUiContentListItem.Action.CHECK_BOX);
+ item = new CarUiContentListItem();
item.setIcon(getDrawable(R.drawable.ic_launcher));
item.setTitle("Title -- Item with checkbox");
item.setBody("Item is initially checked");
+ item.setAction(CarUiContentListItem.Action.CHECK_BOX);
item.setChecked(true);
mData.add(item);
- CarUiContentListItem radioItem1 = new CarUiContentListItem(
- CarUiContentListItem.Action.RADIO_BUTTON);
- CarUiContentListItem radioItem2 = new CarUiContentListItem(
- CarUiContentListItem.Action.RADIO_BUTTON);
+ CarUiContentListItem radioItem1 = new CarUiContentListItem();
+ CarUiContentListItem radioItem2 = new CarUiContentListItem();
radioItem1.setTitle("Title -- Item with radio button");
radioItem1.setBody("Item is initially unchecked checked");
+ radioItem1.setAction(CarUiContentListItem.Action.RADIO_BUTTON);
radioItem1.setChecked(false);
- radioItem1.setOnCheckedChangeListener((listItem, isChecked) -> {
+ radioItem1.setOnCheckedChangedListener((listItem, isChecked) -> {
if (isChecked) {
radioItem2.setChecked(false);
mAdapter.notifyItemChanged(mData.indexOf(radioItem2));
@@ -146,8 +148,9 @@
radioItem2.setIcon(getDrawable(R.drawable.ic_launcher));
radioItem2.setTitle("Item is mutually exclusive with item above");
+ radioItem2.setAction(CarUiContentListItem.Action.RADIO_BUTTON);
radioItem2.setChecked(true);
- radioItem2.setOnCheckedChangeListener((listItem, isChecked) -> {
+ radioItem2.setOnCheckedChangedListener((listItem, isChecked) -> {
if (isChecked) {
radioItem1.setChecked(false);
mAdapter.notifyItemChanged(mData.indexOf(radioItem1));
@@ -155,7 +158,7 @@
});
mData.add(radioItem2);
- item = new CarUiContentListItem(CarUiContentListItem.Action.ICON);
+ item = new CarUiContentListItem();
item.setIcon(getDrawable(R.drawable.ic_launcher));
item.setTitle("Title");
item.setBody("Random body text -- with action divider");
@@ -164,13 +167,14 @@
item.setChecked(true);
mData.add(item);
- item = new CarUiContentListItem(CarUiContentListItem.Action.ICON);
+ item = new CarUiContentListItem();
item.setIcon(getDrawable(R.drawable.ic_launcher));
item.setTitle("Null supplemental icon");
+ item.setAction(CarUiContentListItem.Action.ICON);
item.setChecked(true);
mData.add(item);
- item = new CarUiContentListItem(CarUiContentListItem.Action.ICON);
+ item = new CarUiContentListItem();
item.setTitle("Supplemental icon with listener");
item.setSupplementalIcon(getDrawable(R.drawable.ic_launcher),
v -> Toast.makeText(context, "Clicked supplemental icon",
diff --git a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/dialogs/DialogsActivity.java b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/dialogs/DialogsActivity.java
index 769a1ab..37c9a42 100644
--- a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/dialogs/DialogsActivity.java
+++ b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/dialogs/DialogsActivity.java
@@ -29,8 +29,6 @@
import com.android.car.ui.AlertDialogBuilder;
import com.android.car.ui.paintbooth.R;
-import com.android.car.ui.recyclerview.CarUiRadioButtonListItem;
-import com.android.car.ui.recyclerview.CarUiRadioButtonListItemAdapter;
import com.android.car.ui.recyclerview.CarUiRecyclerView;
import java.util.ArrayList;
@@ -68,9 +66,6 @@
v -> showDialogWithSubtitle()));
mButtons.add(Pair.create(R.string.dialog_show_subtitle_and_icon,
v -> showDialogWithSubtitleAndIcon()));
- mButtons.add(Pair.create(R.string.dialog_show_single_choice,
- v -> showDialogWithSingleChoiceItems()));
-
CarUiRecyclerView recyclerView = requireViewById(R.id.list);
recyclerView.setAdapter(mAdapter);
@@ -157,28 +152,6 @@
.show();
}
- private void showDialogWithSingleChoiceItems() {
- ArrayList<CarUiRadioButtonListItem> data = new ArrayList<>();
-
- CarUiRadioButtonListItem item = new CarUiRadioButtonListItem();
- item.setTitle("First item");
- data.add(item);
-
- item = new CarUiRadioButtonListItem();
- item.setTitle("Second item");
- data.add(item);
-
- item = new CarUiRadioButtonListItem();
- item.setTitle("Third item");
- data.add(item);
-
- new AlertDialogBuilder(this)
- .setTitle("Select one option.")
- .setSubtitle("Ony one option may be selected at a time")
- .setSingleChoiceItems(new CarUiRadioButtonListItemAdapter(data), null)
- .show();
- }
-
private void showDialogWithSubtitleAndIcon() {
new AlertDialogBuilder(this)
.setTitle("My Title!")
diff --git a/car-ui-lib/tests/robotests/src/com/android/car/ui/recyclerview/CarUiListItemTest.java b/car-ui-lib/tests/robotests/src/com/android/car/ui/recyclerview/CarUiListItemTest.java
index 0cc3dee..dec4c19 100644
--- a/car-ui-lib/tests/robotests/src/com/android/car/ui/recyclerview/CarUiListItemTest.java
+++ b/car-ui-lib/tests/robotests/src/com/android/car/ui/recyclerview/CarUiListItemTest.java
@@ -50,7 +50,7 @@
private Context mContext;
@Mock
- CarUiContentListItem.OnCheckedChangeListener mOnCheckedChangeListener;
+ CarUiContentListItem.OnCheckedChangedListener mOnCheckedChangedListener;
@Before
public void setUp() {
@@ -127,7 +127,7 @@
public void testItemVisibility_withTitle() {
List<CarUiListItem> items = new ArrayList<>();
- CarUiContentListItem item = new CarUiContentListItem(CarUiContentListItem.Action.NONE);
+ CarUiContentListItem item = new CarUiContentListItem();
item.setTitle("Test title");
items.add(item);
@@ -145,7 +145,7 @@
public void testItemVisibility_withTitle_withBody() {
List<CarUiListItem> items = new ArrayList<>();
- CarUiContentListItem item = new CarUiContentListItem(CarUiContentListItem.Action.NONE);
+ CarUiContentListItem item = new CarUiContentListItem();
item.setTitle("Test title");
item.setBody("Test body");
items.add(item);
@@ -164,7 +164,7 @@
public void testItemVisibility_withTitle_withIcon() {
List<CarUiListItem> items = new ArrayList<>();
- CarUiContentListItem item = new CarUiContentListItem(CarUiContentListItem.Action.NONE);
+ CarUiContentListItem item = new CarUiContentListItem();
item.setTitle("Test title");
item.setIcon(mContext.getDrawable(R.drawable.car_ui_icon_close));
items.add(item);
@@ -183,8 +183,9 @@
public void testItemVisibility_withTitle_withCheckbox() {
List<CarUiListItem> items = new ArrayList<>();
- CarUiContentListItem item = new CarUiContentListItem(CarUiContentListItem.Action.CHECK_BOX);
+ CarUiContentListItem item = new CarUiContentListItem();
item.setTitle("Test title");
+ item.setAction(CarUiContentListItem.Action.CHECK_BOX);
items.add(item);
updateRecyclerViewAdapter(new CarUiListItemAdapter(items));
@@ -203,9 +204,10 @@
public void testItemVisibility_withTitle_withBody_withSwitch() {
List<CarUiListItem> items = new ArrayList<>();
- CarUiContentListItem item = new CarUiContentListItem(CarUiContentListItem.Action.SWITCH);
+ CarUiContentListItem item = new CarUiContentListItem();
item.setTitle("Test title");
item.setBody("Body text");
+ item.setAction(CarUiContentListItem.Action.SWITCH);
items.add(item);
updateRecyclerViewAdapter(new CarUiListItemAdapter(items));
@@ -224,9 +226,10 @@
public void testCheckedState_switch() {
List<CarUiListItem> items = new ArrayList<>();
- CarUiContentListItem item = new CarUiContentListItem(CarUiContentListItem.Action.SWITCH);
+ CarUiContentListItem item = new CarUiContentListItem();
item.setTitle("Test title");
- item.setOnCheckedChangeListener(mOnCheckedChangeListener);
+ item.setOnCheckedChangedListener(mOnCheckedChangedListener);
+ item.setAction(CarUiContentListItem.Action.SWITCH);
item.setChecked(true);
items.add(item);
@@ -237,7 +240,7 @@
assertThat(switchWidget.isChecked()).isEqualTo(true);
switchWidget.performClick();
assertThat(switchWidget.isChecked()).isEqualTo(false);
- verify(mOnCheckedChangeListener, times(1))
+ verify(mOnCheckedChangedListener, times(1))
.onCheckedChanged(item, false);
}
@@ -245,9 +248,10 @@
public void testCheckedState_checkbox() {
List<CarUiListItem> items = new ArrayList<>();
- CarUiContentListItem item = new CarUiContentListItem(CarUiContentListItem.Action.CHECK_BOX);
+ CarUiContentListItem item = new CarUiContentListItem();
item.setTitle("Test title");
- item.setOnCheckedChangeListener(mOnCheckedChangeListener);
+ item.setAction(CarUiContentListItem.Action.CHECK_BOX);
+ item.setOnCheckedChangedListener(mOnCheckedChangedListener);
items.add(item);
updateRecyclerViewAdapter(new CarUiListItemAdapter(items));
@@ -257,7 +261,7 @@
assertThat(checkBox.isChecked()).isEqualTo(false);
checkBox.performClick();
assertThat(checkBox.isChecked()).isEqualTo(true);
- verify(mOnCheckedChangeListener, times(1))
+ verify(mOnCheckedChangedListener, times(1))
.onCheckedChanged(item, true);
}
@@ -271,6 +275,8 @@
updateRecyclerViewAdapter(new CarUiListItemAdapter(items));
+ CarUiListItemAdapter.HeaderViewHolder viewHolder = getHeaderViewHolderAtPosition(0);
+
assertThat(getHeaderViewHolderTitleAtPosition(0).getVisibility()).isEqualTo(View.VISIBLE);
assertThat(getHeaderViewHolderTitleAtPosition(0).getText()).isEqualTo(title);
assertThat(getHeaderViewHolderBodyAtPosition(0).getVisibility()).isNotEqualTo(View.VISIBLE);