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.launcher3.allapps.search;
18 
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
22 
23 import com.android.launcher3.allapps.AllAppsGridAdapter;
24 import com.android.launcher3.views.ActivityContext;
25 
26 /**
27  * A UI expansion wrapper providing for search results
28  *
29  * @param <T> Context for this adapter provider.
30  */
31 public abstract class SearchAdapterProvider<T extends ActivityContext> {
32 
33     protected final T mLauncher;
34 
SearchAdapterProvider(T launcher)35     public SearchAdapterProvider(T launcher) {
36         mLauncher = launcher;
37     }
38 
39     /**
40      * Handles selection event on search adapter item. Returns false if provider can not handle
41      * event
42      */
launchHighlightedItem()43     public abstract boolean launchHighlightedItem();
44 
45     /**
46      * Returns the current highlighted view
47      */
getHighlightedItem()48     public abstract View getHighlightedItem();
49 
50     /**
51      * Clear the highlighted view.
52      */
clearHighlightedItem()53     public abstract void clearHighlightedItem();
54 
55     /**
56      * Returns whether or not viewType can be handled by searchProvider
57      */
isViewSupported(int viewType)58     public abstract boolean isViewSupported(int viewType);
59 
60     /**
61      * Called from RecyclerView.Adapter#onBindViewHolder
62      */
onBindView(AllAppsGridAdapter.ViewHolder holder, int position)63     public abstract void onBindView(AllAppsGridAdapter.ViewHolder holder, int position);
64 
65     /**
66      * Called from RecyclerView.Adapter#onCreateViewHolder
67      */
onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup parent, int viewType)68     public abstract AllAppsGridAdapter.ViewHolder onCreateViewHolder(LayoutInflater layoutInflater,
69             ViewGroup parent, int viewType);
70 
71     /**
72      * Returns supported item per row combinations supported
73      */
getSupportedItemsPerRowArray()74     public int[] getSupportedItemsPerRowArray() {
75         return new int[]{};
76     }
77 
78     /**
79      * Returns how many cells a view should span
80      */
getItemsPerRow(int viewType, int appsPerRow)81     public int getItemsPerRow(int viewType, int appsPerRow) {
82         return appsPerRow;
83     }
84 }
85