/android/export-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/export-contacts

« back to all changes in this revision

Viewing changes to src/am/ed/exportcontacts/VcardExporter.java

  • Committer: edam
  • Date: 2012-12-21 15:53:59 UTC
  • Revision ID: tim@ed.am-20121221155359-p8h3n0xhtulmwva0
fixed column values in Contacts backend; don't write-out empty notes; remember to close my queries; switched from wrappers to static valueOf() functions; fix line-endings (should be \r\n)

Show diffs side-by-side

added added

removed removed

268
268
                                case ContactData.TYPE_WORK:
269
269
                                        types.add( "WORK" ); break;
270
270
                                }
 
271
                                // we use LABEL because is accepts formatted text (whereas ADR
 
272
                                // expects semicolon-delimited fields with specific purposes)
271
273
                                out.append( fold( "LABEL" +
272
274
                                        ( types.size() > 0? ";TYPE=" + join( types, "," ) : "" ) +
273
275
                                        ":" + escape( addresses.get( a ).getAddress() ) ) + "\n" );
283
285
                // append footer
284
286
                out.append( "END:VCARD\n" );
285
287
 
 
288
                // replace '\n' with "\r\n" (spec requires CRLF)
 
289
                int pos = 0;
 
290
                while( true ) {
 
291
                        pos = out.indexOf( "\n", pos );
 
292
                        if( pos == -1 ) break;
 
293
                        out.replace( pos, pos + 1, "\r\n" );
 
294
 
 
295
                        // skip our inserted string
 
296
                        pos += 2;
 
297
                }
 
298
 
286
299
                // write to file
287
300
                try {
288
301
                        _ostream.write( out.toString().getBytes() );