MockSource.java revision f252dc7a25ba08b973ecc1cfbbce58eb78d42167
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 public MockSource(String name) { 40 mName = name; 41 } 42 43 public ComponentName getComponentName() { 44 // Not an activity, but no code should treat it as one. 45 return new ComponentName("com.android.quicksearchbox", 46 getClass().getName() + "." + mName); 47 } 48 49 public String getName() { 50 return getComponentName().flattenToShortString(); 51 } 52 53 public String getDefaultIntentAction() { 54 return null; 55 } 56 57 public String getDefaultIntentData() { 58 return null; 59 } 60 61 public Drawable getIcon(String drawableId) { 62 return null; 63 } 64 65 public Uri getIconUri(String drawableId) { 66 return null; 67 } 68 69 public String getLabel() { 70 return "MockSource " + mName; 71 } 72 73 public int getQueryThreshold() { 74 return 0; 75 } 76 77 public CharSequence getHint() { 78 return null; 79 } 80 81 public String getSettingsDescription() { 82 return "Suggestions from MockSource " + mName; 83 } 84 85 public Drawable getSourceIcon() { 86 return null; 87 } 88 89 public Uri getSourceIconUri() { 90 return null; 91 } 92 93 public SourceResult getSuggestions(String query, int queryLimit) { 94 if (query.length() == 0) { 95 return null; 96 } 97 DataSuggestionCursor cursor = new DataSuggestionCursor(query); 98 Intent i1 = new Intent(Intent.ACTION_VIEW); 99 SuggestionData s1 = new SuggestionData(this) 100 .setText1(query + "_1") 101 .setIntentAction(Intent.ACTION_VIEW) 102 .setIntentData("content://" + getClass().getName() + "/1"); 103 SuggestionData s2 = new SuggestionData(this) 104 .setText1(query + "_2") 105 .setIntentAction(Intent.ACTION_VIEW) 106 .setIntentData("content://" + getClass().getName() + "/2"); 107 cursor.add(s1); 108 cursor.add(s2); 109 return new Result(query, cursor); 110 } 111 112 private class Result extends SuggestionCursorWrapper implements SourceResult { 113 114 public Result(String userQuery, SuggestionCursor cursor) { 115 super(userQuery, cursor); 116 } 117 118 public Source getSource() { 119 return MockSource.this; 120 } 121 122 } 123 124 public SuggestionCursor refreshShortcut(String shortcutId, String extraData) { 125 return null; 126 } 127 128 public boolean isWebSuggestionSource() { 129 return false; 130 } 131 132 public boolean queryAfterZeroResults() { 133 return false; 134 } 135 136 public boolean shouldRewriteQueryFromData() { 137 return false; 138 } 139 140 public boolean shouldRewriteQueryFromText() { 141 return false; 142 } 143 144 public String getSuggestActionMsg(int keyCode) { 145 return null; 146 } 147 148 public String getSuggestActionMsgColumn(int keyCode) { 149 return null; 150 } 151 152 public Intent createSearchIntent(String query, Bundle appData) { 153 return null; 154 } 155 156 public SuggestionData createSearchShortcut(String query) { 157 return null; 158 } 159 160 public Intent createVoiceSearchIntent(Bundle appData) { 161 return null; 162 } 163 164 public boolean voiceSearchEnabled() { 165 return false; 166 } 167 168} 169