summaryrefslogtreecommitdiffstats
path: root/src/com/android/mail/ui/AccountItemView.java
blob: 5b87f7edf9e6e98bc645de58e162c4e58005d755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
 * Copyright (c) 2013, Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.mail.ui;

import android.content.Context;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.bitmap.BitmapCache;
import com.android.mail.R;
import com.android.mail.bitmap.AccountAvatarDrawable;
import com.android.mail.bitmap.ContactResolver;
import com.android.mail.providers.Account;

/**
 * The view for each account in the folder list/drawer.
 */
public class AccountItemView extends LinearLayout {
    private TextView mAccountDisplayName;
    private TextView mAccountAddress;
    private ImageView mAvatar;
    private ImageView mCheckmark;

    public AccountItemView(Context context) {
        super(context);
    }

    public AccountItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AccountItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mAccountDisplayName = (TextView)findViewById(R.id.account_display_name);
        mAccountAddress = (TextView)findViewById(R.id.account_address);
        mAvatar = (ImageView)findViewById(R.id.avatar);
        mCheckmark = (ImageView)findViewById(R.id.checkmark);
    }

    /**
     * Sets the account name and draws the unread count. Depending on the account state (current or
     * unused), the colors and drawables will change through the call to setSelected for each
     * necessary element.
     *
     * @param account account whose name will be displayed
     * @param isCurrentAccount true if the account is the one in use, false otherwise
     */
    public void bind(final Context context, final Account account, final boolean isCurrentAccount,
            final BitmapCache imagesCache, final ContactResolver contactResolver) {
        if (!TextUtils.isEmpty(account.getSenderName())) {
            mAccountDisplayName.setText(account.getSenderName());
            mAccountAddress.setText(account.getEmailAddress());
            mAccountAddress.setVisibility(View.VISIBLE);
        } else if (!TextUtils.isEmpty(account.getDisplayName()) &&
                !TextUtils.equals(account.getDisplayName(), account.getEmailAddress())) {
            mAccountDisplayName.setText(account.getDisplayName());
            mAccountAddress.setText(account.getEmailAddress());
            mAccountAddress.setVisibility(View.VISIBLE);
        } else {
            mAccountDisplayName.setText(account.getEmailAddress());
            mAccountAddress.setVisibility(View.GONE);
        }
        if (isCurrentAccount) {
            mCheckmark.setVisibility(View.VISIBLE);
            mAccountDisplayName.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            final int blackColor = getResources().getColor(R.color.text_color_black);
            mAccountDisplayName.setTextColor(blackColor);
            mAccountAddress.setTextColor(blackColor);
        } else {
            mCheckmark.setVisibility(View.GONE);
            mAccountDisplayName.setTypeface(Typeface.DEFAULT);
            final int greyColor = getResources().getColor(R.color.text_color_grey);
            mAccountDisplayName.setTextColor(greyColor);
            mAccountAddress.setTextColor(greyColor);
        }

        ImageView v = (ImageView) mAvatar.findViewById(R.id.avatar);
        AccountAvatarDrawable drawable = new AccountAvatarDrawable(
                context.getResources(), imagesCache, contactResolver);
        final int size = context.getResources().getDimensionPixelSize(
                R.dimen.account_avatar_dimension);
        drawable.setDecodeDimensions(size, size);
        drawable.bind(account.getSenderName(), account.getEmailAddress());
        v.setImageDrawable(drawable);

    }
}