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 
     17 package com.android.quicksearchbox.ui;
     18 
     19 import com.android.quicksearchbox.Suggestion;
     20 import com.android.quicksearchbox.SuggestionCursor;
     21 
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 
     25 import java.util.Collection;
     26 
     27 /**
     28  * Factory interface for suggestion views.
     29  */
     30 public interface SuggestionViewFactory {
     31 
     32     /**
     33      * Returns all the view types that are used by this factory. Each view type corresponds to a
     34      * specific layout that is used to display suggestions. The returned set must have at least one
     35      * item in it.
     36      *
     37      * View types must be unique across all suggestion view factories.
     38      */
     39     Collection<String> getSuggestionViewTypes();
     40 
     41     /**
     42      * Returns the view type to be used for displaying the given suggestion. This MUST correspond to
     43      * one of the view types returned by {@link #getSuggestionViewTypes()}.
     44      */
     45     String getViewType(Suggestion suggestion);
     46 
     47     /**
     48      * Gets a view corresponding to the current suggestion in the given cursor.
     49      *
     50      * @param convertView The old view to reuse, if possible. Note: You should check that this view
     51      *        is non-null and of an appropriate type before using. If it is not possible to convert
     52      *        this view to display the correct data, this method can create a new view.
     53      * @param parent The parent that this view will eventually be attached to
     54      * @return A View corresponding to the data within this suggestion.
     55      */
     56     View getView(SuggestionCursor suggestion, String userQuery, View convertView, ViewGroup parent);
     57 
     58     /**
     59      * Checks whether this factory can create views for the given suggestion.
     60      */
     61     boolean canCreateView(Suggestion suggestion);
     62 
     63 }
     64