android.content.ContentProviderOperation Java Examples

The following examples show how to use android.content.ContentProviderOperation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContactsDatabase.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void addContactVoiceSupport(List<ContentProviderOperation> operations,
                                    @NonNull String address, long rawContactId)
{
  operations.add(ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI)
                                         .withSelection(RawContacts._ID + " = ?", new String[] {String.valueOf(rawContactId)})
                                         .withValue(RawContacts.SYNC4, "true")
                                         .build());

  operations.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build())
                                         .withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
                                         .withValue(ContactsContract.Data.MIMETYPE, CALL_MIMETYPE)
                                         .withValue(ContactsContract.Data.DATA1, address)
                                         .withValue(ContactsContract.Data.DATA2, context.getString(R.string.app_name))
                                         .withValue(ContactsContract.Data.DATA3, context.getString(R.string.ContactsDatabase_signal_call_s, address))
                                         .withYieldAllowed(true)
                                         .build());
}
 
Example #2
Source File: ActivityItemsProvider.java    From GitJourney with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #3
Source File: ContentProviderProxy1.java    From Neptune with Apache License 2.0 6 votes vote down vote up
@Override
public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    if (operations.size() > 0) {
        ContentProvider provider = getContentProvider(operations.get(0).getUri());
        if (provider != null) {
            try {
                for (ContentProviderOperation operation : operations) {
                    Uri pluginUri = Uri.parse(operation.getUri().getQueryParameter(IntentConstant.EXTRA_TARGET_URI_KEY));
                    ReflectionUtils.on(operation).set("mUri", pluginUri);
                }
                return provider.applyBatch(operations);
            } catch (Exception e) {
                return new ContentProviderResult[0];
            }
        }
    }
    return new ContentProviderResult[0];
}
 
Example #4
Source File: RemoteContentProvider.java    From VirtualAPK with Apache License 2.0 6 votes vote down vote up
@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];
}
 
Example #5
Source File: ContactsManager.java    From Linphone4Android with GNU General Public License v3.0 6 votes vote down vote up
public void deleteMultipleContactsAtOnce(List<String> ids) {
	String select = Data.CONTACT_ID + " = ?";
	ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

	for (String id : ids) {
		String[] args = new String[] { id };
		ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).withSelection(select, args).build());
	}

	ContentResolver cr = ContactsManager.getInstance().getContentResolver();
	try {
		cr.applyBatch(ContactsContract.AUTHORITY, ops);
	} catch (Exception e) {
		Log.e(e);
	}
}
 
Example #6
Source File: SQLiteProvider.java    From android-atleap with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    ContentProviderResult[] result = null;

    SQLiteDatabase db = this.getDatabaseHelper().getWritableDatabase();

    db.beginTransaction();
    try {
        result = super.applyBatch(operations);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    return result;
}
 
Example #7
Source File: ContactProvider.java    From RememBirthday with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Exception doInBackground(Void... voids) {
    try {
        ArrayList<ContentProviderOperation> ops = new ArrayList<>();
        ContentProviderOperation.Builder contentBuilder =  ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
                .withSelection(ContactsContract.Data._ID + " =? AND " +
                                ContactsContract.Data.MIMETYPE + " =? AND " +
                                ContactsContract.CommonDataKinds.Event.START_DATE + " =? AND " +
                                ContactsContract.CommonDataKinds.Event.TYPE + " =?"
                        , new String[]{String.valueOf(dataId),
                                ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE,
                                oldBirthday.toBackupString(),
                                String.valueOf(ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)})
                .withValue(ContactsContract.CommonDataKinds.Event.START_DATE, birthday.toBackupString());
        Log.d(getClass().getSimpleName(), "Update birthday " + oldBirthday + " to " + birthday);
        ops.add(contentBuilder.build());
        ContentProviderResult[] results = context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
        if(results[0].count == 0)
            return new Exception("Unable to update birthday");
    } catch(Exception e) {
        return e;
    }
    return null;
}
 
