Lixin Yue | 24fc763 | 2009-12-04 17:03:00 +0800 | [diff] [blame] | 1 | //package com.motorola.vcardshare; |
| 2 | |
| 3 | package com.android.contacts; |
| 4 | |
| 5 | import java.util.List; |
| 6 | import com.android.contacts.model.Sources; |
| 7 | import com.android.contacts.util.AccountSelectionUtil; |
| 8 | import android.accounts.Account; |
| 9 | import android.app.Activity; |
| 10 | import android.content.Intent; |
| 11 | import android.net.Uri; |
| 12 | import android.os.Bundle; |
| 13 | import android.util.Log; |
| 14 | |
| 15 | public class VCardActivity extends Activity { |
| 16 | private static final String TAG = "VCardActivity"; |
| 17 | public static final int IMPORT_TYPE_GOOGLE = 0; |
| 18 | public static final int IMPORT_TYPE_EXCHANGE = 1; |
| 19 | |
| 20 | /** Called when the activity is first created. */ |
| 21 | @Override |
| 22 | public void onCreate(Bundle savedInstanceState) { |
| 23 | super.onCreate(savedInstanceState); |
| 24 | setContentView(R.layout.vcardshare_main); |
| 25 | |
| 26 | Intent intent = getIntent(); |
| 27 | String action = intent.getAction(); |
| 28 | Log.v(TAG, "action is " + action); |
| 29 | Uri path = intent.getData(); |
| 30 | Log.v(TAG, "path is " + path); |
| 31 | String mimeType = intent.getType(); |
| 32 | Log.v(TAG, "mimeType is " + mimeType); |
| 33 | |
| 34 | if (action.equals(Intent.ACTION_VIEW)) { |
| 35 | |
| 36 | AccountSelectionUtil.mVCardShare = true; |
| 37 | AccountSelectionUtil.mPath = path; |
| 38 | handleImportRequest(R.string.import_from_sdcard); |
| 39 | } else { |
| 40 | Log.w(TAG, "VcardActivity not handle such action: " + action); |
| 41 | } |
| 42 | finish(); |
| 43 | } |
| 44 | |
| 45 | private void handleImportRequest(int resId) { |
| 46 | // There's three possibilities: |
| 47 | // - more than one accounts -> ask the user |
| 48 | // - just one account -> use the account without asking the user |
| 49 | // - no account -> use phone-local storage without asking the user |
| 50 | final Sources sources = Sources.getInstance(this); |
| 51 | final List<Account> accountList = sources.getAccounts(true); |
| 52 | final int size = accountList.size(); |
| 53 | Log.v(TAG, "account num = " + size); |
| 54 | |
| 55 | if (size > 1) { |
| 56 | // showDialog(resId); |
| 57 | AccountSelectionUtil.getSelectAccountDialog(this, resId); |
| 58 | } |
| 59 | |
| 60 | AccountSelectionUtil.doImport(this, resId, (size == 1 ? accountList.get(0) : null)); |
| 61 | } |
| 62 | } |