예제 #1
0
  private Cursor getWeatherByLocationAndDay(Uri uri, String[] projection, String sortOrder) {
    String locationSetting = WeatherContract.WeatherEntry.getLocationSettingFromUri(uri);
    String day = WeatherContract.WeatherEntry.getDateFromUri(uri);

    return weatherByLocationSettingQueryBuilder.query(
        weatherDbHelper.getReadableDatabase(),
        projection,
        locationSettingWithDaySelection,
        new String[] {locationSetting, day},
        null,
        null,
        sortOrder);
  }
예제 #2
0
  private Cursor getWeatherByLocationSetting(Uri uri, String[] projection, String sortOrder) {
    String locationSetting = WeatherContract.WeatherEntry.getLocationSettingFromUri(uri);
    String startDate = WeatherContract.WeatherEntry.getStartDateFromUri(uri);

    String[] selectionArgs;
    String selection;

    if (startDate == null) {
      selection = locationSettingSelection;
      selectionArgs = new String[] {locationSetting};
    } else {
      selection = locationSettingWithStartDateSelection;
      selectionArgs = new String[] {locationSetting, startDate};
    }

    return weatherByLocationSettingQueryBuilder.query(
        weatherDbHelper.getReadableDatabase(),
        projection,
        selection,
        selectionArgs,
        null,
        null,
        sortOrder);
  }
예제 #3
0
  @Override
  public Uri insert(Uri uri, ContentValues contentValues) {

    final int match = uriMatcher.match(uri);
    Uri returnUri = null;
    SQLiteDatabase db = weatherDbHelper.getWritableDatabase();

    switch (match) {
      case WEATHER:
        {
          long id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, contentValues);
          if (id > 0) {
            returnUri = WeatherContract.WeatherEntry.buildWeatherUri(id);
          } else {
            throw new SQLException("Failed to insert row into " + uri);
          }
          break;
        }

      case LOCATION:
        {
          long id = db.insert(WeatherContract.LocationEntry.TABLE_NAME, null, contentValues);
          if (id > 0) {
            returnUri = WeatherContract.LocationEntry.buildLocationUri(id);
          } else {
            throw new SQLException("Failed to insert row into " + uri);
          }
          break;
        }

      default:
        throw new UnsupportedOperationException("Unknown uri " + uri);
    }

    // notify any registered observers of this change
    getContext().getContentResolver().notifyChange(uri, null);

    return returnUri;
  }