// jsc: seems like we need atleast one in and one out string :) public void CreateEvent(string Title, string Location, string Description, Action<string> y) { // http://developer.android.com/reference/android/provider/CalendarContract.EventsColumns.html#DESCRIPTION Console.WriteLine("CreateEvent " + new { Title, Location, Description }); Intent calIntent = new Intent(Intent.ACTION_INSERT); // when one opens browser in android calendar stays hidden.. // http://stackoverflow.com/questions/2232238/how-to-bring-an-activity-to-foreground-top-of-stack //calIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); calIntent.setType("vnd.android.cursor.item/event"); calIntent.putExtra("title", Title); calIntent.putExtra("eventLocation", Location); calIntent.putExtra("description", Description); GregorianCalendar calDate = new GregorianCalendar(2012, 7, 15); calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true); calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calDate.getTimeInMillis()); calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, calDate.getTimeInMillis()); calIntent.putExtra("accessLevel", 0x00000002); calIntent.putExtra("availability", 0x00000000); calIntent.putExtra("rrule", "FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH"); // well spawn another activity/thread ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext.startActivity(calIntent); y(""); }
protected override void onCreate(Bundle savedInstanceState) { base.onCreate(savedInstanceState); var sv = new ScrollView(this); var ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); sv.addView(ll); new Button(this) .WithText("Create Event!") .AttachTo(ll) .AtClick( b => { b.setText("Done!"); // http://developer.android.com/reference/android/provider/CalendarContract.EventsColumns.html#DESCRIPTION Intent calIntent = new Intent(Intent.ACTION_INSERT); calIntent.setType("vnd.android.cursor.item/event"); calIntent.putExtra("title", "My House Party"); calIntent.putExtra("eventLocation", "My Beach House"); calIntent.putExtra("description", "A Pig Roast on the Beach"); GregorianCalendar calDate = new GregorianCalendar(2012, 7, 15); calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true); calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calDate.getTimeInMillis()); calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, calDate.getTimeInMillis()); //ttdw calIntent.putExtra("accessLevel", 0x00000002); calIntent.putExtra("availability", 0x00000000); calIntent.putExtra("rrule", "FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH"); startActivity(calIntent); } ); var COLS = new[] { "title", "dtstart" }; var at = new TextView(this).AttachTo(ll); at.setText("at " + CalendarContract.Events.CONTENT_URI.ToString()); // from t in calendars // select t.title var mCursor = this.getContentResolver().query( CalendarContract.Events.CONTENT_URI, COLS, null, null, null ); mCursor.moveToLast(); var tv = new TextView(this).AttachTo(ll); tv.setText("n/a"); Action update = delegate { var title = ""; var start = ""; var w = ""; //Format df = android.text.format.DateFormat.getDateFormat(this); //Format tf = android.text.format.DateFormat.getTimeFormat(this); //try //{ title = mCursor.getString(0); start = ((object)mCursor.getLong(1)).ToString(); w += title; w += " at "; w += start; tv.setText(w); //} //catch //{ // tv.setText("n/a error"); // throw; //} }; Button prev, next = null; prev = new Button(this) .WithText("Prev") .AttachTo(ll) .AtClick( b => { if (!mCursor.isFirst()) { mCursor.moveToPrevious(); next.setEnabled(true); } else b.setEnabled(false); update(); } ); next = new Button(this) .WithText("Next") .AttachTo(ll) .AtClick( b => { if (!mCursor.isLast()) { mCursor.moveToNext(); prev.setEnabled(true); } else b.setEnabled(false); update(); } ); update(); this.setContentView(sv); }