Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.tenforwardconsulting.phonegap.plugins.CalendarPlugin" version="0.0.1">
<name>CalendarPlugin</name>
<description>Calendar Plugin</description>
<license>MIT</license>
<keywords>cordova,calendar</keywords>
<js-module src="www/calendar.js" name="device">
<clobbers target="plugins" />
</js-module>
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="CalendarPlugin" value="com.tenforwardconsulting.phonegap.plugins.CalendarPlugin">
<param name="android-package" value="com.tenforwardconsulting.phonegap.plugins.CalendarPlugin"/>
</feature>
</config-file>
<source-file src="src/android/CalendarPlugin.java"
target-dir="src/com/tenforwardconsulting/phonegap/plugins/" />
</platform>
</plugin>
14 changes: 8 additions & 6 deletions CalendarPlugin.java → src/android/CalendarPlugin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tenforwardconsulting.phonegap.plugins;

import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -26,7 +26,8 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
.putExtra("endTime", arg_object.getLong("endTimeMillis"))
.putExtra("title", arg_object.getString("title"))
.putExtra("description", arg_object.getString("description"))
.putExtra("eventLocation", arg_object.getString("eventLocation"));
.putExtra("eventLocation", arg_object.getString("eventLocation"))
.putExtra("allDay", arg_object.getBoolean("allDay"));

this.cordova.startActivityForResult(this, calIntent, RESULT_CODE_CREATE);
return true;
Expand All @@ -41,10 +42,11 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == RESULT_CODE_CREATE) {
if(resultCode == Activity.RESULT_OK) {
if(resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED) {
callback.success();
} else {
callback.error("Activity result code " + resultCode);
}
else {
callback.error("Unable to add event (" + resultCode + ").");
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions calendar.js → www/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ function calendarPlugin()
{
}

calendarPlugin.prototype.createEvent = function(title,location,notes,startDate,endDate, successCallback, errorCallback) {
calendarPlugin.prototype.createEvent = function(
title,location,notes,startDate,endDate,calendarName,reminderMinutes,successCallback,errorCallback
) {
if (typeof errorCallback != "function") {
console.log("calendarPlugin.createEvent failure: errorCallback parameter must be a function");
return
Expand All @@ -14,6 +16,16 @@ calendarPlugin.prototype.createEvent = function(title,location,notes,startDate,e
console.log("calendarPlugin.createEvent failure: successCallback parameter must be a function");
return
}

//TODO: implement reminderMinutes, calendarName

var allDay = (startDate.getHours()==0
&& startDate.getMinutes()==0
&& startDate.getSeconds()==0
&& endDate.getHours()==0
&& endDate.getMinutes()==0
&& endDate.getSeconds()==0);

cordova.exec(
successCallback, // called when signature capture is successful
errorCallback, // called when signature capture encounters an error
Expand All @@ -24,7 +36,8 @@ calendarPlugin.prototype.createEvent = function(title,location,notes,startDate,e
"description": notes,
"eventLocation": location,
"startTimeMillis": startDate.getTime(),
"endTimeMillis": endDate.getTime()
"endTimeMillis": endDate.getTime(),
"allDay": allDay
}]
); // List of arguments to the plugin
};
Expand Down