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