List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:edu.pdx.cecs.orcycle.Uploader.java
private boolean SendAllSegments() { boolean result = true; Vector<Long> unsentSegmentIds = new Vector<Long>(); mDb.openReadOnly();/*from w ww. java 2 s . com*/ try { Cursor cursor = mDb.fetchUnsentSegmentIds(); try { if (cursor != null && cursor.getCount() > 0) { // pd.setMessage("Sent. You have previously unsent notes; submitting those now."); while (!cursor.isAfterLast()) { unsentSegmentIds.add(Long.valueOf(cursor.getLong(0))); cursor.moveToNext(); } } } finally { cursor.close(); } } finally { mDb.close(); } for (Long segmentId : unsentSegmentIds) { result &= uploadOneSegment(segmentId); } return result; }
From source file:mp.teardrop.Song.java
/** * Populate fields with data from the supplied cursor. * * @param cursor Cursor queried with FILLED_PROJECTION projection *//*from ww w . ja va 2 s. co m*/ public void populate(Cursor cursor) { id = cursor.getLong(0); path = cursor.getString(1); title = cursor.getString(2); album = cursor.getString(3); artist = cursor.getString(4); albumId = cursor.getLong(5); artistId = cursor.getLong(6); //duration = cursor.getLong(7); trackNumber = cursor.getInt(8); }
From source file:com.notifry.android.database.NotifrySource.java
@Override protected NotifrySource inflate(Context context, Cursor cursor) { NotifrySource source = new NotifrySource(); source.setAccountName(cursor.getString(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_ACCOUNT_NAME))); source.setId(cursor.getLong(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_ID))); source.setServerEnabled(/*from w w w. ja v a2 s . co m*/ cursor.getLong(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_SERVER_ENABLED)) == 0 ? false : true); source.setLocalEnabled( cursor.getLong(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_LOCAL_ENABLED)) == 0 ? false : true); source.setServerId(cursor.getLong(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_SERVER_ID))); source.setTitle(cursor.getString(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_TITLE))); source.setChangeTimestamp( cursor.getString(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_CHANGE_TIMESTAMP))); source.setSourceKey(cursor.getString(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_SOURCE_KEY))); source.setUseGlobalNotification( cursor.getLong(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_USE_GLOBAL_NOTIFICATION)) == 0 ? false : true); source.setVibrate( cursor.getLong(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_VIBRATE)) == 0 ? false : true); source.setRingtone( cursor.getLong(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_RINGTONE)) == 0 ? false : true); source.setLedFlash( cursor.getLong(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_LED_FLASH)) == 0 ? false : true); source.setCustomRingtone( cursor.getString(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_CUSTOM_RINGTONE))); source.setSpeakMessage( cursor.getLong(cursor.getColumnIndex(NotifryDatabaseAdapter.KEY_SPEAK_MESSAGE)) == 0 ? false : true); return source; }
From source file:com.jaspersoft.android.jaspermobile.activities.profile.fragment.ServersFragment.java
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { JasperMobileApplication.removeAllCookies(); Cursor cursor = mAdapter.getCursor(); cursor.moveToPosition(position);// w ww.j a v a2 s . co m JsServerProfile oldProfile = jsRestClient.getServerProfile(); long profileId = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID)); boolean isSameCurrentProfileSelected = (oldProfile != null && oldProfile.getId() == profileId); if (isSameCurrentProfileSelected) { setResultOk(profileId); } else { JsServerProfile newProfile = profileHelper.createProfileFromCursor(cursor); String password = newProfile.getPassword(); boolean alwaysAskPassword = TextUtils.isEmpty(password); if (alwaysAskPassword) { setResultOk(profileId); } else { JsRestClient tmpRestClient = new JsRestClient(); tmpRestClient.setConnectTimeout(prefHelper.getConnectTimeoutValue()); tmpRestClient.setReadTimeout(prefHelper.getReadTimeoutValue()); tmpRestClient.setServerProfile(newProfile); GetServerInfoRequest request = new GetServerInfoRequest(tmpRestClient); request.setRetryPolicy(null); setRefreshActionState(true); getSpiceManager().execute(new GetServerInfoRequest(tmpRestClient), new ValidateServerInfoListener(newProfile)); } } }
From source file:com.ichi2.libanki.Finder.java
public static int findReplace(Collection col, List<Long> nids, String src, String dst, boolean isRegex, String field, boolean fold) { Map<Long, Integer> mmap = new HashMap<Long, Integer>(); if (field != null) { try {//from w w w . j a v a 2s . c om for (JSONObject m : col.getModels().all()) { JSONArray flds = m.getJSONArray("flds"); for (int fi = 0; fi < flds.length(); ++fi) { JSONObject f = flds.getJSONObject(fi); if (f.getString("name").equals(field)) { mmap.put(m.getLong("id"), f.getInt("ord")); } } } } catch (JSONException e) { throw new RuntimeException(e); } if (mmap.isEmpty()) { return 0; } } // find and gather replacements if (!isRegex) { src = Pattern.quote(src); } if (fold) { src = "(?i)" + src; } Pattern regex = Pattern.compile(src); ArrayList<Object[]> d = new ArrayList<Object[]>(); String snids = Utils.ids2str(nids); nids = new ArrayList<Long>(); Cursor cur = null; try { cur = col.getDb().getDatabase().rawQuery("select id, mid, flds from notes where id in " + snids, null); while (cur.moveToNext()) { String flds = cur.getString(2); String origFlds = flds; // does it match? String[] sflds = Utils.splitFields(flds); if (field != null) { long mid = cur.getLong(1); if (!mmap.containsKey(mid)) { // note doesn't have that field continue; } int ord = mmap.get(mid); sflds[ord] = regex.matcher(sflds[ord]).replaceAll(dst); } else { for (int i = 0; i < sflds.length; ++i) { sflds[i] = regex.matcher(sflds[i]).replaceAll(dst); } } flds = Utils.joinFields(sflds); if (!flds.equals(origFlds)) { long nid = cur.getLong(0); nids.add(nid); d.add(new Object[] { flds, Utils.intNow(), col.usn(), nid }); // order based on query below } } } finally { if (cur != null) { cur.close(); } } if (d.isEmpty()) { return 0; } // replace col.getDb().executeMany("update notes set flds=?,mod=?,usn=? where id=?", d); long[] pnids = Utils.toPrimitive(nids); col.updateFieldCache(pnids); col.genCards(pnids); return d.size(); }
From source file:org.thomnichols.android.gmarks.WebViewCookiesDB.java
List<Cookie> getCookies() { List<Cookie> cookies = new ArrayList<Cookie>(); SQLiteDatabase db = openDatabase(SQLiteDatabase.OPEN_READONLY); if (db == null) return cookies; try {//from ww w.j av a 2 s . com db.execSQL("PRAGMA read_uncommitted = true;"); Cursor cursor = db.query(TABLE_NAME, COLUMNS, null, null, null, null, null); while (cursor.moveToNext()) { BasicClientCookie c = new BasicClientCookie(cursor.getString(COL_NAME), cursor.getString(COL_VALUE)); c.setDomain(cursor.getString(COL_DOMAIN)); c.setPath(cursor.getString(COL_PATH)); Long expiry = cursor.getLong(COL_EXPIRES); if (expiry != null) c.setExpiryDate(new Date(expiry)); c.setSecure(cursor.getShort(COL_SECURE) == 1); Log.d(TAG, "Got cookie: " + c.getName()); cookies.add(c); } cursor.close(); // cursor = db.query(TABLE_NAME, new String[] {"count(name)"}, null, null, null, null, null); // cursor.moveToFirst(); // Log.d("WEBVIEW DB QUERY", "COunt: " + cursor.getLong(0) ); // cursor.close(); return cookies; } finally { db.close(); } }
From source file:com.ruuhkis.cookies.CookieSQLSource.java
/** * Creates SQLCookie from cursor that is assumed * to be located at SQLCookie entry/*w w w .j a v a2s . co m*/ * @param cursor * @return */ private SQLCookie cursorToCookie(Cursor cursor) { SQLCookie cookie = new SQLCookie(); cookie.setComment(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_COMMENT))); cookie.setCommentURL(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_COMMENT_URL))); cookie.setDomain(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_DOMAIN))); long expiryDate = cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_EXPIRY_DATE)); cookie.setExpiryDate(expiryDate != -1 ? new Date(expiryDate) : null); cookie.setName(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_NAME))); cookie.setPath(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_PATH))); cookie.setPersistent(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_PERSISTENT)) == 1); cookie.setPorts(getPorts(cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_ID)))); cookie.setSecure(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_SECURE)) == 1); cookie.setValue(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_VALUE))); cookie.setVersion(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_VERSION))); cookie.setId(cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_ID))); return cookie; }
From source file:ru.orangesoftware.financisto.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 w w w. j av a 2 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(); targetFolder = 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 = ""; } if (http_client != null) { //make html link beetwen Flowzr.com & Drive 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.exchange.EasOutboxService.java
@Override public void run() { setupService();/*from w w w.j a v a 2 s . c o m*/ File cacheDir = mContext.getCacheDir(); try { mDeviceId = SyncManager.getDeviceId(); Cursor c = mContext.getContentResolver().query(Message.CONTENT_URI, Message.ID_COLUMN_PROJECTION, MAILBOX_KEY_AND_NOT_SEND_FAILED, new String[] { Long.toString(mMailbox.mId) }, null); try { while (c.moveToNext()) { long msgId = c.getLong(0); if (msgId != 0) { int result = sendMessage(cacheDir, msgId); // If there's an error, it should stop the service; we will distinguish // at least between login failures and everything else if (result == EmailServiceStatus.LOGIN_FAILED) { mExitStatus = EXIT_LOGIN_FAILURE; return; } else if (result == EmailServiceStatus.REMOTE_EXCEPTION) { mExitStatus = EXIT_EXCEPTION; return; } } } } finally { c.close(); } mExitStatus = EXIT_DONE; } catch (IOException e) { mExitStatus = EXIT_IO_ERROR; } catch (Exception e) { userLog("Exception caught in EasOutboxService", e); mExitStatus = EXIT_EXCEPTION; } finally { userLog(mMailbox.mDisplayName, ": sync finished"); userLog("Outbox exited with status ", mExitStatus); SyncManager.done(this); } }
From source file:com.hichinaschool.flashcards.libanki.Note.java
public ArrayList<Card> cards() { ArrayList<Card> cards = new ArrayList<Card>(); Cursor cur = null; try {/*from ww w. ja v a 2 s.c om*/ cur = mCol.getDb().getDatabase().rawQuery("SELECT id FROM cards WHERE nid = " + mId + " ORDER BY ord", null); while (cur.moveToNext()) { cards.add(mCol.getCard(cur.getLong(0))); } } finally { if (cur != null) { cur.close(); } } return cards; }