SingleSourceCorpus.java revision f95ce100dcbc77794b79b0187c566bb58b5978d3
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 Context mContext;
34
35    private final Source mSource;
36
37    public SingleSourceCorpus(Context context, Source source) {
38        mContext = context;
39        mSource = source;
40    }
41
42    protected Context getContext() {
43        return mContext;
44    }
45
46    public Drawable getCorpusIcon() {
47        return mSource.getSourceIcon();
48    }
49
50    public Uri getCorpusIconUri() {
51        return mSource.getSourceIconUri();
52    }
53
54    public CharSequence getLabel() {
55        return mSource.getLabel();
56    }
57
58    public CharSequence getHint() {
59        return mSource.getHint();
60    }
61
62    public CharSequence getSettingsDescription() {
63        return mSource.getSettingsDescription();
64    }
65
66    public CorpusResult getSuggestions(String query, int queryLimit) {
67        LatencyTracker latencyTracker = new LatencyTracker();
68        SourceResult sourceResult = mSource.getSuggestions(query, queryLimit);
69        int latency = latencyTracker.getLatency();
70        return new SingleSourceCorpusResult(this, query, sourceResult, latency);
71    }
72
73    public String getName() {
74        return mSource.getName();
75    }
76
77    public boolean queryAfterZeroResults() {
78        return mSource.queryAfterZeroResults();
79    }
80
81    public int getQueryThreshold() {
82        return mSource.getQueryThreshold();
83    }
84
85    public boolean voiceSearchEnabled() {
86        return mSource.voiceSearchEnabled();
87    }
88
89    public Intent createSearchIntent(String query, Bundle appData) {
90        return mSource.createSearchIntent(query, appData);
91    }
92
93    public Intent createVoiceSearchIntent(Bundle appData) {
94        return mSource.createVoiceSearchIntent(appData);
95    }
96
97    public SuggestionData createSearchShortcut(String query) {
98        // We don't make shortcuts for searches in app corpora
99        return null;
100    }
101
102    public boolean isWebCorpus() {
103        return false;
104    }
105
106    public Collection<Source> getSources() {
107        return Collections.singletonList(mSource);
108    }
109
110}
111