List of usage examples for android.content ContentResolver insert
public final @Nullable Uri insert(@RequiresPermission.Write @NonNull Uri url, @Nullable ContentValues values)
From source file:cn.edu.nju.dapenti.activity.EditFeedActivity.java
public void onClickAddFilter(View view) { final View dialogView = getLayoutInflater().inflate(R.layout.dialog_filter_edit, null); new AlertDialog.Builder(this) // .setTitle(R.string.filter_add_title) // .setView(dialogView) // .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override/*from w w w. j a v a 2s . c o m*/ public void onClick(DialogInterface dialog, int id) { String filterText = ((EditText) dialogView.findViewById(R.id.filterText)).getText() .toString(); if (filterText.length() != 0) { String feedId = getIntent().getData().getLastPathSegment(); ContentValues values = new ContentValues(); values.put(FilterColumns.FILTER_TEXT, filterText); values.put(FilterColumns.IS_REGEX, ((CheckBox) dialogView.findViewById(R.id.regexCheckBox)).isChecked()); values.put(FilterColumns.IS_APPLIED_TO_TITLE, ((RadioButton) dialogView.findViewById(R.id.applyTitleRadio)).isChecked()); ContentResolver cr = getContentResolver(); cr.insert(FilterColumns.FILTERS_FOR_FEED_CONTENT_URI(feedId), values); } } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }).show(); }
From source file:co.nerdart.ourss.activity.EditFeedActivity.java
public void onClickAddFilter(View view) { final View dialogView = getLayoutInflater().inflate(R.layout.filter_edit, null); new AlertDialog.Builder(this) // .setTitle(R.string.filter_add_title) // .setView(dialogView) // .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override//from w w w . ja v a2 s .c o m public void onClick(DialogInterface dialog, int id) { String filterText = ((EditText) dialogView.findViewById(R.id.filterText)).getText() .toString(); if (filterText.length() != 0) { String feedId = getIntent().getData().getLastPathSegment(); ContentValues values = new ContentValues(); values.put(FilterColumns.FILTER_TEXT, filterText); values.put(FilterColumns.IS_REGEX, ((CheckBox) dialogView.findViewById(R.id.regexCheckBox)).isChecked()); values.put(FilterColumns.IS_APPLIED_TO_TITLE, ((RadioButton) dialogView.findViewById(R.id.applyTitleRadio)).isChecked()); ContentResolver cr = getContentResolver(); cr.insert(FilterColumns.FILTERS_FOR_FEED_CONTENT_URI(feedId), values); } } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }).show(); }
From source file:cz.maresmar.sfm.view.credential.CredentialDetailFragment.java
@Nullable @Override//from ww w. j a v a 2 s. co m public Uri saveData() { Timber.i("Saving credential data"); // Defines an object to contain the new values to insert ContentValues values = new ContentValues(); /* * Sets the values of each column and inserts the word. The arguments to the "put" * method are "column name" and "value" */ values.put(ProviderContract.Credentials.CREDENTIALS_GROUP_ID, mCredentialGroupSpinner.getSelectedItemId()); values.put(ProviderContract.Credentials.PORTAL_GROUP_ID, mPortalGroupId); // User will be added from user prefix values.put(ProviderContract.Credentials.USER_NAME, mNameText.getText().toString()); values.put(ProviderContract.Credentials.USER_PASS, mPasswordText.getText().toString()); values.put(ProviderContract.Credentials.EXTRA, getExtraData()); // Notifications @ProviderContract.CredentialFlags int flags = 0; if (!mCreditIncreaseNotificationCheckBox.isChecked()) { flags |= ProviderContract.CREDENTIAL_FLAG_DISABLE_CREDIT_INCREASE_NOTIFICATION; } if (!mLowCreditNotificationCheckBox.isChecked()) { flags |= ProviderContract.CREDENTIAL_FLAG_DISABLE_LOW_CREDIT_NOTIFICATION; } values.put(ProviderContract.Credentials.FLAGS, flags); values.put(ProviderContract.Credentials.LOW_CREDIT_THRESHOLD, mLowCreditText.getText().toString()); //noinspection ConstantConditions ContentResolver contentResolver = getContext().getContentResolver(); if (mCredentialUri == null) { Uri credentialUri = Uri.withAppendedPath(mUserPrefixUri, ProviderContract.CREDENTIALS_PATH); mCredentialTempUri = contentResolver.insert(credentialUri, values); mCredentialUri = mCredentialTempUri; } else { int updatedRows = contentResolver.update(mCredentialUri, values, null, null); if (BuildConfig.DEBUG) { Assert.isOne(updatedRows); } } return mCredentialUri; }
From source file:net.fred.feedex.activity.EditFeedActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish();/*from www. j av a 2 s . com*/ return true; case R.id.menu_validate: // only in insert mode final String name = mNameEditText.getText().toString().trim(); final String urlOrSearch = mUrlEditText.getText().toString().trim(); if (urlOrSearch.isEmpty()) { UiUtils.showMessage(EditFeedActivity.this, R.string.error_feed_error); } if (!urlOrSearch.contains(".") || !urlOrSearch.contains("/") || urlOrSearch.contains(" ")) { final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this); pd.setMessage(getString(R.string.loading)); pd.setCancelable(true); pd.setIndeterminate(true); pd.show(); getLoaderManager().restartLoader(1, null, new LoaderManager.LoaderCallbacks<ArrayList<HashMap<String, String>>>() { @Override public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int id, Bundle args) { String encodedSearchText = urlOrSearch; try { encodedSearchText = URLEncoder.encode(urlOrSearch, Constants.UTF8); } catch (UnsupportedEncodingException ignored) { } return new GetFeedSearchResultsLoader(EditFeedActivity.this, encodedSearchText); } @Override public void onLoadFinished(Loader<ArrayList<HashMap<String, String>>> loader, final ArrayList<HashMap<String, String>> data) { pd.cancel(); if (data == null) { UiUtils.showMessage(EditFeedActivity.this, R.string.error); } else if (data.isEmpty()) { UiUtils.showMessage(EditFeedActivity.this, R.string.no_result); } else { AlertDialog.Builder builder = new AlertDialog.Builder(EditFeedActivity.this); builder.setTitle(R.string.feed_search); // create the grid item mapping String[] from = new String[] { FEED_SEARCH_TITLE, FEED_SEARCH_DESC }; int[] to = new int[] { android.R.id.text1, android.R.id.text2 }; // fill in the grid_item layout SimpleAdapter adapter = new SimpleAdapter(EditFeedActivity.this, data, R.layout.item_search_result, from, to); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { FeedDataContentProvider.addFeed(EditFeedActivity.this, data.get(which).get(FEED_SEARCH_URL), name.isEmpty() ? data.get(which).get(FEED_SEARCH_TITLE) : name, mRetrieveFulltextCb.isChecked()); setResult(RESULT_OK); finish(); } }); builder.show(); } } @Override public void onLoaderReset(Loader<ArrayList<HashMap<String, String>>> loader) { } }); } else { FeedDataContentProvider.addFeed(EditFeedActivity.this, urlOrSearch, name, mRetrieveFulltextCb.isChecked()); setResult(RESULT_OK); finish(); } return true; case R.id.menu_add_filter: { final View dialogView = getLayoutInflater().inflate(R.layout.dialog_filter_edit, null); new AlertDialog.Builder(this) // .setTitle(R.string.filter_add_title) // .setView(dialogView) // .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { String filterText = ((EditText) dialogView.findViewById(R.id.filterText)).getText() .toString(); if (filterText.length() != 0) { String feedId = getIntent().getData().getLastPathSegment(); ContentValues values = new ContentValues(); values.put(FilterColumns.FILTER_TEXT, filterText); values.put(FilterColumns.IS_REGEX, ((CheckBox) dialogView.findViewById(R.id.regexCheckBox)).isChecked()); values.put(FilterColumns.IS_APPLIED_TO_TITLE, ((RadioButton) dialogView.findViewById(R.id.applyTitleRadio)).isChecked()); values.put(FilterColumns.IS_ACCEPT_RULE, ((RadioButton) dialogView.findViewById(R.id.acceptRadio)).isChecked()); ContentResolver cr = getContentResolver(); cr.insert(FilterColumns.FILTERS_FOR_FEED_CONTENT_URI(feedId), values); } } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }).show(); return true; } default: return super.onOptionsItemSelected(item); } }
From source file:com.heneryh.aquanotes.ui.livestock.LivestockActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_add_ls: ContentResolver mResolver = getContentResolver(); ContentValues values = new ContentValues(); Uri livestockUri = Livestock.buildInsertLivestockUri(); values.clear();/* w ww . j a v a 2s . c om*/ values.put(AquaNotesDbContract.Livestock.COMMON_NAME, "Red Balloon"); values.put(AquaNotesDbContract.Livestock.TYPE, "SPS"); values.put(AquaNotesDbContract.Livestock.THUMBNAIL, R.drawable.red_balloon); values.put(AquaNotesDbContract.Livestock.TIMESTAMP, 0); try { mResolver.insert(livestockUri, values); } catch (SQLException e) { Log.e("LOG_TAG", "Inserting livestock", e); } //Directory.addToCategory(0,new LivestockEntry("Blue Balloon", R.drawable.blue_balloon)); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.chen.mail.providers.Attachment.java
/** * Constructor for use when creating attachments in eml files. */// w ww . j ava2 s . c om public Attachment(Context context, Part part, Uri emlFileUri, String messageId, String partId) { try { // Transfer fields from mime format to provider format final String contentTypeHeader = MimeUtility.unfoldAndDecode(part.getContentType()); name = MimeUtility.getHeaderParameter(contentTypeHeader, "name"); if (name == null) { final String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition()); name = MimeUtility.getHeaderParameter(contentDisposition, "filename"); } contentType = MimeType.inferMimeType(name, part.getMimeType()); uri = EmlAttachmentProvider.getAttachmentUri(emlFileUri, messageId, partId); contentUri = uri; thumbnailUri = uri; previewIntentUri = null; state = UIProvider.AttachmentState.SAVED; providerData = null; supportsDownloadAgain = false; destination = UIProvider.AttachmentDestination.CACHE; type = UIProvider.AttachmentType.STANDARD; flags = 0; // insert attachment into content provider so that we can open the file final ContentResolver resolver = context.getContentResolver(); resolver.insert(uri, toContentValues()); // save the file in the cache try { final InputStream in = part.getBody().getInputStream(); final OutputStream out = resolver.openOutputStream(uri, "rwt"); size = IOUtils.copy(in, out); downloadedSize = size; in.close(); out.close(); } catch (FileNotFoundException e) { LogUtils.e(LOG_TAG, e, "Error in writing attachment to cache"); } catch (IOException e) { LogUtils.e(LOG_TAG, e, "Error in writing attachment to cache"); } // perform a second insert to put the updated size and downloaded size values in resolver.insert(uri, toContentValues()); } catch (MessagingException e) { LogUtils.e(LOG_TAG, e, "Error parsing eml attachment"); } }
From source file:com.android.mail.providers.Attachment.java
/** * Constructor for use when creating attachments in eml files. *//*from w w w . j a v a2 s .c om*/ public Attachment(Context context, Part part, Uri emlFileUri, String messageId, String cid, boolean inline) { try { // Transfer fields from mime format to provider format final String contentTypeHeader = MimeUtility.unfoldAndDecode(part.getContentType()); name = MimeUtility.getHeaderParameter(contentTypeHeader, "name"); if (name == null) { final String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition()); name = MimeUtility.getHeaderParameter(contentDisposition, "filename"); } contentType = MimeType.inferMimeType(name, part.getMimeType()); uri = EmlAttachmentProvider.getAttachmentUri(emlFileUri, messageId, cid); contentUri = uri; thumbnailUri = uri; previewIntentUri = null; state = AttachmentState.SAVED; providerData = null; supportsDownloadAgain = false; destination = AttachmentDestination.CACHE; type = inline ? AttachmentType.INLINE_CURRENT_MESSAGE : AttachmentType.STANDARD; partId = cid; flags = 0; // insert attachment into content provider so that we can open the file final ContentResolver resolver = context.getContentResolver(); resolver.insert(uri, toContentValues()); // save the file in the cache try { final InputStream in = part.getBody().getInputStream(); final OutputStream out = resolver.openOutputStream(uri, "rwt"); size = IOUtils.copy(in, out); downloadedSize = size; in.close(); out.close(); } catch (FileNotFoundException e) { LogUtils.e(LOG_TAG, e, "Error in writing attachment to cache"); } catch (IOException e) { LogUtils.e(LOG_TAG, e, "Error in writing attachment to cache"); } // perform a second insert to put the updated size and downloaded size values in resolver.insert(uri, toContentValues()); } catch (MessagingException e) { LogUtils.e(LOG_TAG, e, "Error parsing eml attachment"); } }
From source file:ro.weednet.contactssync.platform.ContactManager.java
public static long ensureGroupExists(Context context, Account account) { final ContentResolver resolver = context.getContentResolver(); // Lookup the group long groupId = 0; final Cursor cursor = resolver.query(Groups.CONTENT_URI, new String[] { Groups._ID }, Groups.ACCOUNT_NAME + "=? AND " + Groups.ACCOUNT_TYPE + "=? AND " + Groups.TITLE + "=?", new String[] { account.name, account.type, GROUP_NAME }, null); if (cursor != null) { try {//w w w .ja v a 2 s. co m if (cursor.moveToFirst()) { groupId = cursor.getLong(0); } } finally { cursor.close(); } } if (groupId == 0) { // Group doesn't exist yet, so create it final ContentValues contentValues = new ContentValues(); contentValues.put(Groups.ACCOUNT_NAME, account.name); contentValues.put(Groups.ACCOUNT_TYPE, account.type); contentValues.put(Groups.TITLE, GROUP_NAME); // contentValues.put(Groups.GROUP_IS_READ_ONLY, true); contentValues.put(Groups.GROUP_VISIBLE, true); final Uri newGroupUri = resolver.insert(Groups.CONTENT_URI, contentValues); groupId = ContentUris.parseId(newGroupUri); } return groupId; }
From source file:com.appsimobile.appsii.module.weather.WeatherLoadingService.java
void onWeatherDataLoaded(@Nullable CircularArray<WeatherData> weatherDataList, String unit) { int N = weatherDataList == null ? 0 : weatherDataList.size(); for (int i1 = 0; i1 < N; i1++) { WeatherData weatherData = weatherDataList.get(i1); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_LAST_UPDATED, System.currentTimeMillis()); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_WOEID, weatherData.woeid); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_ATMOSPHERE_HUMIDITY, weatherData.atmosphereHumidity); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_ATMOSPHERE_PRESSURE, weatherData.atmospherePressure); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_ATMOSPHERE_RISING, weatherData.atmosphereRising); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_ATMOSPHERE_VISIBILITY, weatherData.atmosphereVisible); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_NOW_CONDITION_CODE, weatherData.nowConditionCode); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_NOW_TEMPERATURE, weatherData.nowTemperature); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_SUNRISE, weatherData.sunrise); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_SUNSET, weatherData.sunset); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_WIND_CHILL, weatherData.windChill); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_WIND_DIRECTION, weatherData.windDirection); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_WIND_SPEED, weatherData.windSpeed); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_CITY, weatherData.location); weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_UNIT, unit); ContentResolver contentResolver = mContext.getContentResolver(); contentResolver.insert(WeatherContract.WeatherColumns.CONTENT_URI, weatherValues); List<WeatherData.Forecast> forecasts = weatherData.forecasts; if (!forecasts.isEmpty()) { int count = forecasts.size(); ContentValues[] forecastValues = new ContentValues[count]; for (int i = 0; i < count; i++) { WeatherData.Forecast forecast = forecasts.get(i); ContentValues contentValues = new ContentValues(); contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_FORECAST_DAY, forecast.julianDay); contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_LAST_UPDATED, System.currentTimeMillis()); contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_LOCATION_WOEID, weatherData.woeid); contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_CONDITION_CODE, forecast.conditionCode); contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_TEMPERATURE_HIGH, forecast.high); contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_TEMPERATURE_LOW, forecast.low); contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_UNIT, unit); forecastValues[i] = contentValues; }// w w w. ja va 2s .com Uri uri = WeatherContract.ForecastColumns.CONTENT_URI; contentResolver.bulkInsert(uri, forecastValues); } } Intent i = new Intent(ACTION_WEATHER_UPDATED); i.setPackage(mContext.getPackageName()); mContext.sendBroadcast(i); }
From source file:com.google.android.apps.muzei.SourceSubscriberService.java
@Override protected void onHandleIntent(Intent intent) { if (intent == null || intent.getAction() == null) { return;/*ww w .j a v a 2s .c o m*/ } String action = intent.getAction(); if (!ACTION_PUBLISH_STATE.equals(action)) { return; } // Handle API call from source String token = intent.getStringExtra(EXTRA_TOKEN); ComponentName selectedSource = SourceManager.getSelectedSource(this); if (selectedSource == null || !TextUtils.equals(token, selectedSource.flattenToShortString())) { Log.w(TAG, "Dropping update from non-selected source, token=" + token + " does not match token for " + selectedSource); return; } SourceState state = null; if (intent.hasExtra(EXTRA_STATE)) { Bundle bundle = intent.getBundleExtra(EXTRA_STATE); if (bundle != null) { state = SourceState.fromBundle(bundle); } } if (state == null) { // If there is no state, there is nothing to change return; } ContentValues values = new ContentValues(); values.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, selectedSource.flattenToShortString()); values.put(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED, true); values.put(MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION, state.getDescription()); values.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, state.getWantsNetworkAvailable()); JSONArray commandsSerialized = new JSONArray(); int numSourceActions = state.getNumUserCommands(); boolean supportsNextArtwork = false; for (int i = 0; i < numSourceActions; i++) { UserCommand command = state.getUserCommandAt(i); if (command.getId() == MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK) { supportsNextArtwork = true; } else { commandsSerialized.put(command.serialize()); } } values.put(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND, supportsNextArtwork); values.put(MuzeiContract.Sources.COLUMN_NAME_COMMANDS, commandsSerialized.toString()); ContentResolver contentResolver = getContentResolver(); Cursor existingSource = contentResolver.query(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?", new String[] { selectedSource.flattenToShortString() }, null, null); if (existingSource != null && existingSource.moveToFirst()) { Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI, existingSource.getLong(0)); contentResolver.update(sourceUri, values, null, null); } else { contentResolver.insert(MuzeiContract.Sources.CONTENT_URI, values); } if (existingSource != null) { existingSource.close(); } Artwork artwork = state.getCurrentArtwork(); if (artwork != null) { artwork.setComponentName(selectedSource); contentResolver.insert(MuzeiContract.Artwork.CONTENT_URI, artwork.toContentValues()); // Download the artwork contained from the newly published SourceState startService(TaskQueueService.getDownloadCurrentArtworkIntent(this)); } }