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 17 package com.android.quicksearchbox; 18 19 import android.content.Intent; 20 import android.graphics.drawable.Drawable; 21 import android.net.Uri; 22 import android.os.Bundle; 23 24 import java.util.Collection; 25 import java.util.Collections; 26 27 /** 28 * Mock implementation of {@link Corpus}. 29 * 30 */ 31 public class MockCorpus implements Corpus { 32 33 public static final Corpus CORPUS_1 = new MockCorpus(MockSource.SOURCE_1); 34 35 public static final Corpus CORPUS_2 = new MockCorpus(MockSource.SOURCE_2); 36 37 public static final Corpus WEB_CORPUS = new MockCorpus(MockSource.WEB_SOURCE); 38 39 private final String mName; 40 41 private final Source mSource; 42 43 private final boolean mDefaultEnabled; 44 45 public MockCorpus(Source source) { 46 this(source, true); 47 } 48 49 public MockCorpus(Source source, boolean defaultEnabled) { 50 mName = "corpus_" + source.getName(); 51 mSource = source; 52 mDefaultEnabled = defaultEnabled; 53 } 54 55 public Intent createSearchIntent(String query, Bundle appData) { 56 return null; 57 } 58 59 public Intent createVoiceSearchIntent(Bundle appData) { 60 return null; 61 } 62 63 public Drawable getCorpusIcon() { 64 return null; 65 } 66 67 public Uri getCorpusIconUri() { 68 return null; 69 } 70 71 public CharSequence getLabel() { 72 return mName; 73 } 74 75 public CharSequence getHint() { 76 return null; 77 } 78 79 public String getName() { 80 return mName; 81 } 82 83 public int getQueryThreshold() { 84 return 0; 85 } 86 87 public Collection<Source> getSources() { 88 return Collections.singletonList(mSource); 89 } 90 91 public CharSequence getSettingsDescription() { 92 return null; 93 } 94 95 public CorpusResult getSuggestions(String query, int queryLimit, boolean onlyCorpus) { 96 return new Result(query, mSource.getSuggestions(query, queryLimit, true)); 97 } 98 99 @Override 100 public String toString() { 101 return getName(); 102 } 103 104 @Override 105 public boolean equals(Object o) { 106 if (o != null && o.getClass().equals(this.getClass())) { 107 MockCorpus s = (MockCorpus) o; 108 return s.mName.equals(mName); 109 } 110 return false; 111 } 112 113 @Override 114 public int hashCode() { 115 return mName.hashCode(); 116 } 117 118 private class Result extends SuggestionCursorWrapper implements CorpusResult { 119 public Result(String userQuery, SuggestionCursor cursor) { 120 super(userQuery, cursor); 121 } 122 123 public Corpus getCorpus() { 124 return MockCorpus.this; 125 } 126 127 public int getLatency() { 128 return 0; 129 } 130 } 131 132 public boolean isWebCorpus() { 133 return mSource.getName().equals(MockSource.WEB_SOURCE.getName()); 134 } 135 136 public boolean queryAfterZeroResults() { 137 return false; 138 } 139 140 public boolean voiceSearchEnabled() { 141 return false; 142 } 143 144 public boolean isCorpusDefaultEnabled() { 145 return mDefaultEnabled; 146 } 147 148 public boolean includeInAll() { 149 return true; 150 } 151 152 public boolean isCorpusEnabled() { 153 return true; 154 } 155 156 public boolean isCorpusHidden() { 157 return false; 158 } 159 160 } 161