Home | History | Annotate | Download | only in ui
      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 android.support.v7.app.ActionBarActivity;
     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 ActionBarActivity implements RestrictedActivity {
     41 
     42     private final UiHandler mUiHandler = new UiHandler();
     43 
     44     private static final boolean STRICT_MODE = false;
     45 
     46     @Override
     47     protected void onCreate(Bundle savedInstanceState) {
     48         if (STRICT_MODE) {
     49             StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
     50                     .detectDiskReads()
     51                     .detectDiskWrites()
     52                     .detectNetwork()   // or .detectAll() for all detectable problems
     53                     .penaltyLog()
     54                     .build());
     55             StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
     56                     .detectLeakedSqlLiteObjects()
     57                     .detectLeakedClosableObjects()
     58                     .penaltyLog()
     59                     .build());
     60         }
     61 
     62         super.onCreate(savedInstanceState);
     63         mUiHandler.setEnabled(true);
     64     }
     65 
     66     @Override
     67     protected void onStart() {
     68         super.onStart();
     69 
     70         mUiHandler.setEnabled(true);
     71     }
     72 
     73     @Override
     74     protected void onSaveInstanceState(Bundle outState) {
     75         super.onSaveInstanceState(outState);
     76 
     77         mUiHandler.setEnabled(false);
     78     }
     79 
     80     @Override
     81     protected void onResume() {
     82         super.onResume();
     83 
     84         mUiHandler.setEnabled(true);
     85     }
     86 
     87     @Override
     88     public Context getActivityContext() {
     89         return this;
     90     }
     91 
     92     @Override
     93     public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
     94         super.dump(prefix, fd, writer, args);
     95         // Supplementally dump the contents of the OS LoaderManager and FragmentManager.
     96         // Both are still possible to use, and the supportlib dump reads from neither.
     97         getLoaderManager().dump(prefix, fd, writer, args);
     98         getFragmentManager().dump(prefix, fd, writer, args);
     99     }
    100 
    101 }
    102