Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 1 | /* |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 2 | * Copyright (C) 2009 The Android Open Source Project |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 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.contacts; |
| 18 | |
Dmitri Plotnikov | 6e2009d | 2010-04-22 16:03:53 -0700 | [diff] [blame] | 19 | |
Dmitri Plotnikov | e8a9517 | 2010-06-23 16:18:10 -0700 | [diff] [blame^] | 20 | import com.android.contacts.list.ContactEntryListFragment; |
| 21 | import com.android.contacts.list.ContactsRequest; |
Dmitri Plotnikov | 59fb48e | 2010-04-26 17:09:19 -0700 | [diff] [blame] | 22 | import com.android.contacts.list.JoinContactListFragment; |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 23 | import com.android.contacts.list.OnContactPickerActionListener; |
Dmitri Plotnikov | e8a9517 | 2010-06-23 16:18:10 -0700 | [diff] [blame^] | 24 | import com.android.contacts.ui.ContactsPreferencesActivity; |
Dmitri Plotnikov | 807a0fe | 2010-04-20 12:03:10 -0700 | [diff] [blame] | 25 | |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 26 | import android.app.Activity; |
| 27 | import android.app.FragmentTransaction; |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 28 | import android.content.Intent; |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 29 | import android.net.Uri; |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 30 | import android.os.Bundle; |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 31 | import android.provider.ContactsContract; |
Dmitri Plotnikov | e8a9517 | 2010-06-23 16:18:10 -0700 | [diff] [blame^] | 32 | import android.provider.Settings; |
| 33 | import android.provider.ContactsContract.Contacts; |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 34 | import android.util.Log; |
Dmitri Plotnikov | e8a9517 | 2010-06-23 16:18:10 -0700 | [diff] [blame^] | 35 | import android.view.Menu; |
| 36 | import android.view.MenuInflater; |
| 37 | import android.view.MenuItem; |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * An activity that shows a list of contacts that can be joined with the target contact. |
| 41 | */ |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 42 | public class JoinContactActivity extends Activity { |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 43 | |
| 44 | private static final String TAG = "JoinContactActivity"; |
| 45 | |
| 46 | /** |
| 47 | * The action for the join contact activity. |
| 48 | * <p> |
| 49 | * Input: extra field {@link #EXTRA_TARGET_CONTACT_ID} is the aggregate ID. |
| 50 | * TODO: move to {@link ContactsContract}. |
| 51 | */ |
| 52 | public static final String JOIN_CONTACT = "com.android.contacts.action.JOIN_CONTACT"; |
| 53 | |
| 54 | /** |
| 55 | * Used with {@link #JOIN_CONTACT} to give it the target for aggregation. |
| 56 | * <p> |
| 57 | * Type: LONG |
| 58 | */ |
| 59 | public static final String EXTRA_TARGET_CONTACT_ID = "com.android.contacts.action.CONTACT_ID"; |
| 60 | |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 61 | private long mTargetContactId; |
| 62 | |
Dmitri Plotnikov | e8a9517 | 2010-06-23 16:18:10 -0700 | [diff] [blame^] | 63 | private JoinContactListFragment mListFragment; |
| 64 | |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 65 | @Override |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 66 | protected void onCreate(Bundle savedInstanceState) { |
| 67 | super.onCreate(savedInstanceState); |
| 68 | |
| 69 | Intent intent = getIntent(); |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 70 | mTargetContactId = intent.getLongExtra(EXTRA_TARGET_CONTACT_ID, -1); |
| 71 | if (mTargetContactId == -1) { |
| 72 | Log.e(TAG, "Intent " + intent.getAction() + " is missing required extra: " |
| 73 | + EXTRA_TARGET_CONTACT_ID); |
| 74 | setResult(RESULT_CANCELED); |
| 75 | finish(); |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 76 | return; |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 77 | } |
Dmitri Plotnikov | 59fb48e | 2010-04-26 17:09:19 -0700 | [diff] [blame] | 78 | |
Dmitri Plotnikov | e8a9517 | 2010-06-23 16:18:10 -0700 | [diff] [blame^] | 79 | mListFragment = new JoinContactListFragment(); |
| 80 | mListFragment.setTargetContactId(mTargetContactId); |
| 81 | mListFragment.setOnContactPickerActionListener(new OnContactPickerActionListener() { |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 82 | public void onPickContactAction(Uri contactUri) { |
| 83 | Intent intent = new Intent(null, contactUri); |
| 84 | setResult(RESULT_OK, intent); |
| 85 | finish(); |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 88 | public void onSearchAllContactsAction(String string) { |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 91 | public void onShortcutIntentCreated(Intent intent) { |
| 92 | } |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 93 | |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 94 | public void onCreateNewContactAction() { |
| 95 | } |
| 96 | }); |
| 97 | |
| 98 | FragmentTransaction transaction = openFragmentTransaction(); |
Dmitri Plotnikov | e8a9517 | 2010-06-23 16:18:10 -0700 | [diff] [blame^] | 99 | transaction.add(android.R.id.content, mListFragment); |
Dmitri Plotnikov | e4d32d9 | 2010-05-10 19:06:22 -0700 | [diff] [blame] | 100 | transaction.commit(); |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 101 | } |
Dmitri Plotnikov | e8a9517 | 2010-06-23 16:18:10 -0700 | [diff] [blame^] | 102 | |
| 103 | @Override |
| 104 | public boolean onCreateOptionsMenu(Menu menu) { |
| 105 | MenuInflater inflater = getMenuInflater(); |
| 106 | inflater.inflate(R.menu.search, menu); |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public boolean onOptionsItemSelected(MenuItem item) { |
| 112 | switch (item.getItemId()) { |
| 113 | case R.id.menu_search: { |
| 114 | onSearchRequested(); |
| 115 | return true; |
| 116 | } |
| 117 | } |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, |
| 123 | boolean globalSearch) { |
| 124 | if (globalSearch) { |
| 125 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 126 | } else { |
| 127 | mListFragment.startSearch(initialQuery); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 133 | if (requestCode == ContactEntryListFragment.ACTIVITY_REQUEST_CODE_PICKER |
| 134 | && resultCode == RESULT_OK) { |
| 135 | mListFragment.onPickerResult(data); |
| 136 | } |
| 137 | } |
Dmitri Plotnikov | 501b7ea | 2010-04-07 17:20:49 -0700 | [diff] [blame] | 138 | } |