1 /* 2 * Copyright (C) 2015 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; 17 18 import android.content.ComponentName; 19 import android.graphics.Rect; 20 import android.view.View; 21 import android.view.ViewGroup; 22 23 import com.android.launcher3.util.ComponentKey; 24 25 import java.util.ArrayList; 26 27 /** 28 * An interface to a search box that AllApps can command. 29 */ 30 public abstract class AllAppsSearchBarController { 31 32 protected AlphabeticalAppsList mApps; 33 protected Callbacks mCb; 34 35 /** 36 * Sets the references to the apps model and the search result callback. 37 */ initialize(AlphabeticalAppsList apps, Callbacks cb)38 public final void initialize(AlphabeticalAppsList apps, Callbacks cb) { 39 mApps = apps; 40 mCb = cb; 41 onInitialize(); 42 } 43 44 /** 45 * To be overridden by subclasses. This method will get called when the controller is set, 46 * before getView(). 47 */ onInitialize()48 protected abstract void onInitialize(); 49 50 /** 51 * Returns the search bar view. 52 * @param parent the parent to attach the search bar view to. 53 */ getView(ViewGroup parent)54 public abstract View getView(ViewGroup parent); 55 56 /** 57 * Focuses the search field to handle key events. 58 */ focusSearchField()59 public abstract void focusSearchField(); 60 61 /** 62 * Returns whether the search field is focused. 63 */ isSearchFieldFocused()64 public abstract boolean isSearchFieldFocused(); 65 66 /** 67 * Resets the search bar state. 68 */ reset()69 public abstract void reset(); 70 71 /** 72 * Returns whether the prediction bar should currently be visible depending on the state of 73 * the search bar. 74 */ 75 @Deprecated shouldShowPredictionBar()76 public abstract boolean shouldShowPredictionBar(); 77 78 /** 79 * Callback for getting search results. 80 */ 81 public interface Callbacks { 82 83 /** 84 * Called when the bounds of the search bar has changed. 85 */ onBoundsChanged(Rect newBounds)86 void onBoundsChanged(Rect newBounds); 87 88 /** 89 * Called when the search is complete. 90 * 91 * @param apps sorted list of matching components or null if in case of failure. 92 */ onSearchResult(String query, ArrayList<ComponentKey> apps)93 void onSearchResult(String query, ArrayList<ComponentKey> apps); 94 95 /** 96 * Called when the search results should be cleared. 97 */ clearSearchResult()98 void clearSearchResult(); 99 } 100 }