MockSource.java revision 3e44ff1f2a204db3f479698cf0b3eab3d451dec2
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;
23
24/**
25 * Mock implementation of {@link Source}.
26 *
27 */
28public class MockSource implements Source {
29
30    public static final Source SOURCE_1 = new MockSource("SOURCE_1");
31
32    public static final Source SOURCE_2 = new MockSource("SOURCE_2");
33
34    private final String mName;
35
36    public MockSource(String name) {
37        mName = name;
38    }
39
40    public ComponentName getComponentName() {
41        // Not an activity, but no code should treat it as one.
42        return new ComponentName("com.android.quicksearchbox",
43                "com.android.quicksearchbox.MockSource." + mName);
44    }
45
46    public String getDefaultIntentAction() {
47        return null;
48    }
49
50    public String getDefaultIntentData() {
51        return null;
52    }
53
54    public Drawable getIcon(String drawableId) {
55        return null;
56    }
57
58    public Uri getIconUri(String drawableId) {
59        return null;
60    }
61
62    public String getLabel() {
63        return "MockSource " + mName;
64    }
65
66    public int getQueryThreshold() {
67        return 0;
68    }
69
70    public ComponentName getSearchActivity() {
71        // Not an activity, so this will case intent resolution to fail
72        return new ComponentName("com.android.quicksearchbox",
73                "com.android.quicksearchbox.MockSource." + mName + ".Target");
74    }
75
76    public String getSettingsDescription() {
77        return "Suggestions from MockSource " + mName;
78    }
79
80    public Drawable getSourceIcon() {
81        return null;
82    }
83
84    public Uri getSourceIconUri() {
85        return null;
86    }
87
88    public SuggestionCursor getSuggestions(String query, int queryLimit) {
89        if (query.length() == 0) {
90            return null;
91        }
92        DataSuggestionCursor cursor = new DataSuggestionCursor(query);
93        Intent i1 = new Intent(Intent.ACTION_VIEW);
94        i1.setData(Uri.parse("content://com.android.quicksearchbox.MockSource/1"));
95        SuggestionData s1 = new SuggestionData.Builder(this)
96                .text1(query + "_1")
97                .displayQuery(query + "_1")
98                .intent(i1)
99                .build();
100        Intent i2 = new Intent(Intent.ACTION_VIEW);
101        i1.setData(Uri.parse("content://com.android.quicksearchbox.MockSource/2"));
102        SuggestionData s2 = new SuggestionData.Builder(this)
103                .text1(query + "_2")
104                .displayQuery(query + "_2")
105                .intent(i2)
106                .build();
107        cursor.add(s1);
108        cursor.add(s2);
109        return cursor;
110    }
111
112    public boolean isWebSuggestionSource() {
113        return false;
114    }
115
116    public boolean queryAfterZeroResults() {
117        return false;
118    }
119
120    public boolean shouldRewriteQueryFromData() {
121        return false;
122    }
123
124    public boolean shouldRewriteQueryFromText() {
125        return false;
126    }
127
128}
129