Welcome.java revision 9fe51f632965f5d085ae45a1089c7c97dcec8881
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 17package com.android.email.activity; 18 19import com.android.email.AccountBackupRestore; 20import com.android.email.ExchangeUtils; 21import com.android.email.activity.setup.AccountSetupBasics; 22import com.android.email.provider.EmailContent.Account; 23import com.android.email.provider.EmailContent.Mailbox; 24 25import android.app.Activity; 26import android.content.Intent; 27import android.database.Cursor; 28import android.os.Bundle; 29 30/** 31 * The Welcome activity initializes the application and decides what Activity 32 * the user should start with. 33 * If no accounts are configured the user is taken to the AccountSetupBasics Activity where they 34 * can configure an account. 35 * If a single account is configured the user is taken directly to the MessageList for 36 * the INBOX of that account. 37 * If more than one account is configured the user is taken to the AccountFolderList Activity so 38 * they can select an account. 39 */ 40public class Welcome extends Activity { 41 42 public static void actionStart(Activity fromActivity) { 43 Intent i = new Intent(fromActivity, Welcome.class); 44 fromActivity.startActivity(i); 45 } 46 47 @Override 48 public void onCreate(Bundle icicle) { 49 super.onCreate(icicle); 50 51 // Restore accounts, if it has not happened already 52 // NOTE: This is blocking, which it should not be (in the UI thread) 53 // We're going to live with this for the short term and replace with something 54 // smarter. Long-term fix: Move this, and most of the code below, to an AsyncTask 55 // and do the DB work in a thread. Then post handler to finish() as appropriate. 56 AccountBackupRestore.restoreAccountsIfNeeded(this); 57 58 // Because the app could be reloaded (for debugging, etc.), we need to make sure that 59 // SyncManager gets a chance to start. There is no harm to starting it if it has already 60 // been started 61 // TODO More completely separate SyncManager from Email app 62 ExchangeUtils.startExchangeService(this); 63 64 // Find out how many accounts we have, and if there's just one, go directly to it 65 Cursor c = null; 66 try { 67 c = getContentResolver().query( 68 Account.CONTENT_URI, 69 Account.ID_PROJECTION, 70 null, null, null); 71 switch (c.getCount()) { 72 case 0: 73 AccountSetupBasics.actionNewAccount(this); 74 break; 75 case 1: 76 c.moveToFirst(); 77 long accountId = c.getLong(Account.CONTENT_ID_COLUMN); 78 MessageList.actionHandleAccount(this, accountId, Mailbox.TYPE_INBOX); 79 break; 80 default: 81 AccountFolderList.actionShowAccounts(this); 82 break; 83 } 84 } finally { 85 if (c != null) { 86 c.close(); 87 } 88 } 89 90 // In all cases, do not return to this activity 91 finish(); 92 } 93} 94