微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android.content.ContentProviderOperation的实例源码

项目:iosched-reader    文件SpeakersHandler.java   
private void buildSpeaker(boolean isInsert,Speaker speaker,ArrayList<ContentProviderOperation> list) {
    Uri allSpeakersUri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Speakers.CONTENT_URI);
    Uri thisspeakerUri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Speakers.buildSpeakerUri(speaker.id));

    ContentProviderOperation.Builder builder;
    if (isInsert) {
        builder = ContentProviderOperation.newInsert(allSpeakersUri);
    } else {
        builder = ContentProviderOperation.newUpdate(thisspeakerUri);
    }

    list.add(builder.withValue(ScheduleContract.SyncColumns.UPDATED,System.currentTimeMillis())
            .withValue(ScheduleContract.Speakers.SPEAKER_ID,speaker.id)
            .withValue(ScheduleContract.Speakers.SPEAKER_NAME,speaker.name)
            .withValue(ScheduleContract.Speakers.SPEAKER_ABSTRACT,speaker.bio)
            .withValue(ScheduleContract.Speakers.SPEAKER_COMPANY,speaker.company)
            .withValue(ScheduleContract.Speakers.SPEAKER_IMAGE_URL,speaker.thumbnailUrl)
            .withValue(ScheduleContract.Speakers.SPEAKER_PLUSONE_URL,speaker.plusoneUrl)
            .withValue(ScheduleContract.Speakers.SPEAKER_TWITTER_URL,speaker.twitterUrl)
            .withValue(ScheduleContract.Speakers.SPEAKER_IMPORT_HASHCODE,speaker.getImportHashcode())
            .build());
}
项目:ContentPal    文件RowSnapshotReferenceTest.java   
@Test
public void testAssertOperationBuilder() throws Exception
{
    ContentProviderOperation.Builder dummyResultBuilder = dummy(ContentProviderOperation.Builder.class);
    SoftRowReference<Object> dummyOriginalReference = dummy(SoftRowReference.class);
    RowReference<Object> mockResolvedReference = failingMock(RowReference.class);
    RowSnapshot<Object> mockSnapshot = failingMock(RowSnapshot.class);
    TransactionContext mockTransactionContext = failingMock(TransactionContext.class);
    doReturn(dummyOriginalReference).when(mockSnapshot).reference();
    doReturn(mockResolvedReference).when(mockTransactionContext).resolved(dummyOriginalReference);

    doReturn(dummyResultBuilder).when(mockResolvedReference).assertOperationBuilder(mockTransactionContext);

    assertthat(new RowSnapshotReference<>(mockSnapshot).assertOperationBuilder(mockTransactionContext),sameInstance(dummyResultBuilder));

}
项目:Linphone4Android    文件LinphoneContact.java   
public void setPhoto(byte[] photo) {
    if (photo != null) {
        if (isAndroidContact()) {
            if (androidRawId != null) {
                changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                    .withValue(ContactsContract.Data.RAW_CONTACT_ID,androidRawId)
                    .withValue(ContactsContract.Data.MIMETYPE,CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
                    .withValue(CommonDataKinds.Photo.PHOTO,photo)
                    .withValue(ContactsContract.Data.IS_PRIMARY,1)
                    .withValue(ContactsContract.Data.IS_SUPER_PRIMARY,1)
                    .build());
            } else {
                changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                    .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,0)
                    .withValue(ContactsContract.Data.MIMETYPE,photo)
                    .build());
            }
        }
    }
}
项目:ContentPal    文件BulkAssertTest.java   
@Test
public void testContentOperationBuilder_ctor_table_data()
{
    Table<Object> mockTable = failingMock(Table.class);
    Operation<Object> mockAssertOperation = failingMock(Operation.class);

    doReturn(mockAssertOperation).when(mockTable).assertOperation(same(EmptyUriParams.INSTANCE),predicateWithSelection("1"));

    doReturn(ContentProviderOperation.newAssertQuery(Uri.EMPTY)).when(mockAssertOperation).contentOperationBuilder(any(TransactionContext.class));

    assertthat(new BulkAssert<>(mockTable,new CharSequenceRowData<>("key","value")),builds(
                    assertOperation(),withoutExpectedCount(),withYieldNotAllowed(),withValuesOnly(
                            containing("key","value"))));
}
项目:ContentPal    文件BulkAssertTest.java   
@Test
public void testContentOperationBuilder_ctor_table()
{
    Table<Object> mockTable = failingMock(Table.class);
    Operation<Object> mockAssertOperation = failingMock(Operation.class);

    doReturn(mockAssertOperation).when(mockTable).assertOperation(same(EmptyUriParams.INSTANCE),predicateWithSelection("1"));

    doReturn(ContentProviderOperation.newAssertQuery(Uri.EMPTY)).when(mockAssertOperation).contentOperationBuilder(any(TransactionContext.class));

    assertthat(new BulkAssert<>(mockTable),withoutValues()));
}
项目:iosched-reader    文件BlocksHandler.java   
private static void outputBlock(Block block,ArrayList<ContentProviderOperation> list) {
    Uri uri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Blocks.CONTENT_URI);
    ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri);
    String title = block.title != null ? block.title : "";
    String Meta = block.subtitle != null ? block.subtitle : "";

    String type = block.type;
    if ( ! ScheduleContract.Blocks.isValidBlockType(type)) {
        LOGW(TAG,"block from "+block.start+" to "+block.end+" has unrecognized type ("
                +type+"). Using "+ ScheduleContract.Blocks.BLOCK_TYPE_BREAK +" instead.");
        type = ScheduleContract.Blocks.BLOCK_TYPE_BREAK;
    }

    long startTimeL = ParserUtils.parseTime(block.start);
    long endTimeL = ParserUtils.parseTime(block.end);
    final String blockId = ScheduleContract.Blocks.generateBlockId(startTimeL,endTimeL);
    builder.withValue(ScheduleContract.Blocks.BLOCK_ID,blockId);
    builder.withValue(ScheduleContract.Blocks.BLOCK_TITLE,title);
    builder.withValue(ScheduleContract.Blocks.BLOCK_START,startTimeL);
    builder.withValue(ScheduleContract.Blocks.BLOCK_END,endTimeL);
    builder.withValue(ScheduleContract.Blocks.BLOCK_TYPE,type);
    builder.withValue(ScheduleContract.Blocks.BLOCK_SUBTITLE,Meta);
    list.add(builder.build());
}
项目:LaunchEnr    文件ImportDataTask.java   
@Override
public long insertAndCheck(sqliteDatabase db,ContentValues values) {
    if (mExistingItems.size() >= mrequiredSize) {
        // No need to add more items.
        return 0;
    }
    Intent intent;
    try {
        intent = Intent.parseUri(values.getAsstring(Favorites.INTENT),0);
    } catch (URISyntaxException e) {
        return 0;
    }
    String pkg = getPackage(intent);
    if (pkg == null || mExisitingApps.contains(pkg)) {
        // The item does not target an app or is already in hotseat.
        return 0;
    }
    mExisitingApps.add(pkg);

    // find next vacant spot.
    long screen = 0;
    while (mExistingItems.get(screen) != null) {
        screen++;
    }
    mExistingItems.put(screen,intent);
    values.put(Favorites.SCREEN,screen);
    mOutops.add(ContentProviderOperation.newInsert(Favorites.CONTENT_URI).withValues(values).build());
    return 0;
}
项目:xyz-reader-2    文件ItemsProvider.java   
/**
 * Apply the given set of {@link ContentProviderOperation},executing inside
 * a {@link sqliteDatabase} transaction. All changes will be rolled back if
 * any single one fails.
 */
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
    final sqliteDatabase db = mOpenHelper.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();
    }
}
项目:mobile-store    文件RepoPersister.java   
private void flushApksToDbInBatch(Map<String,Long> appIds) throws RepoUpdater.UpdateException {
    List<Apk> apksToSaveList = new ArrayList<>();
    for (Map.Entry<String,List<Apk>> entries : apksToSave.entrySet()) {
        for (Apk apk : entries.getValue()) {
            apk.appId = appIds.get(apk.packageName);
        }
        apksToSaveList.addAll(entries.getValue());
    }

    calcApkCompatibilityFlags(apksToSaveList);

    ArrayList<ContentProviderOperation> apkOperations = insertApks(apksToSaveList);

    try {
        context.getContentResolver().applyBatch(TempApkProvider.getAuthority(),apkOperations);
    } catch (remoteexception | OperationApplicationException e) {
        throw new RepoUpdater.UpdateException(repo,"An internal error occurred while updating the database",e);
    }
}
项目:ContentPal    文件DeleteTest.java   
@Test
public void testContentOperationBuilder() throws Exception
{
    RowSnapshot<Object> mockRowSnapshot = failingMock(RowSnapshot.class);
    SoftRowReference<Object> rowReference = failingMock(SoftRowReference.class);
    doReturn(rowReference).when(mockRowSnapshot).reference();
    doReturn(ContentProviderOperation.newDelete(Uri.EMPTY)).when(rowReference).deleteOperationBuilder(any(TransactionContext.class));

    assertthat(
            new Delete<>(mockRowSnapshot),builds(
                    deleteOperation(),withoutValues()));
}
项目:aos-MediaLib    文件MusicProvider.java   
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
    if (DBG) Log.d(TAG,"applyBatch");
    ContentProviderResult[] result = null;
    sqliteDatabase db = mDbHolder.get();
    db.beginTransaction();
    try {
         result = super.applyBatch(operations);
         db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    if (result != null) {
        mCr.notifyChange(MusicStore.ALL_CONTENT_URI,null);
    }
    return result;
}
项目:Phoenix-for-VK    文件Dialogsstore.java   
@Override
public Completable insertDialogs(int accountId,List<DialogEntity> dbos,boolean clearBefore) {
    return Completable.create(emitter -> {
        final long start = System.currentTimeMillis();
        final Uri uri = MessengerContentProvider.getDialogsContentUriFor(accountId);
        final ArrayList<ContentProviderOperation> operations = new ArrayList<>();

        if(clearBefore){
            operations.add(ContentProviderOperation.newDelete(uri).build());
        }

        for(DialogEntity dbo : dbos){
            ContentValues cv = createCv(dbo);
            operations.add(ContentProviderOperation.newInsert(uri).withValues(cv).build());

            Messagesstore.appendDboOperation(accountId,dbo.getMessage(),operations,null,null);
        }

        getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY,operations);
        emitter.onComplete();

        Exestime.log("Dialogsstore.insertDialogs",start,"count: " + dbos.size() + ",clearBefore: " + clearBefore);
    });
}
项目:ContentPal    文件PutTest.java   
@Test
public void testContentOperationBuilderWithData() throws Exception
{
    RowSnapshot<Object> mockRowSnapshot = failingMock(RowSnapshot.class);
    SoftRowReference<Object> mockRowReference = failingMock(SoftRowReference.class);

    doReturn(mockRowReference).when(mockRowSnapshot).reference();
    doReturn(ContentProviderOperation.newUpdate(Uri.EMPTY)).when(mockRowReference).putoperationBuilder(any(TransactionContext.class));

    assertthat(new Put<>(mockRowSnapshot,new CharSequenceRowData<>("x","y")),builds(
                    updateOperation(),withValuesOnly(
                            containing("x","y"))));
}
项目:Phoenix-for-VK    文件DatabaseStore.java   
@Override
public Completable storeCountries(int accountId,List<CountryEntity> dbos) {
    return Completable.create(emitter -> {
        Uri uri = MessengerContentProvider.getCountriesContentUriFor(accountId);

        ArrayList<ContentProviderOperation> operations = new ArrayList<>(dbos.size() + 1);
        operations.add(ContentProviderOperation.newUpdate(uri).build());

        for (CountryEntity dbo : dbos) {
            ContentValues cv = new ContentValues();
            cv.put(CountriesColumns._ID,dbo.getId());
            cv.put(CountriesColumns.NAME,dbo.getTitle());

            operations.add(ContentProviderOperation.newInsert(uri)
                    .withValues(cv)
                    .build());
        }

        getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY,operations);
        emitter.onComplete();
    });
}
项目:ContentPal    文件AggregationException.java   
@NonNull
@Override
public ContentProviderOperation.Builder contentOperationBuilder(@NonNull TransactionContext transactionContext) throws UnsupportedOperationException
{
    // updating Aggregation exceptions works a bit strange. Instead of selecting a specific entry,we have to refer to them in the values.
    return mRawContact2.builderWithReferenceData(
            transactionContext,mRawContact1.builderWithReferenceData(
                    transactionContext,AggregationExceptions.INSTANCE.updateOperation(
                            EmptyUriParams.INSTANCE,new AnyOf()
                    ).contentOperationBuilder(transactionContext),ContactsContract.AggregationExceptions.RAW_CONTACT_ID1),ContactsContract.AggregationExceptions.RAW_CONTACT_ID2);

}
项目:ContentPal    文件SingleEventData.java   
@NonNull
@Override
public ContentProviderOperation.Builder updatedBuilder(TransactionContext transactionContext,@NonNull ContentProviderOperation.Builder builder)
{
    return builder.withValue(CalendarContract.Events.DTSTART,mStart.getTimestamp())
            .withValue(CalendarContract.Events.EVENT_TIMEZONE,mStart.isAllDay() ? "UTC" : mStart.getTimeZone().getID())
            .withValue(CalendarContract.Events.ALL_DAY,mStart.isAllDay() ? 1 : 0)
            .withValue(CalendarContract.Events.DTEND,mEnd.getTimestamp())
            .withValue(CalendarContract.Events.EVENT_END_TIMEZONE,mEnd.isAllDay() ? "UTC" : mEnd.getTimeZone().getID())
            .withValue(CalendarContract.Events.TITLE,mTitle.toString())
            // explicitly (re-)set all recurring event values to null
            .withValue(CalendarContract.Events.RRULE,null)
            .withValue(CalendarContract.Events.RDATE,null)
            .withValue(CalendarContract.Events.EXDATE,null)
            .withValue(CalendarContract.Events.DURATION,null);
}
项目:Phoenix-for-VK    文件RelativeshipStore.java   
private Completable completableStoreForType(int accountId,List<UserEntity> userEntities,int objectId,int relationType,boolean clear) {
    return Completable.create(emitter -> {
        Uri uri = MessengerContentProvider.getRelativeshipContentUriFor(accountId);

        ArrayList<ContentProviderOperation> operations = new ArrayList<>();

        if (clear) {
            operations.add(clearOperationFor(accountId,objectId,relationType));
        }

        appendInsertHeaders(uri,userEntities,relationType);
        OwnersRepositiry.appendUsersInsertOperation(operations,accountId,userEntities);

        getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY,operations);
        emitter.onComplete();
    });
}
项目:iosched-reader    文件SessionsHandler.java   
private void buildSessionSpeakerMapping(Session session,ArrayList<ContentProviderOperation> list) {
    final Uri uri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Sessions.buildSpeakersDirUri(session.id));

    // delete any existing relationship between this session and speakers
    list.add(ContentProviderOperation.newDelete(uri).build());

    // add relationship records to indicate the speakers for this session
    if (session.speakers != null) {
        for (String speakerId : session.speakers) {
            list.add(ContentProviderOperation.newInsert(uri)
                    .withValue(ScheduleDatabase.Sessionsspeakers.SESSION_ID,session.id)
                    .withValue(ScheduleDatabase.Sessionsspeakers.SPEAKER_ID,speakerId)
                    .build());
        }
    }
}
项目:ContentPal    文件RecurringEventData.java   
@NonNull
@Override
public ContentProviderOperation.Builder updatedBuilder(TransactionContext transactionContext,mStart.isAllDay() ? 1 : 0)
            .withValue(CalendarContract.Events.DURATION,mDuration.toString())
            .withValue(CalendarContract.Events.TITLE,mTitle.toString())
            .withValue(CalendarContract.Events.RRULE,TextUtils.join("\n",mRules))
            .withValue(CalendarContract.Events.RDATE,TextUtils.join(",",new Mapped<>(mRDates,mUtcDate)))
            .withValue(CalendarContract.Events.EXDATE,new Mapped<>(mExDates,mUtcDate)))
            // explicitly (re-)set DTEND to null
            .withValue(CalendarContract.Events.DTEND,null)
            .withValue(CalendarContract.Events.EVENT_END_TIMEZONE,null);
}
项目:ContentPal    文件PutTest.java   
@Test
public void testContentOperationBuilder() throws Exception
{
    RowSnapshot<Object> mockRowSnapshot = failingMock(RowSnapshot.class);
    SoftRowReference<Object> mockRowReference = failingMock(SoftRowReference.class);

    doReturn(mockRowReference).when(mockRowSnapshot).reference();
    doReturn(ContentProviderOperation.newUpdate(Uri.EMPTY)).when(mockRowReference).putoperationBuilder(any(TransactionContext.class));

    assertthat(new Put<>(mockRowSnapshot),withoutValues()
            )
    );
}
项目:orgzly-android    文件Provider.java   
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    ContentProviderResult[] results;

    sqliteDatabase db = mOpenHelper.getWritableDatabase();

    db.beginTransaction();
    try {
        inBatch.set(true);
        results = super.applyBatch(operations);
        inBatch.set(false);

        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }

    notifyChange();

    return results;
}
项目:orgzly-android    文件ReposClient.java   
/**
 * Since old repository URL Could be used,do not actually update the existing record,* but create a new one.
 */
