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