• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.email;
18 
19 import com.android.common.contacts.BaseEmailAddressAdapter;
20 import com.android.emailcommon.provider.Account;
21 import com.android.ex.chips.AccountSpecifier;
22 
23 import android.content.Context;
24 import android.text.TextUtils;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.widget.TextView;
29 
30 /**
31  * An adaptation of {@link BaseEmailAddressAdapter} for the Email app. The main
32  * purpose of the class is to bind the generic implementation to the resources
33  * defined locally: strings and layouts.
34  */
35 public class EmailAddressAdapter extends BaseEmailAddressAdapter implements AccountSpecifier {
36 
37     private LayoutInflater mInflater;
38 
EmailAddressAdapter(Context context)39     public EmailAddressAdapter(Context context) {
40         super(context);
41         mInflater = LayoutInflater.from(context);
42     }
43 
44     @Override
inflateItemView(ViewGroup parent)45     protected View inflateItemView(ViewGroup parent) {
46         return mInflater.inflate(R.layout.recipient_dropdown_item, parent, false);
47     }
48 
49     @Override
inflateItemViewLoading(ViewGroup parent)50     protected View inflateItemViewLoading(ViewGroup parent) {
51         return mInflater.inflate(R.layout.recipient_dropdown_item_loading, parent, false);
52     }
53 
54     @Override
bindView(View view, String directoryType, String directoryName, String displayName, String emailAddress)55     protected void bindView(View view, String directoryType, String directoryName,
56             String displayName, String emailAddress) {
57       TextView text1 = (TextView)view.findViewById(R.id.text1);
58       TextView text2 = (TextView)view.findViewById(R.id.text2);
59       text1.setText(displayName);
60       text2.setText(emailAddress);
61     }
62 
63     @Override
bindViewLoading(View view, String directoryType, String directoryName)64     protected void bindViewLoading(View view, String directoryType, String directoryName) {
65         TextView text1 = (TextView)view.findViewById(R.id.text1);
66         String text = getContext().getString(R.string.gal_searching_fmt,
67                 TextUtils.isEmpty(directoryName) ? directoryType : directoryName);
68         text1.setText(text);
69     }
70 
71     /**
72      * Set the account when known. Causes the search to prioritize contacts
73      * from that account.
74      */
setAccount(Account account)75     public void setAccount(Account account) {
76         if (account != null) {
77             // TODO: figure out how to infer the contacts account type from the email account
78             super.setAccount(new android.accounts.Account(account.mEmailAddress, "unknown"));
79         }
80     }
81 }
82