java类android.content.ContentProviderOperation的实例源码

SpeakersHandler.java 文件源码 项目:iosched-reader 阅读 37 收藏 0 点赞 0 评论 0
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());
}
RowSnapshotReferenceTest.java 文件源码 项目:ContentPal 阅读 37 收藏 0 点赞 0 评论 0
@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));

}
LinphoneContact.java 文件源码 项目:Linphone4Android 阅读 35 收藏 0 点赞 0 评论 0
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, CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
                    .withValue(CommonDataKinds.Photo.PHOTO, photo)
                    .build());
            }
        }
    }
}
BulkAssertTest.java 文件源码 项目:ContentPal 阅读 31 收藏 0 点赞 0 评论 0
@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"))));
}
BulkAssertTest.java 文件源码 项目:ContentPal 阅读 36 收藏 0 点赞 0 评论 0
@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),
            builds(
                    assertOperation(),
                    withoutExpectedCount(),
                    withYieldNotAllowed(),
                    withoutValues()));
}
BlocksHandler.java 文件源码 项目:iosched-reader 阅读 35 收藏 0 点赞 0 评论 0
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());
}
ImportDataTask.java 文件源码 项目:LaunchEnr 阅读 42 收藏 0 点赞 0 评论 0
@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;
}
ItemsProvider.java 文件源码 项目:xyz-reader-2 阅读 43 收藏 0 点赞 0 评论 0
/**
 * 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();
    }
}
RepoPersister.java 文件源码 项目:mobile-store 阅读 50 收藏 0 点赞 0 评论 0
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);
    }
}
DeleteTest.java 文件源码 项目:ContentPal 阅读 40 收藏 0 点赞 0 评论 0
@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(),
                    withYieldNotAllowed(),
                    withoutExpectedCount(),
                    withoutValues()));
}
MusicProvider.java 文件源码 项目:aos-MediaLib 阅读 28 收藏 0 点赞 0 评论 0
@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;
}
DialogsStore.java 文件源码 项目:Phoenix-for-VK 阅读 41 收藏 0 点赞 0 评论 0
@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);
    });
}
PutTest.java 文件源码 项目:ContentPal 阅读 31 收藏 0 点赞 0 评论 0
@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(),
                    withYieldNotAllowed(),
                    withoutExpectedCount(),
                    withValuesOnly(
                            containing("x", "y"))));
}
DatabaseStore.java 文件源码 项目:Phoenix-for-VK 阅读 35 收藏 0 点赞 0 评论 0
@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();
    });
}
AggregationException.java 文件源码 项目:ContentPal 阅读 37 收藏 0 点赞 0 评论 0
@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);

}
SingleEventData.java 文件源码 项目:ContentPal 阅读 35 收藏 0 点赞 0 评论 0
@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);
}
RelativeshipStore.java 文件源码 项目:Phoenix-for-VK 阅读 37 收藏 0 点赞 0 评论 0
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, operations, objectId, userEntities, relationType);
        OwnersRepositiry.appendUsersInsertOperation(operations, accountId, userEntities);

        getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
        emitter.onComplete();
    });
}
SessionsHandler.java 文件源码 项目:iosched-reader 阅读 37 收藏 0 点赞 0 评论 0
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());
        }
    }
}
RecurringEventData.java 文件源码 项目:ContentPal 阅读 34 收藏 0 点赞 0 评论 0
@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.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, TextUtils.join(",", new Mapped<>(mExDates, mUtcDate)))
            // explicitly (re-)set DTEND to null
            .withValue(CalendarContract.Events.DTEND, null)
            .withValue(CalendarContract.Events.EVENT_END_TIMEZONE, null);
}
PutTest.java 文件源码 项目:ContentPal 阅读 39 收藏 0 点赞 0 评论 0
@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),
            builds(
                    updateOperation(),
                    withYieldNotAllowed(),
                    withoutExpectedCount(),
                    withoutValues()
            )
    );
}
Provider.java 文件源码 项目:orgzly-android 阅读 40 收藏 0 点赞 0 评论 0
@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;
}
ReposClient.java 文件源码 项目:orgzly-android 阅读 34 收藏 0 点赞 0 评论 0
/**
 * 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;
}
CurrentRooksClient.java 文件源码 项目:orgzly-android 阅读 33 收藏 0 点赞 0 评论 0
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();
    }
}
LocalEvent.java 文件源码 项目:EasyAppleSyncAdapter 阅读 28 收藏 0 点赞 0 评论 0
@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);
    }
}
RemoteContentProvider.java 文件源码 项目:VirtualAPK 阅读 35 收藏 0 点赞 0 评论 0
@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];
}
ImportDataTask.java 文件源码 项目:SimpleUILauncher 阅读 38 收藏 0 点赞 0 评论 0
@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;
}
ScheduleProvider.java 文件源码 项目:iosched-reader 阅读 37 收藏 0 点赞 0 评论 0
/**
 * 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, results, i);
        }
        db.setTransactionSuccessful();
        return results;
    } finally {
        db.endTransaction();
    }
}
LauncherModel.java 文件源码 项目:FlickLauncher 阅读 44 收藏 0 点赞 0 评论 0
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);
}
APEZProvider.java 文件源码 项目:react-native-videoplayer 阅读 31 收藏 0 点赞 0 评论 0
@Override
public ContentProviderResult[] applyBatch(
        ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
       initIfNecessary();
    return super.applyBatch(operations);
}
TitleData.java 文件源码 项目:ContentPal 阅读 44 收藏 0 点赞 0 评论 0
@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());
}


问题


面经


文章

微信
公众号

扫码关注公众号