Home | History | Annotate | Download | only in lenspicker
      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 com.android.support.car.lenspicker;
     17 
     18 import android.content.Context;
     19 import android.text.TextUtils;
     20 import android.view.View;
     21 import android.widget.ImageView;
     22 import android.widget.TextView;
     23 
     24 import androidx.recyclerview.widget.RecyclerView;
     25 
     26 /**
     27  * A view that renders a single row in the lens picker list
     28  */
     29 public class LensPickerRow extends RecyclerView.ViewHolder {
     30     private final View mCardView;
     31     private final ImageView mIconView;
     32     private final TextView mTitleView;
     33 
     34     public LensPickerRow(View itemView) {
     35         super(itemView);
     36         mCardView = itemView.findViewById(R.id.stream_card);
     37         mIconView = (ImageView) itemView.findViewById(R.id.icon);
     38         mTitleView = (TextView) itemView.findViewById(R.id.text);
     39     }
     40 
     41     public void bind(Context context, LensPickerItem item,
     42             LensPickerSelectionHandler selectionHandler) {
     43         String label = item.getLabel();
     44         if (TextUtils.isEmpty(label)) {
     45             label = context.getString(R.string.unknown_provider_name);
     46         }
     47         mTitleView.setText(label);
     48         mIconView.setImageDrawable(item.getIcon());
     49 
     50         if (selectionHandler != null) {
     51             mCardView.setOnClickListener(v -> selectionHandler.onActivitySelected(item));
     52         }
     53     }
     54 }
     55