Bugfix for Concurrent Exception
This commit is contained in:
parent
9c1899fe42
commit
2b8017c475
@ -45,20 +45,14 @@ public class MainActivity extends AppCompatActivity implements Observer {
|
||||
if (viewStackRef.getChildCount() > 0)
|
||||
viewStackRef.removeViewAt(0);
|
||||
viewStackRef.addView(newTrView);
|
||||
//viewStackRef.addView(newTrView, 0);
|
||||
//int childCount = viewStackRef.getChildCount();
|
||||
//if (childCount > 30) {
|
||||
// viewStackRef.removeViewAt(childCount-1);
|
||||
//}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void onStepButtonClick(View view) {
|
||||
//for (int j = 0; j < 3000; j++) {
|
||||
this.track.timeElapse();
|
||||
//}
|
||||
}
|
||||
|
||||
public void onPlayButtonClick(View view) {
|
||||
|
@ -7,6 +7,7 @@ import android.graphics.Paint;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.List;
|
||||
|
||||
public class TimeRecordView extends View {
|
||||
@ -58,16 +59,21 @@ public class TimeRecordView extends View {
|
||||
int y = 0;
|
||||
List<List<VehicleTimeRecord>> stepList = this.track.getVtrList();
|
||||
for (int curStepIdx = stepList.size()-1; curStepIdx >= stepList.size()-1-50 && curStepIdx >= 0; curStepIdx--) {
|
||||
try {
|
||||
List<VehicleTimeRecord> step = stepList.get(curStepIdx);
|
||||
int i = 0;
|
||||
for (VehicleTimeRecord r : step) {
|
||||
int left = (int) (this.pixelPerVehicle * r.getPosition());
|
||||
this.paint.setColor(getColor(r.getVelocity(), r.getMaxVelocity()));
|
||||
canvas.drawRect(left, y, left + this.pixelPerVehicle - 1,
|
||||
y+10, this.paint);
|
||||
y + 10, this.paint);
|
||||
i++;
|
||||
}
|
||||
y += 10;
|
||||
} catch (ConcurrentModificationException ex) {
|
||||
System.out.println("Concurrent Exception occured, skipping record");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,11 +73,11 @@ public class Track extends Observable {
|
||||
this.setChanged();
|
||||
this.notifyObservers();
|
||||
this.clearChanged();
|
||||
try {
|
||||
Thread.sleep(125);
|
||||
} catch (InterruptedException ex) {
|
||||
|
||||
}
|
||||
// try {
|
||||
// Thread.sleep(125);
|
||||
// } catch (InterruptedException ex) {
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
public float avg_step(int step){
|
||||
|
Loading…
Reference in New Issue
Block a user