• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 package com.android.mail.ui;
19 
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.os.StrictMode;
23 import androidx.appcompat.app.AppCompatActivity;
24 
25 import java.io.FileDescriptor;
26 import java.io.PrintWriter;
27 
28 /**
29  * <p>
30  * A complete Mail activity instance. This is the toplevel class that creates the views and handles
31  * the activity lifecycle.</p>
32  *
33  * <p>This class is abstract to allow many other activities to be quickly created by subclassing
34  * this activity and overriding a small subset of the life cycle methods: for example
35  * ComposeActivity and CreateShortcutActivity.</p>
36  *
37  * <p>In the Gmail codebase, this was called GmailBaseActivity</p>
38  *
39  */
40 public abstract class AbstractMailActivity extends AppCompatActivity implements RestrictedActivity {
41 
42     private final UiHandler mUiHandler = new UiHandler();
43 
44     // STOPSHIP: ship with false
45     private static final boolean STRICT_MODE = true;
46 
47     @Override
onCreate(Bundle savedInstanceState)48     protected void onCreate(Bundle savedInstanceState) {
49         if (STRICT_MODE) {
50             StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
51                     .detectDiskReads()
52                     .detectDiskWrites()
53                     .detectNetwork()   // or .detectAll() for all detectable problems
54                     .penaltyLog()
55                     .build());
56             StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
57                     .detectLeakedSqlLiteObjects()
58                     .detectLeakedClosableObjects()
59                     .penaltyLog()
60                     .build());
61         }
62 
63         super.onCreate(savedInstanceState);
64         mUiHandler.setEnabled(true);
65     }
66 
67     @Override
onStart()68     protected void onStart() {
69         super.onStart();
70 
71         mUiHandler.setEnabled(true);
72     }
73 
74     @Override
onSaveInstanceState(Bundle outState)75     protected void onSaveInstanceState(Bundle outState) {
76         super.onSaveInstanceState(outState);
77 
78         mUiHandler.setEnabled(false);
79     }
80 
81     @Override
onResume()82     protected void onResume() {
83         super.onResume();
84 
85         mUiHandler.setEnabled(true);
86     }
87 
88     @Override
getActivityContext()89     public Context getActivityContext() {
90         return this;
91     }
92 
93     @Override
dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)94     public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
95         super.dump(prefix, fd, writer, args);
96         // Supplementally dump the contents of the OS LoaderManager and FragmentManager.
97         // Both are still possible to use, and the supportlib dump reads from neither.
98         getLoaderManager().dump(prefix, fd, writer, args);
99         getFragmentManager().dump(prefix, fd, writer, args);
100     }
101 
102 }
103