|
|
@@ -11,18 +11,17 @@ import java.util.List; |
|
|
|
|
|
|
|
public class TimeRecordView extends View { |
|
|
|
protected Paint paint; |
|
|
|
protected List<VehicleTimeRecord> records; |
|
|
|
protected Track track; |
|
|
|
protected int pixelPerVehicle; |
|
|
|
protected float trackLength; |
|
|
|
|
|
|
|
public TimeRecordView(Context context, List<VehicleTimeRecord> records, float trackLength) { |
|
|
|
public TimeRecordView(Context context, Track track) { |
|
|
|
super(context); |
|
|
|
this.records = records; |
|
|
|
this.trackLength = trackLength; |
|
|
|
this.track = track; |
|
|
|
this.paint = new Paint(); |
|
|
|
paint.setColor(Color.BLACK); |
|
|
|
paint.setStyle(Paint.Style.FILL_AND_STROKE); |
|
|
|
this.setBackgroundColor(Color.BLACK); |
|
|
|
this.pixelPerVehicle = (int) (this.getWidth() / this.track.getTrackLength()); |
|
|
|
} |
|
|
|
|
|
|
|
protected int getColor(float curVelocity, float maxVelocity) { |
|
|
@@ -43,25 +42,32 @@ public class TimeRecordView extends View { |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
|
|
|
super.onMeasure(widthMeasureSpec, 10); |
|
|
|
setMeasuredDimension(widthMeasureSpec, 10); |
|
|
|
super.onMeasure(widthMeasureSpec, 10*50); |
|
|
|
setMeasuredDimension(widthMeasureSpec, 10*50); |
|
|
|
this.pixelPerVehicle = (int) (this.getWidth() / this.track.getTrackLength()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
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()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onDraw(Canvas canvas) { |
|
|
|
this.pixelPerVehicle = (int) (this.getWidth() / this.trackLength); |
|
|
|
int i = 0; |
|
|
|
for (VehicleTimeRecord r : this.records) { |
|
|
|
int left = (int) (this.pixelPerVehicle * r.getPosition()); |
|
|
|
this.paint.setColor(getColor(r.getVelocity(), r.getMaxVelocity())); |
|
|
|
canvas.drawRect(left, 0, left + this.pixelPerVehicle - 1, |
|
|
|
10, this.paint); |
|
|
|
i++; |
|
|
|
int y = 0; |
|
|
|
List<List<VehicleTimeRecord>> stepList = this.track.getVtrList(); |
|
|
|
for (int curStepIdx = stepList.size()-1; curStepIdx >= stepList.size()-1-50 && curStepIdx >= 0; curStepIdx--) { |
|
|
|
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); |
|
|
|
i++; |
|
|
|
} |
|
|
|
y += 10; |
|
|
|
} |
|
|
|
} |
|
|
|
} |