147f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan/*
2ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov * Copyright (C) 2010 The Android Open Source Project
347f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan *
447f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan * Licensed under the Apache License, Version 2.0 (the "License");
547f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan * you may not use this file except in compliance with the License.
647f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan * You may obtain a copy of the License at
747f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan *
847f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan *      http://www.apache.org/licenses/LICENSE-2.0
947f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan *
1047f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan * Unless required by applicable law or agreed to in writing, software
1147f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan * distributed under the License is distributed on an "AS IS" BASIS,
1247f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1347f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan * See the License for the specific language governing permissions and
1447f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan * limitations under the License.
1547f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan */
1647f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan
1747f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chanpackage com.android.calendar;
1847f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan
19ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikovimport com.android.common.contacts.BaseEmailAddressAdapter;
2018cabd263b91d7d09f3b93b0bf6c78533bbc2c6aMindy Pereiraimport com.android.ex.chips.AccountSpecifier;
21ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov
2247f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chanimport android.content.Context;
23ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikovimport android.text.TextUtils;
24ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikovimport android.view.LayoutInflater;
2547f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chanimport android.view.View;
26ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikovimport android.view.ViewGroup;
2747f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chanimport android.widget.TextView;
2847f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan
29ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov/**
30ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov* An adaptation of {@link BaseEmailAddressAdapter} for the Email app. The main
31ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov* purpose of the class is to bind the generic implementation to the resources
32ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov* defined locally: strings and layouts.
33ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov*/
3418cabd263b91d7d09f3b93b0bf6c78533bbc2c6aMindy Pereirapublic class EmailAddressAdapter extends BaseEmailAddressAdapter implements AccountSpecifier {
3547f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan
36ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   private LayoutInflater mInflater;
3747f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan
38ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   public EmailAddressAdapter(Context context) {
39ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov       super(context);
40ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov       mInflater = LayoutInflater.from(context);
41ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   }
4247f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan
43ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   @Override
44ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   protected View inflateItemView(ViewGroup parent) {
45ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov       return mInflater.inflate(R.layout.email_autocomplete_item, parent, false);
46ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   }
4747f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan
48ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   @Override
49ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   protected View inflateItemViewLoading(ViewGroup parent) {
50ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov       return mInflater.inflate(R.layout.email_autocomplete_item_loading, parent, false);
51ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   }
52368530b9be64bcf4af53e3438749d0eed39153baMichael Chan
53ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   @Override
54ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   protected void bindView(View view, String directoryType, String directoryName,
55ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov           String displayName, String emailAddress) {
56ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov     TextView text1 = (TextView)view.findViewById(R.id.text1);
57ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov     TextView text2 = (TextView)view.findViewById(R.id.text2);
58ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov     text1.setText(displayName);
59ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov     text2.setText(emailAddress);
60ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   }
6147f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan
62ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   @Override
63ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   protected void bindViewLoading(View view, String directoryType, String directoryName) {
64ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov       TextView text1 = (TextView)view.findViewById(R.id.text1);
65ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov       String text = getContext().getString(R.string.directory_searching_fmt,
66ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov               TextUtils.isEmpty(directoryName) ? directoryType : directoryName);
67ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov       text1.setText(text);
68ee212201f3b7dd290eb9ca99de5b4d0b9c62acfdDmitri Plotnikov   }
6947f3f70eafed4545f60a47a3ec6c1b24fc11b56fMichael Chan}
70