User Tools

Site Tools


script_calendar_widget

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
script_calendar_widget [2015/04/19 21:13]
lm13 [About the script]
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.0 +  * 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.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 27: Line 31:
 var patternAllDay = "dd. MM.";//​used for all-day-entries ​ var patternAllDay = "dd. MM.";//​used for all-day-entries ​
 var showMax = 3; var showMax = 3;
 +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 47: Line 53:
 var cr = cx.getContentResolver() var cr = cx.getContentResolver()
  
-if(saved==null ​&& (typeof active =='​undefined'​ || active==false)){ +if(saved==null){
-active=true;​+
 var projection = [Calendars._ID,​Calendars.NAME];​ var projection = [Calendars._ID,​Calendars.NAME];​
 var calCursor = cr.query(Calendars.CONTENT_URI,​ projection, Calendars.VISIBLE + " = 1", null, Calendars._ID + " ASC"); var calCursor = cr.query(Calendars.CONTENT_URI,​ projection, Calendars.VISIBLE + " = 1", null, Calendars._ID + " ASC");
 if (!calCursor.moveToFirst()){ if (!calCursor.moveToFirst()){
 AndroiSD. makeNewToast("​No Calendar found"​).show();​ AndroiSD. makeNewToast("​No Calendar found"​).show();​
 +calCursor.close();​
 return; return;
 } }
Line 70: Line 76:
 update(cals);​ update(cals);​
 Android.makeNewToast("​Saved!",​true).show();​ Android.makeNewToast("​Saved!",​true).show();​
 +calCursor.close();​
 } }
 }) })
 .setNegativeButton("​Cancel",​null) .setNegativeButton("​Cancel",​null)
 .setTitle("​Select Calendar(s)"​) .setTitle("​Select Calendar(s)"​)
-.setOnDismissListener(new DialogInterface.OnDismissListener(){ 
-onDismiss:​function(dialog){ 
-active=false;​ 
-} 
-}) 
 .create(); .create();
 dialog.getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);​ dialog.getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);​
 dialog.show();​ dialog.show();​
 } }
-else if(saved!=null) ​update(JSON.parse(saved));​+else update(JSON.parse(saved));​
  
 function update(cals){ function update(cals){
 if(cals.length<​1)return;​ if(cals.length<​1)return;​
 var cal = Calendar.getInstance();​ var cal = Calendar.getInstance();​
-cal.add(Calendar.HOUR_OF_DAY,​-cal.get(Calendar.HOUR_OF_DAY) - 1); 
 var begin = cal.getTimeInMillis();​ var begin = cal.getTimeInMillis();​
-cal.add(Calendar.YEAR,1);+cal.add(Calendar.DAY_OF_YEAR,days);
 var end = cal.getTimeInMillis();​ var end = cal.getTimeInMillis();​
 var proj = [ Instances._ID,​ Instances.BEGIN,​ Instances.END,​Instances.TITLE,​Instances.ALL_DAY]; ​ var proj = [ Instances._ID,​ Instances.BEGIN,​ Instances.END,​Instances.TITLE,​Instances.ALL_DAY]; ​
Line 103: 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 116: 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 133: Line 137:
 } }
 LL.getEvent().getItem().setLabel(s,​ true); LL.getEvent().getItem().setLabel(s,​ true);
 +cursor.close();​
 } }
 </​sxh>​ </​sxh>​
script_calendar_widget.1429478034.txt.gz · Last modified: 2015/04/19 21:13 by lm13