PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/CVox/src/com/android/contacts/EditContactActivity.java

http://eyes-free.googlecode.com/
Java | 1583 lines | 73 code | 7 blank | 1503 comment | 1 complexity | 2294fbfd5d8aa880e37b7e2945d6f66b MD5 | raw file
Possible License(s): GPL-3.0, Apache-2.0
  1. /*
  2. * Copyright (C) 2007 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. package com.android.contacts;
  17. //import com.google.android.collect.Lists;
  18. //
  19. //import static com.android.contacts.ContactEntryAdapter.CONTACT_CUSTOM_RINGTONE_COLUMN;
  20. //import static com.android.contacts.ContactEntryAdapter.CONTACT_NAME_COLUMN;
  21. //import static com.android.contacts.ContactEntryAdapter.CONTACT_NOTES_COLUMN;
  22. //import static com.android.contacts.ContactEntryAdapter.CONTACT_PROJECTION;
  23. //import static com.android.contacts.ContactEntryAdapter.CONTACT_SEND_TO_VOICEMAIL_COLUMN;
  24. //import static com.android.contacts.ContactEntryAdapter.METHODS_AUX_DATA_COLUMN;
  25. //import static com.android.contacts.ContactEntryAdapter.METHODS_DATA_COLUMN;
  26. //import static com.android.contacts.ContactEntryAdapter.METHODS_ID_COLUMN;
  27. //import static com.android.contacts.ContactEntryAdapter.METHODS_ISPRIMARY_COLUMN;
  28. //import static com.android.contacts.ContactEntryAdapter.METHODS_KIND_COLUMN;
  29. //import static com.android.contacts.ContactEntryAdapter.METHODS_LABEL_COLUMN;
  30. //import static com.android.contacts.ContactEntryAdapter.METHODS_PROJECTION;
  31. //import static com.android.contacts.ContactEntryAdapter.METHODS_TYPE_COLUMN;
  32. //import static com.android.contacts.ContactEntryAdapter.ORGANIZATIONS_COMPANY_COLUMN;
  33. //import static com.android.contacts.ContactEntryAdapter.ORGANIZATIONS_ID_COLUMN;
  34. //import static com.android.contacts.ContactEntryAdapter.ORGANIZATIONS_ISPRIMARY_COLUMN;
  35. //import static com.android.contacts.ContactEntryAdapter.ORGANIZATIONS_LABEL_COLUMN;
  36. //import static com.android.contacts.ContactEntryAdapter.ORGANIZATIONS_PROJECTION;
  37. //import static com.android.contacts.ContactEntryAdapter.ORGANIZATIONS_TITLE_COLUMN;
  38. //import static com.android.contacts.ContactEntryAdapter.ORGANIZATIONS_TYPE_COLUMN;
  39. //import static com.android.contacts.ContactEntryAdapter.PHONES_ID_COLUMN;
  40. //import static com.android.contacts.ContactEntryAdapter.PHONES_ISPRIMARY_COLUMN;
  41. //import static com.android.contacts.ContactEntryAdapter.PHONES_LABEL_COLUMN;
  42. //import static com.android.contacts.ContactEntryAdapter.PHONES_NUMBER_COLUMN;
  43. //import static com.android.contacts.ContactEntryAdapter.PHONES_PROJECTION;
  44. //import static com.android.contacts.ContactEntryAdapter.PHONES_TYPE_COLUMN;
  45. import android.app.Activity;
  46. import android.app.AlertDialog;
  47. import android.app.Dialog;
  48. import android.content.ActivityNotFoundException;
  49. import android.content.ContentResolver;
  50. import android.content.ContentUris;
  51. import android.content.ContentValues;
  52. import android.content.Context;
  53. import android.content.DialogInterface;
  54. import android.content.Intent;
  55. import android.content.SharedPreferences;
  56. import android.content.res.Resources;
  57. import android.database.Cursor;
  58. import android.graphics.Bitmap;
  59. import android.media.Ringtone;
  60. import android.media.RingtoneManager;
  61. import android.net.Uri;
  62. import android.os.Bundle;
  63. import android.os.Parcel;
  64. import android.os.Parcelable;
  65. import android.preference.PreferenceManager;
  66. import android.provider.Contacts;
  67. import android.provider.Contacts.ContactMethods;
  68. import android.provider.Contacts.Intents.Insert;
  69. import android.provider.Contacts.Organizations;
  70. import android.provider.Contacts.People;
  71. import android.provider.Contacts.Phones;
  72. import android.telephony.PhoneNumberFormattingTextWatcher;
  73. import android.text.TextUtils;
  74. import android.text.method.DialerKeyListener;
  75. import android.text.method.TextKeyListener;
  76. import android.text.method.TextKeyListener.Capitalize;
  77. import android.util.Log;
  78. import android.view.ContextThemeWrapper;
  79. import android.view.KeyEvent;
  80. import android.view.LayoutInflater;
  81. import android.view.Menu;
  82. import android.view.MenuItem;
  83. import android.view.View;
  84. import android.view.ViewGroup;
  85. import android.view.ViewParent;
  86. import android.widget.Button;
  87. import android.widget.CheckBox;
  88. import android.widget.EditText;
  89. import android.widget.ExpandableListView;
  90. import android.widget.ImageView;
  91. import android.widget.LinearLayout;
  92. import android.widget.SimpleExpandableListAdapter;
  93. import android.widget.TextView;
  94. import android.widget.Toast;
  95. import java.io.ByteArrayOutputStream;
  96. import java.util.ArrayList;
  97. import java.util.HashMap;
  98. import java.util.List;
  99. import java.util.Map;
  100. /**
  101. * Activity for editing or inserting a contact. Note that if the contact data changes in the
  102. * background while this activity is running, the updates will be overwritten.
  103. */
  104. public final class EditContactActivity {
  105. //extends Activity implements View.OnClickListener,
  106. // ExpandableListView.OnChildClickListener {
  107. // private static final String TAG = "EditContactActivity";
  108. //
  109. // private static final int STATE_UNKNOWN = 0;
  110. // /** Editing an existing contact */
  111. // private static final int STATE_EDIT = 1;
  112. // /** The full insert mode */
  113. // private static final int STATE_INSERT = 2;
  114. //
  115. // /** The launch code when picking a photo and the raw data is returned */
  116. // private static final int PHOTO_PICKED_WITH_DATA = 3021;
  117. //
  118. // /** The launch code when picking a ringtone */
  119. // private static final int RINGTONE_PICKED = 3023;
  120. //
  121. // // Label picker position info
  122. // final static int LABEL_PICKER_PHONES_POSITION = 0;
  123. // final static int LABEL_PICKER_EMAIL_POSITION = 1;
  124. // final static int LABEL_PICKER_IM_POSITION = 2;
  125. // final static int LABEL_PICKER_POSTAL_POSITION = 3;
  126. // final static int LABEL_PICKER_OTHER_POSITION = 4;
  127. //
  128. // // These correspond to the string array in resources for picker "other" items
  129. // final static int OTHER_ORGANIZATION = 0;
  130. // final static int OTHER_NOTE = 1;
  131. //
  132. // // Dialog IDs
  133. // final static int LABEL_PICKER_ALL_TYPES_DIALOG = 1;
  134. // final static int DELETE_CONFIRMATION_DIALOG = 2;
  135. //
  136. // // Menu item IDs
  137. // public static final int MENU_ITEM_SAVE = 1;
  138. // public static final int MENU_ITEM_DONT_SAVE = 2;
  139. // public static final int MENU_ITEM_DELETE = 3;
  140. // public static final int MENU_ITEM_ADD = 5;
  141. // public static final int MENU_ITEM_PHOTO = 6;
  142. //
  143. // // Key listener types
  144. // final static int INPUT_TEXT = 1;
  145. // final static int INPUT_TEXT_WORDS = 2;
  146. // final static int INPUT_TEXT_SENTENCES = 3;
  147. // final static int INPUT_DIALER = 4;
  148. //
  149. // /** Used to represent an invalid type for a contact entry */
  150. // private static final int INVALID_TYPE = -1;
  151. //
  152. // /** The default type for a phone that is added via an intent */
  153. // private static final int DEFAULT_PHONE_TYPE = Phones.TYPE_MOBILE;
  154. //
  155. // /** The default type for an email that is added via an intent */
  156. // private static final int DEFAULT_EMAIL_TYPE = ContactMethods.TYPE_HOME;
  157. //
  158. // /** The default type for a postal address that is added via an intent */
  159. // private static final int DEFAULT_POSTAL_TYPE = ContactMethods.TYPE_HOME;
  160. //
  161. // private int mState; // saved across instances
  162. // private boolean mInsert; // saved across instances
  163. // private Uri mUri; // saved across instances
  164. // /** In insert mode this is the photo */
  165. // private Bitmap mPhoto; // saved across instances
  166. // private boolean mPhotoChanged = false; // saved across instances
  167. //
  168. // private EditText mNameView;
  169. // private ImageView mPhotoImageView;
  170. // private Button mPhotoButton;
  171. // private CheckBox mSendToVoicemailCheckBox;
  172. // private LinearLayout mLayout;
  173. // private LayoutInflater mInflater;
  174. // private MenuItem mPhotoMenuItem;
  175. // private boolean mPhotoPresent = false;
  176. //
  177. // // These are accessed by inner classes. They're package scoped to make access more efficient.
  178. // /* package */ ContentResolver mResolver;
  179. // /* package */ ArrayList<EditEntry> mPhoneEntries = new ArrayList<EditEntry>();
  180. // /* package */ ArrayList<EditEntry> mEmailEntries = new ArrayList<EditEntry>();
  181. // /* package */ ArrayList<EditEntry> mImEntries = new ArrayList<EditEntry>();
  182. // /* package */ ArrayList<EditEntry> mPostalEntries = new ArrayList<EditEntry>();
  183. // /* package */ ArrayList<EditEntry> mOtherEntries = new ArrayList<EditEntry>();
  184. // /* package */ ArrayList<ArrayList<EditEntry>> mSections = new ArrayList<ArrayList<EditEntry>>();
  185. //
  186. // /* package */ static final int MSG_DELETE = 1;
  187. // /* package */ static final int MSG_CHANGE_LABEL = 2;
  188. // /* package */ static final int MSG_ADD_PHONE = 3;
  189. // /* package */ static final int MSG_ADD_EMAIL = 4;
  190. // /* package */ static final int MSG_ADD_POSTAL = 5;
  191. //
  192. // public void onClick(View v) {
  193. // switch (v.getId()) {
  194. // case R.id.photoButton:
  195. // case R.id.photoImage: {
  196. // doPickPhotoAction();
  197. // break;
  198. // }
  199. //
  200. // case R.id.addMore:
  201. // doAddAction();
  202. // break;
  203. //
  204. // case R.id.saveButton:
  205. // doSaveAction();
  206. // break;
  207. //
  208. // case R.id.discardButton:
  209. // doRevertAction();
  210. // break;
  211. //
  212. // case R.id.delete:
  213. // case R.id.delete2: {
  214. // EditEntry entry = findEntryForView(v);
  215. // if (entry != null) {
  216. // // Clear the text and hide the view so it gets saved properly
  217. // ((TextView) entry.view.findViewById(R.id.data)).setText(null);
  218. // entry.view.setVisibility(View.GONE);
  219. // entry.isDeleted = true;
  220. // }
  221. // break;
  222. // }
  223. //
  224. // case R.id.label: {
  225. // EditEntry entry = findEntryForView(v);
  226. // if (entry != null) {
  227. // String[] labels = getLabelsForKind(this, entry.kind);
  228. // LabelPickedListener listener = new LabelPickedListener(entry, labels);
  229. // new AlertDialog.Builder(EditContactActivity.this)
  230. // .setItems(labels, listener)
  231. // .setTitle(R.string.selectLabel)
  232. // .show();
  233. // }
  234. // break;
  235. // }
  236. //
  237. // case R.id.data: {
  238. // EditEntry entry = findEntryForView(v);
  239. // if (isRingtoneEntry(entry)) {
  240. // doPickRingtone(entry);
  241. // }
  242. // break;
  243. // }
  244. // }
  245. // }
  246. //
  247. // private void setPhotoPresent(boolean present) {
  248. // mPhotoImageView.setVisibility(present ? View.VISIBLE : View.GONE);
  249. // mPhotoButton.setVisibility(present ? View.GONE : View.VISIBLE);
  250. // mPhotoPresent = present;
  251. // if (mPhotoMenuItem != null) {
  252. // if (present) {
  253. // mPhotoMenuItem.setTitle(R.string.removePicture);
  254. // mPhotoMenuItem.setIcon(android.R.drawable.ic_menu_delete);
  255. // } else {
  256. // mPhotoMenuItem.setTitle(R.string.addPicture);
  257. // mPhotoMenuItem.setIcon(android.R.drawable.ic_menu_add);
  258. // }
  259. // }
  260. // }
  261. //
  262. // private EditEntry findEntryForView(View v) {
  263. // // Try to find the entry for this view
  264. // EditEntry entry = null;
  265. // do {
  266. // Object tag = v.getTag();
  267. // if (tag != null && tag instanceof EditEntry) {
  268. // entry = (EditEntry) tag;
  269. // break;
  270. // } else {
  271. // ViewParent parent = v.getParent();
  272. // if (parent != null && parent instanceof View) {
  273. // v = (View) parent;
  274. // } else {
  275. // v = null;
  276. // }
  277. // }
  278. // } while (v != null);
  279. // return entry;
  280. // }
  281. //
  282. // private DialogInterface.OnClickListener mDeleteContactDialogListener =
  283. // new DialogInterface.OnClickListener() {
  284. // public void onClick(DialogInterface dialog, int button) {
  285. // mResolver.delete(mUri, null, null);
  286. // finish();
  287. // }
  288. // };
  289. //
  290. // private boolean mMobilePhoneAdded = false;
  291. // private boolean mPrimaryEmailAdded = false;
  292. //
  293. // @Override
  294. // protected void onCreate(Bundle icicle) {
  295. // super.onCreate(icicle);
  296. //
  297. // mResolver = getContentResolver();
  298. //
  299. // // Build the list of sections
  300. // setupSections();
  301. //
  302. // // Load the UI
  303. // setContentView(R.layout.edit_contact);
  304. // mLayout = (LinearLayout) findViewById(R.id.list);
  305. // mNameView = (EditText) findViewById(R.id.name);
  306. // mPhotoImageView = (ImageView) findViewById(R.id.photoImage);
  307. // mPhotoImageView.setOnClickListener(this);
  308. // mPhotoImageView.setVisibility(View.GONE);
  309. // mPhotoButton = (Button) findViewById(R.id.photoButton);
  310. // mPhotoButton.setOnClickListener(this);
  311. // mSendToVoicemailCheckBox = (CheckBox) findViewById(R.id.send_to_voicemail);
  312. //
  313. // // Setup the bottom buttons
  314. // View view = findViewById(R.id.addMore);
  315. // view.setOnClickListener(this);
  316. // view = findViewById(R.id.saveButton);
  317. // view.setOnClickListener(this);
  318. // view = findViewById(R.id.discardButton);
  319. // view.setOnClickListener(this);
  320. //
  321. // mInflater = getLayoutInflater();
  322. //
  323. // // Resolve the intent
  324. // mState = STATE_UNKNOWN;
  325. // Intent intent = getIntent();
  326. // String action = intent.getAction();
  327. // mUri = intent.getData();
  328. // if (mUri != null) {
  329. // if (action.equals(Intent.ACTION_EDIT)) {
  330. // if (icicle == null) {
  331. // // Build the entries & views
  332. // buildEntriesForEdit(getIntent().getExtras());
  333. // buildViews();
  334. // }
  335. // mState = STATE_EDIT;
  336. // } else if (action.equals(Intent.ACTION_INSERT)) {
  337. // if (icicle == null) {
  338. // // Build the entries & views
  339. // buildEntriesForInsert(getIntent().getExtras());
  340. // buildViews();
  341. // }
  342. // mState = STATE_INSERT;
  343. // mInsert = true;
  344. // }
  345. // }
  346. //
  347. // if (mState == STATE_UNKNOWN) {
  348. // Log.e(TAG, "Cannot resolve intent: " + intent);
  349. // finish();
  350. // return;
  351. // }
  352. //
  353. // if (mState == STATE_EDIT) {
  354. // setTitle(getResources().getText(R.string.editContact_title_edit));
  355. // } else {
  356. // setTitle(getResources().getText(R.string.editContact_title_insert));
  357. // }
  358. // }
  359. //
  360. // private void setupSections() {
  361. // mSections.add(mPhoneEntries);
  362. // mSections.add(mEmailEntries);
  363. // mSections.add(mImEntries);
  364. // mSections.add(mPostalEntries);
  365. // mSections.add(mOtherEntries);
  366. // }
  367. //
  368. // @Override
  369. // protected void onSaveInstanceState(Bundle outState) {
  370. // outState.putParcelableArrayList("phoneEntries", mPhoneEntries);
  371. // outState.putParcelableArrayList("emailEntries", mEmailEntries);
  372. // outState.putParcelableArrayList("imEntries", mImEntries);
  373. // outState.putParcelableArrayList("postalEntries", mPostalEntries);
  374. // outState.putParcelableArrayList("otherEntries", mOtherEntries);
  375. // outState.putInt("state", mState);
  376. // outState.putBoolean("insert", mInsert);
  377. // outState.putParcelable("uri", mUri);
  378. // outState.putString("name", mNameView.getText().toString());
  379. // outState.putParcelable("photo", mPhoto);
  380. // outState.putBoolean("photoChanged", mPhotoChanged);
  381. // outState.putBoolean("sendToVoicemail", mSendToVoicemailCheckBox.isChecked());
  382. // }
  383. //
  384. // @Override
  385. // protected void onRestoreInstanceState(Bundle inState) {
  386. // mPhoneEntries = inState.getParcelableArrayList("phoneEntries");
  387. // mEmailEntries = inState.getParcelableArrayList("emailEntries");
  388. // mImEntries = inState.getParcelableArrayList("imEntries");
  389. // mPostalEntries = inState.getParcelableArrayList("postalEntries");
  390. // mOtherEntries = inState.getParcelableArrayList("otherEntries");
  391. // setupSections();
  392. //
  393. // mState = inState.getInt("state");
  394. // mInsert = inState.getBoolean("insert");
  395. // mUri = inState.getParcelable("uri");
  396. // mNameView.setText(inState.getString("name"));
  397. // mPhoto = inState.getParcelable("photo");
  398. // if (mPhoto != null) {
  399. // mPhotoImageView.setImageBitmap(mPhoto);
  400. // setPhotoPresent(true);
  401. // } else {
  402. // mPhotoImageView.setImageResource(R.drawable.ic_contact_picture);
  403. // setPhotoPresent(false);
  404. // }
  405. // mPhotoChanged = inState.getBoolean("photoChanged");
  406. // mSendToVoicemailCheckBox.setChecked(inState.getBoolean("sendToVoicemail"));
  407. //
  408. // // Now that everything is restored, build the view
  409. // buildViews();
  410. // }
  411. //
  412. // @Override
  413. // protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  414. // if (resultCode != RESULT_OK) {
  415. // return;
  416. // }
  417. //
  418. // switch (requestCode) {
  419. // case PHOTO_PICKED_WITH_DATA: {
  420. // final Bundle extras = data.getExtras();
  421. // if (extras != null) {
  422. // Bitmap photo = extras.getParcelable("data");
  423. // mPhoto = photo;
  424. // mPhotoChanged = true;
  425. // mPhotoImageView.setImageBitmap(photo);
  426. // setPhotoPresent(true);
  427. // }
  428. // break;
  429. // }
  430. //
  431. // case RINGTONE_PICKED: {
  432. // Uri pickedUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
  433. // handleRingtonePicked(pickedUri);
  434. // break;
  435. // }
  436. // }
  437. // }
  438. //
  439. // @Override
  440. // public boolean onKeyDown(int keyCode, KeyEvent event) {
  441. // switch (keyCode) {
  442. // case KeyEvent.KEYCODE_BACK: {
  443. // doSaveAction();
  444. // return true;
  445. // }
  446. // }
  447. // return super.onKeyDown(keyCode, event);
  448. // }
  449. //
  450. // @Override
  451. // public boolean onCreateOptionsMenu(Menu menu) {
  452. // super.onCreateOptionsMenu(menu);
  453. // menu.add(0, MENU_ITEM_SAVE, 0, R.string.menu_done)
  454. // .setIcon(android.R.drawable.ic_menu_save)
  455. // .setAlphabeticShortcut('\n');
  456. // menu.add(0, MENU_ITEM_DONT_SAVE, 0, R.string.menu_doNotSave)
  457. // .setIcon(android.R.drawable.ic_menu_close_clear_cancel)
  458. // .setAlphabeticShortcut('q');
  459. // if (!mInsert) {
  460. // menu.add(0, MENU_ITEM_DELETE, 0, R.string.menu_deleteContact)
  461. // .setIcon(android.R.drawable.ic_menu_delete);
  462. // }
  463. //
  464. // menu.add(0, MENU_ITEM_ADD, 0, R.string.menu_addItem)
  465. // .setIcon(android.R.drawable.ic_menu_add)
  466. // .setAlphabeticShortcut('n');
  467. //
  468. // mPhotoMenuItem = menu.add(0, MENU_ITEM_PHOTO, 0, null);
  469. // // Updates the state of the menu item
  470. // setPhotoPresent(mPhotoPresent);
  471. //
  472. // return true;
  473. // }
  474. //
  475. // @Override
  476. // public boolean onOptionsItemSelected(MenuItem item) {
  477. // switch (item.getItemId()) {
  478. // case MENU_ITEM_SAVE:
  479. // doSaveAction();
  480. // return true;
  481. //
  482. // case MENU_ITEM_DONT_SAVE:
  483. // doRevertAction();
  484. // return true;
  485. //
  486. // case MENU_ITEM_DELETE:
  487. // // Get confirmation
  488. // showDialog(DELETE_CONFIRMATION_DIALOG);
  489. // return true;
  490. //
  491. // case MENU_ITEM_ADD:
  492. // doAddAction();
  493. // return true;
  494. //
  495. // case MENU_ITEM_PHOTO:
  496. // if (!mPhotoPresent) {
  497. // doPickPhotoAction();
  498. // } else {
  499. // doRemovePhotoAction();
  500. // }
  501. // return true;
  502. // }
  503. //
  504. // return false;
  505. // }
  506. //
  507. // private void doAddAction() {
  508. // showDialog(LABEL_PICKER_ALL_TYPES_DIALOG);
  509. // }
  510. //
  511. // private void doRevertAction() {
  512. // finish();
  513. // }
  514. //
  515. // private void doPickPhotoAction() {
  516. // Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
  517. // // TODO: get these values from constants somewhere
  518. // intent.setType("image/*");
  519. // intent.putExtra("crop", "true");
  520. // intent.putExtra("aspectX", 1);
  521. // intent.putExtra("aspectY", 1);
  522. // intent.putExtra("outputX", 96);
  523. // intent.putExtra("outputY", 96);
  524. // try {
  525. // intent.putExtra("return-data", true);
  526. // startActivityForResult(intent, PHOTO_PICKED_WITH_DATA);
  527. // } catch (ActivityNotFoundException e) {
  528. // new AlertDialog.Builder(EditContactActivity.this)
  529. // .setTitle(R.string.errorDialogTitle)
  530. // .setMessage(R.string.photoPickerNotFoundText)
  531. // .setPositiveButton(R.string.okButtonText, null)
  532. // .show();
  533. // }
  534. // }
  535. //
  536. // private void doRemovePhotoAction() {
  537. // mPhoto = null;
  538. // mPhotoChanged = true;
  539. // mPhotoImageView.setImageResource(R.drawable.ic_contact_picture);
  540. // setPhotoPresent(false);
  541. // }
  542. //
  543. // private void doPickRingtone(EditEntry entry) {
  544. // Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
  545. // // Allow user to pick 'Default'
  546. // intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
  547. // // Show only ringtones
  548. // intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
  549. // // Don't show 'Silent'
  550. // intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
  551. // if (entry.data != null) {
  552. // Uri ringtoneUri = Uri.parse(entry.data);
  553. // // Put checkmark next to the current ringtone for this contact
  554. // intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneUri);
  555. // }
  556. // // Launch!
  557. // startActivityForResult(intent, RINGTONE_PICKED);
  558. // }
  559. //
  560. // private void handleRingtonePicked(Uri pickedUri) {
  561. // EditEntry entry = getRingtoneEntry();
  562. // if (entry == null) {
  563. // Log.w(TAG, "Ringtone picked but could not find ringtone entry");
  564. // return;
  565. // }
  566. //
  567. // if (pickedUri == null || RingtoneManager.isDefault(pickedUri)) {
  568. // entry.data = null;
  569. // } else {
  570. // entry.data = pickedUri.toString();
  571. // }
  572. //
  573. // updateRingtoneView(entry);
  574. // }
  575. //
  576. // private void updateRingtoneView(EditEntry entry) {
  577. // if (entry.data == null) {
  578. // updateDataView(entry, getString(R.string.default_ringtone));
  579. // } else {
  580. // Uri ringtoneUri = Uri.parse(entry.data);
  581. // Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
  582. // if (ringtone == null) {
  583. // Log.w(TAG, "ringtone's URI doesn't resolve to a Ringtone");
  584. // return;
  585. // }
  586. // updateDataView(entry, ringtone.getTitle(this));
  587. // }
  588. // }
  589. //
  590. // private void updateDataView(EditEntry entry, String text) {
  591. // TextView dataView = (TextView) entry.view.findViewById(R.id.data);
  592. // dataView.setText(text);
  593. // }
  594. //
  595. // @Override
  596. // protected Dialog onCreateDialog(int id) {
  597. // switch (id) {
  598. // case LABEL_PICKER_ALL_TYPES_DIALOG:
  599. // return createAllTypesPicker();
  600. //
  601. // case DELETE_CONFIRMATION_DIALOG:
  602. // return new AlertDialog.Builder(EditContactActivity.this)
  603. // .setTitle(R.string.deleteConfirmation_title)
  604. // .setIcon(android.R.drawable.ic_dialog_alert)
  605. // .setMessage(R.string.deleteConfirmation)
  606. // .setNegativeButton(R.string.noButton, null)
  607. // .setPositiveButton(R.string.yesButton, mDeleteContactDialogListener)
  608. // .setCancelable(false)
  609. // .create();
  610. // }
  611. // return super.onCreateDialog(id);
  612. // }
  613. static String[] getLabelsForKind(Context context, int kind) {
  614. final Resources resources = context.getResources();
  615. switch (kind) {
  616. case Contacts.KIND_PHONE:
  617. return resources.getStringArray(android.R.array.phoneTypes);
  618. case Contacts.KIND_EMAIL:
  619. return resources.getStringArray(android.R.array.emailAddressTypes);
  620. case Contacts.KIND_POSTAL:
  621. return resources.getStringArray(android.R.array.postalAddressTypes);
  622. case Contacts.KIND_IM:
  623. return resources.getStringArray(android.R.array.imProtocols);
  624. case Contacts.KIND_ORGANIZATION:
  625. return resources.getStringArray(android.R.array.organizationTypes);
  626. // case EditEntry.KIND_CONTACT:
  627. // return resources.getStringArray(R.array.otherLabels);
  628. }
  629. return null;
  630. }
  631. // int getTypeFromLabelPosition(CharSequence[] labels, int labelPosition) {
  632. // // In the UI Custom... comes last, but it is uses the constant 0
  633. // // so it is in the same location across the various kinds. Fix up the
  634. // // position to a valid type here.
  635. // if (labelPosition == labels.length - 1) {
  636. // return ContactMethods.TYPE_CUSTOM;
  637. // } else {
  638. // return labelPosition + 1;
  639. // }
  640. // }
  641. //
  642. // public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
  643. // int childPosition, long id) {
  644. // EditEntry entry = null;
  645. //
  646. // // Make the dialog go away
  647. // dismissDialog(LABEL_PICKER_ALL_TYPES_DIALOG);
  648. //
  649. // // Create the new entry
  650. // switch (groupPosition) {
  651. // case LABEL_PICKER_PHONES_POSITION: {
  652. // String[] labels = getLabelsForKind(this, Contacts.KIND_PHONE);
  653. // final int type = getTypeFromLabelPosition(labels, childPosition);
  654. // entry = EditEntry.newPhoneEntry(EditContactActivity.this,
  655. // labels[childPosition], type,
  656. // null, Uri.withAppendedPath(mUri, People.Phones.CONTENT_DIRECTORY), 0);
  657. // if (type == Phones.TYPE_CUSTOM) {
  658. // createCustomPicker(entry, mPhoneEntries);
  659. // return true;
  660. // } else {
  661. // mPhoneEntries.add(entry);
  662. // }
  663. // break;
  664. // }
  665. //
  666. // case LABEL_PICKER_EMAIL_POSITION: {
  667. // String[] labels = getLabelsForKind(this, Contacts.KIND_EMAIL);
  668. // final int type = getTypeFromLabelPosition(labels, childPosition);
  669. // entry = EditEntry.newEmailEntry(EditContactActivity.this,
  670. // labels[childPosition], type, null,
  671. // Uri.withAppendedPath(mUri, People.ContactMethods.CONTENT_DIRECTORY), 0);
  672. // if (type == ContactMethods.TYPE_CUSTOM) {
  673. // createCustomPicker(entry, mEmailEntries);
  674. // return true;
  675. // } else {
  676. // mEmailEntries.add(entry);
  677. // }
  678. // break;
  679. // }
  680. //
  681. // case LABEL_PICKER_IM_POSITION: {
  682. // String[] labels = getLabelsForKind(this, Contacts.KIND_IM);
  683. // entry = EditEntry.newImEntry(EditContactActivity.this,
  684. // labels[childPosition], childPosition, null,
  685. // Uri.withAppendedPath(mUri, People.ContactMethods.CONTENT_DIRECTORY), 0);
  686. // mImEntries.add(entry);
  687. // break;
  688. // }
  689. //
  690. // case LABEL_PICKER_POSTAL_POSITION: {
  691. // String[] labels = getLabelsForKind(this, Contacts.KIND_POSTAL);
  692. // final int type = getTypeFromLabelPosition(labels, childPosition);
  693. // entry = EditEntry.newPostalEntry(EditContactActivity.this,
  694. // labels[childPosition], type, null,
  695. // Uri.withAppendedPath(mUri, People.ContactMethods.CONTENT_DIRECTORY), 0);
  696. // if (type == ContactMethods.TYPE_CUSTOM) {
  697. // createCustomPicker(entry, mPostalEntries);
  698. // return true;
  699. // } else {
  700. // mPostalEntries.add(entry);
  701. // }
  702. // break;
  703. // }
  704. //
  705. // case LABEL_PICKER_OTHER_POSITION: {
  706. // switch (childPosition) {
  707. // case OTHER_ORGANIZATION:
  708. // entry = EditEntry.newOrganizationEntry(EditContactActivity.this,
  709. // Uri.withAppendedPath(mUri, Organizations.CONTENT_DIRECTORY),
  710. // ContactMethods.TYPE_WORK);
  711. // mOtherEntries.add(entry);
  712. // break;
  713. //
  714. // case OTHER_NOTE:
  715. // entry = EditEntry.newNotesEntry(EditContactActivity.this, null, mUri);
  716. // mOtherEntries.add(entry);
  717. // break;
  718. //
  719. // default:
  720. // entry = null;
  721. // }
  722. // break;
  723. // }
  724. //
  725. // default:
  726. // entry = null;
  727. // }
  728. //
  729. // // Rebuild the views if needed
  730. // if (entry != null) {
  731. // buildViews();
  732. //
  733. // View dataView = entry.view.findViewById(R.id.data);
  734. // if (dataView == null) {
  735. // entry.view.requestFocus();
  736. // } else {
  737. // dataView.requestFocus();
  738. // }
  739. // }
  740. // return true;
  741. // }
  742. //
  743. // private EditEntry getRingtoneEntry() {
  744. // for (int i = mOtherEntries.size() - 1; i >= 0; i--) {
  745. // EditEntry entry = mOtherEntries.get(i);
  746. // if (isRingtoneEntry(entry)) {
  747. // return entry;
  748. // }
  749. // }
  750. // return null;
  751. // }
  752. //
  753. // private static boolean isRingtoneEntry(EditEntry entry) {
  754. // return entry != null && entry.column != null && entry.column.equals(People.CUSTOM_RINGTONE);
  755. // }
  756. //
  757. // private Dialog createAllTypesPicker() {
  758. // // Setup the adapter
  759. // List<Map<String, ?>> groupData = Lists.newArrayList();
  760. // List<List<Map<String, ?>>> childData = Lists.newArrayList();
  761. // List<Map<String, ?>> children;
  762. // HashMap<String, CharSequence> curGroupMap;
  763. // CharSequence[] labels;
  764. // int labelsSize;
  765. //
  766. // // Phones
  767. // curGroupMap = new HashMap<String, CharSequence>();
  768. // groupData.add(curGroupMap);
  769. // curGroupMap.put("data", getText(R.string.phoneLabelsGroup));
  770. //
  771. // labels = getLabelsForKind(this, Contacts.KIND_PHONE);
  772. // labelsSize = labels.length;
  773. // children = Lists.newArrayList();
  774. // for (int i = 0; i < labelsSize; i++) {
  775. // HashMap<String, CharSequence> curChildMap = new HashMap<String, CharSequence>();
  776. // children.add(curChildMap);
  777. // curChildMap.put("data", labels[i]);
  778. // }
  779. // childData.add(LABEL_PICKER_PHONES_POSITION, children);
  780. //
  781. // // Email
  782. // curGroupMap = new HashMap<String, CharSequence>();
  783. // groupData.add(curGroupMap);
  784. // curGroupMap.put("data", getText(R.string.emailLabelsGroup));
  785. //
  786. // labels = getLabelsForKind(this, Contacts.KIND_EMAIL);
  787. // labelsSize = labels.length;
  788. // children = Lists.newArrayList();
  789. // for (int i = 0; i < labelsSize; i++) {
  790. // HashMap<String, CharSequence> curChildMap = new HashMap<String, CharSequence>();
  791. // children.add(curChildMap);
  792. // curChildMap.put("data", labels[i]);
  793. // }
  794. // childData.add(LABEL_PICKER_EMAIL_POSITION, children);
  795. //
  796. // // IM
  797. // curGroupMap = new HashMap<String, CharSequence>();
  798. // groupData.add(curGroupMap);
  799. // curGroupMap.put("data", getText(R.string.imLabelsGroup));
  800. //
  801. // labels = getLabelsForKind(this, Contacts.KIND_IM);
  802. // labelsSize = labels.length;
  803. // children = Lists.newArrayList();
  804. // for (int i = 0; i < labelsSize; i++) {
  805. // HashMap<String, CharSequence> curChildMap = new HashMap<String, CharSequence>();
  806. // children.add(curChildMap);
  807. // curChildMap.put("data", labels[i]);
  808. // }
  809. // childData.add(LABEL_PICKER_IM_POSITION, children);
  810. //
  811. // // Postal
  812. // curGroupMap = new HashMap<String, CharSequence>();
  813. // groupData.add(curGroupMap);
  814. // curGroupMap.put("data", getText(R.string.postalLabelsGroup));
  815. //
  816. // labels = getLabelsForKind(this, Contacts.KIND_POSTAL);
  817. // labelsSize = labels.length;
  818. // children = Lists.newArrayList();
  819. // for (int i = 0; i < labelsSize; i++) {
  820. // HashMap<String, CharSequence> curChildMap = new HashMap<String, CharSequence>();
  821. // children.add(curChildMap);
  822. // curChildMap.put("data", labels[i]);
  823. // }
  824. // childData.add(LABEL_PICKER_POSTAL_POSITION, children);
  825. //
  826. // // Other
  827. // curGroupMap = new HashMap<String, CharSequence>();
  828. // groupData.add(curGroupMap);
  829. // curGroupMap.put("data", getText(R.string.otherLabelsGroup));
  830. //
  831. // labels = getLabelsForKind(this, EditEntry.KIND_CONTACT);
  832. // labelsSize = labels.length;
  833. // children = Lists.newArrayList();
  834. // for (int i = 0; i < labelsSize; i++) {
  835. // HashMap<String, CharSequence> curChildMap = new HashMap<String, CharSequence>();
  836. // children.add(curChildMap);
  837. // curChildMap.put("data", labels[i]);
  838. // }
  839. // childData.add(LABEL_PICKER_OTHER_POSITION, children);
  840. //
  841. // // Create the expandable list view
  842. // ExpandableListView list = new ExpandableListView(new ContextThemeWrapper(this,
  843. // android.R.style.Theme_Light));
  844. // list.setOnChildClickListener(this);
  845. // list.setAdapter(new SimpleExpandableListAdapter(
  846. // new ContextThemeWrapper(this, android.R.style.Theme_Light),
  847. // groupData,
  848. // android.R.layout.simple_expandable_list_item_1,
  849. // new String[] { "data" },
  850. // new int[] { android.R.id.text1 },
  851. // childData,
  852. // android.R.layout.simple_expandable_list_item_1,
  853. // new String[] { "data" },
  854. // new int[] { android.R.id.text1 }
  855. // ));
  856. // // This list shouldn't have a color hint since the dialog may be transparent
  857. // list.setCacheColorHint(0);
  858. //
  859. // // Create the dialog
  860. // return new AlertDialog.Builder(this).setView(list).setInverseBackgroundForced(true)
  861. // .setTitle(R.string.selectLabel).create();
  862. // }
  863. //
  864. // private void createCustomPicker(final EditEntry entry, final ArrayList<EditEntry> addTo) {
  865. // final EditText label = new EditText(this);
  866. // label.setKeyListener(TextKeyListener.getInstance(false, Capitalize.WORDS));
  867. // label.requestFocus();
  868. // new AlertDialog.Builder(this)
  869. // .setView(label)
  870. // .setTitle(R.string.customLabelPickerTitle)
  871. // .setPositiveButton(R.string.okButtonText, new DialogInterface.OnClickListener() {
  872. // public void onClick(DialogInterface dialog, int which) {
  873. // entry.setLabel(EditContactActivity.this, ContactMethods.TYPE_CUSTOM,
  874. // label.getText().toString());
  875. // if (addTo != null) {
  876. // addTo.add(entry);
  877. // buildViews();
  878. // entry.view.requestFocus(View.FOCUS_DOWN);
  879. // }
  880. // }
  881. // })
  882. // .setNegativeButton(R.string.cancelButtonText, null)
  883. // .show();
  884. // }
  885. //
  886. // /**
  887. // * Saves or creates the contact based on the mode, and if sucessful finishes the activity.
  888. // */
  889. // private void doSaveAction() {
  890. // // Save or create the contact if needed
  891. // switch (mState) {
  892. // case STATE_EDIT:
  893. // save();
  894. // break;
  895. //
  896. // case STATE_INSERT:
  897. // create();
  898. // break;
  899. //
  900. // default:
  901. // Log.e(TAG, "Unknown state in doSaveOrCreate: " + mState);
  902. // break;
  903. // }
  904. // finish();
  905. // }
  906. //
  907. // /**
  908. // * Save the various fields to the existing contact.
  909. // */
  910. // private void save() {
  911. // ContentValues values = new ContentValues();
  912. // String data;
  913. // int numValues = 0;
  914. //
  915. // // Handle the name and send to voicemail specially
  916. // final String name = mNameView.getText().toString();
  917. // if (name != null && TextUtils.isGraphic(name)) {
  918. // numValues++;
  919. // }
  920. // values.put(People.NAME, name);
  921. // values.put(People.SEND_TO_VOICEMAIL, mSendToVoicemailCheckBox.isChecked() ? 1 : 0);
  922. // mResolver.update(mUri, values, null, null);
  923. //
  924. // if (mPhotoChanged) {
  925. // // Only write the photo if it's changed, since we don't initially load mPhoto
  926. // if (mPhoto != null) {
  927. // ByteArrayOutputStream stream = new ByteArrayOutputStream();
  928. // mPhoto.compress(Bitmap.CompressFormat.JPEG, 75, stream);
  929. // Contacts.People.setPhotoData(mResolver, mUri, stream.toByteArray());
  930. // } else {
  931. // Contacts.People.setPhotoData(mResolver, mUri, null);
  932. // }
  933. // }
  934. //
  935. // int entryCount = ContactEntryAdapter.countEntries(mSections, false);
  936. // for (int i = 0; i < entryCount; i++) {
  937. // EditEntry entry = ContactEntryAdapter.getEntry(mSections, i, false);
  938. // int kind = entry.kind;
  939. // data = entry.getData();
  940. // boolean empty = data == null || !TextUtils.isGraphic(data);
  941. // if (kind == EditEntry.KIND_CONTACT) {
  942. // values.clear();
  943. // if (!empty) {
  944. // values.put(entry.column, data);
  945. // mResolver.update(entry.uri, values, null, null);
  946. // numValues++;
  947. // } else {
  948. // values.put(entry.column, (String) null);
  949. // mResolver.update(entry.uri, values, null, null);
  950. // }
  951. // } else {
  952. // if (!empty) {
  953. // values.clear();
  954. // entry.toValues(values);
  955. // if (entry.id != 0) {
  956. // mResolver.update(entry.uri, values, null, null);
  957. // } else {
  958. // mResolver.insert(entry.uri, values);
  959. // }
  960. // numValues++;
  961. // } else if (entry.id != 0) {
  962. // mResolver.delete(entry.uri, null, null);
  963. // }
  964. // }
  965. // }
  966. //
  967. // if (numValues == 0) {
  968. // // The contact is completely empty, delete it
  969. // mResolver.delete(mUri, null, null);
  970. // mUri = null;
  971. // setResult(RESULT_CANCELED);
  972. // } else {
  973. // // Add the entry to the my contacts group if it isn't there already
  974. // People.addToMyContactsGroup(mResolver, ContentUris.parseId(mUri));
  975. // setResult(RESULT_OK, new Intent().setData(mUri));
  976. // Toast.makeText(this, R.string.contactSavedToast, Toast.LENGTH_SHORT).show();
  977. // }
  978. // }
  979. //
  980. // /**
  981. // * Takes the entered data and saves it to a new contact.
  982. // */
  983. // private void create() {
  984. // ContentValues values = new ContentValues();
  985. // String data;
  986. // int numValues = 0;
  987. //
  988. // // Create the contact itself
  989. // final String name = mNameView.getText().toString();
  990. // if (name != null && TextUtils.isGraphic(name)) {
  991. // numValues++;
  992. // }
  993. // values.put(People.NAME, name);
  994. // values.put(People.SEND_TO_VOICEMAIL, mSendToVoicemailCheckBox.isChecked() ? 1 : 0);
  995. //
  996. // // Add the contact to the My Contacts group
  997. // Uri contactUri = People.createPersonInMyContactsGroup(mResolver, values);
  998. //
  999. // // Add the contact to the group that is being displayed in the contact list
  1000. // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  1001. // int displayType = prefs.getInt(ContactsPreferenceActivity.PREF_DISPLAY_TYPE,
  1002. // ContactsPreferenceActivity.DISPLAY_TYPE_UNKNOWN);
  1003. // if (displayType == ContactsPreferenceActivity.DISPLAY_TYPE_USER_GROUP) {
  1004. // String displayGroup = prefs.getString(ContactsPreferenceActivity.PREF_DISPLAY_INFO,
  1005. // null);
  1006. // if (!TextUtils.isEmpty(displayGroup)) {
  1007. // People.addToGroup(mResolver, ContentUris.parseId(contactUri), displayGroup);
  1008. // }
  1009. // }
  1010. //
  1011. // // Handle the photo
  1012. // if (mPhoto != null) {
  1013. // ByteArrayOutputStream stream = new ByteArrayOutputStream();
  1014. // mPhoto.compress(Bitmap.CompressFormat.JPEG, 75, stream);
  1015. // Contacts.People.setPhotoData(getContentResolver(), contactUri, stream.toByteArray());
  1016. // }
  1017. //
  1018. // // Create the contact methods
  1019. // int entryCount = ContactEntryAdapter.countEntries(mSections, false);
  1020. // for (int i = 0; i < entryCount; i++) {
  1021. // EditEntry entry = ContactEntryAdapter.getEntry(mSections, i, false);
  1022. // if (entry.kind != EditEntry.KIND_CONTACT) {
  1023. // values.clear();
  1024. // if (entry.toValues(values)) {
  1025. // // Only create the entry if there is data
  1026. // entry.uri = mResolver.insert(
  1027. // Uri.withAppendedPath(contactUri, entry.contentDirectory), values);
  1028. // entry.id = ContentUris.parseId(entry.uri);
  1029. // numValues++;
  1030. // }
  1031. // } else {
  1032. // // Update the contact with any straggling data, like notes
  1033. // data = entry.getData();
  1034. // values.clear();
  1035. // if (data != null && TextUtils.isGraphic(data)) {
  1036. // values.put(entry.column, data);
  1037. // mResolver.update(contactUri, values, null, null);
  1038. // numValues++;
  1039. // }
  1040. // }
  1041. // }
  1042. //
  1043. // if (numValues == 0) {
  1044. // mResolver.delete(contactUri, null, null);
  1045. // setResult(RESULT_CANCELED);
  1046. // } else {
  1047. // mUri = contactUri;
  1048. // Intent resultIntent = new Intent()
  1049. // .setData(mUri)
  1050. // .putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
  1051. // setResult(RESULT_OK, resultIntent);
  1052. // Toast.makeText(this, R.string.contactCreatedToast, Toast.LENGTH_SHORT).show();
  1053. // }
  1054. // }
  1055. //
  1056. // /**
  1057. // * Build up the entries to display on the screen.
  1058. // *
  1059. // * @param extras the extras used to start this activity, may be null
  1060. // */
  1061. // private void buildEntriesForEdit(Bundle extras) {
  1062. // Cursor personCursor = mResolver.query(mUri, CONTACT_PROJECTION, null, null, null);
  1063. // if (personCursor == null) {
  1064. // Log.e(TAG, "invalid contact uri: " + mUri);
  1065. // finish();
  1066. // return;
  1067. // } else if (!personCursor.moveToFirst()) {
  1068. // Log.e(TAG, "invalid contact uri: " + mUri);
  1069. // finish();
  1070. // personCursor.close();
  1071. // return;
  1072. // }
  1073. //
  1074. // // Clear out the old entries
  1075. // int numSections = mSections.size();
  1076. // for (int i = 0; i < numSections; i++) {
  1077. // mSections.get(i).clear();
  1078. // }
  1079. //
  1080. // EditEntry entry;
  1081. //
  1082. // // Name
  1083. // mNameView.setText(personCursor.getString(CONTACT_NAME_COLUMN));
  1084. //
  1085. // // Photo
  1086. // mPhoto = People.loadContactPhoto(this, mUri, 0, null);
  1087. // if (mPhoto == null) {
  1088. // setPhotoPresent(false);
  1089. // } else {
  1090. // setPhotoPresent(true);
  1091. // mPhotoImageView.setImageBitmap(mPhoto);
  1092. // }
  1093. //
  1094. // // Send to voicemail
  1095. // mSendToVoicemailCheckBox
  1096. // .setChecked(personCursor.getInt(CONTACT_SEND_TO_VOICEMAIL_COLUMN) == 1);
  1097. //
  1098. // // Organizations
  1099. // Uri organizationsUri = Uri.withAppendedPath(mUri, Organizations.CONTENT_DIRECTORY);
  1100. // Cursor organizationsCursor = mResolver.query(organizationsUri, ORGANIZATIONS_PROJECTION,
  1101. // null, null, null);
  1102. //
  1103. // if (organizationsCursor != null) {
  1104. // while (organizationsCursor.moveToNext()) {
  1105. // int type = organizationsCursor.getInt(ORGANIZATIONS_TYPE_COLUMN);
  1106. // String label = organizationsCursor.getString(ORGANIZATIONS_LABEL_COLUMN);
  1107. // String company = organizationsCursor.getString(ORGANIZATIONS_COMPANY_COLUMN);
  1108. // String title = organizationsCursor.getString(ORGANIZATIONS_TITLE_COLUMN);
  1109. // long id = organizationsCursor.getLong(ORGANIZATIONS_ID_COLUMN);
  1110. // Uri uri = ContentUris.withAppendedId(Organizations.CONTENT_URI, id);
  1111. //
  1112. // // Add an organization entry
  1113. // entry = EditEntry.newOrganizationEntry(this, label, type, company, title, uri, id);
  1114. // entry.isPrimary = organizationsCursor.getLong(ORGANIZATIONS_ISPRIMARY_COLUMN) != 0;
  1115. // mOtherEntries.add(entry);
  1116. // }
  1117. // organizationsCursor.close();
  1118. // }
  1119. //
  1120. // // Notes
  1121. // if (!personCursor.isNull(CONTACT_NOTES_COLUMN)) {
  1122. // entry = EditEntry.newNotesEntry(this, personCursor.getString(CONTACT_NOTES_COLUMN),
  1123. // mUri);
  1124. // mOtherEntries.add(entry);
  1125. // }
  1126. //
  1127. // // Ringtone
  1128. // entry = EditEntry.newRingtoneEntry(this,
  1129. // personCursor.getString(CONTACT_CUSTOM_RINGTONE_COLUMN), mUri);
  1130. // mOtherEntries.add(entry);
  1131. // personCursor.close();
  1132. //
  1133. // // Build up the phone entries
  1134. // Uri phonesUri = Uri.withAppendedPath(mUri, People.Phones.CONTENT_DIRECTORY);
  1135. // Cursor phonesCursor = mResolver.query(phonesUri, PHONES_PROJECTION,
  1136. // null, null, null);
  1137. //
  1138. // if (phonesCursor != null) {
  1139. // while (phonesCursor.moveToNext()) {
  1140. // int type = phonesCursor.getInt(PHONES_TYPE_COLUMN);
  1141. // String label = phonesCursor.getString(PHONES_LABEL_COLUMN);
  1142. // String number = phonesCursor.getString(PHONES_NUMBER_COLUMN);
  1143. // long id = phonesCursor.getLong(PHONES_ID_COLUMN);
  1144. // boolean isPrimary = phonesCursor.getLong(PHONES_ISPRIMARY_COLUMN) != 0;
  1145. // Uri uri = ContentUris.withAppendedId(phonesUri, id);
  1146. //
  1147. // // Add a phone number entry
  1148. // entry = EditEntry.newPhoneEntry(this, label, type, number, uri, id);
  1149. // entry.isPrimary = isPrimary;
  1150. // mPhoneEntries.add(entry);
  1151. //
  1152. // // Keep track of which primary types have been added
  1153. // if (type == Phones.TYPE_MOBILE) {
  1154. // mMobilePhoneAdded = true;
  1155. // }
  1156. // }
  1157. //
  1158. // phonesCursor.close();
  1159. // }
  1160. //
  1161. // // Build the contact method entries
  1162. // Uri methodsUri = Uri.withAppendedPath(mUri, People.ContactMethods.CONTENT_DIRECTORY);
  1163. // Cursor methodsCursor = mResolver.query(methodsUri, METHODS_PROJECTION, null, null, null);
  1164. //
  1165. // if (methodsCursor != null) {
  1166. // while (methodsCursor.moveToNext()) {
  1167. // int kind = methodsCursor.getInt(METHODS_KIND_COLUMN);
  1168. // String label = methodsCursor.getString(METHODS_LABEL_COLUMN);
  1169. // String data = methodsCursor.getString(METHODS_DATA_COLUMN);
  1170. // String auxData = methodsCursor.getString(METHODS_AUX_DATA_COLUMN);
  1171. // int type = methodsCursor.getInt(METHODS_TYPE_COLUMN);
  1172. // long id = methodsCursor.getLong(METHODS_ID_COLUMN);
  1173. // boolean isPrimary = methodsCursor.getLong(METHODS_ISPRIMARY_COLUMN) != 0;
  1174. // Uri uri = ContentUris.withAppendedId(methodsUri, id);
  1175. //
  1176. // switch (kind) {
  1177. // case Contacts.KIND_EMAIL: {
  1178. // entry = EditEntry.newEmailEntry(this, label, type, data, uri, id);
  1179. // entry.isPrimary = isPrimary;
  1180. // mEmailEntries.add(entry);
  1181. //
  1182. // if (isPrimary) {
  1183. // mPrimaryEmailAdded = true;
  1184. // }
  1185. // break;
  1186. // }
  1187. //
  1188. // case Contacts.KIND_POSTAL: {
  1189. // entry = EditEntry.newPostalEntry(this, label, type, data, uri, id);
  1190. // entry.isPrimary = isPrimary;
  1191. // mPostalEntries.add(entry);
  1192. // break;
  1193. // }
  1194. //
  1195. // case Contacts.KIND_IM: {
  1196. // Object protocolObj = ContactMethods.decodeImProtocol(auxData);
  1197. // if (protocolObj == null) {
  1198. // // Invalid IM protocol, log it then ignore.
  1199. // Log.e(TAG, "Couldn't decode IM protocol: " + auxData);
  1200. // continue;
  1201. // } else {
  1202. // if (protocolObj instanceof Number) {
  1203. // int protocol = ((Number) protocolObj).intValue();
  1204. // entry = EditEntry.newImEntry(this,
  1205. // getLabelsForKind(this, Contacts.KIND_IM)[protocol], protocol,
  1206. // data, uri, id);
  1207. // } else {
  1208. // entry = EditEntry.newImEntry(this, protocolObj.toString(), -1, data,
  1209. // uri, id);
  1210. // }
  1211. // mImEntries.add(entry);
  1212. // }
  1213. // break;
  1214. // }
  1215. // }
  1216. // }
  1217. //
  1218. // methodsCursor.close();
  1219. // }
  1220. //
  1221. // // Add values from the extras, if there are any
  1222. // if (extras != null) {
  1223. // addFromExtras(extras, phonesUri, methodsUri);
  1224. // }
  1225. //
  1226. // // Add the base types if needed
  1227. // if (!mMobilePhoneAdded) {
  1228. // entry = EditEntry.newPhoneEntry(this,
  1229. // Uri.withAppendedPath(mUri, People.Phones.CONTENT_DIRECTORY),
  1230. // DEFAULT_PHONE_TYPE);
  1231. // mPhoneEntries.add(entry);
  1232. // }
  1233. //
  1234. // if (!mPrimaryEmailAdded) {
  1235. // entry = EditEntry.newEmailEntry(this,
  1236. // Uri.withAppendedPath(mUri, People.ContactMethods.CONTENT_DIRECTORY),
  1237. // DEFAULT_EMAIL_TYPE);
  1238. // entry.isPrimary = true;
  1239. // mEmailEntries.add(entry);
  1240. // }
  1241. // }
  1242. //
  1243. // /**
  1244. // * Build the list of EditEntries for full mode insertions.
  1245. // *
  1246. // * @param extras the extras used to start this activity, may be null
  1247. // */
  1248. // private void buildEntriesForInsert(Bundle extras) {
  1249. // // Clear out the old entries
  1250. // int numSections = mSections.size();
  1251. // for (int i = 0; i < numSections; i++) {
  1252. // mSections.get(i).clear();
  1253. // }
  1254. //
  1255. // EditEntry entry;
  1256. //
  1257. // // Check the intent extras
  1258. // if (extras != null) {
  1259. // addFromExtras(extras, null, null);
  1260. // }
  1261. //
  1262. // // Photo
  1263. // mPhotoImageView.setImageResource(R.drawable.ic_contact_picture);
  1264. //
  1265. // // Add the base entries if they're not already present
  1266. // if (!mMobilePhoneAdded) {
  1267. // entry = EditEntry.newPhoneEntry(this, null, Phones.TYPE_MOBILE);
  1268. // entry.isPrimary = true;
  1269. // mPhoneEntries.add(entry);
  1270. // }
  1271. //
  1272. // if (!mPrimaryEmailAdded) {
  1273. // entry = EditEntry.newEmailEntry(this, null, DEFAULT_EMAIL_TYPE);
  1274. // entry.isPrimary = true;
  1275. // mEmailEntries.add(entry);
  1276. // }
  1277. //
  1278. // // Ringtone
  1279. // entry = EditEntry.newRingtoneEntry(this, null, mUri);
  1280. // mOtherEntries.add(entry);
  1281. //
  1282. // }
  1283. //
  1284. // private void addFromExtras(Bundle extras, Uri phonesUri, Uri methodsUri) {
  1285. // EditEntry entry;
  1286. //
  1287. // // Read the name from the bundle
  1288. // CharSequence name = extras.getCharSequence(Insert.NAME);
  1289. // if (name != null && TextUtils.isGraphic(name)) {
  1290. // mNameView.setText(name);
  1291. // }
  1292. //
  1293. // // Postal entries from extras
  1294. // CharSequence postal = extras.getCharSequence(Insert.POSTAL);
  1295. // int postalType = extras.getInt(Insert.POSTAL_TYPE, INVALID_TYPE);
  1296. // if (!TextUtils.isEmpty(postal) && postalType == INVALID_TYPE) {
  1297. // postalType = DEFAULT_POSTAL_TYPE;
  1298. // }
  1299. //
  1300. // if (postalType != INVALID_TYPE) {
  1301. // entry = EditEntry.newPostalEntry(this, null, postalType, postal.toString(),
  1302. // methodsUri, 0);
  1303. // entry.isPrimary = extras.getBoolean(Insert.POSTAL_ISPRIMARY);
  1304. // mPostalEntries.add(entry);
  1305. // }
  1306. //
  1307. // // Email entries from extras
  1308. // CharSequence email = extras.getCharSequence(Insert.EMAIL);
  1309. // int emailType = extras.getInt(Insert.EMAIL_TYPE, INVALID_TYPE);
  1310. // if (!TextUtils.isEmpty(email) && emailType == INVALID_TYPE) {
  1311. // emailType = DEFAULT_EMAIL_TYPE;
  1312. // mPrimaryEmailAdded = true;
  1313. // }
  1314. //
  1315. // if (emailType != INVALID_TYPE) {
  1316. // entry = EditEntry.newEmailEntry(this, null, emailType, email.toString(), methodsUri, 0);
  1317. // entry.isPrimary = extras.getBoolean(Insert.EMAIL_ISPRIMARY);
  1318. // mEmailEntries.add(entry);
  1319. //
  1320. // // Keep track of which primary types have been added
  1321. // if (entry.isPrimary) {
  1322. // mPrimaryEmailAdded = true;
  1323. // }
  1324. // }
  1325. //
  1326. // // Phone entries from extras
  1327. // CharSequence phoneNumber = extras.getCharSequence(Insert.PHONE);
  1328. // int phoneType = extras.getInt(Insert.PHONE_TYPE, INVALID_TYPE);
  1329. // if (!TextUtils.isEmpty(phoneNumber) && phoneType == INVALID_TYPE) {
  1330. // phoneType = DEFAULT_PHONE_TYPE;
  1331. // }
  1332. //
  1333. // if (phoneType != INVALID_TYPE) {
  1334. // entry = EditEntry.newPhoneEntry(this, null, phoneType,
  1335. // phoneNumber.toString(), phonesUri, 0);
  1336. // entry.isPrimary = extras.getBoolean(Insert.PHONE_ISPRIMARY);
  1337. // mPhoneEntries.add(entry);
  1338. //
  1339. // // Keep track of which primary types have been added
  1340. // if (phoneType == Phones.TYPE_MOBILE) {
  1341. // mMobilePhoneAdded = true;
  1342. // }
  1343. // }
  1344. //
  1345. // // IM entries from extras
  1346. // CharSequence imHandle = extras.getCharSequence(Insert.IM_HANDLE);
  1347. // CharSequence imProtocol = extras.getCharSequence(Insert.IM_PROTOCOL);
  1348. //
  1349. // if (imHandle != null && imProtocol != null) {
  1350. // Object protocolObj = ContactMethods.decodeImProtocol(imProtocol.toString());
  1351. // if (protocolObj instanceof Number) {
  1352. // int protocol = ((Number) protocolObj).intValue();
  1353. // entry = EditEntry.newImEntry(this,
  1354. // getLabelsForKind(this, Contacts.KIND_IM)[protocol], protocol,
  1355. // imHandle.toString(), null, 0);
  1356. // } else {
  1357. // entry = EditEntry.newImEntry(this, protocolObj.toString(), -1, imHandle.toString(),
  1358. // null, 0);
  1359. // }
  1360. // entry.isPrimary = extras.getBoolean(Insert.IM_ISPRIMARY);
  1361. // mImEntries.add(entry);
  1362. // }
  1363. // }
  1364. //
  1365. // /**
  1366. // * Removes all existing views, builds new ones for all the entries, and adds them.
  1367. // */
  1368. // private void buildViews() {
  1369. // // Remove existing views
  1370. // final LinearLayout layout = mLayout;
  1371. // layout.removeAllViews();
  1372. //
  1373. // buildViewsForSection(layout, mPhoneEntries, R.string.listSeparatorCallNumber);
  1374. // buildViewsForSection(layout, mEmailEntries, R.string.listSeparatorSendEmail);
  1375. // buildViewsForSection(layout, mImEntries, R.string.listSeparatorSendIm);
  1376. // buildViewsForSection(layout, mPostalEntries, R.string.listSeparatorMapAddress);
  1377. // buildViewsForSection(layout, mOtherEntries, R.string.listSeparatorOtherInformation);
  1378. // }
  1379. //
  1380. //
  1381. // /**
  1382. // * Builds the views for a specific section.
  1383. // *
  1384. // * @param layout the container
  1385. // * @param section the section to build the views for
  1386. // */
  1387. // private void buildViewsForSection(final LinearLayout layout, ArrayList<EditEntry> section,
  1388. // int separatorResource) {
  1389. // // Build the separator if the section isn't empty
  1390. // if (section.size() > 0) {
  1391. // View separator = mInflater.inflate(R.layout.edit_separator, layout, false);
  1392. // TextView text = (TextView) separator.findViewById(R.id.text);
  1393. // text.setText(getText(separatorResource));
  1394. // layout.addView(separator);
  1395. // }
  1396. //
  1397. // // Build views for the current section
  1398. // for (EditEntry entry : section) {
  1399. // entry.activity = this; // this could be null from when the state is restored
  1400. // if (!entry.isDeleted) {
  1401. // View view = buildViewForEntry(entry);
  1402. // layout.addView(view);
  1403. // }
  1404. // }
  1405. // }
  1406. //
  1407. // /**
  1408. // * Builds a view to display an EditEntry.
  1409. // *
  1410. // * @param entry the entry to display
  1411. // * @return a view that will display the given entry
  1412. // */
  1413. // /* package */ View buildViewForEntry(final EditEntry entry) {
  1414. // // Look for any existing entered text, and save it if found
  1415. // if (entry.view != null && entry.syncDataWithView) {
  1416. // String enteredText = ((TextView) entry.view.findViewById(R.id.data))
  1417. // .getText().toString();
  1418. // if (!TextUtils.isEmpty(enteredText)) {
  1419. // entry.data = enteredText;
  1420. // }
  1421. // }
  1422. //
  1423. // // Build a new view
  1424. // final ViewGroup parent = mLayout;
  1425. // View view;
  1426. //
  1427. // if (entry.kind == Contacts.KIND_ORGANIZATION) {
  1428. // view = mInflater.inflate(R.layout.edit_contact_entry_org, parent, false);
  1429. // } else if (isRingtoneEntry(entry)) {
  1430. // view = mInflater.inflate(R.layout.edit_contact_entry_ringtone, parent, false);
  1431. // } else if (!entry.isStaticLabel) {
  1432. // view = mInflater.inflate(R.layout.edit_contact_entry, parent, false);
  1433. // } else {
  1434. // view = mInflater.inflate(R.layout.edit_contact_entry_static_label, parent, false);
  1435. // }
  1436. // entry.view = view;
  1437. //
  1438. // // Set the entry as the tag so we can find it again later given just the view
  1439. // view.setTag(entry);
  1440. //
  1441. // // Bind the label
  1442. // entry.bindLabel(this);
  1443. //
  1444. // // Bind data
  1445. // TextView data = (TextView) view.findViewById(R.id.data);
  1446. // TextView data2 = (TextView) view.findViewById(R.id.data2);
  1447. //
  1448. // if (data instanceof Button) {
  1449. // data.setOnClickListener(this);
  1450. // }
  1451. // if (data.length() == 0) {
  1452. // if (entry.syncDataWithView) {
  1453. // // If there is already data entered don't overwrite it
  1454. // data.setText(entry.data);
  1455. // } else {
  1456. // fillViewData(entry);
  1457. // }
  1458. // }
  1459. // if (data2 != null && data2.length() == 0) {
  1460. // // If there is already data entered don't overwrite it
  1461. // data2.setText(entry.data2);
  1462. // }
  1463. // data.setHint(entry.hint);
  1464. // if (data2 != null) data2.setHint(entry.hint2);
  1465. // if (entry.lines > 1) {
  1466. // data.setLines(entry.lines);
  1467. // data.setMaxLines(entry.maxLines);
  1468. // if (data2 != null) {
  1469. // data2.setLines(entry.lines);
  1470. // data2.setMaxLines(entry.maxLines);
  1471. // }
  1472. // } else if (entry.lines >= 0) {
  1473. // data.setSingleLine();
  1474. // if (data2 != null) {
  1475. // data2.setSingleLine();
  1476. // }
  1477. // }
  1478. // switch (entry.keyListener) {
  1479. // case INPUT_TEXT:
  1480. // data.setKeyListener(TextKeyListener.getInstance());
  1481. // if (data2 != null) {
  1482. // data2.setKeyListener(TextKeyListener.getInstance());
  1483. // }
  1484. // break;
  1485. //
  1486. // case INPUT_TEXT_WORDS:
  1487. // data.setKeyListener(TextKeyListener.getInstance(true, Capitalize.WORDS));
  1488. // if (data2 != null) {
  1489. // data2.setKeyListener(TextKeyListener.getInstance(true, Capitalize.WORDS));
  1490. // }
  1491. // break;
  1492. //
  1493. // case INPUT_TEXT_SENTENCES:
  1494. // data.setKeyListener(TextKeyListener.getInstance(true, Capitalize.SENTENCES));
  1495. // if (data2 != null) {
  1496. // data2.setKeyListener(TextKeyListener.getInstance(true, Capitalize.SENTENCES));
  1497. // }
  1498. // break;
  1499. //
  1500. // case INPUT_DIALER:
  1501. // data.setKeyListener(DialerKeyListener.getInstance());
  1502. // data.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
  1503. // if (data2 != null) {
  1504. // data2.setKeyListener(DialerKeyListener.getInstance());
  1505. // data2.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
  1506. // }
  1507. // break;
  1508. // }
  1509. //
  1510. // // Hook up the delete button
  1511. // View delete = view.findViewById(R.id.delete);
  1512. // if (delete != null) delete.setOnClickListener(this);
  1513. // View delete2 = view.findViewById(R.id.delete2);
  1514. // if (delete2 != null) delete2.setOnClickListener(this);
  1515. //
  1516. // return view;
  1517. // }
  1518. //
  1519. // private void fillViewData(final EditEntry entry) {
  1520. // if (isRingtoneEntry(entry)) {
  1521. // updateRingtoneView(entry);
  1522. // }
  1523. // }
  1524. //
  1525. // /**
  1526. // * Handles the results from the label change picker.
  1527. // */
  1528. // private final class LabelPickedListener implements DialogInterface.OnClickListener {
  1529. // EditEntry mEntry;
  1530. // String[] mLabels;
  1531. //
  1532. // public LabelPickedListener(EditEntry entry, String[] labels) {
  1533. // mEntry = entry;
  1534. // mLabels = labels;
  1535. // }
  1536. //
  1537. // public void onClick(DialogInterface dialog, int which) {
  1538. // // TODO: Use a managed dialog
  1539. // if (mEntry.kind != Contacts.KIND_IM) {
  1540. // final int type = getTypeFromLabelPosition(mLabels, which);
  1541. // if (type == ContactMethods.TYPE_CUSTOM) {
  1542. // createCustomPicker(mEntry, null);
  1543. // } else {
  1544. // mEntry.setLabel(EditContactActivity.this, type, mLabels[which]);
  1545. // }
  1546. // } else {
  1547. // mEntry.setLabel(EditContactActivity.this, which, mLabels[which]);
  1548. // }
  1549. // }
  1550. // }
  1551. //
  1552. // /**
  1553. // * A basic structure with the data for a contact entry in the list.
  1554. // */
  1555. // private static final class EditEntry extends ContactEntryAdapter.Entry implements Parcelable {
  1556. // // These aren't stuffed into the parcel
  1557. // public EditContactActivity activity;
  1558. // public View view;
  1559. //
  1560. // // These are stuffed into the parcel
  1561. // public String hint;
  1562. // public String hint2;
  1563. // public String column;
  1564. // public String contentDirectory;
  1565. // public String data2;
  1566. // public int keyListener;
  1567. // public int type;
  1568. // /**
  1569. // * If 0 or 1, setSingleLine will be called. If negative, setSingleLine
  1570. // * will not be called.
  1571. // */
  1572. // public int lines = 1;
  1573. // public boolean isPrimary;
  1574. // public boolean isDeleted = false;
  1575. // public boolean isStaticLabel = false;
  1576. // public