Fixed reset button for execution times
This commit is contained in:
parent
9d8674a3ed
commit
f7a9fa09d4
4 changed files with 29 additions and 1 deletions
|
|
@ -13,6 +13,7 @@ public abstract class UeBehaviour implements Serializable{
|
|||
private static final Logger log = Logger.getLogger(UeBehaviour.class);
|
||||
|
||||
private transient boolean running;
|
||||
private transient long execTime = -1;
|
||||
private transient BehaviourExecutionListener execListener;
|
||||
|
||||
|
||||
|
|
@ -24,6 +25,7 @@ public abstract class UeBehaviour implements Serializable{
|
|||
* Starts to run the behaviour, this method will block until the execution is done
|
||||
*/
|
||||
public void run(){
|
||||
execTime = -1;
|
||||
long startTime = System.currentTimeMillis();
|
||||
if(execListener != null)
|
||||
execListener.executionStarted();
|
||||
|
|
@ -34,7 +36,8 @@ public abstract class UeBehaviour implements Serializable{
|
|||
if(execListener != null) execListener.exception(e);
|
||||
log.warn(null, e);
|
||||
}
|
||||
long execTime = System.currentTimeMillis() - startTime;
|
||||
running = false;
|
||||
execTime = System.currentTimeMillis() - startTime;
|
||||
if(execListener != null)
|
||||
execListener.executionStopped(execTime);
|
||||
}
|
||||
|
|
@ -46,6 +49,22 @@ public abstract class UeBehaviour implements Serializable{
|
|||
running = false;
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
terminate();
|
||||
execTime = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the last measured execution time, -1 if time is not available
|
||||
*/
|
||||
public long getExecTime(){
|
||||
return execTime;
|
||||
}
|
||||
|
||||
public boolean isRunning(){
|
||||
return running;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if currently running behaviour should be terminated
|
||||
*/
|
||||
|
|
@ -54,6 +73,7 @@ public abstract class UeBehaviour implements Serializable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
public void setExecutionListener(BehaviourExecutionListener l){
|
||||
execListener = l;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,9 @@ public class UeControlExecutor implements Runnable{
|
|||
public synchronized void reset(){
|
||||
terminate();
|
||||
currentlyActive = null;
|
||||
for(int i=0; i<behaviours.size(); i++){
|
||||
behaviours.get(i).reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -193,6 +193,8 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
executor.reset();
|
||||
if(statusFragment != null)
|
||||
statusFragment.reset();
|
||||
if(behaviourListFragment != null)
|
||||
behaviourListFragment.onResume();
|
||||
updateExecutionState();
|
||||
}
|
||||
else if (id == R.id.action_edit) {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,10 @@ public class BehaviourListAdapter extends StableArrayAdapter<UeBehaviour>{
|
|||
// Setting all values in listview
|
||||
title.setText(behaviour.getName());
|
||||
description.setText(""+behaviour);
|
||||
time.setText(StringUtil.getTimeString(behaviour.getExecTime()));
|
||||
|
||||
if(!behaviour.isRunning())
|
||||
time.setVisibility(View.VISIBLE);
|
||||
if(editable)
|
||||
draggable.setVisibility(View.VISIBLE);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue