Home | History | Annotate | Download | only in api
      1 /*
      2  * Copyright (C) 2011 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.ide.common.rendering.api;
     18 
     19 import java.util.ArrayList;
     20 import java.util.Iterator;
     21 import java.util.List;
     22 
     23 /**
     24  * Describe the content of the dynamic android.widget.Adapter used to fill
     25  * android.widget.AdapterView
     26  */
     27 public class AdapterBinding implements Iterable<DataBindingItem> {
     28 
     29     private final int mRepeatCount;
     30     private final List<ResourceReference> mHeaders = new ArrayList<ResourceReference>();
     31     private final List<DataBindingItem> mItems = new ArrayList<DataBindingItem>();
     32     private final List<ResourceReference> mFooters = new ArrayList<ResourceReference>();
     33 
     34     public AdapterBinding(int repeatCount) {
     35         mRepeatCount = repeatCount;
     36     }
     37 
     38     public int getRepeatCount() {
     39         return mRepeatCount;
     40     }
     41 
     42     public void addHeader(ResourceReference layoutInfo) {
     43         mHeaders.add(layoutInfo);
     44     }
     45 
     46     public int getHeaderCount() {
     47         return mHeaders.size();
     48     }
     49 
     50     public ResourceReference getHeaderAt(int index) {
     51         return mHeaders.get(index);
     52     }
     53 
     54     public void addItem(DataBindingItem item) {
     55         mItems.add(item);
     56     }
     57 
     58     public int getItemCount() {
     59         return mItems.size();
     60     }
     61 
     62     public DataBindingItem getItemAt(int index) {
     63         return mItems.get(index);
     64     }
     65 
     66     public void addFooter(ResourceReference layoutInfo) {
     67         mFooters.add(layoutInfo);
     68     }
     69 
     70     public int getFooterCount() {
     71         return mFooters.size();
     72     }
     73 
     74     public ResourceReference getFooterAt(int index) {
     75         return mFooters.get(index);
     76     }
     77 
     78     @Override
     79     public Iterator<DataBindingItem> iterator() {
     80         return mItems.iterator();
     81     }
     82 }
     83