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