OSDN Git Service

グラフ表示で、一度終了したときにポイントが表示できていなかった不具合を修正。
authorMRSa <mrsa@myad.jp>
Sun, 25 Mar 2018 12:46:31 +0000 (21:46 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 25 Mar 2018 12:46:31 +0000 (21:46 +0900)
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/ITimerCounter.java
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/IWearableActivityControl.java
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/MainActivity.java
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/MyTimerCounter.java
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/WearableActivityController.java
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/graphview/LapTimeGraphView.java
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/listview/ILapTimeHolder.java
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/listview/LapTimeArrayAdapter.java

index 5b44343..037802e 100644 (file)
@@ -19,6 +19,7 @@ public interface ITimerCounter
     long getStartTime();
     long getStopTime();
 
+    List<Long> getLapTimeList();
     List<Long> getReferenceLapTimeList();
     long getReferenceLapTime(int position);
 
index 5c767ae..88effb9 100644 (file)
@@ -20,5 +20,7 @@ public interface IWearableActivityControl
     void timerStarted(boolean isStarted);
     void addTimeStamp(long count, long lapTime, long diffTime);
     void clearTimeStamp();
+    int getLapTimeCount();
+
     void setupReferenceData();
 }
index 00adc9d..ea6a5b8 100644 (file)
@@ -20,6 +20,7 @@ import net.osdn.gokigen.joggingtimer.utilities.TimeStringConvert;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.List;
 import java.util.Locale;
 
 /**
@@ -292,6 +293,7 @@ public class MainActivity extends WearableActivity implements IClickCallback, My
             ITimerCounter timerCounter = counter;
             if (timerCounter != null)
             {
+                LapTimeGraphView graphView = findViewById(R.id.graph_area);
                 if (timerCounter.isStarted())
                 {
                     Log.v(TAG, "startTimer() LAP TIME");
@@ -307,6 +309,11 @@ public class MainActivity extends WearableActivity implements IClickCallback, My
                         controller.getDataEntry().appendTimeData(lapTime);
                         controller.addTimeStamp(currentLapCount, currentElapsedTime, diffTime);
                         //Log.v(TAG, " [[[ " + currentLapCount + " lap: " + currentElapsedTime + " diff:" + diffTime + " (" + refLapTime + ") ]]]");
+
+                        if (graphView != null)
+                        {
+                            graphView.notifyLapTime();
+                        }
                     }
                 }
                 else
@@ -323,7 +330,14 @@ public class MainActivity extends WearableActivity implements IClickCallback, My
                     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();
             }
@@ -353,6 +367,12 @@ public class MainActivity extends WearableActivity implements IClickCallback, My
                     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();
             }
@@ -400,6 +420,11 @@ public class MainActivity extends WearableActivity implements IClickCallback, My
                 controller.vibrate(50);
                 controller.clearTimeStamp();
                 currentLapCount = 0;
+                LapTimeGraphView graphView = findViewById(R.id.graph_area);
+                if (graphView != null)
+                {
+                    graphView.notifyReset();
+                }
             }
             updateTimerLabel();
         }
@@ -525,8 +550,7 @@ public class MainActivity extends WearableActivity implements IClickCallback, My
      */
     private void updateElapsedTimesGraph()
     {
-        Log.v(TAG, "updateElapsedTimesGraph()");
-
+        //Log.v(TAG, "updateElapsedTimesGraph()");
         LapTimeGraphView view = findViewById(R.id.graph_area);
         view.invalidate();
     }
@@ -563,7 +587,7 @@ public class MainActivity extends WearableActivity implements IClickCallback, My
      *
      */
     @Override
-    protected void onUserLeaveHint ()
+    protected void onUserLeaveHint()
     {
         Log.v(TAG, "onUserLeaveHint() " );
         // ハードキー(ホームボタン)が押されたとき、これがひろえるが...
@@ -617,23 +641,49 @@ public class MainActivity extends WearableActivity implements IClickCallback, My
     @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
index 2c37ce4..191a764 100644 (file)
@@ -166,6 +166,12 @@ public class MyTimerCounter implements ITimerCounter, IDatabaseReloadCallback
     }
 
     @Override
+    public List<Long> getLapTimeList()
+    {
+        return (elapsedTime);
+    }
+
+    @Override
     public void setCallback(ICounterStatusNotify callback)
     {
         this.callback = callback;
index 65bb0bd..5864015 100644 (file)
@@ -291,6 +291,17 @@ class WearableActivityController implements IWearableActivityControl, ITimeEntry
     }
 
     @Override
+    public int getLapTimeCount()
+    {
+        int count = 0;
+        if (lapTimeHolder != null)
+        {
+            count = lapTimeHolder.getLapTimeCount();
+        }
+        return (count);
+    }
+
+    @Override
     public void setupReferenceData()
     {
         try
index a6c4494..8a64ff2 100644 (file)
@@ -10,6 +10,7 @@ import android.util.AttributeSet;
 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;
@@ -21,10 +22,13 @@ 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;
 
     /**
      *   コンストラクタ
@@ -62,6 +66,7 @@ public class LapTimeGraphView extends View
     private void initComponent(Context context)
     {
         setWillNotDraw(false);
+        curLapTimeList = new ArrayList<>();
     }
 
     /**
@@ -72,6 +77,50 @@ public class LapTimeGraphView extends View
     {
         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;
     }
 
     /**
@@ -95,7 +144,6 @@ public class LapTimeGraphView extends View
         // メッセージの表示
         drawMessage(canvas);
 
-        counter++;
     }
 
     /**
@@ -135,8 +183,8 @@ public class LapTimeGraphView extends View
         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)
@@ -154,9 +202,45 @@ public class LapTimeGraphView extends View
      */
     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);
+        }
+    }
 
     /**
      *
@@ -166,16 +250,26 @@ public class LapTimeGraphView extends View
     {
         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);
@@ -194,9 +288,9 @@ public class LapTimeGraphView extends View
         refLapTimeList = null;
 
         List<Long> refTimeList = timerCounter.getReferenceLapTimeList();
-        referenceCount = refTimeList.size();
-        maxReferenceTime = 0;
-        if (referenceCount <= 1)
+        totalLaptimeCount = refTimeList.size();
+        maxLaptime = 0;
+        if (totalLaptimeCount <= 1)
         {
             return;
         }
@@ -209,12 +303,57 @@ public class LapTimeGraphView extends View
             {
                 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
index 42c0265..5e6428e 100644 (file)
@@ -2,7 +2,7 @@ package net.osdn.gokigen.joggingtimer.stopwatch.listview;
 
 public interface ILapTimeHolder
 {
+    int getLapTimeCount();
     void clearLapTime();
     void addLapTime(LapTimeItems item);
-
 }
index 65a6841..b1312df 100644 (file)
@@ -64,6 +64,12 @@ public class LapTimeArrayAdapter  extends ArrayAdapter<LapTimeItems> implements
     }
 
     @Override
+    public int getLapTimeCount()
+    {
+        return (getCount());
+    }
+
+    @Override
     public void clearLapTime()
     {
         clear();