fix in DateTimeTrigger management and executions when service already stopped
This commit is contained in:
parent
7ed04c7ae2
commit
152b0c3c49
@ -256,8 +256,10 @@ public class ActivityManageRule extends Activity
|
|||||||
switch(selectedTrigger.getTriggerType())
|
switch(selectedTrigger.getTriggerType())
|
||||||
{
|
{
|
||||||
case timeFrame:
|
case timeFrame:
|
||||||
ActivityManageTriggerTimeFrame.editedTimeFrameTrigger = selectedTrigger;
|
// ActivityManageTriggerTimeFrame.editedTimeFrameTrigger = selectedTrigger;
|
||||||
Intent timeFrameEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerTimeFrame.class);
|
Intent timeFrameEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerTimeFrame.class);
|
||||||
|
timeFrameEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||||
|
timeFrameEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||||
startActivityForResult(timeFrameEditor, requestCodeTriggerTimeframeEdit);
|
startActivityForResult(timeFrameEditor, requestCodeTriggerTimeframeEdit);
|
||||||
break;
|
break;
|
||||||
case bluetoothConnection:
|
case bluetoothConnection:
|
||||||
@ -1232,9 +1234,15 @@ public class ActivityManageRule extends Activity
|
|||||||
else if(requestCode == requestCodeTriggerTimeframeEdit)
|
else if(requestCode == requestCodeTriggerTimeframeEdit)
|
||||||
{
|
{
|
||||||
//edit TimeFrame
|
//edit TimeFrame
|
||||||
if(resultCode == RESULT_OK && ActivityManageTriggerTimeFrame.editedTimeFrameTrigger != null)
|
if(resultCode == RESULT_OK && data.hasExtra(intentNameTriggerParameter2))
|
||||||
{
|
{
|
||||||
ActivityManageTriggerTimeFrame.editedTimeFrameTrigger.setParentRule(ruleToEdit);
|
Trigger responseTimeFrame = new Trigger();
|
||||||
|
responseTimeFrame.setTriggerType(Trigger_Enum.timeFrame);
|
||||||
|
responseTimeFrame.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||||
|
responseTimeFrame.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||||
|
responseTimeFrame.setTimeFrame(new TimeFrame(data.getStringExtra(intentNameTriggerParameter2)));
|
||||||
|
responseTimeFrame.setParentRule(ruleToEdit);
|
||||||
|
ruleToEdit.getTriggerSet().set(editIndex, responseTimeFrame);
|
||||||
this.refreshTriggerList();
|
this.refreshTriggerList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@ -27,7 +28,7 @@ public class ActivityManageTriggerTimeFrame extends Activity
|
|||||||
RadioButton radioTimeFrameEntering, radioTimeFrameLeaving;
|
RadioButton radioTimeFrameEntering, radioTimeFrameLeaving;
|
||||||
EditText etRepeatEvery;
|
EditText etRepeatEvery;
|
||||||
|
|
||||||
public static Trigger editedTimeFrameTrigger = null;
|
static Trigger editedTimeFrameTrigger = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
@ -152,8 +153,13 @@ public class ActivityManageTriggerTimeFrame extends Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
editedTimeFrameTrigger.setTriggerParameter(radioTimeFrameEntering.isChecked());
|
editedTimeFrameTrigger.setTriggerParameter(radioTimeFrameEntering.isChecked());
|
||||||
|
editedTimeFrameTrigger.setTriggerParameter2(editedTimeFrameTrigger.getTimeFrame().toTriggerParameter2String());
|
||||||
|
|
||||||
setResult(RESULT_OK);
|
Intent response = new Intent();
|
||||||
|
response.putExtra(ActivityManageRule.intentNameTriggerParameter1, editedTimeFrameTrigger.getTriggerParameter());
|
||||||
|
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, editedTimeFrameTrigger.getTriggerParameter2());
|
||||||
|
|
||||||
|
setResult(RESULT_OK, response);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -167,9 +173,15 @@ public class ActivityManageTriggerTimeFrame extends Activity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(editedTimeFrameTrigger.getTimeFrame() != null)
|
if(getIntent().hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||||
|
{
|
||||||
|
editedTimeFrameTrigger = new Trigger();
|
||||||
|
editedTimeFrameTrigger.setTriggerParameter(getIntent().getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||||
|
editedTimeFrameTrigger.setTriggerParameter2(getIntent().getStringExtra(ActivityManageRule.intentNameTriggerParameter2));
|
||||||
|
editedTimeFrameTrigger.setTimeFrame(new TimeFrame(editedTimeFrameTrigger.getTriggerParameter2()));
|
||||||
loadVariableIntoGui();
|
loadVariableIntoGui();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loadVariableIntoGui()
|
private void loadVariableIntoGui()
|
||||||
{
|
{
|
||||||
@ -219,5 +231,4 @@ public class ActivityManageTriggerTimeFrame extends Activity
|
|||||||
etRepeatEvery.setText(String.valueOf(editedTimeFrameTrigger.getTimeFrame().getRepetition()));
|
etRepeatEvery.setText(String.valueOf(editedTimeFrameTrigger.getTimeFrame().getRepetition()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -80,6 +80,29 @@ public class TimeFrame
|
|||||||
this.setRepetition(Long.parseLong(dateArray[3]));
|
this.setRepetition(Long.parseLong(dateArray[3]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toTriggerParameter2String()
|
||||||
|
{
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
response.append(this.getTriggerTimeStart().getHours() + ":" + this.getTriggerTimeStart().getMinutes() + ":0");
|
||||||
|
response.append(separator);
|
||||||
|
response.append(this.getTriggerTimeStop().getHours() + ":" + this.getTriggerTimeStop().getMinutes() + ":0");
|
||||||
|
response.append(separator);
|
||||||
|
|
||||||
|
StringBuilder days = new StringBuilder();
|
||||||
|
|
||||||
|
for(int day : dayList)
|
||||||
|
days.append(String.valueOf(day));
|
||||||
|
|
||||||
|
response.append(days.toString());
|
||||||
|
|
||||||
|
if(this.repetition > 0)
|
||||||
|
{
|
||||||
|
response.append(separator + this.getRepetition());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
@ -254,8 +254,6 @@ public class XmlFileInterface
|
|||||||
else
|
else
|
||||||
serializer.text("null");
|
serializer.text("null");
|
||||||
}
|
}
|
||||||
else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.timeFrame)
|
|
||||||
serializer.text(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTimeFrame().toString());
|
|
||||||
else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.speed)
|
else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.speed)
|
||||||
serializer.text(String.valueOf(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getSpeed()));
|
serializer.text(String.valueOf(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getSpeed()));
|
||||||
else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.noiseLevel)
|
else if(Rule.getRuleCollection().get(i).getTriggerSet().get(j).getTriggerType() == Trigger_Enum.noiseLevel)
|
||||||
@ -838,7 +836,6 @@ public class XmlFileInterface
|
|||||||
|
|
||||||
private static Trigger readTrigger(XmlPullParser parser) throws IOException, XmlPullParserException
|
private static Trigger readTrigger(XmlPullParser parser) throws IOException, XmlPullParserException
|
||||||
{
|
{
|
||||||
|
|
||||||
/* FILE EXAMPE:
|
/* FILE EXAMPE:
|
||||||
* *****************
|
* *****************
|
||||||
* <Automation>
|
* <Automation>
|
||||||
|
@ -29,8 +29,8 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
private static AlarmManager centralAlarmManagerInstance;
|
private static AlarmManager centralAlarmManagerInstance;
|
||||||
private static boolean alarmListenerActive=false;
|
private static boolean alarmListenerActive=false;
|
||||||
private static ArrayList<ScheduleElement> alarmCandidates = new ArrayList<>();
|
private static ArrayList<ScheduleElement> alarmCandidates = new ArrayList<>();
|
||||||
|
|
||||||
private static ArrayList<Integer> requestCodeList = new ArrayList<Integer>();
|
private static ArrayList<Integer> requestCodeList = new ArrayList<Integer>();
|
||||||
|
static PendingIntent alarmPendingIntent = null;
|
||||||
|
|
||||||
public static void startAlarmListener(final AutomationService automationServiceRef)
|
public static void startAlarmListener(final AutomationService automationServiceRef)
|
||||||
{
|
{
|
||||||
@ -246,7 +246,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
|
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
|
||||||
PendingIntent alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
centralAlarmManagerInstance.set(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent);
|
centralAlarmManagerInstance.set(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent);
|
||||||
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("E dd.MM.yyyy HH:mm");
|
SimpleDateFormat sdf = new SimpleDateFormat("E dd.MM.yyyy HH:mm");
|
||||||
@ -261,10 +261,10 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
for(int requestCode : requestCodeList)
|
for(int requestCode : requestCodeList)
|
||||||
{
|
{
|
||||||
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
|
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
|
||||||
PendingIntent alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, requestCode, alarmIntent, 0);
|
if(alarmPendingIntent == null)
|
||||||
|
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, requestCode, alarmIntent, 0);
|
||||||
// Miscellaneous.logEvent("i", "AlarmManager", "Clearing alarm with request code: " + String.valueOf(requestCode));
|
// Miscellaneous.logEvent("i", "AlarmManager", "Clearing alarm with request code: " + String.valueOf(requestCode));
|
||||||
centralAlarmManagerInstance.cancel(alarmPendingIntent);
|
centralAlarmManagerInstance.cancel(alarmPendingIntent);
|
||||||
centralAlarmManagerInstance.
|
|
||||||
}
|
}
|
||||||
requestCodeList.clear();
|
requestCodeList.clear();
|
||||||
}
|
}
|
||||||
@ -298,7 +298,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
|||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "AlarmListener", "Stopping alarm listener.", 4);
|
Miscellaneous.logEvent("i", "AlarmListener", "Stopping alarm listener.", 4);
|
||||||
clearAlarms();
|
clearAlarms();
|
||||||
// centralAlarmManagerInstance.cancel(alarmPendingIntent);
|
centralAlarmManagerInstance.cancel(alarmPendingIntent);
|
||||||
alarmListenerActive = false;
|
alarmListenerActive = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user