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:com.carlrice.reader.activity.EditFeedActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish();//w w w . jav a 2 s .com 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; } case R.id.menu_search_feed: { final View dialogView = getLayoutInflater().inflate(R.layout.dialog_search_feed, null); final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText); if (!mUrlEditText.getText().toString().startsWith(Constants.HTTP_SCHEME) && !mUrlEditText.getText().toString().startsWith(Constants.HTTPS_SCHEME)) { searchText.setText(mUrlEditText.getText()); } final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup); new AlertDialog.Builder(EditFeedActivity.this) // .setIcon(R.drawable.action_search) // .setTitle(R.string.feed_search) // .setView(dialogView) // .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (searchText.getText().length() > 0) { String tmp = searchText.getText().toString(); try { tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8); } catch (UnsupportedEncodingException ignored) { } final String text = tmp; switch (radioGroup.getCheckedRadioButtonId()) { case R.id.byWebSearch: 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) { return new GetFeedSearchResultsLoader(EditFeedActivity.this, text); } @Override public void onLoadFinished( Loader<ArrayList<HashMap<String, String>>> loader, final ArrayList<HashMap<String, String>> data) { pd.cancel(); if (data == null) { Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show(); } else if (data.isEmpty()) { Toast.makeText(EditFeedActivity.this, R.string.no_result, Toast.LENGTH_SHORT).show(); } 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) { mNameEditText.setText(data.get(which) .get(FEED_SEARCH_TITLE)); mUrlEditText.setText(data.get(which) .get(FEED_SEARCH_URL)); } }); builder.show(); } } @Override public void onLoaderReset( Loader<ArrayList<HashMap<String, String>>> loader) { } }); break; case R.id.byTopic: mUrlEditText.setText("http://www.faroo.com/api?q=" + text + "&start=1&length=10&l=en&src=news&f=rss"); break; case R.id.byYoutube: mUrlEditText.setText("http://www.youtube.com/rss/user/" + text.replaceAll("\\+", "") + "/videos.rss"); break; } } } }).setNegativeButton(android.R.string.cancel, null).show(); return true; } default: return super.onOptionsItemSelected(item); } }
From source file:com.app.uafeed.activity.EditFeedActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish();//w w w . j a v a2 s. c om 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()); 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; } case R.id.menu_search_feed: { final View dialogView = getLayoutInflater().inflate(R.layout.dialog_search_feed, null); final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText); if (!mUrlEditText.getText().toString().startsWith(Constants.HTTP_SCHEME) && !mUrlEditText.getText().toString().startsWith(Constants.HTTPS_SCHEME)) { searchText.setText(mUrlEditText.getText()); } final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup); new AlertDialog.Builder(EditFeedActivity.this) // .setIcon(R.drawable.action_search) // .setTitle(R.string.feed_search) // .setView(dialogView) // .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (searchText.getText().length() > 0) { String tmp = searchText.getText().toString(); try { tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8); } catch (UnsupportedEncodingException ignored) { } final String text = tmp; switch (radioGroup.getCheckedRadioButtonId()) { case R.id.byWebSearch: 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) { return new GetFeedSearchResultsLoader(EditFeedActivity.this, text); } @Override public void onLoadFinished( Loader<ArrayList<HashMap<String, String>>> loader, final ArrayList<HashMap<String, String>> data) { pd.cancel(); if (data == null) { Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show(); } else if (data.isEmpty()) { Toast.makeText(EditFeedActivity.this, R.string.no_result, Toast.LENGTH_SHORT).show(); } 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) { mNameEditText.setText(data.get(which) .get(FEED_SEARCH_TITLE)); mUrlEditText.setText(data.get(which) .get(FEED_SEARCH_URL)); } }); builder.show(); } } @Override public void onLoaderReset( Loader<ArrayList<HashMap<String, String>>> loader) { } }); break; case R.id.byTopic: mUrlEditText.setText("http://www.faroo.com/api?q=" + text + "&start=1&length=10&l=en&src=news&f=rss"); break; case R.id.byYoutube: mUrlEditText.setText("http://www.youtube.com/rss/user/" + text.replaceAll("\\+", "") + "/videos.rss"); break; } } } }).setNegativeButton(android.R.string.cancel, null).show(); return true; } default: return super.onOptionsItemSelected(item); } }
From source file:th.in.ffc.person.visit.VisitDiagActivity.java
private void insertRadiusDetail() { String where = "visitno=?"; String[] selectionArgs = { visitno }; ContentValues conValues = new ContentValues(); conValues.put("visitno", visitno); conValues.put("radius", RADIUS_DEFAULT); conValues.put("colorcode", COLORCODE_DEFAULT); conValues.put("level", LEVEL_DEFALUT); ContentResolver cr = getContentResolver(); int update = cr.update(FFC506RADIUS.CONTENT_URI, conValues, where, selectionArgs); if (update < 1) { cr.insert(FFC506RADIUS.CONTENT_URI, conValues); }/*from w w w. j a va 2 s . co m*/ }
From source file:com.bt.download.android.gui.UniversalScanner.java
private void scanDocument(String filePath) { File file = new File(filePath); if (documentExists(filePath, file.length())) { return;/*from w w w. j a v a2 s . c o m*/ } String displayName = FilenameUtils.getBaseName(file.getName()); ContentResolver cr = context.getContentResolver(); ContentValues values = new ContentValues(); values.put(DocumentsColumns.DATA, filePath); values.put(DocumentsColumns.SIZE, file.length()); values.put(DocumentsColumns.DISPLAY_NAME, displayName); values.put(DocumentsColumns.TITLE, displayName); values.put(DocumentsColumns.DATE_ADDED, System.currentTimeMillis()); values.put(DocumentsColumns.DATE_MODIFIED, file.lastModified()); values.put(DocumentsColumns.MIME_TYPE, UIUtils.getMimeType(filePath)); Uri uri = cr.insert(Documents.Media.CONTENT_URI, values); FileDescriptor fd = new FileDescriptor(); fd.fileType = Constants.FILE_TYPE_DOCUMENTS; fd.id = Integer.valueOf(uri.getLastPathSegment()); shareFinishedDownload(fd); }
From source file:no.digipost.android.gui.metadata.AppointmentView.java
private void addToCalendar(Metadata appointment) { String description = appointment.subTitle + "\n\n" + appointment.getInfoTitleAndText(); Calendar beginTime = Calendar.getInstance(); beginTime.setTime(appointment.getStartDate()); Calendar endTime = Calendar.getInstance(); endTime.setTime(appointment.getEndDate()); ContentResolver cr = getActivity().getContentResolver(); ContentValues values = new ContentValues(); values.put(CalendarContract.Events.DTSTART, beginTime.getTimeInMillis()); values.put(CalendarContract.Events.DTEND, endTime.getTimeInMillis()); values.put(CalendarContract.Events.TITLE, appointment.title); values.put(CalendarContract.Events.EVENT_LOCATION, appointment.getPlaceAddress() + " - " + appointment.getPlace()); values.put(CalendarContract.Events.DESCRIPTION, description); values.put(CalendarContract.Events.EVENT_TIMEZONE, beginTime.getTimeZone().toString()); values.put(CalendarContract.Events.CALENDAR_ID, 1); Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values); }
From source file:com.noshufou.android.su.AppDetailsFragment.java
private void doToggle() { ContentResolver cr = getActivity().getContentResolver(); Uri uri = Uri.withAppendedPath(Apps.CONTENT_URI, String.valueOf(mShownIndex)); ContentValues values = new ContentValues(); values.put(Apps.ALLOW, mAllow == 1 ? 0 : 1); cr.update(uri, values, null, null);//from ww w . j a va2 s.c o m // Update the log values.clear(); values.put(Logs.DATE, System.currentTimeMillis()); values.put(Logs.TYPE, Logs.LogType.TOGGLE); cr.insert(Uri.withAppendedPath(Logs.CONTENT_URI, String.valueOf(mShownIndex)), values); Intent intent = new Intent(getActivity(), ResultService.class); intent.putExtra(ResultService.EXTRA_ACTION, ResultService.ACTION_RECYCLE); getActivity().startService(intent); }
From source file:com.stoneapp.ourvlemoodle2.tasks.EventSync.java
public void addCalendarEvent(MoodleEvent event) { Calendar cal = Calendar.getInstance(); Uri EVENTS_URI = Uri.parse("content://com.android.calendar/" + "events"); //creates a new uri for calendar ContentResolver cr = context.getContentResolver(); // event insert ContentValues values = new ContentValues(); values.put("calendar_id", 1); values.put("_id", event.getEventid()); values.put("title", event.getName()); values.put("allDay", 0); values.put("dtstart", (long) event.getTimestart() * 1000); values.put("dtend", (long) event.getTimestart() * 1000 + ((long) event.getTimeduration() * 1000)); values.put("description", Html.fromHtml(event.getDescription()).toString().trim()); values.put("hasAlarm", 1); values.put("eventTimezone", "UTC/GMT -5:00"); Uri calevent = cr.insert(EVENTS_URI, values); // reminder insert Uri REMINDERS_URI = Uri.parse("content://com.android.calendar/" + "reminders"); values = new ContentValues(); ContentValues values2 = new ContentValues(); ContentValues values3 = new ContentValues(); values.put("event_id", Long.parseLong(calevent.getLastPathSegment())); values.put("method", 1); values.put("minutes", 10); values2.put("event_id", Long.parseLong(calevent.getLastPathSegment())); values2.put("method", 1); values2.put("minutes", 60); values3.put("event_id", Long.parseLong(calevent.getLastPathSegment())); values3.put("method", 1); values3.put("minutes", 60 * 24); cr.insert(REMINDERS_URI, values); cr.insert(REMINDERS_URI, values2); cr.insert(REMINDERS_URI, values3); }
From source file:com.jefftharris.passwdsafe.file.PasswdFileUri.java
/** Create a new children file URI */ public PasswdFileUri createNewChild(String fileName, Context ctx) throws IOException { switch (itsType) { case FILE: {//from ww w . ja v a 2s. com File file = new File(itsFile, fileName); return new PasswdFileUri(file); } case SYNC_PROVIDER: { ContentResolver cr = ctx.getContentResolver(); ContentValues values = new ContentValues(); values.put(PasswdSafeContract.Files.COL_TITLE, fileName); Uri childUri = cr.insert(itsUri, values); return new PasswdFileUri(childUri, ctx); } case EMAIL: case GENERIC_PROVIDER: { break; } } throw new IOException("Can't create child \"" + fileName + "\" for URI " + toString()); }
From source file:com.rjfun.cordova.sms.SMSPlugin.java
private PluginResult restoreSMS(JSONArray array, CallbackContext callbackContext) { ContentResolver resolver = this.cordova.getActivity().getContentResolver(); Uri uri = Uri.parse(SMS_URI_INBOX); int n = array.length(); int m = 0;/* w ww.j a v a 2 s . com*/ for (int i = 0; i < n; ++i) { JSONObject json; if ((json = array.optJSONObject(i)) == null) continue; String str = json.toString(); Log.d(LOGTAG, str); Uri newuri = resolver.insert(uri, this.getContentValuesFromJson(json)); Log.d(LOGTAG, ("inserted: " + newuri.toString())); ++m; } if (callbackContext != null) { callbackContext.success(m); } return null; }
From source file:cz.maresmar.sfm.view.portal.PortalDetailFragment.java
@NonNull @Override//from www . ja v a2 s. c o m public Uri saveData() { Timber.i("Saving portal 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.Portal.NAME, mNameText.getText().toString()); values.put(ProviderContract.Portal.REFERENCE, mRefText.getText().toString()); values.put(ProviderContract.Portal.PLUGIN, getSelectedPluginId()); int[] ids = getResources().getIntArray(R.array.connection_security_ids); int selectedId = ids[mSecuritySpinner.getSelectedItemPosition()]; values.put(ProviderContract.Portal.SECURITY, selectedId); if (mLocation != null) { values.put(ProviderContract.Portal.LOC_N, mLocation.latitude); values.put(ProviderContract.Portal.LOC_E, mLocation.longitude); } values.put(ProviderContract.Portal.EXTRA, getExtraData()); // New menu notification @ProviderContract.PortalFlags int flags; if (mNewMenuNotificationCheckBox.isChecked()) { flags = 0; } else { flags = ProviderContract.PORTAL_FLAG_DISABLE_NEW_MENU_NOTIFICATION; } values.put(ProviderContract.Portal.FLAGS, flags); //noinspection ConstantConditions ContentResolver contentResolver = getContext().getContentResolver(); if (mPortalUri == null) { // Ads new portal group mPortalGroupTempUri = contentResolver.insert(ProviderContract.PortalGroup.getUri(), null); //noinspection ConstantConditions long portalGroupId = Long.parseLong(mPortalGroupTempUri.getLastPathSegment()); // Ads portal group to values values.put(ProviderContract.Portal.PORTAL_GROUP_ID, portalGroupId); // Insert them mPortalTempUri = contentResolver.insert(ProviderContract.Portal.getUri(), values); mPortalUri = mPortalTempUri; } else { int updatedRows = contentResolver.update(mPortalUri, values, null, null); if (BuildConfig.DEBUG) { Assert.isOne(updatedRows); } } return mPortalUri; }