List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:com.samknows.measurement.storage.TestResultDataSource.java
private TestResult cursorToTestResult(Cursor cursor) { long id = cursor.getLong(columnIdx.get(SKSQLiteHelper.TR_COLUMN_ID)); String type = cursor.getString(columnIdx.get(SKSQLiteHelper.TR_COLUMN_TYPE)); long dtime = cursor.getLong(columnIdx.get(SKSQLiteHelper.TR_COLUMN_DTIME)); String location = cursor.getString(columnIdx.get(SKSQLiteHelper.TR_COLUMN_LOCATION)); long success = cursor.getLong(columnIdx.get(SKSQLiteHelper.TR_COLUMN_SUCCESS)); double result = cursor.getDouble(columnIdx.get(SKSQLiteHelper.TR_COLUMN_RESULT)); return new TestResult(type, dtime, location, success, result); }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
/** * Calculates directory content size, recursively if necessary. * /*from w w w.j a v a2 s .c om*/ * @param resourcePath * the directory resource path to calculate size of * @param recursive * the flag indicating recursive calculation * @return the resorucePath defined directory size */ public static long getDirectorySize(final String resourcePath, final boolean recursive) { final String[] projection = new String[] { Nodes.NODE_RESOURCE_PATH, Nodes.NODE_KIND, Nodes.NODE_SIZE }; final String selection = Nodes.NODE_PARENT_PATH + "=?"; final String[] selectionArgs = new String[] { resourcePath }; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); U1NodeKind kind; long size = 0L; try { if (c.moveToFirst()) { do { kind = U1NodeKind .valueOf(c.getString(c.getColumnIndex(Nodes.NODE_KIND)).toUpperCase(Locale.US)); if (U1NodeKind.FILE == kind) { size += c.getLong(c.getColumnIndex(Nodes.NODE_SIZE)); } else if (U1NodeKind.DIRECTORY == kind && recursive) { final String subDirResourcePath = c.getString(c.getColumnIndex(Nodes.NODE_RESOURCE_PATH)); size += getDirectorySize(subDirResourcePath, true); } } while (c.moveToNext()); } } finally { c.close(); } return size; }
From source file:com.android.emailcommon.provider.Account.java
/** * Return the id of the default account. If one hasn't been explicitly specified, return the * first one in the database. If no account exists, returns {@link #NO_ACCOUNT}. * * @param context the caller's context// w ww . j a v a 2s . c o m * @param lastUsedAccountId the last used account id, which is the basis of the default account */ public static long getDefaultAccountId(final Context context, final long lastUsedAccountId) { final Cursor cursor = context.getContentResolver().query(CONTENT_URI, ID_PROJECTION, null, null, null); long firstAccount = NO_ACCOUNT; try { if (cursor != null && cursor.moveToFirst()) { do { final long accountId = cursor.getLong(Account.ID_PROJECTION_COLUMN); if (accountId == lastUsedAccountId) { return accountId; } if (firstAccount == NO_ACCOUNT) { firstAccount = accountId; } } while (cursor.moveToNext()); } } finally { if (cursor != null) { cursor.close(); } } return firstAccount; }
From source file:ro.weednet.contactssync.platform.ContactManager.java
public static void updateContact(Context context, ContentResolver resolver, RawContact rawContact, boolean updateAvatar, boolean inSync, long rawContactId, BatchOperation batchOperation) { ContactsSync app = ContactsSync.getInstance(); boolean existingAvatar = false; final Cursor c = resolver.query(DataQuery.CONTENT_URI, DataQuery.PROJECTION, DataQuery.SELECTION, new String[] { String.valueOf(rawContactId) }, null); final ContactOperations contactOp = ContactOperations.updateExistingContact(context, rawContactId, inSync, batchOperation);//from w ww .jav a2 s. com try { // Iterate over the existing rows of data, and update each one // with the information we received from the server. while (c.moveToNext()) { final long id = c.getLong(DataQuery.COLUMN_ID); final String mimeType = c.getString(DataQuery.COLUMN_MIMETYPE); final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, id); if (mimeType.equals(StructuredName.CONTENT_ITEM_TYPE)) { contactOp.updateName(uri, c.getString(DataQuery.COLUMN_GIVEN_NAME), c.getString(DataQuery.COLUMN_FAMILY_NAME), rawContact.getFirstName(), rawContact.getLastName()); /* } else if (mimeType.equals(Phone.CONTENT_ITEM_TYPE)) { final int type = c.getInt(DataQuery.COLUMN_PHONE_TYPE); if (type == Phone.TYPE_MOBILE) { existingCellPhone = true; contactOp.updatePhone( c.getString(DataQuery.COLUMN_PHONE_NUMBER), "5345345", uri); } else if (type == Phone.TYPE_HOME) { existingHomePhone = true; contactOp.updatePhone( c.getString(DataQuery.COLUMN_PHONE_NUMBER), "5345345", uri); } else if (type == Phone.TYPE_WORK) { existingWorkPhone = true; contactOp.updatePhone( c.getString(DataQuery.COLUMN_PHONE_NUMBER), "5345345", uri); } */ } else if (mimeType.equals(Photo.CONTENT_ITEM_TYPE)) { existingAvatar = true; if (app.getSyncType() == ContactsSync.SyncType.LEGACY) { contactOp.updateAvatar(c.getString(DataQuery.COLUMN_DATA1), rawContact.getAvatarUrl(), uri); } } } // while } finally { c.close(); } // Add the avatar if we didn't update the existing avatar if (app.getSyncType() != ContactsSync.SyncType.HARD && !existingAvatar) { contactOp.addAvatar(rawContact.getAvatarUrl()); } // If we don't have a status profile, then create one. This could // happen for contacts that were created on the client - we don't // create the status profile until after the first sync... final String serverId = rawContact.getUid(); final long profileId = lookupProfile(resolver, serverId); if (profileId <= 0) { contactOp.addProfileAction(serverId); } }
From source file:edu.pdx.cecs.orcycle.SegmentData.java
void populateDetails() { mDb.openReadOnly();//from w w w .j av a2 s .c o m try { Cursor cursor = mDb.fetchSegment(segmentId); try { tripId = cursor.getLong(cursor.getColumnIndex("tripid")); rating = cursor.getInt(cursor.getColumnIndex("rating")); details = cursor.getString(cursor.getColumnIndex("details")); startIndex = cursor.getInt(cursor.getColumnIndex("startindex")); endIndex = cursor.getInt(cursor.getColumnIndex("endindex")); segmentStatus = cursor.getInt(cursor.getColumnIndex("status")); } finally { cursor.close(); } } finally { mDb.close(); } }
From source file:com.liferay.alerts.model.Alert.java
public Alert(Cursor cursor) { _id = cursor.getLong(cursor.getColumnIndex(ID)); _userId = cursor.getLong(cursor.getColumnIndex(USER_ID)); try {//from w ww . ja v a2 s. c o m _payload = new JSONObject(cursor.getString(cursor.getColumnIndex(PAYLOAD))); } catch (JSONException je) { } _read = (cursor.getInt(cursor.getColumnIndex(READ)) == 1); _timestamp = cursor.getLong(cursor.getColumnIndex(TIMESTAMP)); }
From source file:com.jaspersoft.android.jaspermobile.util.ProfileHelper.java
public JsServerProfile createProfileFromCursor(Cursor cursor) { long id = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID)); ServerProfiles dbProfile = new ServerProfiles(cursor); return new JsServerProfile(id, dbProfile.getAlias(), dbProfile.getServerUrl(), dbProfile.getOrganization(), dbProfile.getUsername(), dbProfile.getPassword()); }
From source file:fr.mixit.android.io.JsonHandlerApplyTalks.java
private static boolean isItemUpdated(Uri uri, JSONObject item, ContentResolver resolver) throws JSONException { final Cursor cursor = resolver.query(uri, MixItContract.Sessions.PROJ_DETAIL.PROJECTION, null, null, null); try {/* w ww . j a v a 2s . c o m*/ if (!cursor.moveToFirst()) { return false; } String curTitle = cursor.getString(MixItContract.Sessions.PROJ_DETAIL.TITLE); if (TextUtils.isEmpty(curTitle)) { curTitle = EMPTY; } String curSummary = cursor.getString(MixItContract.Sessions.PROJ_DETAIL.SUMMARY); if (TextUtils.isEmpty(curSummary)) { curSummary = EMPTY; } String curDesc = cursor.getString(MixItContract.Sessions.PROJ_DETAIL.DESC); if (TextUtils.isEmpty(curDesc)) { curDesc = EMPTY; } final long curStart = cursor.getLong(MixItContract.Sessions.PROJ_DETAIL.START); final long curEnd = cursor.getLong(MixItContract.Sessions.PROJ_DETAIL.END); String curRoomId = cursor.getString(MixItContract.Sessions.PROJ_DETAIL.ROOM_ID); if (TextUtils.isEmpty(curRoomId)) { curRoomId = EMPTY; } final int curNbVotes = cursor.getInt(MixItContract.Sessions.PROJ_DETAIL.NB_VOTES); // final int curMyVote = cursor.getInt(MixItContract.Sessions.PROJ_DETAIL.MY_VOTE); // final int curIsFavorite = cursor.getInt(MixItContract.Sessions.PROJ_DETAIL.IS_FAVORITE); String curFormat = cursor.getString(MixItContract.Sessions.PROJ_DETAIL.FORMAT); if (TextUtils.isEmpty(curFormat)) { curFormat = EMPTY; } String curLevel = cursor.getString(MixItContract.Sessions.PROJ_DETAIL.LEVEL); if (TextUtils.isEmpty(curLevel)) { curLevel = EMPTY; } String curLang = cursor.getString(MixItContract.Sessions.PROJ_DETAIL.LANG); if (TextUtils.isEmpty(curLang)) { curLang = EMPTY; } final String newTitle = item.has(TAG_TITLE) ? item.getString(TAG_TITLE).trim() : curTitle; final String newSummary = item.has(TAG_SUMMARY) ? item.getString(TAG_SUMMARY).trim() : curSummary; final String newDesc = item.has(TAG_DESC) ? item.getString(TAG_DESC).trim() : curDesc; long newStart = 0; if (item.has(TAG_START)) { final String start = item.getString(TAG_START); newStart = DateUtils.parseISO8601(start); } else { newStart = curStart; } long newEnd = 0; if (item.has(TAG_END)) { final String end = item.getString(TAG_END); newEnd = DateUtils.parseISO8601(end); } else { newEnd = curEnd; } final String newRoomId = item.has(TAG_ROOM) ? item.getString(TAG_ROOM).trim() : curRoomId; final int newNbVotes = item.has(TAG_NB_VOTES) ? item.getInt(TAG_NB_VOTES) : curNbVotes; // final int newMyVote = session.has(TAG_MY_VOTE) ? session.getBoolean(TAG_MY_VOTE) ? 1 : 0 : curMyVote; // final int newIsFavorite = session.has(TAG_IS_FAVORITE) ? session.getInt(TAG_IS_FAVORITE) : curIsFavorite; final String newFormat = item.has(TAG_FORMAT) ? item.getString(TAG_FORMAT).trim() : curFormat; final String newLevel = item.has(TAG_LEVEL) ? item.getString(TAG_LEVEL).trim() : curLevel; final String newLang = item.has(TAG_LANG) ? item.getString(TAG_LANG).trim() : curLang; return !curTitle.equals(newTitle) || // !curSummary.equals(newSummary) || // !curDesc.equals(newDesc) || // curStart != newStart || // curEnd != newEnd || // !curRoomId.equals(newRoomId) || // curNbVotes != newNbVotes || // // curMyVote != newMyVote || // curIsFavorite != newIsFavorite || // !curFormat.equals(newFormat) || // !curLevel.equals(newLevel) || // !curLang.equals(newLang); } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.android.emailcommon.provider.Account.java
public static Account restoreAccountWithAddress(Context context, String emailAddress, ContentObserver observer) {// w w w. j a va 2s . c om final Cursor c = context.getContentResolver().query(CONTENT_URI, new String[] { AccountColumns._ID }, AccountColumns.EMAIL_ADDRESS + "=?", new String[] { emailAddress }, null); try { if (c == null || !c.moveToFirst()) { return null; } final long id = c.getLong(c.getColumnIndex(AccountColumns._ID)); return restoreAccountWithId(context, id, observer); } finally { if (c != null) { c.close(); } } }
From source file:ro.weednet.contactssync.platform.ContactManager.java
private static long lookupContact(ContentResolver resolver, String name, String fb_id, boolean joinById, boolean syncAll) { Cursor c; if (joinById) { c = resolver.query(ContactsContract.Data.CONTENT_URI, //table new String[] { ContactsContract.Data.RAW_CONTACT_ID }, //select (projection) ContactsContract.Data.MIMETYPE + "=? AND " + CommonDataKinds.Note.NOTE + " LIKE ?", //where new String[] { ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE, "%" + fb_id + "%" }, //params null //sort );//from w w w . j a v a 2 s .com try { if (c != null && c.moveToFirst()) { return c.getLong(0); } } finally { if (c != null) { c.close(); } } } if (syncAll) { return -1; } c = resolver.query(Contacts.CONTENT_URI, //table new String[] { Contacts._ID }, //select (projection) Contacts.DISPLAY_NAME + "=?", //where new String[] { name }, //params null //sort ); try { if (c != null && c.getCount() > 0) { return 0; } } finally { if (c != null) { c.close(); } } return -1; }