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 /**
     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  */
     37 public abstract class AbstractMailActivity extends ActionBarActivity implements RestrictedActivity {
     38 
     39     private final UiHandler mUiHandler = new UiHandler();
     40 
     41     // STOPSHIP: ship with false
     42     private static final boolean STRICT_MODE = true;
     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     @Override
     86     public Context getActivityContext() {
     87         return this;
     88     }
     89 }
     90