1/*
2 * Copyright (C) 2013 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.mail.ui;
18
19import android.content.Context;
20
21import com.android.mail.R;
22import com.android.mail.analytics.Analytics;
23import com.android.mail.browse.ConversationCursor;
24import com.android.mail.preferences.MailPrefs;
25import com.android.mail.providers.Folder;
26
27/**
28 * A tip to educate users about long press to enter CAB mode.  Appears on top of conversation list.
29 */
30public class ConversationLongPressTipView extends ConversationTipView {
31    private final MailPrefs mMailPrefs;
32    private boolean mShow;
33
34    public ConversationLongPressTipView(final Context context) {
35        super(context);
36
37        mMailPrefs = MailPrefs.get(context);
38        setText(getResources().getString(R.string.long_press_to_select_tip));
39    }
40
41    @Override
42    public void onUpdate(Folder folder, ConversationCursor cursor) {
43        mShow = checkWhetherToShow();
44    }
45
46    @Override
47    public boolean getShouldDisplayInList() {
48        mShow = checkWhetherToShow();
49        return mShow;
50    }
51
52    private boolean checkWhetherToShow() {
53        // show if 1) sender images are disabled 2) there are items
54        return !shouldShowSenderImage() && !mAdapter.isEmpty()
55                && !mMailPrefs.isLongPressToSelectTipAlreadyShown();
56    }
57
58    @Override
59    public void onCabModeEntered() {
60        if (mShow) {
61            dismiss();
62        }
63    }
64
65    @Override
66    public void dismiss() {
67        if (mShow) {
68            mMailPrefs.setLongPressToSelectTipAlreadyShown();
69            mShow = false;
70            Analytics.getInstance().sendEvent("list_swipe", "long_press_tip", null, 0);
71        }
72        super.dismiss();
73    }
74
75    protected boolean shouldShowSenderImage() {
76        return mMailPrefs.getShowSenderImages();
77    }
78}