EmailAddressAdapter.java revision ee212201f3b7dd290eb9ca99de5b4d0b9c62acfd
1/* 2 * Copyright (C) 2010 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.calendar; 18 19import com.android.common.contacts.BaseEmailAddressAdapter; 20 21import android.content.Context; 22import android.text.TextUtils; 23import android.view.LayoutInflater; 24import android.view.View; 25import android.view.ViewGroup; 26import android.widget.TextView; 27 28/** 29* An adaptation of {@link BaseEmailAddressAdapter} for the Email app. The main 30* purpose of the class is to bind the generic implementation to the resources 31* defined locally: strings and layouts. 32*/ 33public class EmailAddressAdapter extends BaseEmailAddressAdapter { 34 35 private LayoutInflater mInflater; 36 37 public EmailAddressAdapter(Context context) { 38 super(context); 39 mInflater = LayoutInflater.from(context); 40 } 41 42 @Override 43 protected View inflateItemView(ViewGroup parent) { 44 return mInflater.inflate(R.layout.email_autocomplete_item, parent, false); 45 } 46 47 @Override 48 protected View inflateItemViewLoading(ViewGroup parent) { 49 return mInflater.inflate(R.layout.email_autocomplete_item_loading, parent, false); 50 } 51 52 @Override 53 protected void bindView(View view, String directoryType, String directoryName, 54 String displayName, String emailAddress) { 55 TextView text1 = (TextView)view.findViewById(R.id.text1); 56 TextView text2 = (TextView)view.findViewById(R.id.text2); 57 text1.setText(displayName); 58 text2.setText(emailAddress); 59 } 60 61 @Override 62 protected void bindViewLoading(View view, String directoryType, String directoryName) { 63 TextView text1 = (TextView)view.findViewById(R.id.text1); 64 String text = getContext().getString(R.string.directory_searching_fmt, 65 TextUtils.isEmpty(directoryName) ? directoryType : directoryName); 66 text1.setText(text); 67 } 68} 69