50 lines
1.5 KiB
Java
50 lines
1.5 KiB
Java
package de.hems.trafficsim;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import android.widget.TextView;
|
|
|
|
import java.util.Observable;
|
|
import java.util.Observer;
|
|
|
|
public class MainActivity extends AppCompatActivity implements Observer {
|
|
|
|
protected Track track;
|
|
protected TrackView trackView;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_main);
|
|
this.track = new Track(20, 50);
|
|
this.trackView = new TrackView(this, this.track);
|
|
this.track.addObserver(this);
|
|
ConstraintLayout layout = (ConstraintLayout) findViewById(R.id.constr_layout);
|
|
layout.addView(this.trackView);
|
|
}
|
|
|
|
@Override
|
|
public void update(Observable observable, Object o) {
|
|
String s = "";
|
|
for (Vehicle v: this.track.getVehicles()){
|
|
s+= "Vehicle " + v.id + " | "
|
|
+ "Pos = " + v.getPosition() + " | "
|
|
+ "Vel = " + v.getCurVelocity()+ " | "
|
|
+ "\n";
|
|
;
|
|
}
|
|
TextView view = (TextView) findViewById(R.id.debugTextView);
|
|
view.setText(s);
|
|
view.invalidate();
|
|
this.trackView.invalidate();
|
|
}
|
|
|
|
public void onStepButtonClick (View view) {
|
|
//for (int j = 0; j < 3000; j++) {
|
|
this.track.timeElapse(50);
|
|
//}
|
|
}
|
|
} |