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 package com.android.launcher3.allapps.search; 17 18 import android.graphics.Canvas; 19 import android.view.LayoutInflater; 20 import android.view.View; 21 import android.view.ViewGroup; 22 23 import androidx.annotation.NonNull; 24 import androidx.recyclerview.widget.RecyclerView; 25 26 import com.android.launcher3.BaseDraggingActivity; 27 import com.android.launcher3.BubbleTextView; 28 import com.android.launcher3.allapps.AllAppsContainerView; 29 import com.android.launcher3.allapps.AllAppsGridAdapter; 30 import com.android.launcher3.model.data.ItemInfo; 31 32 /** 33 * Provides views for local search results 34 */ 35 public class DefaultSearchAdapterProvider extends SearchAdapterProvider { 36 37 private final RecyclerView.ItemDecoration mDecoration; 38 private View mHighlightedView; 39 DefaultSearchAdapterProvider(BaseDraggingActivity launcher, AllAppsContainerView appsContainerView)40 public DefaultSearchAdapterProvider(BaseDraggingActivity launcher, 41 AllAppsContainerView appsContainerView) { 42 super(launcher, appsContainerView); 43 mDecoration = new RecyclerView.ItemDecoration() { 44 @Override 45 public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, 46 @NonNull RecyclerView.State state) { 47 super.onDraw(c, parent, state); 48 } 49 }; 50 } 51 52 @Override onBindView(AllAppsGridAdapter.ViewHolder holder, int position)53 public void onBindView(AllAppsGridAdapter.ViewHolder holder, int position) { 54 if (position == 0) { 55 mHighlightedView = holder.itemView; 56 } 57 } 58 59 @Override isViewSupported(int viewType)60 public boolean isViewSupported(int viewType) { 61 return false; 62 } 63 64 @Override onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup parent, int viewType)65 public AllAppsGridAdapter.ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, 66 ViewGroup parent, int viewType) { 67 return null; 68 } 69 70 @Override launchHighlightedItem()71 public boolean launchHighlightedItem() { 72 if (mHighlightedView instanceof BubbleTextView 73 && mHighlightedView.getTag() instanceof ItemInfo) { 74 ItemInfo itemInfo = (ItemInfo) mHighlightedView.getTag(); 75 return mLauncher.startActivitySafely(mHighlightedView, itemInfo.getIntent(), itemInfo); 76 } 77 return false; 78 } 79 80 @Override getHighlightedItem()81 public View getHighlightedItem() { 82 return mHighlightedView; 83 } 84 85 @Override getDecorator()86 public RecyclerView.ItemDecoration getDecorator() { 87 return mDecoration; 88 } 89 } 90