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