1 /* 2 * Copyright (C) 2010 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.quicksearchbox.ui; 17 18 import com.android.quicksearchbox.SuggestionCursor; 19 import com.android.quicksearchbox.SuggestionPosition; 20 import com.android.quicksearchbox.Suggestions; 21 22 import android.view.View.OnFocusChangeListener; 23 import android.widget.ExpandableListAdapter; 24 import android.widget.ListAdapter; 25 26 /** 27 * Interface for suggestions adapters. 28 * 29 * @param <A> the adapter class used by the UI, probably either {@link ListAdapter} or 30 * {@link ExpandableListAdapter}. 31 */ 32 public interface SuggestionsAdapter<A> { 33 34 /** 35 * Sets the listener to be notified of clicks on suggestions. 36 */ setSuggestionClickListener(SuggestionClickListener listener)37 void setSuggestionClickListener(SuggestionClickListener listener); 38 39 /** 40 * Sets the listener to be notified of focus change events on suggestion views. 41 */ setOnFocusChangeListener(OnFocusChangeListener l)42 void setOnFocusChangeListener(OnFocusChangeListener l); 43 44 /** 45 * Sets the current suggestions. 46 */ setSuggestions(Suggestions suggestions)47 void setSuggestions(Suggestions suggestions); 48 49 /** 50 * Indicates if there's any suggestions in this adapter. 51 */ isEmpty()52 boolean isEmpty(); 53 54 /** 55 * Gets the current suggestions. 56 */ getSuggestions()57 Suggestions getSuggestions(); 58 59 /** 60 * Gets the cursor and position corresponding to the given suggestion ID. 61 * @param suggestionId Suggestion ID. 62 */ getSuggestion(long suggestionId)63 SuggestionPosition getSuggestion(long suggestionId); 64 65 /** 66 * Handles a regular click on a suggestion. 67 * 68 * @param suggestionId The ID of the suggestion clicked. If the suggestion list is flat, this 69 * will be the position within the list. 70 */ onSuggestionClicked(long suggestionId)71 void onSuggestionClicked(long suggestionId); 72 73 /** 74 * Handles a click on the query refinement button. 75 * 76 * @param suggestionId The ID of the suggestion clicked. If the suggestion list is flat, this 77 * will be the position within the list. 78 */ onSuggestionQueryRefineClicked(long suggestionId)79 void onSuggestionQueryRefineClicked(long suggestionId); 80 81 /** 82 * Gets the adapter to be used by the UI view. 83 */ getListAdapter()84 A getListAdapter(); 85 86 } 87