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