1 /* 2 * Copyright (C) 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 com.android.launcher3.allapps.search; 18 19 import android.view.LayoutInflater; 20 import android.view.View; 21 22 import androidx.recyclerview.widget.RecyclerView; 23 24 import com.android.launcher3.R; 25 import com.android.launcher3.allapps.ActivityAllAppsContainerView; 26 import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem; 27 import com.android.launcher3.views.ActivityContext; 28 29 import java.util.List; 30 31 /** Initializes the search box and its interactions with All Apps. */ 32 public class AllAppsSearchUiDelegate { 33 34 protected final ActivityAllAppsContainerView<?> mAppsView; 35 protected final ActivityContext mActivityContext; 36 AllAppsSearchUiDelegate(ActivityAllAppsContainerView<?> appsView)37 public AllAppsSearchUiDelegate(ActivityAllAppsContainerView<?> appsView) { 38 mAppsView = appsView; 39 mActivityContext = ActivityContext.lookupContext(mAppsView.getContext()); 40 } 41 42 /** Invoked when an All Apps {@link RecyclerView} is initialized. */ onInitializeRecyclerView(RecyclerView rv)43 public void onInitializeRecyclerView(RecyclerView rv) { 44 // Do nothing. 45 } 46 47 /** Invoked when search results are updated in All Apps. */ onSearchResultsChanged(List<AdapterItem> results, int searchResultCode)48 public void onSearchResultsChanged(List<AdapterItem> results, int searchResultCode) { 49 // Do nothing. 50 } 51 52 /** Invoked when transition animations to go to search is completed . */ onAnimateToSearchStateCompleted()53 public void onAnimateToSearchStateCompleted() { 54 // Do nothing 55 } 56 57 /** Invoked when the search bar has been added to All Apps. */ onInitializeSearchBar()58 public void onInitializeSearchBar() { 59 // Do nothing. 60 } 61 62 /** Invoked when the search bar has been removed from All Apps. */ onDestroySearchBar()63 public void onDestroySearchBar() { 64 // Do nothing. 65 } 66 67 /** The layout inflater for All Apps and search UI. */ getLayoutInflater()68 public LayoutInflater getLayoutInflater() { 69 return LayoutInflater.from(mAppsView.getContext()); 70 } 71 72 /** Inflate the search bar for All Apps. */ inflateSearchBar()73 public View inflateSearchBar() { 74 return getLayoutInflater().inflate(R.layout.search_container_all_apps, mAppsView, false); 75 } 76 77 /** Whether the search box is floating above the apps surface (inset by the IME). */ isSearchBarFloating()78 public boolean isSearchBarFloating() { 79 return false; 80 } 81 82 /** Creates the adapter provider for the main section. */ createMainAdapterProvider()83 public SearchAdapterProvider<?> createMainAdapterProvider() { 84 return new DefaultSearchAdapterProvider(mActivityContext); 85 } 86 } 87