List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:utils.database.sqlite.data.AFieldData.java
/** * /* w ww . ja va 2 s . c o m*/ * Create the object from cursor db. * * @param t * the table. * @param cursor */ public AFieldData(ITables t, Cursor cursor) { this.tab = t; IColumns[] values = t.getColumns(); if (cursor != null) { for (IColumns c : values) { String name = ((Enum) c).name(); if (c.getType().equals(ConstantsDB.INTEGER)) { integerValue.put(c, cursor.getInt(cursor.getColumnIndex(name))); } else if (c.getType().equals(ConstantsDB.TEXT)) { stringValue.put(c, cursor.getString(cursor.getColumnIndex(name))); } else if (c.getType().equals(ConstantsDB.REAL)) { doubleValue.put(c, cursor.getDouble(cursor.getColumnIndex(name))); } } } }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static U1Node getNodeByResourcePath(String resourcePath) { String[] selectionArgs = new String[] { resourcePath }; String selection = Nodes.NODE_RESOURCE_PATH + "=?"; String[] projection = Nodes.getDefaultProjection(); final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); if (c != null) { try {/*from w w w . j a v a2 s .c om*/ if (c.moveToFirst()) { String key; U1NodeKind kind; Boolean isLive = true; String path; String parentPath; String volumePath; Date whenCreated; Date whenChanged; Long generation; Long generationCreated; String contentPath; key = c.getString(c.getColumnIndex(Nodes.NODE_KEY)); kind = U1NodeKind .valueOf(c.getString(c.getColumnIndex(Nodes.NODE_KIND)).toUpperCase(Locale.US)); isLive = c.getInt(c.getColumnIndex(Nodes.NODE_IS_LIVE)) != 0; path = c.getString(c.getColumnIndex(Nodes.NODE_PATH)); parentPath = c.getString(c.getColumnIndex(Nodes.NODE_PARENT_PATH)); volumePath = c.getString(c.getColumnIndex(Nodes.NODE_VOLUME_PATH)); whenCreated = new Date(c.getLong(c.getColumnIndex(Nodes.NODE_WHEN_CREATED))); whenChanged = new Date(c.getLong(c.getColumnIndex(Nodes.NODE_WHEN_CHANGED))); generation = c.getLong(c.getColumnIndex(Nodes.NODE_GENERATION)); generationCreated = c.getLong(c.getColumnIndex(Nodes.NODE_GENERATION_CREATED)); contentPath = c.getString(c.getColumnIndex(Nodes.NODE_CONTENT_PATH)); return new U1Node(resourcePath, kind, isLive, path, parentPath, volumePath, key, whenCreated, whenChanged, generation, generationCreated, contentPath); } else { return null; } } finally { c.close(); } } return null; }
From source file:com.android.browser.BookmarksPageCallbacks.java
boolean canEdit(Cursor c) { int type = c.getInt(BookmarksLoader.COLUMN_INDEX_TYPE); return type == BrowserContract.Bookmarks.BOOKMARK_TYPE_BOOKMARK || type == BrowserContract.Bookmarks.BOOKMARK_TYPE_FOLDER; }
From source file:com.android.mms.MmsConfig.java
public static int updateAllQuicktexts() { Cursor cursor = mContext.getContentResolver().query(Telephony.MmsSms.CONTENT_URI_QUICKTEXT, null, null, null, null);//from w w w .j a v a 2s . com allQuickTextIds.clear(); allQuickTexts.clear(); String[] defaultTexts = mContext.getResources().getStringArray(R.array.default_quick_texts); int maxId = defaultTexts.length; if (cursor != null) { try { while (cursor.moveToNext()) { int qtId = cursor.getInt(0); allQuickTextIds.add(qtId); String qtText = cursor.getString(1); if (qtText != null && !qtText.isEmpty()) { allQuickTexts.add(qtText); } else { allQuickTexts.add(defaultTexts[qtId - 1]); } if (qtId > maxId) { maxId = qtId; } } } finally { cursor.close(); } } return maxId; }
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. *//*ww w .ja v a2 s .com*/ 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.android.providers.contacts.ContactsSyncAdapter.java
static private void addContactMethodsToContactEntry(ContentResolver cr, long personId, ContactEntry entry) throws ParseException { Cursor c = cr.query(ContactMethods.CONTENT_URI, null, "person=" + personId, null, null); int kindIndex = c.getColumnIndexOrThrow(ContactMethods.KIND); int dataIndex = c.getColumnIndexOrThrow(ContactMethods.DATA); int auxDataIndex = c.getColumnIndexOrThrow(ContactMethods.AUX_DATA); try {/*from w ww . ja va 2s.co m*/ while (c.moveToNext()) { int kind = c.getInt(kindIndex); switch (kind) { case Contacts.KIND_IM: { ImAddress address = new ImAddress(); cursorToContactsElement(address, c, PROVIDER_TYPE_TO_ENTRY_IM); address.setAddress(c.getString(dataIndex)); Object object = ContactMethods.decodeImProtocol(c.getString(auxDataIndex)); if (object == null) { address.setProtocolPredefined(ImAddress.PROTOCOL_NONE); } else if (object instanceof Integer) { address.setProtocolPredefined(PROVIDER_IM_PROTOCOL_TO_ENTRY_PROTOCOL.get((Integer) object)); } else { if (!(object instanceof String)) { throw new IllegalArgumentException("expected an String, " + object); } address.setProtocolPredefined(ImAddress.PROTOCOL_CUSTOM); address.setProtocolCustom((String) object); } entry.addImAddress(address); break; } case Contacts.KIND_POSTAL: { PostalAddress address = new PostalAddress(); cursorToContactsElement(address, c, PROVIDER_TYPE_TO_ENTRY_POSTAL); address.setValue(c.getString(dataIndex)); entry.addPostalAddress(address); break; } case Contacts.KIND_EMAIL: { EmailAddress address = new EmailAddress(); cursorToContactsElement(address, c, PROVIDER_TYPE_TO_ENTRY_EMAIL); address.setAddress(c.getString(dataIndex)); entry.addEmailAddress(address); break; } } } } finally { if (c != null) c.close(); } }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesSchedulesSyncService.java
/** * Check the ferries schedules table for any starred entries. If we find some, save them * to a list so we can re-star those after we flush the database. *//*from w ww. j a v a2 s . c o m*/ private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(FerriesSchedules.CONTENT_URI, new String[] { FerriesSchedules.FERRIES_SCHEDULE_ID }, FerriesSchedules.FERRIES_SCHEDULE_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:com.andrew.apollo.utils.MusicUtils.java
private static int getFirstId(Cursor cursor, int id) { if (cursor != null) { cursor.moveToFirst();/* www . j av a2s . co m*/ if (!cursor.isAfterLast()) { id = cursor.getInt(0); } cursor.close(); } return id; }
From source file:com.murrayc.galaxyzoo.app.syncadapter.SyncAdapter.java
private int getNotDoneCount() { final ContentResolver resolver = getContentResolver(); final Cursor c = resolver.query(Item.ITEMS_URI, PROJECTION_COUNT_AS_COUNT, WHERE_CLAUSE_NOT_DONE, null, null);//from www. ja v a 2s . co m c.moveToFirst(); final int result = c.getInt(0); c.close(); return result; }
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. *///from ww w. j a v a 2 s.c o 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 = 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(); }