List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
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 {/*from w w w. j a va 2 s . 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:github.popeen.dsub.util.SongDBHandler.java
public JSONArray exportData() { SQLiteDatabase db = this.getReadableDatabase(); String[] columns = { SONGS_ID, SONGS_SERVER_KEY, SONGS_SERVER_ID, SONGS_COMPLETE_PATH, SONGS_LAST_PLAYED, SONGS_LAST_COMPLETED };/* ww w .j av a 2s .co m*/ Cursor cursor = db.query(TABLE_SONGS, columns, SONGS_LAST_PLAYED + " != ''", null, null, null, null, null); try { JSONArray jsonSongDb = new JSONArray(); while (cursor.moveToNext()) { JSONObject tempJson = new JSONObject(); tempJson.put("SONGS_ID", cursor.getInt(0)); tempJson.put("SONGS_SERVER_KEY", cursor.getInt(1)); tempJson.put("SONGS_SERVER_ID", cursor.getString(2)); tempJson.put("SONGS_COMPLETE_PATH", cursor.getString(3)); tempJson.put("SONGS_LAST_PLAYED", cursor.getInt(4)); tempJson.put("SONGS_LAST_COMPLETED", cursor.getInt(5)); jsonSongDb.put(tempJson); } cursor.close(); return jsonSongDb; } catch (Exception e) { } return new JSONArray(); }
From source file:com.google.zxing.client.android.history.HistoryManager.java
public boolean hasHistoryItems() { SQLiteOpenHelper helper = new DBHelper(activity); SQLiteDatabase db = null;/* w w w. j av a 2 s . c o m*/ Cursor cursor = null; try { db = helper.getReadableDatabase(); cursor = db.query(DBHelper.TABLE_NAME, COUNT_COLUMN, null, null, null, null, null); cursor.moveToFirst(); return cursor.getInt(0) > 0; } finally { close(cursor, db); } }
From source file:com.samknows.measurement.storage.TestResultDataSource.java
public List<AggregateTestResult> getAverageResults(long starttime, long endtime) { List<AggregateTestResult> ret = new ArrayList<AggregateTestResult>(); String selection = String.format("dtime BETWEEN %d AND %d AND success <> 0", starttime, endtime); String averageColumn = String.format("AVG(%s)", SKSQLiteHelper.TR_COLUMN_RESULT); String[] columns = { SKSQLiteHelper.TR_COLUMN_TYPE, averageColumn, "COUNT(*)" }; String groupBy = SKSQLiteHelper.TR_COLUMN_TYPE; Cursor cursor = database.query(SKSQLiteHelper.TABLE_TESTRESULT, columns, selection, null, groupBy, null, null);//from w w w . j a v a2s. c om cursor.moveToFirst(); while (!cursor.isAfterLast()) { AggregateTestResult curr = new AggregateTestResult(); curr.testType = cursor.getString(0); curr.aggregateFunction = "average"; curr.value = cursor.getDouble(1); curr.numberOfResults = cursor.getInt(2); ret.add(curr); } cursor.close(); return ret; }
From source file:export.format.FacebookCourse.java
private JSONArray trail(long activityId) throws JSONException { final String cols[] = { DB.LOCATION.TYPE, DB.LOCATION.LATITUDE, DB.LOCATION.LONGITUDE, DB.LOCATION.TIME, DB.LOCATION.SPEED };/*from w w w .ja v a2s.com*/ Cursor c = mDB.query(DB.LOCATION.TABLE, cols, DB.LOCATION.ACTIVITY + " = " + activityId, null, null, null, null); if (c.moveToFirst()) { Location prev = null, last = null; double sumDist = 0; long sumTime = 0; double accTime = 0; final double period = 30; JSONArray arr = new JSONArray(); do { switch (c.getInt(0)) { case DB.LOCATION.TYPE_START: case DB.LOCATION.TYPE_RESUME: last = new Location("Dill"); last.setLatitude(c.getDouble(1)); last.setLongitude(c.getDouble(2)); last.setTime(c.getLong(3)); accTime = period * 1000; // always emit first point // start/resume break; case DB.LOCATION.TYPE_END: accTime = period * 1000; // always emit last point case DB.LOCATION.TYPE_GPS: case DB.LOCATION.TYPE_PAUSE: Location l = new Location("Sill"); l.setLatitude(c.getDouble(1)); l.setLongitude(c.getDouble(2)); l.setTime(c.getLong(3)); if (!c.isNull(4)) l.setSpeed(c.getFloat(4)); if (last != null) { sumDist += l.distanceTo(last); sumTime += l.getTime() - last.getTime(); accTime += l.getTime() - last.getTime(); } prev = last; last = l; } if (Math.round(accTime / 1000) >= period) { arr.put(point(prev, last, sumTime, sumDist)); accTime -= period * 1000; } } while (c.moveToNext()); c.close(); return arr; } c.close(); return null; }
From source file:org.openbmap.activities.DialogPreferenceCatalogs.java
/** * Initialises download manager for GINGERBREAD and newer *//* w w w . ja va 2 s .com*/ @SuppressLint("NewApi") private void initDownloadManager() { mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE); mReceiver = new BroadcastReceiver() { @SuppressLint("NewApi") @Override public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); final DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(downloadId); final Cursor c = mDownloadManager.query(query); if (c.moveToFirst()) { final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) { // we're not checking download id here, that is done in handleDownloads final String uriString = c .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); handleDownloads(uriString); } else { final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON)); Log.e(TAG, "Download failed: " + reason); } } } } }; getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
From source file:com.esri.squadleader.model.GeoPackageReader.java
/** * Reads the tables in a GeoPackage, makes a layer from each table, and returns a list containing * those layers.//from w w w . j a va2 s .co m * * @param gpkgPath the full path to the .gpkg file. * @param sr the spatial reference to which any raster layers should be projected, typically the * spatial reference of your map. * @param showVectors if true, this method will include the GeoPackage's vector layers. * @param showRasters if true, this method will include the GeoPackage's raster layer. * @param rasterRenderer the renderer to be used for raster layers. One simple option is an RGBRenderer. * @param markerRenderer the renderer to be used for point layers. * @param lineRenderer the renderer to be used for polyline layers. * @param fillRenderer the renderer to be used for polygon layers. * @return a list of the layers created for all tables in the GeoPackage. * @throws IOException if gpkgPath cannot be read. Possible reasons include the file not * existing, failure to request READ_EXTERNAL_STORAGE or * WRITE_EXTERNAL_STORAGE permission, or the GeoPackage containing an * invalid spatial reference. */ public List<Layer> readGeoPackageToLayerList(String gpkgPath, SpatialReference sr, boolean showVectors, boolean showRasters, RasterRenderer rasterRenderer, Renderer markerRenderer, Renderer lineRenderer, Renderer fillRenderer) throws IOException { List<Layer> layers = new ArrayList<Layer>(); if (showRasters) { // Check to see if there are any rasters before loading them SQLiteDatabase sqliteDb = null; Cursor cursor = null; try { sqliteDb = SQLiteDatabase.openDatabase(gpkgPath, null, SQLiteDatabase.OPEN_READONLY); cursor = sqliteDb.rawQuery("SELECT COUNT(*) FROM gpkg_contents WHERE data_type = ?", new String[] { "tiles" }); if (cursor.moveToNext()) { if (0 < cursor.getInt(0)) { cursor.close(); sqliteDb.close(); FileRasterSource src = new FileRasterSource(gpkgPath); rasterSources.add(src); if (null != sr) { src.project(sr); } RasterLayer rasterLayer = new RasterLayer(src); rasterLayer.setRenderer(rasterRenderer); rasterLayer .setName((gpkgPath.contains("/") ? gpkgPath.substring(gpkgPath.lastIndexOf("/") + 1) : gpkgPath) + " (raster)"); layers.add(rasterLayer); } } } catch (Throwable t) { Log.e(TAG, "Could not read raster(s) from GeoPackage", t); } finally { if (null != cursor) { cursor.close(); } if (null != sqliteDb) { sqliteDb.close(); } } } if (showVectors) { Geopackage gpkg; try { gpkg = new Geopackage(gpkgPath); } catch (RuntimeException ex) { throw new IOException(null != ex.getMessage() && ex.getMessage().contains("unknown wkt") ? "Geopackage " + gpkgPath + " contains an invalid spatial reference." : null, ex); } geopackages.add(gpkg); List<GeopackageFeatureTable> tables = gpkg.getGeopackageFeatureTables(); if (0 < tables.size()) { //First pass: polygons and unknowns HashSet<Geometry.Type> types = new HashSet<Geometry.Type>(); types.add(Geometry.Type.ENVELOPE); types.add(Geometry.Type.POLYGON); types.add(Geometry.Type.UNKNOWN); layers.addAll(getTablesAsLayers(tables, types, fillRenderer)); //Second pass: lines types.clear(); types.add(Geometry.Type.LINE); types.add(Geometry.Type.POLYLINE); layers.addAll(getTablesAsLayers(tables, types, lineRenderer)); //Third pass: points types.clear(); types.add(Geometry.Type.MULTIPOINT); types.add(Geometry.Type.POINT); layers.addAll(getTablesAsLayers(tables, types, markerRenderer)); } } return layers; }
From source file:com.tlongdev.bktf.interactor.TlongdevPriceListInteractor.java
public Integer run() { if (System.currentTimeMillis() - mPrefs.getLong(mContext.getString(R.string.pref_last_price_list_update), 0) < 3600000L && !manualSync) {/*from w w w. j ava 2 s. c om*/ //This task ran less than an hour ago and wasn't a manual sync, nothing to do. return 0; } try { //Get the youngest price from the database. If it's an update only prices newer than this //will be updated to speed up the update and reduce data usage. if (updateDatabase) { String[] columns = { PriceEntry.COLUMN_LAST_UPDATE }; Cursor cursor = mContext.getContentResolver().query(PriceEntry.CONTENT_URI, columns, null, null, PriceEntry.COLUMN_LAST_UPDATE + " DESC LIMIT 1"); if (cursor != null) { if (cursor.moveToFirst()) latestUpdate = cursor.getInt(0); cursor.close(); } } Uri uri = Uri.parse("http://tlongdev.com/api/v1/prices").buildUpon() .appendQueryParameter("since", String.valueOf(latestUpdate)).build(); OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url(uri.toString()).build(); Response response = client.newCall(request).execute(); if (response.body() != null) { return parseJson(response.body().byteStream()); } else if (response.code() >= 500) { errorMessage = "Server error: " + response.code(); } else if (response.code() >= 400) { errorMessage = "Client error: " + response.code(); } return -1; } catch (IOException e) { //There was a network error errorMessage = mContext.getString(R.string.error_network); e.printStackTrace(); } return -1; }
From source file:org.openbmap.activities.DialogPreferenceMaps.java
/** * Initialises download manager for GINGERBREAD and newer *///from ww w . ja va2 s.c o m @SuppressLint("NewApi") private void initDownloadManager() { mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE); mReceiver = new BroadcastReceiver() { @SuppressLint("NewApi") @Override public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); final DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(downloadId); final Cursor c = mDownloadManager.query(query); if (c.moveToFirst()) { final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) { // we're not checking download id here, that is done in handleDownloads final String uriString = c .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); handleDownloads(uriString); } else { final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON)); Log.e(TAG, "Download failed: " + reason); } } } } }; getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
From source file:se.lu.nateko.edca.svc.GetMap.java
/** * Method that fetches the names of the layers set to be displayed in the local * SQLite database and returns them in a single String, with the names separated * by commas.//from w ww . j av a 2 s . c o m * @return A String with the names of the layers to be included in a GetMap request. */ public String fetchLayerNames() { // Log.d(TAG, "fetchLayerNames() called."); Cursor layers = mService.getSQLhelper().fetchData(LocalSQLDBhelper.TABLE_LAYER, LocalSQLDBhelper.KEY_LAYER_COLUMNS, LocalSQLDBhelper.ALL_RECORDS, null, false); mService.getActiveActivity().startManagingCursor(layers); String layerString = ""; if (layers.moveToFirst()) { int layerCount = 0; if (layers.getInt(2) % LocalSQLDBhelper.LAYER_MODE_DISPLAY == 0) { // If the layer is set to "display", then; layerString = layerString + layers.getString(1); // Add the first name to the String. layerCount++; } while (layers.moveToNext()) { // As long as there's another row: if (layers.getInt(2) % LocalSQLDBhelper.LAYER_MODE_DISPLAY == 0) {// If the layer is set to "display", then; if (layerCount > 0) layerString = layerString + ","; // Add a comma separator to the String. layerString = layerString + layers.getString(1); // Add the next name to the String. layerCount++; } } Log.v(TAG, String.valueOf(layerCount) + " layers are to be included in the GetMap request."); } Log.v(TAG, "layerString: " + layerString); return layerString; }