OSDN Git Service

基準値のラップタイムをグラフ表示できるようにした。
authorMRSa <mrsa@myad.jp>
Sat, 24 Mar 2018 15:51:21 +0000 (00:51 +0900)
committerMRSa <mrsa@myad.jp>
Sat, 24 Mar 2018 15:51:21 +0000 (00:51 +0900)
.idea/misc.xml
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/ButtonClickListener.java
wear/src/main/java/net/osdn/gokigen/joggingtimer/stopwatch/ITimerCounter.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

index 73edeca..387a8cf 100644 (file)
@@ -99,9 +99,6 @@
   <component name="ProjectType">
     <option name="id" value="Android" />
   </component>
-  <component name="SvnConfiguration">
-    <configuration>C:\Users\MRSa\AppData\Roaming\Subversion</configuration>
-  </component>
   <component name="masterDetails">
     <states>
       <state key="ProjectJDKs.UI">
index 255e0d2..aaefec7 100644 (file)
@@ -117,7 +117,6 @@ public class ButtonClickListener implements View.OnClickListener, View.OnLongCli
     {
         try
         {
-            //
             Log.v(TAG, " in : " + in.toString());
         }
         catch (Exception e)
@@ -129,6 +128,12 @@ public class ButtonClickListener implements View.OnClickListener, View.OnLongCli
     @Override
     public boolean onTouch(View v, MotionEvent event)
     {
-        return (v.performClick());
+        int id = v.getId();
+        if (id == R.id.graph_area)
+        {
+            Log.v(TAG, "onTouch()");
+            return (v.performClick());
+        }
+        return (false);
     }
 }
index 5b76001..5b44343 100644 (file)
@@ -1,5 +1,7 @@
 package net.osdn.gokigen.joggingtimer.stopwatch;
 
+import java.util.List;
+
 public interface ITimerCounter
 {
     boolean isStarted();
@@ -17,6 +19,7 @@ public interface ITimerCounter
     long getStartTime();
     long getStopTime();
 
+    List<Long> getReferenceLapTimeList();
     long getReferenceLapTime(int position);
 
     void setCallback(MyTimerCounter.ICounterStatusNotify callback);
index 2b2c7b1..2c37ce4 100644 (file)
@@ -160,13 +160,19 @@ public class MyTimerCounter implements ITimerCounter, IDatabaseReloadCallback
     }
 
     @Override
+    public List<Long> getReferenceLapTimeList()
+    {
+        return (referenceTime);
+    }
+
+    @Override
     public void setCallback(ICounterStatusNotify callback)
     {
         this.callback = callback;
     }
 
     @Override
