RecipientAdapter.java revision 9753d2fde1b549ba109a198b6c768280833cd6d0
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.string.more_string,
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    }
43
44    /**
45     * Set the account when known. Causes the search to prioritize contacts from
46     * that account.
47     */
48    public void setAccount(Account account) {
49        if (account != null) {
50            // TODO: figure out how to infer the contacts account
51            // type from the email account
52            super.setAccount(new android.accounts.Account(account.name, "unknown"));
53        }
54    }
55
56    @Override
57    protected int getDefaultPhotoResource() {
58        return R.drawable.ic_contact_picture;
59    }
60
61    @Override
62    protected int getItemLayout() {
63        return R.layout.chips_recipient_dropdown_item;
64    }
65
66    @Override
67    protected int getSeparatorLayout() {
68        return R.layout.chips_separator;
69    }
70
71    @Override
72    protected int getSeparatorWithinGroupLayout() {
73        return R.layout.chips_separator_within_group;
74    }
75
76    @Override
77    protected int getWaitingForDirectorySearchLayout() {
78        return R.layout.chips_waiting_for_directory_search;
79    }
80}
81