List of usage examples for android.content ContentValues clear
public void clear()
From source file:com.tct.mail.NotificationActionIntentService.java
/** * Give the chance to restore the mail's status,here we restore to queue status * @param context//from w ww .ja v a 2 s. co m * @param boxId is the outbox's id */ private void cleanFaildMailStatus(Context context, long boxId) { Cursor cursor = null; ContentResolver resolver = context.getContentResolver(); ArrayList<Long> pendingSendMails = new ArrayList<Long>(); ContentValues value = new ContentValues(); //query the failed mails try { cursor = resolver.query(EmailContent.Message.CONTENT_URI, EmailContent.Message.ID_COLUMN_WITH_STATUS_PROJECTION, MessageColumns.SENDING_STATUS + "=?" + " AND " + MessageColumns.MAILBOX_KEY + "=?", new String[] { Long.toString(EmailContent.Message.MAIL_IN_FAILED_STATUS), Long.toString(boxId) }, null); while (cursor.moveToNext()) { pendingSendMails.add(cursor.getLong(0)); } } catch (Exception e) { LogUtils.e(LogUtils.TAG, e, "Exception happen during queue the failed mails in cleanFaildMailStatus "); } finally { if (cursor != null) { cursor.close(); } } //update the mails status if (pendingSendMails.size() > 0) { for (long id : pendingSendMails) { value.clear(); Uri uri = ContentUris.withAppendedId(EmailContent.Message.CONTENT_URI, id); value.put(MessageColumns.SENDING_STATUS, EmailContent.Message.MAIL_IN_QUEUE_STATUS); resolver.update(uri, value, null, null); LogUtils.d(LogUtils.TAG, "update the mail's status from FAIL to QUEUE,current message id is %d", id); } } pendingSendMails.clear(); }
From source file:com.intuit.qboecoui.email.SalesFormEmail.java
/** * This method prepares the command to update the company preference and send the email. * @return//w w w.jav a2 s.co m */ private boolean handleUpdatePreference() { // If there is no error in form data send the request. JSONObject jsonObj = new JSONObject(); try { jsonObj.put(V3Operation.SEND, mSalesFormEmailJson.toSerialize()); } catch (JSONException e1) { CustomLog.logError(TAG, e1, "SalesFormEmail: problem deteceted while serializing the send payload."); return false; } String jsonPayload = ""; try { jsonPayload = (jsonObj.get(V3Operation.SEND)).toString(); } catch (JSONException exception) { CustomLog.logError(TAG, exception, "SalesFormEmail: Error retrieving the payload"); return false; } // handle update of the attach pdf preference. final ContentValues pContentValues = new ContentValues(2); pContentValues.clear(); pContentValues.put(Preference._ID, 1); pContentValues.put(Preference.ETRANSACTION_ATTACH_PDF, "true"); mCurrentCommandRequest = ISyncConstants.FLAG_EDIT_PREF_AND_SEND_MAIL; Uri prefUri = getApplicationContext().getContentResolver().insert(Preference.CONTENT_URI, pContentValues); UpdateSFMPreferenceAndSendEmailRequest updateRequest = UpdateSFMPreferenceAndSendEmailRequest.createRequest( BaseApplicationModule.getNetworkModule(), this, ISyncConstants.FLAG_EDIT_PREF_AND_SEND_MAIL, prefUri, mUri, jsonPayload, mTransactionType, this, this); updateRequest.setTag(this); // TODO P1 : check this code for case when the update preference fails / passes. BaseApplicationModule.getNetworkModule().dispatchRequest(updateRequest); try { // We shoud stop the pdf preview service here this.stopService(new Intent(this, PreviewService.class)); ((PreviewResponseHandler) mPreviewHandler).onFinish(); } catch (SecurityException ex) { // do nothing } // track the click of send button //SalesFormEmail.SFM_Flow_tracking = Util.buildTrackingFlow(SalesFormEmail.SFM_Flow_tracking, QBMTrackConstants.SALES_FORM_EMAIL_SENT ); BaseApplicationModule.getTrackingModule().trackLink(QBMTrackConstants.SALES_FORM_EMAIL_PAGE_NAME, QBMTrackConstants.SALES_FORM_EMAIL_SENT_WITH_PREF_UPDATE); startProgressBar(getString(R.string.sales_form_email_sending_email_text)); return true; }
From source file:net.sf.diningout.content.SyncAdapter.java
/** * Update the synchronised object at the URI with the values received from the server. * * @param synceds can be null//from ww w . j a v a2 s .c o m */ private void response(List<? extends Synced> synceds, ContentProviderClient cp, Uri uri) throws RemoteException { if (synceds == null) { return; } ContentValues vals = new ContentValues(2); String sel = Columns.VERSION + " = ?"; String[] args = new String[1]; int size = synceds.size(); for (int i = 0; i < size; i++) { Synced synced = synceds.get(i); if (synced.globalId > 0 && uri != REVIEW_DRAFTS_URI) { vals.put(Columns.GLOBAL_ID, synced.globalId); if (uri == RESTAURANTS_URI) { Restaurants.deleteConflict(synced.localId, synced.globalId); } } vals.put(Columns.DIRTY, synced.dirty); args[0] = String.valueOf(synced.version); cp.update(ContentUris.withAppendedId(uri, synced.localId), vals, sel, args); vals.clear(); } }
From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java
private void saveStackBlocking() { final ContentResolver resolver = getContentResolver(); final ContentValues values = new ContentValues(); final byte[] rawStack = DurableUtils.writeToArrayOrNull(mState.stack); if (mState.action == ACTION_CREATE) { // Remember stack for last create values.clear(); values.put(RecentColumns.KEY, mState.stack.buildKey()); values.put(RecentColumns.STACK, rawStack); resolver.insert(RecentsProvider.buildRecent(), values); }/*w w w. j av a 2 s. c o m*/ // Remember location for next app launch final String packageName = getCallingPackageMaybeExtra(); values.clear(); values.put(ResumeColumns.STACK, rawStack); values.put(ResumeColumns.EXTERNAL, 0); resolver.insert(RecentsProvider.buildResume(packageName), values); }
From source file:com.android.messaging.mmslib.pdu.PduPersister.java
private void persistAddress(final long msgId, final int type, final EncodedStringValue[] array) { final ContentValues values = new ContentValues(3); for (final EncodedStringValue addr : array) { values.clear(); // Clear all values first. values.put(Addr.ADDRESS, toIsoString(addr.getTextString())); values.put(Addr.CHARSET, addr.getCharacterSet()); values.put(Addr.TYPE, type);//ww w.j a va 2 s . co m final Uri uri = Uri.parse("content://mms/" + msgId + "/addr"); SqliteWrapper.insert(mContext, mContentResolver, uri, values); } }
From source file:com.nextgis.maplibui.activity.ModifyAttributesActivity.java
protected void putSign() { LinearLayout layout = (LinearLayout) findViewById(R.id.controls_list); for (int i = 0; i < layout.getChildCount(); i++) { View child = layout.getChildAt(i); if (child instanceof Sign) { IGISApplication application = (IGISApplication) getApplication(); Uri uri = Uri.parse("content://" + application.getAuthority() + "/" + mLayer.getPath().getName() + "/" + mFeatureId + "/" + Constants.URI_ATTACH); ContentValues values = new ContentValues(); values.put(VectorLayer.ATTACH_DISPLAY_NAME, "_signature"); values.put(VectorLayer.ATTACH_DESCRIPTION, "_signature"); values.put(VectorLayer.ATTACH_MIME_TYPE, "image/jpeg"); Cursor saved = getContentResolver().query(uri, null, VectorLayer.ATTACH_ID + " = ?", new String[] { Sign.SIGN_FILE }, null); boolean hasSign = false; if (saved != null) { hasSign = saved.moveToFirst(); saved.close();//from w ww . j a v a 2 s. c o m } if (!hasSign) { Uri result = getContentResolver().insert(uri, values); if (result != null) { long id = Long.parseLong(result.getLastPathSegment()); values.clear(); values.put(VectorLayer.ATTACH_ID, Integer.MAX_VALUE); uri = Uri.withAppendedPath(uri, id + ""); getContentResolver().update(uri, values, null, null); } } File png = new File(mLayer.getPath(), mFeatureId + ""); Sign sign = (Sign) child; try { if (!png.isDirectory()) FileUtil.createDir(png); png = new File(png, Sign.SIGN_FILE); sign.save(sign.getWidth(), sign.getHeight(), true, png); } catch (IOException | RuntimeException e) { e.printStackTrace(); } } } }
From source file:com.piusvelte.sonet.core.OAuthLogin.java
private String addAccount(String username, String token, String secret, int expiry, int service, String sid) { String accountId;//from ww w. j av a2 s . c om ContentValues values = new ContentValues(); values.put(Accounts.USERNAME, username); values.put(Accounts.TOKEN, token); values.put(Accounts.SECRET, secret); values.put(Accounts.EXPIRY, expiry); values.put(Accounts.SERVICE, service); values.put(Accounts.SID, sid); if (mAccountId != Sonet.INVALID_ACCOUNT_ID) { // re-authenticating accountId = Long.toString(mAccountId); getContentResolver().update(Accounts.getContentUri(this), values, Accounts._ID + "=?", new String[] { Long.toString(mAccountId) }); } else { // new account accountId = getContentResolver().insert(Accounts.getContentUri(this), values).getLastPathSegment(); values.clear(); values.put(Widget_accounts.ACCOUNT, accountId); values.put(Widget_accounts.WIDGET, mWidgetId); getContentResolver().insert(Widget_accounts.getContentUri(this), values); } setResult(RESULT_OK); return accountId; }
From source file:com.shafiq.myfeedle.core.OAuthLogin.java
private String addAccount(String username, String token, String secret, int expiry, int service, String sid) { String accountId;/*from www. j a va2 s .c o m*/ ContentValues values = new ContentValues(); values.put(Accounts.USERNAME, username); values.put(Accounts.TOKEN, token); values.put(Accounts.SECRET, secret); values.put(Accounts.EXPIRY, expiry); values.put(Accounts.SERVICE, service); values.put(Accounts.SID, sid); if (mAccountId != Myfeedle.INVALID_ACCOUNT_ID) { // re-authenticating accountId = Long.toString(mAccountId); getContentResolver().update(Accounts.getContentUri(this), values, Accounts._ID + "=?", new String[] { Long.toString(mAccountId) }); } else { // new account accountId = getContentResolver().insert(Accounts.getContentUri(this), values).getLastPathSegment(); values.clear(); values.put(Widget_accounts.ACCOUNT, accountId); values.put(Widget_accounts.WIDGET, mWidgetId); getContentResolver().insert(Widget_accounts.getContentUri(this), values); } setResult(RESULT_OK); return accountId; }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
/** * ??/*from w w w .j a v a 2 s . c o m*/ * * @param message ? * @param boxType ?? * tableName ??a * @return ?ID */ public static long insertIMessage(ECMessage message, int boxType) { long ownThreadId = 0; long row = 0L; try { if (!TextUtils.isEmpty(message.getSessionId())) { String contactIds = message.getSessionId(); if (contactIds.toUpperCase().startsWith("G")) { GroupSqlManager.checkGroup(contactIds); } checkContact(message.getForm(), message.getNickName()); ownThreadId = ConversationSqlManager.querySessionIdForBySessionId(contactIds); if (ownThreadId == 0) { try { ownThreadId = ConversationSqlManager.insertSessionRecord(message); } catch (Exception e) { LogUtil.e(TAG + " " + e.toString()); } } if (ownThreadId > 0) { int isread = IMESSENGER_TYPE_UNREAD; if (boxType == IMESSENGER_BOX_TYPE_OUTBOX || boxType == IMESSENGER_BOX_TYPE_DRAFT) { isread = IMESSENGER_TYPE_READ; } ContentValues values = new ContentValues(); if (boxType == IMESSENGER_BOX_TYPE_DRAFT) { try { // ??? values.put(IMessageColumn.OWN_THREAD_ID, ownThreadId); values.put(IMessageColumn.sender, message.getForm()); values.put(IMessageColumn.MESSAGE_ID, message.getMsgId()); values.put(IMessageColumn.MESSAGE_TYPE, message.getType().ordinal()); values.put(IMessageColumn.SEND_STATUS, message.getMsgStatus().ordinal()); values.put(IMessageColumn.READ_STATUS, isread); values.put(IMessageColumn.BOX_TYPE, boxType); values.put(IMessageColumn.BODY, ((ECTextMessageBody) message.getBody()).getMessage()); values.put(IMessageColumn.USER_DATA, message.getUserData()); values.put(IMessageColumn.RECEIVE_DATE, System.currentTimeMillis()); values.put(IMessageColumn.CREATE_DATE, message.getMsgTime()); row = getInstance().sqliteDB().insertOrThrow(DatabaseHelper.TABLES_NAME_IM_MESSAGE, null, values); } catch (SQLException e) { LogUtil.e(TAG + " " + e.toString()); } finally { ChattingFragment.isFireMsg = false; values.clear(); } } else { try { values.put(IMessageColumn.OWN_THREAD_ID, ownThreadId); values.put(IMessageColumn.MESSAGE_ID, message.getMsgId()); values.put(IMessageColumn.SEND_STATUS, message.getMsgStatus().ordinal()); values.put(IMessageColumn.READ_STATUS, isread); values.put(IMessageColumn.BOX_TYPE, boxType); // values.put(IMessageColumn.VERSION, // message.getVersion()); values.put(IMessageColumn.USER_DATA, message.getUserData()); values.put(IMessageColumn.RECEIVE_DATE, System.currentTimeMillis()); values.put(IMessageColumn.CREATE_DATE, message.getMsgTime()); values.put(IMessageColumn.sender, message.getForm()); values.put(IMessageColumn.MESSAGE_TYPE, message.getType().ordinal()); if (message.getType() == Type.VIDEO && message.getDirection() == Direction.RECEIVE) { ECVideoMessageBody videoBody = (ECVideoMessageBody) message.getBody(); values.put(IMessageColumn.BODY, videoBody.getLength() + ""); } if (message.getType() == Type.RICH_TEXT) { ECPreviewMessageBody body = (ECPreviewMessageBody) message.getBody(); values.put(IMessageColumn.FILE_URL, body.getUrl()); values.put(IMessageColumn.BODY, body.getTitle()); values.put(IMessageColumn.FILE_PATH, body.getLocalUrl()); } if (message.getType() == Type.IMAGE && message.getDirection() == Direction.RECEIVE) { values.put(IMessageColumn.BODY, message.getUserData()); } if (message.getType() == Type.IMAGE && message.getDirection() == Direction.SEND && ChattingFragment.isFireMsg) { values.put(IMessageColumn.BODY, "fireMessage"); } // ? putValues(message, values); LogUtil.d(TAG, "[insertIMessage] " + values.toString()); row = getInstance().sqliteDB().insertOrThrow(DatabaseHelper.TABLES_NAME_IM_MESSAGE, null, values); } catch (SQLException e) { e.printStackTrace(); LogUtil.e(TAG + " " + e.toString()); } finally { ChattingFragment.isFireMsg = false; values.clear(); } } getInstance().notifyChanged(contactIds); } } } catch (Exception e) { LogUtil.e(e.getMessage()); } return row; }
From source file:com.android.contacts.ContactSaveService.java
private void createGroup(Intent intent) { String accountType = intent.getStringExtra(EXTRA_ACCOUNT_TYPE); String accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME); String dataSet = intent.getStringExtra(EXTRA_DATA_SET); String label = intent.getStringExtra(EXTRA_GROUP_LABEL); final long[] rawContactsToAdd = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_ADD); // Create the new group final Uri groupUri = mGroupsDao.create(label, new AccountWithDataSet(accountName, accountType, dataSet)); final ContentResolver resolver = getContentResolver(); // If there's no URI, then the insertion failed. Abort early because group members can't be // added if the group doesn't exist if (groupUri == null) { Log.e(TAG, "Couldn't create group with label " + label); return;/*from w ww . j ava 2s. c o m*/ } // Add new group members addMembersToGroup(resolver, rawContactsToAdd, ContentUris.parseId(groupUri)); ContentValues values = new ContentValues(); // TODO: Move this into the contact editor where it belongs. This needs to be integrated // with the way other intent extras that are passed to the // {@link ContactEditorActivity}. values.clear(); values.put(Data.MIMETYPE, GroupMembership.CONTENT_ITEM_TYPE); values.put(GroupMembership.GROUP_ROW_ID, ContentUris.parseId(groupUri)); Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT); callbackIntent.setData(groupUri); // TODO: This can be taken out when the above TODO is addressed callbackIntent.putExtra(ContactsContract.Intents.Insert.DATA, Lists.newArrayList(values)); deliverCallback(callbackIntent); }