Skip to content

Commit 1f6e037

Browse files
Jiarui JiangGerrit Code Review
Jiarui Jiang
authored and
Gerrit Code Review
committed
Merge "Add sectioned item list demo to test app" into androidx-main
2 parents 131671b + 12511f2 commit 1f6e037

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

car/app/app-samples/showcase/common/src/main/java/androidx/car/app/sample/showcase/common/screens/templatelayouts/ListTemplateDemoScreen.java

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import androidx.car.app.sample.showcase.common.screens.templatelayouts.listtemplates.ContentProviderIconsDemoScreen;
3030
import androidx.car.app.sample.showcase.common.screens.templatelayouts.listtemplates.RadioButtonListDemoScreen;
3131
import androidx.car.app.sample.showcase.common.screens.templatelayouts.listtemplates.SecondaryActionsAndDecorationDemoScreen;
32+
import androidx.car.app.sample.showcase.common.screens.templatelayouts.listtemplates.SectionedItemListDemoScreen;
3233
import androidx.car.app.sample.showcase.common.screens.templatelayouts.listtemplates.TextAndIconsDemosScreen;
3334
import androidx.car.app.sample.showcase.common.screens.templatelayouts.listtemplates.ToggleButtonListDemoScreen;
3435
import androidx.car.app.versioning.CarAppApiLevels;
@@ -60,6 +61,9 @@ public Template onGetTemplate() {
6061
new SecondaryActionsAndDecorationDemoScreen(getCarContext()),
6162
R.string.secondary_actions_decoration_button_demo_title));
6263
}
64+
listBuilder.addItem(buildRowForTemplate(
65+
new SectionedItemListDemoScreen(getCarContext()),
66+
R.string.sectioned_item_list_demo_title));
6367
return new ListTemplate.Builder()
6468
.setSingleList(listBuilder.build())
6569
.setTitle(getCarContext().getString(R.string.list_template_demo_title))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2023 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 androidx.car.app.sample.showcase.common.screens.templatelayouts.listtemplates;
18+
19+
import static androidx.car.app.model.Action.BACK;
20+
21+
import androidx.annotation.NonNull;
22+
import androidx.car.app.CarContext;
23+
import androidx.car.app.Screen;
24+
import androidx.car.app.model.Action;
25+
import androidx.car.app.model.ActionStrip;
26+
import androidx.car.app.model.ItemList;
27+
import androidx.car.app.model.ListTemplate;
28+
import androidx.car.app.model.Row;
29+
import androidx.car.app.model.SectionedItemList;
30+
import androidx.car.app.model.Template;
31+
import androidx.car.app.sample.showcase.common.R;
32+
33+
34+
/** A screen demonstrating lists with sectioned item list */
35+
public class SectionedItemListDemoScreen extends Screen {
36+
public SectionedItemListDemoScreen(@NonNull CarContext carContext) {
37+
super(carContext);
38+
}
39+
40+
@NonNull
41+
@Override
42+
public Template onGetTemplate() {
43+
44+
ItemList.Builder listBuilderOne = new ItemList.Builder();
45+
listBuilderOne.addItem(buildRowForTemplate(R.string.sectioned_item_list_subtext));
46+
47+
listBuilderOne.addItem(buildRowForTemplate(R.string.sectioned_item_list_subtext));
48+
49+
ItemList.Builder listBuilderTwo = new ItemList.Builder();
50+
51+
listBuilderTwo.addItem(buildRowForTemplate(R.string.sectioned_item_list_subtext));
52+
53+
return new ListTemplate.Builder()
54+
.addSectionedList(SectionedItemList.create(listBuilderOne.build(),
55+
getCarContext()
56+
.getString(R.string.sectioned_item_list_one_title)))
57+
.addSectionedList(SectionedItemList.create(listBuilderTwo.build(),
58+
getCarContext()
59+
.getString(R.string.sectioned_item_list_two_title)))
60+
.setTitle(getCarContext()
61+
.getString(R.string.sectioned_item_list_demo_title))
62+
.setHeaderAction(BACK)
63+
.setActionStrip(
64+
new ActionStrip.Builder()
65+
.addAction(
66+
new Action.Builder()
67+
.setTitle(getCarContext().getString(
68+
R.string.home_caps_action_title))
69+
.setOnClickListener(
70+
() -> getScreenManager().popToRoot())
71+
.build())
72+
.build())
73+
.build();
74+
}
75+
76+
private Row buildRowForTemplate(int title) {
77+
return new Row.Builder()
78+
.setTitle(getCarContext().getString(title))
79+
.build();
80+
}
81+
}

car/app/app-samples/showcase/common/src/main/res/values/strings.xml

+7
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,13 @@
411411
<string name="secondary_action_toast">Secondary Action is selected</string>
412412
<string name="row_primary_action_toast">Row primary action is selected</string>
413413

414+
415+
<!--SectionedItemListDemoScreen -->
416+
<string name="sectioned_item_list_demo_title">Sectioned Item List Demo</string>
417+
<string name="sectioned_item_list_one_title">List 1</string>
418+
<string name="sectioned_item_list_two_title">List 2</string>
419+
<string name="sectioned_item_list_subtext">Subtext under each list</string>
420+
414421
<!-- StartScreen -->
415422
<string name="misc_templates_demos_title">Misc Templates Demos</string>
416423
<string name="cal_api_level_prefix" translatable="false">CAL API Level: %d</string>

0 commit comments

Comments
 (0)