Home | History | Annotate | Download | only in ui
      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 
     17 package com.android.quicksearchbox.ui;
     18 
     19 import com.android.quicksearchbox.SuggestionPosition;
     20 import com.android.quicksearchbox.Suggestions;
     21 
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 import android.widget.BaseAdapter;
     25 import android.widget.ListAdapter;
     26 
     27 /**
     28  * Uses a {@link Suggestions} object to back a {@link SuggestionsView}.
     29  */
     30 public class SuggestionsListAdapter extends SuggestionsAdapterBase<ListAdapter> {
     31 
     32     private Adapter mAdapter;
     33 
     34     public SuggestionsListAdapter(SuggestionViewFactory viewFactory) {
     35         super(viewFactory);
     36         mAdapter = new Adapter();
     37     }
     38 
     39     @Override
     40     public boolean isEmpty() {
     41         return mAdapter.getCount() == 0;
     42     }
     43 
     44     @Override
     45     public boolean willPublishNonPromotedSuggestions() {
     46         return false;
     47     }
     48 
     49     @Override
     50     public SuggestionPosition getSuggestion(long suggestionId) {
     51         return new SuggestionPosition(getCurrentPromotedSuggestions(), (int) suggestionId);
     52     }
     53 
     54     @Override
     55     public BaseAdapter getListAdapter() {
     56         return mAdapter;
     57     }
     58 
     59     @Override
     60     public void notifyDataSetChanged() {
     61         mAdapter.notifyDataSetChanged();
     62     }
     63 
     64     @Override
     65     public void notifyDataSetInvalidated() {
     66         mAdapter.notifyDataSetInvalidated();
     67     }
     68 
     69     class Adapter extends BaseAdapter {
     70 
     71         @Override
     72         public int getCount() {
     73             return getPromotedCount();
     74         }
     75 
     76         @Override
     77         public Object getItem(int position) {
     78             return getPromotedSuggestion(position);
     79         }
     80 
     81         @Override
     82         public long getItemId(int position) {
     83             return position;
     84         }
     85 
     86         @Override
     87         public View getView(int position, View convertView, ViewGroup parent) {
     88             return SuggestionsListAdapter.this.getView(
     89                     getCurrentPromotedSuggestions(), position, position, convertView, parent);
     90         }
     91 
     92         @Override
     93         public int getItemViewType(int position) {
     94             return getSuggestionViewType(getCurrentPromotedSuggestions(), position);
     95         }
     96 
     97         @Override
     98         public int getViewTypeCount() {
     99             return getSuggestionViewTypeCount();
    100         }
    101 
    102     }
    103 
    104 }
    105