fixed calorie value update.
authorTrillGates <williamtrillgates@gmail.com>
Fri, 23 Jul 2021 03:23:03 +0000 (11:23 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Fri, 23 Jul 2021 03:23:03 +0000 (11:23 +0800)
app/src/main/java/com/ic/work/SensorDataService.java
app/src/main/java/com/ic/work/hardware/PedBaseRunnable.java

index 498aa69..6c42549 100644 (file)
@@ -179,14 +179,14 @@ public class SensorDataService extends Service implements TemperatureHelper.Temp
             ContentValues contentValuesCalorie = new ContentValues();
             contentValuesCalorie.put("s_key", "sport_calorie_value");
             contentValuesCalorie.put("s_value", value);
-            getContentResolver().insert(Uri.parse(SensorDataService.SETTINGS), contentValues);
+            ICLogger.d("sport_calorie_value == > " + value);
+            getContentResolver().insert(Uri.parse(SensorDataService.SETTINGS), contentValuesCalorie);
             //获取步数,然后入库
             handler.removeCallbacks(this);
             handler.postDelayed(this, 1000 * 5);
         }
     };
 
-
     /**
      * 此方法已经是子线程了,不可以再开子线程,包括结果的处理。
      * 这样才可以确保单一的一个任务执行,解决并发读取数据不准的问题。
index 4278cd0..b626148 100644 (file)
@@ -7,6 +7,7 @@ import android.net.Uri;
 import com.ic.work.SensorDataService;
 import com.ic.work.db.PedInjection;
 import com.ic.work.db.entity.PedEntity;
+import com.ic.work.utils.ICLogger;
 import com.ic.work.utils.PedUtil;
 import com.ic.work.utils.SPUtils;
 
@@ -71,6 +72,15 @@ public class PedBaseRunnable {
         entity.setPedDistance(getDistanceValue(number));
         entity.setPedCalorie(getCalorieValue(number));
         mPedInjection.updateDBPedDate(entity);
+        //更新卡路里
+        //保存一份到数据库中
+        BigDecimal bg = new BigDecimal(PedUtil.calcConsumeEnergy(mHeight, mWeight, number));
+        String value = String.valueOf(bg.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
+        ContentValues contentValuesCalorie = new ContentValues();
+        contentValuesCalorie.put("s_key", "sport_calorie_value");
+        contentValuesCalorie.put("s_value", value);
+        ICLogger.d("sport_calorie_value == > " + value);
+        mContext.getContentResolver().insert(Uri.parse(SensorDataService.SETTINGS), contentValuesCalorie);
     }
 
     protected void updateCountDB(int ped, OffsetDateTime dateTime) {