summaryrefslogtreecommitdiffstats
path: root/src/com/android/mail/ui/MailActivity.java
blob: af26817928b802ff84f4a39d87413d89e62a6641 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*******************************************************************************
 *      Copyright (C) 2012 Google Inc.
 *      Licensed to The Android Open Source Project.
 *
 *      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.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.ActionMode;
import android.view.DragEvent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;

import com.android.mail.providers.Conversation;
import com.android.mail.providers.Folder;
import com.android.mail.providers.Settings;
import com.android.mail.ui.FolderListFragment.FolderListSelectionListener;
import com.android.mail.ui.ViewMode.ModeChangeListener;
import com.android.mail.utils.Utils;

/**
 * This is the root activity container that holds the left navigation fragment
 * (usually a list of folders), and the main content fragment (either a
 * conversation list or a conversation view).
 */
public class MailActivity extends AbstractMailActivity implements ControllableActivity {
    // TODO(viki) This class lacks: Conversation Position tracking
    // TODO(viki) This class lacks: What's New dialog
    // TODO(viki) This class lacks: Sync Window Upgrade dialog

    private static final boolean STRICT_MODE = true;

    /**
     * The activity controller to which we delegate most Activity lifecycle events.
     */
    private ActivityController mController;
    /**
     * A clean launch is when the activity is not resumed. We want to show a "What's New" dialog
     * on a clean launch: when the user started the Activity by tapping on the icon: not when he
     * selected "Up" from compose, not when he resumed the activity, etc.
     */
    private boolean mLaunchedCleanly = false;

    private ViewMode mViewMode;

    public MailActivity() {
        super();
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        mController.onTouchEvent(ev);
        return super.dispatchTouchEvent(ev);
    }

    /**
     * Default implementation returns a null view mode.
     */
    @Override
    public ViewMode getViewMode() {
        return mViewMode;
    }

    @Override
    public void onActionModeFinished(ActionMode mode) {
        super.onActionModeFinished(mode);
    }

    @Override
    public void onActionModeStarted(ActionMode mode) {
        super.onActionModeStarted(mode);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        mController.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onBackPressed() {
        if (!mController.onBackPressed()) {
            super.onBackPressed();
        }
    }

    @Override
    public void onCreate(Bundle savedState) {
        if (STRICT_MODE) {
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                    .detectDiskReads()
                    .detectDiskWrites()
                    .detectNetwork()   // or .detectAll() for all detectable problems
                    .penaltyLog()
                    .build());
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectLeakedSqlLiteObjects()
                    .detectLeakedClosableObjects()
                    .penaltyLog()
//                    .penaltyDeath()
                    .build());
        }
        super.onCreate(savedState);

        mViewMode = new ViewMode(this);
        final boolean tabletUi = Utils.useTabletUI(this);
        mController = ControllerFactory.forActivity(this, mViewMode, tabletUi);
        mController.onCreate(savedState);

        Intent intent = getIntent();
        // Only display "What's New" and similar dialogs on a clean launch.
        // A clean launch is one where the activity is not resumed.
        // We also want to avoid showing any dialogs when the user goes "up"
        // from a compose
        // activity launched directly from a send-to intent. (in that case the
        // action is null.)
        if (savedState == null && intent.getAction() != null) {
            mLaunchedCleanly = true;
        }
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        mController.onRestoreInstanceState(savedInstanceState);
    }

    @Override
    public Dialog onCreateDialog(int id, Bundle bundle) {
        Dialog dialog = mController.onCreateDialog(id, bundle);
        // TODO(viki): Handle what's new and the sync window upgrade dialog here.
        return dialog == null ? super.onCreateDialog(id, bundle) : dialog;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return mController.onCreateOptionsMenu(menu) || super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return mController.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return mController.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
    }

    @Override
    public void onPause() {
        super.onPause();
        mController.onPause();
        //        mSyncWindowUpgradeReceiver.disable();
    }

    @Override
    public void onPrepareDialog(int id, Dialog dialog, Bundle bundle) {
        super.onPrepareDialog(id, dialog, bundle);
        mController.onPrepareDialog(id, dialog, bundle);
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        return mController.onPrepareOptionsMenu(menu) || super.onPrepareOptionsMenu(menu);
    }

    @Override
    public void onResume() {
        super.onResume();
        mController.onResume();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mController.onSaveInstanceState(outState);
    }

    @Override
    public boolean onSearchRequested(String query) {
        mController.onSearchRequested(query);
        return true;
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (mLaunchedCleanly) {
            // TODO(viki): Show a "what's new screen"
        }
    }

    @Override
    public boolean onSearchRequested() {
        mController.startSearch();
        return true;
    }

    @Override
    public void onStop() {
        super.onStop();
        mController.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mController.onDestroy();
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        mController.onWindowFocusChanged(hasFocus);
    }

    @Override
    public void setViewModeListener(ModeChangeListener listener) {
        mViewMode.addListener(listener);
    }

    @Override
    public void unsetViewModeListener(ModeChangeListener listener) {
        mViewMode.removeListener(listener);
    }

    @Override
    public ConversationListCallbacks getListHandler() {
        return mController;
    }

    @Override
    public FolderChangeListener getFolderChangeListener() {
        return mController;
    }

    @Override
    public FolderListSelectionListener getFolderListSelectionListener() {
        return mController;
    }

    @Override
    public Settings getSettings() {
        return mController.getSettings();
    }

    @Override
    public boolean shouldShowFirstConversation() {
        return mController.shouldShowFirstConversation();
    }

    @Override
    public ConversationSelectionSet getSelectedSet() {
        return mController.getSelectedSet();
    }

    @Override
    public boolean supportsDrag(DragEvent event, Folder folder) {
        return mController.supportsDrag(event, folder);
    }

    @Override
    public void handleDrop(DragEvent event, Folder folder) {
        mController.handleDrop(event, folder);
    }

    @Override
    public void onUndoCancel() {
        mController.onUndoCancel();
    }

    @Override
    public void onUndoAvailable(UndoOperation undoOp) {
        mController.onUndoAvailable(undoOp);
    }

    @Override
    public void onConversationSeen(Conversation conv) {
        mController.onConversationSeen(conv);
    }

    @Override
    public Folder getCurrentFolder() {
        return mController.getFolder();
    }

    @Override
    public ConversationUpdater getConversationUpdater() {
        return mController;
    }
}