You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3KB

  1. package de.hems.trafficsim;
  2. import androidx.appcompat.app.AppCompatActivity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.TextView;
  6. import java.util.Observable;
  7. import java.util.Observer;
  8. public class MainActivity extends AppCompatActivity implements Observer {
  9. protected Track track;
  10. protected VehicleTimeRecord records;
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_main);
  15. this.track = new Track(20);
  16. this.records = null;
  17. this.track.addObserver(this);
  18. }
  19. @Override
  20. public void update(Observable observable, Object o) {
  21. String s = "";
  22. for (Vehicle v: this.track.getVehicles()){
  23. s+= "Vehicle " + v.id + " | "
  24. + "Pos = " + v.getPosition() + " | "
  25. + "Vel = " + v.getCurVelocity()+ " | "
  26. + "\n";
  27. ;
  28. }
  29. String t = ""; //vtr arraylist to string
  30. String text = s + "\n" + t;
  31. TextView view = (TextView) findViewById(R.id.debugTextView);
  32. view.setText(text);
  33. view.invalidate();
  34. }
  35. public void onStepButtonClick (View view) {
  36. for (int j = 0; j < 1; j++) {
  37. this.track.timeElapse(50);
  38. }
  39. }
  40. }