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:org.ohmage.streams.StreamPointBuilder.java
/** * Send this point to ohmage.//from w ww . j av a 2 s. co m * <p/> * If you have many points to send within a few milliseconds of each * other, you will get better performance by calling {@link #write(StreamWriter)} or * {@link #writeAsync(AsyncBulkInsertHandler)}. * <p/> * This call will block until the point has been saved in ohmage. * * @param resolver a {@link ContentResolver} that is used to save the point */ public void write(ContentResolver resolver) { buildMetaData(); if (StreamContract.checkContentProviderExists(resolver)) resolver.insert(StreamContract.Streams.CONTENT_URI, toContentValues()); }
From source file:com.antew.redditinpictures.library.reddit.AboutResponse.java
@Override public void processHttpResponse(Context context) { Ln.v("About Subreddit complete! = %s", result.getJson()); About aboutSubreddit = JsonDeserializer.deserialize(result.getJson(), About.class); if (aboutSubreddit == null) { Ln.e("Something went wrong on About Subreddit status code: %d json: %s", result.getHttpStatusCode(), result.getJson());// w ww.j ava 2 s . c o m return; } ContentResolver resolver = context.getContentResolver(); //TODO: Once API-11 is sunset, replace with an update instead of delete/insert. // Updates with parameters aren't supported prior to API-11 (Honeycomb). So instead we are just deleting the record if it exists and recreating it. resolver.delete(RedditContract.Subreddits.CONTENT_URI, "subredditId = ?", new String[] { aboutSubreddit.getData().getId() }); Ln.v("Deleted row"); resolver.insert(RedditContract.Subreddits.CONTENT_URI, aboutSubreddit.getContentValues()); Ln.v("Inserted row"); LocalBroadcastManager.getInstance(context) .sendBroadcast(new Intent(Constants.Broadcast.BROADCAST_ABOUT_SUBREDDIT)); }
From source file:org.mariotaku.twidere.fragment.support.SearchFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true);//from w ww . j a v a2s. c om final Bundle args = getArguments(); final FragmentActivity activity = getActivity(); mPagerAdapter = new SupportTabsAdapter(activity, getChildFragmentManager(), null, 1); mPagerAdapter.addTab(StatusesSearchFragment.class, args, getString(R.string.statuses), R.drawable.ic_action_twitter, 0, null); mPagerAdapter.addTab(SearchUsersFragment.class, args, getString(R.string.users), R.drawable.ic_action_user, 1, null); mViewPager.setAdapter(mPagerAdapter); mViewPager.setOffscreenPageLimit(2); mPagerIndicator.setViewPager(mViewPager); mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL); mPagerIndicator.setOnPageChangeListener(this); ThemeUtils.initPagerIndicatorAsActionBarTab(activity, mPagerIndicator, mPagerWindowOverlay); ThemeUtils.setCompatToolbarOverlay(activity, new EmptyDrawable()); ThemeUtils.setCompatContentViewOverlay(activity, new EmptyDrawable()); ThemeUtils.setWindowOverlayViewOverlay(activity, new EmptyDrawable()); if (activity instanceof IThemedActivity) { final String backgroundOption = ((IThemedActivity) activity).getCurrentThemeBackgroundOption(); final boolean isTransparent = ThemeUtils.isTransparentBackground(backgroundOption); final int actionBarAlpha = isTransparent ? ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(activity)) : 0xFF; mPagerIndicator.setAlpha(actionBarAlpha / 255f); } if (savedInstanceState == null && args != null && args.containsKey(EXTRA_QUERY)) { final String query = args.getString(EXTRA_QUERY); final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(), RecentSearchProvider.AUTHORITY, RecentSearchProvider.MODE); suggestions.saveRecentQuery(query, null); final ContentResolver cr = getContentResolver(); final ContentValues values = new ContentValues(); values.put(SearchHistory.QUERY, query); cr.insert(SearchHistory.CONTENT_URI, values); if (activity instanceof LinkHandlerActivity) { final ActionBar ab = activity.getActionBar(); if (ab != null) { ab.setSubtitle(query); } } } updateTabOffset(); }
From source file:com.akop.bach.parser.PsnParser.java
public void createAccount(BasicAccount account, ContentValues cv) { // Add profile to database ContentResolver cr = mContext.getContentResolver(); cr.insert(Profiles.CONTENT_URI, cv); cr.notifyChange(Profiles.CONTENT_URI, null); PsnAccount psnAccount = (PsnAccount) account; // Save changes to preferences psnAccount.setOnlineId(cv.getAsString(Profiles.ONLINE_ID)); psnAccount.setIconUrl(cv.getAsString(Profiles.ICON_URL)); psnAccount.setLastSummaryUpdate(System.currentTimeMillis()); account.save(Preferences.get(mContext)); }
From source file:com.amrutpatil.makeanote.NotesActivity.java
private void moveToTrash() { ContentValues contentValues = new ContentValues(); TextView title = (TextView) findViewById(R.id.title_note_custom_home); TextView description = (TextView) findViewById(R.id.description_note_custom_home); TextView dateTime = (TextView) findViewById(R.id.date_time_note_custom_home); contentValues.put(TrashContract.TrashColumns.TRASH_TITLE, title.getText().toString()); contentValues.put(TrashContract.TrashColumns.TRASH_DESCRIPTION, description.getText().toString()); contentValues.put(TrashContract.TrashColumns.TRASH_DATE_TIME, dateTime.getText().toString()); ContentResolver cr = this.getContentResolver(); Uri uri = TrashContract.URI_TABLE; cr.insert(uri, contentValues); }
From source file:com.ultramegatech.ey.UpdateService.java
@Override protected void onHandleIntent(Intent intent) { if (!HttpHelper.isConnected(this)) { return;//w ww. ja v a 2s .c o m } final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final long lastCheck = preferences.getLong(KEY_LAST_CHECK, 0); final long now = System.currentTimeMillis(); if (now - lastCheck < CHECK_INTERVAL) { return; } Log.v(TAG, "Checking for updates"); final int version = preferences.getInt(KEY_VERSION, 0); final int newVersion = HttpHelper.getVersion(); if (newVersion > version) { Log.v(TAG, "Downloading updates..."); final ContentValues[] valuesArray = fetchElementData(newVersion); if (valuesArray == null) { return; } final ContentResolver cr = getContentResolver(); Uri uri; int changed; for (int i = 0; i < valuesArray.length; i++) { uri = ContentUris.withAppendedId(Elements.CONTENT_URI_NUMBER, valuesArray[i].getAsLong(Elements.NUMBER)); changed = cr.update(uri, valuesArray[i], null, null); if (changed == 0) { cr.insert(Elements.CONTENT_URI, valuesArray[i]); } } preferences.edit().putInt(KEY_VERSION, newVersion).commit(); Log.v(TAG, "Update completed successfully"); } preferences.edit().putLong(KEY_LAST_CHECK, System.currentTimeMillis()).commit(); }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static void updateNode(ContentResolver contentResolver, U1Node node, String data) { final String resourcePath = node.getResourcePath(); final boolean isDirectory = node.getKind() == U1NodeKind.DIRECTORY; if (!isDirectory && ((U1File) node).getSize() == null) { // Ignore files with null size. return;/* w w w. j av a 2 s . co m*/ } ContentValues values = Nodes.valuesFromRepr(node, data); String selection = Nodes.NODE_KEY + "=?"; String[] selectionArgs = new String[] { node.getKey() }; if (node.getIsLive()) { int updated = contentResolver.update(Nodes.CONTENT_URI, values, selection, selectionArgs); if (updated == 0) { boolean isNonEmptyFile = !isDirectory && ((U1File) node).getSize() != null; if (isDirectory || isNonEmptyFile) { contentResolver.insert(Nodes.CONTENT_URI, values); } } } else { if (node.getKind() == U1NodeKind.FILE) { FileUtilities.removeSilently(FileUtilities.getFilePathFromResourcePath(resourcePath)); } MetaUtilities.deleteByResourcePath(resourcePath); } MetaUtilities.notifyChange(Nodes.CONTENT_URI); }
From source file:com.textuality.lifesaver.Restorer.java
private int restore(BufferedReader file, HashMap<String, Boolean> logged, Columns r, Uri uri, ProgressBar progress, String zeroField, int total) throws Exception { int added = 0; ContentResolver cr = getContentResolver(); int count = 0; String line;/*ww w.jav a 2 s. co m*/ float denominator = ((float) total) / 100.0F; while ((line = file.readLine()) != null) { JSONObject json = new JSONObject(line); String key = r.jsonToKey(json); if (logged.get(key) == null) { ContentValues cv = r.jsonToContentValues(json); if (zeroField != null) cv.put(zeroField, 0); cr.insert(uri, cv); added++; } count += 1; progress.setProgress((int) (count / denominator)); } file.close(); return added; }
From source file:com.amrutpatil.makeanote.NotesActivity.java
private void moveToArchive(View view, int position) { ContentValues contentValues = new ContentValues(); TextView title = (TextView) findViewById(R.id.title_note_custom_home); TextView description = (TextView) findViewById(R.id.description_note_custom_home); TextView dateTime = (TextView) findViewById(R.id.date_time_note_custom_home); LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.home_list); int isList = linearLayout.getVisibility(); String listDescription = ""; if (isList == View.VISIBLE) { //If a note contains list of items NoteCustomList noteCustomList = (NoteCustomList) linearLayout.getChildAt(0); listDescription = noteCustomList.getLists(); // for(int i = 0 ; i < noteCustomList.getChildCount(); i++){ // LinearLayout first = (LinearLayout) linearLayout.getChildAt(i); // CheckBox checkBox = (CheckBox) first.getChildAt(0); // TextView textView = (TextView) first.getChildAt(1); // listDescription = description + textView.toString() + checkBox.isChecked() + "%"; // } contentValues.put(ArchivesContract.ArchivesColumns.ARCHIVES_TYPE, AppConstant.LIST); } else {//from w w w.j av a 2s . c o m listDescription = description.getText().toString(); contentValues.put(ArchivesContract.ArchivesColumns.ARCHIVES_TYPE, AppConstant.NORMAL); } contentValues.put(ArchivesContract.ArchivesColumns.ARCHIVES_DESCRIPTION, listDescription); contentValues.put(ArchivesContract.ArchivesColumns.ARCHIVES_TITLE, title.getText().toString()); contentValues.put(ArchivesContract.ArchivesColumns.ARCHIVES_DATE_TIME, dateTime.getText().toString()); contentValues.put(ArchivesContract.ArchivesColumns.ARCHIVES_CATEGORY, mTitle); ContentResolver cr = this.getContentResolver(); Uri uri = ArchivesContract.URI_TABLE; cr.insert(uri, contentValues); delete(view, position); }
From source file:com.slp.rss_api.activity.EditFeedActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish();// w ww . j av a2 s . c o m 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); } }