1 /* 2 * Copyright (C) 2016 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.content.pm.ResolveInfo; 20 import android.text.TextUtils; 21 import android.view.View; 22 import android.widget.ImageView; 23 import android.widget.TextView; 24 25 import androidx.recyclerview.widget.RecyclerView; 26 27 /** 28 * A {@link androidx.recyclerview.widget.RecyclerView.ViewHolder} representing a row within the 29 * {@link LensResolverActivity}. 30 */ 31 public class ResolverListRow extends RecyclerView.ViewHolder { 32 private final View mCardView; 33 private final ImageView mIconView; 34 private final TextView mTitleView; 35 36 public interface ResolverSelectionHandler { onActivitySelected(ResolveInfo info, LensPickerItem item)37 void onActivitySelected(ResolveInfo info, LensPickerItem item); 38 } 39 ResolverListRow(View itemView)40 public ResolverListRow(View itemView) { 41 super(itemView); 42 mCardView = itemView.findViewById(R.id.stream_card); 43 mIconView = (ImageView) itemView.findViewById(R.id.icon); 44 mTitleView = (TextView) itemView.findViewById(R.id.text); 45 } 46 bind(Context context, ResolveInfo info, LensPickerItem item, ResolverSelectionHandler selectionHandler)47 public void bind(Context context, ResolveInfo info, LensPickerItem item, 48 ResolverSelectionHandler selectionHandler) { 49 String label = item.getLabel(); 50 if (TextUtils.isEmpty(label)) { 51 label = context.getString(R.string.unknown_provider_name); 52 } 53 54 mTitleView.setText(label); 55 mIconView.setImageDrawable(item.getIcon()); 56 57 if (selectionHandler != null) { 58 mCardView.setOnClickListener(v -> selectionHandler.onActivitySelected(info, item)); 59 } 60 } 61 } 62