List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:com.upenn.chriswang1990.sunshine.sync.SunshineSyncAdapter.java
private void notifyWeather() { Context context = getContext(); //checking the last update and notify if it' the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String displayNotificationsKey = context.getString(R.string.pref_enable_notifications_key); boolean displayNotifications = prefs.getBoolean(displayNotificationsKey, Boolean.parseBoolean(context.getString(R.string.pref_enable_notifications_default))); if (displayNotifications) { String lastNotificationKey = context.getString(R.string.pref_last_notification); long lastSync = prefs.getLong(lastNotificationKey, 0); if (System.currentTimeMillis() - lastSync >= DAY_IN_MILLIS) { // Last sync was more than 1 day ago, let's send a notification with the weather. String locationQuery = Utility.getPreferredLocation(context); String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC"; Uri weatherUri = WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationQuery, Utility.normalizeDate(System.currentTimeMillis() / 1000, Utility.getTimezoneID(context))); // we'll query our contentProvider, as always Cursor cursor = context.getContentResolver().query(weatherUri, NOTIFY_WEATHER_PROJECTION, null, null, null);//from w w w . j a va2s . co m if (cursor.moveToFirst()) { String cityName = cursor.getString(INDEX_CITY_NAME); int weatherId = cursor.getInt(INDEX_WEATHER_ID); double high = cursor.getDouble(INDEX_MAX_TEMP); double low = cursor.getDouble(INDEX_MIN_TEMP); String desc = cursor.getString(INDEX_SHORT_DESC); int iconId = Utility.getIconResourceForWeatherCondition(weatherId); Resources resources = context.getResources(); Bitmap largeIcon = BitmapFactory.decodeResource(resources, Utility.getArtResourceForWeatherCondition(weatherId)); String title = context.getString(R.string.app_name); // Define the text of the forecast. String contentText = String.format(context.getString(R.string.format_notification), cityName, desc, Utility.formatTemperature(context, high), Utility.formatTemperature(context, low)); // NotificationCompatBuilder is a very convenient way to build backward-compatible // notifications. Just throw in some data. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setColor(context.getResources().getColor(R.color.primary_light)).setSmallIcon(iconId) .setLargeIcon(largeIcon).setContentTitle(title).setContentText(contentText); // Make something interesting happen when the user clicks on the notification. // In this case, opening the app is sufficient. Intent resultIntent = new Intent(context, MainActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); // WEATHER_NOTIFICATION_ID allows you to update the notification later on. mNotificationManager.notify(WEATHER_NOTIFICATION_ID, mBuilder.build()); //refreshing last sync SharedPreferences.Editor editor = prefs.edit(); editor.putLong(lastNotificationKey, System.currentTimeMillis()); editor.apply(); } cursor.close(); } } }
From source file:edu.auburn.ppl.cyclecolumbus.TripUploader.java
/****************************************************************************************** * Puts the data from a trip in database into vector ****************************************************************************************** * @param tripId Unique ID of each trip/*from w w w. j av a 2 s . c o m*/ * @return Vector of the trip ******************************************************************************************/ private Vector<String> getTripData(long tripId) { Vector<String> tripData = new Vector<String>(); mDb.openReadOnly(); Cursor tripCursor = mDb.fetchTrip(tripId); setKcalCo2Savings(tripCursor); String note = tripCursor.getString(tripCursor.getColumnIndex(DbAdapter.K_TRIP_NOTE)); String purpose = tripCursor.getString(tripCursor.getColumnIndex(DbAdapter.K_TRIP_PURP)); Double startTime = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_START)); Double endTime = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_END)); tripCursor.close(); mDb.close(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); tripData.add(note); tripData.add(purpose); tripData.add(df.format(startTime)); tripData.add(df.format(endTime)); return tripData; }
From source file:org.xbmc.kore.ui.sections.video.MovieInfoFragment.java
/** {@inheritDoc} */ @Override//from ww w. j a va 2 s. c o m public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { if (cursor != null && cursor.getCount() > 0) { switch (cursorLoader.getId()) { case LOADER_MOVIE: cursor.moveToFirst(); this.cursor = cursor; DataHolder dataHolder = getDataHolder(); dataHolder.setFanArtUrl(cursor.getString(MovieDetailsQuery.FANART)); dataHolder.setPosterUrl(cursor.getString(MovieDetailsQuery.THUMBNAIL)); dataHolder.setRating(cursor.getDouble(MovieDetailsQuery.RATING)); dataHolder.setMaxRating(10); dataHolder.setVotes(cursor.getInt(MovieDetailsQuery.VOTES)); String director = cursor.getString(MovieDetailsQuery.DIRECTOR); if (!TextUtils.isEmpty(director)) { director = getString(R.string.directors) + " " + director; } int runtime = cursor.getInt(MovieDetailsQuery.RUNTIME) / 60; String year = String.valueOf(cursor.getInt(MovieDetailsQuery.YEAR)); String durationYear = runtime > 0 ? String.format(getString(R.string.minutes_abbrev), String.valueOf(runtime)) + " | " + year : String.valueOf(year); dataHolder.setDetails( durationYear + "\n" + cursor.getString(MovieDetailsQuery.GENRES) + "\n" + director); dataHolder.setTitle(cursor.getString(MovieDetailsQuery.TITLE)); dataHolder.setUndertitle(cursor.getString(MovieDetailsQuery.TAGLINE)); dataHolder.setDescription(cursor.getString(MovieDetailsQuery.PLOT)); movieDownloadInfo = new FileDownloadHelper.MovieInfo(dataHolder.getTitle(), cursor.getString(MovieDetailsQuery.FILE)); setDownloadButtonState(movieDownloadInfo.downloadDirectoryExists()); setSeenButtonState(cursor.getInt(MovieDetailsQuery.PLAYCOUNT) > 0); updateView(dataHolder); checkOutdatedMovieDetails(cursor); break; } } }
From source file:ch.berta.fabio.popularmovies.data.repositories.MovieRepositoryImpl.java
@Override public Movie getMovieFromFavMovieDetailsCursor(@NonNull Cursor cursor) { final int dbId = cursor.getInt(COL_INDEX_MOVIE_DETAILS_DB_ID); final String title = cursor.getString(COL_INDEX_MOVIE_DETAILS_TITLE); final Date releaseDate = new Date(cursor.getLong(COL_INDEX_MOVIE_DETAILS_RELEASE_DATE)); final String poster = cursor.getString(COL_INDEX_MOVIE_DETAILS_POSTER); final String backdrop = cursor.getString(COL_INDEX_MOVIE_DETAILS_BACKDROP); final String plot = cursor.getString(COL_INDEX_MOVIE_DETAILS_PLOT); final double rating = cursor.getDouble(COL_INDEX_MOVIE_DETAILS_VOTE_AVERAGE); List<Review> reviews = new ArrayList<>(); int reviewIdCounter = 0; List<Video> videos = new ArrayList<>(); int videoIdCounter = 0; do {/*from www. j a va 2 s . c om*/ if (!cursor.isNull(COL_INDEX_MOVIE_DETAILS_REVIEW_ID)) { final int id = cursor.getInt(COL_INDEX_MOVIE_DETAILS_REVIEW_ID); final String author = cursor.getString(COL_INDEX_MOVIE_DETAILS_REVIEW_AUTHOR); final String content = cursor.getString(COL_INDEX_MOVIE_DETAILS_REVIEW_CONTENT); final String url = cursor.getString(COL_INDEX_MOVIE_DETAILS_REVIEW_URL); if (id > reviewIdCounter) { reviewIdCounter = id; reviews.add(new Review(author, content, url)); } } if (!cursor.isNull(COL_INDEX_MOVIE_DETAILS_VIDEO_ID)) { final int id = cursor.getInt(COL_INDEX_MOVIE_DETAILS_VIDEO_ID); final String name = cursor.getString(COL_INDEX_MOVIE_DETAILS_VIDEO_NAME); final String key = cursor.getString(COL_INDEX_MOVIE_DETAILS_VIDEO_KEY); final String site = cursor.getString(COL_INDEX_MOVIE_DETAILS_VIDEO_SITE); final int size = cursor.getInt(COL_INDEX_MOVIE_DETAILS_VIDEO_SIZE); final String type = cursor.getString(COL_INDEX_MOVIE_DETAILS_VIDEO_TYPE); if (id > videoIdCounter) { videoIdCounter = id; videos.add(new Video(name, key, site, size, type)); } } } while (cursor.moveToNext()); return new Movie(videos, backdrop, dbId, plot, releaseDate, poster, title, rating, reviews, true); }
From source file:com.katamaditya.apps.weather4u.weathersync.Weather4USyncAdapter.java
public void notifyWeather() { Context context = getContext(); //checking the last update and notify if it' the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String displayNotificationsKey = context.getString(R.string.pref_enable_notifications_key); boolean displayNotifications = prefs.getBoolean(displayNotificationsKey, Boolean.parseBoolean(context.getString(R.string.pref_enable_notifications_default))); if (displayNotifications) { String lastNotificationKey = context.getString(R.string.pref_last_notification); long lastSync = prefs.getLong(lastNotificationKey, 0); if (System.currentTimeMillis() - lastSync >= getNotificationTimeGap()) { // Last sync was more than 1 day ago, let's send a notification with the weather. String locationQuery = WeatherUtil.getPreferredLocation(context); Uri weatherUri = WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationQuery, System.currentTimeMillis()); // we'll query our contentProvider, as always Cursor cursor = context.getContentResolver().query(weatherUri, NOTIFY_WEATHER_PROJECTION, null, null, null);// w w w.j a v a 2 s .c o m if (cursor.moveToFirst()) { int weatherId = cursor.getInt(INDEX_WEATHER_ID); double high = cursor.getDouble(INDEX_MAX_TEMP); double low = cursor.getDouble(INDEX_MIN_TEMP); String desc = cursor.getString(INDEX_SHORT_DESC); int iconId = WeatherUtil.getIconResourceForWeatherCondition(weatherId); Resources resources = context.getResources(); Bitmap largeIcon = BitmapFactory.decodeResource(resources, WeatherUtil.getArtResourceForWeatherCondition(weatherId)); String title = getTitle(); // Define the text of the forecast. String contentText = String.format(context.getString(R.string.format_notification), desc, WeatherUtil.formatTemperature(context, high), WeatherUtil.formatTemperature(context, low)); // NotificationCompatBuilder is a very convenient way to build backward-compatible // notifications. Just throw in some data. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getContext()) .setColor(resources.getColor(R.color.weather4u_light_blue)).setSmallIcon(iconId) .setLargeIcon(largeIcon).setContentTitle(title).setContentText(contentText); mBuilder.setAutoCancel(true); // Make something interesting happen when the user clicks on the notification. // In this case, opening the app is sufficient. Intent resultIntent = new Intent(context, MainActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); // WEATHER_NOTIFICATION_ID allows you to update the notification later on. mNotificationManager.notify(WEATHER_NOTIFICATION_ID, mBuilder.build()); //refreshing last sync SharedPreferences.Editor editor = prefs.edit(); editor.putLong(lastNotificationKey, System.currentTimeMillis()); editor.commit(); } cursor.close(); } } }
From source file:com.wildplot.android.ankistats.CardsTypes.java
public boolean calculateCardsTypes(int type) { mTitle = R.string.stats_cards_types; mAxisTitles = new int[] { R.string.stats_answer_type, R.string.stats_answers, R.string.stats_cumulative_correct_percentage }; mValueLabels = new int[] { R.string.statistics_mature, R.string.statistics_young_and_learn, R.string.statistics_unlearned, R.string.statistics_suspended }; mColors = new int[] { R.color.stats_mature, R.color.stats_young, R.color.stats_unseen, R.color.stats_suspended };//from w w w . j a v a 2 s . c om mType = type; ArrayList<double[]> list = new ArrayList<double[]>(); double[] pieData; Cursor cur = null; String query = "select " + "sum(case when queue=2 and ivl >= 21 then 1 else 0 end), -- mtr\n" + "sum(case when queue in (1,3) or (queue=2 and ivl < 21) then 1 else 0 end), -- yng/lrn\n" + "sum(case when queue=0 then 1 else 0 end), -- new\n" + "sum(case when queue<0 then 1 else 0 end) -- susp\n" + "from cards where did in " + _limitWholeOnly(); Log.d(AnkiStatsApplication.TAG, "CardsTypes query: " + query); try { cur = mAnkiDb.getDatabase().rawQuery(query, null); cur.moveToFirst(); pieData = new double[] { cur.getDouble(0), cur.getDouble(1), cur.getDouble(2), cur.getDouble(3) }; } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } //TODO adjust for CardsTypes, for now only copied from intervals // small adjustment for a proper chartbuilding with achartengine // if (list.size() == 0 || list.get(0)[0] > 0) { // list.add(0, new double[] { 0, 0, 0 }); // } // if (num == -1 && list.size() < 2) { // num = 31; // } // if (type != Utils.TYPE_LIFE && list.get(list.size() - 1)[0] < num) { // list.add(new double[] { num, 0, 0 }); // } else if (type == Utils.TYPE_LIFE && list.size() < 2) { // list.add(new double[] { Math.max(12, list.get(list.size() - 1)[0] + 1), 0, 0 }); // } mSeriesList = new double[1][4]; mSeriesList[0] = pieData; return list.size() > 0; }
From source file:fr.eoit.activity.ItemInfo2Activity.java
@Override public void onLoadFinished(Cursor cursor) { if (DbUtil.hasAtLeastOneRow(cursor)) { itemId = cursor.getInt(cursor.getColumnIndexOrThrow(Item._ID)); categorieId = cursor.getInt(cursor.getColumnIndexOrThrow(Groups.COLUMN_NAME_CATEGORIE_ID)); favorite = cursor.getInt(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_FAVORITE)) > 0; metaGroupId = cursor.getInt(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_META_GROUP_ID)); int groupId = cursor.getInt(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_GROUP_ID)); volume = cursor.getDouble(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_VOLUME)); itemName = cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME)); setActionBarTitle(itemName);//from ww w . ja va2 s.co m trackEvent("Event", "Item view", itemName, (int) Parameters.characterId); int choosen_price_id = cursor.getInt(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_CHOSEN_PRICE_ID)); switch (choosen_price_id) { case EOITConst.BUY_PRICE_ID: setActionBarSubtitle(R.string.item_buy_desc); break; case EOITConst.SELL_PRICE_ID: setActionBarSubtitle(R.string.item_sell_desc); break; case EOITConst.PRODUCE_PRICE_ID: setActionBarSubtitle(R.string.item_prod_desc); break; default: break; } IconUtil.initIconOrRender(itemId, categorieId, groupId, (ImageView) findViewById(R.id.ITEM_ICON)); pricesFragment.setItemId(itemId); if (categorieId == EOITConst.Categories.PLANETARY_COMMODITIES_CATEGORIE_ID || categorieId == EOITConst.Categories.COMMODITY_CATEGORIE_ID && groupId == EOITConst.Groups.GENERAL_COMMODITY_GROUP_ID) { producesFragment.getView().setVisibility(View.GONE); } else { producesFragment.setItemId(itemId); } if (categorieId == EOITConst.Categories.ASTEROID_CATEGORIE_ID) { refineMaterialListFragment.setCategoryId(categorieId); refineMaterialListFragment.setItemId(itemId); } else { refineMaterialListFragment.getView().setVisibility(View.GONE); } blueprintInfoFragment.setGroupId(groupId); blueprintInfoFragment.setMetaGroupId(metaGroupId); blueprintInfoFragment.setCategorieId(categorieId); blueprintInfoFragment.setItemName(itemName); blueprintInfoFragment.setItemId(itemId); if (favoriteMenuItem != null) { favoriteMenuItem.setActionView(new FavoriteActionView(getApplicationContext(), itemId, favorite)); } setActionBarInderterminate(false); } }
From source file:com.yammy.meter.MainActivity.java
private void getVehVal() { /**/*from ww w. ja va 2s. c o m*/ * get value from saved preferences */ try { prefs = getSharedPreferences(prefName, MODE_PRIVATE); nopol.setText(prefs.getString("nopol", null)); idkendaraan = Integer.parseInt(prefs.getString("idkendaraan", null)); start.setEnabled(true); } catch (Exception e) { idkendaraan = prefs.getInt("idkendaraan", 0); start.setEnabled(false); } dbHelper = new MySQLHelper(getApplicationContext()); SQLiteDatabase jdb = dbHelper.getReadableDatabase(); try { Cursor cursor = jdb.rawQuery("SELECT SUM(jarak) FROM perjalanan WHERE id_kendaraan=" + idkendaraan, null); if (cursor.moveToFirst()) { try { totalJarakDitempuhKendaraan = Double.parseDouble(String.format("%.2f", cursor.getString(0))); } catch (NumberFormatException e) { totalJarakDitempuhKendaraan = Double.parseDouble(cursor.getString(0)); } catch (Exception e) { totalJarakDitempuhKendaraan = cursor.getDouble(0); } } else { totalJarakDitempuhKendaraan = 0.0; } Toast.makeText(getBaseContext(), "Sudah ditempuh : " + totalJarakDitempuhKendaraan + " m", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), "Belum pernah melakukan perjalanan", Toast.LENGTH_SHORT).show(); } jdb.close(); }
From source file:edu.pdx.cecs.orcycle.TripUploader.java
@SuppressLint("SimpleDateFormat") private Vector<String> getTripData(long tripId) { Vector<String> tripData = new Vector<String>(); mDb.openReadOnly();// w w w. j a va 2 s . c om Cursor tripCursor = mDb.fetchTrip(tripId); String note = tripCursor.getString(tripCursor.getColumnIndex(DbAdapter.K_TRIP_NOTE)); String purpose = tripCursor.getString(tripCursor.getColumnIndex(DbAdapter.K_TRIP_PURP)); Double startTime = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_START)); Double endTime = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_END)); tripCursor.close(); mDb.close(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); tripData.add(note); tripData.add(purpose); tripData.add(df.format(startTime)); tripData.add(df.format(endTime)); return tripData; }
From source file:com.facebook.stetho.inspector.protocol.module.Database.java
/** * Flatten all columns and all rows of a cursor to a single array. The array cannot be * interpreted meaningfully without the number of columns. * * @param cursor//from w ww .j av a2 s .c o m * @param limit Maximum number of rows to process. * @return List of Java primitives matching the value type of each column. */ private List<Object> flattenRows(Cursor cursor, int limit) { Util.throwIfNot(limit >= 0); List<Object> flatList = new ArrayList<Object>(); final int numColumns = cursor.getColumnCount(); for (int row = 0; row < limit && cursor.moveToNext(); row++) { for (int column = 0; column < numColumns; column++) { switch (cursor.getType(column)) { case Cursor.FIELD_TYPE_NULL: flatList.add(null); break; case Cursor.FIELD_TYPE_INTEGER: flatList.add(cursor.getLong(column)); break; case Cursor.FIELD_TYPE_FLOAT: flatList.add(cursor.getDouble(column)); break; case Cursor.FIELD_TYPE_BLOB: flatList.add(cursor.getBlob(column)); break; case Cursor.FIELD_TYPE_STRING: default: flatList.add(cursor.getString(column)); break; } } } if (!cursor.isAfterLast()) { for (int column = 0; column < numColumns; column++) { flatList.add("{truncated}"); } } return flatList; }