MockSource.java revision d32d6753347e872aa5d9d6e9015ed7f24db3e362
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 getFlattenedComponentName() { 47 return getComponentName().flattenToShortString(); 48 } 49 50 public String getDefaultIntentAction() { 51 return null; 52 } 53 54 public String getDefaultIntentData() { 55 return null; 56 } 57 58 public Drawable getIcon(String drawableId) { 59 return null; 60 } 61 62 public Uri getIconUri(String drawableId) { 63 return null; 64 } 65 66 public String getLabel() { 67 return "MockSource " + mName; 68 } 69 70 public int getQueryThreshold() { 71 return 0; 72 } 73 74 public ComponentName getSearchActivity() { 75 // Not an activity, so this will case intent resolution to fail 76 return new ComponentName("com.android.quicksearchbox", 77 "com.android.quicksearchbox.MockSource." + mName + ".Target"); 78 } 79 80 public String getSettingsDescription() { 81 return "Suggestions from MockSource " + mName; 82 } 83 84 public Drawable getSourceIcon() { 85 return null; 86 } 87 88 public Uri getSourceIconUri() { 89 return null; 90 } 91 92 public SuggestionCursor getSuggestions(String query, int queryLimit) { 93 if (query.length() == 0) { 94 return null; 95 } 96 DataSuggestionCursor cursor = new DataSuggestionCursor(query); 97 Intent i1 = new Intent(Intent.ACTION_VIEW); 98 i1.setData(Uri.parse("content://com.android.quicksearchbox.MockSource/1")); 99 SuggestionData s1 = new SuggestionData(this); 100 s1.setText1(query + "_1"); 101 s1.setDisplayQuery(query + "_1"); 102 s1.setIntent(i1); 103 Intent i2 = new Intent(Intent.ACTION_VIEW); 104 i1.setData(Uri.parse("content://com.android.quicksearchbox.MockSource/2")); 105 SuggestionData s2 = new SuggestionData(this); 106 s2.setText1(query + "_2"); 107 s2.setDisplayQuery(query + "_2"); 108 s2.setIntent(i2); 109 cursor.add(s1); 110 cursor.add(s2); 111 return cursor; 112 } 113 114 public boolean isWebSuggestionSource() { 115 return false; 116 } 117 118 public boolean queryAfterZeroResults() { 119 return false; 120 } 121 122 public boolean shouldRewriteQueryFromData() { 123 return false; 124 } 125 126 public boolean shouldRewriteQueryFromText() { 127 return false; 128 } 129 130 public String getSuggestActionMsg(int keyCode) { 131 return null; 132 } 133 134 public String getSuggestActionMsgColumn(int keyCode) { 135 return null; 136 } 137 138} 139