1/* 2 * Copyright (C) 2011 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 17package com.android.ex.chips; 18 19import android.content.Context; 20import android.text.util.Rfc822Tokenizer; 21import android.view.LayoutInflater; 22import android.view.View; 23import android.view.ViewGroup; 24import android.widget.ArrayAdapter; 25import android.widget.ImageView; 26import android.widget.TextView; 27 28class SingleRecipientArrayAdapter extends ArrayAdapter<RecipientEntry> { 29 private int mLayoutId; 30 31 private final LayoutInflater mLayoutInflater; 32 33 public SingleRecipientArrayAdapter(Context context, int resourceId, RecipientEntry entry) { 34 super(context, resourceId, new RecipientEntry[] { 35 entry 36 }); 37 mLayoutInflater = LayoutInflater.from(context); 38 mLayoutId = resourceId; 39 } 40 41 @Override 42 public View getView(int position, View convertView, ViewGroup parent) { 43 if (convertView == null) { 44 convertView = newView(); 45 } 46 bindView(convertView, getItem(position)); 47 return convertView; 48 } 49 50 private View newView() { 51 return mLayoutInflater.inflate(mLayoutId, null); 52 } 53 54 private static void bindView(View view, RecipientEntry entry) { 55 TextView display = (TextView) view.findViewById(android.R.id.title); 56 ImageView imageView = (ImageView) view.findViewById(android.R.id.icon); 57 display.setText(entry.getDisplayName()); 58 display.setVisibility(View.VISIBLE); 59 imageView.setVisibility(View.VISIBLE); 60 TextView destination = (TextView) view.findViewById(android.R.id.text1); 61 destination.setText(Rfc822Tokenizer.tokenize(entry.getDestination())[0].getAddress()); 62 } 63} 64