• 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 
24 import com.android.car.ui.FocusArea;
25 import com.android.car.ui.baselayout.Insets;
26 import com.android.car.ui.baselayout.InsetsChangedListener;
27 import com.android.car.ui.core.CarUi;
28 import com.android.car.ui.paintbooth.R;
29 import com.android.car.ui.recyclerview.CarUiRecyclerView;
30 import com.android.car.ui.toolbar.NavButtonMode;
31 import com.android.car.ui.toolbar.ToolbarController;
32 
33 import java.util.ArrayList;
34 
35 /** Activity that shows GridCarUiRecyclerView example with sample data. */
36 public class GridCarUiRecyclerViewActivity extends Activity implements
37         InsetsChangedListener {
38     private final ArrayList<String> mData = new ArrayList<>();
39     private final int mDataToGenerate = 200;
40 
41     @Override
onCreate(Bundle savedInstanceState)42     protected void onCreate(Bundle savedInstanceState) {
43         super.onCreate(savedInstanceState);
44         setContentView(R.layout.grid_car_ui_recycler_view_activity);
45 
46         ToolbarController toolbar = CarUi.requireToolbar(this);
47         toolbar.setTitle(getTitle());
48         toolbar.setNavButtonMode(NavButtonMode.BACK);
49 
50         CarUiRecyclerView recyclerView = findViewById(R.id.list);
51 
52         RecyclerViewAdapter adapter = new RecyclerViewAdapter(generateSampleData());
53         recyclerView.setAdapter(adapter);
54     }
55 
generateSampleData()56     private ArrayList<String> generateSampleData() {
57         for (int i = 1; i <= mDataToGenerate; i++) {
58             mData.add("data" + i);
59         }
60         return mData;
61     }
62 
63     @Override
onCarUiInsetsChanged(@onNull Insets insets)64     public void onCarUiInsetsChanged(@NonNull Insets insets) {
65         FocusArea focusArea = requireViewById(R.id.focus_area);
66         focusArea.setBoundsOffset(0, insets.getTop(), 0, insets.getBottom());
67         focusArea.setHighlightPadding(0, insets.getTop(), 0, insets.getBottom());
68         requireViewById(R.id.list)
69                 .setPadding(0, insets.getTop(), 0, insets.getBottom());
70         requireViewById(android.R.id.content)
71                 .setPadding(insets.getLeft(), 0, insets.getRight(), 0);
72     }
73 }
74