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:com.todoroo.astrid.gcal.GCalControlSet.java
@Override protected void writeToModelAfterInitialized(Task task) { if (!task.hasDueDate()) { return;/*from w w w .j a v a 2 s .c o m*/ } if ((gcal.isDefaultCalendarSet() || calendarSelector.getSelectedItemPosition() != 0) && calendarUri == null) { try { ContentResolver cr = activity.getContentResolver(); ContentValues values = new ContentValues(); String calendarId = calendars.calendarIds[calendarSelector.getSelectedItemPosition() - 1]; values.put("calendar_id", calendarId); calendarUri = gcal.createTaskEvent(task, cr, values); if (calendarUri != null) { task.setCalendarUri(calendarUri.toString()); if (calendarSelector.getSelectedItemPosition() != 0 && !hasEvent) { // pop up the new event Intent intent = new Intent(Intent.ACTION_VIEW, calendarUri); intent.putExtra("beginTime", values.getAsLong("dtstart")); intent.putExtra("endTime", values.getAsLong("dtend")); activity.startActivity(intent); } } } catch (Exception e) { log.error(e.getMessage(), e); } } else if (calendarUri != null) { try { ContentValues updateValues = new ContentValues(); // check if we need to update the item ContentValues setValues = task.getSetValues(); if (setValues.containsKey(Task.TITLE.name)) { updateValues.put("title", task.getTitle()); } if (setValues.containsKey(Task.NOTES.name)) { updateValues.put("description", task.getNotes()); } if (setValues.containsKey(Task.DUE_DATE.name) || setValues.containsKey(Task.ESTIMATED_SECONDS.name)) { gcal.createStartAndEndDate(task, updateValues); } ContentResolver cr = activity.getContentResolver(); cr.update(calendarUri, updateValues, null, null); } catch (Exception e) { log.error("unable-to-update-calendar: " + task.getCalendarURI(), e); } } }
From source file:com.android.mail.NotificationActionIntentService.java
@Override protected void onHandleIntent(final Intent intent) { final Context context = this; final String action = intent.getAction(); /*//from w w w. j av a2s . c o m * Grab the alarm from the intent. Since the remote AlarmManagerService fills in the Intent * to add some extra data, it must unparcel the NotificationAction object. It throws a * ClassNotFoundException when unparcelling. * To avoid this, do the marshalling ourselves. */ final NotificationAction notificationAction; final byte[] data = intent.getByteArrayExtra(EXTRA_NOTIFICATION_ACTION); if (data != null) { final Parcel in = Parcel.obtain(); in.unmarshall(data, 0, data.length); in.setDataPosition(0); notificationAction = NotificationAction.CREATOR.createFromParcel(in, NotificationAction.class.getClassLoader()); } else { LogUtils.wtf(LOG_TAG, "data was null trying to unparcel the NotificationAction"); return; } final Message message = notificationAction.getMessage(); final ContentResolver contentResolver = getContentResolver(); LogUtils.i(LOG_TAG, "Handling %s", action); logNotificationAction(action, notificationAction); if (notificationAction.getSource() == NotificationAction.SOURCE_REMOTE) { // Skip undo if the action is bridged from remote node. This should be similar to the // logic after the Undo notification expires in a regular flow. LogUtils.d(LOG_TAG, "Canceling %s", notificationAction.getNotificationId()); NotificationManagerCompat.from(context).cancel(notificationAction.getNotificationId()); NotificationActionUtils.processDestructiveAction(this, notificationAction); NotificationActionUtils.resendNotifications(context, notificationAction.getAccount(), notificationAction.getFolder()); return; } if (ACTION_UNDO.equals(action)) { NotificationActionUtils.cancelUndoTimeout(context, notificationAction); NotificationActionUtils.cancelUndoNotification(context, notificationAction); } else if (ACTION_ARCHIVE_REMOVE_LABEL.equals(action) || ACTION_DELETE.equals(action)) { // All we need to do is switch to an Undo notification NotificationActionUtils.createUndoNotification(context, notificationAction); NotificationActionUtils.registerUndoTimeout(context, notificationAction); } else { if (ACTION_UNDO_TIMEOUT.equals(action) || ACTION_DESTRUCT.equals(action)) { // Process the action NotificationActionUtils.cancelUndoTimeout(this, notificationAction); NotificationActionUtils.processUndoNotification(this, notificationAction); } else if (ACTION_MARK_READ.equals(action)) { final Uri uri = message.uri; final ContentValues values = new ContentValues(1); values.put(UIProvider.MessageColumns.READ, 1); contentResolver.update(uri, values, null, null); } NotificationActionUtils.resendNotifications(context, notificationAction.getAccount(), notificationAction.getFolder()); } }
From source file:com.android.contacts.ContactSaveService.java
private void updateGroup(Intent intent) { long groupId = intent.getLongExtra(EXTRA_GROUP_ID, -1); String label = intent.getStringExtra(EXTRA_GROUP_LABEL); long[] rawContactsToAdd = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_ADD); long[] rawContactsToRemove = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_REMOVE); if (groupId == -1) { Log.e(TAG, "Invalid arguments for updateGroup request"); return;/*from ww w.j a v a 2 s . com*/ } final ContentResolver resolver = getContentResolver(); final Uri groupUri = ContentUris.withAppendedId(Groups.CONTENT_URI, groupId); // Update group name if necessary if (label != null) { ContentValues values = new ContentValues(); values.put(Groups.TITLE, label); resolver.update(groupUri, values, null, null); } // Add and remove members if necessary addMembersToGroup(resolver, rawContactsToAdd, groupId); removeMembersFromGroup(resolver, rawContactsToRemove, groupId); Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT); callbackIntent.setData(groupUri); deliverCallback(callbackIntent); }
From source file:org.zywx.wbpalmstar.plugin.uexcontacts.PFConcactMan.java
public static boolean modify(Context context, String inName, String inNum, String inEmail) { int sdkVersion = Build.VERSION.SDK_INT; ContentResolver contentResolver = context.getContentResolver(); boolean isModify = false; if (sdkVersion < 8) { try {/*from www . j a v a 2 s .c om*/ Cursor cusor = null; String[] projection = new String[] { android.provider.Contacts.People._ID, android.provider.Contacts.People.NAME, android.provider.Contacts.People.NUMBER }; cusor = contentResolver.query(android.provider.Contacts.People.CONTENT_URI, projection, null, null, null); cusor.moveToFirst(); while (cusor.moveToNext()) { String name = cusor.getString(cusor.getColumnIndex(android.provider.Contacts.People.NAME)); String contactName = name;// ?? if (contactName != null && contactName.indexOf(" ") != -1) {// contactName = contactName.replaceAll(" ", ""); name = contactName; } if (name != null && name.equals(inName)) { String id = cusor.getString(cusor.getColumnIndex(android.provider.Contacts.People._ID)); ContentValues values = new ContentValues(); // ??type?????? values.clear(); values.put(android.provider.Contacts.Phones.TYPE, android.provider.Contacts.Phones.TYPE_MOBILE); values.put(android.provider.Contacts.Phones.NUMBER, inNum); String numWhere = android.provider.Contacts.Phones.PERSON_ID + "=? "; String[] numWhereParams = { id }; contentResolver.update(android.provider.Contacts.Phones.CONTENT_URI, values, numWhere, numWhereParams); // ?type????? values.clear(); values.put(android.provider.Contacts.ContactMethods.KIND, android.provider.Contacts.KIND_EMAIL); values.put(android.provider.Contacts.ContactMethods.DATA, inEmail); values.put(android.provider.Contacts.ContactMethods.TYPE, android.provider.Contacts.ContactMethods.TYPE_HOME); String emailWhere = android.provider.Contacts.ContactMethods.PERSON_ID + "=? "; String[] emailWhereParams = { id }; contentResolver.update(android.provider.Contacts.ContactMethods.CONTENT_URI, values, emailWhere, emailWhereParams); isModify = true; } } if (cusor != null) cusor.close(); } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); return false; } } else if (sdkVersion < 14) { try { Cursor cur = contentResolver.query(android.provider.ContactsContract.RawContacts.CONTENT_URI, null, null, null, null); cur.moveToFirst(); while (cur.moveToNext()) { String name = cur .getString(cur.getColumnIndex(android.provider.ContactsContract.Contacts.DISPLAY_NAME)); String id = cur.getString(cur.getColumnIndex(android.provider.ContactsContract.Contacts._ID)); String contactName = name;// ?? if (contactName != null && contactName.indexOf(" ") != -1) {// contactName = contactName.replaceAll(" ", ""); name = contactName; } if (name.equals(inName)) { ContentValues values = new ContentValues(); values.clear(); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER, inNum); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.TYPE, android.provider.ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE); String nameWhere = android.provider.ContactsContract.Data.RAW_CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] nameSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, nameWhere, nameSelection); values.clear(); values.put(android.provider.ContactsContract.Data.RAW_CONTACT_ID, id); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.Email.DATA, inEmail); values.put(android.provider.ContactsContract.CommonDataKinds.Email.TYPE, android.provider.ContactsContract.CommonDataKinds.Email.TYPE_WORK); String emailWhere = android.provider.ContactsContract.Data.RAW_CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] emailSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, emailWhere, emailSelection); isModify = true; } } if (cur != null) cur.close(); } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); } } else { try { Cursor cur = contentResolver.query(android.provider.ContactsContract.RawContacts.CONTENT_URI, null, null, null, null); while (cur.moveToNext()) { String name = cur .getString(cur.getColumnIndex(android.provider.ContactsContract.Contacts.DISPLAY_NAME)); String id = cur.getString(cur.getColumnIndex(android.provider.ContactsContract.Contacts._ID)); String contactName = name;// ?? if (contactName != null && contactName.indexOf(" ") != -1) {// contactName = contactName.replaceAll(" ", ""); name = contactName; } if (name.equals(inName)) { ContentValues values = new ContentValues(); values.clear(); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER, inNum); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.TYPE, android.provider.ContactsContract.PhoneLookup.NUMBER); String nameWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] nameSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, nameWhere, nameSelection); values.clear(); values.put(android.provider.ContactsContract.Data.RAW_CONTACT_ID, id); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.Email.DATA, inEmail); values.put(android.provider.ContactsContract.CommonDataKinds.Email.TYPE, android.provider.ContactsContract.CommonDataKinds.Email.TYPE_WORK); String emailWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] emailSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, emailWhere, emailSelection); isModify = true; break; } } if (cur != null) cur.close(); Cursor cursor = context.getContentResolver() .query(android.provider.ContactsContract.Contacts.CONTENT_URI, null, null, null, null); while (cursor.moveToNext()) { String name = cursor.getString( cursor.getColumnIndex(android.provider.ContactsContract.Contacts.DISPLAY_NAME)); String id = cursor .getString(cursor.getColumnIndex(android.provider.ContactsContract.Contacts._ID)); String contactName = name;// ?? if (contactName != null && contactName.indexOf(" ") != -1) {// contactName = contactName.replaceAll(" ", ""); name = contactName; } if (name.equals(inName)) { ContentValues values = new ContentValues(); values.clear(); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER, inNum); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.TYPE, android.provider.ContactsContract.PhoneLookup.NUMBER); String nameWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] nameSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, nameWhere, nameSelection); values.clear(); values.put(android.provider.ContactsContract.Data.RAW_CONTACT_ID, id); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.Email.DATA, inEmail); values.put(android.provider.ContactsContract.CommonDataKinds.Email.TYPE, android.provider.ContactsContract.CommonDataKinds.Email.TYPE_WORK); String emailWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] emailSelection = new String[] { id, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, emailWhere, emailSelection); isModify = true; break; } } if (cursor != null) cursor.close(); try { Cursor cusor = null; String[] projection = new String[] { android.provider.Contacts.People._ID, android.provider.Contacts.People.NAME, android.provider.Contacts.People.NUMBER }; cusor = contentResolver.query(android.provider.Contacts.People.CONTENT_URI, projection, null, null, null); cusor.moveToFirst(); while (cusor.moveToNext()) { String name = cusor.getString(cusor.getColumnIndex(android.provider.Contacts.People.NAME)); String contactName = name;// ?? if (contactName != null && contactName.indexOf(" ") != -1) {// contactName = contactName.replaceAll(" ", ""); name = contactName; } if (name != null && name.equals(inName)) { String id = cusor.getString(cusor.getColumnIndex(android.provider.Contacts.People._ID)); ContentValues values = new ContentValues(); // ??type?????? values.clear(); values.put(android.provider.Contacts.Phones.TYPE, android.provider.Contacts.Phones.TYPE_MOBILE); values.put(android.provider.Contacts.Phones.NUMBER, inNum); String numWhere = android.provider.Contacts.Phones.PERSON_ID + "=? "; String[] numWhereParams = { id }; contentResolver.update(android.provider.Contacts.Phones.CONTENT_URI, values, numWhere, numWhereParams); // ?type????? values.clear(); values.put(android.provider.Contacts.ContactMethods.KIND, android.provider.Contacts.KIND_EMAIL); values.put(android.provider.Contacts.ContactMethods.DATA, inEmail); values.put(android.provider.Contacts.ContactMethods.TYPE, android.provider.Contacts.ContactMethods.TYPE_HOME); String emailWhere = android.provider.Contacts.ContactMethods.PERSON_ID + "=? "; String[] emailWhereParams = { id }; contentResolver.update(android.provider.Contacts.ContactMethods.CONTENT_URI, values, emailWhere, emailWhereParams); isModify = true; break; } } if (cusor != null) cusor.close(); } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); return false; } } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); } } if (isModify) { ToastShow(context, finder.getString(context, "plugin_contact_modify_succeed")); } else { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); } return isModify; }
From source file:com.ichi2.anki.tests.ContentProviderTest.java
/** * Move all the cards from their old decks to the first deck that was added in setup() *//* ww w .ja v a 2 s .co m*/ public void testMoveCardsToOtherDeck() { final ContentResolver cr = getContext().getContentResolver(); // Query all available notes final Cursor allNotesCursor = cr.query(FlashCardsContract.Note.CONTENT_URI, null, "tag:" + TEST_TAG, null, null); assertNotNull(allNotesCursor); try { assertEquals("Check number of results", mCreatedNotes.size(), allNotesCursor.getCount()); while (allNotesCursor.moveToNext()) { // Now iterate over all cursors Uri cardsUri = Uri.withAppendedPath( Uri.withAppendedPath(FlashCardsContract.Note.CONTENT_URI, allNotesCursor .getString(allNotesCursor.getColumnIndex(FlashCardsContract.Note._ID))), "cards"); final Cursor cardsCursor = cr.query(cardsUri, null, null, null, null); assertNotNull("Check that there is a valid cursor after query for cards", cardsCursor); try { assertTrue("Check that there is at least one result for cards", cardsCursor.getCount() > 0); while (cardsCursor.moveToNext()) { long targetDid = mTestDeckIds[0]; // Move to test deck ContentValues values = new ContentValues(); values.put(FlashCardsContract.Card.DECK_ID, targetDid); Uri cardUri = Uri.withAppendedPath(cardsUri, cardsCursor .getString(cardsCursor.getColumnIndex(FlashCardsContract.Card.CARD_ORD))); cr.update(cardUri, values, null, null); Cursor movedCardCur = cr.query(cardUri, null, null, null, null); assertNotNull("Check that there is a valid cursor after moving card", movedCardCur); assertTrue("Move to beginning of cursor after moving card", movedCardCur.moveToFirst()); long did = movedCardCur .getLong(movedCardCur.getColumnIndex(FlashCardsContract.Card.DECK_ID)); assertEquals("Make sure that card is in new deck", targetDid, did); } } finally { cardsCursor.close(); } } } finally { allNotesCursor.close(); } }
From source file:com.tct.mail.NotificationActionIntentService.java
@Override protected void onHandleIntent(final Intent intent) { final Context context = this; final String action = intent.getAction(); // TS: chao.zhang 2015-09-21 EMAIL FEATURE-585337 ADD_S //NOTE: handle the refresh intent. if (ACTION_REFRESH.equals(action)) { boolean cleanStatus = intent.getBooleanExtra(NotificationUtils.EXTRA_NEED_CLEAN_STATUS, false); long boxId = intent.getLongExtra(NotificationUtils.EXTRA_OUTBOX_ID, -1); //after click the action,cancel the notification. int notificationId = intent.getIntExtra(NotificationUtils.EXTRA_FAIL_NOTIFICATION_ID, 0); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.cancel(notificationId); if (boxId == -1) { LogUtils.e(LOG_TAG,// www . j av a2 s. com "can't find the oubox during handle Intent ACTION_REFRESH in NotificationActionIntentService#onHandleIntent"); return; } Uri refreshUri = intent.getData(); if (cleanStatus && isOutboxNotEmpty(context, boxId)) { // 1.clean failed status cleanFaildMailStatus(context, boxId); // 2.start refresh(sync) the outbox context.getContentResolver().query(refreshUri, null, null, null, null); // 3. show the sending toast // Why add toast to Handler? cause the notificationActionIntentService is // asynchronous,so want show toast, // only must add toast to Main thread. Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), R.string.sending, Toast.LENGTH_SHORT).show(); } }); } return; } // TS: chao.zhang 2015-09-21 EMAIL FEATURE-585337 ADD_E else if (ACTION_CALENDAR_NEVER_ASK_AGAIN.equals(action)) { NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (mNotificationManager != null) { mNotificationManager.cancel(NotificationController.EXCHANGE_NEWCALENDAR_NOTIFICATION_ID); } MailPrefs.get(context).setIgnoreExchangeCalendarPermission(true); //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD return; } else if (ACTION_CONTACTS_NEVER_ASK_AGAIN.equals(action)) { NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (mNotificationManager != null) { mNotificationManager.cancel(NotificationController.EXCHANGE_NEWCONTACTS_NOTIFICATION_ID); } MailPrefs.get(context).setIgnoreExchangeContactPermission(true); //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD return; } else if (ACTION_STORAGE_NEVER_ASK_AGAIN.equals(action)) { //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD_S NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (mNotificationManager != null) { mNotificationManager.cancel(NotificationController.EXCHANGE_NEWSTORAGE_NOTIFICATION_ID); } MailPrefs.get(context).setIgnoreExchangeStoragePermission(true); //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD_E } /* * Grab the alarm from the intent. Since the remote AlarmManagerService fills in the Intent * to add some extra data, it must unparcel the NotificationAction object. It throws a * ClassNotFoundException when unparcelling. * To avoid this, do the marshalling ourselves. */ final NotificationAction notificationAction; final byte[] data = intent.getByteArrayExtra(EXTRA_NOTIFICATION_ACTION); if (data != null) { final Parcel in = Parcel.obtain(); in.unmarshall(data, 0, data.length); in.setDataPosition(0); notificationAction = NotificationAction.CREATOR.createFromParcel(in, NotificationAction.class.getClassLoader()); } else { LogUtils.wtf(LOG_TAG, "data was null trying to unparcel the NotificationAction"); return; } final Message message = notificationAction.getMessage(); final ContentResolver contentResolver = getContentResolver(); LogUtils.i(LOG_TAG, "Handling %s", action); logNotificationAction(action, notificationAction); if (notificationAction.getSource() == NotificationAction.SOURCE_REMOTE) { // Skip undo if the action is bridged from remote node. This should be similar to the // logic after the Undo notification expires in a regular flow. LogUtils.d(LOG_TAG, "Canceling %s", notificationAction.getNotificationId()); NotificationManagerCompat.from(context).cancel(notificationAction.getNotificationId()); NotificationActionUtils.processDestructiveAction(this, notificationAction); NotificationActionUtils.resendNotifications(context, notificationAction.getAccount(), notificationAction.getFolder()); return; } if (ACTION_UNDO.equals(action)) { NotificationActionUtils.cancelUndoTimeout(context, notificationAction); NotificationActionUtils.cancelUndoNotification(context, notificationAction); } else if (ACTION_ARCHIVE_REMOVE_LABEL.equals(action) || ACTION_DELETE.equals(action)) { // All we need to do is switch to an Undo notification NotificationActionUtils.createUndoNotification(context, notificationAction); NotificationActionUtils.registerUndoTimeout(context, notificationAction); } else { if (ACTION_UNDO_TIMEOUT.equals(action) || ACTION_DESTRUCT.equals(action)) { // Process the action NotificationActionUtils.cancelUndoTimeout(this, notificationAction); NotificationActionUtils.processUndoNotification(this, notificationAction); } else if (ACTION_MARK_READ.equals(action)) { final Uri uri = message.uri; final ContentValues values = new ContentValues(1); values.put(UIProvider.MessageColumns.READ, 1); contentResolver.update(uri, values, null, null); } NotificationActionUtils.resendNotifications(context, notificationAction.getAccount(), notificationAction.getFolder()); } }
From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java
public void changeUser(final long account_id, final User user) { mFriendship = null;//from w ww . j a v a2s. com mUserId = -1; mAccountId = -1; if (user == null || user.getId() <= 0 || getActivity() == null || !isMyActivatedAccount(getActivity(), account_id)) return; if (mUserInfoTask != null && mUserInfoTask.getStatus() == AsyncTask.Status.RUNNING) { mUserInfoTask.cancel(true); } final boolean is_my_activated_account = isMyActivatedAccount(getActivity(), user.getId()); mUserInfoTask = null; mErrorRetryContainer.setVisibility(View.GONE); mAccountId = account_id; mUserId = user.getId(); mScreenName = user.getScreenName(); updateUserColor(); final boolean is_multiple_account_enabled = getActivatedAccountIds(getActivity()).length > 1; mListView.setBackgroundResource(is_multiple_account_enabled ? R.drawable.ic_label_account_nopadding : 0); if (is_multiple_account_enabled) { final Drawable d = mListView.getBackground(); if (d != null) { d.mutate().setColorFilter(getAccountColor(getActivity(), account_id), PorterDuff.Mode.MULTIPLY); mListView.invalidate(); } } mNameView.setText(user.getName()); mScreenNameView.setText("@" + user.getScreenName()); mScreenNameView.setCompoundDrawablesWithIntrinsicBounds( getUserTypeIconRes(user.isVerified(), user.isProtected()), 0, 0, 0); final String description = user.getDescription(); mDescriptionContainer .setVisibility(is_my_activated_account || !isNullOrEmpty(description) ? View.VISIBLE : View.GONE); mDescriptionContainer.setOnLongClickListener(this); mDescriptionView.setText(description); final TwidereLinkify linkify = new TwidereLinkify(mDescriptionView); linkify.setOnLinkClickListener(this); linkify.addAllLinks(); mDescriptionView.setMovementMethod(LinkMovementMethod.getInstance()); final String location = user.getLocation(); mLocationContainer .setVisibility(is_my_activated_account || !isNullOrEmpty(location) ? View.VISIBLE : View.GONE); mLocationContainer.setOnLongClickListener(this); mLocationView.setText(location); final String url = user.getURL() != null ? user.getURL().toString() : null; mURLContainer.setVisibility(is_my_activated_account || !isNullOrEmpty(url) ? View.VISIBLE : View.GONE); mURLContainer.setOnLongClickListener(this); mURLView.setText(url); mCreatedAtView.setText(formatToLongTimeString(getActivity(), getTimestampFromDate(user.getCreatedAt()))); mTweetCount.setText(String.valueOf(user.getStatusesCount())); mFollowersCount.setText(String.valueOf(user.getFollowersCount())); mFriendsCount.setText(String.valueOf(user.getFriendsCount())); // final boolean display_profile_image = // mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_PROFILE_IMAGE, true); // mProfileImageView.setVisibility(display_profile_image ? View.VISIBLE // : View.GONE); // if (display_profile_image) { final String profile_image_url_string = parseString(user.getProfileImageURL()); final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image); mLazyImageLoader.displayProfileImage(mProfileImageView, hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string) : profile_image_url_string); // } String profile_banner_url_string = parseString(user.getProfileBannerImageUrl()); if (profile_banner_url_string != null) { final int def_width = getResources().getDisplayMetrics().widthPixels; profile_banner_url_string = profile_banner_url_string + "/" + getBestBannerType(def_width); } final String banner_url = profile_banner_url_string; if (mProfileBackgroundView != null) { mProfileBackgroundView.setScaleType(ImageView.ScaleType.CENTER_CROP); if (banner_url != null) { mLazyImageLoader.displayPreviewImage(mProfileBackgroundView, banner_url); } else { final Drawable d = getResources().getDrawable(R.drawable.linen); mProfileBackgroundView.setImageDrawable(d); } } mUser = user; if (isMyAccount(getActivity(), user.getId())) { final ContentResolver resolver = getContentResolver(); final ContentValues values = new ContentValues(); final URL profile_image_url = user.getProfileImageURL(); if (profile_image_url != null) { values.put(Accounts.PROFILE_IMAGE_URL, profile_image_url.toString()); } values.put(Accounts.USERNAME, user.getScreenName()); final String where = Accounts.USER_ID + " = " + user.getId() + " AND 1 = 1"; resolver.update(Accounts.CONTENT_URI, values, where, null); } mAdapter.add(new UserRecentPhotosAction()); mAdapter.add(new FavoritesAction()); mAdapter.add(new UserMentionsAction()); mAdapter.add(new UserListTypesAction()); if (user.getId() == mAccountId) { mAdapter.add(new MyTweetsRetweetedAction()); mAdapter.add(new SavedSearchesAction()); boolean nativeMapSupported = true; try { Class.forName("com.google.android.maps.MapActivity"); Class.forName("com.google.android.maps.MapView"); } catch (final ClassNotFoundException e) { nativeMapSupported = false; } if (nativeMapSupported) { mAdapter.add(new UserNearbyAction()); } if (user.isProtected()) { mAdapter.add(new IncomingFriendshipsAction()); } mAdapter.add(new UserBlocksAction()); } mAdapter.notifyDataSetChanged(); if (mRecentPhotosGallery != null) { mRecentPhotosGallery.setVisibility(View.GONE); mRecentPhotosGallery.setAdapter(new ImageAdapter(this.getActivity())); mRecentPhotosGallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { ParcelableStatus pStatus = mMediaStatuses.get(position); final ImageSpec spec = getAllAvailableImage(pStatus.image_orig_url_string); if (spec != null) { openImage(UserProfileFragment.this.getActivity(), Uri.parse(spec.full_image_link), pStatus.is_possibly_sensitive); } } }); mMediaTimelineTask = new MediaTimelineTask(this.getActivity(), mAccountId, mUser.getScreenName()); if (mMediaTimelineTask != null) { mMediaTimelineTask.execute(); } } getFriendship(); checkPushTracked(); }
From source file:nl.privacybarometer.privacyvandaag.activity.EditFeedActivity.java
@Override protected void onDestroy() { if (getIntent().getAction().equals(Intent.ACTION_EDIT)) { String url = mUrlEditText.getText().toString(); ContentResolver cr = getContentResolver(); Cursor cursor = null;/*from www .ja va 2s .com*/ try { cursor = getContentResolver().query(FeedColumns.CONTENT_URI, FeedColumns.PROJECTION_ID, FeedColumns.URL + Constants.DB_ARG, new String[] { url }, null); if (cursor != null && cursor.moveToFirst() && !getIntent().getData().getLastPathSegment().equals(cursor.getString(0))) { Toast.makeText(EditFeedActivity.this, R.string.error_feed_url_exists, Toast.LENGTH_LONG).show(); } else { ContentValues values = new ContentValues(); if (!url.startsWith(Constants.HTTP_SCHEME) && !url.startsWith(Constants.HTTPS_SCHEME)) { url = Constants.HTTP_SCHEME + url; } values.put(FeedColumns.URL, url); String name = mNameEditText.getText().toString(); String cookieName = mCookieNameEditText.getText().toString(); String cookieValue = mCookieValueEditText.getText().toString(); values.put(FeedColumns.NAME, name.trim().length() > 0 ? name : null); values.put(FeedColumns.RETRIEVE_FULLTEXT, mRetrieveFulltextCb.isChecked() ? 1 : null); values.put(FeedColumns.COOKIE_NAME, cookieName.trim().length() > 0 ? cookieName : ""); values.put(FeedColumns.COOKIE_VALUE, cookieValue.trim().length() > 0 ? cookieValue : ""); final TypedArray selectedValues = getResources() .obtainTypedArray(R.array.settings_keep_time_values); values.put(FeedColumns.KEEP_TIME, selectedValues.getInt(mKeepTime.getSelectedItemPosition(), 0)); values.put(FeedColumns.FETCH_MODE, 0); values.putNull(FeedColumns.ERROR); cr.update(getIntent().getData(), values, null, null); } } catch (Exception ignored) { } finally { if (cursor != null) { cursor.close(); } } } super.onDestroy(); }
From source file:com.akop.bach.parser.XboxLiveParser.java
private void parseViewMessage(XboxLiveAccount account, long messageUid) throws IOException, ParserException { long started = System.currentTimeMillis(); String token = getVToken(String.format(URL_VTOKEN_MESSAGES, mLocale)); String url = String.format(URL_JSON_READ_MESSAGE, mLocale); List<NameValuePair> inputs = new ArrayList<NameValuePair>(3); addValue(inputs, "msgID", messageUid); addValue(inputs, "__RequestVerificationToken", token); String page = getResponse(url, inputs, true); if (App.getConfig().logToConsole()) displayTimeTaken("Message page fetch", started); JSONObject json = getXboxJsonObject(page); String message;//from ww w.ja v a2 s.c o m if ((json == null) || (message = json.optString("Text")) == null) throw new ParserException(mContext, R.string.error_json_parser_error); ContentResolver cr = mContext.getContentResolver(); ContentValues cv = new ContentValues(); if (!json.isNull("Text")) cv.put(Messages.BODY, htmlDecode(message)); cv.put(Messages.IS_DIRTY, 0); cv.put(Messages.IS_READ, 1); int rows = cr.update(Messages.CONTENT_URI, cv, Messages.UID + "=" + messageUid + " AND " + Messages.ACCOUNT_ID + "=" + account.getId(), null); if (rows < 1) throw new ParserException(mContext, R.string.message_not_found); cr.notifyChange(Messages.CONTENT_URI, null); if (App.getConfig().logToConsole()) displayTimeTaken("Message processing", started); }
From source file:org.getlantern.firetweet.loader.support.ParcelableUserLoader.java
@Override public SingleResponse<ParcelableUser> loadInBackground() { final Context context = getContext(); final ContentResolver resolver = context.getContentResolver(); if (!mOmitIntentExtra && mExtras != null) { final ParcelableUser user = mExtras.getParcelable(EXTRA_USER); if (user != null) { final ContentValues values = ParcelableUser.makeCachedUserContentValues(user); resolver.insert(CachedUsers.CONTENT_URI, values); return SingleResponse.getInstance(user); }/*from w w w .j a va 2 s. c om*/ } final Twitter twitter = getTwitterInstance(context, mAccountId, true); if (twitter == null) return SingleResponse.getInstance(); if (mLoadFromCache) { final Expression where; final String[] whereArgs; if (mUserId > 0) { where = Expression.equals(CachedUsers.USER_ID, mUserId); whereArgs = null; } else { where = Expression.equalsArgs(CachedUsers.SCREEN_NAME); whereArgs = new String[] { mScreenName }; } final Cursor cur = resolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS, where.getSQL(), whereArgs, null); final int count = cur.getCount(); try { if (count > 0) { final CachedIndices indices = new CachedIndices(cur); cur.moveToFirst(); return SingleResponse.getInstance(new ParcelableUser(cur, indices, mAccountId)); } } finally { cur.close(); } } try { final User user = TwitterWrapper.tryShowUser(twitter, mUserId, mScreenName); final ContentValues cachedUserValues = createCachedUser(user); final long userId = user.getId(); resolver.insert(CachedUsers.CONTENT_URI, cachedUserValues); final ParcelableUser result = new ParcelableUser(user, mAccountId); if (isMyAccount(context, userId)) { final ContentValues accountValues = new ContentValues(); accountValues.put(Accounts.NAME, result.name); accountValues.put(Accounts.SCREEN_NAME, result.screen_name); accountValues.put(Accounts.PROFILE_IMAGE_URL, result.profile_image_url); accountValues.put(Accounts.PROFILE_BANNER_URL, result.profile_banner_url); final String accountWhere = Expression.equals(Accounts.ACCOUNT_ID, userId).getSQL(); resolver.update(Accounts.CONTENT_URI, accountValues, accountWhere, null); } return SingleResponse.getInstance(result); } catch (final TwitterException e) { return SingleResponse.getInstance(e); } }