public static int updateUrl(Context mContext,long id,String url) {
    ArrayList<ContentProviderOperation> ops = new ArrayList<>();

    ops.add(ContentProviderOperation
                    .newDelete(ContentUris.withAppendedId(ProviderContract.Repos.ContentUri.repos(),id))
                    .build());

    ops.add(ContentProviderOperation
                    .newInsert(ProviderContract.Repos.ContentUri.repos())
                    .withValue(ProviderContract.Repos.Param.REPO_URL,url)
                    .build());

    try {
        mContext.getContentResolver().applyBatch(ProviderContract.AUTHORITY,ops);
    } catch (remoteexception | OperationApplicationException e) {
        e.printstacktrace();
        throw new RuntimeException(e);
    }

    return 1;
}
项目:orgzly-android    文件CurrentRooksClient.java   
public static void set(Context context,List<VersionedRook> books) {
    ArrayList<ContentProviderOperation> ops = new ArrayList<>();

    /* Delete all prevIoUs. */
    ops.add(ContentProviderOperation
            .newDelete(ProviderContract.CurrentRooks.ContentUri.currentRooks())
            .build());

    /* Insert each one. */
    for (VersionedRook book: books) {
        ContentValues values = new ContentValues();
        CurrentRooksClient.toContentValues(values,book);

        ops.add(ContentProviderOperation
                .newInsert(ProviderContract.CurrentRooks.ContentUri.currentRooks())
                .withValues(values)
                .build());
    }

    try {
        context.getContentResolver().applyBatch(ProviderContract.AUTHORITY,ops);
    } catch (remoteexception | OperationApplicationException e) {
        e.printstacktrace();
    }
}
项目:EasyAppleSyncAdapter    文件LocalEvent.java   
@Override
protected void buildEvent(Event recurrence,ContentProviderOperation.Builder builder) {
    super.buildEvent(recurrence,builder);

    boolean buildException = recurrence != null;
    Event eventToBuild = buildException ? recurrence : event;

    builder.withValue(COLUMN_UID,event.uid)
            .withValue(COLUMN_SEQUENCE,eventToBuild.sequence)
            .withValue(CalendarContract.Events.DIRTY,0)
            .withValue(CalendarContract.Events.DELETED,0);

    if (buildException) {
        builder.withValue(CalendarContract.Events.ORIGINAL_SYNC_ID,fileName);
    } else {
        builder.withValue(CalendarContract.Events._SYNC_ID,fileName)
                .withValue(COLUMN_ETAG,eTag);
    }
}
项目:VirtualAPK    文件RemoteContentProvider.java   
@NonNull
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    try {
        Field uriField = ContentProviderOperation.class.getDeclaredField("mUri");
        uriField.setAccessible(true);
        for (ContentProviderOperation operation : operations) {
            Uri pluginUri = Uri.parse(operation.getUri().getQueryParameter(KEY_URI));
            uriField.set(operation,pluginUri);
        }
    } catch (Exception e) {
        return new ContentProviderResult[0];
    }

    if (operations.size() > 0) {
        ContentProvider provider = getContentProvider(operations.get(0).getUri());
        if (provider != null) {
            return provider.applyBatch(operations);
        }
    }

    return new ContentProviderResult[0];
}
项目:SimpleUILauncher    文件ImportDataTask.java   
@Override
public long insertAndCheck(sqliteDatabase db,screen);
    mOutops.add(ContentProviderOperation.newInsert(Favorites.CONTENT_URI).withValues(values).build());
    return 0;
}
项目:iosched-reader    文件ScheduleProvider.java   
/**
 * Apply the given set of {@link ContentProviderOperation},executing inside
 * a {@link sqliteDatabase} transaction. All changes will be rolled back if
 * any single one fails.
 */
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
    final sqliteDatabase db = mOpenHelper.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,i);
        }
        db.setTransactionSuccessful();
        return results;
    } finally {
        db.endTransaction();
    }
}
项目:FlickLauncher    文件LauncherModel.java   
static void updateItemsInDatabaseHelper(Context context,final ArrayList<ContentValues> valuesList,final ArrayList<ItemInfo> items,final String callingFunction) {
    final ContentResolver cr = context.getContentResolver();

    final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
    Runnable r = new Runnable() {
        public void run() {
            ArrayList<ContentProviderOperation> ops =
                    new ArrayList<ContentProviderOperation>();
            int count = items.size();
            for (int i = 0; i < count; i++) {
                ItemInfo item = items.get(i);
                final long itemId = item.id;
                final Uri uri = LauncherSettings.Favorites.getContentUri(itemId);
                ContentValues values = valuesList.get(i);

                ops.add(ContentProviderOperation.newUpdate(uri).withValues(values).build());
                updateItemArrays(item,itemId,stackTrace);

            }
            try {
                cr.applyBatch(LauncherProvider.AUTHORITY,ops);
            } catch (Exception e) {
                e.printstacktrace();
            }
        }
    };
    runOnWorkerThread(r);
}
项目:react-native-videoplayer    文件APEZProvider.java   
@Override
public ContentProviderResult[] applyBatch(
        ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
       initIfNecessary();
    return super.applyBatch(operations);
}
项目:ContentPal    文件TitleData.java   
@NonNull
@Override
public ContentProviderOperation.Builder updatedBuilder(TransactionContext transactionContext,@NonNull ContentProviderOperation.Builder builder)
{
    return mDelegate.updatedBuilder(transactionContext,builder)
            .withValue(ContactsContract.CommonDataKinds.Organization.TITLE,mTitle == null ? null : mTitle.toString());
}
项目:Linphone4Android    文件LinphoneContact.java   
public void setorganization(String org) {
    if (isAndroidContact()) {
        if (androidRawId != null) {
            String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + CommonDataKinds.Organization.CONTENT_ITEM_TYPE + "'";
            String[] args = new String[]{ getAndroidId() };

            if (organization != null) {
                changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
                    .withSelection(select,args)
                    .withValue(ContactsContract.Data.MIMETYPE,CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
                    .withValue(CommonDataKinds.Organization.COMPANY,org)
                    .build());
            } else {
                changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                    .withValue(ContactsContract.Data.RAW_CONTACT_ID,org)
                    .build());
            }
        } else {
            changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,0)
                .withValue(ContactsContract.Data.MIMETYPE,CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
                .withValue(CommonDataKinds.Organization.COMPANY,org)
                .build());
        }
    }

    organization = org;
}
项目:Linphone4Android    文件LinphoneContact.java   
private void createLinphoneContactTag() {
    ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>();

    batch.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
        .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,ContactsManager.getInstance().getString(R.string.sync_account_type))
        .withValue(ContactsContract.RawContacts.ACCOUNT_NAME,ContactsManager.getInstance().getString(R.string.sync_account_name))
        .withValue(ContactsContract.RawContacts.AGGREGATION_MODE,ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
        .build());

    batch.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
        .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,0)
        .withValue(ContactsContract.Data.MIMETYPE,CommonDataKinds.Structuredname.CONTENT_ITEM_TYPE)
        .withValue(CommonDataKinds.Structuredname.disPLAY_NAME,getFullName())
        .build());

    batch.add(ContentProviderOperation.newUpdate(ContactsContract.AggregationExceptions.CONTENT_URI)
        .withValue(ContactsContract.AggregationExceptions.TYPE,ContactsContract.AggregationExceptions.TYPE_KEEP_TOGETHER)
        .withValue(ContactsContract.AggregationExceptions.RAW_CONTACT_ID1,androidRawId)
        .withValueBackReference(ContactsContract.AggregationExceptions.RAW_CONTACT_ID2,0)
        .build());

    if (changesToCommit2.size() > 0) {
        for(ContentProviderOperation cpo : changesToCommit2) {
            batch.add(cpo);
        }
    }

    try {
        ContactsManager.getInstance().getContentResolver().applyBatch(ContactsContract.AUTHORITY,batch);
        androidTagId = findLinphoneRawContactId();
    } catch (Exception e) {
        Log.e(e);
    }
}
项目:LaunchEnr    文件GridSizeMigrationTask.java   
/**
 * Updates an item in the DB.
 */
