use of android.content.ContentProviderResult in project packages_apps_Contacts by AOKP.
the class ContactSaveService method createRawContact.
private void createRawContact(Intent intent) {
String accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME);
String accountType = intent.getStringExtra(EXTRA_ACCOUNT_TYPE);
String dataSet = intent.getStringExtra(EXTRA_DATA_SET);
List<ContentValues> valueList = intent.getParcelableArrayListExtra(EXTRA_CONTENT_VALUES);
Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT);
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
operations.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI).withValue(RawContacts.ACCOUNT_NAME, accountName).withValue(RawContacts.ACCOUNT_TYPE, accountType).withValue(RawContacts.DATA_SET, dataSet).build());
int size = valueList.size();
for (int i = 0; i < size; i++) {
ContentValues values = valueList.get(i);
values.keySet().retainAll(ALLOWED_DATA_COLUMNS);
operations.add(ContentProviderOperation.newInsert(Data.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID, 0).withValues(values).build());
}
ContentResolver resolver = getContentResolver();
ContentProviderResult[] results;
try {
results = resolver.applyBatch(ContactsContract.AUTHORITY, operations);
} catch (Exception e) {
throw new RuntimeException("Failed to store new contact", e);
}
Uri rawContactUri = results[0].uri;
callbackIntent.setData(RawContacts.getContactLookupUri(resolver, rawContactUri));
deliverCallback(callbackIntent);
}
use of android.content.ContentProviderResult in project robolectric by robolectric.
the class ShadowContentProviderResultTest method uri.
@Test
public void uri() {
Uri uri = Uri.parse("content://org.robolectric");
ContentProviderResult result = new ContentProviderResult(uri);
assertThat(result.uri).isEqualTo(uri);
}
use of android.content.ContentProviderResult in project robolectric by robolectric.
the class ShadowContentResolverTest method applyBatchForUnregisteredProvider.
@Test
public void applyBatchForUnregisteredProvider() throws RemoteException, OperationApplicationException {
List<ContentProviderOperation> resultOperations = shadowContentResolver.getContentProviderOperations(AUTHORITY);
assertThat(resultOperations).isNotNull();
assertThat(resultOperations.size()).isEqualTo(0);
ContentProviderResult[] contentProviderResults = new ContentProviderResult[] { new ContentProviderResult(1), new ContentProviderResult(1) };
shadowContentResolver.setContentProviderResult(contentProviderResults);
Uri uri = Uri.parse("content://org.robolectric");
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
operations.add(ContentProviderOperation.newInsert(uri).withValue("column1", "foo").withValue("column2", 5).build());
operations.add(ContentProviderOperation.newUpdate(uri).withSelection("id_column", new String[] { "99" }).withValue("column1", "bar").build());
operations.add(ContentProviderOperation.newDelete(uri).withSelection("id_column", new String[] { "11" }).build());
ContentProviderResult[] result = contentResolver.applyBatch(AUTHORITY, operations);
resultOperations = shadowContentResolver.getContentProviderOperations(AUTHORITY);
assertThat(resultOperations).isEqualTo(operations);
assertThat(result).isEqualTo(contentProviderResults);
}
use of android.content.ContentProviderResult in project Etar-Calendar by Etar-Group.
the class AsyncQueryService method handleMessage.
@Override
public void handleMessage(Message msg) {
OperationInfo info = (OperationInfo) msg.obj;
int token = msg.what;
int op = msg.arg1;
if (localLOGV) {
Log.d(TAG, "AsyncQueryService.handleMessage: token=" + token + ", op=" + op + ", result=" + info.result);
}
// pass token back to caller on each callback.
switch(op) {
case Operation.EVENT_ARG_QUERY:
onQueryComplete(token, info.cookie, (Cursor) info.result);
break;
case Operation.EVENT_ARG_INSERT:
onInsertComplete(token, info.cookie, (Uri) info.result);
break;
case Operation.EVENT_ARG_UPDATE:
onUpdateComplete(token, info.cookie, (Integer) info.result);
break;
case Operation.EVENT_ARG_DELETE:
onDeleteComplete(token, info.cookie, (Integer) info.result);
break;
case Operation.EVENT_ARG_BATCH:
onBatchComplete(token, info.cookie, (ContentProviderResult[]) info.result);
break;
}
}
use of android.content.ContentProviderResult in project mechanoid by robotoworks.
the class MechanoidContentProvider method applyBatch.
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
final SQLiteDatabase db = getOpenHelper().getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
Aggregations