MailboxListItem.java revision db0a601714a311ccbf7b6e780b80d8e5318df848
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.activity;
18
19import com.android.email.R;
20import com.android.email.provider.EmailContent.Mailbox;
21import com.android.internal.util.ArrayUtils;
22
23import android.content.Context;
24import android.content.res.Resources;
25import android.graphics.drawable.Drawable;
26import android.util.AttributeSet;
27import android.widget.RelativeLayout;
28import android.widget.TextView;
29
30public class MailboxListItem extends RelativeLayout {
31    // Colors used for drop targets
32    private static Integer sDropUnavailableFgColor;
33    private static Integer sDropAvailableBgColor;
34    private static Integer sTextPrimaryColor;
35    private static Integer sTextSecondaryColor;
36
37    public long mMailboxId;
38    public Integer mMailboxType;
39    public MailboxesAdapter mAdapter;
40
41    private Drawable mBackground;
42    private TextView mLabelName;
43    private TextView mLabelCount;
44
45    public MailboxListItem(Context context) {
46        super(context);
47    }
48
49    public MailboxListItem(Context context, AttributeSet attrs) {
50        super(context, attrs);
51    }
52
53    public MailboxListItem(Context context, AttributeSet attrs, int defStyle) {
54        super(context, attrs, defStyle);
55    }
56
57    @Override
58    protected void onFinishInflate() {
59        super.onFinishInflate();
60        mBackground = getBackground();
61        if (sDropAvailableBgColor == null) {
62            Resources res = getResources();
63            sDropAvailableBgColor = res.getColor(R.color.mailbox_drop_available_bg_color);
64            sDropUnavailableFgColor = res.getColor(R.color.mailbox_drop_unavailable_fg_color);
65            sTextPrimaryColor = res.getColor(R.color.text_primary_color);
66            sTextSecondaryColor = res.getColor(R.color.text_secondary_color);
67        }
68        mLabelName = (TextView)findViewById(R.id.mailbox_name);
69        mLabelCount = (TextView)findViewById(R.id.message_count);
70    }
71
72    public boolean isDropTarget(long itemMailbox) {
73        if ((mMailboxId < 0) || (itemMailbox == mMailboxId)) {
74            return false;
75        }
76        return !ArrayUtils.contains(Mailbox.INVALID_DROP_TARGETS, mMailboxType);
77    }
78
79    public void setDropTargetBackground(boolean dragInProgress, long itemMailbox) {
80        int labelNameColor = sTextPrimaryColor;
81        int labelCountColor = sTextSecondaryColor;
82        if (dragInProgress) {
83            if (isDropTarget(itemMailbox)) {
84                setBackgroundColor(sDropAvailableBgColor);
85            } else {
86                labelNameColor = sDropUnavailableFgColor;
87                labelCountColor = sDropUnavailableFgColor;
88            }
89        } else {
90            setBackgroundDrawable(mBackground);
91        }
92        mLabelName.setTextColor(labelNameColor);
93        mLabelCount.setTextColor(labelCountColor);
94    }
95}
96