GoogleSource.java revision 93bd2e70b8b08da1ec37fd0e990dac05551d2e90
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.AbstractSource; 19import com.android.quicksearchbox.CursorBackedSourceResult; 20import com.android.quicksearchbox.QsbApplication; 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.graphics.drawable.Drawable; 29import android.net.Uri; 30import android.os.Bundle; 31 32/** 33 * Special source implementation for Google suggestions. 34 */ 35public class GoogleSource extends AbstractSource { 36 37 private static final String GOOGLE_SOURCE_NAME = "google"; 38 39 private final GoogleClient mClient; 40 41 public GoogleSource(Context context) { 42 super(context); 43 mClient = createGoogleClient(); 44 } 45 46 protected GoogleClient createGoogleClient() { 47 return new GoogleSuggestClient(getContext(), this); 48 } 49 50 public boolean canRead() { 51 return true; 52 } 53 54 public Intent createVoiceSearchIntent(Bundle appData) { 55 return createVoiceWebSearchIntent(appData); 56 } 57 58 public String getDefaultIntentAction() { 59 return Intent.ACTION_WEB_SEARCH; 60 } 61 62 public String getDefaultIntentData() { 63 return null; 64 } 65 66 public CharSequence getHint() { 67 return getContext().getString(R.string.google_search_hint); 68 } 69 70 @Override 71 protected String getIconPackage() { 72 return getContext().getPackageName(); 73 } 74 75 public ComponentName getIntentComponent() { 76 return mClient.getIntentComponent(); 77 } 78 79 public CharSequence getLabel() { 80 return getContext().getString(R.string.google_search_label); 81 } 82 83 public String getName() { 84 return GOOGLE_SOURCE_NAME; 85 } 86 87 public int getQueryThreshold() { 88 return 0; 89 } 90 91 public CharSequence getSettingsDescription() { 92 return getContext().getString(R.string.google_search_description); 93 } 94 95 public Drawable getSourceIcon() { 96 return getContext().getResources().getDrawable(getSourceIconResource()); 97 } 98 99 public Uri getSourceIconUri() { 100 return Uri.parse("android.resource://" + getContext().getPackageName() 101 + "/" + getSourceIconResource()); 102 } 103 104 private int getSourceIconResource() { 105 return R.drawable.google_icon; 106 } 107 108 public SourceResult getSuggestions(String query, int queryLimit, boolean onlySource) { 109 SourceResult result = mClient.query(query); 110 if (result == null) { 111 // getSuggestions() should never return null 112 return new CursorBackedSourceResult(this, query); 113 } else { 114 return result; 115 } 116 } 117 118 public int getVersionCode() { 119 return QsbApplication.get(getContext()).getVersionCode(); 120 } 121 122 public boolean queryAfterZeroResults() { 123 return true; 124 } 125 126 public SuggestionCursor refreshShortcut(String shortcutId, String extraData) { 127 return mClient.refreshShortcut(shortcutId, extraData); 128 } 129 130 public boolean voiceSearchEnabled() { 131 return true; 132 } 133 134 public boolean isWebSuggestionSource() { 135 return true; 136 } 137 138 public boolean isLocationAware() { 139 return mClient.isLocationAware(); 140 } 141 142} 143