/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 13:26:31 UTC
  • Revision ID: tim@ed.am-20121221132631-ofj30d60lvuxp4a3
added ContactsContract backend; removed references to Contacts types (conversion to/from backend types now done in backends); added support for exporting NOTEs

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * Exporter.java
3
3
 *
4
 
 * Copyright (C) 2011 to 2012 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2011 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of the Export Contacts program (hereafter referred
7
7
 * to as "this program"). For more information, see
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)
273
271
                                out.append( fold( "LABEL" +
274
272
                                        ( types.size() > 0? ";TYPE=" + join( types, "," ) : "" ) +
275
273
                                        ":" + escape( addresses.get( a ).getAddress() ) ) + "\n" );
285
283
                // append footer
286
284
                out.append( "END:VCARD\n" );
287
285
 
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
 
 
299
286
                // write to file
300
287
                try {
301
288
                        _ostream.write( out.toString().getBytes() );