MockSource.java revision 93bd2e70b8b08da1ec37fd0e990dac05551d2e90
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 Intent.ACTION_SEARCH; 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 boolean isLocationAware() { 109 return false; 110 } 111 112 public SourceResult getSuggestions(String query, int queryLimit, boolean onlySource) { 113 if (query.length() == 0) { 114 return null; 115 } 116 ListSuggestionCursor cursor = new ListSuggestionCursor(query); 117 Intent i1 = new Intent(Intent.ACTION_VIEW); 118 SuggestionData s1 = new SuggestionData(this) 119 .setText1(query + "_1") 120 .setIntentAction(Intent.ACTION_VIEW) 121 .setIntentData("content://" + mName + "/1"); 122 SuggestionData s2 = new SuggestionData(this) 123 .setText1(query + "_2") 124 .setIntentAction(Intent.ACTION_VIEW) 125 .setIntentData("content://" + mName + "/2"); 126 cursor.add(s1); 127 cursor.add(s2); 128 return new Result(query, cursor); 129 } 130 131 @Override 132 public boolean equals(Object o) { 133 if (o != null && o.getClass().equals(this.getClass())) { 134 MockSource s = (MockSource) o; 135 return s.mName.equals(mName); 136 } 137 return false; 138 } 139 140 @Override 141 public int hashCode() { 142 return mName.hashCode(); 143 } 144 145 @Override 146 public String toString() { 147 return getName() + ":" + getVersionCode(); 148 } 149 150 private class Result extends SuggestionCursorWrapper implements SourceResult { 151 152 public Result(String userQuery, SuggestionCursor cursor) { 153 super(userQuery, cursor); 154 } 155 156 public Source getSource() { 157 return MockSource.this; 158 } 159 160 } 161 162 public SuggestionCursor refreshShortcut(String shortcutId, String extraData) { 163 return null; 164 } 165 166 public boolean isExternal() { 167 return false; 168 } 169 170 public boolean isWebSuggestionSource() { 171 return false; 172 } 173 174 public boolean queryAfterZeroResults() { 175 return false; 176 } 177 178 public Intent createSearchIntent(String query, Bundle appData) { 179 return null; 180 } 181 182 public SuggestionData createSearchShortcut(String query) { 183 return null; 184 } 185 186 public Intent createVoiceSearchIntent(Bundle appData) { 187 return null; 188 } 189 190 public boolean voiceSearchEnabled() { 191 return false; 192 } 193 194} 195