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