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 package com.android.quicksearchbox
17 
18 import android.content.ComponentName
19 import android.content.Intent
20 import android.graphics.drawable.Drawable
21 import android.net.Uri
22 import android.os.Bundle
23 import com.android.quicksearchbox.util.NowOrLater
24 
25 /** Interface for suggestion sources. */
26 interface Source : SuggestionCursorProvider<com.android.quicksearchbox.SourceResult?> {
27   /** Gets the name activity that intents from this source are sent to. */
28   val intentComponent: ComponentName?
29 
30   /** Gets the suggestion URI for getting suggestions from this Source. */
31   val suggestUri: String?
32 
33   /** Gets the localized, human-readable label for this source. */
34   val label: CharSequence?
35 
36   /** Gets the icon for this suggestion source. */
37   val sourceIcon: Drawable?
38 
39   /** Gets the icon URI for this suggestion source. */
40   val sourceIconUri: Uri?
41 
42   /**
43    * Gets an icon from this suggestion source.
44    *
45    * @param drawableId Resource ID or URI.
46    */
getIconnull47   fun getIcon(drawableId: String?): NowOrLater<Drawable?>?
48 
49   /**
50    * Gets the URI for an icon form this suggestion source.
51    *
52    * @param drawableId Resource ID or URI.
53    */
54   fun getIconUri(drawableId: String?): Uri?
55 
56   /** Gets the search hint text for this suggestion source. */
57   val hint: CharSequence?
58 
59   /** Gets the description to use for this source in system search settings. */
60   val settingsDescription: CharSequence?
61 
62   /**
63    *
64    * Note: this does not guarantee that this source will be queried for queries of this length or
65    * longer, only that it will not be queried for anything shorter.
66    *
67    * @return The minimum number of characters needed to trigger this source.
68    */
69   val queryThreshold: Int
70 
71   /**
72    * Indicates whether a source should be invoked for supersets of queries it has returned zero
73    * results for in the past. For example, if a source returned zero results for "bo", it would be
74    * ignored for "bob".
75    *
76    * If set to `false`, this source will only be ignored for a single session; the next time the
77    * search dialog is brought up, all sources will be queried.
78    *
79    * @return `true` if this source should be queried after returning no results.
80    */
81   fun queryAfterZeroResults(): Boolean
82   fun voiceSearchEnabled(): Boolean
83 
84   /**
85    * Whether this source should be included in the blended All mode. The source must also be enabled
86    * to be included in All.
87    */
88   fun includeInAll(): Boolean
89   fun createSearchIntent(query: String?, appData: Bundle?): Intent?
90   fun createVoiceSearchIntent(appData: Bundle?): Intent?
91 
92   /** Checks if the current process can read the suggestions from this source. */
93   fun canRead(): Boolean
94 
95   /**
96    * Gets suggestions from this source.
97    *
98    * @param query The user query.
99    * @return The suggestion results.
100    */
101   @Override override fun getSuggestions(query: String?, queryLimit: Int): SourceResult?
102 
103   /**
104    * Gets the default intent action for suggestions from this source.
105    *
106    * @return The default intent action, or `null`.
107    */
108   val defaultIntentAction: String?
109 
110   /**
111    * Gets the default intent data for suggestions from this source.
112    *
113    * @return The default intent data, or `null`.
114    */
115   val defaultIntentData: String?
116 
117   /**
118    * Gets the root source, if this source is a wrapper around another. Otherwise, returns this
119    * source.
120    */
121   fun getRoot(): Source
122 }
123