MailboxListItem.java revision 80a98fd939f0760f2e2d8abb604c492125c0bbad
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.provider.EmailContent.Mailbox;
20import com.android.internal.util.ArrayUtils;
21
22import android.content.Context;
23import android.graphics.drawable.Drawable;
24import android.util.AttributeSet;
25import android.view.MotionEvent;
26import android.widget.RelativeLayout;
27
28public class MailboxListItem extends RelativeLayout {
29    // STOPSHIP Need final color/ui
30    // Color used for valid drop targets
31    private static final int DROP_AVAILABLE = 0xFFFFFF33;
32    private static final int DROP_UNAVAILABLE = 0xFFFFFFFF;
33
34    public long mMailboxId;
35    public Integer mMailboxType;
36    public MailboxesAdapter mAdapter;
37
38    private Drawable mBackground;
39
40    public MailboxListItem(Context context) {
41        super(context);
42    }
43
44    public MailboxListItem(Context context, AttributeSet attrs) {
45        super(context, attrs);
46    }
47
48    public MailboxListItem(Context context, AttributeSet attrs, int defStyle) {
49        super(context, attrs, defStyle);
50    }
51
52    @Override
53    protected void onFinishInflate() {
54        super.onFinishInflate();
55        mBackground = getBackground();
56    }
57
58    public boolean isDropTarget(long itemMailbox) {
59        if ((mMailboxId < 0) || (itemMailbox == mMailboxId)) {
60            return false;
61        }
62        return !ArrayUtils.contains(Mailbox.INVALID_DROP_TARGETS, mMailboxType);
63    }
64
65    public boolean setDropTargetBackground(boolean dragInProgress, long itemMailbox) {
66        if (dragInProgress) {
67            if (isDropTarget(itemMailbox)) {
68                setBackgroundColor(DROP_AVAILABLE);
69                return true;
70            } else {
71                setBackgroundColor(DROP_UNAVAILABLE);
72                return false;
73            }
74        } else {
75            setBackgroundDrawable(mBackground);
76            return false;
77        }
78    }
79
80    @Override
81    public boolean onTouchEvent(MotionEvent event) {
82        // TODO Can we know we're in mailbox list / message list two-pane mode?  If so, we should
83        // check for this instead...
84        // We don't want a touch very near the right edge to be used to visit a folder, as it might
85        // easily have been an attempt to drag
86        // STOPSHIP
87        if (Welcome.useTwoPane(getContext()) && event.getAction() == MotionEvent.ACTION_DOWN) {
88            if (event.getX() + 10 > this.getWidth()) {
89                return true;
90            }
91        }
92        return super.onTouchEvent(event);
93    }
94}
95