本文整理汇总了Java中android.content.ContentProviderOperation类的典型用法代码示例。如果您正苦于以下问题:Java ContentProviderOperation类的具体用法?Java ContentProviderOperation怎么用?Java ContentProviderOperation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContentProviderOperation类属于android.content包,在下文中一共展示了ContentProviderOperation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildSpeaker
import android.content.ContentProviderOperation; //导入依赖的package包/类
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());
}
示例2: testAssertOperationBuilder
import android.content.ContentProviderOperation; //导入依赖的package包/类
@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));
}
示例3: setPhoto
import android.content.ContentProviderOperation; //导入依赖的package包/类
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());
}
}
}
}
示例4: testContentOperationBuilder_ctor_table_data
import android.content.ContentProviderOperation; //导入依赖的package包/类
@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"))));
}
示例5: testContentOperationBuilder_ctor_table
import android.content.ContentProviderOperation; //导入依赖的package包/类
@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()));
}
示例6: outputBlock
import android.content.ContentProviderOperation; //导入依赖的package包/类
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());
}
示例7: insertAndCheck
import android.content.ContentProviderOperation; //导入依赖的package包/类
@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;
}
示例8: applyBatch
import android.content.ContentProviderOperation; //导入依赖的package包/类
/**
* 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();
}
}
示例9: flushApksToDbInBatch
import android.content.ContentProviderOperation; //导入依赖的package包/类
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);
}
}
示例10: testContentOperationBuilder
import android.content.ContentProviderOperation; //导入依赖的package包/类
@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()));
}
示例11: applyBatch
import android.content.ContentProviderOperation; //导入依赖的package包/类
@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;
}
示例12: insertDialogs
import android.content.ContentProviderOperation; //导入依赖的package包/类
@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);
});
}
示例13: testContentOperationBuilderWithData
import android.content.ContentProviderOperation; //导入依赖的package包/类
@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"))));
}
示例14: storeCountries
import android.content.ContentProviderOperation; //导入依赖的package包/类
@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();
});
}
示例15: contentOperationBuilder
import android.content.ContentProviderOperation; //导入依赖的package包/类
@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);
}