Recognize LOCATION in VEVENT

git-svn-id: https://zxing.googlecode.com/svn/trunk@1301 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2010-04-11 16:42:11 +00:00
parent 974d22fbd9
commit 047c932fcb
4 changed files with 17 additions and 10 deletions

View file

@ -59,11 +59,11 @@ public final class CalendarResultHandler extends ResultHandler {
@Override
public void handleButtonPress(int index) {
CalendarParsedResult calendarResult = (CalendarParsedResult) getResult();
switch (index) {
case 0:
addCalendarEvent(calendarResult.getSummary(), calendarResult.getStart(),
calendarResult.getEnd());
break;
if (index == 0) {
addCalendarEvent(calendarResult.getSummary(),
calendarResult.getStart(),
calendarResult.getEnd(),
calendarResult.getLocation());
}
}

View file

@ -143,16 +143,21 @@ public abstract class ResultHandler {
* @param summary A description of the event
* @param start The start time as yyyyMMdd or yyyyMMdd'T'HHmmss or yyyyMMdd'T'HHmmss'Z'
* @param end The end time as yyyyMMdd or yyyyMMdd'T'HHmmss or yyyyMMdd'T'HHmmss'Z'
* @param location a text description of the event location
*/
final void addCalendarEvent(String summary, String start, String end) {
final void addCalendarEvent(String summary, String start, String end, String location) {
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", calculateMilliseconds(start));
if (start.length() == 8) {
intent.putExtra("allDay", true);
}
if (end == null) {
end = start;
}
intent.putExtra("endTime", calculateMilliseconds(end));
intent.putExtra("title", summary);
intent.putExtra("eventLocation", location);
launchIntent(intent);
}

View file

@ -20,7 +20,7 @@ import com.google.zxing.Result;
/**
* Partially implements the iCalendar format's "VEVENT" format for specifying a
* calendar event. See RFC 2445. This supports SUMMARY, DTSTART and DTEND fields.
* calendar event. See RFC 2445. This supports SUMMARY, LOCATION, DTSTART and DTEND fields.
*
* @author Sean Owen
*/
@ -46,8 +46,9 @@ final class VEventResultParser extends ResultParser {
String summary = VCardResultParser.matchSingleVCardPrefixedField("SUMMARY", rawText, true);
String start = VCardResultParser.matchSingleVCardPrefixedField("DTSTART", rawText, true);
String end = VCardResultParser.matchSingleVCardPrefixedField("DTEND", rawText, true);
String location = VCardResultParser.matchSingleVCardPrefixedField("LOCATION", rawText, true);
try {
return new CalendarParsedResult(summary, start, end, null, null, null);
return new CalendarParsedResult(summary, start, end, location, null, null);
} catch (IllegalArgumentException iae) {
return null;
}

View file

@ -29,9 +29,10 @@ public final class CalendarParsedResultTestCase extends TestCase {
public void testVEvent() {
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nDTEND:20080505T234555Z\r\n" +
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
"DTEND:20080505T234555Z\r\nLOCATION:Miami\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
null, "foo", null, "20080504T123456Z", "20080505T234555Z", null);
null, "foo", "Miami", "20080504T123456Z", "20080505T234555Z", null);
}
private static void doTest(String contents,