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