|
| 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 | +} |
0 commit comments