Widget replacement: Calendar
Widget replacement: Calendar
This shows your next appointments in a minimalistic way.
Setup:
– install read_calendar package from http://www.pierrox.net/android/applications/lightning_launcher/permissions/ or grant READ_CALENDAR permission via Permission Manager
– create a text item and set this script in its resumed event
– Change the config section o whatever you want
– Set the maxline attribute of the item to showMax or higher
]]>
< ![CDATA[
//config
var pattern = “dd. MM. HH:mm”;//format has to match http://developer.android.com/reference/java/text/SimpleDateFormat.html
var showEnd = true;
var patternEnd = “HH:mm”; //used when entry ends on same day
var patternAllDay = “dd. MM.”;//used for all-day-entries
var showMax = 3;
//endconfig
LL.bindClass(“android.provider.CalendarContract”);
LL.bindClass(“java.util.Calendar”);
LL.bindClass(“android.content.ContentUris”);
LL.bindClass(“java.text.SimpleDateFormat”);
var Calendars = CalendarContract.Calendars;
var Instances = CalendarContract.Instances;
var Events = CalendarContract.Events;
var projection = [Calendars._ID];
var cursor=LL.getContext().getContentResolver().query(Calendars.CONTENT_URI, projection, Calendars.VISIBLE + ” = 1″, null, Calendars._ID + ” ASC”);
if (!cursor.moveToFirst())return;
var id = cursor.getLong(0);
var cal=Calendar.getInstance();
cal.add(Calendar.HOUR_OF_DAY,-1-cal.get(Calendar.HOUR_OF_DAY));
var begin = cal.getTimeInMillis();
cal.add(Calendar.YEAR,1);
var end = cal.getTimeInMillis();
var proj = [ Instances._ID, Instances.BEGIN, Instances.END,Instances.TITLE,Instances.ALL_DAY];
var uriBuilder = Instances.CONTENT_URI.buildUpon();
ContentUris.appendId(uriBuilder,begin);
ContentUris.appendId(uriBuilder,end);
var cursor = LL.getContext().getContentResolver().query(uriBuilder.build(), proj, Instances.CALENDAR_ID+”=”+id,null,Instances.BEGIN+” ASC”);
if(!cursor.moveToFirst())return;
var s=””;
for(var i=0;i
{
var c=Calendar.getInstance();
c.setTimeInMillis(cursor.getLong(1));
var c2=c.clone();
c2.setTimeInMillis(cursor.getLong(2));
var format=new SimpleDateFormat(pattern);
var formatEnd=new SimpleDateFormat(patternEnd);
var formatAllDay=new SimpleDateFormat(patternAllDay);
var isAllDay=(cursor.getInt(4)==1);
s+= cursor.getString(3);
if(isAllDay)c2.add(Calendar.DAY_OF_YEAR,-1);
var endsOnSame=(c.get(Calendar.DAY_OF_YEAR)==c2.get(Calendar.DAY_OF_YEAR));
if(!isAllDay){
s+=” “+format.format(c.getTime());
if(showEnd){
if(endsOnSame) s+=” – “+formatEnd.format(c2.getTime());
else s+=” – “+format.format(c2.getTime());
}
}
else{
s+=” “+formatAllDay.format(c.getTime());
if(!endsOnSame&&showEnd)s+=” – “+formatAllDay.format(c2.getTime());
}
if(cursor.moveToNext())s+=”\n”;
else break;
}
LL.getEvent().getItem().setLabel(s, true);
]]>
< ![CDATA[
Brilliant! was just about to try to write this myself … any screenshots?
]]>
< ![CDATA[
One more widget I can uninstall!
]]>
< ![CDATA[
Lightning keeps getting better with all those genius minds here.: )
]]>
< ![CDATA[
Sweet. Any way to show entries from multiple calendars on my device?
]]>
< ![CDATA[
Often I wished the text element could have more lines. This is yet another useful script that makes me wish the text element had more lines we could use : )
]]>
< ![CDATA[
Morgan Moyaerts Uhm… Haven’t thought of that, I’ll investigate.
Evelien Wijbenga 1. Thanks
2. You can use the keyboard to set a higher value than the bar allows
]]>
< ![CDATA[
Lukas Morawietz tried it before but somehow it didn’t work. But now it works. Just what I need. Thanks. Great script you made here.
]]>
< ![CDATA[
Hi Lukas Morawietz, noticed that the first agenda item is the all day item from yesterday.
]]>