• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 com.android.car.ui.paintbooth.caruirecyclerview;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 
22 import androidx.annotation.NonNull;
23 import androidx.recyclerview.widget.LinearLayoutManager;
24 
25 import com.android.car.ui.FocusArea;
26 import com.android.car.ui.baselayout.Insets;
27 import com.android.car.ui.baselayout.InsetsChangedListener;
28 import com.android.car.ui.core.CarUi;
29 import com.android.car.ui.paintbooth.R;
30 import com.android.car.ui.recyclerview.CarUiRecyclerView;
31 import com.android.car.ui.toolbar.NavButtonMode;
32 import com.android.car.ui.toolbar.ToolbarController;
33 
34 import java.util.ArrayList;
35 
36 /**
37  * Activity that shows CarUiRecyclerView example with sample data.
38  */
39 public class CarUiRecyclerViewActivity extends Activity implements InsetsChangedListener {
40     private final ArrayList<String> mData = new ArrayList<>();
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45         setContentView(R.layout.car_ui_recycler_view_activity);
46 
47         ToolbarController toolbar = CarUi.requireToolbar(this);
48         toolbar.setTitle(getTitle());
49         toolbar.setNavButtonMode(NavButtonMode.BACK);
50 
51         CarUiRecyclerView recyclerView = findViewById(R.id.list);
52         recyclerView.setLayoutManager(new LinearLayoutManager(this));
53 
54         RecyclerViewAdapter adapter = new RecyclerViewAdapter(generateSampleData());
55         recyclerView.setAdapter(adapter);
56     }
57 
generateSampleData()58     private ArrayList<String> generateSampleData() {
59         for (int i = 0; i <= 100; i++) {
60             mData.add(getString(R.string.test_data) + i);
61         }
62         return mData;
63     }
64 
65     @Override
onCarUiInsetsChanged(@onNull Insets insets)66     public void onCarUiInsetsChanged(@NonNull Insets insets) {
67         FocusArea focusArea = requireViewById(R.id.focus_area);
68         focusArea.setBoundsOffset(0, insets.getTop(), 0, insets.getBottom());
69         focusArea.setHighlightPadding(0, insets.getTop(), 0, insets.getBottom());
70         requireViewById(R.id.list)
71                 .setPadding(0, insets.getTop(), 0, insets.getBottom());
72         requireViewById(android.R.id.content)
73                 .setPadding(insets.getLeft(), 0, insets.getRight(), 0);
74     }
75 }
76 
77