RecipientAdapter.java revision 4693fecab2806ec6134a7eead7f5311f3831cfc3
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.email;
18
19import com.android.ex.chips.BaseRecipientAdapter;
20import com.android.ex.chips.RecipientEditTextView;
21
22import android.accounts.Account;
23import android.content.Context;
24import android.content.res.Resources;
25import android.graphics.Bitmap;
26import android.graphics.BitmapFactory;
27
28public class RecipientAdapter extends BaseRecipientAdapter {
29    public RecipientAdapter(Context context, RecipientEditTextView list) {
30        super(context);
31        Resources r = context.getResources();
32        Bitmap def = BitmapFactory.decodeResource(r, R.drawable.ic_contact_picture);
33        list.setChipDimensions(
34                r.getDrawable(R.drawable.chip_background),
35                r.getDrawable(R.drawable.chip_background_selected),
36                r.getDrawable(R.drawable.chip_background_invalid),
37                r.getDrawable(R.drawable.chip_delete), def, R.layout.more_item,
38                R.layout.chips_alternate_item,
39                        r.getDimension(R.dimen.chip_height),
40                        r.getDimension(R.dimen.chip_padding),
41                        r.getDimension(R.dimen.chip_text_size),
42                        R.layout.copy_chip_dialog_layout);
43    }
44
45    /**
46     * Set the account when known. Causes the search to prioritize contacts from
47     * that account.
48     */
49    public void setAccount(Account account) {
50        if (account != null) {
51            // TODO: figure out how to infer the contacts account
52            // type from the email account
53            super.setAccount(new android.accounts.Account(account.name, "unknown"));
54        }
55    }
56
57    @Override
58    protected int getDefaultPhotoResource() {
59        return R.drawable.ic_contact_picture;
60    }
61
62    @Override
63    protected int getItemLayout() {
64        return R.layout.chips_recipient_dropdown_item;
65    }
66
67    @Override
68    protected int getWaitingForDirectorySearchLayout() {
69        return R.layout.chips_waiting_for_directory_search;
70    }
71}
72