1 /* 2 * Copyright (C) 2011 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.R; 20 import com.android.emailcommon.provider.Account; 21 import com.android.emailcommon.utility.EmailAsyncTask; 22 import com.android.emailcommon.utility.Utility; 23 import com.google.common.annotations.VisibleForTesting; 24 25 import android.app.Activity; 26 import android.content.Context; 27 import android.content.Intent; 28 import android.net.Uri; 29 import android.os.Bundle; 30 31 /** 32 * A dummy activity to support old-style (pre-honeycomb) account shortcuts. 33 */ 34 public class MessageList extends Activity { 35 @VisibleForTesting 36 static final String EXTRA_ACCOUNT_ID = "com.android.email.activity._ACCOUNT_ID"; 37 38 private final EmailAsyncTask.Tracker mTaskTracker = new EmailAsyncTask.Tracker(); 39 40 @Override 41 protected void onCreate(Bundle savedInstanceState) { 42 super.onCreate(savedInstanceState); 43 44 final Activity me = this; 45 new EmailAsyncTask<Void, Void, Long>(mTaskTracker) { 46 @Override 47 protected Long doInBackground(Void... params) { 48 return getAccountFromIntent(me, getIntent()); 49 } 50 51 @Override 52 protected void onSuccess(Long accountId) { 53 if ((accountId == null) || (accountId == Account.NO_ACCOUNT)) { 54 // Account deleted? 55 Utility.showToast(me, R.string.toast_account_not_found); 56 Welcome.actionStart(me); 57 } else { 58 Welcome.actionOpenAccountInbox(me, accountId); 59 } 60 finish(); 61 } 62 }.executeParallel(); 63 } 64 65 @Override 66 protected void onDestroy() { 67 mTaskTracker.cancellAllInterrupt(); 68 super.onDestroy(); 69 } 70 71 @VisibleForTesting 72 static long getAccountFromIntent(Context context, Intent i) { 73 final Uri uri = i.getData(); 74 if (uri == null) { 75 return Account.NO_ACCOUNT; 76 } 77 return Account.getAccountIdFromShortcutSafeUri(context, uri); 78 } 79 80 /** 81 * Create a froyo/gingerbread style account shortcut intent. Used by unit tests and 82 * test code in {@link ShortcutPicker}. 83 */ 84 @VisibleForTesting 85 static Intent createFroyoIntent(Context context, Account account) { 86 final Intent intent = new Intent(context, MessageList.class); 87 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 88 intent.putExtra(EXTRA_ACCOUNT_ID, account.mId); 89 intent.setData(account.getShortcutSafeUri()); 90 91 return intent; 92 } 93 } 94