1fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood/*
2fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Copyright (C) 2009 The Android Open Source Project
3fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood *
4fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Licensed under the Apache License, Version 2.0 (the "License");
5fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * you may not use this file except in compliance with the License.
6fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * You may obtain a copy of the License at
7fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood *
8fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood *      http://www.apache.org/licenses/LICENSE-2.0
9fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood *
10fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Unless required by applicable law or agreed to in writing, software
11fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * distributed under the License is distributed on an "AS IS" BASIS,
12fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * See the License for the specific language governing permissions and
14fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * limitations under the License.
15fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood */
16fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
17fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodpackage com.android.quicksearchbox.ui;
18fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
197a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwoodimport com.android.quicksearchbox.SuggestionPosition;
20fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport com.android.quicksearchbox.Suggestions;
21fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
22fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.view.View;
23fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.view.ViewGroup;
24fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.widget.BaseAdapter;
25fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.widget.ListAdapter;
26fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
27fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood/**
28fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Uses a {@link Suggestions} object to back a {@link SuggestionsView}.
29fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood */
30fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodpublic class SuggestionsListAdapter extends SuggestionsAdapterBase<ListAdapter> {
31fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
32fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    private Adapter mAdapter;
33fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
3477909685887bd6db7454b73cf274afc3aca2f58dBjorn Bringert    public SuggestionsListAdapter(SuggestionViewFactory viewFactory) {
3577909685887bd6db7454b73cf274afc3aca2f58dBjorn Bringert        super(viewFactory);
36fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        mAdapter = new Adapter();
37fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    }
38fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
39fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    @Override
407a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood    public boolean isEmpty() {
417a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood        return mAdapter.getCount() == 0;
427a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood    }
437a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood
447a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood    @Override
45116affd19a834a2df4226a1ae37afcc1113a230eMathew Inwood    public boolean willPublishNonPromotedSuggestions() {
46116affd19a834a2df4226a1ae37afcc1113a230eMathew Inwood        return false;
47116affd19a834a2df4226a1ae37afcc1113a230eMathew Inwood    }
48116affd19a834a2df4226a1ae37afcc1113a230eMathew Inwood
49116affd19a834a2df4226a1ae37afcc1113a230eMathew Inwood    @Override
507a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood    public SuggestionPosition getSuggestion(long suggestionId) {
517a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood        return new SuggestionPosition(getCurrentPromotedSuggestions(), (int) suggestionId);
527a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood    }
537a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood
547a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood    @Override
55fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    public BaseAdapter getListAdapter() {
56fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        return mAdapter;
57fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    }
58fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
59fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    @Override
60fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    public void notifyDataSetChanged() {
61fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        mAdapter.notifyDataSetChanged();
62fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    }
63fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
64fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    @Override
65fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    public void notifyDataSetInvalidated() {
66fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        mAdapter.notifyDataSetInvalidated();
67fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    }
68fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
69fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    class Adapter extends BaseAdapter {
70fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
71fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        @Override
72fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        public int getCount() {
73fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood            return getPromotedCount();
74fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        }
75fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
76fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        @Override
77fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        public Object getItem(int position) {
78fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood            return getPromotedSuggestion(position);
79fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        }
80fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
81fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        @Override
82fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        public long getItemId(int position) {
83fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood            return position;
84fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        }
85fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
86fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        @Override
87fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        public View getView(int position, View convertView, ViewGroup parent) {
88fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood            return SuggestionsListAdapter.this.getView(
897a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood                    getCurrentPromotedSuggestions(), position, position, convertView, parent);
90fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        }
91fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
92fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        @Override
93fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        public int getItemViewType(int position) {
94fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood            return getSuggestionViewType(getCurrentPromotedSuggestions(), position);
95fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        }
96fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
97fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        @Override
98fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        public int getViewTypeCount() {
99fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood            return getSuggestionViewTypeCount();
100fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood        }
101fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
102fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood    }
103fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood
104fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood}
105