Search in sources :

Example 16 with ContentProviderResult

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);
}
Also used : ContentValues(android.content.ContentValues) ContentProviderResult(android.content.ContentProviderResult) ContentProviderOperation(android.content.ContentProviderOperation) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Uri(android.net.Uri) RemoteException(android.os.RemoteException) OperationApplicationException(android.content.OperationApplicationException) ContentResolver(android.content.ContentResolver)

Example 17 with ContentProviderResult

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);
}
Also used : ContentProviderResult(android.content.ContentProviderResult) Uri(android.net.Uri) Test(org.junit.Test)

Example 18 with ContentProviderResult

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);
}
Also used : ContentProviderResult(android.content.ContentProviderResult) ContentProviderOperation(android.content.ContentProviderOperation) ArrayList(java.util.ArrayList) Uri(android.net.Uri) Test(org.junit.Test)

Example 19 with ContentProviderResult

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;
    }
}
Also used : OperationInfo(com.android.calendar.AsyncQueryServiceHelper.OperationInfo) ContentProviderResult(android.content.ContentProviderResult)

Example 20 with ContentProviderResult

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();
    }
}
Also used : ContentProviderResult(android.content.ContentProviderResult) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

ContentProviderResult (android.content.ContentProviderResult)39 ContentProviderOperation (android.content.ContentProviderOperation)30 OperationApplicationException (android.content.OperationApplicationException)22 ArrayList (java.util.ArrayList)20 RemoteException (android.os.RemoteException)17 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)12 ContentValues (android.content.ContentValues)9 Uri (android.net.Uri)9 ContentResolver (android.content.ContentResolver)6 Intent (android.content.Intent)6 NonNull (android.support.annotation.NonNull)6 BroadcastReceiver (android.content.BroadcastReceiver)4 Context (android.content.Context)4 IntentFilter (android.content.IntentFilter)4 PackageMonitor (com.android.internal.content.PackageMonitor)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 Test (org.junit.Test)3 ContentProvider (android.content.ContentProvider)2 OperationInfo (com.android.calendar.AsyncQueryServiceHelper.OperationInfo)2 OrgProperties (com.orgzly.org.OrgProperties)2