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