#include "UiConfig.h"
#include "common/image_cache_manager.h"
#include "components/ui_button.h"
+#include "components/ui_canvas.h"
+#include "components/ui_label.h"
#include "components/ui_label_ext.h"
#include "traing/Training_UiConfig.h"
#include "traing/include/TraingModel.h"
#include <string> // 包含字符串处理库,用于使用 std::to_string
#include <ui_scroll_view.h>
-/*测试打印函数*/
-#define PRINT_LINE_INFO() \
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "File: %s, Line: %d\r\n", __FILE__, \
- __LINE__)
-#define PRINT_FUNCTION_LINE() \
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Function: %s, Line: %d\r\n", \
- __FUNCTION__, __LINE__)
-
/*
普通运动:
时长,平均心率,训练强度,卡路里,目标完成度
距离,步数,平均配速,步幅,步频,目标完成度
*/
#define UI_UPDATA 0
-namespace OHOS {
+#define CANVAS_SIZE 400
-static const int startY_Unit = 252;
-static const int startY_Value = 292;
-static const int labelHeight = 40;
-static const int labelInterval = 130;
-ColorType textColor = Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f);
+namespace OHOS {
-static const int initialY = 132;
+static const int initialY = 132 + CANVAS_SIZE;
static const int lineHeight = 130;
static const int iconHeight = 80;
static const int verticalOffset = 2;
-static const int baseY = 214;
+static const int baseY = 214 + CANVAS_SIZE;
+static const int startY_Unit = 252 + CANVAS_SIZE;
+static const int startY_Value = 292 + CANVAS_SIZE;
+static const int labelHeight = 40;
+static const int labelInterval = 130;
+
+ColorType textColor = Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f);
static TraingEnddataView *g_pTraingEnddataView{nullptr};
TraingEnddataView::~TraingEnddataView() {
DeInit();
- // scrollView_->RemoveAll();
-
- // UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(container_);
- // UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
-
g_pTraingEnddataView = nullptr;
}
/*title and sport*/
InitRollLabel(labeltype, 83, 50, 300, 35, "label1", STR_EXERCISE_LIST,
DEFAULT_VECTOR_FONT_FILENAME, 30);
- InitRollLabel(labelsport, 147, 140, 240, 35, "label6",
+ InitRollLabel(labelsport, 147, 140 + CANVAS_SIZE, 240, 35, "label6",
STR_EXERCISE_OUTDOORRUNNING, DEFAULT_VECTOR_FONT_FILENAME, 30);
- InitLabel(labelduration, 146, 179, 240, 40, "label7", "13:00:22-15:00:12",
- DEFAULT_VECTOR_FONT_FILENAME, 28);
+ InitLabel(labelduration, 146, 179 + CANVAS_SIZE, 240, 40, "label7",
+ "13:00:22-15:00:12", DEFAULT_VECTOR_FONT_FILENAME, 28);
// 初始化Label
//时长
InitRollLabel(labelutime, 146, startY_Unit + labelInterval * 0, 240, 40,
container_->SetOnDragListener(presenter_);
SetKeyActListener();
+
+ ///////////////////////////gps轨迹测试//////////////////////
+ UICanvas *canvas = new UICanvas();
+ canvas->SetHeight(CANVAS_SIZE);
+ canvas->SetWidth(CANVAS_SIZE);
+ canvas->SetPosition(33, 100);
+ scrollView_->Add(canvas);
+ GenerateTrackPoints();
+ DrawTrackSegment(canvas);
+ DrawMarkers(canvas);
}
void TraingEnddataView::OnSetUpView() {
}
return;
}
+//////////////////////////////gps轨迹测试/////////////////////////////////////
+
+std::vector<Marker> markers_ = {{{58, 18}, "起", Color::Green()},
+ {{299, 146}, "终", Color::Blue()}};
+
+void TraingEnddataView::GenerateTrackPoints() {
+ trackSegments_.clear();
+
+ TrackSegment seg1;
+ seg1.color = Color::Blue();
+ seg1.points = {
+ {299, 146}, {293, 154}, {288, 149}, {281, 163}, {277, 156}, {272, 166},
+ {273, 169}, {268, 168}, {266, 172}, {261, 185}, {254, 181}, {253, 191},
+ {249, 196}, {247, 201}, {243, 194}, {244, 198}, {239, 204}, {237, 217},
+ {234, 218}, {231, 215}, {229, 217}, {226, 219}, {224, 228}, {224, 238},
+ {221, 232}, {221, 244}, {220, 238}, {220, 245}, {218, 254}, {215, 250},
+ {212, 256}, {214, 265}, {210, 257}, {208, 261}, {207, 265}, {208, 268},
+ {204, 278}, {206, 277}, {206, 271}, {203, 282}, {202, 275}, {202, 278},
+ {198, 289}, {197, 289}, {199, 291}, {199, 291}, {194, 291}, {195, 287},
+ {193, 293}, {193, 285}, {189, 292}, {191, 299}, {188, 286}, {190, 289},
+ {188, 297}, {184, 294}, {181, 294}, {182, 284}, {182, 293}, {177, 284},
+ {179, 283}, {175, 280}, {171, 277}, {171, 275}, {170, 280}, {164, 278},
+ {165, 269}, {161, 270}, {159, 260}, {158, 267}, {156, 255}, {149, 249},
+ {147, 254}, {142, 244}, {143, 238}, {137, 237}, {131, 223}, {130, 225},
+ {128, 212}, {121, 201}, {117, 206}, {115, 197}, {108, 191}, {106, 174},
+ {98, 171}, {92, 163}, {89, 148}, {85, 141}, {74, 131}, {73, 123},
+ {64, 111}, {61, 98}, {52, 92}, {47, 84}, {36, 70}, {30, 48},
+ {23, 43}, {17, 33}, {58, 18},
+ };
+ trackSegments_.push_back(seg1);
+}
+void TraingEnddataView::DrawTrackSegment(UICanvas *canvas) {
+ // 绘制网格
+ // Paint debugPaint;
+ // debugPaint.SetStrokeColor(Color::Gray());
+ // for (int i = 0; i < CANVAS_SIZE; i += 5) {
+ // canvas->DrawLine({i, 0}, {i, CANVAS_SIZE}, debugPaint);
+ // canvas->DrawLine({0, i}, {CANVAS_SIZE, i}, debugPaint);
+ // }
+
+ // 绘制轨迹
+ for (const auto &seg : trackSegments_) {
+ if (seg.points.size() < 3) //至少需要 3 个点位
+ return;
+
+ Paint paint;
+ paint.SetStyle(Paint::PaintStyle::STROKE_STYLE);
+ paint.SetStrokeWidth(8);
+ paint.SetStrokeColor(seg.color);
+
+ canvas->BeginPath();
+ canvas->MoveTo(seg.points[0]);
+ for (size_t i = 1; i < seg.points.size(); ++i) {
+ canvas->LineTo(seg.points[i]);
+ }
+ canvas->DrawPath(paint);
+ }
+}
+void TraingEnddataView::DrawMarkers(UICanvas *canvas) {
+ Paint circlePaint;
+ circlePaint.SetStyle(Paint::PaintStyle::FILL_STYLE);
+
+ Paint textPaint;
+ textPaint.SetFillColor(Color::White());
+
+ for (const auto &marker : markers_) {
+ // 绘制标记点圆形
+ circlePaint.SetFillColor(Color::Green());
+ canvas->DrawCircle(marker.pos, 12, circlePaint);
+
+ // 绘制文字,调整位置和排版
+ UICanvas::FontStyle fontStyle;
+ fontStyle.align = TEXT_ALIGNMENT_LEFT; // 文字居左,避免 RTL 反向
+ fontStyle.direct = TEXT_DIRECT_LTR; // 从左到右排版
+ fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
+ fontStyle.fontSize = 24; // 适配 300*300 画布
+ fontStyle.letterSpace = 2;
+
+ // 文字位置:圆点右侧偏移,避免覆盖
+ canvas->DrawLabel({marker.pos.x + 18, marker.pos.y - 6}, marker.text, 80,
+ fontStyle, textPaint);
+ }
+}
} // namespace OHOS
#include "bleService.h"
#include "chip_system_time.h"
#include <custom_save_runtime.h>
+#include "cmath"
extern "C" errcode_t uapi_get_timestampe_ms(uint32_t *tm);
extern "C" errcode_t uapi_get_timestampe_ss(uint32_t *tm);
OHOS::TraingModel::GetInstance()->RecordSportData();
return;
}
-#if TIMER
+
namespace OHOS {
+#if TIMER
// 声明定时器变量
static osTimerId_t g_startCounting = NULL; // 定时器
static constexpr uint64_t MS_ONE_SECONDS = 1000;
static constexpr int32 NUM_TIME_DAY = 86400;
#endif
+// #define min(x, y) (((x) < (y)) ? (x) : (y))
+// #define max(x, y) (((x) > (y)) ? (x) : (y))
+
SportData *sportdata = new SportData();
int shock_count{0}; //震动提醒
Openstate = true; // 开启运动开始标志位
shock_count = 0; //重置震动计数
+
+ gpsData.clear();// 清空gps数据
+ canvasData.clear();// 清空画布数据
}
uint32_t TraingModel::get_current_time() {
return true;
}
+//////////////////////////////////////GPS///////////////////////////////////////////////
+/*
+ Latitude(纬度):范围:-90° 至 +90°(或南纬 90° 至北纬 90°);
+ Longitude(经度):范围:-180° 至 +180°(或西经 180° 至东经 180°);
+
+ -画布数据集最多是100个定位坐标,超过按比例进行拿取100个点位;
+ -通过映射关系,将经纬度转换为400*400画布上的坐标;
+ -但是不能靠近400,以免显示不全等问题,350*350;
+ -如果处理负数,需要将其转换为正数,然后再进行映射?
+ -如果有正数又有负数,应该怎么处理?
+*/
+
+static double getmin(double a, double b)
+{
+ return a < b ? a : b;
+}
+
+static double getmax(double a, double b)
+{
+ return a > b ? a : b;
+}
+
+// 通过经纬度数据集映射画布绘制轨迹坐标集
+void TraingModel::GetPointData()
+{
+ // 1. 按比例采样最多100个点位
+ std::vector<GPSData> sampledData;
+ if (gpsData.size() > 100) {
+ double step = static_cast<double>(gpsData.size() - 1) / 99;
+ for (int i = 0; i < 100; i++) {
+ int index = static_cast<int>(i * step);
+ sampledData.push_back(gpsData[index]);
+ }
+ } else {
+ sampledData = gpsData;
+ }
+
+ // 2. 计算经纬度的最小值和最大值
+ double minLat = 90.0, maxLat = -90.0;
+ double minLon = 180.0, maxLon = -180.0;
+ for (const auto& point : sampledData) {
+ minLat = getmin(minLat, point.latitude);
+ maxLat = getmax(maxLat, point.latitude);
+ minLon = getmin(minLon, point.longitude);
+ maxLon = getmax(maxLon, point.longitude);
+ }
+
+ // 3. 将经纬度映射到350×350画布区域(居中在400×400画布)
+ canvasData.clear();
+ const double canvasSize = 350.0;
+ const double offset = 25.0; // 400 - 350 = 50,两边各留25的边距
+
+ for (const auto& point : sampledData) {
+ // 归一化处理(0-1范围)
+ double normLat = (point.latitude - minLat) / (maxLat - minLat);
+ double normLon = (point.longitude - minLon) / (maxLon - minLon);
+
+ // 映射到画布坐标(考虑偏移)
+ double x = normLon * canvasSize + offset;
+ double y = (1.0 - normLat) * canvasSize + offset; // 注意:y轴需要反转(屏幕坐标系向下为正)
+
+ canvasData.push_back({x, y});
+ }
+}
+
+// 添加经纬度数据集
+void TraingModel::AddGPSData(double latitude, double longitude)
+{
+ // 判断数据是否合理
+ if (latitude < -90 || latitude > 90 || longitude < -180 || longitude > 180) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid GPS data");
+ return;
+ }
+ // 添加数据
+ gpsData.push_back({latitude, longitude});
+}
+
+// 获取轨迹点集
+std::vector<CanvasPoint> TraingModel::GetCanvasData() const
+{
+ return canvasData;
+}
+
} // namespace OHOS