private void addNewQuake(Quake quake) {
    ContentResolver cr = getContentResolver();

    // Construct a where clause to make sure we don't already have this
    // earthquake in the provider.
    String w = EarthquakeProvider.KEY_DATE + " = " + quake.getDate().getTime();

    // If the earthquake is new, insert it into the provider.
    Cursor query = cr.query(EarthquakeProvider.CONTENT_URI, null, w, null, null);

    if (query.getCount() == 0) {
      ContentValues values = new ContentValues();

      values.put(EarthquakeProvider.KEY_DATE, quake.getDate().getTime());
      values.put(EarthquakeProvider.KEY_DETAILS, quake.getDetails());
      values.put(EarthquakeProvider.KEY_SUMMARY, quake.toString());

      double lat = quake.getLocation().getLatitude();
      double lng = quake.getLocation().getLongitude();
      values.put(EarthquakeProvider.KEY_LOCATION_LAT, lat);
      values.put(EarthquakeProvider.KEY_LOCATION_LNG, lng);
      values.put(EarthquakeProvider.KEY_LINK, quake.getLink());
      values.put(EarthquakeProvider.KEY_MAGNITUDE, quake.getMagnitude());

      cr.insert(EarthquakeProvider.CONTENT_URI, values);
    }
    query.close();
  }
Exemplo n.º 2
0
  private void announceNewQuake(Quake quake) {
    Intent intent = new Intent(NEW_EARTHQUAKE_FOUND);
    intent.putExtra("date", quake.getDate().getTime());
    intent.putExtra("details", quake.getDetails());
    intent.putExtra("longitude", quake.getLocation().getLongitude());
    intent.putExtra("latitude", quake.getLocation().getLatitude());
    intent.putExtra("magnitude", quake.getMagnitude());

    sendBroadcast(intent);
  }