Home | History | Annotate | Download | only in ui
      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.Promoter;
     19 import com.android.quicksearchbox.SuggestionCursor;
     20 import com.android.quicksearchbox.SuggestionPosition;
     21 import com.android.quicksearchbox.Suggestions;
     22 
     23 import android.view.View.OnFocusChangeListener;
     24 import android.widget.ExpandableListAdapter;
     25 import android.widget.ListAdapter;
     26 
     27 /**
     28  * Interface for suggestions adapters.
     29  *
     30  * @param <A> the adapter class used by the UI, probably either {@link ListAdapter} or
     31  *      {@link ExpandableListAdapter}.
     32  */
     33 public interface SuggestionsAdapter<A> {
     34 
     35     /**
     36      * Sets the maximum number of promoted suggestions to be provided by this adapter.
     37      */
     38     void setMaxPromoted(int maxPromoted);
     39 
     40     /**
     41      * Sets the suggestion promoter.
     42      */
     43     void setPromoter(Promoter promoter);
     44 
     45     /**
     46      * Sets the listener to be notified of clicks on suggestions.
     47      */
     48     void setSuggestionClickListener(SuggestionClickListener listener);
     49 
     50     /**
     51      * Sets the listener to be notified of focus change events on suggestion views.
     52      */
     53     void setOnFocusChangeListener(OnFocusChangeListener l);
     54 
     55     /**
     56      * Sets the current suggestions.
     57      */
     58     void setSuggestions(Suggestions suggestions);
     59 
     60     /**
     61      * Indicates if there's any suggestions in this adapter.
     62      */
     63     boolean isEmpty();
     64 
     65     /**
     66      * Gets the current suggestions.
     67      */
     68     Suggestions getSuggestions();
     69 
     70     /**
     71      * Gets the cursor and position corresponding to the given suggestion ID.
     72      * @param suggestionId Suggestion ID.
     73      */
     74     SuggestionPosition getSuggestion(long suggestionId);
     75 
     76     /**
     77      * Gets the current list of promoted suggestions.
     78      */
     79     SuggestionCursor getCurrentPromotedSuggestions();
     80 
     81     /**
     82      * Handles a regular click on a suggestion.
     83      *
     84      * @param suggestionId The ID of the suggestion clicked. If the suggestion list is flat, this
     85      *      will be the position within the list.
     86      */
     87     void onSuggestionClicked(long suggestionId);
     88 
     89     /**
     90      * Handles a click on a quick contact badge.
     91      *
     92      * @param suggestionId The ID of the suggestion clicked. If the suggestion list is flat, this
     93      *      will be the position within the list.
     94      */
     95     void onSuggestionQuickContactClicked(long suggestionId);
     96 
     97     /**
     98      * Handles a request to remove a suggestion from history.
     99      *
    100      * @param suggestionId The ID of the suggestion clicked. If the suggestion list is flat, this
    101      *      will be the position within the list.
    102      */
    103     void onSuggestionRemoveFromHistoryClicked(long suggestionId);
    104 
    105     /**
    106      * Handles a click on the query refinement button.
    107      *
    108      * @param suggestionId The ID of the suggestion clicked. If the suggestion list is flat, this
    109      *      will be the position within the list.
    110      */
    111     void onSuggestionQueryRefineClicked(long suggestionId);
    112 
    113     /**
    114      * Gets the adapter to be used by the UI view.
    115      */
    116     A getListAdapter();
    117 
    118 }
    119