protected void update(DbEntry item) {
    mTempValues.clear();
    item.addToContentValues(mTempValues);
    mUpdateOperations.add(ContentProviderOperation
            .newUpdate(LauncherSettings.Favorites.getContentUri(item.id))
            .withValues(mTempValues).build());
}
项目:LaunchEnr    文件ImportDataTask.java   
private boolean importWorkspace() throws Exception {
    ArrayList<Long> allScreens = Launcherdbutils.getScreenIdsFromCursor(
            mContext.getContentResolver().query(mOtherScreensUri,LauncherSettings.WorkspaceScreens.SCREEN_RANK));


    // During import we reset the screen IDs to 0-indexed values.
    if (allScreens.isEmpty()) {
        // No thing to migrate

        return false;
    }

    mHotseatSize = mMaxGridSizeX = mMaxGridSizeY = 0;

    // Build screen update
    ArrayList<ContentProviderOperation> screenops = new ArrayList<>();
    int count = allScreens.size();
    LongSparseArray<Long> screenIdMap = new LongSparseArray<>(count);
    for (int i = 0; i < count; i++) {
        ContentValues v = new ContentValues();
        v.put(LauncherSettings.WorkspaceScreens._ID,i);
        v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK,i);
        screenIdMap.put(allScreens.get(i),(long) i);
        screenops.add(ContentProviderOperation.newInsert(
                LauncherSettings.WorkspaceScreens.CONTENT_URI).withValues(v).build());
    }
    mContext.getContentResolver().applyBatch(ProviderConfig.AUTHORITY,screenops);
    importWorkspaceItems(allScreens.get(0),screenIdMap);

    GridSizeMigrationTask.markForMigration(mContext,mMaxGridSizeX,mMaxGridSizeY,mHotseatSize);

    // Create empty DB flag.
    LauncherSettings.Settings.call(mContext.getContentResolver(),LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG);
    return true;
}
项目:LaunchEnr    文件ImportDataTask.java   
HotseatParserCallback(
        HashSet<String> existingApps,LongArrayMap<Object> existingItems,ArrayList<ContentProviderOperation> outops,int startItemId,int requiredSize) {
    mExisitingApps = existingApps;
    mExistingItems = existingItems;
    mOutops = outops;
    mrequiredSize = requiredSize;
    mStartItemId = startItemId;
}
项目:SimpleUILauncher    文件ImportDataTask.java   
HotseatParserCallback(
        HashSet<String> existingApps,int requiredSize) {
    mExisitingApps = existingApps;
    mExistingItems = existingItems;
    mOutops = outops;
    mrequiredSize = requiredSize;
    mStartItemId = startItemId;
}
项目:ContentPal    文件Prefixed.java   
@NonNull
@Override
public ContentProviderOperation.Builder updatedBuilder(TransactionContext transactionContext,builder)
            .withValue(ContactsContract.CommonDataKinds.Structuredname.PREFIX,mPrefix == null ? null : mPrefix.toString());
}
项目:ContentPal    文件RegionData.java   
@NonNull
@Override
public ContentProviderOperation.Builder updatedBuilder(TransactionContext transactionContext,builder)
            .withValue(ContactsContract.CommonDataKinds.StructuredPostal.REGION,mRegion == null ? null : mRegion.toString());
}
项目:ContentPal    文件SipAddressData.java   
@NonNull
@Override
public ContentProviderOperation.Builder updatedBuilder(TransactionContext transactionContext,@NonNull ContentProviderOperation.Builder builder)
{
    return builder
            .withValue(ContactsContract.CommonDataKinds.SipAddress.MIMETYPE,ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS,mSipAddress.toString());
}
项目:ContentPal    文件MultiInsertBatchTest.java   
@Test
public void testSingleComposite()
{
    InsertOperation<Object> mockOp = mock(InsertOperation.class);
    when(mockOp.contentOperationBuilder(any(TransactionContext.class))).then(new Answer<ContentProviderOperation.Builder>()
    {
        @Override
        public ContentProviderOperation.Builder answer(InvocationOnMock invocation) throws Throwable
        {
            return ContentProviderOperation.newInsert(Uri.EMPTY);
        }
    });

    assertthat(new MultiInsertBatch<>(mockOp,new Composite<>(
                            new CharSequenceRowData<>("key","value"),new CharSequenceRowData<>("key2","value2"),new CharSequenceRowData<>("key3","value3"))),Matchers.contains(
                    builds(
                            insertOperation(),withValuesOnly(
                                    containing("key",containing("key2",containing("key3","value3")),withYieldNotAllowed())));
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。