import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.List;
import java.util.Locale;
/**
ITimerCounter timerCounter = counter;
if (timerCounter != null)
{
+ LapTimeGraphView graphView = findViewById(R.id.graph_area);
if (timerCounter.isStarted())
{
Log.v(TAG, "startTimer() LAP TIME");
controller.getDataEntry().appendTimeData(lapTime);
controller.addTimeStamp(currentLapCount, currentElapsedTime, diffTime);
//Log.v(TAG, " [[[ " + currentLapCount + " lap: " + currentElapsedTime + " diff:" + diffTime + " (" + refLapTime + ") ]]]");
+
+ if (graphView != null)
+ {
+ graphView.notifyLapTime();
+ }
}
}
else
Date date = new Date();
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
String title = sdf1.format(date);
- controller.getDataEntry().createIndex(title, timerCounter.getStartTime());
+ long startTime = timerCounter.getStartTime();
+ controller.getDataEntry().createIndex(title, startTime);
+
+ if (graphView != null)
+ {
+ graphView.notifyStarted(startTime);
+ }
+
}
updateTimerLabel();
}
controller.vibrate(120);
controller.getDataEntry().finishTimeData(timerCounter.getStartTime(), timerCounter.getStopTime());
ret = true;
+
+ LapTimeGraphView graphView = findViewById(R.id.graph_area);
+ if (graphView != null)
+ {
+ graphView.notifyStopped();
+ }
}
updateTimerLabel();
}
controller.vibrate(50);
controller.clearTimeStamp();
currentLapCount = 0;
+ LapTimeGraphView graphView = findViewById(R.id.graph_area);
+ if (graphView != null)
+ {
+ graphView.notifyReset();
+ }
}
updateTimerLabel();
}
*/
private void updateElapsedTimesGraph()
{
- Log.v(TAG, "updateElapsedTimesGraph()");
-
+ //Log.v(TAG, "updateElapsedTimesGraph()");
LapTimeGraphView view = findViewById(R.id.graph_area);
view.invalidate();
}
*
*/
@Override
- protected void onUserLeaveHint ()
+ protected void onUserLeaveHint()
{
Log.v(TAG, "onUserLeaveHint() " );
// ハードキー(ホームボタン)が押されたとき、これがひろえるが...
@Override
public void counterStatusChanged(boolean forceStartTimer)
{
+ ITimerCounter timerCounter = counter;
if (forceStartTimer)
{
try
{
- ITimerCounter timerCounter = counter;
+ LapTimeGraphView graphView = findViewById(R.id.graph_area);
if (timerCounter != null)
{
MyTimerTrigger trigger = new MyTimerTrigger(this, 100, timerCounter);
trigger.startTimer();
stopTrigger = trigger;
}
+ if (graphView != null)
+ {
+ graphView.notifyLapTime();
+ }
}
catch (Exception e)
{
e.printStackTrace();
}
}
+
+ // Adapter と TimerCounterの整合性を確認
+ if (timerCounter != null)
+ {
+ try
+ {
+ List<Long> lapTimeList = timerCounter.getLapTimeList();
+ int lapCount = lapTimeList.size();
+ int listCount = controller.getLapTimeCount();
+ if (lapCount != listCount)
+ {
+ Log.v(TAG, "LAP COUNT IS MISMATCH!!! lap:" + lapCount + " vs list:" + listCount);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+
runOnUiThread(new Runnable()
{
@Override
import android.view.View;
import net.osdn.gokigen.joggingtimer.stopwatch.ITimerCounter;
+import net.osdn.gokigen.joggingtimer.utilities.TimeStringConvert;
import java.util.ArrayList;
import java.util.List;
public class LapTimeGraphView extends View
{
private ITimerCounter timerCounter = null;
- private long counter = 0;
- private long maxReferenceTime = 0;
- private int referenceCount = 0;
+ private boolean isStarted = false;
+ private long maxLaptime = 0;
+ private long lastSystemLaptime = 0;
+ private long currentLapTime = 0;
+ private int totalLaptimeCount = 0;
private List<Long> refLapTimeList = null;
+ private List<Long> curLapTimeList = null;
/**
* コンストラクタ
private void initComponent(Context context)
{
setWillNotDraw(false);
+ curLapTimeList = new ArrayList<>();
}
/**
{
timerCounter = counter;
parseReferenceTimeList();
+ parseLapTime();
+ }
+
+ /**
+ *
+ *
+ */
+ public void notifyStarted(long startTime)
+ {
+ curLapTimeList.clear();
+ lastSystemLaptime = startTime;
+ isStarted = true;
+ }
+
+ /**
+ *
+ *
+ */
+ public void notifyLapTime()
+ {
+ // ラップタイムの取得
+ parseLapTime();
+ isStarted = true;
+ }
+
+ /**
+ *
+ *
+ */
+ public void notifyStopped()
+ {
+ // ラップタイムの取得
+ parseLapTime();
+ isStarted = false;
+ }
+
+ /**
+ *
+ *
+ */
+ public void notifyReset()
+ {
+ curLapTimeList.clear();
+ isStarted = false;
}
/**
// メッセージの表示
drawMessage(canvas);
- counter++;
}
/**
paint.setStrokeWidth(0.0f);
paint.setAntiAlias(true);
- float boxWidthUnit = width / refLapTimeList.size();
- float boxHeightUnit = height / (maxReferenceTime * 1.2f);
+ float boxWidthUnit = width / totalLaptimeCount;
+ float boxHeightUnit = height / (maxLaptime * 1.2f);
float startX = 0.0f;
for (Long time : refLapTimeList)
*/
private void drawCurrentLap(Canvas canvas)
{
+ if (curLapTimeList == null)
+ {
+ return;
+ }
- }
+ float width = canvas.getWidth();
+ float height = canvas.getHeight();
+
+ Paint paint = new Paint();
+ paint.setColor(Color.WHITE);
+ paint.setStyle(Paint.Style.STROKE);
+ paint.setStyle(Paint.Style.FILL);
+ paint.setStrokeWidth(0.0f);
+ paint.setAntiAlias(true);
+
+ float boxWidthUnit = width / totalLaptimeCount;
+ float boxHeightUnit = height / (maxLaptime * 1.2f);
+ float circleRadius = boxWidthUnit / 4.0f;
+
+ float startX = 0.0f;
+ if ((curLapTimeList.size() <= 0)&&(isStarted))
+ {
+ currentLapTime = System.currentTimeMillis() - lastSystemLaptime;
+ canvas.drawCircle((startX + (boxWidthUnit / 2.0f)), (height - boxHeightUnit * currentLapTime), circleRadius, paint);
+ return;
+ }
+
+ for (Long time : curLapTimeList)
+ {
+ canvas.drawCircle((startX + (boxWidthUnit / 2.0f)), (height - boxHeightUnit * time), circleRadius, paint);
+ startX = startX + boxWidthUnit;
+ }
+ if (isStarted)
+ {
+ currentLapTime = System.currentTimeMillis() - lastSystemLaptime;
+ canvas.drawCircle((startX + (boxWidthUnit / 2.0f)), (height - boxHeightUnit * currentLapTime), circleRadius, paint);
+ }
+ }
/**
*
{
int width = canvas.getWidth();
int height = canvas.getHeight();
- Rect rect = new Rect(0,0, width, height);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(0.0f);
paint.setAntiAlias(true);
- canvas.drawRect(rect, paint);
+ //canvas.drawRect(rect, paint);
- String message = width + "x" + height + " [" + referenceCount + "] " + maxReferenceTime;
+ int lapCount = 0;
+ if (curLapTimeList != null)
+ {
+ lapCount = curLapTimeList.size();
+ }
+
+ String lap = "";
+ if (currentLapTime == 0)
+ {
+ lap = TimeStringConvert.getDiffTimeString(currentLapTime).toString();
+ }
+ String message = " [" + lapCount +"/" + totalLaptimeCount + "] " + lap;
float textWidth = paint.measureText(message);
canvas.drawText(message, ((width / 2) - (textWidth / 2)) , height / 2, paint);
refLapTimeList = null;
List<Long> refTimeList = timerCounter.getReferenceLapTimeList();
- referenceCount = refTimeList.size();
- maxReferenceTime = 0;
- if (referenceCount <= 1)
+ totalLaptimeCount = refTimeList.size();
+ maxLaptime = 0;
+ if (totalLaptimeCount <= 1)
{
return;
}
{
refLapTimeList.add(currTime);
}
- if (currTime > maxReferenceTime)
+ if (currTime > maxLaptime)
+ {
+ maxLaptime = currTime;
+ }
+ prevTime = time;
+ }
+ }
+
+ /**
+ *
+ *
+ */
+ private void parseLapTime()
+ {
+ if (timerCounter == null)
+ {
+ return;
+ }
+ List<Long> lapTimeList = timerCounter.getLapTimeList();
+ int lapTimeCount = lapTimeList.size();
+ if (lapTimeCount > totalLaptimeCount)
+ {
+ totalLaptimeCount = lapTimeCount;
+ }
+ if (lapTimeCount < 1)
+ {
+ // 開始前の場合...
+ return;
+ }
+ if (lapTimeCount == 1)
+ {
+ lastSystemLaptime = lapTimeList.get(0);
+ return;
+ }
+
+ curLapTimeList.clear();
+ long prevTime = lapTimeList.get(0);
+ for (Long time : lapTimeList)
+ {
+ long currTime = time - prevTime;
+ if (currTime > 0)
+ {
+ curLapTimeList.add(currTime);
+ }
+ if (currTime > maxLaptime)
{
- maxReferenceTime = currTime;
+ maxLaptime = currTime;
}
prevTime = time;
}
+ lastSystemLaptime = prevTime;
}
@Override