List of usage examples for android.content ContentResolver delete
public final int delete(@RequiresPermission.Write @NonNull Uri url, @Nullable String where, @Nullable String[] selectionArgs)
From source file:edu.princeton.jrpalmer.asmlibrary.Settings.java
@Override protected void onResume() { if (Util.trafficCop(this)) finish();/*from w ww . j av a 2 s.c om*/ IntentFilter uploadFilter; uploadFilter = new IntentFilter( getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_UPLOADED); uploadReceiver = new UploadReceiver(); registerReceiver(uploadReceiver, uploadFilter); IntentFilter fixFilter; fixFilter = new IntentFilter( getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_RECORDED); fixReceiver = new FixReceiver(); registerReceiver(fixReceiver, fixFilter); shareMyData = PropertyHolder.getShareData(); toggleParticipationViews(shareMyData); int nUploads = PropertyHolder.getNUploads(); final long participationTime = PropertyHolder.ptCheck(); participationTimeText.setBase(SystemClock.elapsedRealtime() - participationTime); // service button boolean isServiceOn = PropertyHolder.isServiceOn(); mServiceButton.setChecked(isServiceOn); mServiceButton.setOnClickListener(new ToggleButton.OnClickListener() { public void onClick(View view) { if (view.getId() != R.id.service_button) return; Context context = view.getContext(); boolean on = ((ToggleButton) view).isChecked(); String schedule = on ? Util.MESSAGE_SCHEDULE : Util.MESSAGE_UNSCHEDULE; // Log.e(TAG, schedule + on); // now schedule or unschedule Intent intent = new Intent(getString(R.string.internal_message_id) + schedule); context.sendBroadcast(intent); showSpinner(on, storeMyData); if (on && shareMyData) { final long ptNow = PropertyHolder.ptStart(); participationTimeText.setBase(SystemClock.elapsedRealtime() - ptNow); participationTimeText.start(); ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("ONF", "on," + Util.iso8601(System.currentTimeMillis()) + "," + ptNow)); } else { final long ptNow = PropertyHolder.ptStop(); participationTimeText.setBase(SystemClock.elapsedRealtime() - ptNow); participationTimeText.stop(); // stop uploader Intent stopUploaderIntent = new Intent(Settings.this, FileUploader.class); // Stop service if it is currently running stopService(stopUploaderIntent); if (shareMyData) { ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("ONF", "off," + Util.iso8601(System.currentTimeMillis()) + "," + ptNow)); } } // If user turns CountdownDisplay on but GPS is not on, remind // user to turn // GPS on if (on) { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { if (!manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { buildAlertMessageNoGpsNoNet(); } else buildAlertMessageNoGps(); } } return; } }); // interval spinner int intspinner_item = android.R.layout.simple_spinner_item; int dropdown_item = android.R.layout.simple_spinner_dropdown_item; ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.interval_array, intspinner_item); adapter.setDropDownViewResource(dropdown_item); mIntervalSpinner.setAdapter(adapter); mIntervalSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { int parentId = parent.getId(); if (parentId != R.id.spinner_interval) return; if (pos > mInterval.length) return; if (!PropertyHolder.isServiceOn()) { PropertyHolder.setAlarmInterval(mInterval[pos]); return; } PropertyHolder.setAlarmInterval(mInterval[pos]); mServiceButton.setChecked(true); Intent intent = new Intent(getString(R.string.internal_message_id) + Util.MESSAGE_SCHEDULE); Context context = getApplicationContext(); context.sendBroadcast(intent); showSpinner(true, storeMyData); if (shareMyData) { ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("INT", Util.iso8601(System.currentTimeMillis()) + "," + mInterval[pos])); } } public void onNothingSelected(AdapterView<?> parent) { // do nothing } }); int pos = ai2pos(PropertyHolder.getAlarmInterval()); mIntervalSpinner.setSelection(pos); showSpinner(isServiceOn, storeMyData); // mydata buttons // storage spinner storageDays = PropertyHolder.getStorageDays(); mStorageSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { int parentId = parent.getId(); if (parentId != R.id.spinner_mydata) return; if (pos > MAX_STORAGE - MIN_STORAGE) return; PropertyHolder.setStorageDays(pos + MIN_STORAGE); PropertyHolder.setStoreMyData((pos + MIN_STORAGE) > 0); } public void onNothingSelected(AdapterView<?> parent) { // do nothing } }); int storagepos = storageDays - MIN_STORAGE; mStorageSpinner.setSelection(storagepos); // NEW STUFF mToggleSatRadioGroup = (RadioGroup) findViewById(R.id.toggleSatRadioGroup); mToggleIconsRadioGroup = (RadioGroup) findViewById(R.id.toggleIconsRadioGroup); mToggleAccRadioGroup = (RadioGroup) findViewById(R.id.toggleAccRadioGroup); mLimitStartDateRadioGroup = (RadioGroup) findViewById(R.id.limitStartDateRadioGroup); mLimitEndDateRadioGroup = (RadioGroup) findViewById(R.id.limitEndDateRadioGroup); Intent i = getIntent(); if (i.getBooleanExtra(MapMyData.DATES_BUTTON_MESSAGE, false)) { RelativeLayout dateSettingsArea = (RelativeLayout) findViewById(R.id.dateSettingsArea); dateSettingsArea.setFocusable(true); dateSettingsArea.setFocusableInTouchMode(true); dateSettingsArea.requestFocus(); } if (shareMyData && isServiceOn) { participationTimeText.setBase(SystemClock.elapsedRealtime() - PropertyHolder.ptStart()); participationTimeText.start(); } nUploadsText.setText(String.valueOf(nUploads)); if (nUploads >= Util.UPLOADS_TO_PRO && !PropertyHolder.getProVersion() && participationTime >= Util.TIME_TO_PRO) { Util.createProNotification(context); PropertyHolder.setProVersion(true); PropertyHolder.setNeedsDebriefingSurvey(true); } boolean proV = PropertyHolder.getProVersion(); // 19 December 2013: end of research changes mShareDataRadioGroup.check(R.id.sharedataNo); mShareDataRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.sharedataYes) { buildSharingOverAnnouncement(); } mShareDataRadioGroup.check(R.id.sharedataNo); } }); /* * if (proV) { * * if (shareMyData) { mShareDataRadioGroup.check(R.id.sharedataYes); if * (PropertyHolder.isRegistered() == false || * PropertyHolder.hasConsented() == false) { send2Intro(context); } } * else { mShareDataRadioGroup.check(R.id.sharedataNo); } * * mShareDataRadioGroup .setOnCheckedChangeListener(new * OnCheckedChangeListener() { * * @Override public void onCheckedChanged(RadioGroup group, int * checkedId) { shareMyData = (checkedId == R.id.sharedataYes); * PropertyHolder.setShareData(shareMyData); * toggleParticipationViews(shareMyData); final boolean on = * PropertyHolder.isServiceOn(); if (shareMyData) { if * (PropertyHolder.isRegistered() == false || * PropertyHolder.hasConsented() == false) { send2Intro(context); * * } if (on) { * * final long ptNow = PropertyHolder.ptStart(); * participationTimeText.setBase(SystemClock .elapsedRealtime() - * ptNow); * * participationTimeText.start(); * * ContentResolver ucr = getContentResolver(); * * ucr.insert( Util.getUploadQueueUri(context), * UploadContentValues.createUpload( "ONF", "on," + Util.iso8601(System * .currentTimeMillis()) + "," + ptNow)); * * } } else { * * final long ptNow = PropertyHolder.ptStop(); * participationTimeText.setBase(SystemClock .elapsedRealtime() - * ptNow); participationTimeText.stop(); // stop uploader Intent i = new * Intent(Settings.this, FileUploader.class); // Stop service if it is * currently running stopService(i); * * if (on) { ContentResolver ucr = getContentResolver(); * * ucr.insert( Util.getUploadQueueUri(context), * UploadContentValues.createUpload( "ONF", "off," + Util.iso8601(System * .currentTimeMillis()) + "," + ptNow)); * * } * * } * * } }); } else { mShareDataRadioGroup.check(R.id.sharedataYes); * mShareDataRadioGroup .setOnCheckedChangeListener(new * OnCheckedChangeListener() { * * @Override public void onCheckedChanged(RadioGroup group, int * checkedId) { if (checkedId == R.id.sharedataNo) { * mShareDataRadioGroup.check(R.id.sharedataYes); * showCurrentlySharingDialog(); } } }); * * } */ new CheckPendingUploadsSizeTask().execute(context); new CheckUserDbSizeTask().execute(context); deletePendingUploadsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ContentResolver cr = getContentResolver(); final int nDeleted = cr.delete(Util.getUploadQueueUri(context), "1", null); // Log.i("Settings", "number of rows deleted=" + nDeleted); Util.toast(context, String.valueOf(nDeleted) + " " + getResources().getString(R.string.locations_deleted) + "."); updateStorageSizes(); } }); deleteUserDbButton = (ImageButton) findViewById(R.id.deleteMyDbButton); deleteUserDbButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ContentResolver cr = getContentResolver(); final int nDeleted = cr.delete(Util.getFixesUri(context), "1", null); Util.toast(context, String.valueOf(nDeleted) + " " + getResources().getString(R.string.locations_deleted) + "."); updateStorageSizes(); } }); uploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (Util.isOnline(context)) { Intent i = new Intent(Settings.this, FileUploader.class); startService(i); new UploadMessageTask().execute(context); } else { Util.toast(context, getResources().getString(R.string.offline_warning)); } } }); mToggleSatRadioGroup.check(PropertyHolder.getMapSat() ? R.id.toggleSatYes : R.id.toggleSatNo); mToggleSatRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapSat(checkedId == R.id.toggleSatYes); } }); mToggleIconsRadioGroup.check(PropertyHolder.getMapIcons() ? R.id.toggleIconsYes : R.id.toggleIconsNo); mToggleIconsRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapIcons(checkedId == R.id.toggleIconsYes); } }); mToggleAccRadioGroup.check(PropertyHolder.getMapAcc() ? R.id.toggleAccYes : R.id.toggleAccNo); mToggleAccRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapAcc(checkedId == R.id.toggleAccYes); } }); mStartDateButton = (Button) findViewById(R.id.startDateButton); mEndDateButton = (Button) findViewById(R.id.endDateButton); boolean limitStartDate = PropertyHolder.getLimitStartDate(); boolean limitEndDate = PropertyHolder.getLimitEndDate(); if (!limitStartDate) mStartDateButton.setVisibility(View.GONE); else { mStartDateButton.setVisibility(View.VISIBLE); } if (!limitEndDate) mEndDateButton.setVisibility(View.GONE); else { mEndDateButton.setVisibility(View.VISIBLE); } mLimitStartDateRadioGroup.check(limitStartDate ? R.id.limitStartDateYes : R.id.limitStartDateNo); mLimitStartDateRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setLimitStartDate(checkedId == R.id.limitStartDateYes); if (checkedId != R.id.limitStartDateYes) mStartDateButton.setVisibility(View.GONE); else { mStartDateButton.setVisibility(View.VISIBLE); } } }); mLimitEndDateRadioGroup.check(limitEndDate ? R.id.limitEndDateYes : R.id.limitEndDateNo); mLimitEndDateRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setLimitEndDate(checkedId == R.id.limitEndDateYes); if (checkedId != R.id.limitEndDateYes) mEndDateButton.setVisibility(View.GONE); else { mEndDateButton.setVisibility(View.VISIBLE); } } }); mStartDateButton.setText(Util.userDateNoTime(PropertyHolder.getMapStartDate())); mStartDateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = new StartDatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker"); } }); mEndDateButton.setText(Util.userDateNoTime(PropertyHolder.getMapEndDate())); mEndDateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = new EndDatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker"); } }); if (PropertyHolder.getNeedsDebriefingSurvey()) { buildProAnnouncement(); PropertyHolder.setNeedsDebriefingSurvey(false); } super.onResume(); }
From source file:com.mwebster.exchange.SyncManager.java
static public void alert(Context context, final long id) { final SyncManager syncManager = INSTANCE; checkSyncManagerServiceRunning();// w w w . jav a2 s . co m if (id < 0) { kick("ping SyncManager"); } else if (syncManager == null) { context.startService(new Intent(context, SyncManager.class)); } else { final AbstractSyncService service = syncManager.mServiceMap.get(id); if (service != null) { // Handle alerts in a background thread, as we are typically called from a // broadcast receiver, and are therefore running in the UI thread new Thread(new Runnable() { public void run() { Mailbox m = Mailbox.restoreMailboxWithId(syncManager, id); if (m != null) { // We ignore drafts completely (doesn't sync). Changes in Outbox are // handled in the checkMailboxes loop, so we can ignore these pings. if (m.mType == Mailbox.TYPE_DRAFTS || m.mType == Mailbox.TYPE_OUTBOX) { String[] args = new String[] { Long.toString(m.mId) }; ContentResolver resolver = INSTANCE.mResolver; resolver.delete(Message.DELETED_CONTENT_URI, WHERE_MAILBOX_KEY, args); resolver.delete(Message.UPDATED_CONTENT_URI, WHERE_MAILBOX_KEY, args); return; } service.mAccount = Account.restoreAccountWithId(INSTANCE, m.mAccountKey); service.mMailbox = m; // Send the alarm to the sync service if (!service.alarm()) { // A false return means that we were forced to interrupt the thread // In this case, we release the mailbox so that we can start another // thread to do the work log("Alarm failed; releasing mailbox"); synchronized (sSyncLock) { syncManager.releaseMailbox(id); } // Shutdown the connection manager; this should close all of our // sockets and generate IOExceptions all around. SyncManager.shutdownConnectionManager(); } } } }).start(); } } }
From source file:com.android.exchange.SyncManager.java
static public void alert(Context context, final long id) { final SyncManager syncManager = INSTANCE; checkSyncManagerServiceRunning();// w w w . j a v a2 s.c o m if (id < 0) { kick("ping SyncManager"); } else if (syncManager == null) { context.startService(new Intent(context, SyncManager.class)); } else { final AbstractSyncService service = syncManager.mServiceMap.get(id); if (service != null) { // Handle alerts in a background thread, as we are typically called from a // broadcast receiver, and are therefore running in the UI thread String threadName = "SyncManager Alert: "; if (service.mMailbox != null) { threadName += service.mMailbox.mDisplayName; } new Thread(new Runnable() { public void run() { Mailbox m = Mailbox.restoreMailboxWithId(syncManager, id); if (m != null) { // We ignore drafts completely (doesn't sync). Changes in Outbox are // handled in the checkMailboxes loop, so we can ignore these pings. if (m.mType == Mailbox.TYPE_DRAFTS || m.mType == Mailbox.TYPE_OUTBOX) { String[] args = new String[] { Long.toString(m.mId) }; ContentResolver resolver = INSTANCE.mResolver; resolver.delete(Message.DELETED_CONTENT_URI, WHERE_MAILBOX_KEY, args); resolver.delete(Message.UPDATED_CONTENT_URI, WHERE_MAILBOX_KEY, args); return; } service.mAccount = Account.restoreAccountWithId(INSTANCE, m.mAccountKey); service.mMailbox = m; // Send the alarm to the sync service if (!service.alarm()) { // A false return means that we were forced to interrupt the thread // In this case, we release the mailbox so that we can start another // thread to do the work log("Alarm failed; releasing mailbox"); synchronized (sSyncLock) { syncManager.releaseMailbox(id); } // Shutdown the connection manager; this should close all of our // sockets and generate IOExceptions all around. SyncManager.shutdownConnectionManager(); } } } }, threadName).start(); } } }
From source file:com.charabia.SmsViewActivity.java
@Override public void onResume() { super.onResume(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefPhoneNumber = prefs.getString(PreferencesActivity.PHONE_NUMBER, null); if (prefPhoneNumber == null || prefPhoneNumber.length() <= 0) { Intent intent;/*from w w w . jav a 2 s . c o m*/ intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.setClassName(this, PreferencesActivity.class.getName()); startActivity(intent); intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.setClassName(this, WebViewActivity.class.getName()); intent.setData(Uri.parse(WebViewActivity.getBaseUrl(this, "/help", "enter_phone_number.html"))); startActivity(intent); //Attempt to retrieve old keys android.content.ContentResolver cr = getContentResolver(); android.database.Cursor cursor = cr.query(Data.CONTENT_URI, new String[] { Data._ID, Tools.PHONE, Tools.KEY }, Data.MIMETYPE + "=?", new String[] { Tools.CONTENT_ITEM_TYPE }, null); while (cursor.moveToNext()) { try { tools.updateOrCreateContactKey(cursor.getString(cursor.getColumnIndex(Tools.PHONE)), Base64.decode(cursor.getString(cursor.getColumnIndex(Tools.KEY)), Base64.DEFAULT), false); cr.delete(ContentUris.withAppendedId(Data.CONTENT_URI, cursor.getLong(cursor.getColumnIndex(Data._ID))), null, null); } catch (NoContactException e) { e.printStackTrace(); Toast.makeText(this, "No contact for " + cursor.getColumnIndex(Tools.PHONE), Toast.LENGTH_SHORT) .show(); } } } }
From source file:org.mariotaku.twidere.util.DataStoreUtils.java
public static void deleteStatus(@NonNull ContentResolver cr, @NonNull UserKey accountKey, @NonNull String statusId, @Nullable ParcelableStatus status) { final String host = accountKey.getHost(); final String deleteWhere, updateWhere; final String[] deleteWhereArgs, updateWhereArgs; if (host != null) { deleteWhere = Expression/*from www . ja va2 s . c o m*/ .and(Expression.likeRaw(new Column(Statuses.ACCOUNT_KEY), "'%@'||?"), Expression.or( Expression.equalsArgs(Statuses.STATUS_ID), Expression.equalsArgs(Statuses.RETWEET_ID))) .getSQL(); deleteWhereArgs = new String[] { host, statusId, statusId }; updateWhere = Expression.and(Expression.likeRaw(new Column(Statuses.ACCOUNT_KEY), "'%@'||?"), Expression.equalsArgs(Statuses.MY_RETWEET_ID)).getSQL(); updateWhereArgs = new String[] { host, statusId }; } else { deleteWhere = Expression .or(Expression.equalsArgs(Statuses.STATUS_ID), Expression.equalsArgs(Statuses.RETWEET_ID)) .getSQL(); deleteWhereArgs = new String[] { statusId, statusId }; updateWhere = Expression.equalsArgs(Statuses.MY_RETWEET_ID).getSQL(); updateWhereArgs = new String[] { statusId }; } for (final Uri uri : STATUSES_URIS) { cr.delete(uri, deleteWhere, deleteWhereArgs); if (status != null) { final ContentValues values = new ContentValues(); values.putNull(Statuses.MY_RETWEET_ID); values.put(Statuses.RETWEET_COUNT, status.retweet_count - 1); cr.update(uri, values, updateWhere, updateWhereArgs); } } }
From source file:com.android.exchange.ExchangeService.java
static public void alert(Context context, final long id) { final ExchangeService exchangeService = INSTANCE; checkExchangeServiceServiceRunning(); if (id < 0) { log("ExchangeService alert"); kick("ping ExchangeService"); } else if (exchangeService == null) { context.startService(new Intent(context, ExchangeService.class)); } else {// w w w .j a v a 2 s . co m final AbstractSyncService service = exchangeService.mServiceMap.get(id); if (service != null) { // Handle alerts in a background thread, as we are typically called from a // broadcast receiver, and are therefore running in the UI thread String threadName = "ExchangeService Alert: "; if (service.mMailbox != null) { threadName += service.mMailbox.mDisplayName; } new Thread(new Runnable() { public void run() { Mailbox m = Mailbox.restoreMailboxWithId(exchangeService, id); if (m != null) { // We ignore drafts completely (doesn't sync). Changes in Outbox are // handled in the checkMailboxes loop, so we can ignore these pings. if (Eas.USER_LOG) { Log.d(TAG, "Alert for mailbox " + id + " (" + m.mDisplayName + ")"); } if (m.mType == Mailbox.TYPE_DRAFTS || m.mType == Mailbox.TYPE_OUTBOX) { String[] args = new String[] { Long.toString(m.mId) }; ContentResolver resolver = INSTANCE.mResolver; resolver.delete(Message.DELETED_CONTENT_URI, WHERE_MAILBOX_KEY, args); resolver.delete(Message.UPDATED_CONTENT_URI, WHERE_MAILBOX_KEY, args); return; } service.mAccount = Account.restoreAccountWithId(INSTANCE, m.mAccountKey); service.mMailbox = m; // Send the alarm to the sync service if (!service.alarm()) { // A false return means that we were forced to interrupt the thread // In this case, we release the mailbox so that we can start another // thread to do the work log("Alarm failed; releasing mailbox"); synchronized (sSyncLock) { exchangeService.releaseMailbox(id); } // Shutdown the connection manager; this should close all of our // sockets and generate IOExceptions all around. ExchangeService.shutdownConnectionManager(); } } } }, threadName).start(); } } }
From source file:com.ichi2.anki.tests.ContentProviderTest.java
/** * Check that inserting and removing a note into default deck works as expected *//* w w w . jav a2 s .c om*/ public void testInsertAndRemoveNote() throws Exception { // Get required objects for test final ContentResolver cr = getContext().getContentResolver(); final Collection col = CollectionHelper.getInstance().getCol(getContext()); final AddContentApi api = new AddContentApi(getContext()); // Add the note Uri newNoteUri = api.addNewNote(mModelId, 1, TEST_NOTE_FIELDS, TEST_TAG); assertNotNull("Check that URI returned from addNewNote is not null", newNoteUri); // Check that it looks as expected Note addedNote = new Note(col, Long.parseLong(newNoteUri.getLastPathSegment())); addedNote.load(); assertTrue("Check that fields were set correctly", Arrays.equals(addedNote.getFields(), TEST_NOTE_FIELDS)); assertEquals("Check that tag was set correctly", TEST_TAG, addedNote.getTags().get(0)); int expectedNumCards = col.getModels().get(mModelId).getJSONArray("tmpls").length(); assertEquals("Check that correct number of cards generated", expectedNumCards, addedNote.cards().size()); // Now delete the note cr.delete(newNoteUri, null, null); try { addedNote.load(); fail("Expected RuntimeException to be thrown when deleting note"); } catch (RuntimeException e) { // Expect RuntimeException to be thrown when loading deleted note } }
From source file:org.mariotaku.twidere.util.DataStoreUtils.java
public static void deleteActivityStatus(@NonNull ContentResolver cr, @NonNull UserKey accountKey, @NonNull final String statusId, @Nullable final ParcelableStatus result) { final String host = accountKey.getHost(); final String deleteWhere, updateWhere; final String[] deleteWhereArgs, updateWhereArgs; if (host != null) { deleteWhere = Expression.and(Expression.likeRaw(new Column(Activities.ACCOUNT_KEY), "'%@'||?"), Expression.or(Expression.equalsArgs(Activities.STATUS_ID), Expression.equalsArgs(Activities.STATUS_RETWEET_ID))) .getSQL();//from ww w . jav a 2 s . c o m deleteWhereArgs = new String[] { host, statusId, statusId }; updateWhere = Expression.and(Expression.likeRaw(new Column(Activities.ACCOUNT_KEY), "'%@'||?"), Expression.equalsArgs(Activities.STATUS_MY_RETWEET_ID)).getSQL(); updateWhereArgs = new String[] { host, statusId }; } else { deleteWhere = Expression.or(Expression.equalsArgs(Activities.STATUS_ID), Expression.equalsArgs(Activities.STATUS_RETWEET_ID)).getSQL(); deleteWhereArgs = new String[] { statusId, statusId }; updateWhere = Expression.equalsArgs(Activities.STATUS_MY_RETWEET_ID).getSQL(); updateWhereArgs = new String[] { statusId }; } for (final Uri uri : ACTIVITIES_URIS) { cr.delete(uri, deleteWhere, deleteWhereArgs); updateActivity(cr, uri, updateWhere, updateWhereArgs, new UpdateActivityAction() { @Override public void process(ParcelableActivity activity) { activity.status_my_retweet_id = null; ParcelableStatus[][] statusesMatrix = { activity.target_statuses, activity.target_object_statuses }; for (ParcelableStatus[] statusesArray : statusesMatrix) { if (statusesArray == null) continue; for (ParcelableStatus status : statusesArray) { if (statusId.equals(status.id) || statusId.equals(status.retweet_id) || statusId.equals(status.my_retweet_id)) { status.my_retweet_id = null; if (result != null) { status.reply_count = result.reply_count; status.retweet_count = result.retweet_count - 1; status.favorite_count = result.favorite_count; } } } } } }); } }
From source file:org.getlantern.firetweet.fragment.support.UserFragment.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUser user = getUser(); final Relationship relationship = mRelationship; if (user == null || twitter == null) return false; switch (item.getItemId()) { case MENU_BLOCK: { if (mRelationship != null) { if (mRelationship.isSourceBlockingTarget()) { twitter.destroyBlockAsync(user.account_id, user.id); } else { CreateUserBlockDialogFragment.show(getFragmentManager(), user); }//from w w w . ja va2s .c om } break; } case MENU_REPORT_SPAM: { ReportSpamDialogFragment.show(getFragmentManager(), user); break; } case MENU_ADD_TO_FILTER: { final boolean filtering = Utils.isFilteringUser(getActivity(), user.id); final ContentResolver cr = getContentResolver(); if (filtering) { final Expression where = Expression.equals(Filters.Users.USER_ID, user.id); cr.delete(Filters.Users.CONTENT_URI, where.getSQL(), null); showInfoMessage(getActivity(), R.string.message_user_unmuted, false); } else { cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user)); showInfoMessage(getActivity(), R.string.message_user_muted, false); } break; } case MENU_MUTE_USER: { if (mRelationship != null) { if (mRelationship.isSourceMutingTarget()) { twitter.destroyMuteAsync(user.account_id, user.id); } else { CreateUserMuteDialogFragment.show(getFragmentManager(), user); } } break; } case MENU_MENTION: { final Intent intent = new Intent(INTENT_ACTION_MENTION); final Bundle bundle = new Bundle(); bundle.putParcelable(EXTRA_USER, user); intent.putExtras(bundle); startActivity(intent); break; } case MENU_SEND_DIRECT_MESSAGE: { final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_FIRETWEET); builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION); builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_id)); builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user.id)); final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); intent.putExtra(EXTRA_ACCOUNT, ParcelableCredentials.getAccount(getActivity(), user.account_id)); intent.putExtra(EXTRA_USER, user); startActivity(intent); break; } case MENU_SET_COLOR: { final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class); intent.putExtra(EXTRA_COLOR, getUserColor(getActivity(), user.id, true)); intent.putExtra(EXTRA_ALPHA_SLIDER, false); intent.putExtra(EXTRA_CLEAR_BUTTON, true); startActivityForResult(intent, REQUEST_SET_COLOR); break; } case MENU_CLEAR_NICKNAME: { clearUserNickname(getActivity(), user.id); break; } case MENU_SET_NICKNAME: { final String nick = getUserNickname(getActivity(), user.id, true); SetUserNicknameDialogFragment.show(getFragmentManager(), user.id, nick); break; } case MENU_ADD_TO_LIST: { final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST); intent.setClass(getActivity(), UserListSelectorActivity.class); intent.putExtra(EXTRA_ACCOUNT_ID, user.account_id); intent.putExtra(EXTRA_SCREEN_NAME, getAccountScreenName(getActivity(), user.account_id)); startActivityForResult(intent, REQUEST_ADD_TO_LIST); break; } case MENU_OPEN_WITH_ACCOUNT: { final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT); intent.setClass(getActivity(), AccountSelectorActivity.class); intent.putExtra(EXTRA_SINGLE_SELECTION, true); startActivityForResult(intent, REQUEST_SELECT_ACCOUNT); break; } case MENU_FOLLOW: { if (relationship == null) return false; final boolean isFollowing = relationship.isSourceFollowingTarget(); final boolean isCreatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id); final boolean isDestroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id); if (!isCreatingFriendship && !isDestroyingFriendship) { if (isFollowing) { DestroyFriendshipDialogFragment.show(getFragmentManager(), user); } else { twitter.createFriendshipAsync(user.account_id, user.id); } } return true; } case R.id.muted_users: { openMutesUsers(getActivity(), user.account_id); return true; } case R.id.blocked_users: { openUserBlocks(getActivity(), user.account_id); return true; } case R.id.incoming_friendships: { openIncomingFriendships(getActivity(), user.account_id); return true; } default: { if (item.getIntent() != null) { try { startActivity(item.getIntent()); } catch (final ActivityNotFoundException e) { Log.w(LOGTAG, e); return false; } } break; } } return true; }
From source file:com.bt.download.android.gui.Librarian.java
private void syncMediaStore(byte fileType, Set<File> ignorableFiles) { TableFetcher fetcher = TableFetchers.getFetcher(fileType); Cursor c = null;/*from w w w.j ava2s .c o m*/ try { ContentResolver cr = context.getContentResolver(); String where = MediaColumns.DATA + " LIKE ?"; String[] whereArgs = new String[] { SystemPaths.getAppStorage().getAbsolutePath() + "%" }; c = cr.query(fetcher.getContentUri(), new String[] { MediaColumns._ID, MediaColumns.DATA }, where, whereArgs, null); if (c == null) { return; } int idCol = c.getColumnIndex(MediaColumns._ID); int pathCol = c.getColumnIndex(MediaColumns.DATA); List<Integer> ids = new ArrayList<Integer>(); while (c.moveToNext()) { int id = Integer.valueOf(c.getString(idCol)); String path = c.getString(pathCol); if (ignorableFiles.contains(new File(path))) { ids.add(id); } } cr.delete(fetcher.getContentUri(), MediaColumns._ID + " IN " + StringUtils.buildSet(ids), null); } catch (Throwable e) { Log.e(TAG, "General failure during sync of MediaStore", e); } finally { if (c != null) { c.close(); } } }