Added stopped and ended listeners to behaviours

This commit is contained in:
Ziver Koc 2015-03-04 15:54:03 +01:00
parent b18e5cc649
commit 6216afd36b
3 changed files with 25 additions and 12 deletions

View file

@ -40,9 +40,14 @@ public abstract class UeBehaviour implements Serializable{
} }
execTime = System.currentTimeMillis() - startTime; execTime = System.currentTimeMillis() - startTime;
executor = null;
if(execListener != null) if(execListener != null) {
execListener.executionStopped(execTime); if(!isRunning()) // Has execution been stopped prematurely
execListener.executionStopped();
else
execListener.executionEnded(execTime);
}
terminate();
} }
/** /**
@ -113,7 +118,8 @@ public abstract class UeBehaviour implements Serializable{
public static interface BehaviourExecutionListener { public static interface BehaviourExecutionListener {
public void executionStarted(); public void executionStarted();
public void progressChanged(float progress); public void progressChanged(float progress);
public void executionStopped(long executionTime); public void executionStopped();
public void executionEnded(long executionTime);
public void exception(Exception e); public void exception(Exception e);
} }

View file

@ -32,13 +32,11 @@ public class BehaviourListAdapter extends StableArrayAdapter<UeBehaviour>{
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView; final View vi = (convertView!=null ? convertView : inflater.inflate(VIEW_RESOURCE, null));
if(convertView==null)
vi = inflater.inflate(VIEW_RESOURCE, null);
ImageView draggable = (ImageView)vi.findViewById(R.id.draggable); final ImageView draggable = (ImageView)vi.findViewById(R.id.draggable);
TextView title = (TextView)vi.findViewById(R.id.title); final TextView title = (TextView)vi.findViewById(R.id.title);
TextView description = (TextView)vi.findViewById(R.id.description); final TextView description = (TextView)vi.findViewById(R.id.description);
final ImageView warning = (ImageView) vi.findViewById(R.id.warning); final ImageView warning = (ImageView) vi.findViewById(R.id.warning);
final ProgressBar active = (ProgressBar)vi.findViewById(R.id.active); final ProgressBar active = (ProgressBar)vi.findViewById(R.id.active);
final ProgressBar progress = (ProgressBar) vi.findViewById(R.id.progress); final ProgressBar progress = (ProgressBar) vi.findViewById(R.id.progress);
@ -60,6 +58,7 @@ public class BehaviourListAdapter extends StableArrayAdapter<UeBehaviour>{
public void executionStarted() { public void executionStarted() {
progress.post(new Runnable() { progress.post(new Runnable() {
public void run() { public void run() {
vi.setAlpha(1f);
time.setVisibility(View.INVISIBLE); time.setVisibility(View.INVISIBLE);
active.setVisibility(View.VISIBLE); active.setVisibility(View.VISIBLE);
progress.setVisibility(View.VISIBLE); progress.setVisibility(View.VISIBLE);
@ -73,7 +72,15 @@ public class BehaviourListAdapter extends StableArrayAdapter<UeBehaviour>{
executionStarted(); executionStarted();
progress.setProgress((int) (p * 100)); progress.setProgress((int) (p * 100));
} }
public void executionStopped(final long execTime) { public void executionStopped() {
progress.post(new Runnable() {
public void run() {
active.setVisibility(View.INVISIBLE);
vi.setAlpha(0.5f);
}
});
}
public void executionEnded(final long execTime) {
progress.post(new Runnable() { progress.post(new Runnable() {
public void run() { public void run() {
active.setVisibility(View.INVISIBLE); active.setVisibility(View.INVISIBLE);

View file

@ -70,7 +70,7 @@
<ProgressBar <ProgressBar
android:id="@+id/progress" android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal" style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/description" android:layout_below="@+id/description"