Welcome.java revision e59c8725c595ae21dff5e04dc418818a18555a55
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.activity.setup.AccountSetupBasics;
20import com.android.email.provider.EmailContent.Account;
21import com.android.email.provider.EmailContent.Mailbox;
22import com.android.exchange.SyncManager;
23
24import android.app.Activity;
25import android.content.Intent;
26import android.database.Cursor;
27import android.os.Bundle;
28
29/**
30 * The Welcome activity initializes the application and decides what Activity
31 * the user should start with.
32 * If no accounts are configured the user is taken to the AccountSetupBasics Activity where they
33 * can configure an account.
34 * If a single account is configured the user is taken directly to the MessageList for
35 * the INBOX of that account.
36 * If more than one account is configured the user is taken to the AccountFolderList Activity so
37 * they can select an account.
38 */
39public class Welcome extends Activity {
40
41    @Override
42    public void onCreate(Bundle icicle) {
43        super.onCreate(icicle);
44
45        // Because the app could be reloaded (for debugging, etc.), we need to make sure that
46        // SyncManager gets a chance to start.  There is no harm to starting it if it has already
47        // been started
48        // TODO More completely separate SyncManager from Email app
49        startService(new Intent(this, SyncManager.class));
50
51        // Find out how many accounts we have, and if there's just one, go directly to it
52        Cursor c = null;
53        try {
54            c = getContentResolver().query(
55                    Account.CONTENT_URI,
56                    Account.ID_PROJECTION,
57                    null, null, null);
58            switch (c.getCount()) {
59                case 0:
60                    AccountSetupBasics.actionNewAccount(this);
61                    break;
62                case 1:
63                    c.moveToFirst();
64                    long accountId = c.getLong(Account.CONTENT_ID_COLUMN);
65                    MessageList.actionHandleAccount(this, accountId, Mailbox.TYPE_INBOX);
66                    break;
67                default:
68                    AccountFolderList.actionShowAccounts(this);
69                    break;
70            }
71        } finally {
72            if (c != null) {
73                c.close();
74            }
75        }
76
77        // In all cases, do not return to this activity
78        finish();
79    }
80}
81