1 /* 2 * Copyright (C) 2021 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.widescreenime; 18 19 import android.os.Bundle; 20 21 import androidx.annotation.NonNull; 22 import androidx.appcompat.app.AppCompatActivity; 23 import androidx.recyclerview.widget.LinearLayoutManager; 24 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.paintbooth.caruirecyclerview.RecyclerViewAdapter; 30 import com.android.car.ui.recyclerview.CarUiRecyclerView; 31 import com.android.car.ui.toolbar.MenuItem; 32 import com.android.car.ui.toolbar.NavButtonMode; 33 import com.android.car.ui.toolbar.SearchConfig; 34 import com.android.car.ui.toolbar.SearchMode; 35 import com.android.car.ui.toolbar.ToolbarController; 36 37 import java.util.ArrayList; 38 import java.util.Collections; 39 import java.util.List; 40 41 /** 42 * Activity that the custom view inflated in IME window. 43 */ 44 public class WideScreenTestView extends AppCompatActivity implements InsetsChangedListener { 45 46 @Override onCreate(Bundle savedInstanceState)47 protected void onCreate(Bundle savedInstanceState) { 48 super.onCreate(savedInstanceState); 49 setContentView(R.layout.car_ui_recycler_view_activity); 50 51 ToolbarController toolbar = CarUi.requireToolbar(this); 52 toolbar.setTitle(getTitle()); 53 toolbar.setNavButtonMode(NavButtonMode.BACK); 54 toolbar.setLogo(R.drawable.ic_launcher); 55 boolean[] isSearching = new boolean[]{false}; 56 toolbar.registerBackListener( 57 () -> { 58 if (isSearching[0]) { 59 toolbar.setSearchMode(SearchMode.DISABLED); 60 isSearching[0] = false; 61 return true; 62 } 63 return false; 64 }); 65 66 toolbar.setMenuItems(Collections.singletonList(MenuItem.builder(this) 67 .setToSearch() 68 .setOnClickListener(i -> { 69 isSearching[0] = true; 70 toolbar.setSearchMode(SearchMode.SEARCH); 71 if (toolbar.getSearchCapabilities().canShowSearchResultsView()) { 72 toolbar.setSearchConfig(SearchConfig.builder() 73 .setSearchResultsView(findViewById(R.id.list)).build()); 74 } 75 }).build())); 76 77 CarUiRecyclerView recyclerView = findViewById(R.id.list); 78 recyclerView.setLayoutManager(new LinearLayoutManager(this)); 79 80 RecyclerViewAdapter adapter = new RecyclerViewAdapter(generateSampleData()); 81 recyclerView.setAdapter(adapter); 82 } 83 generateSampleData()84 private List<String> generateSampleData() { 85 List<String> data = new ArrayList<>(); 86 for (int i = 0; i <= 100; i++) { 87 data.add(getString(R.string.test_data) + i); 88 } 89 return data; 90 } 91 92 @Override onCarUiInsetsChanged(@onNull Insets insets)93 public void onCarUiInsetsChanged(@NonNull Insets insets) { 94 requireViewById(R.id.list) 95 .setPadding(0, insets.getTop(), 0, insets.getBottom()); 96 requireViewById(android.R.id.content) 97 .setPadding(insets.getLeft(), 0, insets.getRight(), 0); 98 } 99 } 100