Exemplo n.º 1
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != Activity.RESULT_OK) {
      return;
    }

    Uri contactData;

    switch (requestCode) {
      case PICK_CONTACT:
        contactData = data.getData();
        updateContactWithSelection(contactData);

        break;

      case REQUEST_CROP_PHOTO:
        if (mUriOfSelected == null) {
          break;
        }

        ContentResolver resolver = getContentResolver();
        Cursor cursor =
            resolver.query(
                mUriOfSelected,
                new String[] {Results.CONTACT_ID, Results.PIC_URL, Results.LOOKUP_KEY},
                null,
                null,
                null);

        ResultsListAdapter adapter = (ResultsListAdapter) mListview.getAdapter();

        if (cursor.moveToFirst()) {
          String id = cursor.getString(cursor.getColumnIndex(Results.CONTACT_ID));
          String url = cursor.getString(cursor.getColumnIndex(Results.PIC_URL));
          String lookup = cursor.getString(cursor.getColumnIndex(Results.LOOKUP_KEY));

          Bitmap bitmap = (Bitmap) data.getParcelableExtra("data");
          if (bitmap != null) {
            byte[] bytes = Utils.bitmapToPNG(bitmap);

            mContactUtils.updatePhoto(getContentResolver(), bytes, id, true);
            mDbHelper.updateHashes(id, lookup, null, bytes);

            mCache.add(url, bitmap);
            adapter.notifyDataSetChanged();
          }
        }

        cursor.close();
        break;
    }
  }
Exemplo n.º 2
0
  private void unlink(String id, boolean purge) {
    if (id == null) {
      return;
    }

    final ContentResolver resolver = getContentResolver();
    ContentValues values = new ContentValues();
    values.put(Results.DESCRIPTION, getString(R.string.resultsdescription_notfound));
    values.putNull(Results.CONTACT_ID);
    resolver.update(Results.CONTENT_URI, values, Results.CONTACT_ID + "=" + id, null);

    if (purge) {
      mDbHelper.deletePicture(id);
      resolver.delete(Uri.withAppendedPath(SyncMyPix.Contacts.CONTENT_URI, id), null, null);
    }
  }