• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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;
18 
19 import android.content.ComponentName;
20 import android.content.Intent;
21 import android.graphics.drawable.Drawable;
22 import android.net.Uri;
23 import android.os.Bundle;
24 
25 /**
26  * Mock implementation of {@link Source}.
27  *
28  */
29 public class MockSource implements Source {
30 
31     public static final MockSource SOURCE_1 = new MockSource("SOURCE_1");
32 
33     public static final MockSource SOURCE_2 = new MockSource("SOURCE_2");
34 
35     public static final MockSource SOURCE_3 = new MockSource("SOURCE_3");
36 
37     public static final MockSource WEB_SOURCE = new MockSource("WEB") {
38         @Override
39         public boolean isWebSuggestionSource() {
40             return true;
41         }
42     };
43 
44     private final String mName;
45 
46     private final int mVersionCode;
47 
MockSource(String name)48     public MockSource(String name) {
49         this(name, 0);
50     }
51 
MockSource(String name, int versionCode)52     public MockSource(String name, int versionCode) {
53         mName = name;
54         mVersionCode = versionCode;
55     }
56 
getIntentComponent()57     public ComponentName getIntentComponent() {
58         // Not an activity, but no code should treat it as one.
59         return new ComponentName("com.android.quicksearchbox",
60                 getClass().getName() + "." + mName);
61     }
62 
getVersionCode()63     public int getVersionCode() {
64         return mVersionCode;
65     }
66 
isVersionCodeCompatible(int version)67     public boolean isVersionCodeCompatible(int version) {
68         return version == mVersionCode;
69     }
70 
getName()71     public String getName() {
72         return getIntentComponent().flattenToShortString();
73     }
74 
getDefaultIntentAction()75     public String getDefaultIntentAction() {
76         return Intent.ACTION_SEARCH;
77     }
78 
getDefaultIntentData()79     public String getDefaultIntentData() {
80         return null;
81     }
82 
getIcon(String drawableId)83     public Drawable getIcon(String drawableId) {
84         return null;
85     }
86 
getIconUri(String drawableId)87     public Uri getIconUri(String drawableId) {
88         return null;
89     }
90 
getLabel()91     public String getLabel() {
92         return "MockSource " + mName;
93     }
94 
getQueryThreshold()95     public int getQueryThreshold() {
96         return 0;
97     }
98 
getHint()99     public CharSequence getHint() {
100         return null;
101     }
102 
getSettingsDescription()103     public String getSettingsDescription() {
104         return "Suggestions from MockSource " + mName;
105     }
106 
getSourceIcon()107     public Drawable getSourceIcon() {
108         return null;
109     }
110 
getSourceIconUri()111     public Uri getSourceIconUri() {
112         return null;
113     }
114 
canRead()115     public boolean canRead() {
116         return true;
117     }
118 
isLocationAware()119     public boolean isLocationAware() {
120         return false;
121     }
122 
getSuggestions(String query, int queryLimit, boolean onlySource)123     public SourceResult getSuggestions(String query, int queryLimit, boolean onlySource) {
124         if (query.length() == 0) {
125             return null;
126         }
127         ListSuggestionCursor cursor = new ListSuggestionCursor(query);
128         cursor.add(createSuggestion(query + "_1"));
129         cursor.add(createSuggestion(query + "_2"));
130         return new Result(query, cursor);
131     }
132 
createSuggestion(String query)133     public Suggestion createSuggestion(String query) {
134         Uri data = new Uri.Builder().scheme("content").authority(mName).path(query).build();
135         return new SuggestionData(this)
136                 .setText1(query)
137                 .setIntentAction(Intent.ACTION_VIEW)
138                 .setIntentData(data.toString());
139     }
140 
141     @Override
equals(Object o)142     public boolean equals(Object o) {
143         if (o != null && o.getClass().equals(this.getClass())) {
144             MockSource s = (MockSource) o;
145             return s.mName.equals(mName);
146         }
147         return false;
148     }
149 
150     @Override
hashCode()151     public int hashCode() {
152         return mName.hashCode();
153     }
154 
155     @Override
toString()156     public String toString() {
157         return getName() + ":" + getVersionCode();
158     }
159 
160     private class Result extends SuggestionCursorWrapper implements SourceResult {
161 
Result(String userQuery, SuggestionCursor cursor)162         public Result(String userQuery, SuggestionCursor cursor) {
163             super(userQuery, cursor);
164         }
165 
getSource()166         public Source getSource() {
167             return MockSource.this;
168         }
169 
170     }
171 
refreshShortcut(String shortcutId, String extraData)172     public SuggestionCursor refreshShortcut(String shortcutId, String extraData) {
173         return null;
174     }
175 
isExternal()176     public boolean isExternal() {
177         return false;
178     }
179 
isWebSuggestionSource()180     public boolean isWebSuggestionSource() {
181         return false;
182     }
183 
queryAfterZeroResults()184     public boolean queryAfterZeroResults() {
185         return false;
186     }
187 
createSearchIntent(String query, Bundle appData)188     public Intent createSearchIntent(String query, Bundle appData) {
189         return null;
190     }
191 
createSearchShortcut(String query)192     public SuggestionData createSearchShortcut(String query) {
193         return null;
194     }
195 
createVoiceSearchIntent(Bundle appData)196     public Intent createVoiceSearchIntent(Bundle appData) {
197         return null;
198     }
199 
voiceSearchEnabled()200     public boolean voiceSearchEnabled() {
201         return false;
202     }
203 
204 }
205