Home | History | Annotate | Download | only in quicksearchbox
      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 extends AbstractCorpus {
     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     public MockCorpus(Source source) {
     42         mName = "corpus_" + source.getName();
     43         mSource = source;
     44     }
     45 
     46     public Intent createSearchIntent(String query, Bundle appData) {
     47         return null;
     48     }
     49 
     50     public Intent createVoiceSearchIntent(Bundle appData) {
     51         return null;
     52     }
     53 
     54     public SuggestionData createSearchShortcut(String query) {
     55         return null;
     56     }
     57 
     58     public Drawable getCorpusIcon() {
     59         return null;
     60     }
     61 
     62     public Uri getCorpusIconUri() {
     63         return null;
     64     }
     65 
     66     public CharSequence getLabel() {
     67         return mName;
     68     }
     69 
     70     public CharSequence getHint() {
     71         return null;
     72     }
     73 
     74     public String getName() {
     75         return mName;
     76     }
     77 
     78     public int getQueryThreshold() {
     79         return 0;
     80     }
     81 
     82     public Collection<Source> getSources() {
     83         return Collections.singletonList(mSource);
     84     }
     85 
     86     public CharSequence getSettingsDescription() {
     87         return null;
     88     }
     89 
     90     public CorpusResult getSuggestions(String query, int queryLimit) {
     91         return new Result(query, mSource.getSuggestions(query, queryLimit));
     92     }
     93 
     94     @Override
     95     public boolean equals(Object o) {
     96         if (o != null && o.getClass().equals(this.getClass())) {
     97             MockCorpus s = (MockCorpus) o;
     98             return s.mName.equals(mName);
     99         }
    100         return false;
    101     }
    102 
    103     @Override
    104     public int hashCode() {
    105         return mName.hashCode();
    106     }
    107 
    108     private class Result extends SuggestionCursorWrapper implements CorpusResult {
    109         public Result(String userQuery, SuggestionCursor cursor) {
    110             super(userQuery, cursor);
    111         }
    112 
    113         public Corpus getCorpus() {
    114             return MockCorpus.this;
    115         }
    116 
    117         public int getLatency() {
    118             return 0;
    119         }
    120     }
    121 
    122     public boolean isWebCorpus() {
    123         return false;
    124     }
    125 
    126     public boolean queryAfterZeroResults() {
    127         return false;
    128     }
    129 
    130     public boolean voiceSearchEnabled() {
    131         return false;
    132     }
    133 
    134 }
    135