Example #8
Source File: DataProvider.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
/**
 * 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, results, i);
        }
        db.setTransactionSuccessful();
        return results;
    } finally {
        db.endTransaction();
    }
}
 
Example #9
Source File: DisplayActivity.java    From coursera-android with MIT License 6 votes vote down vote up
private void addRecordToBatchInsertOperation(String name,
		List<ContentProviderOperation> ops) {

	int position = ops.size();

	// First part of operation
	ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
			.withValue(RawContacts.ACCOUNT_TYPE, mType)
			.withValue(RawContacts.ACCOUNT_NAME, mName)
			.withValue(Contacts.STARRED, 1).build());

	// Second part of operation
	ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
			.withValueBackReference(Data.RAW_CONTACT_ID, position)
			.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
			.withValue(StructuredName.DISPLAY_NAME, name).build());

}
 
Example #10
Source File: FileDataStorageManager.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
private ArrayList<ContentProviderOperation> prepareRemoveSharesInFile(
        String filePath, ArrayList<ContentProviderOperation> preparedOperations) {

    String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND "
            + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
    String[] whereArgs = new String[]{filePath, mAccount.name};

    preparedOperations.add(
            ContentProviderOperation.newDelete(ProviderTableMeta.CONTENT_URI_SHARE).
                    withSelection(where, whereArgs).
                    build()
    );

    return preparedOperations;

}
 
Example #11
Source File: ItemsProvider.java    From make-your-app-material with Apache License 2.0 6 votes vote down vote up
/**
 * 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, results, i);
        }
        db.setTransactionSuccessful();
        return results;
    } finally {
        db.endTransaction();
    }
}
 
Example #12
Source File: GithubLocalDataSource.java    From gito-github-client with Apache License 2.0 5 votes vote down vote up
public void saveTrendingRepositories(String period, String language,
                                     List<TrendingRepository> repositories) {
    Uri uri = TrendingContract.TrendingEntry.CONTENT_URI;

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

    ops.add(ContentProviderOperation.newDelete(uri)
            .withSelection(TrendingContract.TrendingEntry.COLUMN_LANGUAGE + " = ? AND " +
                            TrendingContract.TrendingEntry.COLUMN_PERIOD + " = ? ",
                    new String[]{language, period}).build());

    for (TrendingRepository repository : repositories) {

        repository.setLanguage(language);
        repository.setPeriod(period);

        ContentValues contentValues = TrendingContract.TrendingEntry
                .buildContentValues(repository, period, language);
        ops.add(ContentProviderOperation.newInsert(uri)
                .withValues(contentValues).build());
    }
    try {
        mContentResolver.applyBatch(TrendingContract.CONTENT_AUTHORITY, ops);
        mContentResolver.notifyChange(uri, null);
    } catch (RemoteException | OperationApplicationException e) {
        FirebaseCrash.report(e);
    }
}
 
Example #13
Source File: RepoPersister.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
private ArrayList<ContentProviderOperation> insertApks(List<Apk> packages) {
    ArrayList<ContentProviderOperation> operations = new ArrayList<>(packages.size());
    for (Apk apk : packages) {
        ContentValues values = apk.toContentValues();
        Uri uri = TempApkProvider.getContentUri();
        operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build());
    }

    return operations;
}
 
Example #14
Source File: TransactionHelper.java    From CPOrm with MIT License 5 votes vote down vote up
private static ContentProviderOperation.Builder newUpdate(Context context, TableDetails tableDetails, CPDefaultRecord cpDefaultRecord) {

        ContentValues contentValues = ModelInflater.deflate(tableDetails, cpDefaultRecord);
        Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), cpDefaultRecord);
        Uri itemUri = UriMatcherHelper.generateItemUri(context, tableDetails, String.valueOf(columnValue)).build();

        return ContentProviderOperation.newUpdate(itemUri)
                .withExpectedCount(1)
                .withValues(contentValues);
    }
 
Example #15
Source File: RepoPersister.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
private ArrayList<ContentProviderOperation> insertApps(List<App> apps) {
    ArrayList<ContentProviderOperation> operations = new ArrayList<>(apps.size());
    for (App app : apps) {
        ContentValues values = app.toContentValues();
        Uri uri = TempAppProvider.getContentUri();
        operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build());
    }
    return operations;
}
 
Example #16
Source File: ContactsFragment.java    From android-RuntimePermissions with Apache License 2.0 5 votes vote down vote up
/**
 * Accesses the Contacts content provider directly to insert a new contact.
 * <p>
 * The contact is called "__DUMMY ENTRY" and only contains a name.
 */
