Home | History | Annotate | Download | only in binding
      1 /*
      2  * Copyright (C) 2013 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.layoutlib.bridge.impl.binding;
     18 
     19 import java.util.ArrayList;
     20 import java.util.Collections;
     21 import java.util.List;
     22 
     23 import com.android.ide.common.rendering.api.DataBindingItem;
     24 
     25 /**
     26  * This is the items provided by the adapter. They are dynamically generated.
     27  */
     28 final class AdapterItem {
     29     private final DataBindingItem mItem;
     30     private final int mType;
     31     private final int mFullPosition;
     32     private final int mPositionPerType;
     33     private List<AdapterItem> mChildren;
     34 
     35     protected AdapterItem(DataBindingItem item, int type, int fullPosition,
     36             int positionPerType) {
     37         mItem = item;
     38         mType = type;
     39         mFullPosition = fullPosition;
     40         mPositionPerType = positionPerType;
     41     }
     42 
     43     void addChild(AdapterItem child) {
     44         if (mChildren == null) {
     45             mChildren = new ArrayList<AdapterItem>();
     46         }
     47 
     48         mChildren.add(child);
     49     }
     50 
     51     List<AdapterItem> getChildren() {
     52         if (mChildren != null) {
     53             return mChildren;
     54         }
     55 
     56         return Collections.emptyList();
     57     }
     58 
     59     int getType() {
     60         return mType;
     61     }
     62 
     63     int getFullPosition() {
     64         return mFullPosition;
     65     }
     66 
     67     int getPositionPerType() {
     68         return mPositionPerType;
     69     }
     70 
     71     DataBindingItem getDataBindingItem() {
     72         return mItem;
     73     }
     74 }
     75