-    public void dataIsReloaded(@NonNull  ArrayList<Long> timelist)
+    public void dataIsReloaded(@NonNull ArrayList<Long> timelist)
     {
         try
         {
index 923f83e..65bb0bd 100644 (file)
@@ -57,7 +57,8 @@ class WearableActivityController implements IWearableActivityControl, ITimeEntry
     }
 
     @Override
-    public void setup(WearableActivity activity, IClickCallback callback, IDatabaseReloadCallback dbCallback) {
+    public void setup(WearableActivity activity, IClickCallback callback, IDatabaseReloadCallback dbCallback)
+    {
         this.preferences = PreferenceManager.getDefaultSharedPreferences(activity);
         this.dbCallback = dbCallback;
         setupPermissions(activity);
@@ -71,7 +72,8 @@ class WearableActivityController implements IWearableActivityControl, ITimeEntry
      *
      *
      */
-    private void setupPermissions(WearableActivity activity) {
+    private void setupPermissions(WearableActivity activity)
+    {
         if ((ContextCompat.checkSelfPermission(activity, Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED) ||
                 (ContextCompat.checkSelfPermission(activity, Manifest.permission.WAKE_LOCK) != PackageManager.PERMISSION_GRANTED)) {
             ActivityCompat.requestPermissions(activity,
@@ -87,7 +89,8 @@ class WearableActivityController implements IWearableActivityControl, ITimeEntry
      *
      *
      */
-    private void setupHardwares(WearableActivity activity) {
+    private void setupHardwares(WearableActivity activity)
+    {
         // バイブレータをつかまえる
         vibrator = (Vibrator) activity.getSystemService(VIBRATOR_SERVICE);
 
@@ -102,7 +105,8 @@ class WearableActivityController implements IWearableActivityControl, ITimeEntry
     private void setupScreen(WearableActivity activity)
     {
         TextView mTextView = activity.findViewById(R.id.text);
-        if (mTextView != null) {
+        if (mTextView != null)
+        {
             mTextView.setText(R.string.app_name);
         }
 
@@ -117,18 +121,23 @@ class WearableActivityController implements IWearableActivityControl, ITimeEntry
      * データベースのセットアップ
      */
     @Override
-    public void setupDatabase(final WearableActivity activity, final boolean isInitialize) {
+    public void setupDatabase(final WearableActivity activity, final boolean isInitialize)
+    {
         database = new TimeEntryDatabaseFactory(activity, this).getEntryDatabase();
         Thread thread = new Thread(new Runnable() {
             @Override
             public void run() {
-                try {
-                    if (isInitialize) {
+                try
+                {
+                    if (isInitialize)
+                    {
                         // 既存のデータベースを消去する場合、、、
                         TimeEntryDatabaseFactory.deleteDatabase(activity);
                     }
                     database.prepare();
-                } catch (Exception e) {
+                }
+                catch (Exception e)
+                {
                     e.printStackTrace();
                 }
             }
@@ -165,14 +174,13 @@ class WearableActivityController implements IWearableActivityControl, ITimeEntry
             sub1.setOnLongClickListener(clickListener);
 
             ListView lap = activity.findViewById(R.id.laptime_list_area);
-            lap.setOnClickListener(clickListener);
+            //lap.setOnClickListener(clickListener);
             lap.setOnLongClickListener(clickListener);
 
             LapTimeGraphView graphView = activity.findViewById(R.id.graph_area);
+            graphView.setOnTouchListener(clickListener);
             graphView.setOnClickListener(clickListener);
             graphView.setOnLongClickListener(clickListener);
-            graphView.setOnTouchListener(clickListener);
-
         }
         catch (Exception e)
         {
@@ -191,12 +199,16 @@ class WearableActivityController implements IWearableActivityControl, ITimeEntry
             @Override
             public void run() {
                 // DBのクローズ実行
-                if (isReadyDatabase) {
+                if (isReadyDatabase)
+                {
                     isReadyDatabase = false;
-                    try {
+                    try
+                    {
                         Log.v(TAG, "closeDatabase() EXECUTE...");
                         database.close();
-                    } catch (Exception e) {
+                    }
+                    catch (Exception e)
+                    {
                         e.printStackTrace();
                     }
                 }
@@ -305,7 +317,8 @@ class WearableActivityController implements IWearableActivityControl, ITimeEntry
         Log.v(TAG, "database prepareFinished() : " + isReady);
         isReadyDatabase = isReady;
 
-        try {
+        try
+        {
             boolean isStarted = preferences.getBoolean(PREF_KEY_TIMER_STARTED, false);
             recordingIndexId = preferences.getLong(PREF_KEY_TIMER_INDEXID, -1);
 
@@ -343,7 +356,8 @@ class WearableActivityController implements IWearableActivityControl, ITimeEntry
         {
             ArrayList<Long> refList = null;
             Cursor cursor = database.getAllReferenceDetailData();
-            if (cursor != null) {
+            if (cursor != null)
+            {
                 refList = new ArrayList<>();
                 while (cursor.moveToNext())
                 {
index 3cb1e54..a6c4494 100644 (file)
@@ -5,21 +5,26 @@ import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
 import android.graphics.Rect;
+import android.graphics.RectF;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.view.View;
 
 import net.osdn.gokigen.joggingtimer.stopwatch.ITimerCounter;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  *
  *
  */
 public class LapTimeGraphView extends View
 {
-    private final String TAG = toString();
     private ITimerCounter timerCounter = null;
     private long counter = 0;
+    private long maxReferenceTime = 0;
+    private int referenceCount = 0;
+    private List<Long> refLapTimeList = null;
 
     /**
      *   コンストラクタ
@@ -41,11 +46,6 @@ public class LapTimeGraphView extends View
         initComponent(context);
     }
 
-    public void setITimerCounter(ITimerCounter counter)
-    {
-        timerCounter = counter;
-    }
-
     /**
      *   コンストラクタ
      *
@@ -61,7 +61,6 @@ public class LapTimeGraphView extends View
      */
     private void initComponent(Context context)
     {
-        Log.v(TAG, "initComponent()");
         setWillNotDraw(false);
     }
 
@@ -69,6 +68,16 @@ public class LapTimeGraphView extends View
      *
      *
      */
+    public void setITimerCounter(ITimerCounter counter)
+    {
+        timerCounter = counter;
+        parseReferenceTimeList();
+    }
+
+    /**
+     *
+     *
+     */
     @Override
     protected void onDraw(Canvas canvas)
     {
@@ -100,11 +109,9 @@ public class LapTimeGraphView extends View
 
         Rect rect = new Rect(0,0, width, height);
         Paint paint = new Paint();
-        paint.setColor(Color.BLUE);
+        paint.setColor(Color.BLACK);
         paint.setStyle(Paint.Style.FILL);
         canvas.drawRect(rect, paint);
-
-        canvas.drawText(width + "x" + height, width / 2 , height / 2, paint);
     }
 
     /**
@@ -113,17 +120,31 @@ public class LapTimeGraphView extends View
      */
     private void drawReferenceLap(Canvas canvas)
     {
-        int width = canvas.getWidth();
-        int height = canvas.getHeight();
-        Rect rect = new Rect(0,0, width, height);
-        Paint paint = new Paint();
+        if ((refLapTimeList == null)||(refLapTimeList.size() <= 0))
+        {
+            return;
+        }
 
-        paint.setColor(Color.WHITE);
+        float width = canvas.getWidth();
+        float height = canvas.getHeight();
+
+        Paint paint = new Paint();
+        paint.setColor(Color.BLUE);
         paint.setStyle(Paint.Style.STROKE);
+        paint.setStyle(Paint.Style.FILL);
         paint.setStrokeWidth(0.0f);
         paint.setAntiAlias(true);
-        canvas.drawRect(rect, paint);
 
+        float boxWidthUnit = width / refLapTimeList.size();
+        float boxHeightUnit = height / (maxReferenceTime * 1.2f);
+
+        float startX = 0.0f;
+        for (Long time : refLapTimeList)
+        {
+            RectF barRect = new RectF(startX, (height - boxHeightUnit * time), (startX + boxWidthUnit), height);
+            canvas.drawRect(barRect, paint);
+            startX = startX + boxWidthUnit;
+        }
     }
 
 
@@ -133,6 +154,7 @@ public class LapTimeGraphView extends View
      */
     private void drawCurrentLap(Canvas canvas)
     {
+
     }
 
 
@@ -153,17 +175,48 @@ public class LapTimeGraphView extends View
         paint.setAntiAlias(true);
         canvas.drawRect(rect, paint);
 
-
-        String message = width + "x" + height;
+        String message = width + "x" + height + "  [" + referenceCount + "] " + maxReferenceTime;
         float textWidth = paint.measureText(message);
 
-        canvas.drawText(width + "x" + height, ((width / 2) - (textWidth / 2)) , height / 2, paint);
+        canvas.drawText(message, ((width / 2) - (textWidth / 2)) , height / 2, paint);
     }
 
     /**
      *
      *
      */
+    private void parseReferenceTimeList()
+    {
+        if (timerCounter == null)
+        {
+            return;
+        }
+        refLapTimeList = null;
+
+        List<Long> refTimeList = timerCounter.getReferenceLapTimeList();
+        referenceCount = refTimeList.size();
+        maxReferenceTime = 0;
+        if (referenceCount <= 1)
+        {
+            return;
+        }
+        refLapTimeList = new ArrayList<>();
+        long prevTime = refTimeList.get(0);
+        for (Long time : refTimeList)
+        {
+            long currTime = time - prevTime;
+            if (currTime > 0)
+            {
+                refLapTimeList.add(currTime);
+            }
+            if (currTime > maxReferenceTime)
+            {
+                maxReferenceTime = currTime;
+            }
+            prevTime = time;
+        }
+    }
+
     @Override
     public boolean performClick()
     {