private void insertDummyContact() {
    // Two operations are needed to insert a new contact.
    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(2);

    // First, set up a new raw contact.
    ContentProviderOperation.Builder op =
            ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
                    .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
                    .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null);
    operations.add(op.build());

    // Next, set the name for the contact.
    op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE,
                    ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
                    DUMMY_CONTACT_NAME);
    operations.add(op.build());

    // Apply the operations.
    ContentResolver resolver = getActivity().getContentResolver();
    try {
        resolver.applyBatch(ContactsContract.AUTHORITY, operations);
    } catch (RemoteException | OperationApplicationException e) {
        Snackbar.make(mMessageText.getRootView(), "Could not add a new contact: " +
                e.getMessage(), Snackbar.LENGTH_LONG);
    }
}
 
Example #17
Source File: APODContentProvider.java    From stetho with MIT License 5 votes vote down vote up
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
    throws OperationApplicationException {
  SQLiteDatabase db = mOpenHelper.getWritableDatabase();
  db.beginTransaction();
  try {
    ContentProviderResult[] results = super.applyBatch(operations);
    db.setTransactionSuccessful();
    return results;
  } finally {
    db.endTransaction();
    notifyChange();
  }
}
 
Example #18
Source File: AbstractProvider.java    From simpleprovider with MIT License 5 votes vote down vote up
@SuppressWarnings("NullableProblems")
@Override
public final ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
    ContentProviderResult[] result = null;
    mDatabase.beginTransaction();
    try {
        result = super.applyBatch(operations);
        mDatabase.setTransactionSuccessful();
    } finally {
        mDatabase.endTransaction();
    }
    return result;
}
 
Example #19
Source File: Organization.java    From react-native-paged-contacts with MIT License 5 votes vote down vote up
@Override
public void addCreationOp(ArrayList<ContentProviderOperation> ops) {
    ContentProviderOperation.Builder op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, organizationName)
            .withValue(ContactsContract.CommonDataKinds.Organization.DEPARTMENT, departmentName)
            .withValue(ContactsContract.CommonDataKinds.Organization.TITLE, jobTitle)
            .withValue(ContactsContract.CommonDataKinds.Organization.PHONETIC_NAME, phoneticOrganizationName);

    ops.add(op.build());
}
 
Example #20
Source File: DatabaseProviderTest.java    From arca-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void testDatabaseApplyBatchEmptyOperations() {
	try {
		final ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
		getProvider().applyBatch(operations);
	} catch (final Exception e) {
		Assert.fail();
	}
}
 
Example #21
Source File: AndroidContact.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
private void addChangesToCommit(ContentProviderOperation operation) {
    Log.i("[Contact] Added operation " + operation);
    if (mChangesToCommit == null) {
        mChangesToCommit = new ArrayList<>();
    }
    mChangesToCommit.add(operation);
}
 
Example #22
Source File: IdenticonRemovalService.java    From Identiconizer with Apache License 2.0 5 votes vote down vote up
private void processPhotos(ArrayList<ContactInfo> contactInfos) {
    for (int i = 0, j = contactInfos.size(); i < j; i++) {
        updateNotification(getString(R.string.identicons_remove_service_running_title),
                String.format(getString(R.string.identicons_remove_service_contact_summary),
                        i, j)
        );
        // ContactsListActivity gives us name_raw_contact_id, which is not unique.
        // For example, if the user has 3 accounts (e.g. Google, WhatsApp and Viber) then three
        // photo rows will exist, one for each.
        // We want to get those that have a photo set (any photo, not identicons.)
        // We can't assume name_raw_contact_id == raw_contact_id because it might only match
        // one photo row (which might be empty) when multiple accounts are present.
        Cursor cursor = getIdenticonPhotos(contactInfos.get(i).nameRawContactId);
        while (cursor.moveToNext()) {
            int contactId = cursor.getInt(0);
            byte[] data = cursor.getBlob(1);
            if (data != null)
                removeIdenticon(contactId);
        }
    }

    if (!mOps.isEmpty()) {
        updateNotification(getString(R.string.identicons_remove_service_running_title),
                getString(R.string.identicons_remove_service_contact_summary_finishing));
        try {
            // Perform operations in batches of 100, to avoid TransactionTooLargeExceptions
            for (int i = 0, j = mOps.size(); i < j; i += 100)
                getContentResolver().applyBatch(ContactsContract.AUTHORITY,
                        new ArrayList<ContentProviderOperation>(mOps.subList(i, i + Math.min(100, j - i))));
        } catch (RemoteException | OperationApplicationException e) {
            Log.e(TAG, "Unable to apply batch", e);
        }
    }
}
 
