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 */
16package com.android.quicksearchbox.ui;
17
18import android.content.Context;
19import android.util.AttributeSet;
20import android.view.View;
21import android.widget.ExpandableListAdapter;
22import android.widget.ExpandableListView;
23
24/**
25 * Suggestions view that displays suggestions clustered by corpus type.
26 */
27public class ClusteredSuggestionsView extends ExpandableListView
28        implements SuggestionsListView<ExpandableListAdapter> {
29
30    SuggestionsAdapter<ExpandableListAdapter> mSuggestionsAdapter;
31
32    public ClusteredSuggestionsView(Context context, AttributeSet attrs) {
33        super(context, attrs);
34    }
35
36    public void setSuggestionsAdapter(SuggestionsAdapter<ExpandableListAdapter> adapter) {
37        mSuggestionsAdapter = adapter;
38        super.setAdapter(adapter == null ? null : adapter.getListAdapter());
39    }
40
41    public SuggestionsAdapter<ExpandableListAdapter> getSuggestionsAdapter() {
42        return mSuggestionsAdapter;
43    }
44
45    public void setLimitSuggestionsToViewHeight(boolean limit) {
46        // not supported
47    }
48
49    @Override
50    public void onFinishInflate() {
51        super.onFinishInflate();
52        setItemsCanFocus(false);
53        setOnGroupClickListener(new OnGroupClickListener(){
54            public boolean onGroupClick(
55                    ExpandableListView parent, View v, int groupPosition, long id) {
56                // disable collapsing / expanding
57                return true;
58            }});
59    }
60
61    public void expandAll() {
62        if (mSuggestionsAdapter != null) {
63            ExpandableListAdapter adapter = mSuggestionsAdapter.getListAdapter();
64            for (int i = 0; i < adapter.getGroupCount(); ++i) {
65                expandGroup(i);
66            }
67        }
68    }
69
70}
71