Skip to content

Commit ab86a01

Browse files
imhappidsn5ft
authored andcommitted
[Lists] Added segmented list style, public attrs, and catalog demos
PiperOrigin-RevId: 793796271
1 parent ac82767 commit ab86a01

File tree

22 files changed

+362
-158
lines changed

22 files changed

+362
-158
lines changed

catalog/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def srcDirs = [
9898
'font',
9999
'internal',
100100
'loadingindicator',
101+
'listitem',
101102
'main',
102103
'materialswitch',
103104
'menu',

catalog/java/io/material/catalog/lists/ListsFragment.java renamed to catalog/java/io/material/catalog/listitem/ListsFragment.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.material.catalog.lists;
17+
package io.material.catalog.listitem;
1818

1919
import io.material.catalog.R;
2020

@@ -45,6 +45,7 @@ public int getDescriptionResId() {
4545
}
4646

4747
@Override
48+
@NonNull
4849
public Demo getMainDemo() {
4950
return new Demo() {
5051
@Override
@@ -59,10 +60,10 @@ public Fragment createFragment() {
5960
public List<Demo> getAdditionalDemos() {
6061
List<Demo> additionalDemos = new ArrayList<>();
6162
additionalDemos.add(
62-
new Demo(R.string.cat_lists_custom_content_demo_title) {
63+
new Demo(R.string.cat_lists_segmented_demo_title) {
6364
@Override
6465
public Fragment createFragment() {
65-
return new ListsCustomContentDemoFragment();
66+
return new SegmentedListDemoFragment();
6667
}
6768
});
6869
return additionalDemos;

catalog/java/io/material/catalog/lists/ListsCustomContentDemoFragment.java renamed to catalog/java/io/material/catalog/listitem/ListsMainDemoFragment.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 The Android Open Source Project
2+
* Copyright 2019 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.material.catalog.lists;
17+
package io.material.catalog.listitem;
1818

1919
import io.material.catalog.R;
2020

@@ -39,9 +39,8 @@
3939
import java.util.ArrayList;
4040
import java.util.List;
4141

42-
/** A fragment that displays a List demos with custom content for the Catalog app. */
43-
public class ListsCustomContentDemoFragment extends DemoFragment {
44-
42+
/** A fragment that displays the main List demos for the Catalog app. */
43+
public class ListsMainDemoFragment extends DemoFragment {
4544
@NonNull
4645
@Override
4746
public View onCreateDemoView(
@@ -126,7 +125,7 @@ public void getItemOffsets(@NonNull Rect outRect,
126125
}
127126
}
128127

129-
/** A ViewHolder that shows a custom list item */
128+
/** A ViewHolder that shows custom list items */
130129
public static class CustomItemViewHolder extends ListItemViewHolder {
131130

132131
private final ImageView startButton;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.material.catalog.listitem;
18+
19+
import io.material.catalog.R;
20+
21+
import android.os.Bundle;
22+
import androidx.recyclerview.widget.LinearLayoutManager;
23+
import androidx.recyclerview.widget.RecyclerView;
24+
import android.view.LayoutInflater;
25+
import android.view.View;
26+
import android.view.ViewGroup;
27+
import androidx.annotation.NonNull;
28+
import androidx.annotation.Nullable;
29+
import java.util.ArrayList;
30+
import java.util.List;
31+
32+
/** A fragment that displays a segmented List demos for the Catalog app. */
33+
public class SegmentedListDemoFragment extends ListsMainDemoFragment {
34+
35+
@NonNull
36+
@Override
37+
public View onCreateDemoView(
38+
@NonNull LayoutInflater layoutInflater,
39+
@Nullable ViewGroup viewGroup,
40+
@Nullable Bundle bundle) {
41+
RecyclerView view =
42+
(RecyclerView) layoutInflater.inflate(R.layout.cat_lists_bright_background_fragment, viewGroup, false);
43+
44+
view.setLayoutManager(new LinearLayoutManager(getContext()));
45+
List<CustomCardData> data = new ArrayList<>();
46+
for (int i = 0; i < 20; i++) {
47+
data.add(new CustomCardData(i+1));
48+
}
49+
50+
view.setAdapter(new ListsAdapter(data));
51+
view.addItemDecoration(new MarginItemDecoration(getContext()));
52+
53+
return view;
54+
}
55+
56+
/** An Adapter that shows custom list items */
57+
public static class ListsAdapter extends ListsMainDemoFragment.ListsAdapter {
58+
59+
public ListsAdapter(@NonNull List<CustomCardData> items) {
60+
super(items);
61+
}
62+
63+
@NonNull
64+
@Override
65+
public CustomItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
66+
ViewGroup item =
67+
(ViewGroup)
68+
LayoutInflater.from(parent.getContext()).inflate(R.layout.cat_list_item_segmented_viewholder, parent, /* attachToRoot= */ false);
69+
return new CustomItemViewHolder(item);
70+
}
71+
}
72+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<com.google.android.material.listitem.ListItemLayout xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
style="?attr/listItemLayoutSegmentedStyle">
21+
<com.google.android.material.card.MaterialCardView
22+
android:id="@+id/cat_list_item_card_view"
23+
android:layout_width="match_parent"
24+
android:layout_height="wrap_content"
25+
android:checkable="true"
26+
android:clickable="true"
27+
android:focusable="true">
28+
29+
<LinearLayout
30+
android:orientation="horizontal"
31+
android:layout_width="match_parent"
32+
android:layout_height="wrap_content"
33+
android:gravity="center_vertical">
34+
35+
<ImageView
36+
android:id="@+id/cat_list_item_start_icon"
37+
android:layout_width="wrap_content"
38+
android:layout_height="wrap_content"
39+
android:paddingTop="8dp"
40+
android:paddingBottom="8dp"
41+
android:paddingStart="16dp"
42+
android:paddingEnd="16dp"
43+
android:contentDescription="@string/cat_list_item_icon_content_description" />
44+
45+
<TextView
46+
android:id="@+id/cat_list_item_text"
47+
android:layout_width="0dp"
48+
android:layout_height="wrap_content"
49+
android:layout_weight="1"/>
50+
51+
<ImageView
52+
android:id="@+id/cat_list_item_end_icon"
53+
android:layout_width="wrap_content"
54+
android:layout_height="wrap_content"
55+
android:paddingTop="8dp"
56+
android:paddingBottom="8dp"
57+
android:paddingStart="16dp"
58+
android:paddingEnd="16dp"
59+
android:contentDescription="@string/cat_list_item_icon_content_description" />
60+
61+
</LinearLayout>
62+
</com.google.android.material.card.MaterialCardView>
63+
</com.google.android.material.listitem.ListItemLayout>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:tools="http://schemas.android.com/tools"
20+
tools:ignore="Overdraw"
21+
android:id="@+id/recycler_view"
22+
android:layout_width="match_parent"
23+
android:layout_height="match_parent"
24+
android:padding="8dp"
25+
android:clipToPadding="false"
26+
android:background="?attr/colorSurfaceContainerHighest" />

catalog/java/io/material/catalog/lists/res/layout/cat_lists_fragment.xml renamed to catalog/java/io/material/catalog/listitem/res/layout/cat_lists_fragment.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
limitations under the License.
1616
-->
1717

18-
<androidx.recyclerview.widget.RecyclerView
19-
xmlns:android="http://schemas.android.com/apk/res/android"
18+
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:tools="http://schemas.android.com/tools"
20+
tools:ignore="Overdraw"
2021
android:id="@+id/recycler_view"
2122
android:layout_width="match_parent"
2223
android:layout_height="match_parent"
23-
android:paddingTop="8dp"
24-
android:paddingBottom="8dp"
24+
android:padding="8dp"
2525
android:clipToPadding="false"/>

catalog/java/io/material/catalog/lists/res/values/strings.xml renamed to catalog/java/io/material/catalog/listitem/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<string name="mtrl_list_item_three_line">Three Line Item</string>
2828
<string name="mtrl_list_item_secondary_text">Secondary Text</string>
2929
<string name="mtrl_list_item_tertiary_text">Tertiary Text</string>
30-
<string name="cat_lists_custom_content_demo_title" description="Label for the demo that shows custom list content. [CHAR_LIMIT=100]">Custom Content Demo</string>
30+
<string name="cat_lists_segmented_demo_title" description="Label for the demo that shows segmented list content. [CHAR_LIMIT=100]">Segmented Demo</string>
3131
<string name="cat_list_item_icon_content_description" description="Description for sample icon in custom list item demo. [CHAR_LIMIT=100]">List item icon</string>
3232
</resources>
3333

0 commit comments

Comments
 (0)