AbstractMailActivity.java revision f6c00b8304062a17d14b484bd1fc33a83c4a90d7
1/*******************************************************************************
2 *      Copyright (C) 2012 Google Inc.
3 *      Licensed to The Android Open Source Project.
4 *
5 *      Licensed under the Apache License, Version 2.0 (the "License");
6 *      you may not use this file except in compliance with the License.
7 *      You may obtain a copy of the License at
8 *
9 *           http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *      Unless required by applicable law or agreed to in writing, software
12 *      distributed under the License is distributed on an "AS IS" BASIS,
13 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *      See the License for the specific language governing permissions and
15 *      limitations under the License.
16 *******************************************************************************/
17
18package com.android.mail.ui;
19
20import android.app.Activity;
21import android.content.Context;
22import android.os.Bundle;
23import android.os.StrictMode;
24
25/**
26 * <p>
27 * A complete Mail activity instance. This is the toplevel class that creates the views and handles
28 * the activity lifecycle.</p>
29 *
30 * <p>This class is abstract to allow many other activities to be quickly created by subclassing
31 * this activity and overriding a small subset of the life cycle methods: for example
32 * ComposeActivity and CreateShortcutActivity.</p>
33 *
34 * <p>In the Gmail codebase, this was called GmailBaseActivity</p>
35 *
36 */
37public abstract class AbstractMailActivity extends Activity
38        implements HelpCallback, RestrictedActivity {
39
40    private final UiHandler mUiHandler = new UiHandler();
41
42    private static final boolean STRICT_MODE = false;
43
44    @Override
45    protected void onCreate(Bundle savedInstanceState) {
46        if (STRICT_MODE) {
47            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
48                    .detectDiskReads()
49                    .detectDiskWrites()
50                    .detectNetwork()   // or .detectAll() for all detectable problems
51                    .penaltyLog()
52                    .build());
53            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
54                    .detectLeakedSqlLiteObjects()
55                    .detectLeakedClosableObjects()
56                    .penaltyLog()
57                    .build());
58        }
59
60        super.onCreate(savedInstanceState);
61        mUiHandler.setEnabled(true);
62    }
63
64    @Override
65    protected void onStart() {
66        super.onStart();
67
68        mUiHandler.setEnabled(true);
69    }
70
71    @Override
72    protected void onSaveInstanceState(Bundle outState) {
73        super.onSaveInstanceState(outState);
74
75        mUiHandler.setEnabled(false);
76    }
77
78    @Override
79    protected void onResume() {
80        super.onResume();
81
82        mUiHandler.setEnabled(true);
83    }
84
85    /**
86     * Get the contextual help parameter for this activity. This can be overridden
87     * to allow the extending activities to return different help context strings.
88     * The default implementation is to return "gm".
89     * @return The help context of this activity.
90     */
91    @Override
92    public String getHelpContext() {
93        return "Mail";
94    }
95
96    @Override
97    public Context getActivityContext() {
98        return this;
99    }
100}
101