Home | History | Annotate | Download | only in activity
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.email.activity;
     18 
     19 import com.android.email.AccountBackupRestore;
     20 import com.android.email.Email;
     21 import com.android.email.ExchangeUtils;
     22 import com.android.email.activity.setup.AccountSetupBasics;
     23 import com.android.email.provider.EmailContent;
     24 import com.android.email.provider.EmailContent.Mailbox;
     25 
     26 import android.app.Activity;
     27 import android.content.Intent;
     28 import android.database.Cursor;
     29 import android.os.Bundle;
     30 
     31 /**
     32  * The Welcome activity initializes the application and decides what Activity
     33  * the user should start with.
     34  * If no accounts are configured the user is taken to the AccountSetupBasics Activity where they
     35  * can configure an account.
     36  * If a single account is configured the user is taken directly to the MessageList for
     37  * the INBOX of that account.
     38  * If more than one account is configured the user is taken to the AccountFolderList Activity so
     39  * they can select an account.
     40  */
     41 public class Welcome extends Activity {
     42 
     43     /**
     44      * Launch this activity.  Note:  It's assumed that this activity is only called as a means to
     45      * 'reset' the UI state; Because of this, it is always launched with FLAG_ACTIVITY_CLEAR_TOP,
     46      * which will drop any other activities on the stack (e.g. AccountFolderList or MessageList).
     47      */
     48     public static void actionStart(Activity fromActivity) {
     49         Intent i = new Intent(fromActivity, Welcome.class);
     50         i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     51         fromActivity.startActivity(i);
     52     }
     53 
     54     @Override
     55     public void onCreate(Bundle icicle) {
     56         super.onCreate(icicle);
     57 
     58         // Reset the "accounts changed" notification, now that we're here
     59         Email.setNotifyUiAccountsChanged(false);
     60 
     61         // Quickly check for bulk upgrades (from older app versions) and switch to the
     62         // upgrade activity if necessary
     63         if (UpgradeAccounts.doBulkUpgradeIfNecessary(this)) {
     64             finish();
     65             return;
     66         }
     67 
     68         // Restore accounts, if it has not happened already
     69         // NOTE:  This is blocking, which it should not be (in the UI thread)
     70         // We're going to live with this for the short term and replace with something
     71         // smarter.  Long-term fix:  Move this, and most of the code below, to an AsyncTask
     72         // and do the DB work in a thread.  Then post handler to finish() as appropriate.
     73         AccountBackupRestore.restoreAccountsIfNeeded(this);
     74 
     75         // Because the app could be reloaded (for debugging, etc.), we need to make sure that
     76         // SyncManager gets a chance to start.  There is no harm to starting it if it has already
     77         // been started
     78         // TODO More completely separate SyncManager from Email app
     79         ExchangeUtils.startExchangeService(this);
     80 
     81         // Find out how many accounts we have, and if there's just one, go directly to it
     82         Cursor c = null;
     83         try {
     84             c = getContentResolver().query(
     85                     EmailContent.Account.CONTENT_URI,
     86                     EmailContent.Account.ID_PROJECTION,
     87                     null, null, null);
     88             switch (c.getCount()) {
     89                 case 0:
     90                     AccountSetupBasics.actionNewAccount(this);
     91                     break;
     92                 case 1:
     93                     c.moveToFirst();
     94                     long accountId = c.getLong(EmailContent.Account.CONTENT_ID_COLUMN);
     95                     MessageList.actionHandleAccount(this, accountId, Mailbox.TYPE_INBOX);
     96                     break;
     97                 default:
     98                     AccountFolderList.actionShowAccounts(this);
     99                     break;
    100             }
    101         } finally {
    102             if (c != null) {
    103                 c.close();
    104             }
    105         }
    106 
    107         // In all cases, do not return to this activity
    108         finish();
    109     }
    110 }
    111