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