Пример #1
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    // Here's the switch statement that, given a URI, will determine what kind of request it is,
    // and query the database accordingly.
    Cursor retCursor;
    switch (sUriMatcher.match(uri)) {
        // "weather/*/*"
      case WEATHER_WITH_LOCATION_AND_DATE:
        {
          retCursor = getWeatherByLocationSettingAndDate(uri, projection, sortOrder);
          break;
        }
        // "weather/*"
      case WEATHER_WITH_LOCATION:
        {
          retCursor = getWeatherByLocationSetting(uri, projection, sortOrder);
          break;
        }
        // "weather"
      case WEATHER:
        {
          retCursor =
              mOpenHelper
                  .getReadableDatabase()
                  .query(
                      WeatherContract.WeatherEntry.TABLE_NAME,
                      projection,
                      selection,
                      selectionArgs,
                      null,
                      null,
                      sortOrder);

          break;
        }
        // "location"
      case LOCATION:
        {
          retCursor =
              mOpenHelper
                  .getReadableDatabase()
                  .query(
                      WeatherContract.LocationEntry.TABLE_NAME,
                      projection,
                      selection,
                      selectionArgs,
                      null,
                      null,
                      sortOrder);
          break;
        }

      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    retCursor.setNotificationUri(getContext().getContentResolver(), uri);
    return retCursor;
  }
Пример #2
0
  private Cursor getWeatherByLocationSettingAndDate(
      Uri uri, String[] projection, String sortOrder) {
    String locationSetting = WeatherContract.WeatherEntry.getLocationSettingFromUri(uri);
    long date = WeatherContract.WeatherEntry.getDateFromUri(uri);

    return sWeatherByLocationSettingQueryBuilder.query(
        mOpenHelper.getReadableDatabase(),
        projection,
        sLocationSettingAndDaySelection,
        new String[] {locationSetting, Long.toString(date)},
        null,
        null,
        sortOrder);
  }
Пример #3
0
  private Cursor getWeatherByLocationSetting(Uri uri, String[] projection, String sortOrder) {
    String locationSetting = WeatherContract.WeatherEntry.getLocationSettingFromUri(uri);
    long startDate = WeatherContract.WeatherEntry.getStartDateFromUri(uri);

    String[] selectionArgs;
    String selection;

    if (startDate == 0) {
      selection = sLocationSettingSelection;
      selectionArgs = new String[] {locationSetting};
    } else {
      selectionArgs = new String[] {locationSetting, Long.toString(startDate)};
      selection = sLocationSettingWithStartDateSelection;
    }

    return sWeatherByLocationSettingQueryBuilder.query(
        mOpenHelper.getReadableDatabase(),
        projection,
        selection,
        selectionArgs,
        null,
        null,
        sortOrder);
  }