Make notification open XL activity on tablet

* Now notification kicks Welcome, which knows which
  activity to use.
* Extracted cancelNewMessageNotification
* Also fixed 2909215.  There'll be only one XL activity on the app stack.

Bug 2945369
Bug 2909215

Change-Id: I2a7fec0d48a7618375cae55138ca51fefc70ff6e
This commit is contained in:
Makoto Onuki 2010-08-24 19:09:34 -07:00
parent 4829dfaf7f
commit 0be2d85bb8
6 changed files with 126 additions and 33 deletions

View File

@ -207,9 +207,7 @@ public class AccountFolderList extends Activity implements AccountFolderListFrag
public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_REMOVE_ACCOUNT);
// Clear notifications, which may become stale here
NotificationManager notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(MailService.NOTIFICATION_ID_NEW_MESSAGES);
MailService.cancelNewMessageNotification(AccountFolderList.this);
int numAccounts = EmailContent.count(AccountFolderList.this,
Account.CONTENT_URI, null, null);
mListFragment.hideDeletingAccount(mSelectedContextAccount.mId);

View File

@ -237,9 +237,7 @@ public class MessageList extends Activity implements OnClickListener,
mController.addResultCallback(mControllerCallback);
// clear notifications here
NotificationManager notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(MailService.NOTIFICATION_ID_NEW_MESSAGES);
MailService.cancelNewMessageNotification(this);
// Exit immediately if the accounts list has changed (e.g. externally deleted)
if (Email.getNotifyUiAccountsChanged()) {

View File

@ -22,6 +22,8 @@ import com.android.email.RefreshManager;
import com.android.email.Utility;
import com.android.email.activity.setup.AccountSettingsXL;
import com.android.email.activity.setup.AccountSetupBasics;
import com.android.email.provider.EmailContent.Mailbox;
import com.android.email.service.MailService;
import android.app.ActionBar;
import android.app.Activity;
@ -38,6 +40,8 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.security.InvalidParameterException;
// TODO Where/when/how do we close loaders?? Do we have to? Getting this error:
// Finalizing a Cursor that has not been deactivated or closed.
// database = /data/data/com.google.android.email/databases/EmailProvider.db,
@ -51,7 +55,8 @@ import android.view.View;
*/
public class MessageListXL extends Activity implements View.OnClickListener,
MessageListXLFragmentManager.TargetActivity {
private static final String EXTRA_ACCOUNT_ID = "com.android.email.activity._ACCOUNT_ID";
private static final String EXTRA_ACCOUNT_ID = "ACCOUNT_ID";
private static final String EXTRA_MAILBOX_ID = "MAILBOX_ID";
private static final int LOADER_ID_ACCOUNT_LIST = 0;
private Context mContext;
@ -77,12 +82,32 @@ public class MessageListXL extends Activity implements View.OnClickListener,
/**
* Launch and open account's inbox.
*
* @param accountId If -1, default account will be used.
*/
public static void actionStart(Activity fromActivity, long accountId) {
public static void actionOpenAccount(Activity fromActivity, long accountId) {
Intent i = new Intent(fromActivity, MessageListXL.class);
if (accountId != -1) {
i.putExtra(EXTRA_ACCOUNT_ID, accountId);
}
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fromActivity.startActivity(i);
}
/**
* Launch and open a mailbox.
*
* @param accountId must not be -1.
* @param mailboxId must not be -1.
*/
public static void actionOpenMailbox(Activity fromActivity, long accountId, long mailboxId) {
Intent i = new Intent(fromActivity, MessageListXL.class);
if (accountId == -1 || mailboxId == -1) {
throw new InvalidParameterException();
}
i.putExtra(EXTRA_ACCOUNT_ID, accountId);
i.putExtra(EXTRA_MAILBOX_ID, Mailbox.QUERY_ALL_INBOXES);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fromActivity.startActivity(i);
}
@ -126,8 +151,14 @@ public class MessageListXL extends Activity implements View.OnClickListener,
private void initFromIntent() {
final Intent i = getIntent();
final long accountId = i.getLongExtra(EXTRA_ACCOUNT_ID, -1);
final long mailboxId = i.getLongExtra(EXTRA_MAILBOX_ID, -1);
if (Email.DEBUG) {
Log.d(Email.LOG_TAG,
String.format("Welcome: %d %d", accountId, mailboxId));
}
if (accountId != -1) {
mFragmentManager.selectAccount(accountId);
mFragmentManager.selectAccount(accountId, mailboxId, true);
}
}
@ -156,6 +187,8 @@ public class MessageListXL extends Activity implements View.OnClickListener,
protected void onResume() {
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) Log.d(Email.LOG_TAG, "MessageListXL onResume");
super.onResume();
MailService.cancelNewMessageNotification(this);
// TODO Add stuff that's done in MessageList.onResume().
}
@ -488,7 +521,7 @@ public class MessageListXL extends Activity implements View.OnClickListener,
@Override
public boolean onNavigationItemSelected(int itemPosition, long accountId) {
if (Email.DEBUG) Log.d(Email.LOG_TAG, "Account selected: accountId=" + accountId);
mFragmentManager.selectAccount(accountId);
mFragmentManager.selectAccount(accountId, -1, true);
return true;
}
}

View File

@ -252,8 +252,13 @@ class MessageListXLFragmentManager {
/**
* Call it to select an account.
*
* @param accountId account ID. Must not be -1.
* @param mailboxId mailbox ID. Pass -1 to open account's inbox.
* @param byExplicitUserAction set true if the user is explicitly opening the mailbox,
* in which case we perform "auto-refresh".
*/
public void selectAccount(long accountId) {
public void selectAccount(long accountId, long mailboxId, boolean byExplicitUserAction) {
// TODO Handle "combined mailboxes".
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Email.LOG_TAG, "selectAccount mAccountId=" + accountId);
@ -298,7 +303,11 @@ class MessageListXLFragmentManager {
Log.w(Email.LOG_TAG, "MailboxListFragment not set yet.");
}
if (mailboxId == -1) {
startInboxLookup();
} else {
selectMailbox(mailboxId, byExplicitUserAction);
}
}
private void updateMailboxListFragment(MailboxListFragment fragment) {
@ -311,6 +320,9 @@ class MessageListXLFragmentManager {
mMailboxListFragment = fragment;
fragment.setCallback(mMailboxListFragmentCallback);
fragment.openMailboxes(mAccountId);
if (mMailboxId != -1) {
mMailboxListFragment.setSelectedMailbox(mMailboxId);
}
}
/**

View File

@ -39,15 +39,37 @@ import android.os.Handler;
/**
* The Welcome activity initializes the application and decides what Activity
* the user should start with.
* If no accounts are configured the user is taken to the AccountSetupBasics Activity where they
* can configure an account.
* If a single account is configured the user is taken directly to the MessageList for
* the INBOX of that account.
* If more than one account is configured the user is taken to the AccountFolderList Activity so
* they can select an account.
*
* This class knows which activity should be launched under the current configuration (screen size)
* and the number of accounts configured. So if you want to open an account or a mailbox,
* you should alawys do so via its static methods, such as {@link #actionOpenAccountInbox}.
*/
public class Welcome extends Activity {
private static final String EXTRA_ACCOUNT_ID = "com.android.email.activity._ACCOUNT_ID";
/*
* Commands for testing...
* Open 1 pane
adb shell am start -a android.intent.action.MAIN \
-n com.google.android.email/com.android.email.activity.Welcome \
-e DEBUG_PANE_MODE 1
* Open 2 pane
adb shell am start -a android.intent.action.MAIN \
-n com.google.android.email/com.android.email.activity.Welcome \
-e DEBUG_PANE_MODE 2
* Open an account (ID=2) in 2 pane
adb shell am start -a android.intent.action.MAIN \
-n com.google.android.email/com.android.email.activity.Welcome \
-e DEBUG_PANE_MODE 2 --el ACCOUNT_ID 2
* Open Combined Inbox (ID=-2) in 2 pane
adb shell am start -a android.intent.action.MAIN \
-n com.google.android.email/com.android.email.activity.Welcome \
-e DEBUG_PANE_MODE 2 --el MAILBOX_ID -2
*/
private static final String EXTRA_ACCOUNT_ID = "ACCOUNT_ID";
private static final String EXTRA_MAILBOX_ID = "MAILBOX_ID";
/**
* Extra for debugging. Set 1 to force one-pane. Set 2 to force two-pane.
@ -79,14 +101,23 @@ public class Welcome extends Activity {
/**
* Create an Intent to open account's inbox.
*/
public static Intent createOpenAccountInboxIntent(Activity fromActivity, long accountId) {
Intent i = new Intent(fromActivity, Welcome.class);
public static Intent createOpenAccountInboxIntent(Context context, long accountId) {
Intent i = new Intent(context, Welcome.class);
if (accountId != -1) {
i.putExtra(EXTRA_ACCOUNT_ID, accountId);
}
return i;
}
/**
* Create an Intent to open "Combined Inbox".
*/
public static Intent createOpenCombinedInboxIntent(Context context) {
Intent i = new Intent(context, Welcome.class);
i.putExtra(EXTRA_MAILBOX_ID, Mailbox.QUERY_ALL_INBOXES);
return i;
}
/**
* Open account's inbox.
*/
@ -147,8 +178,9 @@ public class Welcome extends Activity {
mAccountsUpdatedListener.onAccountsUpdated(null);
final long accountId = getIntent().getLongExtra(EXTRA_ACCOUNT_ID, -1);
final long mailboxId = getIntent().getLongExtra(EXTRA_MAILBOX_ID, -1);
final int debugPaneMode = getDebugPaneMode(getIntent());
new MainActivityLauncher(this, accountId, debugPaneMode).execute();
new MainActivityLauncher(this, accountId, mailboxId, debugPaneMode).execute();
}
@Override
@ -182,13 +214,20 @@ public class Welcome extends Activity {
private final Activity mFromActivity;
private final int mDebugPaneMode;
private final long mAccountId;
private final long mMailboxId;
public MainActivityLauncher(Activity fromActivity, long accountId, int debugPaneMode) {
public MainActivityLauncher(Activity fromActivity, long accountId, long mailboxId,
int debugPaneMode) {
mFromActivity = fromActivity;
mAccountId = accountId;
mMailboxId = mailboxId;
mDebugPaneMode = debugPaneMode;
}
private boolean isMailboxSelected() {
return mMailboxId != -1;
}
@Override
protected Void doInBackground(Void... params) {
final int numAccount =
@ -205,9 +244,18 @@ public class Welcome extends Activity {
|| (useTwoPane(mFromActivity) && mDebugPaneMode == 0);
if (useTwoPane) {
MessageListXL.actionStart(mFromActivity, accountId);
if (isMailboxSelected()) {
MessageListXL.actionOpenMailbox(mFromActivity, accountId, mMailboxId);
} else {
MessageList.actionHandleAccount(mFromActivity, accountId, Mailbox.TYPE_INBOX);
MessageListXL.actionOpenAccount(mFromActivity, accountId);
}
} else {
if (isMailboxSelected()) {
MessageList.actionHandleMailbox(mFromActivity, mMailboxId);
} else {
MessageList.actionHandleAccount(
mFromActivity, accountId, Mailbox.TYPE_INBOX);
}
}
}
return null;

View File

@ -22,14 +22,14 @@ import com.android.email.Email;
import com.android.email.R;
import com.android.email.SecurityPolicy;
import com.android.email.Utility;
import com.android.email.activity.MessageList;
import com.android.email.activity.Welcome;
import com.android.email.mail.MessagingException;
import com.android.email.provider.EmailContent;
import com.android.email.provider.EmailProvider;
import com.android.email.provider.EmailContent.Account;
import com.android.email.provider.EmailContent.AccountColumns;
import com.android.email.provider.EmailContent.HostAuth;
import com.android.email.provider.EmailContent.Mailbox;
import com.android.email.provider.EmailProvider;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
@ -73,7 +73,7 @@ public class MailService extends Service {
private static final String LOG_TAG = "Email-MailService";
public static final int NOTIFICATION_ID_NEW_MESSAGES = 1;
private static final int NOTIFICATION_ID_NEW_MESSAGES = 1;
public static final int NOTIFICATION_ID_SECURITY_NEEDED = 2;
public static final int NOTIFICATION_ID_EXCHANGE_CALENDAR_ADDED = 3;
public static final int NOTIFICATION_ID_WARNING = 4;
@ -188,6 +188,12 @@ public class MailService extends Service {
context.startService(i);
}
public static void cancelNewMessageNotification(Context context) {
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(MailService.NOTIFICATION_ID_NEW_MESSAGES);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
@ -282,9 +288,7 @@ public class MailService extends Service {
// As a precaution, clear any outstanding Email notifications
// We could be smarter and only do this when the list of accounts changes,
// but that's an edge condition and this is much safer.
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID_NEW_MESSAGES);
cancelNewMessageNotification(this);
// When called externally, we refresh the sync reports table to pick up
// any changes in the account list or account settings
@ -754,14 +758,14 @@ public class MailService extends Service {
reportString = getResources().getQuantityString(
R.plurals.notification_new_one_account_fmt, numNewMessages,
numNewMessages, reportName);
intent = MessageList.createIntent(this, accountId, -1, Mailbox.TYPE_INBOX);
intent = Welcome.createOpenAccountInboxIntent(this, accountId);
} else {
// Prepare a report for multiple accounts
// "4 accounts"
reportString = getResources().getQuantityString(
R.plurals.notification_new_multi_account_fmt, accountsWithNewMessages,
accountsWithNewMessages);
intent = MessageList.createIntent(this, -1, Mailbox.QUERY_ALL_INBOXES, -1);
intent = Welcome.createOpenCombinedInboxIntent(this);
}
// prepare appropriate pending intent, set up notification, and send