time class changed

This commit is contained in:
jens 2022-05-26 18:47:30 +02:00
parent df68f7ca5c
commit 67a58077cc
6 changed files with 85 additions and 38 deletions

View File

@ -61,11 +61,11 @@ public class ActivityManageTriggerTimeFrame extends Activity
@Override
public void onClick(View v)
{
Time startTime = new Time(0);
TimeObject startTime = new TimeObject();
startTime.setHours(startPicker.getCurrentHour());
startTime.setMinutes(startPicker.getCurrentMinute());
Time stopTime = new Time(0);
TimeObject stopTime = new TimeObject();
stopTime.setHours(stopPicker.getCurrentHour());
stopTime.setMinutes(stopPicker.getCurrentMinute());

View File

@ -490,7 +490,7 @@ public class Miscellaneous extends Service
}
}
public static int compareTimes(Time time1, Time time2)
public static int compareTimes(TimeObject time1, TimeObject time2)
{
// Miscellaneous.logEvent("i", "TimeCompare", "To compare: " + time1.toString() + " / " + time2.toString());

View File

@ -6,8 +6,8 @@ import java.util.ArrayList;
public class TimeFrame
{
// Defines a timeframe
protected Time triggerTimeStart;
protected Time triggerTimeStop;
protected TimeObject triggerTimeStart;
protected TimeObject triggerTimeStop;
protected long repetition;
protected final static String separator = "/";
@ -34,20 +34,20 @@ public class TimeFrame
}
}
public Time getTriggerTimeStart()
public TimeObject getTriggerTimeStart()
{
return triggerTimeStart;
}
public void setTriggerTimeStart(Time triggerTimeStart)
public void setTriggerTimeStart(TimeObject triggerTimeStart)
{
this.triggerTimeStart = triggerTimeStart;
}
public Time getTriggerTimeStop()
public TimeObject getTriggerTimeStop()
{
return triggerTimeStop;
}
public void setTriggerTimeStop(Time triggerTimeStop)
public void setTriggerTimeStop(TimeObject triggerTimeStop)
{
this.triggerTimeStop = triggerTimeStop;
}
@ -62,7 +62,7 @@ public class TimeFrame
this.repetition = repetition;
}
public TimeFrame (Time timeStart, Time timeEnd, ArrayList<Integer> dayList2, long repetition)
public TimeFrame (TimeObject timeStart, TimeObject timeEnd, ArrayList<Integer> dayList2, long repetition)
{
this.setTriggerTimeStart(timeStart);
this.setTriggerTimeStop(timeEnd);
@ -73,8 +73,8 @@ public class TimeFrame
public TimeFrame (String fileContent)
{
String[] dateArray = fileContent.split(separator); // example: timestart/timestop/days[int]/repetition
this.setTriggerTimeStart(Time.valueOf(dateArray[0]));
this.setTriggerTimeStop(Time.valueOf(dateArray[1]));
this.setTriggerTimeStart(TimeObject.valueOf(dateArray[0]));
this.setTriggerTimeStop(TimeObject.valueOf(dateArray[1]));
this.setDayListFromString(dateArray[2]);
if(dateArray.length > 3) // may not exist in old config files
this.setRepetition(Long.parseLong(dateArray[3]));

View File

@ -0,0 +1,68 @@
package com.jens.automation2;
import java.sql.Time;
public class TimeObject
{
int hours, minutes, seconds;
public TimeObject()
{
}
public int getHours()
{
return hours;
}
public void setHours(int hours)
{
this.hours = hours;
}
public int getMinutes()
{
return minutes;
}
public void setMinutes(int minutes)
{
this.minutes = minutes;
}
public int getSeconds()
{
return seconds;
}
public void setSeconds(int seconds)
{
this.seconds = seconds;
}
public TimeObject(int hours, int minutes, int seconds)
{
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
}
public static TimeObject valueOf(String input)
{
TimeObject ro = null;
if(input.contains(":"))
{
String[] parts = input.split(":");
if(parts.length == 2)
ro = new TimeObject(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), 0);
else if(parts.length == 3)
ro = new TimeObject(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
else
Miscellaneous.logEvent("w", "TimeObject", "Invalid length for time. Input: " + input, 4);
}
return ro;
}
}

View File

@ -934,7 +934,7 @@ public class Trigger
triggeringTime = new Date();
String timeString = String.valueOf(triggeringTime.getHours()) + ":" + String.valueOf(triggeringTime.getMinutes()) + ":" + String.valueOf(triggeringTime.getSeconds());
Time nowTime = Time.valueOf(timeString);
TimeObject nowTime = TimeObject.valueOf(timeString);
Calendar calNow = Calendar.getInstance();
try
@ -1089,7 +1089,7 @@ public class Trigger
public static Calendar getNextRepeatedExecutionAfter(Trigger trigger, Calendar now)
{
Calendar calSet;
Time setTime;
TimeObject setTime;
TimeFrame tf = new TimeFrame(trigger.getTriggerParameter2());
if(tf.getRepetition() > 0)

View File

@ -14,6 +14,7 @@ import com.jens.automation2.AutomationService;
import com.jens.automation2.Miscellaneous;
import com.jens.automation2.Rule;
import com.jens.automation2.TimeFrame;
import com.jens.automation2.TimeObject;
import com.jens.automation2.Trigger;
import com.jens.automation2.Trigger.Trigger_Enum;
@ -96,7 +97,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
TimeFrame tf = new TimeFrame(oneTrigger.getTriggerParameter2());
Calendar calSet;
Time setTime;
TimeObject setTime;
if(oneTrigger.getTriggerParameter())
setTime = tf.getTriggerTimeStart();
@ -365,7 +366,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
public static Calendar getNextRepeatedExecutionAfter(Trigger trigger, Calendar now)
{
Calendar calSet;
Time setTime;
TimeObject setTime;
TimeFrame tf = new TimeFrame(trigger.getTriggerParameter2());
if(tf.getRepetition() > 0)
@ -403,26 +404,4 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
return null;
}
public class TimeObject
{
int hours, minutes, seconds;
public int getHours()
{
return hours;
}
public void setHours(int hours)
{
this.hours = hours;
}
public TimeObject(int hours, int minutes, int seconds)
{
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
}
}
}