SuggestionsListAdapter.java revision fd4a4cbc1143a734d357897531daa7105db6459b
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.ui;
18
19import com.android.quicksearchbox.Corpora;
20import com.android.quicksearchbox.Suggestions;
21
22import android.view.View;
23import android.view.ViewGroup;
24import android.widget.BaseAdapter;
25import android.widget.ListAdapter;
26
27/**
28 * Uses a {@link Suggestions} object to back a {@link SuggestionsView}.
29 */
30public class SuggestionsListAdapter extends SuggestionsAdapterBase<ListAdapter> {
31
32    private Adapter mAdapter;
33
34    public SuggestionsListAdapter(SuggestionViewFactory fallbackFactory, Corpora corpora) {
35        super(fallbackFactory, corpora);
36        mAdapter = new Adapter();
37    }
38
39    @Override
40    public BaseAdapter getListAdapter() {
41        return mAdapter;
42    }
43
44    @Override
45    public void notifyDataSetChanged() {
46        mAdapter.notifyDataSetChanged();
47    }
48
49    @Override
50    public void notifyDataSetInvalidated() {
51        mAdapter.notifyDataSetInvalidated();
52    }
53
54    class Adapter extends BaseAdapter {
55
56        @Override
57        public int getCount() {
58            return getPromotedCount();
59        }
60
61        @Override
62        public Object getItem(int position) {
63            return getPromotedSuggestion(position);
64        }
65
66        @Override
67        public long getItemId(int position) {
68            return position;
69        }
70
71        @Override
72        public View getView(int position, View convertView, ViewGroup parent) {
73            return SuggestionsListAdapter.this.getView(
74                    getCurrentPromotedSuggestions(), position, convertView, parent);
75        }
76
77        @Override
78        public int getItemViewType(int position) {
79            return getSuggestionViewType(getCurrentPromotedSuggestions(), position);
80        }
81
82        @Override
83        public int getViewTypeCount() {
84            return getSuggestionViewTypeCount();
85        }
86
87    }
88
89}
90