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  * @hide
29  */
30 public class CarListItemViewHolder extends RecyclerView.ViewHolder {
31     public final FrameLayout iconContainer;
32     public final ImageView icon;
33     public final TextView title;
34     public final TextView text;
35     public final ImageView rightImage;
36     public final CheckBox rightCheckbox;
37     public final TextView rightText;
38     public final FrameLayout remoteViewsContainer;
39 
CarListItemViewHolder(View v, int viewStubLayoutId)40     public CarListItemViewHolder(View v, int viewStubLayoutId) {
41         super(v);
42         icon = (ImageView) v.findViewById(R.id.icon);
43         iconContainer = (FrameLayout) v.findViewById(R.id.icon_container);
44         title = (TextView) v.findViewById(R.id.title);
45         text = (TextView) v.findViewById(R.id.text);
46         remoteViewsContainer = (FrameLayout) v.findViewById(R.id.remoteviews);
47         ViewStub rightStub = (ViewStub) v.findViewById(R.id.right_item);
48         if (rightStub != null) {
49             rightStub.setLayoutResource(viewStubLayoutId);
50             rightStub.setInflatedId(R.id.right_item);
51 
52             if (viewStubLayoutId == R.layout.car_menu_checkbox) {
53                 rightCheckbox = (CheckBox) rightStub.inflate();
54                 rightImage = null;
55                 rightText = null;
56             } else if (viewStubLayoutId == R.layout.car_imageview) {
57                 rightImage = (ImageView) rightStub.inflate();
58                 rightCheckbox = null;
59                 rightText = null;
60             } else if (viewStubLayoutId == R.layout.car_textview) {
61                 rightText = (TextView) rightStub.inflate();
62                 rightCheckbox = null;
63                 rightImage = null;
64             } else {
65                 rightImage = null;
66                 rightCheckbox = null;
67                 rightText = null;
68             }
69         } else {
70             rightImage = null;
71             rightCheckbox = null;
72             rightText = null;
73         }
74     }
75 }