====== Differences ====== This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
script_calendar_widget [2015/04/20 05:24] lm13 |
script_calendar_widget [2016/06/28 12:11] (current) f43nd1r |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== About the script ====== | ====== About the script ====== | ||
| * Purpose : This script will allow you to set up a calendar widget replacement | * Purpose : This script will allow you to set up a calendar widget replacement | ||
| - | * Author : [[https://plus.google.com/+LukasMorawietz|LM13]] | + | * Author : F43nd1r |
| - | * Current Version : 1.1 | + | * Current Version : 1.3 |
| - | * Link : | + | * Link : https://plus.google.com/+LukasMorawietz/posts/ENEoGArx8D4 |
| ====== Changelog ====== | ====== Changelog ====== | ||
| * Version 1.0 (19/4/2015): initial release in wiki | * Version 1.0 (19/4/2015): initial release in wiki | ||
| * Version 1.1 (20/4/2015): fixed showing yesterday's all-day-appointments, reduced minimum API level to 14 | * Version 1.1 (20/4/2015): fixed showing yesterday's all-day-appointments, reduced minimum API level to 14 | ||
| + | * Version 1.2 (21/4/2015): added fix for devices using 23:59 instead of 00:00 (manual) | ||
| + | * Version 1.3 (21/4/2015): Fix memory leaks | ||
| ====== How to use the script ==== | ====== How to use the script ==== | ||
| + | * Either install Calendar package from [[http://www.pierrox.net/android/applications/lightning_launcher/permissions/|here]] or grant READ_ CALENDAR permission using Lightning Permission Manager | ||
| * Create a text item | * Create a text item | ||
| * set this script in its resumed event | * set this script in its resumed event | ||
| Line 29: | Line 32: | ||
| var showMax = 3; | var showMax = 3; | ||
| var days = 90; //how far to search from today (might be not exact) | var days = 90; //how far to search from today (might be not exact) | ||
| + | var dayOffFix=false; //when true adds one to all-day entries | ||
| //endconfig | //endconfig | ||
| Line 54: | Line 58: | ||
| if (!calCursor.moveToFirst()){ | if (!calCursor.moveToFirst()){ | ||
| AndroiSD. makeNewToast("No Calendar found").show(); | AndroiSD. makeNewToast("No Calendar found").show(); | ||
| + | calCursor.close(); | ||
| return; | return; | ||
| } | } | ||
| Line 71: | Line 76: | ||
| update(cals); | update(cals); | ||
| Android.makeNewToast("Saved!",true).show(); | Android.makeNewToast("Saved!",true).show(); | ||
| + | calCursor.close(); | ||
| } | } | ||
| }) | }) | ||
| Line 98: | Line 104: | ||
| var cursor = LL.getContext().getContentResolver().query(uriBuilder.build(), proj, Instances.CALENDAR_ID+" IN "+s,null,Instances.BEGIN+" ASC"); | var cursor = LL.getContext().getContentResolver().query(uriBuilder.build(), proj, Instances.CALENDAR_ID+" IN "+s,null,Instances.BEGIN+" ASC"); | ||
| - | if(!cursor.moveToFirst())return; | + | if(!cursor.moveToFirst()){ |
| + | cursor.close(); | ||
| + | return; | ||
| + | } | ||
| var s=""; | var s=""; | ||
| for(var i=0;i<showMax;i++) | for(var i=0;i<showMax;i++) | ||
| Line 111: | Line 120: | ||
| var isAllDay=(cursor.getInt(4)==1); | var isAllDay=(cursor.getInt(4)==1); | ||
| s+= cursor.getString(3); | s+= cursor.getString(3); | ||
| - | if(isAllDay)c2.add(Calendar.DAY_OF_YEAR,-1); | + | if(isAllDay)(dayOffFix?c:c2).add(Calendar.DAY_OF_YEAR,dayOffFix?1:-1); |
| var endsOnSame=(c.get(Calendar.DAY_OF_YEAR)==c2.get(Calendar.DAY_OF_YEAR)); | var endsOnSame=(c.get(Calendar.DAY_OF_YEAR)==c2.get(Calendar.DAY_OF_YEAR)); | ||
| if(!isAllDay){ | if(!isAllDay){ | ||
| Line 128: | Line 137: | ||
| } | } | ||
| LL.getEvent().getItem().setLabel(s, true); | LL.getEvent().getItem().setLabel(s, true); | ||
| + | cursor.close(); | ||
| } | } | ||
| </sxh> | </sxh> | ||