|
|
@@ -5,7 +5,6 @@ import android.graphics.Canvas; |
|
|
|
import android.graphics.Color; |
|
|
|
import android.graphics.Paint; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
|
|
|
|
import java.util.ConcurrentModificationException; |
|
|
|
import java.util.List; |
|
|
@@ -14,6 +13,7 @@ public class TimeRecordView extends View { |
|
|
|
protected Paint paint; |
|
|
|
protected Track track; |
|
|
|
protected int pixelPerVehicle; |
|
|
|
protected float tooShortPerTrackLength; |
|
|
|
|
|
|
|
public TimeRecordView(Context context, Track track) { |
|
|
|
super(context); |
|
|
@@ -23,6 +23,7 @@ public class TimeRecordView extends View { |
|
|
|
paint.setStyle(Paint.Style.FILL_AND_STROKE); |
|
|
|
this.setBackgroundColor(Color.BLACK); |
|
|
|
this.pixelPerVehicle = (int) (this.getWidth() / this.track.getTrackLength()); |
|
|
|
this.tooShortPerTrackLength = (this.getWidth() - this.pixelPerVehicle*this.track.getTrackLength())/this.track.getTrackLength(); |
|
|
|
} |
|
|
|
|
|
|
|
protected int getColor(float curVelocity, float maxVelocity) { |
|
|
@@ -52,6 +53,7 @@ public class TimeRecordView extends View { |
|
|
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
|
|
|
super.onSizeChanged(w, h, oldw, oldh); |
|
|
|
this.pixelPerVehicle = (int) (this.getWidth() / this.track.getTrackLength()); |
|
|
|
this.tooShortPerTrackLength = (this.getWidth() - this.pixelPerVehicle*this.track.getTrackLength())/this.track.getTrackLength(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@@ -64,8 +66,9 @@ public class TimeRecordView extends View { |
|
|
|
int i = 0; |
|
|
|
for (VehicleTimeRecord r : step) { |
|
|
|
int left = (int) (this.pixelPerVehicle * r.getPosition()); |
|
|
|
int compensate = Math.round(r.getPosition()*this.tooShortPerTrackLength); |
|
|
|
this.paint.setColor(getColor(r.getVelocity(), r.getMaxVelocity())); |
|
|
|
canvas.drawRect(left, y, left + this.pixelPerVehicle - 1, |
|
|
|
canvas.drawRect(left+compensate, y, left + this.pixelPerVehicle - 1+compensate, |
|
|
|
y + 10, this.paint); |
|
|
|
i++; |
|
|
|
} |
|
|
|