List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:ro.weednet.contactssync.platform.ContactManager.java
public static List<RawContact> getLocalContacts(Context context, Uri uri) { Log.i(TAG, "*** Looking for local contacts"); List<RawContact> localContacts = new ArrayList<RawContact>(); final ContentResolver resolver = context.getContentResolver(); final Cursor c = resolver.query(uri, new String[] { Contacts._ID, RawContacts.SOURCE_ID }, null, null, null);/* w w w. j av a 2 s . c o m*/ try { while (c.moveToNext()) { final long rawContactId = c.getLong(0); final String serverContactId = c.getString(1); RawContact rawContact = RawContact.create(rawContactId, serverContactId); localContacts.add(rawContact); } } finally { if (c != null) { c.close(); } } Log.i(TAG, "*** ... found " + localContacts.size()); return localContacts; }
From source file:ro.weednet.contactssync.platform.ContactManager.java
private static long lookupProfile(ContentResolver resolver, String userId) { long profileId = 0; final Cursor c = resolver.query(Data.CONTENT_URI, ProfileQuery.PROJECTION, ProfileQuery.SELECTION, new String[] { userId }, null); try {/* w w w. j av a 2 s .c o m*/ if ((c != null) && c.moveToFirst()) { profileId = c.getLong(ProfileQuery.COLUMN_ID); } } finally { if (c != null) { c.close(); } } return profileId; }
From source file:ro.weednet.contactssync.platform.ContactManager.java
public static List<RawContact> getStarredContacts(Context context, Uri uri) { Log.i(TAG, "*** Looking for starred contacts"); final ContentResolver resolver = context.getContentResolver(); Set<Long> contactIds = new HashSet<Long>(); Cursor c = resolver.query(RawContacts.CONTENT_URI, new String[] { RawContacts.CONTACT_ID }, RawContacts.STARRED + "!=0", null, null); try {//w w w. j a v a 2 s. c om while (c.moveToNext()) { contactIds.add(c.getLong(0)); } } finally { if (c != null) { c.close(); } } Log.i(TAG, "*** ... found " + contactIds.size() + " starred"); int i = 0; StringBuilder sb = new StringBuilder(); for (Long s : contactIds) { sb.append(s); if (++i >= Math.min(contactIds.size(), 50)) { break; } sb.append(","); } List<RawContact> contacts = new ArrayList<RawContact>(); c = resolver.query(uri, new String[] { Contacts._ID, RawContacts.SOURCE_ID }, RawContacts.CONTACT_ID + " IN (" + sb.toString() + ")", null, null); try { while (c.moveToNext()) { final long rawContactId = c.getLong(0); final String serverContactId = c.getString(1); RawContact rawContact = RawContact.create(rawContactId, serverContactId); contacts.add(rawContact); } } catch (Exception e) { Log.i(TAG, "failing .. " + e.toString()); } finally { if (c != null) { c.close(); } } Log.i(TAG, "*** ... and " + contacts.size() + " of mine " + sb.toString()); return contacts; }
From source file:ro.weednet.contactssync.platform.ContactManager.java
private static long lookupRawContact(ContentResolver resolver, Account account, String serverContactId) { long rawContactId = 0; final Cursor c = resolver.query(UserIdQuery.CONTENT_URI, UserIdQuery.PROJECTION, UserIdQuery.SELECTION, new String[] { account.name, account.type, serverContactId }, null); try {/*from w w w. j a v a 2s. c o m*/ if ((c != null) && c.moveToFirst()) { rawContactId = c.getLong(UserIdQuery.COLUMN_RAW_CONTACT_ID); } } finally { if (c != null) { c.close(); } } return rawContactId; }
From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java
/** * Helper method that converts the cursor to a destination object. *///from www. j a v a2 s. c o m static Destination getCursorDestination(Cursor mCursor) { Destination d = new Destination(); d.id = mCursor.getInt(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ID)); d.identifier = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_IDENTIFIER)); d.city = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_CITY)); d.region = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_REGION)); d.country = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_COUNTRY)); d.arrival = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ARRIVAL)); d.departure = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_DEPARTURE)); double lat = mCursor.getDouble(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_LAT)); double lng = mCursor.getDouble(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_LNG)); d.position = new LatLng(lat, lng); d.presentsDelivered = mCursor .getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PRESENTSDELIVERED)); d.presentsDeliveredAtDestination = mCursor .getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PRESENTS_DESTINATION)); d.timezone = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_TIMEZONE)); d.altitude = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ALTITUDE)); d.photoString = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PHOTOS)); d.weatherString = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_WEATHER)); d.streetViewString = mCursor .getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_STREETVIEW)); d.gmmStreetViewString = mCursor .getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_GMMSTREETVIEW)); // Process the panoramio string if possible d.photos = processPhoto(d.photoString); d.weather = processWeather(d.weatherString); d.streetView = processStreetView(d.streetViewString); d.gmmStreetView = processStreetView(d.gmmStreetViewString); return d; }
From source file:com.taobao.weex.devtools.inspector.protocol.module.Database.java
/** * Flatten all columns and all rows of a cursor to a single array. The array cannot be * interpreted meaningfully without the number of columns. * * @param cursor// w ww. ja v a2 s. co m * @param limit Maximum number of rows to process. * @return List of Java primitives matching the value type of each column, converted to * strings. */ private static ArrayList<String> flattenRows(Cursor cursor, int limit) { Util.throwIfNot(limit >= 0); ArrayList<String> flatList = new ArrayList<>(); final int numColumns = cursor.getColumnCount(); for (int row = 0; row < limit && cursor.moveToNext(); row++) { for (int column = 0; column < numColumns; column++) { switch (cursor.getType(column)) { case Cursor.FIELD_TYPE_NULL: flatList.add(null); break; case Cursor.FIELD_TYPE_INTEGER: flatList.add(String.valueOf(cursor.getLong(column))); break; case Cursor.FIELD_TYPE_FLOAT: flatList.add(String.valueOf(cursor.getDouble(column))); break; case Cursor.FIELD_TYPE_BLOB: flatList.add(blobToString(cursor.getBlob(column))); break; case Cursor.FIELD_TYPE_STRING: default: flatList.add(cursor.getString(column)); break; } } } if (!cursor.isAfterLast()) { for (int column = 0; column < numColumns; column++) { flatList.add("{truncated}"); } } return flatList; }
From source file:com.rsegismont.androlife.core.utils.AndrolifeUtils.java
public static long getCurrentIndex(Cursor mCursor) { long dateUtc = -1; if (mCursor == null) return -1; if (mCursor.getCount() <= 0) return -1; final int initialPosition = mCursor.getPosition(); int index = -1; for (int i = 0; i < mCursor.getCount(); i++) { mCursor.moveToPosition(i);//from w ww .ja v a 2s .c o m final long value = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue)); if (System.currentTimeMillis() - value < 0) { index = i - 1; mCursor.moveToPosition(Math.max(0, index)); dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue)); break; } if ((i == 0) && (System.currentTimeMillis() - value < 0)) { mCursor.moveToPosition(0); dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue)); break; } if (i == (mCursor.getCount() - 1)) { index = (mCursor.getCount() - 1); mCursor.moveToPosition(Math.max(0, index)); dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue)); break; } } if (initialPosition >= 0) mCursor.moveToPosition(initialPosition); return dateUtc; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static long getSize(final String resourcePath) { final String[] projection = new String[] { Nodes.NODE_SIZE }; final String selection = Nodes.NODE_RESOURCE_PATH + "=?"; final String[] selectionArgs = new String[] { resourcePath }; Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); long size = 0L; try {/*from w w w . java 2 s. com*/ if (c.moveToFirst()) { size = c.getLong(c.getColumnIndex(Nodes.NODE_SIZE)); } } finally { c.close(); } return size; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static long getVolumeGeneration(String resourcePath) { String[] projection = new String[] { Volumes.VOLUME_GENERATION }; String selection = Volumes.VOLUME_RESOURCE_PATH + "=?"; String[] selectionArgs = new String[] { resourcePath }; Cursor c = sResolver.query(Volumes.CONTENT_URI, projection, selection, selectionArgs, null); if (c != null) { try {//from w w w . ja v a2 s.c o m if (c.moveToFirst()) { return c.getLong(c.getColumnIndex(Volumes.VOLUME_GENERATION)); } } finally { c.close(); } } return 0; }
From source file:com.github.chenxiaolong.dualbootpatcher.FileUtils.java
public static UriMetadata[] queryUriMetadata(ContentResolver cr, Uri... uris) { ThreadUtils.enforceExecutionOnNonMainThread(); UriMetadata[] metadatas = new UriMetadata[uris.length]; for (int i = 0; i < metadatas.length; i++) { UriMetadata metadata = new UriMetadata(); metadatas[i] = metadata;/*ww w . j a v a 2 s . com*/ metadata.uri = uris[i]; metadata.mimeType = cr.getType(metadata.uri); if (SAF_SCHEME.equals(metadata.uri.getScheme())) { Cursor cursor = cr.query(metadata.uri, null, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); metadata.displayName = cursor.getString(nameIndex); if (cursor.isNull(sizeIndex)) { metadata.size = -1; } else { metadata.size = cursor.getLong(sizeIndex); } } } finally { IOUtils.closeQuietly(cursor); } } else if (FILE_SCHEME.equals(metadata.uri.getScheme())) { metadata.displayName = metadata.uri.getLastPathSegment(); metadata.size = new File(metadata.uri.getPath()).length(); } else { throw new IllegalArgumentException("Cannot handle URI: " + metadata.uri); } } return metadatas; }