Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2015 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 package android.support.car.ui;
     17 
     18 import android.support.v7.widget.RecyclerView;
     19 import android.view.View;
     20 import android.view.ViewStub;
     21 import android.widget.CheckBox;
     22 import android.widget.FrameLayout;
     23 import android.widget.ImageView;
     24 import android.widget.TextView;
     25 
     26 /**
     27  * ViewHolder for @layout/sdk_car_list_item that is used to handle the various sdk item templates
     28  */
     29 public class CarListItemViewHolder extends RecyclerView.ViewHolder {
     30     public final FrameLayout iconContainer;
     31     public final ImageView icon;
     32     public final TextView title;
     33     public final TextView text;
     34     public final ImageView rightImage;
     35     public final CheckBox rightCheckbox;
     36     public final TextView rightText;
     37     public final FrameLayout remoteViewsContainer;
     38 
     39     public CarListItemViewHolder(View v, int viewStubLayoutId) {
     40         super(v);
     41         icon = (ImageView) v.findViewById(R.id.icon);
     42         iconContainer = (FrameLayout) v.findViewById(R.id.icon_container);
     43         title = (TextView) v.findViewById(R.id.title);
     44         text = (TextView) v.findViewById(R.id.text);
     45         remoteViewsContainer = (FrameLayout) v.findViewById(R.id.remoteviews);
     46         ViewStub rightStub = (ViewStub) v.findViewById(R.id.right_item);
     47         if (rightStub != null) {
     48             rightStub.setLayoutResource(viewStubLayoutId);
     49             rightStub.setInflatedId(R.id.right_item);
     50 
     51             if (viewStubLayoutId == R.layout.car_menu_checkbox) {
     52                 rightCheckbox = (CheckBox) rightStub.inflate();
     53                 rightImage = null;
     54                 rightText = null;
     55             } else if (viewStubLayoutId == R.layout.car_imageview) {
     56                 rightImage = (ImageView) rightStub.inflate();
     57                 rightCheckbox = null;
     58                 rightText = null;
     59             } else if (viewStubLayoutId == R.layout.car_textview) {
     60                 rightText = (TextView) rightStub.inflate();
     61                 rightCheckbox = null;
     62                 rightImage = null;
     63             } else {
     64                 rightImage = null;
     65                 rightCheckbox = null;
     66                 rightText = null;
     67             }
     68         } else {
     69             rightImage = null;
     70             rightCheckbox = null;
     71             rightText = null;
     72         }
     73     }
     74 }