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.car.overview; 17 18 import android.app.PendingIntent; 19 import android.content.Context; 20 import android.text.TextUtils; 21 import android.util.Log; 22 import android.view.View; 23 import android.widget.ImageView; 24 import android.widget.TextView; 25 import com.android.car.stream.StreamCard; 26 27 /** 28 * A {@link StreamViewHolder} that binds a {@link StreamCard} to a basic card layout. 29 */ 30 public class SimpleStreamViewHolder extends StreamViewHolder { 31 private static final String TAG = "SimpleStreamCardVH"; 32 33 private final TextView mPrimaryTextView; 34 private final TextView mSecondaryTextView; 35 private final ImageView mPrimaryIconView; 36 private final ImageView mSecondaryIconView; 37 38 private PendingIntent mContentPendingIntent; 39 40 public SimpleStreamViewHolder(Context context, View itemView) { 41 super(context, itemView); 42 mPrimaryTextView = (TextView) itemView.findViewById(R.id.primary_text); 43 mSecondaryTextView = (TextView) itemView.findViewById(R.id.secondary_text); 44 mPrimaryIconView = (ImageView) itemView.findViewById(R.id.primary_icon_button); 45 mSecondaryIconView = (ImageView) itemView.findViewById(R.id.secondary_icon_button); 46 47 mActionContainer.setOnClickListener(new View.OnClickListener() { 48 @Override 49 public void onClick(View v) { 50 if (mContentPendingIntent == null) { 51 return; 52 } 53 54 try { 55 mContentPendingIntent.send(mContext, 0 /* resultCode */, null /* intent */); 56 } catch (PendingIntent.CanceledException e) { 57 Log.e(TAG, "Failed to send pending intent for card"); 58 } 59 } 60 }); 61 } 62 63 @Override 64 public void bindStreamCard(StreamCard card) { 65 super.bindStreamCard(card); 66 67 if (!TextUtils.isEmpty(card.getPrimaryText())) { 68 mPrimaryTextView.setText(card.getPrimaryText()); 69 } 70 71 if (!TextUtils.isEmpty(card.getSecondaryText())) { 72 mSecondaryTextView.setText(card.getSecondaryText()); 73 } 74 75 if (card.getPrimaryIcon() != null) { 76 mPrimaryIconView.setImageBitmap(card.getPrimaryIcon()); 77 } 78 79 if (card.getSecondaryIcon() != null) { 80 mSecondaryIconView.setImageBitmap(card.getSecondaryIcon()); 81 } 82 mContentPendingIntent = card.getContentPendingIntent(); 83 } 84 85 @Override 86 protected void resetViews() { 87 mPrimaryTextView.setText(null); 88 mSecondaryTextView.setText(null); 89 mPrimaryIconView.setImageBitmap(null); 90 mSecondaryIconView.setImageBitmap(null); 91 mContentPendingIntent = null; 92 } 93 } 94