List of usage examples for android.database Cursor getFloat
float getFloat(int columnIndex);
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.MapFragment.java
private void onMarkerLoaderComplete(Cursor cursor) { if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst();/*w w w. ja v a 2s . co m*/ while (!cursor.isAfterLast()) { // get data String id = cursor.getString(MarkerQuery.MARKER_ID); int floor = cursor.getInt(MarkerQuery.MARKER_FLOOR); float lat = cursor.getFloat(MarkerQuery.MARKER_LATITUDE); float lon = cursor.getFloat(MarkerQuery.MARKER_LONGITUDE); String type = cursor.getString(MarkerQuery.MARKER_TYPE); String label = cursor.getString(MarkerQuery.MARKER_LABEL); String track = cursor.getString(MarkerQuery.MARKER_TRACK); BitmapDescriptor icon = null; if (TYPE_SESSION.equals(type)) { icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_session); } else if (TYPE_SANDBOX.equals(type)) { icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_sandbox); } else if (TYPE_LABEL.equals(type)) { Bitmap b = MapUtils.createTextLabel(label, mDPI); if (b != null) { icon = BitmapDescriptorFactory.fromBitmap(b); } } // add marker to map if (icon != null) { Marker m = mMap.addMarker(new MarkerOptions().position(new LatLng(lat, lon)).title(id) .snippet(type).icon(icon).visible(false)); MarkerModel model = new MarkerModel(id, floor, type, label, track, m); mMarkersFloor.get(floor).add(m); mMarkers.put(id, model); } cursor.moveToNext(); } // no more markers to load mMarkersLoaded = true; enableFloors(); } }
From source file:com.phonegap.plugins.sqlitePlugin.SQLitePlugin.java
/** * Process query results.//w w w . ja v a 2s . c om * * @param cur * Cursor into query results * @param tx_id * Transaction id */ public void processResults(Cursor cur, String query_id, String tx_id) { String result = "[]"; // If query result has rows if (cur.moveToFirst()) { JSONArray fullresult = new JSONArray(); String key = ""; int colCount = cur.getColumnCount(); // Build up JSON result object for each row do { JSONObject row = new JSONObject(); try { for (int i = 0; i < colCount; ++i) { key = cur.getColumnName(i); if (android.os.Build.VERSION.SDK_INT >= 11) { switch (cur.getType(i)) { case Cursor.FIELD_TYPE_NULL: row.put(key, null); break; case Cursor.FIELD_TYPE_INTEGER: row.put(key, cur.getInt(i)); break; case Cursor.FIELD_TYPE_FLOAT: row.put(key, cur.getFloat(i)); break; case Cursor.FIELD_TYPE_STRING: row.put(key, cur.getString(i)); break; case Cursor.FIELD_TYPE_BLOB: row.put(key, cur.getBlob(i)); break; } } else { row.put(key, cur.getString(i)); } } fullresult.put(row); } catch (JSONException e) { e.printStackTrace(); } } while (cur.moveToNext()); result = fullresult.toString(); } if (query_id.length() > 0) this.sendJavascript(" SQLitePluginTransaction.queryCompleteCallback('" + tx_id + "','" + query_id + "', " + result + ");"); }
From source file:info.curtbinder.reefangel.service.NotificationService.java
private void processNotifications() { Uri uri = Uri.parse(StatusProvider.CONTENT_URI + "/" + StatusProvider.PATH_NOTIFICATION); // get all notifications Cursor c = getContentResolver().query(uri, null, null, null, NotificationTable.COL_ID + " ASC"); int notifyCount = 0; if (c.moveToFirst()) { int param = 0, cond = 0; float value = (float) 0.0; parameters = rapp.getResources().getStringArray(R.array.deviceParameters); // grab the latest parameters to compare against Uri uriLatest = Uri.parse(StatusProvider.CONTENT_URI + "/" + StatusProvider.PATH_LATEST); // get all notifications Cursor l = getContentResolver().query(uriLatest, null, null, null, StatusTable.COL_ID + " DESC"); l.moveToFirst();//from ww w. ja v a 2 s.co m do { param = c.getInt(c.getColumnIndex(NotificationTable.COL_PARAM)); cond = c.getInt(c.getColumnIndex(NotificationTable.COL_CONDITION)); value = c.getFloat(c.getColumnIndex(NotificationTable.COL_VALUE)); errorMessage = ""; if (isNotifyTriggered(param, cond, value, l)) { // notification triggered // add to list of notifications insertErrorMessage(errorMessage); notifyCount++; } } while (c.moveToNext()); l.close(); } // else no notifications c.close(); // launch the notification after we process the messages if (notifyCount > 0) { notifyUser(); } }
From source file:com.example.puter.sunshine.app.DetailFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); long date = data.getLong(COL_WEATHER_DATE); String friendlyDateText = Utility.getDayName(getActivity(), date); String dateText = Utility.getFormattedMonthDay(getActivity(), date); mFriendlyDateView.setText(friendlyDateText); mDateView.setText(dateText);/* w w w. j a va 2 s .c om*/ String description = data.getString(COL_WEATHER_DESC); mDescriptionView.setText(description); mIconView.setContentDescription(description); boolean isMetric = Utility.isMetric(getActivity()); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = Utility.formatTemperature(getActivity(), high); mHighTempView.setText(highString); double low = data.getDouble(COL_WEATHER_MIN_TEMP); String lowString = Utility.formatTemperature(getActivity(), low); mLowTempView.setText(lowString); float humidity = data.getFloat(COL_WEATHER_HUMIDITY); mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity)); float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED); float windDirStr = data.getFloat(COL_WEATHER_DEGREES); mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr)); float pressure = data.getFloat(COL_WEATHER_PRESSURE); mPressureView.setText(getActivity().getString(R.string.format_pressure, pressure)); mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low); if (mShareActionProvider != null) { mShareActionProvider.setShareIntent(createShareForecastIntent()); } } }
From source file:net.fluidnexus.FluidNexusAndroid.services.NexusServiceThread.java
/** * Start the listeners for zeroconf services *//*from w w w.j av a 2 s. c o m*/ public void doStateNone() { if (wifiManager.getWifiState() == wifiManager.WIFI_STATE_ENABLED) { Cursor c = messagesProviderHelper.publicMessages(); while (c.isAfterLast() == false) { String message_hash = c.getString(c.getColumnIndex(MessagesProviderHelper.KEY_MESSAGE_HASH)); boolean result = checkHash(message_hash); if (!result) { try { JSONObject message = new JSONObject(); message.put("message_title", c.getString(c.getColumnIndex(MessagesProviderHelper.KEY_TITLE))); message.put("message_content", c.getString(c.getColumnIndex(MessagesProviderHelper.KEY_CONTENT))); message.put("message_hash", c.getString(c.getColumnIndex(MessagesProviderHelper.KEY_MESSAGE_HASH))); message.put("message_type", c.getInt(c.getColumnIndex(MessagesProviderHelper.KEY_TYPE))); message.put("message_time", c.getFloat(c.getColumnIndex(MessagesProviderHelper.KEY_TIME))); message.put("message_received_time", c.getFloat(c.getColumnIndex(MessagesProviderHelper.KEY_RECEIVED_TIME))); message.put("message_priority", c.getInt(c.getColumnIndex(MessagesProviderHelper.KEY_PRIORITY))); String attachment_path = c .getString(c.getColumnIndex(MessagesProviderHelper.KEY_ATTACHMENT_PATH)); //String serializedMessage = message.toString(); // First, get our nonce consumer = new CommonsHttpOAuthConsumer(key, secret); consumer.setTokenWithSecret(token, token_secret); HttpPost nonce_request = new HttpPost(NEXUS_NONCE_URL); consumer.sign(nonce_request); HttpClient client = new DefaultHttpClient(); String response = client.execute(nonce_request, new BasicResponseHandler()); JSONObject object = new JSONObject(response); String nonce = object.getString("nonce"); // Then, take our nonce and key and put them in the message message.put("message_nonce", nonce); message.put("message_key", key); // Setup our multipart entity MultipartEntity entity = new MultipartEntity(); // Deal with file attachment if (!attachment_path.equals("")) { File file = new File(attachment_path); ContentBody cbFile = new FileBody(file); entity.addPart("message_attachment", cbFile); // add the original filename to the message message.put("message_attachment_original_filename", c.getString( c.getColumnIndex(MessagesProviderHelper.KEY_ATTACHMENT_ORIGINAL_FILENAME))); } String serializedMessage = message.toString(); ContentBody messageBody = new StringBody(serializedMessage); entity.addPart("message", messageBody); HttpPost message_request = new HttpPost(NEXUS_MESSAGE_URL); message_request.setEntity(entity); client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); response = client.execute(message_request, new BasicResponseHandler()); object = new JSONObject(response); boolean message_result = object.getBoolean("result"); if (message_result) { ContentValues values = new ContentValues(); values.put(MessagesProviderHelper.KEY_MESSAGE_HASH, message_hash); values.put(MessagesProviderHelper.KEY_UPLOADED, 1); int res = messagesProviderHelper .setPublic(c.getLong(c.getColumnIndex(MessagesProviderHelper.KEY_ID)), values); if (res == 0) { log.debug("Message with hash " + message_hash + " not found; this should never happen!"); } } } catch (OAuthMessageSignerException e) { log.debug("OAuthMessageSignerException: " + e); } catch (OAuthExpectationFailedException e) { log.debug("OAuthExpectationFailedException: " + e); } catch (OAuthCommunicationException e) { log.debug("OAuthCommunicationException: " + e); } catch (JSONException e) { log.debug("JSON Error: " + e); } catch (IOException e) { log.debug("IOException: " + e); } } c.moveToNext(); } c.close(); } setServiceState(STATE_SERVICE_WAIT); }
From source file:org.spontaneous.trackservice.RemoteService.java
public TrackModel readTrackAndSegmentsById(Long trackId) { TrackModel trackModel = null;/*from w w w . j ava 2 s .c o m*/ if (trackId != null) { String[] mTrackColumns = { Tracks._ID, Tracks.NAME, Tracks.TOTAL_DISTANCE, Tracks.TOTAL_DURATION, Tracks.USER_ID, Tracks.CREATION_TIME }; // Read track Uri trackReadUri = Uri.withAppendedPath(Tracks.CONTENT_URI, String.valueOf(trackId)); Cursor mCursor = getContentResolver().query(trackReadUri, mTrackColumns, null, null, Tracks.CREATION_TIME); if (mCursor != null && mCursor.moveToNext()) { trackModel = new TrackModel(Long.valueOf(mCursor.getString(mCursor.getColumnIndex(Tracks._ID))), mCursor.getString(mCursor.getColumnIndex(Tracks.NAME)), mCursor.getFloat(mCursor.getColumnIndex(Tracks.TOTAL_DISTANCE)), mCursor.getLong(mCursor.getColumnIndex(Tracks.TOTAL_DURATION)), mCursor.getLong(mCursor.getColumnIndex(Tracks.CREATION_TIME)), Integer.valueOf(mCursor.getColumnIndex(Tracks.USER_ID))); // Read Segments and wayPoints String[] mSegmentsColumns = { BaseColumns._ID, SegmentsColumns.TRACK, SegmentsColumns.START_TIME, SegmentsColumns.END_TIME }; Uri segmentReadUri = Uri.withAppendedPath(Tracks.CONTENT_URI, String.valueOf(trackId) + "/segments/"); Cursor mSegmentsCursor = getContentResolver().query(segmentReadUri, mSegmentsColumns, null, null, Segments._ID); if (mSegmentsCursor != null) { SegmentModel segmentModel = null; while (mSegmentsCursor.moveToNext()) { segmentModel = new SegmentModel(); segmentModel.setId(Long .valueOf(mSegmentsCursor.getString(mSegmentsCursor.getColumnIndex(Segments._ID)))); segmentModel.setTrackId(Long.valueOf( mSegmentsCursor.getString(mSegmentsCursor.getColumnIndex(Segments.TRACK)))); segmentModel.setStartTimeInMillis( mSegmentsCursor.getLong(mSegmentsCursor.getColumnIndex(Segments.START_TIME))); segmentModel.setEndTimeInMillis( mSegmentsCursor.getLong(mSegmentsCursor.getColumnIndex(Segments.END_TIME))); trackModel.addSegment(segmentModel); } } } } return trackModel; }
From source file:com.gvccracing.android.tttimer.Tabs.RaceInfoTab.java
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { try {//from w ww.j a v a 2 s . co m Log.i(LOG_TAG(), "onLoadFinished start: id=" + Integer.toString(loader.getId())); switch (loader.getId()) { case RACE_INFO_LOADER: cursor.moveToFirst(); if (cursor.getCount() > 0) { Long raceDateMS = cursor.getLong(cursor.getColumnIndex(Race.RaceDate)); String courseName = cursor.getString(cursor.getColumnIndex(RaceLocation.CourseName)); long raceTypeID = cursor.getLong(cursor.getColumnIndex(Race.RaceType)); String raceTypeName = RaceType.DescriptionFromRaceTypeID(raceTypeID); String startIntervalText = Long .toString(cursor.getLong(cursor.getColumnIndex(Race.StartInterval))); long numRaceLaps = cursor.getLong(cursor.getColumnIndex(Race.NumLaps)); distance = Float.toString( cursor.getFloat(cursor.getColumnIndex(RaceLocation.Distance)) * (float) numRaceLaps); if (distance == null) { distance = ""; } if (raceTypeID == 1) { raceLaps.setText(Long.toString(numRaceLaps)); llRaceLaps.setVisibility(View.VISIBLE); } else { llRaceLaps.setVisibility(View.GONE); } Date raceDateTemp = new Date(raceDateMS); SimpleDateFormat formatter = new SimpleDateFormat("M/d/yy"); raceDate.setText(formatter.format(raceDateTemp).toString()); raceCourseName.setText(courseName); raceType.setText(raceTypeName); raceStartInterval.setText(startIntervalText); SetDistance(); } break; case APP_SETTINGS_LOADER_RACEINFO: getActivity().getSupportLoaderManager().restartLoader(COURSE_RECORD_LOADER, null, this); Integer distanceUnitID = Integer.parseInt(AppSettings.Instance().ReadValue(getActivity(), AppSettings.AppSetting_DistanceUnits_Name, "0")); distanceUnit = "mi"; switch (distanceUnitID) { case 0: distanceUnit = "mi"; break; case 1: distanceUnit = "km"; break; default: distanceUnit = "mi"; break; } getActivity().getSupportLoaderManager().restartLoader(RACE_INFO_LOADER, null, this); break; case COURSE_RECORD_LOADER: if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); long elapsedTime = cursor.getLong(cursor.getColumnIndex(RaceResults.ElapsedTime)); if (courseRecord != null) { courseRecord.setText(TimeFormatter.Format(elapsedTime, true, true, true, true, true, false, false, false)); } } break; } Log.i(LOG_TAG(), "onLoadFinished complete: id=" + Integer.toString(loader.getId())); } catch (Exception ex) { Log.e(LOG_TAG(), "onLoadFinished error", ex); } }
From source file:com.digicorp.plugin.sqlitePlugin.SQLitePlugin.java
/** * Convert results cursor to JSON string. * * @param cur//w w w . j a v a 2 s .c o m * Cursor into query results * * @return results in string form * */ @SuppressLint("NewApi") private String results2string(Cursor cur) { String result = "[]"; // If query result has rows if (cur.moveToFirst()) { JSONArray fullresult = new JSONArray(); String key = ""; int colCount = cur.getColumnCount(); // Build up JSON result object for each row do { JSONObject row = new JSONObject(); try { for (int i = 0; i < colCount; ++i) { key = cur.getColumnName(i); // for old Android SDK remove lines from HERE: if (android.os.Build.VERSION.SDK_INT >= 11) { switch (cur.getType(i)) { case Cursor.FIELD_TYPE_NULL: row.put(key, null); break; case Cursor.FIELD_TYPE_INTEGER: row.put(key, cur.getInt(i)); break; case Cursor.FIELD_TYPE_FLOAT: row.put(key, cur.getFloat(i)); break; case Cursor.FIELD_TYPE_STRING: row.put(key, cur.getString(i)); break; case Cursor.FIELD_TYPE_BLOB: row.put(key, new String(Base64.encode(cur.getBlob(i), Base64.DEFAULT))); break; } } else // to HERE. { row.put(key, cur.getString(i)); } } fullresult.put(row); } catch (JSONException e) { e.printStackTrace(); } } while (cur.moveToNext()); result = fullresult.toString(); } return result; }
From source file:com.zetaDevelopment.phonegap.plugin.sqlitePlugin.SQLitePlugin.java
/** * Convert results cursor to JSON string. * * @param cur/*from w w w. j a v a2 s.c o m*/ * Cursor into query results * * @return results in string form * */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private String results2string(Cursor cur) { String result = "[]"; // If query result has rows if (cur.moveToFirst()) { JSONArray fullresult = new JSONArray(); String key = ""; int colCount = cur.getColumnCount(); // Build up JSON result object for each row do { JSONObject row = new JSONObject(); try { for (int i = 0; i < colCount; ++i) { key = cur.getColumnName(i); // for old Android SDK remove lines from HERE: if (android.os.Build.VERSION.SDK_INT >= 11) { switch (cur.getType(i)) { case Cursor.FIELD_TYPE_NULL: row.put(key, null); break; case Cursor.FIELD_TYPE_INTEGER: row.put(key, cur.getInt(i)); break; case Cursor.FIELD_TYPE_FLOAT: row.put(key, cur.getFloat(i)); break; case Cursor.FIELD_TYPE_STRING: row.put(key, cur.getString(i)); break; case Cursor.FIELD_TYPE_BLOB: //row.put(key, cur.getBlob(i)); row.put(key, new String(Base64.encode(cur.getBlob(i), Base64.DEFAULT))); break; } } else // to HERE. { row.put(key, cur.getString(i)); } } fullresult.put(row); } catch (JSONException e) { e.printStackTrace(); } } while (cur.moveToNext()); result = fullresult.toString(); } return result; }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public float firstFloat(SQLiteDatabase db, String table, String column, String orderBy) { Cursor cursor = null; float value = 0; try {//www.j av a2 s . co m cursor = query(db, table, new String[] { column }, orderBy); if (cursor.moveToFirst()) { value = cursor.getFloat(0); } } finally { Closeables.closeSilently(cursor); } return value; }