From 191448b430f36167bd1706c13d77e48d7e7505cf Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Wed, 4 Aug 2010 15:38:25 -0700 Subject: [PATCH] Make Welcome launch MessageListXL Also added the "1 pane" activity to test the phone UI. Change-Id: I1c86d2088a2298ada5028b7a266bd090b593593c --- AndroidManifest.xml | 51 ++++++++----- res/values/strings.xml | 2 + .../android/email/activity/MessageListXL.java | 5 ++ src/com/android/email/activity/Welcome.java | 76 ++++++++++++------- .../android/email/provider/EmailContent.java | 8 ++ 5 files changed, 95 insertions(+), 47 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 060857bbd..fbd61f47f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -59,24 +59,12 @@ - - - - - - - - > + @@ -180,10 +168,11 @@ - - - - + + + + + + + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 076898ba1..df3948f0b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -717,5 +717,7 @@ Email 2 Pane + + Email 1 Pane diff --git a/src/com/android/email/activity/MessageListXL.java b/src/com/android/email/activity/MessageListXL.java index e7ed84c3c..8d23b1693 100644 --- a/src/com/android/email/activity/MessageListXL.java +++ b/src/com/android/email/activity/MessageListXL.java @@ -24,6 +24,7 @@ import android.app.Activity; import android.app.Fragment; import android.app.LoaderManager.LoaderCallbacks; import android.content.Context; +import android.content.Intent; import android.content.Loader; import android.content.pm.ActivityInfo; import android.database.Cursor; @@ -62,6 +63,10 @@ MessageListXLFragmentManager.TargetActivity { private final MessageOrderManagerCallback mMessageOrderManagerCallback = new MessageOrderManagerCallback(); + public static void actionStart(Activity fromActivity) { + fromActivity.startActivity(new Intent(fromActivity, MessageListXL.class)); + } + @Override protected void onCreate(Bundle savedInstanceState) { if (Email.DEBUG_LIFECYCLE && Email.DEBUG) Log.d(Email.LOG_TAG, "MessageListXL onCreate"); diff --git a/src/com/android/email/activity/Welcome.java b/src/com/android/email/activity/Welcome.java index 2db2c898c..8cd40a5d9 100644 --- a/src/com/android/email/activity/Welcome.java +++ b/src/com/android/email/activity/Welcome.java @@ -29,7 +29,9 @@ import android.accounts.AccountManager; import android.accounts.OnAccountsUpdateListener; import android.app.Activity; import android.content.Intent; +import android.content.res.Configuration; import android.database.Cursor; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; @@ -94,34 +96,7 @@ public class Welcome extends Activity { // Run reconciliation to make sure we're up-to-date on account status mAccountsUpdatedListener.onAccountsUpdated(null); - // Find out how many accounts we have, and if there's just one, go directly to it - Cursor c = null; - try { - c = getContentResolver().query( - EmailContent.Account.CONTENT_URI, - EmailContent.Account.ID_PROJECTION, - null, null, null); - switch (c.getCount()) { - case 0: - AccountSetupBasics.actionNewAccount(this); - break; - case 1: - c.moveToFirst(); - long accountId = c.getLong(EmailContent.Account.CONTENT_ID_COLUMN); - MessageList.actionHandleAccount(this, accountId, Mailbox.TYPE_INBOX); - break; - default: - AccountFolderList.actionShowAccounts(this); - break; - } - } finally { - if (c != null) { - c.close(); - } - } - - // In all cases, do not return to this activity - finish(); + new MainActivityLauncher(this).execute(); } @Override @@ -144,4 +119,49 @@ public class Welcome extends Activity { }); } } + + /** + * Open the Activity appropriate to the current configuration. + * + * - If there's 0 accounts, open AccountSetupBasics. + * - If it has XL screen, open MessageListXL. + * - If there's 1 account, open MessageList. + * - Otherwise open AccountFolderList. + */ + private static class MainActivityLauncher extends AsyncTask { + private final Activity mFromActivity; + + public MainActivityLauncher(Activity fromActivity) { + mFromActivity = fromActivity; + } + + @Override + protected Void doInBackground(Void... params) { + final int numAccount = + EmailContent.count(mFromActivity, EmailContent.Account.CONTENT_URI); + if (numAccount == 0) { + AccountSetupBasics.actionNewAccount(mFromActivity); + } else { + final int screenLayout = mFromActivity.getResources().getConfiguration() + .screenLayout; + if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_XLARGE) != 0) { + MessageListXL.actionStart(mFromActivity); + } else { + if (numAccount == 1) { + long accountId = EmailContent.Account.getDefaultAccountId(mFromActivity); + MessageList.actionHandleAccount(mFromActivity, accountId, + Mailbox.TYPE_INBOX); + } else { + AccountFolderList.actionShowAccounts(mFromActivity); + } + } + } + return null; + } + + @Override + protected void onPostExecute(Void result) { + mFromActivity.finish(); + } + } } diff --git a/src/com/android/email/provider/EmailContent.java b/src/com/android/email/provider/EmailContent.java index 91bc6feb4..4bd13e693 100644 --- a/src/com/android/email/provider/EmailContent.java +++ b/src/com/android/email/provider/EmailContent.java @@ -145,6 +145,7 @@ public abstract class EmailContent { /** * Generic count method that can be used for any ContentProvider + * * @param context the calling Context * @param uri the Uri for the provider query * @param selection as with a query call @@ -156,6 +157,13 @@ public abstract class EmailContent { uri, COUNT_COLUMNS, selection, selectionArgs, null, 0, Long.valueOf(0)).intValue(); } + /** + * Same as {@link #count(Context, Uri, String, String[])} without selection. + */ + static public int count(Context context, Uri uri) { + return count(context, uri, null, null); + } + /** * no public constructor since this is a utility class */