项目: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();
}
}
@NonNull
@Override
public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
ContentProviderResult[] result = null;
isApplyingBatch = true;
final sqliteDatabase db = db();
db.beginTransaction();
try {
result = super.applyBatch(operations);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
isApplyingBatch = false;
}
return result;
}
项目: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);
}
}
项目:PeSanKita-android
文件:DirectoryHelper.java
private static @NonNull RefreshResult updateContactsDatabase(@NonNull Context context,@NonNull String localNumber,@NonNull List<ContactTokenDetails> activetokens,boolean removeMissing)
{
Optional<AccountHolder> account = getorCreateAccount(context);
if (account.isPresent()) {
try {
List<String> newUsers = DatabaseFactory.getContactsDatabase(context)
.setRegisteredUsers(account.get().getAccount(),localNumber,activetokens,removeMissing);
return new RefreshResult(newUsers,account.get().isFresh());
} catch (remoteexception | OperationApplicationException e) {
Log.w(TAG,e);
}
}
return new RefreshResult(new LinkedList<String>(),false);
}
/**
* Apply the given set of {@link ContentProviderOperation},i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
项目: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();
}
}
项目:orgzly-android
文件:NotesClient.java
public static int delete(Context context,long[] noteIds) {
int deleted = 0;
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
for (long noteId: noteIds) {
ops.add(ContentProviderOperation
.newDelete(ProviderContract.Notes.ContentUri.notes())
.withSelection(ProviderContract.Notes.UpdateParam._ID + "=" + noteId,null)
.build()
);
}
try {
context.getContentResolver().applyBatch(ProviderContract.AUTHORITY,ops);
} catch (remoteexception | OperationApplicationException e) {
e.printstacktrace();
throw new RuntimeException(e);
}
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG,"Deleted " + deleted + " notes");
return deleted;
}
项目: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];
}
项目:android-architecture-components
文件:SampleContentProvider.java
@NonNull
@Override
public ContentProviderResult[] applyBatch(
@NonNull ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final Context context = getContext();
if (context == null) {
return new ContentProviderResult[0];
}
final SampleDatabase database = SampleDatabase.getInstance(context);
database.beginTransaction();
try {
final ContentProviderResult[] result = super.applyBatch(operations);
database.setTransactionSuccessful();
return result;
} finally {
database.endTransaction();
}
}
项目:android-architecture-components
文件:SampleContentProviderTest.java
@Test
public void cheese_applyBatch() throws remoteexception,OperationApplicationException {
final ArrayList<ContentProviderOperation> operations = new ArrayList<>();
operations.add(ContentProviderOperation
.newInsert(SampleContentProvider.URI_CHEESE)
.withValue(Cheese.COLUMN_NAME,"Peynir")
.build());
operations.add(ContentProviderOperation
.newInsert(SampleContentProvider.URI_CHEESE)
.withValue(Cheese.COLUMN_NAME,"Queso")
.build());
final ContentProviderResult[] results = mContentResolver.applyBatch(
SampleContentProvider.AUTHORITY,operations);
assertthat(results.length,is(2));
final Cursor cursor = mContentResolver.query(SampleContentProvider.URI_CHEESE,new String[]{Cheese.COLUMN_NAME},null,null);
assertthat(cursor,notNullValue());
assertthat(cursor.getCount(),is(2));
assertthat(cursor.movetoFirst(),is(true));
cursor.close();
}
项目: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();
}
}
项目:Cable-Android
文件:DirectoryHelper.java
private static @NonNull RefreshResult updateContactsDatabase(@NonNull Context context,false);
}
项目: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;
}
项目:aos-MediaLib
文件:ScraperProvider.java
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
sqliteDatabase db = mDbHolder.get();
db.beginTransaction();
ContentProviderResult[] result = null;
try {
result = super.applyBatch(operations);
db.setTransactionSuccessful();
ContentResolver res = mCr;
res.notifyChange(ScraperStore.ALL_CONTENT_URI,null);
return result;
} finally {
db.endTransaction();
}
}
项目:sorm
文件:ContentProviderEngine.java
@Override
public void transactionSuccess() {
try {
ContentProviderResult[] cpr = context.getContentResolver().applyBatch(
dsUri.getAuthority(),trans);
if(cpr == null || cpr.length != trans.size()){
throw new DaoException();
}
for (int i = 0; i < cpr.length; i++) {
if (cpr[i] == null || ( cpr[i].count == null && cpr[i].uri == null)) {
throw new DaoException();
}
}
} catch (remoteexception | OperationApplicationException e) {
throw new DaoException();
} finally {
trans = null;
}
}
项目:sorm
文件:OrmProvider.java
@Override
public ContentProviderResult[] applyBatch( ArrayList<ContentProviderOperation> operations )
throws OperationApplicationException {
ContentProviderResult[] contentProviderResults;
try {
getWritableDatabase().beginTransaction();
contentProviderResults = new ContentProviderResult[operations
.size()];
int i = 0;
for (ContentProviderOperation cpo : operations) {
contentProviderResults[i] = cpo.apply(this,contentProviderResults,i);
if(contentProviderResults[i] == null || (contentProviderResults[i].count == null && contentProviderResults[i].uri == null)){
throw new DaoException();
}
i++;
}
getWritableDatabase().setTransactionSuccessful();
} finally{
if (getWritableDatabase().inTransaction()) {
getWritableDatabase().endTransaction();
}
}
return contentProviderResults;
}
项目:narrate-android
文件:DataProvider.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 = mDatabaseHelper.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();
}
}
项目:Jisort
文件:DsoProvider.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.
*/
@NonNull
@Override
public ContentProviderResult[] applyBatch(@NonNull 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();
}
}
项目:smconf-android
文件:ScheduleProvider.java
/**
* Apply the given set of {@link ContentProviderOperation},i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
项目:android_packages_apps_tv
文件:DvrStorageStatusManager.java
@Override
protected Void doInBackground(Void... params) {
@DvrStorageStatusManager.StorageStatus int storageStatus = getDvrStorageStatus();
if (storageStatus == DvrStorageStatusManager.STORAGE_STATUS_MISSING) {
return null;
}
List<ContentProviderOperation> ops = getDeleteOps(storageStatus
== DvrStorageStatusManager.STORAGE_STATUS_TOTAL_CAPACITY_TOO_SMALL);
if (ops == null || ops.isEmpty()) {
return null;
}
Log.i(TAG,"New device storage mounted. # of recordings to be forgotten : "
+ ops.size());
for (int i = 0 ; i < ops.size() && !isCancelled() ; i += BATCH_OPERATION_COUNT) {
int toIndex = (i + BATCH_OPERATION_COUNT) > ops.size()
? ops.size() : (i + BATCH_OPERATION_COUNT);
ArrayList<ContentProviderOperation> batchOps =
new ArrayList<>(ops.subList(i,toIndex));
try {
mContext.getContentResolver().applyBatch(TvContract.AUTHORITY,batchOps);
} catch (remoteexception | OperationApplicationException e) {
Log.e(TAG,"Failed to clean up RecordedPrograms.",e);
}
}
return null;
}
项目:android_packages_apps_tv
文件:ChannelDataManager.java
public void scannedChannelHandlingCompleted() {
mIsScanning.set(false);
if (!mPrevIoUsScannedChannels.isEmpty()) {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
for (TunerChannel channel : mPrevIoUsScannedChannels) {
ops.add(ContentProviderOperation.newDelete(
TvContract.buildChannelUri(channel.getChannelId())).build());
}
try {
mContext.getContentResolver().applyBatch(TvContract.AUTHORITY,ops);
} catch (remoteexception | OperationApplicationException e) {
Log.e(TAG,"Error deleting obsolete channels",e);
}
}
if (mChannelScanListener != null && mChannelScanHandler != null) {
mChannelScanHandler.post(new Runnable() {
@Override
public void run() {
mChannelScanListener.onChannelHandlingDone();
}
});
} else {
Log.e(TAG,"Error. mChannelScanListener is null.");
}
}
项目:Cirrus
文件:FileContentProvider.java
@Override
public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
Log_OC.d("FileContentProvider","applying batch in provider " + this +
" (temporary: " + istemporary() + ")" );
ContentProviderResult[] results = new ContentProviderResult[operations.size()];
int i=0;
sqliteDatabase db = mDbHelper.getWritableDatabase();
db.beginTransaction(); // it's supposed that transactions can be nested
try {
for (ContentProviderOperation operation : operations) {
results[i] = operation.apply(this,i);
i++;
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
Log_OC.d("FileContentProvider","applied batch in provider " + this);
return results;
}
项目:XYZReader
文件:ItemsProvider.java
/**
* Apply the given set of {@link ContentProviderOperation},i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
项目:espresso-macchiato
文件:EspContactTool.java
public static Uri add(ContactSpec spec) {
// original code http://stackoverflow.com/questions/4744187/how-to-add-new-contacts-in-android
// good blog http://androiddevelopement.blogspot.de/2011/07/insert-update-delete-view-contacts-in.html
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
addContactBase(ops);
addContactdisplayName(spec,ops);
addContactAddress(spec,ops);
try {
ContentProviderResult[] results = InstrumentationRegistry.getTargetContext().getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops);
return results[0].uri;
} catch (remoteexception | OperationApplicationException e) {
throw new IllegalStateException("Could not add contact",e);
}
}
项目:device-database
文件:DevicesProvider.java
@Override
public @NonNull ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
final sqliteDatabase db = helper.getWritableDatabase();
db.beginTransaction();
try {
final ContentProviderResult[] results =
super.applyBatch(operations);
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
项目:apparel
文件:ApparelProvider.java
@Override
public ContentProviderResult[] applyBatch(
ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
/*sqliteDatabase db = sqlOpenHelper.getWritableDatabase();
isInBatchMode.set(true);
db.beginTransaction();
try {
final ContentProviderResult[] retResult = super.applyBatch(operations);
db.setTransactionSuccessful();
getContext().getContentResolver().notifyChange(ApparelContract.CONTENT_URI,null);
return retResult;
}
finally {
isInBatchMode.remove();
db.endTransaction();
}*/
return null;
}
项目:SpatiAtlas
文件:SpatiAtlasProvider.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 = mDbHelper.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();
}
}
项目:2015-Google-I-O-app
文件:ScheduleProvider.java
/**
* Apply the given set of {@link ContentProviderOperation},i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
项目:XiaoMiContactsHelper
文件:MainActivity.java
private void deleteMultiContract(List<Contact> contacts) {
showProgressDialog();
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
for (int i = 0; i < contacts.size(); i++) {
Log.d(TAG,"deleteMultiContract contacts.dataId == " + contacts.get(i).dataId + ",name == " + contacts.get(i).displayName);
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
.withSelection(ContactsContract.Data._ID + "=?",new String[]{contacts.get(i).dataId})
.build());
}
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops);
} catch (remoteexception | OperationApplicationException e) {
e.printstacktrace();
}
UpdateContactService.updateContacts(MainActivity.this,(ArrayList<Contact>) contacts);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mContactTask = new HandleContactTask();
mContactTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
},100);
}
项目:make-your-app-material
文件: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.
*/
@NonNull
public ContentProviderResult[] applyBatch(@NonNull 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();
}
}
项目:MonkeyTree
文件:ContactFixer.java
void fixContactPhonetic(Set<ContactLite> contactIds) {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
for (ContactLite contact : contactIds) {
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(
String.format("%s = ?",ContactsContract.Data._ID),new String[]{String.valueOf(contact.dataId)})
.withValue(ContactsContract.CommonDataKinds.Structuredname.PHONETIC_GIVEN_NAME,contact.phoneticGivenname)
.withValue(ContactsContract.CommonDataKinds.Structuredname.PHONETIC_MIDDLE_NAME,contact.phoneticMiddleName)
.withValue(ContactsContract.CommonDataKinds.Structuredname.PHONETIC_FAMILY_NAME,contact.phoneticFamilyName)
.withValue(ContactsContract.CommonDataKinds.Structuredname.PHONETIC_NAME_STYLE,contact.phoneticNameStyle)
.build());
}
try {
context.getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops);
} catch (remoteexception | OperationApplicationException e) {
Log.e(TAG,"Error when updating",e);
}
Log.i(TAG,"Fix done:" + contactIds.size());
}
private void updateCache() {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
ops.addAll(deleteFromCache(toDelete));
ops.addAll(insertIntoCache(toInsert));
if (ops.size() > 0) {
try {
context.getContentResolver().applyBatch(InstalledAppProvider.getAuthority(),ops);
Utils.debugLog(TAG,"Finished executing " + ops.size() + " CRUD operations on installed app cache.");
} catch (remoteexception | OperationApplicationException e) {
Log.e(TAG,"Error updating installed app cache: " + e);
}
}
}
@NonNull
@Override
public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
ContentProviderResult[] result = null;
isApplyingBatch = true;
final sqliteDatabase db = db();
db.beginTransaction();
try {
result = super.applyBatch(operations);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
isApplyingBatch = false;
}
return result;
}
private void flushApksToDbInBatch() throws RepoUpdater.UpdateException {
List<Apk> apksToSaveList = new ArrayList<>();
for (Map.Entry<String,List<Apk>> entries : apksToSave.entrySet()) {
apksToSaveList.addAll(entries.getValue());
}
calcApkCompatibilityFlags(apksToSaveList);
ArrayList<ContentProviderOperation> apkOperations = new ArrayList<>();
ContentProviderOperation clearOrphans = deleteOrphanedApks(appsToSave,apksToSave);
if (clearOrphans != null) {
apkOperations.add(clearOrphans);
}
apkOperations.addAll(insertOrUpdateApks(apksToSaveList));
try {
context.getContentResolver().applyBatch(TempApkProvider.getAuthority(),e);
}
}
项目:AppHub
文件:InstalledAppCacheUpdater.java
private void updateCache() {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
ops.addAll(deleteFromCache(toDelete));
ops.addAll(insertIntoCache(toInsert));
if (ops.size() > 0) {
try {
context.getContentResolver().applyBatch(InstalledAppProvider.getAuthority(),"Error updating installed app cache: " + e);
}
}
}
项目:AppHub
文件:RepoPersister.java
private void flushApksToDbInBatch() throws RepoUpdater.UpdateException {
List<Apk> apksToSaveList = new ArrayList<>();
for (Map.Entry<String,e);
}
}
项目:RememBirthday
文件:EventLoader.java
public synchronized static void updateEvent(Context context,Contact contact,DateUnkNownYear newBirthday) throws EventException {
// Todo UNIFORMISE
for (CalendarEvent event : getEventsSavedOrCreateNewsForEachYear(context,contact)) {
// Construct each anniversary of new birthday
int year = new DateTime(event.getDate()).getYear();
Date newBirthdayDate = DateUnkNownYear.getDateWithYear(newBirthday.getDate(),year);
event.setDateStart(newBirthdayDate);
event.setAllDay(true);
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
ContentProviderOperation contentProviderOperation = EventProvider.update(event);
operations.add(contentProviderOperation);
try {
ContentProviderResult[] contentProviderResults =
context.getContentResolver().applyBatch(CalendarContract.AUTHORITY,operations);
for(ContentProviderResult contentProviderResult : contentProviderResults) {
if (contentProviderResult.count != 0)
Log.d(TAG,"Update event : " + event.toString());
}
} catch (remoteexception|OperationApplicationException e) {
Log.e(TAG,"Unable to update event : " + e.getMessage());
}
}
}
项目:RememBirthday
文件:EventLoader.java
public synchronized static void deleteEventsFromContact(Context context,Contact contact) {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
try {
for (CalendarEvent event : getEventsSavedForEachYear(context,contact)) {
operations.add(ReminderProvider.deleteall(context,event.getId()));
operations.add(EventProvider.delete(event));
}
ContentProviderResult[] contentProviderResults =
context.getContentResolver().applyBatch(CalendarContract.AUTHORITY,operations);
for(ContentProviderResult contentProviderResult : contentProviderResults) {
Log.d(TAG,contentProviderResult.toString());
if (contentProviderResult.uri != null)
Log.d(TAG,contentProviderResult.uri.toString());
}
} catch (remoteexception |OperationApplicationException |EventException e) {
Log.e(TAG,"Unable to deleteById events : " + e.getMessage());
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。