MockSource.java revision 94e8a2be78530170f50e7895a558bf8011bbf8e8
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 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 String getSettingsDescription() { 75 return "Suggestions from MockSource " + mName; 76 } 77 78 public Drawable getSourceIcon() { 79 return null; 80 } 81 82 public Uri getSourceIconUri() { 83 return null; 84 } 85 86 public SuggestionCursor getSuggestions(String query, int queryLimit) { 87 if (query.length() == 0) { 88 return null; 89 } 90 DataSuggestionCursor cursor = new DataSuggestionCursor(query); 91 Intent i1 = new Intent(Intent.ACTION_VIEW); 92 i1.setData(Uri.parse("content://" + getClass().getName() + "/1")); 93 SuggestionData s1 = new SuggestionData(this); 94 s1.setText1(query + "_1"); 95 s1.setDisplayQuery(query + "_1"); 96 s1.setIntent(i1); 97 Intent i2 = new Intent(Intent.ACTION_VIEW); 98 i1.setData(Uri.parse("content://" + getClass().getName() + "/1")); 99 SuggestionData s2 = new SuggestionData(this); 100 s2.setText1(query + "_2"); 101 s2.setDisplayQuery(query + "_2"); 102 s2.setIntent(i2); 103 cursor.add(s1); 104 cursor.add(s2); 105 return cursor; 106 } 107 108 public SuggestionCursor refreshShortcut(String shortcutId, String extraData) { 109 return null; 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 public String getSuggestActionMsg(int keyCode) { 129 return null; 130 } 131 132 public String getSuggestActionMsgColumn(int keyCode) { 133 return null; 134 } 135 136} 137