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