Example #23
Source File: PhoneNumber.java    From react-native-paged-contacts with MIT License 5 votes vote down vote up
public void addCreationOp(ArrayList<ContentProviderOperation> ops) {
    ContentProviderOperation.Builder op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, number)
            .withValue(ContactsContract.CommonDataKinds.Phone.TYPE,  getTypeInt(type));

    ops.add(op.build());
}
 
Example #24
Source File: HomeActivity.java    From talk-android with MIT License 5 votes vote down vote up
private void writeContacts() {
    Observable.create(new Observable.OnSubscribe<Object>() {
        @Override
        public void call(Subscriber<? super Object> subscriber) {
            final ContentResolver resolver = getContentResolver();
            final String[] projection = {ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER};
            Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, ContactsContract.CommonDataKinds.Phone.NUMBER + "=?", new String[]{MainApp.TALK_BUSINESS_CALL}, null);
            if (cursor != null) {
                if (!cursor.moveToFirst()) {
                    ArrayList<ContentProviderOperation> contentProviderOperations = new ArrayList<>();
                    contentProviderOperations.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
                            .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null).withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null).build());
                    //insert contact display name using Data.CONTENT_URI
                    contentProviderOperations.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0).withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
                            .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, getString(R.string.app_name)).build());
                    //insert mobile number using Data.CONTENT_URI
                    contentProviderOperations.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0).withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
                            .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, MainApp.TALK_BUSINESS_CALL).withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE).build());
                    try {
                        getContentResolver().
                                applyBatch(ContactsContract.AUTHORITY, contentProviderOperations);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                cursor.close();
            }
        }
    }).subscribeOn(Schedulers.computation()).subscribe();
}
 
Example #25
Source File: ContactAccessorSdk5.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
/**
 * Add an email to a list of database actions to be performed
 *
 * @param ops the list of database actions
 * @param email the item to be inserted
 */
private void insertEmail(ArrayList<ContentProviderOperation> ops,
        JSONObject email) {
    ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.Email.DATA, getJsonString(email, "value"))
            .withValue(ContactsContract.CommonDataKinds.Email.TYPE, getContactType(getJsonString(email, "type")))
            .build());
}
 
Example #26
Source File: ImportDataTask.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #27
Source File: ImportDataTask.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
HotseatParserCallback(
        HashSet<String> existingApps, LongArrayMap<Object> existingItems,
        ArrayList<ContentProviderOperation> outOps, int startItemId, int requiredSize) {
    mExisitingApps = existingApps;
    mExistingItems = existingItems;
    mOutOps = outOps;
    mRequiredSize = requiredSize;
    mStartItemId = startItemId;
}
 
Example #28
Source File: ImportDataTask.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
private boolean importWorkspace() throws Exception {
    ArrayList<Long> allScreens = LauncherDbUtils.getScreenIdsFromCursor(
            mContext.getContentResolver().query(mOtherScreensUri, null, null, null,
                    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;
}
 
Example #29
Source File: ContactAccessorSdk5.java    From jpHolo with MIT License 5 votes vote down vote up
/**
 * Add a website to a list of database actions to be performed
 *
 * @param ops the list of database actions
 * @param website the item to be inserted
 */
private void insertWebsite(ArrayList<ContentProviderOperation> ops,
        JSONObject website) {
    ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.Website.DATA, getJsonString(website, "value"))
            .withValue(ContactsContract.CommonDataKinds.Website.TYPE, getContactType(getJsonString(website, "type")))
            .build());
}
 
Example #30
Source File: ContactAccessorSdk5.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
/**
 * Add an im to a list of database actions to be performed
 *
 * @param ops the list of database actions
 * @param im the item to be inserted
 */
private void insertIm(ArrayList<ContentProviderOperation> ops, JSONObject im) {
    ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.Im.DATA, getJsonString(im, "value"))
            .withValue(ContactsContract.CommonDataKinds.Im.TYPE, getImType(getJsonString(im, "type")))
            .build());
}