File: DatebookRecord.java

package info (click to toggle)
pilot-link 0.12.5-dfsg-2
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 6,868 kB
  • ctags: 5,811
  • sloc: ansic: 53,153; sh: 10,459; java: 2,584; perl: 2,247; python: 1,044; makefile: 991; yacc: 662; cpp: 551; xml: 39
file content (422 lines) | stat: -rw-r--r-- 11,086 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
package org.gnu.pilotlink;
import java.util.Date;
import java.util.GregorianCalendar;
public class DatebookRecord extends Record {
    byte buffer[]=new byte[65535]; //max buffer
    //Statics
    public final static int REP_WEEKLY=2;
    public final static int REP_DAYLY=1;
    public final static int REP_MONTHLY_BY_DAY=3;
    public final static int REP_MONTHLY_BY_DATE=4;
    public final static int REP_YEARLY=5;
    public final static int REP_NONE=6;
    public final static int NO_REP=0;
    
    public final static int ALARM_MINUTES=0;
    public final static int ALARM_HOURS=1;
    public final static int ALARM_DAYS=2;
    public final static int ALARM_NONE=3;
    
    //Privates
    //private Record rawData;
    private Date startDate;
    private Date endDate;
    private Date repeatEnd;
    
    private String description;
    private String note;
    
    
    private int alarmAdvance;
    private int alarmUnits;
    
    private int repAdvance;
    private int repType;
    private int repDay;
    private int repWeekstart;
    private int dist;
    
    private Date repExceptions[];
    
    private boolean[] repDays;
    
    //die flags...
    private boolean hasNote;
    private boolean hasAlarm;
    private boolean hasTime;
    private boolean isRepeated;
    private boolean hasDescription;
    private boolean hasExceptions;
    private boolean repeatForever;
    
    public boolean hasNote() {
        return hasNote;
    }
    public boolean hasTime() {
        return hasTime;
    }
    public boolean hasAlarm() {
        return hasAlarm;
    }
    public boolean isRepeated() {
        return isRepeated;
    }
    public boolean hasDescription() {
        return hasDescription;
    }
    public boolean hasExceptions() {
        return hasExceptions;
    }
    public boolean repeatForever() {
        return repeatForever;
    }
    
    public DatebookRecord(Date sd, Date ed,String descr, String n) {
        resetVars();

        
        startDate = sd;
        endDate=ed;
        description=descr;
        note=n;
        
        if (n!=null && n.length()!=0) {
            hasNote=true;
        }
        if (descr!=null && descr.length()!=0) {
            hasDescription=true;
        }
        GregorianCalendar cal=new GregorianCalendar();
        cal.setTime(sd);
        if (cal.get(GregorianCalendar.HOUR_OF_DAY)!=0 && cal.get(GregorianCalendar.MINUTE)!=0) {
            hasTime=true;
        }
        
        //CLUMSY: getting buffer once to calc size
        //getBuffer();
	setSize(getBuffer().length);
    }
    //Constructor
    public DatebookRecord(Record raw) {
        super(raw);        
    }
    public DatebookRecord() {
	    startDate=new Date();
	    resetVars();
	    endDate=new Date();
    }
    
