List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:com.spoiledmilk.ibikecph.util.DB.java
public long saveSearchHistory(HistoryData hd, HistoryData from, Context context) { SQLiteDatabase db = this.getWritableDatabase(); if (db == null) return -1; String[] columns = { KEY_ID, KEY_NAME }; long id;/*from w ww . j a va 2 s . c o m*/ Cursor cursor = db.query(TABLE_SEARCH_HISTORY, columns, KEY_NAME + " = ?", new String[] { hd.getName() }, null, null, null, null); if (cursor == null || cursor.isAfterLast()) { ContentValues values = new ContentValues(); values.put(KEY_NAME, hd.getName()); values.put(KEY_ADDRESS, hd.getAdress()); values.put(KEY_START_DATE, hd.getStartDate()); values.put(KEY_END_DATE, hd.getEndDate()); values.put(KEY_SOURCE, hd.getSource()); values.put(KEY_SUBSOURCE, hd.getSubSource()); values.put(KEY_LAT, Double.valueOf(hd.getLatitude())); values.put(KEY_LONG, Double.valueOf(hd.getLongitude())); id = db.insert(TABLE_SEARCH_HISTORY, null, values); } else { cursor.moveToFirst(); id = cursor.getInt(cursor.getColumnIndex(KEY_ID)); } if (cursor != null) cursor.close(); db.close(); if (context != null && from != null) postHistoryItemToServer(hd, from, context); return id; }
From source file:com.urs.triptracks.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 w w w .j a v a2s .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()) { //HS-unsentTrips.add(new Long(cur.getLong(0)));Use Long.valueOf(cur.getLong(0)) instead unsentTrips.add(Long.valueOf(cur.getLong(0))); cur.moveToNext(); } cur.close(); } mDb.close(); for (Long trip : unsentTrips) { result &= uploadOneTrip(trip); } return result; }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public ArrayList<FavoritesData> getFavorites(ArrayList<FavoritesData> ret) { if (ret == null) { ret = new ArrayList<FavoritesData>(); } else {//from w w w . ja v a 2 s . c o m ret.clear(); } SQLiteDatabase db = getReadableDatabase(); if (db == null) { return null; } String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG, KEY_API_ID }; Cursor cursor = db.query(TABLE_FAVORITES, columns, null, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); int colApiId = cursor.getColumnIndex(KEY_API_ID); FavoritesData fd = new FavoritesData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong), cursor.getInt(colApiId)); ret.add(fd); cursor.moveToNext(); } } if (cursor != null) { cursor.close(); } db.close(); LOG.d("favourites count from DB = " + ret.size()); return ret; }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public ArrayList<SearchListItem> getFavorites2() { ArrayList<SearchListItem> ret = new ArrayList<SearchListItem>(); SQLiteDatabase db = getReadableDatabase(); if (db == null) return null; String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG, KEY_API_ID };//from w w w. j a v a 2 s . c om Cursor cursor = db.query(TABLE_FAVORITES, columns, null, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); int colApiId = cursor.getColumnIndex(KEY_API_ID); FavoritesData fd = new FavoritesData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong), cursor.getInt(colApiId)); ret.add((SearchListItem) fd); cursor.moveToNext(); } } if (cursor != null) cursor.close(); db.close(); return ret; }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public int getApiId(int id) { int ret = -1; SQLiteDatabase db = getWritableDatabase(); if (db == null) return -1; String strFilter = "_id= ?"; Cursor cur = db.query(TABLE_FAVORITES, new String[] { KEY_API_ID }, strFilter, new String[] { id + "" }, null, null, null);//from w ww . jav a 2 s .c o m if (cur != null && cur.moveToFirst()) { if (cur != null && !cur.isAfterLast()) { ret = cur.getInt(cur.getColumnIndex(KEY_API_ID)); } } db.close(); return ret; }
From source file:org.tomahawk.libtomahawk.database.DatabaseHelper.java
public ArrayList<Album> getStarredAlbums() { ArrayList<Album> starredAlbums = new ArrayList<Album>(); String[] columns = new String[] { TomahawkSQLiteHelper.LOVED_ALBUMS_COLUMN_ARTISTNAME, TomahawkSQLiteHelper.LOVED_ALBUMS_COLUMN_ALBUMNAME }; Cursor albumsCursor = mDatabase.query(TomahawkSQLiteHelper.TABLE_LOVED_ALBUMS, columns, null, null, null, null, null);/* ww w . j ava 2s. co m*/ albumsCursor.moveToFirst(); while (!albumsCursor.isAfterLast()) { String artistName = albumsCursor.getString(0); String albumName = albumsCursor.getString(1); starredAlbums.add(Album.get(albumName, Artist.get(artistName))); albumsCursor.moveToNext(); } albumsCursor.close(); return starredAlbums; }
From source file:org.tomahawk.libtomahawk.database.DatabaseHelper.java
public ArrayList<Artist> getStarredArtists() { ArrayList<Artist> starredArtists = new ArrayList<Artist>(); String[] columns = new String[] { TomahawkSQLiteHelper.LOVED_ARTISTS_COLUMN_ARTISTNAME }; Cursor artistsCursor = mDatabase.query(TomahawkSQLiteHelper.TABLE_LOVED_ARTISTS, columns, null, null, null, null, null);/*from w w w . j a va 2s. c o m*/ artistsCursor.moveToFirst(); while (!artistsCursor.isAfterLast()) { String artistName = artistsCursor.getString(0); starredArtists.add(Artist.get(artistName)); artistsCursor.moveToNext(); } artistsCursor.close(); return starredArtists; }
From source file:com.example.app_2.activities.ImageGridActivity.java
private void setActionBarTitleFromCategoryId(Long category_id) { Uri uri = Uri.parse(ImageContract.CONTENT_URI + "/" + category_id); Cursor c = getApplicationContext().getContentResolver().query(uri, new String[] { ImageContract.Columns.FILENAME, ImageContract.Columns.DESC }, null, null, null); if (c != null) { c.moveToFirst();/*from w ww . ja v a 2 s . c o m*/ if (!c.isAfterLast()) { mActionBar.setTitle(c.getString(1)); String path = Storage.getPathToScaledBitmap(c.getString(0), 50); Bitmap user_icon = ScalingUtilities.decodeFile(path, 50, 50, ScalingLogic.FIT); mActionBar.setIcon(new BitmapDrawable(getResources(), user_icon)); } c.close(); } }
From source file:edu.ncsu.asbransc.mouflon.recorder.UploadFile.java
protected void doUpload() { DbAdapter dba = new DbAdapter(this); dba.open();//from w w w . ja va 2 s.c o m Cursor allLogs = dba.fetchAll(); StringBuilder sb = new StringBuilder(); allLogs.moveToFirst(); sb.append("DateTime"); sb.append(","); sb.append("Process"); sb.append(","); sb.append("Type"); sb.append(","); sb.append("Component"); sb.append(","); sb.append("ActionString"); sb.append(","); sb.append("Category"); sb.append("\n"); while (!allLogs.isAfterLast()) { sb.append(allLogs.getString(allLogs.getColumnIndex(DbAdapter.KEY_TIME))); sb.append(","); sb.append(allLogs.getString(allLogs.getColumnIndex(DbAdapter.KEY_PROCESSTAG))); sb.append(","); sb.append(allLogs.getString(allLogs.getColumnIndex(DbAdapter.KEY_EXTRA_1))); sb.append(","); sb.append(allLogs.getString(allLogs.getColumnIndex(DbAdapter.KEY_EXTRA_2))); sb.append(","); sb.append(allLogs.getString(allLogs.getColumnIndex(DbAdapter.KEY_EXTRA_3))); sb.append(","); sb.append(allLogs.getString(allLogs.getColumnIndex(DbAdapter.KEY_EXTRA_4))); sb.append("\n"); allLogs.moveToNext(); } dba.close(); File appDir = getDir("toUpload", MODE_PRIVATE); UUID uuid; uuid = MainScreen.getOrCreateUUID(this); long time = System.currentTimeMillis(); String basename = uuid.toString() + "_AT_" + time; String filename = basename + ".zip.enc"; File file = new File(appDir, filename); FileOutputStream out = null; ZipOutputStream outzip = null; CipherOutputStream outcipher = null; Cipher datac = null; File keyfile = new File(appDir, basename + ".key.enc"); //Log.i("sb length", Integer.toString(sb.length())); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String email = prefs.getString(MainScreen.EMAIL_KEY, ""); String emailFilename = "email.txt"; String csvFilename = "mouflon_log_" + time + ".csv"; try { SecretKey aeskey = generateAESKey(); //Log.i("secret key", bytearrToString(aeskey.getEncoded())); encryptAndWriteAESKey(aeskey, keyfile); datac = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC"); byte[] ivbytes = genIV(); IvParameterSpec iv = new IvParameterSpec(ivbytes); datac.init(Cipher.ENCRYPT_MODE, aeskey, iv); out = new FileOutputStream(file); out.write(ivbytes); //Log.i("iv bytes", bytearrToString(ivbytes)); outcipher = new CipherOutputStream(out, datac); outzip = new ZipOutputStream(outcipher); outzip.setMethod(ZipOutputStream.DEFLATED); //write the first file (e-mail address) String androidVersion = android.os.Build.VERSION.RELEASE; String deviceName = android.os.Build.MODEL; ZipEntry infoEntry = new ZipEntry("info.txt"); outzip.putNextEntry(infoEntry); outzip.write((androidVersion + "\n" + deviceName).getBytes()); outzip.closeEntry(); ZipEntry emailEntry = new ZipEntry(emailFilename); outzip.putNextEntry(emailEntry); outzip.write(email.getBytes()); outzip.closeEntry(); ZipEntry csvEntry = new ZipEntry(csvFilename); outzip.putNextEntry(csvEntry); outzip.write(sb.toString().getBytes()); outzip.closeEntry(); } catch (Exception e) { e.printStackTrace(); } finally { try { outzip.close(); outcipher.close(); out.close(); } catch (IOException e) { //ignore } catch (NullPointerException ne) { //ignore } } //here we actually upload the files String containerFilename = basename + "_container.zip"; File containerFile = new File(appDir, containerFilename); zipUp(containerFile, new File[] { file, keyfile }); boolean success = uploadFile(containerFile); containerFile.delete(); file.delete(); keyfile.delete(); if (success && prefs.getBoolean(MainScreen.DELETE_KEY, true)) { DbAdapter dba2 = new DbAdapter(this); dba2.open(); dba2.clearDB(); dba2.close(); } if (!success && prefs.getBoolean(MainScreen.UPLOAD_KEY, false)) { Editor e = prefs.edit(); e.putInt(MainScreen.DAY_KEY, 6); //reset it to run tomorrow if it fails e.commit(); } String s = success ? "Upload complete. Thanks!" : "Upload Failed"; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(UploadFile.this) .setSmallIcon(R.drawable.ic_launcher_bw).setContentTitle("Mouflon Recorder").setContentText(s) .setAutoCancel(true).setOngoing(false); if (mManual) { //only show a notification if we manually upload the file. Intent toLaunch = new Intent(UploadFile.this, MainScreen.class); //The notification has to go somewhere. PendingIntent pi = PendingIntent.getActivity(UploadFile.this, 0, toLaunch, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(pi); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(1, mBuilder.build()); } stopSelf(); }
From source file:com.samknows.measurement.storage.DBHelper.java
private List<JSONObject> getTestResults(String selection, String limit) { synchronized (sync) { open();/*from ww w. j ava2s. com*/ List<JSONObject> ret = new ArrayList<JSONObject>(); Cursor cursor = database.query(SKSQLiteHelper.TABLE_TESTRESULT, SKSQLiteHelper.TABLE_TESTRESULT_ALLCOLUMNS, selection, null, null, null, SKSQLiteHelper.TEST_RESULT_ORDER, limit); cursor.moveToFirst(); while (!cursor.isAfterLast()) { ret.add(cursorTestResultToJSONObject(cursor)); cursor.moveToNext(); } cursor.close(); close(); return ret; } }