@Override public void bindContactPhoneView(View view, Context context, Cursor cursor) { // Get values String value = cursor.getString(cursor.getColumnIndex(Phones.NUMBER)); String displayName = cursor.getString(cursor.getColumnIndex(Phones.DISPLAY_NAME)); Long peopleId = cursor.getLong(cursor.getColumnIndex(Phones.PERSON_ID)); Uri uri = ContentUris.withAppendedId(People.CONTENT_URI, peopleId); Bitmap bitmap = getContactPhoto(context, uri, false, R.drawable.ic_contact_picture_holo_dark); // Get views TextView tv = (TextView) view.findViewById(R.id.name); TextView sub = (TextView) view.findViewById(R.id.number); TextView label = (TextView) view.findViewById(R.id.label); ImageView imageView = (ImageView) view.findViewById(R.id.contact_photo); // Bind label.setVisibility(View.GONE); view.setTag(value); tv.setText(displayName); sub.setText(value); imageView.setImageBitmap(bitmap); }
public void create(Contact newPhoneContact) throws Exception { // first, we have to create the contact ContentValues newPhoneValues = new ContentValues(); newPhoneValues.put(Contacts.People.NAME, newPhoneContact.getName()); Uri newPhoneRow = resolver.insert(Contacts.People.CONTENT_URI, newPhoneValues); // then we have to add a number newPhoneValues.clear(); newPhoneValues.put(Contacts.People.Phones.TYPE, Contacts.People.Phones.TYPE_MOBILE); newPhoneValues.put(Contacts.Phones.NUMBER, newPhoneContact.getNumber()); // insert the new phone number in the database using the returned uri from creating the contact newPhoneRow = resolver.insert(Uri.withAppendedPath(newPhoneRow, Contacts.People.Phones.CONTENT_DIRECTORY), newPhoneValues); // if contacts uri returned, there was an error with adding the number if (newPhoneRow.getPath().contains("people")) { throw new Exception(String.valueOf(R.string.error_phone_number_not_stored)); } // if phone uri returned, everything went OK if (!newPhoneRow.getPath().contains("phones")) { // some unknown error has happened throw new Exception(String.valueOf(R.string.error_phone_number_error)); } }
public Uri retrieveContactUri(Contact contact) { String id = contact.getId(); String[] projection = new String[] { Contacts.Phones.PERSON_ID }; String path = null; Cursor result; if (null != id) { Uri uri = ContentUris.withAppendedId(Contacts.Phones.CONTENT_URI, Long.valueOf(id)); result = resolver.query(uri, projection, null, null, null); } else { String selection = "name='?' AND number='?'"; String[] selectionArgs = new String[] { contact.getName(), contact.getNumber() }; result = resolver.query(Contacts.Phones.CONTENT_URI, projection, selection, selectionArgs, null); } if (null != result) { result.moveToNext(); path = result.getString(0); result.close(); } if (null == path) { return null; } return Uri.withAppendedPath(Contacts.People.CONTENT_URI, path); }
private void assignRingtoneToContact() { Cursor c = mAdapter.getCursor(); int dataIndex = c.getColumnIndexOrThrow(People._ID); String contactId = c.getString(dataIndex); dataIndex = c.getColumnIndexOrThrow(People.DISPLAY_NAME); String displayName = c.getString(dataIndex); Uri uri = Uri.withAppendedPath(getContactContentUri(), contactId); ContentValues values = new ContentValues(); values.put(People.CUSTOM_RINGTONE, mRingtoneUri.toString()); getContentResolver().update(uri, values, null, null); String message = getResources().getText(R.string.success_contact_ringtone) + " " + displayName; Log.i("Contact Uri", uri.toString()); Log.i("Ringtone Uri", mRingtoneUri.toString()); Toast.makeText(this, message, Toast.LENGTH_SHORT) .show(); finish(); return; }
public Loader<Cursor> onCreateLoader(int id, Bundle args) { // This is called when a new Loader needs to be created. This // sample only has one Loader, so we don't care about the ID. // First, pick the base URI to use depending on whether we are // currently filtering. Uri baseUri; if (mCurFilter != null) { baseUri = Uri.withAppendedPath(People.CONTENT_FILTER_URI, Uri.encode(mCurFilter)); } else { baseUri = People.CONTENT_URI; } // Now create and return a CursorLoader that will take care of // creating a Cursor for the data being displayed. String select = "((" + People.DISPLAY_NAME + " NOTNULL) AND (" + People.DISPLAY_NAME + " != '' ))"; return new CursorLoader(getActivity(), baseUri, CONTACTS_SUMMARY_PROJECTION, select, null, People.DISPLAY_NAME + " COLLATE LOCALIZED ASC"); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText("No phone numbers"); // We have a menu item to show in action bar. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_1, null, new String[] { People.DISPLAY_NAME }, new int[] { android.R.id.text1}, 0); setListAdapter(mAdapter); // Start out with a progress indicator. setListShown(false); // Prepare the loader. Either re-connect with an existing one, // or start a new one. getLoaderManager().initLoader(0, null, this); }
private void returnPickerResult(String name, Uri uri) { final Intent intent = new Intent(); if (mCreateShortcut) { Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, uri); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); final Bitmap icon = People.loadContactPhoto(this, uri, 0, null); if (icon != null) { intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); } else { intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, // R.drawable.ic_launcher_shortcut_contact)); R.drawable.picture_holder)); } setResult(RESULT_OK, intent); } else { setResult(RESULT_OK, intent.setData(uri)); } finish(); }
boolean isExcludedType(Vector<Integer> vExTypesCode, String sNumber, Context oContext) { Uri contactRef = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, sNumber); final String[] PHONES_PROJECTION = new String[] { People.Phones.NUMBER, // 0 People.Phones.TYPE, // 1 }; Cursor phonesCursor = oContext.getContentResolver().query(contactRef, PHONES_PROJECTION, null, null, null); if (phonesCursor != null) { while (phonesCursor.moveToNext()) { final int type = phonesCursor.getInt(1); if(vExTypesCode.contains(Integer.valueOf(type))) return true; } phonesCursor.close(); } return false; }