List of usage examples for android.content ContentResolver update
public final int update(@RequiresPermission.Write @NonNull Uri uri, @Nullable ContentValues values, @Nullable String where, @Nullable String[] selectionArgs)
From source file:org.wheelmap.android.fragment.FilterCategoriesFragment.java
private void clickCategorieItem(Cursor cursor) { int catId = Support.CategoriesContent.getCategoryId(cursor); boolean selected = Support.CategoriesContent.getSelected(cursor); ContentResolver resolver = getActivity().getContentResolver(); ContentValues values = new ContentValues(); if (selected) { values.put(Support.CategoriesContent.SELECTED, Support.CategoriesContent.SELECTED_NO); } else {//from www . j a va2 s . co m values.put(Support.CategoriesContent.SELECTED, Support.CategoriesContent.SELECTED_YES); } String whereClause = "( " + Support.CategoriesContent.CATEGORY_ID + " = ?)"; String[] whereValues = new String[] { Integer.toString(catId) }; resolver.update(mUri, values, whereClause, whereValues); Log.d(TAG, "Name = " + Support.CategoriesContent.getLocalizedName(cursor)); }
From source file:com.alchemiasoft.book.service.BookActionService.java
@Override protected void onHandleIntent(Intent intent) { final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, NOT_VALID_NOTIFICATION); // Cancelling any shown notification if (notificationId != NOT_VALID_NOTIFICATION) { Log.d(TAG_LOG, "Dismissing notification with id=" + notificationId); NotificationManagerCompat.from(this).cancel(notificationId); }//from ww w. ja va 2 s . c o m final long bookId = intent.getLongExtra(EXTRA_BOOK_ID, NOT_VALID_BOOK); if (bookId != NOT_VALID_BOOK) { final ContentResolver cr = getContentResolver(); final Action action = Action.valueOf(intent.getAction()); Log.d(TAG_LOG, "Performing action=" + action + " on book with id=" + bookId); final ContentValues cv = new ContentValues(); switch (action) { case BUY: cv.put(BookDB.Book.OWNED, 1); if (cr.update(BookDB.Book.create(bookId), cv, null, null) == 1 && intent.getBooleanExtra(EXTRA_WEARABLE_INPUT, false)) { final Book book = getBook(bookId); if (book != null) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true) .setContentTitle(getString(R.string.book_purchased)) .setContentText(book.getTitle()); builder.setContentIntent(PendingIntent.getActivity(this, 0, HomeActivity.createFor(this, book), PendingIntent.FLAG_UPDATE_CURRENT)); // ONLY 4 WEARABLE(s) final NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); wearableExtender .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.background)); // ACTION TO SELL A BOOK FROM A WEARABLE final PendingIntent sellIntent = PendingIntent.getService( this, 0, BookActionService.IntentBuilder.sell(this, book) .notificationId(NOTIFICATION_ID).wearableInput().build(), PendingIntent.FLAG_UPDATE_CURRENT); wearableExtender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_action_sell, getString(R.string.action_sell), sellIntent).build()); // Finally extending the notification builder.extend(wearableExtender); NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, builder.build()); } } break; case SELL: cv.put(BookDB.Book.OWNED, 0); if (cr.update(BookDB.Book.create(bookId), cv, null, null) == 1 && intent.getBooleanExtra(EXTRA_WEARABLE_INPUT, false)) { final Book book = getBook(bookId); if (book != null) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true) .setContentTitle(getString(R.string.book_sold)).setContentText(book.getTitle()); builder.setContentIntent(PendingIntent.getActivity(this, 0, HomeActivity.createFor(this, book), PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, builder.build()); } } break; case ADD_NOTE: final CharSequence notes = getExtraNotes(intent); if (!TextUtils.isEmpty(notes)) { cv.put(BookDB.Book.NOTES, notes.toString()); cr.update(BookDB.Book.create(bookId), cv, null, null); } break; default: break; } } }
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); // Update the log values.clear();/* w ww . j av a 2 s . c o m*/ 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:de.ub0r.android.callmeter.data.RuleMatcher.java
public static void resetAlert(final Context context) { Log.d(TAG, "resetAlert()"); ContentValues cv = new ContentValues(); final ContentResolver cr = context.getContentResolver(); cv.put(DataProvider.Plans.NEXT_ALERT, 0); cr.update(DataProvider.Plans.CONTENT_URI, cv, null, null); flush();//from w w w . j a v a 2 s . co m }
From source file:org.xwalk.runtime.extension.api.messaging.MessagingManager.java
private void operation(int instanceID, JSONObject jsonMsg) { JSONObject eventBody = null;/*from w w w . j av a2 s . com*/ String promise_id = null, msgType = null, id = null, cmd = null; boolean isRead = false; try { promise_id = jsonMsg.getString("_promise_id"); eventBody = jsonMsg.getJSONObject("data"); if (eventBody.has("messageID")) { id = eventBody.getString("messageID"); } else { id = eventBody.getString("conversationID"); } cmd = jsonMsg.getString("cmd"); if (eventBody.has("value")) { isRead = eventBody.getBoolean("value"); } msgType = eventBody.getString("type"); } catch (JSONException e) { e.printStackTrace(); return; } String selString = null; if (eventBody.has("messageID")) { selString = String.format("%s = ?", MessagingSmsConsts.ID); } else { selString = String.format("%s = ?", MessagingSmsConsts.THREAD_ID); } String[] selArgs = new String[] { id }; ContentResolver cr = mMainActivity.getContentResolver(); Uri contentUri = getUri(msgType); if (cmd.equals("msg_deleteMessage") || cmd.equals("msg_deleteConversation")) { cr.delete(contentUri, selString, selArgs); } else if (cmd.equals("msg_markMessageRead") || cmd.equals("msg_markConversationRead")) { ContentValues values = new ContentValues(); values.put("read", isRead ? "1" : "0"); cr.update(contentUri, values, selString, selArgs); } JSONObject jsonMsgRet = null; try { jsonMsgRet = new JSONObject(); jsonMsgRet.put("_promise_id", promise_id); JSONObject jsData = new JSONObject(); jsonMsgRet.put("data", jsData); jsData.put("error", false); JSONObject jsBody = new JSONObject(); jsData.put("body", jsBody); if (eventBody.has("messageID")) { jsBody.put("messageID", id); } else { jsBody.put("conversationID", id); } jsonMsgRet.put("cmd", cmd + "_ret"); } catch (JSONException e) { e.printStackTrace(); return; } mMessagingHandler.postMessage(instanceID, jsonMsgRet.toString()); }
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 . ja v a 2s .c om*/ } 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)); } }
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 www . j av a2 s . c o m*/ }
From source file:com.technoxist.fragment.EntryFragment.java
private void refreshUI(Cursor entryCursor) { if (entryCursor != null) { String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos) : entryCursor.getString(mFeedNamePos); BaseActivity activity = (BaseActivity) getActivity(); activity.setTitle(feedTitle);// w w w . ja va2 s.c o m byte[] iconBytes = entryCursor.getBlob(mFeedIconPos); Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24); if (bitmap != null) { activity.getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } else { activity.getActionBar().setIcon(R.drawable.icon); } mFavorite = entryCursor.getInt(mIsFavoritePos) == 1; activity.invalidateOptionsMenu(); // Listen the mobilizing task if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) { hideSwipeProgress(); // Start services here if not already started to avoid an infinite loading if (!PrefUtils.getBoolean(PrefUtils.IS_REFRESHING, false)) { MainApplication.getContext() .startService(new Intent(MainApplication.getContext(), FetcherService.class) .setAction(FetcherService.ACTION_MOBILIZE_FEEDS)); } } else { hideSwipeProgress(); } // Mark the article as read if (entryCursor.getInt(mIsReadPos) != 1) { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread(new Runnable() { @Override public void run() { ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, FeedData.getReadContentValues(), null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }).start(); } } }
From source file:com.app.uafeed.fragment.EntryFragment.java
private void refreshUI(Cursor entryCursor) { if (entryCursor != null) { String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos) : entryCursor.getString(mFeedNamePos); BaseActivity activity = (BaseActivity) getActivity(); activity.setTitle(feedTitle);//from ww w . j a v a 2s.com byte[] iconBytes = entryCursor.getBlob(mFeedIconPos); Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24); if (bitmap != null) { activity.getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } else { activity.getActionBar().setIcon(R.drawable.icon); } mFavorite = entryCursor.getInt(mIsFavoritePos) == 1; activity.invalidateOptionsMenu(); // Listen the mobilizing task boolean isRefreshing = FetcherService.hasTasks(mEntriesIds[mCurrentPagerPos]); activity.getProgressBar().setVisibility(isRefreshing ? View.VISIBLE : View.GONE); // Mark the article as read if (entryCursor.getInt(mIsReadPos) != 1) { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread(new Runnable() { @Override public void run() { ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, FeedData.getReadContentValues(), null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }).start(); } } }
From source file:com.bangz.smartmute.RulelistFragment.java
@Override public void onActivedButtonClick(long id, boolean bActivited) { //Cursor cursor = mAdapter.getCursor(); LogUtils.LOGD(TAG, "Activited Button clicked. id: " + id + " Activited: " + bActivited); ContentResolver cr = getActivity().getContentResolver(); Uri uri = ContentUris.withAppendedId(RulesColumns.CONTENT_URI, id); String[] projects = { RulesColumns.RULETYPE };//from w ww . ja v a 2s . co m Cursor cursor = cr.query(uri, projects, null, null, null); cursor.moveToFirst(); int ruletype = cursor.getInt(cursor.getColumnIndex(RulesColumns.RULETYPE)); ContentValues contentValues = new ContentValues(); contentValues.put(RulesColumns.ACTIVATED, bActivited ? 1 : 0); cr.update(uri, contentValues, null, null); mAdapter.notifyDataSetChanged(); if (ruletype == RulesColumns.RT_TIME) { if (bActivited == false) TimeRuleAlarmService.cancelScheduledAlarm(getActivity(), uri); else TimeRuleAlarmService.startScheduleAlarm(getActivity(), uri); } else if (ruletype == RulesColumns.RT_LOCATION) { //TODO cancel location mute } }