List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:com.newtifry.android.database.NewtifrySource.java
@Override protected NewtifrySource inflate(Context context, Cursor cursor) { NewtifrySource source = new NewtifrySource(); source.setAccountName(cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_ACCOUNT_NAME))); source.setId(cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_ID))); source.setServerEnabled(/*from w ww.j a va 2 s . c o m*/ cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_SERVER_ENABLED)) == 0 ? false : true); source.setLocalEnabled( cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_LOCAL_ENABLED)) == 0 ? false : true); source.setServerId(cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_SERVER_ID))); source.setTitle(cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_TITLE))); source.setChangeTimestamp( cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_CHANGE_TIMESTAMP))); source.setSourceKey(cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_SOURCE_KEY))); source.setSourceColor(cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_SOURCE_COLOR))); source.setUseGlobalNotification( cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_USE_GLOBAL_NOTIFICATION)) == 0 ? false : true); source.setNotification( cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_NOTIFICATION)) == 0 ? false : true); source.setVibrate( cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_VIBRATE)) == 0 ? false : true); source.setNotifierPro( cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_NOTIFIERPRO)) == 0 ? false : true); source.setLedFlash( cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_LED_FLASH)) == 0 ? false : true); source.setRingtone(cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_CUSTOM_RINGTONE))); source.setSpeakMessage( cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_SPEAK_MESSAGE)) == 0 ? false : true); return source; }
From source file:com.crankworks.cycletracks.TripUploader.java
@Override protected Boolean doInBackground(Long... tripid) { // First, send the trip user asked for: Boolean result = uploadOneTrip(tripid[0]); // Then, automatically try and send previously-completed trips // that were not sent successfully. Vector<Long> unsentTrips = new Vector<Long>(); mDb.openReadOnly();//from ww w . jav a2 s . c o m Cursor cur = mDb.fetchUnsentTrips(); if (cur != null && cur.getCount() > 0) { //pd.setMessage("Sent. You have previously unsent trips; submitting those now."); while (!cur.isAfterLast()) { unsentTrips.add(new Long(cur.getLong(0))); cur.moveToNext(); } cur.close(); } mDb.close(); for (Long trip : unsentTrips) { result &= uploadOneTrip(trip); } return result; }
From source file:com.flowzr.budget.holo.export.flowzr.PictureDriveTask.java
protected boolean runUpload(Drive driveService) throws IOException { String targetFolderId = null; String ROOT_FOLDER = MyPreferences.getGoogleDriveFolder(context); // ensure to have the app root folder in drive ... if (rootFolderId == null) { //search root folder ... FileList folders = driveService.files().list().setQ("mimeType='application/vnd.google-apps.folder'") .execute();//from www.ja v a 2s.c o m for (File fl : folders.getItems()) { if (fl.getTitle().equals(ROOT_FOLDER)) { rootFolderId = fl.getId(); } } //if not found create it if (rootFolderId == null) { File body = new File(); body.setTitle(ROOT_FOLDER); body.setMimeType("application/vnd.google-apps.folder"); File file = driveService.files().insert(body).execute(); rootFolderId = file.getId(); } } //search for the target folder (depending of the date) Calendar cal = Calendar.getInstance(); cal.setTime(new Date(trDate)); int month = cal.get(Calendar.MONTH) + 1; String targetFolder = String.valueOf(cal.get(Calendar.YEAR)) + "-" + (month < 10 ? ("0" + month) : (month)); FileList subfolders = driveService.files().list() .setQ("mimeType='application/vnd.google-apps.folder' and '" + rootFolderId + "' in parents") .execute(); for (File fl : subfolders.getItems()) { if (fl.getTitle().equals(targetFolder)) { targetFolderId = fl.getId(); } } //create the target folder if not exist if (targetFolderId == null) { //create folder File body = new File(); body.setTitle(targetFolder); ArrayList<ParentReference> pList = new ArrayList<ParentReference>(); pList.add(new ParentReference().setId(rootFolderId)); body.setParents(pList); body.setMimeType("application/vnd.google-apps.folder"); File file = driveService.files().insert(body).execute(); targetFolderId = file.getId(); } // File's binary content java.io.File fileContent = new java.io.File(fileUri.getPath()); InputStreamContent mediaContent = new InputStreamContent("image/jpeg", new BufferedInputStream(new FileInputStream(fileContent))); mediaContent.setLength(fileContent.length()); // File's metadata. File body = new File(); body.setTitle(fileContent.getName()); body.setMimeType("image/jpeg"); body.setFileSize(fileContent.length()); ArrayList<ParentReference> pList2 = new ArrayList<ParentReference>(); pList2.add(new ParentReference().setId(targetFolderId)); body.setParents(pList2); File file = driveService.files().insert(body, mediaContent).execute(); Thread thread = new Thread() { @Override public void run() { try { synchronized (this) { wait(3000); } } catch (InterruptedException ex) { } } }; thread.start(); String uploadedId = null; FileList files; files = driveService.files().list().setQ("mimeType='image/jpeg' and '" + targetFolderId + "' in parents") .execute(); String file_url = ""; String thumbnail_url = ""; for (File fl : files.getItems()) { if (fl.getTitle().equals(fileUri.getLastPathSegment())) { uploadedId = fl.getId(); try { file_url = fl.getAlternateLink(); thumbnail_url = fl.getIconLink(); } catch (Exception e) { file_url = "https://drive.google.com/#folders/" + targetFolderId + "/"; } } } if (!uploadedId.equals("null")) { String sql = "update transactions set blob_key='" + uploadedId + "' where remote_key='" + remote_key + "'"; dba.db().execSQL(sql); sql = "select from_account_id,attached_picture from " + DatabaseHelper.TRANSACTION_TABLE + " where remote_key='" + remote_key + "'"; Cursor c = dba.db().rawQuery(sql, null); if (c.moveToFirst()) { String account_key = FlowzrSyncEngine.getRemoteKey(DatabaseHelper.ACCOUNT_TABLE, String.valueOf(c.getLong(0))); String file_type = "image/jpeg"; String file_name = c.getString(1); if (file_url == null) { file_url = ""; } if (thumbnail_url == null) { thumbnail_url = ""; } String url = FlowzrSyncEngine.FLOWZR_API_URL + "/clear/blob/?url=" + URLEncoder.encode(file_url, "UTF-8") + "&thumbnail_url=" + URLEncoder.encode(thumbnail_url, "UTF-8") + "&account=" + account_key + "&crebit=" + remote_key + "&name=" + file_name + "&blob_key=" + uploadedId + "type=" + file_type; try { HttpGet httpGet = new HttpGet(url); http_client.execute(httpGet); Log.i("flowzr", "linked to :" + file_url); } catch (Exception e) { e.printStackTrace(); } } } return true; }
From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java
public long getLastArrival() { SQLiteDatabase db = getReadableDatabase(); Cursor c = db.rawQuery("SELECT " + COLUMN_NAME_ARRIVAL + " FROM " + TABLE_NAME + " ORDER BY " + COLUMN_NAME_ARRIVAL + " DESC LIMIT 1", null); c.moveToFirst();//w w w .ja v a 2s . c o m long l; if (c.isAfterLast()) { l = -1; } else { l = c.getLong(c.getColumnIndex(COLUMN_NAME_ARRIVAL)); } c.close(); return l; }
From source file:com.flowzr.export.flowzr.PictureDriveTask.java
protected boolean runUpload(Drive driveService) throws IOException { String targetFolderId = null; String ROOT_FOLDER = MyPreferences.getGoogleDriveFolder(context); // ensure to have the app root folder in drive ... if (rootFolderId == null) { //search root folder ... FileList folders = driveService.files().list().setQ("mimeType='application/vnd.google-apps.folder'") .execute();//w w w.j a v a2 s . c om for (File fl : folders.getItems()) { if (fl.getTitle().equals(ROOT_FOLDER)) { rootFolderId = fl.getId(); } } //if not found create it if (rootFolderId == null) { File body = new File(); body.setTitle(ROOT_FOLDER); body.setMimeType("application/vnd.google-apps.folder"); File file = driveService.files().insert(body).execute(); rootFolderId = file.getId(); } } //search for the target folder (depending of the date) Calendar cal = Calendar.getInstance(); cal.setTime(new Date(trDate)); int month = cal.get(Calendar.MONTH) + 1; String targetFolder = String.valueOf(cal.get(Calendar.YEAR)) + "-" + (month < 10 ? ("0" + month) : (month)); FileList subfolders = driveService.files().list() .setQ("mimeType='application/vnd.google-apps.folder' and '" + rootFolderId + "' in parents") .execute(); for (File fl : subfolders.getItems()) { if (fl.getTitle().equals(targetFolder)) { targetFolderId = fl.getId(); } } //create the target folder if not exist if (targetFolderId == null) { //create folder File body = new File(); body.setTitle(targetFolder); ArrayList<ParentReference> pList = new ArrayList<ParentReference>(); pList.add(new ParentReference().setId(rootFolderId)); body.setParents(pList); body.setMimeType("application/vnd.google-apps.folder"); File file = driveService.files().insert(body).execute(); targetFolderId = file.getId(); } // File's binary content java.io.File fileContent = new java.io.File(fileUri.getPath()); InputStreamContent mediaContent = new InputStreamContent("image/jpeg", new BufferedInputStream(new FileInputStream(fileContent))); mediaContent.setLength(fileContent.length()); // File's metadata. File body = new File(); body.setTitle(fileContent.getName()); body.setMimeType("image/jpeg"); body.setFileSize(fileContent.length()); ArrayList<ParentReference> pList2 = new ArrayList<ParentReference>(); pList2.add(new ParentReference().setId(targetFolderId)); body.setParents(pList2); File file = driveService.files().insert(body, mediaContent).execute(); Thread thread = new Thread() { @Override public void run() { try { synchronized (this) { wait(3000); } } catch (InterruptedException ex) { } } }; thread.start(); String uploadedId = null; FileList files; files = driveService.files().list().setQ("mimeType='image/jpeg' and '" + targetFolderId + "' in parents") .execute(); String file_url = ""; String thumbnail_url = ""; for (File fl : files.getItems()) { if (fl.getTitle().equals(fileUri.getLastPathSegment())) { uploadedId = fl.getId(); try { file_url = fl.getAlternateLink(); thumbnail_url = fl.getIconLink(); } catch (Exception e) { file_url = "https://drive.google.com/#folders/" + targetFolderId + "/"; } } } if (!uploadedId.equals("null")) { String sql = "update transactions set blob_key='" + file_url + "' where remote_key='" + remote_key + "'"; dba.db().execSQL(sql); sql = "select from_account_id,attached_picture from " + DatabaseHelper.TRANSACTION_TABLE + " where remote_key='" + remote_key + "'"; Cursor c = dba.db().rawQuery(sql, null); if (c.moveToFirst()) { String account_key = FlowzrSyncEngine.getRemoteKey(DatabaseHelper.ACCOUNT_TABLE, String.valueOf(c.getLong(0))); String file_type = "image/jpeg"; String file_name = c.getString(1); if (file_url == null) { file_url = ""; } if (thumbnail_url == null) { thumbnail_url = ""; } String url = FlowzrSyncEngine.FLOWZR_API_URL + "/clear/blob/?url=" + URLEncoder.encode(file_url, "UTF-8") + "&thumbnail_url=" + URLEncoder.encode(thumbnail_url, "UTF-8") + "&account=" + account_key + "&crebit=" + remote_key + "&name=" + file_name + "&blob_key=" + uploadedId + "type=" + file_type; try { HttpGet httpGet = new HttpGet(url); http_client.execute(httpGet); Log.i("flowzr", "linked to :" + file_url); } catch (Exception e) { e.printStackTrace(); } } } return true; }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
private static void cursorToContactEntry(String account, ContentResolver cr, Cursor c, ContactEntry entry) throws ParseException { entry.setTitle(c.getString(c.getColumnIndexOrThrow(People.NAME))); entry.setContent(c.getString(c.getColumnIndexOrThrow(People.NOTES))); entry.setYomiName(c.getString(c.getColumnIndexOrThrow(People.PHONETIC_NAME))); long syncLocalId = c.getLong(c.getColumnIndexOrThrow(SyncConstValue._SYNC_LOCAL_ID)); addContactMethodsToContactEntry(cr, syncLocalId, entry); addPhonesToContactEntry(cr, syncLocalId, entry); addOrganizationsToContactEntry(cr, syncLocalId, entry); addGroupMembershipToContactEntry(account, cr, syncLocalId, entry); addExtensionsToContactEntry(cr, syncLocalId, entry); }
From source file:com.android.unit_tests.CheckinProviderTest.java
@MediumTest public void testEventReport() { long start = System.currentTimeMillis(); ContentResolver r = getContext().getContentResolver(); Checkin.logEvent(r, Checkin.Events.Tag.TEST, "Test Value"); Cursor c = r.query(Checkin.Events.CONTENT_URI, null, Checkin.Events.TAG + "=?", new String[] { Checkin.Events.Tag.TEST.toString() }, null); long id = -1; while (c.moveToNext()) { String tag = c.getString(c.getColumnIndex(Checkin.Events.TAG)); String value = c.getString(c.getColumnIndex(Checkin.Events.VALUE)); long date = c.getLong(c.getColumnIndex(Checkin.Events.DATE)); assertEquals(Checkin.Events.Tag.TEST.toString(), tag); if ("Test Value".equals(value) && date >= start) { assertTrue(id < 0);/*from ww w. ja v a2 s. c o m*/ id = c.getInt(c.getColumnIndex(Checkin.Events._ID)); } } assertTrue(id > 0); int rows = r.delete(ContentUris.withAppendedId(Checkin.Events.CONTENT_URI, id), null, null); assertEquals(1, rows); c.requery(); while (c.moveToNext()) { long date = c.getLong(c.getColumnIndex(Checkin.Events.DATE)); assertTrue(date < start); // Have deleted the only newer TEST. } c.close(); }
From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java
public long getFirstDeparture() { SQLiteDatabase db = getReadableDatabase(); Cursor c = db.rawQuery("SELECT " + COLUMN_NAME_DEPARTURE + " FROM " + TABLE_NAME + " ORDER BY " + COLUMN_NAME_DEPARTURE + " ASC LIMIT 1", null); c.moveToFirst();/*from w w w. java 2 s . co m*/ long l; if (c.isAfterLast()) { l = -1; } else { l = c.getLong(c.getColumnIndex(COLUMN_NAME_DEPARTURE)); } c.close(); return l; }
From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java
public long getLastDeparture() { SQLiteDatabase db = getReadableDatabase(); Cursor c = db.rawQuery("SELECT " + COLUMN_NAME_DEPARTURE + " FROM " + TABLE_NAME + " ORDER BY " + COLUMN_NAME_DEPARTURE + " DESC LIMIT 1", null); c.moveToFirst();//from www .ja v a 2s. co m long l; if (c.isAfterLast()) { l = -1; } else { l = c.getLong(c.getColumnIndex(COLUMN_NAME_DEPARTURE)); } c.close(); return l; }
From source file:net.naonedbus.manager.impl.CommentaireManager.java
@Override public Commentaire getSingleFromCursor(final Cursor c) { final Commentaire commentaire = new Commentaire(); commentaire.setId(c.getInt(mColId)); commentaire.setCodeLigne(c.getString(mColCodeLigne)); commentaire.setCodeSens(c.getString(mColCodeSens)); commentaire.setCodeArret(c.getString(mColCodeArret)); commentaire.setMessage(c.getString(mColMessage)); commentaire.setSource(c.getString(mColSource)); commentaire.setTimestamp(c.getLong(mColTimestamp)); return commentaire; }