List of usage examples for android.database Cursor getCount
int getCount();
From source file:com.android.email.mail.transport.Rfc822Output.java
/** * Write the entire message to an output stream. This method provides buffering, so it is * not necessary to pass in a buffered output stream here. * * @param context system context for accessing the provider * @param messageId the message to write out * @param out the output stream to write the message to * @param appendQuotedText whether or not to append quoted text if this is a reply/forward * * TODO alternative parts (e.g. text+html) are not supported here. *///from w ww . j av a 2s . c om public static void writeTo(Context context, long messageId, OutputStream out, boolean appendQuotedText, boolean sendBcc) throws IOException, MessagingException { Message message = Message.restoreMessageWithId(context, messageId); if (message == null) { // throw something? return; } OutputStream stream = new BufferedOutputStream(out, 1024); Writer writer = new OutputStreamWriter(stream); // Write the fixed headers. Ordering is arbitrary (the legacy code iterated through a // hashmap here). String date = mDateFormat.format(new Date(message.mTimeStamp)); writeHeader(writer, "Date", date); writeEncodedHeader(writer, "Subject", message.mSubject); writeHeader(writer, "Message-ID", message.mMessageId); writeAddressHeader(writer, "From", message.mFrom); writeAddressHeader(writer, "To", message.mTo); writeAddressHeader(writer, "Cc", message.mCc); // Address fields. Note that we skip bcc unless the sendBcc argument is true // SMTP should NOT send bcc headers, but EAS must send it! if (sendBcc) { writeAddressHeader(writer, "Bcc", message.mBcc); } writeAddressHeader(writer, "Reply-To", message.mReplyTo); writeHeader(writer, "MIME-Version", "1.0"); // Analyze message and determine if we have multiparts String text = buildBodyText(context, message, appendQuotedText); Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, messageId); Cursor attachmentsCursor = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION, null, null, null); try { int attachmentCount = attachmentsCursor.getCount(); boolean multipart = attachmentCount > 0; String multipartBoundary = null; String multipartType = "mixed"; // Simplified case for no multipart - just emit text and be done. if (!multipart) { if (text != null) { writeTextWithHeaders(writer, stream, text); } else { writer.write("\r\n"); // a truly empty message } } else { // continue with multipart headers, then into multipart body multipartBoundary = "--_com.android.email_" + System.nanoTime(); // Move to the first attachment; this must succeed because multipart is true attachmentsCursor.moveToFirst(); if (attachmentCount == 1) { // If we've got one attachment and it's an ics "attachment", we want to send // this as multipart/alternative instead of multipart/mixed int flags = attachmentsCursor.getInt(Attachment.CONTENT_FLAGS_COLUMN); if ((flags & Attachment.FLAG_ICS_ALTERNATIVE_PART) != 0) { multipartType = "alternative"; } } writeHeader(writer, "Content-Type", "multipart/" + multipartType + "; boundary=\"" + multipartBoundary + "\""); // Finish headers and prepare for body section(s) writer.write("\r\n"); // first multipart element is the body if (text != null) { writeBoundary(writer, multipartBoundary, false); writeTextWithHeaders(writer, stream, text); } // Write out the attachments until we run out do { writeBoundary(writer, multipartBoundary, false); Attachment attachment = Attachment.getContent(attachmentsCursor, Attachment.class); writeOneAttachment(context, writer, stream, attachment); writer.write("\r\n"); } while (attachmentsCursor.moveToNext()); // end of multipart section writeBoundary(writer, multipartBoundary, true); } } finally { attachmentsCursor.close(); } writer.flush(); out.flush(); }
From source file:com.mwebster.iemail.mail.transport.Rfc822Output.java
/** * Write the entire message to an output stream. This method provides buffering, so it is * not necessary to pass in a buffered output stream here. * * @param context system context for accessing the provider * @param messageId the message to write out * @param out the output stream to write the message to * @param appendQuotedText whether or not to append quoted text if this is a reply/forward * * TODO alternative parts (e.g. text+html) are not supported here. */// ww w .jav a 2 s . c om public static void writeTo(Context context, long messageId, OutputStream out, boolean appendQuotedText, boolean sendBcc) throws IOException, MessagingException { Message message = Message.restoreMessageWithId(context, messageId); if (message == null) { // throw something? return; } OutputStream stream = new BufferedOutputStream(out, 1024); Writer writer = new OutputStreamWriter(stream); // Write the fixed headers. Ordering is arbitrary (the legacy code iterated through a // hashmap here). String date = mDateFormat.format(new Date(message.mTimeStamp)); writeHeader(writer, "Date", date); writeEncodedHeader(writer, "Subject", message.mSubject); writeHeader(writer, "Message-ID", message.mMessageId); writeAddressHeader(writer, "From", message.mFrom); writeAddressHeader(writer, "To", message.mTo); writeAddressHeader(writer, "Cc", message.mCc); // Address fields. Note that we skip bcc unless the sendBcc argument is true // SMTP should NOT send bcc headers, but EAS must send it! if (sendBcc) { writeAddressHeader(writer, "Bcc", message.mBcc); } writeAddressHeader(writer, "Reply-To", message.mReplyTo); writeHeader(writer, "MIME-Version", "1.0"); // Analyze message and determine if we have multiparts String text = buildBodyText(context, message, appendQuotedText); Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, messageId); Cursor attachmentsCursor = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION, null, null, null); try { int attachmentCount = attachmentsCursor.getCount(); boolean multipart = attachmentCount > 0; String multipartBoundary = null; String multipartType = "mixed"; // Simplified case for no multipart - just emit text and be done. if (!multipart) { if (text != null) { writeTextWithHeaders(writer, stream, text); } else { writer.write("\r\n"); // a truly empty message } } else { // continue with multipart headers, then into multipart body multipartBoundary = "--_com.mwebster.iemail." + System.nanoTime(); // Move to the first attachment; this must succeed because multipart is true attachmentsCursor.moveToFirst(); if (attachmentCount == 1) { // If we've got one attachment and it's an ics "attachment", we want to send // this as multipart/alternative instead of multipart/mixed int flags = attachmentsCursor.getInt(Attachment.CONTENT_FLAGS_COLUMN); if ((flags & Attachment.FLAG_ICS_ALTERNATIVE_PART) != 0) { multipartType = "alternative"; } } writeHeader(writer, "Content-Type", "multipart/" + multipartType + "; boundary=\"" + multipartBoundary + "\""); // Finish headers and prepare for body section(s) writer.write("\r\n"); // first multipart element is the body if (text != null) { writeBoundary(writer, multipartBoundary, false); writeTextWithHeaders(writer, stream, text); } // Write out the attachments until we run out do { writeBoundary(writer, multipartBoundary, false); Attachment attachment = Attachment.getContent(attachmentsCursor, Attachment.class); writeOneAttachment(context, writer, stream, attachment); writer.write("\r\n"); } while (attachmentsCursor.moveToNext()); // end of multipart section writeBoundary(writer, multipartBoundary, true); } } finally { attachmentsCursor.close(); } writer.flush(); out.flush(); }
From source file:com.example.android.ennis.barrett.popularmovies.asynchronous.TMDbSyncUtil.java
/** * Removes all data from themovies, thevideos, and thereviews tables. Does not remove data * flagged favorite but the columns istoprated, and ispopular will be set to false, "0". * @param context// www. j av a2 s. c om */ public static void deletePopularAndTopRated(Context context) { ContentResolver contentResolver = context.getContentResolver(); ContentValues removePopAndTop = new ContentValues(2); removePopAndTop.put(TMDbContract.Movies.IS_POPULAR, "0"); removePopAndTop.put(TMDbContract.Movies.IS_TOP_RATED, "0"); contentResolver.update(TMDbContract.Movies.URI, removePopAndTop, TMDbContract.Movies.IS_FAVORITE + " = ?", new String[] { "1" }); contentResolver.delete(TMDbContract.Movies.URI, TMDbContract.Movies.IS_POPULAR + " = ? OR " + TMDbContract.Movies.IS_TOP_RATED + " = ?", new String[] { "1", "1" }); Cursor favoriteMovieIds = getFavoriteIds(context); int numberOfIds = favoriteMovieIds.getCount(); String[] movieIds = new String[numberOfIds]; String whereClauseVideos = ""; String whereClauseReviews = ""; for (int i = 0; i < numberOfIds; i++) { favoriteMovieIds.moveToNext(); movieIds[i] = Integer.toString( favoriteMovieIds.getInt(favoriteMovieIds.getColumnIndex(TMDbContract.Movies.MOVIE_ID))); if (i == numberOfIds - 1) { whereClauseVideos += TMDbContract.Videos.MOVIE_IDS + " != ? "; whereClauseReviews += TMDbContract.Videos.MOVIE_IDS + " != ? "; } else { whereClauseVideos += TMDbContract.Videos.MOVIE_IDS + " != ? OR "; whereClauseReviews += TMDbContract.Reviews.MOVIE_IDS + " != ? OR "; } } contentResolver.delete(TMDbContract.Videos.URI, whereClauseVideos, movieIds); contentResolver.delete(TMDbContract.Reviews.URI, whereClauseReviews, movieIds); }
From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java
public static Date geLastRequest(Context context, PublicScript script, String trollId) { MhDlaSQLHelper helper = new MhDlaSQLHelper(context); SQLiteDatabase database = helper.getReadableDatabase(); Cursor cursor = database.rawQuery(SQL_LAST_REQUEST, new String[] { trollId, script.name() }); Date result = null;/*from w w w. j a va 2 s .c o m*/ if (cursor.getCount() > 0) { cursor.moveToFirst(); long resultTimestamp = cursor.getLong(0); result = new Date(resultTimestamp); } cursor.close(); database.close(); String format = "Last request for category %s (script=%s) and troll=%s is: '%s'"; String message = String.format(format, script.category, script, trollId, result); Log.d(TAG, message); return result; }
From source file:com.onesignal.NotificationOpenedProcessor.java
private static void addChildNotifications(JSONArray dataArray, String summaryGroup, SQLiteDatabase writableDb) { String[] retColumn = { NotificationTable.COLUMN_NAME_FULL_DATA }; String[] whereArgs = { summaryGroup }; Cursor cursor = writableDb.query(NotificationTable.TABLE_NAME, retColumn, NotificationTable.COLUMN_NAME_GROUP_ID + " = ? AND " + // Where String NotificationTable.COLUMN_NAME_DISMISSED + " = 0 AND " + NotificationTable.COLUMN_NAME_OPENED + " = 0 AND " + NotificationTable.COLUMN_NAME_IS_SUMMARY + " = 0", whereArgs, null, null, null); if (cursor.getCount() > 1) { cursor.moveToFirst();/*from ww w.j a v a2 s. c o m*/ do { try { String jsonStr = cursor .getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_FULL_DATA)); dataArray.put(new JSONObject(jsonStr)); } catch (Throwable t) { OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Could not parse JSON of sub notification in group: " + summaryGroup); } } while (cursor.moveToNext()); } cursor.close(); }
From source file:eu.e43.impeller.Utils.java
public static JSONObject findPost(Context ctx, Content.Uris uris, JSONObject object) throws JSONException { Cursor res = ctx.getContentResolver().query(uris.activitiesUri, new String[] { "_json" }, "actor=? AND verb='post' AND object.id=?", new String[] { object.getJSONObject("author").getString("id"), object.getString("id") }, null); try {/*from w w w . j av a2s .c o m*/ if (res.getCount() > 0) { res.moveToFirst(); return new JSONObject(res.getString(0)); } else { return null; } } finally { res.close(); } }
From source file:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * @param cr/*from w w w. j a v a 2 s .co m*/ * @param item * @param prefix * @return a list of all the tags attached to a given item */ public static Set<String> getTags(ContentResolver cr, Uri item, String prefix) { final Cursor tags = cr.query(Uri.withAppendedPath(item, Tag.PATH), Tag.DEFAULT_PROJECTION, null, null, null); final Set<String> tagSet = new HashSet<String>(tags.getCount()); final int tagColumn = tags.getColumnIndex(Tag._NAME); final Predicate<String> predicate = getPrefixPredicate(prefix); for (tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) { final String tag = tags.getString(tagColumn); if (predicate.apply(tag)) { final int separatorIndex = tag.indexOf(PREFIX_SEPARATOR); if (separatorIndex == -1) { tagSet.add(tag); } else { tagSet.add(tag.substring(separatorIndex + 1)); } } } tags.close(); return tagSet; }
From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java
protected static int computeRequestCount(Context context, ScriptCategory category, String trollId) { MhDlaSQLHelper helper = new MhDlaSQLHelper(context); SQLiteDatabase database = helper.getReadableDatabase(); Calendar instance = Calendar.getInstance(); instance.add(Calendar.HOUR_OF_DAY, -24); Date sinceDate = instance.getTime(); Cursor cursor = database.rawQuery(SQL_COUNT, new String[] { trollId, category.name(), "" + sinceDate.getTime() }); int result = 0; if (cursor.getCount() > 0) { cursor.moveToFirst();// www . j a v a2s .com result = cursor.getInt(0); } cursor.close(); database.close(); String format = "Quota for category %s and troll=%s since '%s' is: %d"; String message = String.format(format, category, trollId, sinceDate, result); Log.d(TAG, message); return result; }
From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java
public static Date geLastUpdate(Context context, PublicScript script, String trollId) { MhDlaSQLHelper helper = new MhDlaSQLHelper(context); SQLiteDatabase database = helper.getReadableDatabase(); Cursor cursor = database.rawQuery(SQL_LAST_UPDATE, new String[] { trollId, script.name(), MhDlaSQLHelper.STATUS_SUCCESS }); Date result = null;//from w ww. jav a 2 s .com if (cursor.getCount() > 0) { cursor.moveToFirst(); long resultTimestamp = cursor.getLong(0); result = new Date(resultTimestamp); } cursor.close(); database.close(); String format = "Last update for category %s (script=%s) and troll=%s is: '%s'"; String message = String.format(format, script.category, script, trollId, result); Log.d(TAG, message); return result; }
From source file:com.mail163.email.mail.transport.Rfc822Output.java
/** * Write the entire message to an output stream. This method provides buffering, so it is * not necessary to pass in a buffered output stream here. * * @param context system context for accessing the provider * @param messageId the message to write out * @param out the output stream to write the message to * @param appendQuotedText whether or not to append quoted text if this is a reply/forward * * TODO alternative parts (e.g. text+html) are not supported here. *//*from ww w .j a v a2 s. co m*/ public static void writeTo(Context context, long messageId, OutputStream out, boolean appendQuotedText, boolean sendBcc) throws IOException, MessagingException { Message message = Message.restoreMessageWithId(context, messageId); if (message == null) { // throw something? return; } OutputStream stream = new BufferedOutputStream(out, 1024); Writer writer = new OutputStreamWriter(stream); // Write the fixed headers. Ordering is arbitrary (the legacy code iterated through a // hashmap here). String date = DATE_FORMAT.format(new Date(message.mTimeStamp)); writeHeader(writer, "Date", date); writeEncodedHeader(writer, "Subject", message.mSubject); writeEncodedHeader(writer, "X-Priority", message.mPriority); writeHeader(writer, "Message-ID", message.mMessageId); writeAddressHeader(writer, "From", message.mFrom); writeAddressHeader(writer, "To", message.mTo); writeAddressHeader(writer, "Cc", message.mCc); // Address fields. Note that we skip bcc unless the sendBcc argument is true // SMTP should NOT send bcc headers, but EAS must send it! if (sendBcc) { writeAddressHeader(writer, "Bcc", message.mBcc); } writeAddressHeader(writer, "Reply-To", message.mReplyTo); writeHeader(writer, "MIME-Version", "1.0"); // Analyze message and determine if we have multiparts String text = buildBodyText(context, message, appendQuotedText); if (!Global.sendMessage.equals("")) { if (text.endsWith(Global.sendMessage)) {// text = text.substring(0, text.lastIndexOf(Global.sendMessage)); text = text + Global.sendMessage; } else { text = text + "\n\n\n" + Global.sendMessage; } } Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, messageId); Cursor attachmentsCursor = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION, null, null, null); try { int attachmentCount = attachmentsCursor.getCount(); boolean multipart = attachmentCount > 0; String multipartBoundary = null; String multipartType = "mixed"; // Simplified case for no multipart - just emit text and be done. if (!multipart) { if (text != null) { writeTextWithHeaders(writer, stream, text); } else { writer.write("\r\n"); // a truly empty message } } else { // continue with multipart headers, then into multipart body multipartBoundary = "--_com.warmtel.yimail_" + System.nanoTime(); // Move to the first attachment; this must succeed because multipart is true attachmentsCursor.moveToFirst(); if (attachmentCount == 1) { // If we've got one attachment and it's an ics "attachment", we want to send // this as multipart/alternative instead of multipart/mixed int flags = attachmentsCursor.getInt(Attachment.CONTENT_FLAGS_COLUMN); if ((flags & Attachment.FLAG_ICS_ALTERNATIVE_PART) != 0) { multipartType = "alternative"; } } writeHeader(writer, "Content-Type", "multipart/" + multipartType + "; boundary=\"" + multipartBoundary + "\""); // Finish headers and prepare for body section(s) writer.write("\r\n"); // first multipart element is the body if (text != null) { writeBoundary(writer, multipartBoundary, false); writeTextWithHeaders(writer, stream, text); } // Write out the attachments until we run out do { writeBoundary(writer, multipartBoundary, false); Attachment attachment = Attachment.getContent(attachmentsCursor, Attachment.class); writeOneAttachment(context, writer, stream, attachment); writer.write("\r\n"); } while (attachmentsCursor.moveToNext()); // end of multipart section writeBoundary(writer, multipartBoundary, true); } } finally { attachmentsCursor.close(); } writer.flush(); out.flush(); }