AllAppsSearchBarController.java revision 5183285847816cee9d0db6a8a7ab1a5929163e4e
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.content.ComponentName;
19import android.graphics.Rect;
20import android.view.View;
21import android.view.ViewGroup;
22
23import com.android.launcher3.util.ComponentKey;
24
25import java.util.ArrayList;
26
27/**
28 * An interface to a search box that AllApps can command.
29 */
30public 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     */
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     */
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     */
54    public abstract View getView(ViewGroup parent);
55
56    /**
57     * Focuses the search field to handle key events.
58     */
59    public abstract void focusSearchField();
60
61    /**
62     * Returns whether the search field is focused.
63     */
64    public abstract boolean isSearchFieldFocused();
65
66    /**
67     * Resets the search bar state.
68     */
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    public abstract boolean shouldShowPredictionBar();
76
77    /**
78     * Callback for getting search results.
79     */
80    public interface Callbacks {
81
82        /**
83         * Called when the bounds of the search bar has changed.
84         */
85        void onBoundsChanged(Rect newBounds);
86
87        /**
88         * Called when the search is complete.
89         *
90         * @param apps sorted list of matching components or null if in case of failure.
91         */
92        void onSearchResult(String query, ArrayList<ComponentKey> apps);
93
94        /**
95         * Called when the search results should be cleared.
96         */
97        void clearSearchResult();
98    }
99}