• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.google;
17 
18 import com.android.quicksearchbox.AbstractInternalSource;
19 import com.android.quicksearchbox.Config;
20 import com.android.quicksearchbox.CursorBackedSourceResult;
21 import com.android.quicksearchbox.R;
22 import com.android.quicksearchbox.SourceResult;
23 import com.android.quicksearchbox.SuggestionCursor;
24 import com.android.quicksearchbox.util.NamedTaskExecutor;
25 
26 import android.content.ComponentName;
27 import android.content.Context;
28 import android.content.Intent;
29 import android.os.Bundle;
30 import android.os.Handler;
31 
32 /**
33  * Special source implementation for Google suggestions.
34  */
35 public abstract class AbstractGoogleSource extends AbstractInternalSource implements GoogleSource {
36 
37     /*
38      * This name corresponds to what was used in previous version of quick search box. We use the
39      * same name so that shortcuts continue to work after an upgrade. (It also makes logging more
40      * consistent).
41      */
42     private static final String GOOGLE_SOURCE_NAME =
43         "com.android.quicksearchbox/.google.GoogleSearch";
44 
AbstractGoogleSource(Context context, Handler uiThread, NamedTaskExecutor iconLoader)45     public AbstractGoogleSource(Context context, Handler uiThread, NamedTaskExecutor iconLoader) {
46         super(context, uiThread, iconLoader);
47     }
48 
getIntentComponent()49     public abstract ComponentName getIntentComponent();
50 
refreshShortcut(String shortcutId, String extraData)51     public abstract SuggestionCursor refreshShortcut(String shortcutId, String extraData);
52 
53     /**
54      * Called by QSB to get web suggestions for a query.
55      */
queryInternal(String query)56     public abstract SourceResult queryInternal(String query);
57 
58     /**
59      * Called by external apps to get web suggestions for a query.
60      */
queryExternal(String query)61     public abstract SourceResult queryExternal(String query);
62 
createVoiceSearchIntent(Bundle appData)63     public Intent createVoiceSearchIntent(Bundle appData) {
64         return createVoiceWebSearchIntent(appData);
65     }
66 
getDefaultIntentAction()67     public String getDefaultIntentAction() {
68         return Intent.ACTION_WEB_SEARCH;
69     }
70 
getHint()71     public CharSequence getHint() {
72         return getContext().getString(R.string.google_search_hint);
73     }
74 
getLabel()75     public CharSequence getLabel() {
76         return getContext().getString(R.string.google_search_label);
77     }
78 
getName()79     public String getName() {
80         return GOOGLE_SOURCE_NAME;
81     }
82 
getSettingsDescription()83     public CharSequence getSettingsDescription() {
84         return getContext().getString(R.string.google_search_description);
85     }
86 
87     @Override
getSourceIconResource()88     protected int getSourceIconResource() {
89         return R.mipmap.google_icon;
90     }
91 
getSuggestions(String query, int queryLimit, boolean onlySource)92     public SourceResult getSuggestions(String query, int queryLimit, boolean onlySource) {
93         return emptyIfNull(queryInternal(query), query);
94     }
95 
getSuggestionsExternal(String query)96     public SourceResult getSuggestionsExternal(String query) {
97         return emptyIfNull(queryExternal(query), query);
98     }
99 
emptyIfNull(SourceResult result, String query)100     private SourceResult emptyIfNull(SourceResult result, String query) {
101         return result == null ? new CursorBackedSourceResult(this, query) : result;
102     }
103 
voiceSearchEnabled()104     public boolean voiceSearchEnabled() {
105         return true;
106     }
107 
getMaxShortcuts(Config config)108     public int getMaxShortcuts(Config config) {
109         return config.getMaxShortcutsPerWebSource();
110     }
111 
includeInAll()112     public boolean includeInAll() {
113         return true;
114     }
115 
116 }
117