Ejemplo n.º 1
0
  @Override
  public Uri insert(Uri uri, ContentValues initialValues) {
    Long rowId = null;
    Uri projectUri = null;
    switch (sUriMatcher.match(uri)) {
      case SENSORVALUES:
        rowId = mDB.insertSensorValue(initialValues).id();
        projectUri = ContentUris.withAppendedId(SensorValues.CONTENT_URI, rowId);
        break;
      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    if (rowId >= 0) {
      getContext().getContentResolver().notifyChange(projectUri, null);
    }
    return projectUri;
  }
Ejemplo n.º 2
0
  @Override
  public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    String id;
    switch (sUriMatcher.match(uri)) {
      case SENSORVALUE_ID:
        id = uri.getPathSegments().get(1);
        break;
      case SENSORVALUES:
        id = null;
        break;
      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    Integer count = mDB.updateSensorValues(id, values, where, whereArgs);
    if (count > 0) {
      getContext().getContentResolver().notifyChange(uri, null);
    }
    return count;
  }
Ejemplo n.º 3
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    String id = null;
    Cursor c = null;
    switch (sUriMatcher.match(uri)) {
      case SENSORVALUE_ID:
        id = uri.getPathSegments().get(1);
        // fall through
      case SENSORVALUES:
        c = mDB.getSensorValues(id, projection, selection, selectionArgs, sortOrder);
        break;
      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    // Tell the cursor what uri to watch, so it knows when its source data changes
    if (c != null) {
      c.setNotificationUri(getContext().getContentResolver(), uri);
    }
    return c;
  }