List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:Main.java
/** * Try to get the exif orientation of the passed image uri * * @param context// w w w.j a v a 2 s .co m * @param uri * @return */ public static int getExifOrientation(Context context, Uri uri) { final String scheme = uri.getScheme(); ContentProviderClient provider = null; if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) { return getExifOrientation(uri.getPath()); } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) { try { provider = context.getContentResolver().acquireContentProviderClient(uri); } catch (SecurityException e) { return 0; } if (provider != null) { Cursor result; try { result = provider.query(uri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.Images.ImageColumns.DATA }, null, null, null); } catch (Exception e) { e.printStackTrace(); return 0; } if (result == null) { return 0; } int orientationColumnIndex = result.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION); int dataColumnIndex = result.getColumnIndex(MediaStore.Images.ImageColumns.DATA); try { if (result.getCount() > 0) { result.moveToFirst(); int rotation = 0; if (orientationColumnIndex > -1) { rotation = result.getInt(orientationColumnIndex); } if (dataColumnIndex > -1) { String path = result.getString(dataColumnIndex); rotation |= getExifOrientation(path); } return rotation; } } finally { result.close(); } } } return 0; }
From source file:com.eTilbudsavis.etasdk.DbHelper.java
/** * Method does not close the Cursor./* w w w . j av a 2s . c o m*/ * @param c with data * @return A shoppinglistitem */ public static ShoppinglistItem cursorToSli(Cursor c) { ShoppinglistItem sli = new ShoppinglistItem(); sli.setId(c.getString(c.getColumnIndex(ID))); sli.setErn(c.getString(c.getColumnIndex(ERN))); sli.setModified(Utils.stringToDate(c.getString(c.getColumnIndex(MODIFIED)))); sli.setDescription(c.getString(c.getColumnIndex(DESCRIPTION))); sli.setCount(c.getInt(c.getColumnIndex(COUNT))); sli.setTick(0 < c.getInt(c.getColumnIndex(TICK))); sli.setOfferId(c.getString(c.getColumnIndex(OFFER_ID))); sli.setCreator(c.getString(c.getColumnIndex(CREATOR))); sli.setShoppinglistId(c.getString(c.getColumnIndex(SHOPPINGLIST_ID))); sli.setState(c.getInt(c.getColumnIndex(STATE))); sli.setPreviousId(c.getString(c.getColumnIndex(PREVIOUS_ID))); String meta = c.getString(c.getColumnIndex(META)); try { sli.setMeta(meta == null ? null : new JSONObject(meta)); } catch (JSONException e) { EtaLog.e(TAG, null, e); } sli.setUserId(c.getInt(c.getColumnIndex(USER))); return sli; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static long getGroupLastFetchedNumber(String group, Context context) { long lastFetched = -1; DBHelper dbhelper = new DBHelper(context); SQLiteDatabase readdb = dbhelper.getReadableDatabase(); String fQuery = "SELECT lastFetched FROM subscribed_groups WHERE name=" + esc(group); Cursor cur = readdb.rawQuery(fQuery, null); if (cur.getCount() > 0) { cur.moveToFirst();//from w w w.jav a 2s .co m lastFetched = cur.getInt(0); } cur.close(); readdb.close(); dbhelper.close(); return lastFetched; }
From source file:busradar.madison.StopDialog.java
static RouteURL[] get_time_urls(int stopid) { Cursor c = G.db.rawQuery("SELECT url, route " + "FROM routestops " + "WHERE stopid = ? " + "ORDER BY route", new String[] { stopid + "" }); RouteURL[] list = new RouteURL[c.getCount()]; //ArrayList<RouteURL> list = new ArrayLst<RouteURL>(); //int last = -1; int i = 0;/*from w w w .ja v a 2s . co m*/ while (c.moveToNext()) { RouteURL r = new RouteURL(); r.url = c.getString(0); r.route = c.getInt(1); list[i++] = r; } c.close(); return list; }
From source file:com.eTilbudsavis.etasdk.DbHelper.java
public static Share cursorToShare(Cursor c, Shoppinglist sl) { String email = c.getString(c.getColumnIndex(EMAIL)); String acceptUrl = c.getString(c.getColumnIndex(ACCEPT_URL)); String access = c.getString(c.getColumnIndex(ACCESS)); Share s = new Share(email, access, acceptUrl); s.setShoppinglistId(sl.getId());/*from w w w . ja v a 2 s . c om*/ s.setName(c.getString(c.getColumnIndex(NAME))); s.setAccepted(0 < c.getInt(c.getColumnIndex(ACCEPTED))); s.setState(c.getInt(c.getColumnIndex(STATE))); return s; }
From source file:com.eTilbudsavis.etasdk.DbHelper.java
public static Shoppinglist cursorToSl(Cursor c) { Shoppinglist sl = Shoppinglist.fromName(c.getString(c.getColumnIndex(NAME))); sl.setId(c.getString(c.getColumnIndex(ID))); sl.setErn(c.getString(c.getColumnIndex(ERN))); String mod = c.getString(c.getColumnIndex(MODIFIED)); sl.setModified(Utils.stringToDate(mod)); sl.setAccess(c.getString(c.getColumnIndex(ACCESS))); sl.setState(c.getInt(c.getColumnIndex(STATE))); sl.setPreviousId(c.getString(c.getColumnIndex(PREVIOUS_ID))); sl.setType(c.getString(c.getColumnIndex(TYPE))); String meta = c.getString(c.getColumnIndex(META)); try {/* ww w . j a v a2s . c o m*/ sl.setMeta(meta == null ? null : new JSONObject(meta)); } catch (JSONException e) { EtaLog.e(TAG, null, e); } sl.setUserId(c.getInt(c.getColumnIndex(USER))); return sl; }
From source file:com.alchemiasoft.common.model.Book.java
public static Book oneFrom(@NonNull Cursor c) { final Book book = new Book(); int index;//from w w w. j ava 2 s . co m if ((index = c.getColumnIndex(BookDB.Book.SERVER_ID)) > -1) { book.mServerId = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book._ID)) > -1) { book.mId = c.getLong(index); } if ((index = c.getColumnIndex(BookDB.Book.TITLE)) > -1) { book.mTitle = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book.AUTHOR)) > -1) { book.mAuthor = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book.SOURCE)) > -1) { book.mSource = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book.DESCRIPTION)) > -1) { book.mDescription = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book.PAGES)) > -1) { book.mPages = c.getInt(index); } if ((index = c.getColumnIndex(BookDB.Book.NOTES)) > -1) { book.mNotes = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book.OWNED)) > -1) { book.mOwned = c.getInt(index) == 1 ? true : false; } if ((index = c.getColumnIndex(BookDB.Book.UPDATED_AT)) > -1) { book.mUpdatedAt = c.getLong(index); } return book; }
From source file:com.android.emailcommon.provider.Account.java
/** * Clear all account hold flags that are set. * * (This will trigger watchers, and in particular will cause EAS to try and resync the * account(s).)//from w w w .ja v a2 s .c om */ public static void clearSecurityHoldOnAllAccounts(Context context) { ContentResolver resolver = context.getContentResolver(); Cursor c = resolver.query(Account.CONTENT_URI, ACCOUNT_FLAGS_PROJECTION, SECURITY_NONZERO_SELECTION, null, null); try { while (c.moveToNext()) { int flags = c.getInt(ACCOUNT_FLAGS_COLUMN_FLAGS); if (0 != (flags & FLAGS_SECURITY_HOLD)) { ContentValues cv = new ContentValues(); cv.put(AccountColumns.FLAGS, flags & ~FLAGS_SECURITY_HOLD); long accountId = c.getLong(ACCOUNT_FLAGS_COLUMN_ID); Uri uri = ContentUris.withAppendedId(Account.CONTENT_URI, accountId); resolver.update(uri, cv, null, null); } } } finally { c.close(); } }
From source file:com.android.email.LegacyConversions.java
/** * Add a single attachment part to the message * * This will skip adding attachments if they are already found in the attachments table. * The heuristic for this will fail (false-positive) if two identical attachments are * included in a single POP3 message./*from w ww . j a v a2 s. c om*/ * TODO: Fix that, by (elsewhere) simulating an mLocation value based on the attachments * position within the list of multipart/mixed elements. This would make every POP3 attachment * unique, and might also simplify the code (since we could just look at the positions, and * ignore the filename, etc.) * * TODO: Take a closer look at encoding and deal with it if necessary. * * @param context a context for file operations * @param localMessage the attachments will be built against this message * @param part a single attachment part from POP or IMAP * @param upgrading true if upgrading a local account - handle attachments differently * @throws IOException */ private static void addOneAttachment(Context context, EmailContent.Message localMessage, Part part, boolean upgrading) throws MessagingException, IOException { Attachment localAttachment = new Attachment(); // Transfer fields from mime format to provider format String contentType = MimeUtility.unfoldAndDecode(part.getContentType()); String name = MimeUtility.getHeaderParameter(contentType, "name"); if (name == null) { String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition()); name = MimeUtility.getHeaderParameter(contentDisposition, "filename"); } // Select the URI for the new attachments. For attachments downloaded by the legacy // IMAP/POP code, this is not determined yet, so is null (it will be rewritten below, // or later, when the actual attachment file is created.) // // When upgrading older local accounts, the URI represents a local asset (e.g. a photo) // so we need to preserve the URI. // TODO This works for outgoing messages, where the URI does not change. May need // additional logic to handle the case of rewriting URI for received attachments. Uri contentUri = null; String contentUriString = null; if (upgrading) { Body body = part.getBody(); if (body instanceof LocalStore.LocalAttachmentBody) { LocalStore.LocalAttachmentBody localBody = (LocalStore.LocalAttachmentBody) body; contentUri = localBody.getContentUri(); if (contentUri != null) { contentUriString = contentUri.toString(); } } } // Find size, if available, via a number of techniques: long size = 0; if (upgrading) { // If upgrading a legacy account, the size must be recaptured from the data source if (contentUri != null) { Cursor metadataCursor = context.getContentResolver().query(contentUri, ATTACHMENT_META_COLUMNS_PROJECTION, null, null, null); if (metadataCursor != null) { try { if (metadataCursor.moveToFirst()) { size = metadataCursor.getInt(ATTACHMENT_META_COLUMNS_SIZE); } } finally { metadataCursor.close(); } } } // TODO: a downloaded legacy attachment - see if the above code works } else { // Incoming attachment: Try to pull size from disposition (if not downloaded yet) String disposition = part.getDisposition(); if (disposition != null) { String s = MimeUtility.getHeaderParameter(disposition, "size"); if (s != null) { size = Long.parseLong(s); } } } // Get partId for unloaded IMAP attachments (if any) // This is only provided (and used) when we have structure but not the actual attachment String[] partIds = part.getHeader(MimeHeader.HEADER_ANDROID_ATTACHMENT_STORE_DATA); String partId = partIds != null ? partIds[0] : null; localAttachment.mFileName = name; localAttachment.mMimeType = part.getMimeType(); localAttachment.mSize = size; // May be reset below if file handled localAttachment.mContentId = part.getContentId(); localAttachment.mContentUri = contentUriString; localAttachment.mMessageKey = localMessage.mId; localAttachment.mLocation = partId; localAttachment.mEncoding = "B"; // TODO - convert other known encodings if (DEBUG_ATTACHMENTS) { Log.d(Email.LOG_TAG, "Add attachment " + localAttachment); } // To prevent duplication - do we already have a matching attachment? // The fields we'll check for equality are: // mFileName, mMimeType, mContentId, mMessageKey, mLocation // NOTE: This will false-positive if you attach the exact same file, twice, to a POP3 // message. We can live with that - you'll get one of the copies. Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, localMessage.mId); Cursor cursor = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION, null, null, null); boolean attachmentFoundInDb = false; try { while (cursor.moveToNext()) { Attachment dbAttachment = new Attachment().restore(cursor); // We test each of the fields here (instead of in SQL) because they may be // null, or may be strings. if (stringNotEqual(dbAttachment.mFileName, localAttachment.mFileName)) continue; if (stringNotEqual(dbAttachment.mMimeType, localAttachment.mMimeType)) continue; if (stringNotEqual(dbAttachment.mContentId, localAttachment.mContentId)) continue; if (stringNotEqual(dbAttachment.mLocation, localAttachment.mLocation)) continue; // We found a match, so use the existing attachment id, and stop looking/looping attachmentFoundInDb = true; localAttachment.mId = dbAttachment.mId; if (DEBUG_ATTACHMENTS) { Log.d(Email.LOG_TAG, "Skipped, found db attachment " + dbAttachment); } break; } } finally { cursor.close(); } // Save the attachment (so far) in order to obtain an id if (!attachmentFoundInDb) { localAttachment.save(context); } // If an attachment body was actually provided, we need to write the file now if (!upgrading) { saveAttachmentBody(context, part, localAttachment, localMessage.mAccountKey); } if (localMessage.mAttachments == null) { localMessage.mAttachments = new ArrayList<Attachment>(); } localMessage.mAttachments.add(localAttachment); localMessage.mFlagAttachment = true; }
From source file:net.ecfirm.ec.ec1.model.EcModel.java
/** * @deprecated not yet used *///from w w w .j a v a 2s . c o m public int getModified(long value) { String[] cols = { "modified" }; Cursor cursor = this.getColumns(this.nameModel, value, cols); try { return cursor.getInt(0); } catch (Exception e) { app.log(e); return 0; } }