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.Context;
20import android.content.Intent;
21import android.graphics.drawable.Drawable;
22import android.net.Uri;
23import android.os.Bundle;
24
25import java.util.Collection;
26import java.util.Collections;
27
28/**
29 * A corpus that uses a single source.
30 */
31public class SingleSourceCorpus extends AbstractCorpus {
32
33    private final Source mSource;
34
35    public SingleSourceCorpus(Context context, Config config, Source source) {
36        super(context, config);
37        mSource = source;
38    }
39
40    public Drawable getCorpusIcon() {
41        return mSource.getSourceIcon();
42    }
43
44    public Uri getCorpusIconUri() {
45        return mSource.getSourceIconUri();
46    }
47
48    public CharSequence getLabel() {
49        return mSource.getLabel();
50    }
51
52    public CharSequence getHint() {
53        return mSource.getHint();
54    }
55
56    public CharSequence getSettingsDescription() {
57        return mSource.getSettingsDescription();
58    }
59
60    public CorpusResult getSuggestions(String query, int queryLimit, boolean onlyCorpus) {
61        LatencyTracker latencyTracker = new LatencyTracker();
62        SourceResult sourceResult = mSource.getSuggestions(query, queryLimit, true);
63        int latency = latencyTracker.getLatency();
64        return new SingleSourceCorpusResult(this, query, sourceResult, latency);
65    }
66
67    public String getName() {
68        return mSource.getName();
69    }
70
71    public boolean queryAfterZeroResults() {
72        return mSource.queryAfterZeroResults();
73    }
74
75    public int getQueryThreshold() {
76        return mSource.getQueryThreshold();
77    }
78
79    public boolean voiceSearchEnabled() {
80        return mSource.voiceSearchEnabled();
81    }
82
83    public Intent createSearchIntent(String query, Bundle appData) {
84        return mSource.createSearchIntent(query, appData);
85    }
86
87    public Intent createVoiceSearchIntent(Bundle appData) {
88        return mSource.createVoiceSearchIntent(appData);
89    }
90
91    public boolean includeInAll() {
92        return mSource.includeInAll();
93    }
94
95    public boolean isWebCorpus() {
96        return false;
97    }
98
99    public Collection<Source> getSources() {
100        return Collections.singletonList(mSource);
101    }
102
103}
104