SearchActivityViewTwoPane.java revision 0a73d81f02118d0343d3f1c9219a8354466f72b3
1/*
2 * Copyright (C) 2010 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.ui;
18
19import com.android.quicksearchbox.Corpus;
20import com.android.quicksearchbox.R;
21import com.android.quicksearchbox.Suggestions;
22
23import android.content.Context;
24import android.util.AttributeSet;
25import android.widget.ImageView;
26
27/**
28 * Two-pane variant for the search activity view.
29 */
30public class SearchActivityViewTwoPane extends SearchActivityView {
31
32    private ImageView mSettingsButton;
33
34    // View that shows the results other than the query completions
35    private SuggestionsView mResultsView;
36    private SuggestionsAdapter mResultsAdapter;
37
38    public SearchActivityViewTwoPane(Context context) {
39        super(context);
40    }
41
42    public SearchActivityViewTwoPane(Context context, AttributeSet attrs) {
43        super(context, attrs);
44    }
45
46    public SearchActivityViewTwoPane(Context context, AttributeSet attrs, int defStyle) {
47        super(context, attrs, defStyle);
48    }
49
50    @Override
51    protected void onFinishInflate() {
52        super.onFinishInflate();
53
54        mSettingsButton = (ImageView) findViewById(R.id.settings_icon);
55
56        mResultsView = (SuggestionsView) findViewById(R.id.shortcuts);
57        mResultsAdapter = createSuggestionsAdapter();
58        mResultsView.setOnKeyListener(new SuggestionsViewKeyListener());
59    }
60
61    @Override
62    public void onResume() {
63    }
64
65    @Override
66    public void onStop() {
67    }
68
69    @Override
70    public void start() {
71        super.start();
72        mResultsView.setAdapter(mResultsAdapter);
73    }
74
75    @Override
76    public void destroy() {
77        mResultsView.setAdapter(null);
78        super.destroy();
79    }
80
81    @Override
82    protected void considerHidingInputMethod() {
83        // Don't hide keyboard when interacting with suggestions list
84    }
85
86    @Override
87    public void showCorpusSelectionDialog() {
88        // not used
89    }
90
91    @Override
92    public void clearSuggestions() {
93        super.clearSuggestions();
94        mResultsAdapter.setSuggestions(null);
95    }
96
97    @Override
98    public void setMaxPromoted(int maxPromoted) {
99        super.setMaxPromoted(maxPromoted);
100        mResultsAdapter.setMaxPromoted(maxPromoted);
101    }
102
103    @Override
104    public void setSettingsButtonClickListener(OnClickListener listener) {
105        mSettingsButton.setOnClickListener(listener);
106    }
107
108    @Override
109    public void setSuggestionClickListener(SuggestionClickListener listener) {
110        super.setSuggestionClickListener(listener);
111        mResultsAdapter.setSuggestionClickListener(listener);
112    }
113
114    @Override
115    public void setSuggestions(Suggestions suggestions) {
116        super.setSuggestions(suggestions);
117        suggestions.acquire();
118        mResultsAdapter.setSuggestions(suggestions);
119    }
120
121    @Override
122    public void setCorpus(Corpus corpus) {
123        getSuggestionsAdapter().setPromoter(getQsbApplication().createWebPromoter());
124
125        mResultsAdapter.setCorpus(corpus);
126        if (corpus == null) {
127            mResultsAdapter.setPromoter(getQsbApplication().createResultsPromoter());
128        } else {
129            mResultsAdapter.setPromoter(getQsbApplication().createSingleCorpusPromoter());
130        }
131
132        updateUi(getQuery().length() == 0);
133    }
134
135    @Override
136    public Corpus getSearchCorpus() {
137        return getWebCorpus();
138    }
139
140    @Override
141    public Corpus getCorpus() {
142        return null;
143    }
144
145}
146