blob: ef04be63b437661d072f7285bf3f814f2f03d8c4 [file] [log] [blame]
Lixin Yue24fc7632009-12-04 17:03:00 +08001//package com.motorola.vcardshare;
2
3package com.android.contacts;
4
5import java.util.List;
6import com.android.contacts.model.Sources;
7import com.android.contacts.util.AccountSelectionUtil;
8import android.accounts.Account;
9import android.app.Activity;
10import android.content.Intent;
11import android.net.Uri;
12import android.os.Bundle;
13import android.util.Log;
14
15public 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}