    private void resetVars() {
        description="";
        note="";
        
        
        alarmAdvance=0;
        alarmUnits=ALARM_NONE;
        
        repAdvance=0;
        repType=REP_NONE;
        repDay=0;
        repWeekstart=0;

        repAdvance=0;
        dist=0;
        repDays= new boolean[] { false, false ,false, false, false, false, false };
        hasNote=false;
        hasAlarm=false;
        hasTime=false;
        isRepeated=false;
        hasDescription=false;
        hasExceptions=false;
        repeatForever=false;
    }
    public void setBuffer(byte arr[]) {
        //buffer=raw.getBuffer();
        resetVars();
        if (arr[0]==(byte)0xff && arr[1]==(byte)0xff) {
            //keine Zeit festgelegt
            hasTime=false;
            startDate=Record.getDateAt(arr,4);
            endDate=startDate;			
        } else {
            hasTime=true;
            startDate=Record.getDateTimeAt(arr,4,0);
            endDate=Record.getDateTimeAt(arr,4,2);
        }
        
        //Parsing flags
        int flags=arr[6];
        if ((flags & 64) != 0) {
            hasAlarm=true;
        } 
        if ((flags & 32) != 0) {
            isRepeated=true;
        }
        if ((flags & 8) !=0) {
            hasExceptions=true;
        }
        if ((flags & 16) !=0) {
            hasNote=true;
        }
        if ((flags & 4) != 0) {
            hasDescription=true;
        }
        
        int idx=8;
        //getting data
        if (hasAlarm) {
            alarmAdvance=arr[idx];
            idx++;
            alarmUnits=arr[idx];
            idx++;
        }
        if (isRepeated) {
            repType=arr[idx];
            idx+=2;
            dist=256*arr[idx]+arr[idx]+1;
            
            if (dist==0xffff) {
                repeatForever=true;
            } else {
                repeatEnd=Record.getDateAt(arr,idx);
            }
            idx+=2;
            repAdvance=arr[idx];
            idx++;
            int on=arr[idx];
            if (repType==REP_MONTHLY_BY_DAY) {
                repDay=on;
            } else {
                for (int i=0; i<7;i++) {
                    //repDays[i]=((on&(1<<i))!=0);
                }
            }
            idx++;
            repWeekstart=arr[idx];
            idx+=2;
            
        }
        
        if (hasExceptions) {
            repExceptions=new Date[arr[idx]];
            idx+=2;
            for (int i=0; i<repExceptions.length; i++, idx+=2) {
                repExceptions[i]=Record.getDateAt(arr,idx);
            }
        }
        //idx=0x10; //always at idx 16? cant set exceptions on my palm
        if (hasDescription) {
            description=Record.getStringAt(arr,idx);
            idx+=description.length()+1;
        }
        if (hasNote) {
            note=Record.getStringAt(arr,idx);
            idx+=note.length()+1;
        }
        setSize(idx);
    }
    public byte[] getBuffer() {
        int bytecount=0;
        
        
        if (!hasTime) {
            buffer[0]=(byte)0xff;
            buffer[1]=(byte)0xff;
            buffer[2]=(byte)0xff;
            buffer[3]=(byte)0xff;
            Record.setDateAt(buffer,startDate,4);
        } else {
            Record.setDateTimeAt(buffer,startDate,4,0);
            Record.setDateTimeAt(buffer,endDate,4,2);
        }
        int flags=0;
        if (hasAlarm) flags=flags|64;
        if (isRepeated) flags=flags|32;
        if (hasExceptions) flags=flags|8;
        if (hasNote) flags=flags|16;
        if (hasDescription) flags=flags|4;
        buffer[6]=(byte)flags;
        bytecount=8;
        if (hasAlarm) {
            buffer[bytecount]=(byte)alarmAdvance;
            bytecount++;
            buffer[bytecount]=(byte)alarmUnits;
            bytecount++;
        }
        if (isRepeated) {
            buffer[bytecount]=(byte)repType;
            bytecount+=2;
            if (repeatForever) {
                buffer[bytecount]=(byte)0xff;
                buffer[bytecount+1]=(byte)0xff;
            } else {
                Record.setIntAt(buffer,dist-1, bytecount);
            }
            bytecount+=2;
            buffer[bytecount]=(byte)repAdvance;
            bytecount++;
            if (repType==REP_MONTHLY_BY_DAY) {
                buffer[bytecount]=(byte)repDay;
            } else {
                int days=0;
                for (int i=0; i<7; i++) {
                    if (repDays[i]) {
                        days=days|(1<<i);
                    }
                }
            }
            bytecount++;
            buffer[bytecount]=(byte)repWeekstart;
            bytecount+=2;
        }
        if (hasExceptions) {
            buffer[bytecount]=(byte)repExceptions.length;
            bytecount+=2;
            for (int i=0;i<repExceptions.length;i++, bytecount+=2) {
                Record.setDateAt(buffer,repExceptions[i],bytecount);
            }
        }
        //bytecount=16; //cant set exceptions on my palm...
        if (hasDescription) {
            bytecount=Record.setStringAt(buffer,description,bytecount);
        }
        if (hasNote) {
            bytecount=Record.setStringAt(buffer,note,bytecount);
        }
        byte ret[]=new byte[bytecount];
        for (int i=0; i<bytecount; i++) {
            ret[i]=buffer[i];
        }
        
        return ret;
    }
    
    public Date getStartDate() {
        return startDate;
    }
    public Date getEndDate() {
        return endDate;
    }
    public Date repeatUntil() {
        return repeatEnd;
    }
    public String getDescription() {
        return description;
    }
    
    public String getNote() {
        return note;
    }
    public Date getRepeatEnd() {
        return repeatEnd;
    }
    public Date[] getRepExceptions() {
        return repExceptions;
    }
    public int getRepWeekstart() {
        return repWeekstart;
    }
    public int getRepDay() {
        return repDay;
    }
    public int getRepType() {
        return repType;
    }
    public int getRepAdvance() {
        return repAdvance;
    }
    public int getAlarmAdvance() {
        return alarmAdvance;
    }
    public int getAlarmUnits() {
        return alarmUnits;
    }
    public boolean[] getRepDays() {
        return repDays;
    }
    
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
	
	setSize(getBuffer().length);
    }
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
	if (endDate!=null)
		hasTime=true;
    
	setSize(getBuffer().length);
    }
    
    public void setRepeated(boolean r) {
	    isRepeated=r;
    }
    
    public void setRepeatForever(boolean r) {
	    repeatForever=r;
    }
    
    public void setRepeatEnd(Date repeatEnd) {
        this.repeatEnd = repeatEnd;
	if (repeatEnd!=null) {
		setRepeatForever(false);
	}
	setSize(getBuffer().length);
    }
    public void setDescription(String description) {
        this.description = description;
	if (description!=null) {
		hasDescription=true;
	} else {
		hasDescription=false;
	}
	setSize(getBuffer().length);
    }
    public void setNote(String note) {
        this.note = note;
	if (note!=null) {
		hasNote=true;
	} else {
		hasNote=false;
	}
	setSize(getBuffer().length);
    }
    
    public void setAlarm(boolean a) {
	    hasAlarm=a;
    }
    
    public void setAlarmAdvance(int alarmAdvance) {
        this.alarmAdvance = alarmAdvance;
	setSize(getBuffer().length);
    }
    public void setAlarmUnits(int alarmUnits) {
        this.alarmUnits = alarmUnits;
	setSize(getBuffer().length);
    }
    public void setRepAdvance(int repAdvance) {
        this.repAdvance = repAdvance;
	setSize(getBuffer().length);
    }
    public void setRepType(int repType) {
        this.repType = repType;
	setSize(getBuffer().length);
    }
    public void setRepDay(int repDay) {
        this.repDay = repDay;
	setSize(getBuffer().length);
    }
    public void setRepWeekstart(int repWeekstart) {
        this.repWeekstart = repWeekstart;
	setSize(getBuffer().length);
    }
    public void setRepExceptions(Date repExceptions[]) {
        this.repExceptions = repExceptions;
	setSize(getBuffer().length);
    }
    public void setRepDays(boolean[] repDays) {
        this.repDays = repDays;
	setSize(getBuffer().length);
    }
    
}