表盘:增加时间显示格式Slice
authorCaisking <3449750381@qq.com>
Mon, 11 Nov 2024 08:35:00 +0000 (16:35 +0800)
committerCaisking <3449750381@qq.com>
Mon, 11 Nov 2024 08:35:00 +0000 (16:35 +0800)
code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h
code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h
code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp
code/sdk/application/wearable/fd230app/nativeui/set_time_format/include/SetTimeFormatModel.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/set_time_format/include/SetTimeFormatPresenter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/set_time_format/include/SetTimeFormatView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/set_time_format/src/SetTimeFormatModel.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/set_time_format/src/SetTimeFormatView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp

index 22cdc3e..586dc5a 100644 (file)
@@ -132,6 +132,7 @@ typedef enum : uint16_t
     VIEW_CALENDAR,  // 日历
     VIEW_SAFE_MODE, // 安全模式
     VIEW_ASSISTANT, // 智能助手
+    VIEW_SET_TIME_FORMAT,// 时间格式
     /*表盘功能相关VIEW_ID 请勿移动 请勿在下方增加slice*/
     VIEW_DIAL_FUN_ID = 200,
     VIEW_GOAL,    // 步数
index 4adbb5c..c6eb0cc 100644 (file)
@@ -116,6 +116,7 @@ namespace OHOS
         void InitCodedlockSlice(void);
         void InitSafeModeSlice(void);
         void InitAssistantSlice(void);
+        void InitSetTimeFormatSlice(void);
         /* -------------------------------------------------------------------------- */
         // void InitPhoneSlice(void);
         void InitPhoneCallSlice(void);
index a8cd926..d1700f9 100644 (file)
 #include "assistant/include/AssistantView.h"
 #include "assistant/include/AssistantPresenter.h"
 #include "assistant/include/AssistantModel.h"
+/*时间格式显示*/
+#include "set_time_format/include/SetTimeFormatView.h"
+#include "set_time_format/include/SetTimeFormatPresenter.h"
 /* -------------------------------------------------------------------------- */
 #include "secondaryfunction/include/SecondaryFunctionPresenter.h"
 #include "secondaryfunction/include/SecondaryFunctionView.h"
@@ -329,33 +332,52 @@ namespace OHOS
         {VIEW_COMPASS, &NativeLauncher::InitCompassSlice},
         {VIEW_CONNECT_PHONE, &NativeLauncher::InitConnectPhoneSlice},
         {VIEW_INDOORWALK, &NativeLauncher::InitIndoorWalkSlice},
-        {VIEW_WEATHER, &NativeLauncher::InitWeatherSlice},                                   // 天气
-        {VIEW_GOAL, &NativeLauncher::InitGoalSlice},                                         // 每日目标
-        {VIEW_SYSTEM, &NativeLauncher::InitSystemSlice},                                     // 系统实例化地址
-        {VIEW_SOUND_VIBRATION, &NativeLauncher::InitSoundAndVibrationSlice},                 // 声音与震动实例化地址
-        {VIEW_SYSTEM_VOLUME, &NativeLauncher::InitSystemVolumeSlice},                        // 系统音量
-        {VIEW_CALL_VOLUME, &NativeLauncher::InitCallVolumeSlice},                            // 系统音量
-        {VIEW_CLASSIC_BLUETOOTH, &NativeLauncher::InitClassicBluetoothSlice},                // 经典蓝牙slice
-        {VIEW_BLUETOOTH_SERVICE_OPTIONS, &NativeLauncher::InitBluetoothServiceOptionsSlice}, // 蓝牙服务slice
-        {VIEW_DISPLAY_BRIGHTNESS, &NativeLauncher::InitDisplayBrightnessSlice},              // 显示与亮度的实例化地址
-        {VIEW_NETWORKANDCALL, &NativeLauncher::InitNetworkAndCallSlice},                     // 网络与通话
-        {VIEW_MOTION_RECOGNITION, &NativeLauncher::InitMotionRecognitionSlice},              // 网络与通话
-        {VIEW_SYSTEM_UPDATE, &NativeLauncher::InitSystemUpdateSlice},                        // 系统更新界面
-        {VIEW_WATCH_QR_CODE, &NativeLauncher::InitWatchQRCodeSlice},                         // 手表二维码界面
-        {VIEW_RESPIRATORY_TRAINING, &NativeLauncher::InitRespiratoryTrainingSlice},          // 呼吸训练界面
-        {VIEW_THEME_STYLE, &NativeLauncher::InitThemeStyleSlice},                            // 主题样式界面
-        {VIEW_AI_VOICE, &NativeLauncher::InitAiVoiceSlice},                                  //  Ai Voice(人工智能语音)
-        {VIEW_AI_MODELS, &NativeLauncher::InitAiModelsSlice},                                //  Ai Models(Ai模型选择界面)
-        {VIEW_REBOOTANDSHUTDOWN, &NativeLauncher::InitRebootAndShutdownSlice},               //  滑动关机和重启带恢复出厂设置
-        {VIEW_MUSIC_PLAYER, &NativeLauncher::InitMusicPlayerSlice},                          //  音乐播放器
-
-        /* -------------------------------------------------------------------------- */
+        {VIEW_WEATHER, &NativeLauncher::InitWeatherSlice}, // 天气
+        {VIEW_GOAL, &NativeLauncher::InitGoalSlice},       // 每日目标
+        {VIEW_SYSTEM, &NativeLauncher::InitSystemSlice}, // 系统实例化地址
+        {VIEW_SOUND_VIBRATION,
+         &NativeLauncher::InitSoundAndVibrationSlice}, // 声音与震动实例化地址
+        {VIEW_SYSTEM_VOLUME,
+         &NativeLauncher::InitSystemVolumeSlice}, // 系统音量
+        {VIEW_CALL_VOLUME, &NativeLauncher::InitCallVolumeSlice}, // 系统音量
+        {VIEW_CLASSIC_BLUETOOTH,
+         &NativeLauncher::InitClassicBluetoothSlice}, // 经典蓝牙slice
+        {VIEW_BLUETOOTH_SERVICE_OPTIONS,
+         &NativeLauncher::InitBluetoothServiceOptionsSlice}, // 蓝牙服务slice
+        {VIEW_DISPLAY_BRIGHTNESS,
+         &NativeLauncher::InitDisplayBrightnessSlice}, // 显示与亮度的实例化地址
+        {VIEW_NETWORKANDCALL,
+         &NativeLauncher::InitNetworkAndCallSlice}, // 网络与通话
+        {VIEW_MOTION_RECOGNITION,
+         &NativeLauncher::InitMotionRecognitionSlice}, // 网络与通话
+        {VIEW_SYSTEM_UPDATE,
+         &NativeLauncher::InitSystemUpdateSlice}, // 系统更新界面
+        {VIEW_WATCH_QR_CODE,
+         &NativeLauncher::InitWatchQRCodeSlice}, // 手表二维码界面
+        {VIEW_RESPIRATORY_TRAINING,
+         &NativeLauncher::InitRespiratoryTrainingSlice}, // 呼吸训练界面
+        {VIEW_THEME_STYLE,
+         &NativeLauncher::InitThemeStyleSlice}, // 主题样式界面
+        {VIEW_AI_VOICE,
+         &NativeLauncher::InitAiVoiceSlice}, //  Ai Voice(人工智能语音)
+        {VIEW_AI_MODELS,
+         &NativeLauncher::InitAiModelsSlice}, //  Ai Models(Ai模型选择界面)
+        {VIEW_REBOOTANDSHUTDOWN,
+         &NativeLauncher::
+             InitRebootAndShutdownSlice}, //  滑动关机和重启带恢复出厂设置
+        {VIEW_MUSIC_PLAYER,
+         &NativeLauncher::InitMusicPlayerSlice}, //  音乐播放器
+
+        /* --------------------------------------------------------------------------
+         */
         {VIEW_OBU_MESSAGE, &NativeLauncher::InitOBUMessageSlice},
-        /* -------------------------------------------------------------------------- */
+        /* --------------------------------------------------------------------------
+         */
 
         // {VIEW_SECONDARY_FUNCTION, &NativeLauncher::InitSecondaryFunction},
         // {VIEW_FAST_TRAINING, &NativeLauncher::InitFastTrainingSlice},
-        // {VIEW_FAST_TRAINING_ATTENTION, &NativeLauncher::InitFastTrainingAttentionSlice},
+        // {VIEW_FAST_TRAINING_ATTENTION,
+        // &NativeLauncher::InitFastTrainingAttentionSlice},
 
         {VIEW_RECORD, &NativeLauncher::InitRecordingSlice}, // 录音实例化地址
         {VIEW_FIND_PHONE, &NativeLauncher::InitFindPhoneSlice},
@@ -381,24 +403,33 @@ namespace OHOS
         {VIEW_CALCULATOR, &NativeLauncher::InitCalculatorSlice},
         {VIEW_CALENDAR, &NativeLauncher::InintCalendarSlice},
 
-        /* -------------------------------------------------------------------------- */
-        /* ----------------------------------- 训练 ----------------------------------- */
-        {VIEW_TRAINING, &NativeLauncher::InitTraingSlice},               // 训练
-        {VIEW_TRAININGNOMAL, &NativeLauncher::InitTraingNomalSlice},     // 正常训练初始界面
-        {VIEW_TRAININGSET, &NativeLauncher::InitTraingSetSlice},         // 训练目标设置界面
-        {VIEW_TRAININGCRAD, &NativeLauncher::InitTraingCardSlice},       // 训练卡片
-        {VIEW_TRAININGENDDATA, &NativeLauncher::InitTraingEnddataSlice}, // 训练结束详细数据
-        {VIEW_TRAINING_RECORD, &NativeLauncher::InitTraingRecordSlice},  // 训练记录
-        {VIEW_TRAININGMORE, &NativeLauncher::InitTraingMoreSlice},       // 更多训练
-        {VIEW_TRAININGLIMIT, &NativeLauncher::InitTraingLimitSlice},     // 极限训练
-        {VIEW_TRAININGICE, &NativeLauncher::InitTraingIceSlice},         // 冰上训练
-        {VIEW_TRAININGFITNESS, &NativeLauncher::InitTraingFitnessSlice}, // 健身训练
-        {VIEW_TRAININGDANCE, &NativeLauncher::InitTraingDanceSlice},     // 舞蹈训练
-        {VIEW_TRAININGREST, &NativeLauncher::InitTraingRestSlice},       // 休闲训练
-        {VIEW_TRAININGBALL, &NativeLauncher::InitTraingBallSlice},       // 球类训练
-        {VIEW_TRAININGAQUATIC, &NativeLauncher::InitTraingAquaticSlice}, // 水上训练
-        {VIEW_TRAININGOTHER, &NativeLauncher::InitTraingOtherSlice},     // 水上训练
-        /* -------------------------------------------------------------------------- */
+        /* --------------------------------------------------------------------------
+         */
+        /* ----------------------------------- 训练
+           ----------------------------------- */
+        {VIEW_TRAINING, &NativeLauncher::InitTraingSlice}, // 训练
+        {VIEW_TRAININGNOMAL,
+         &NativeLauncher::InitTraingNomalSlice}, // 正常训练初始界面
+        {VIEW_TRAININGSET,
+         &NativeLauncher::InitTraingSetSlice}, // 训练目标设置界面
+        {VIEW_TRAININGCRAD, &NativeLauncher::InitTraingCardSlice}, // 训练卡片
+        {VIEW_TRAININGENDDATA,
+         &NativeLauncher::InitTraingEnddataSlice}, // 训练结束详细数据
+        {VIEW_TRAINING_RECORD,
+         &NativeLauncher::InitTraingRecordSlice}, // 训练记录
+        {VIEW_TRAININGMORE, &NativeLauncher::InitTraingMoreSlice}, // 更多训练
+        {VIEW_TRAININGLIMIT, &NativeLauncher::InitTraingLimitSlice}, // 极限训练
+        {VIEW_TRAININGICE, &NativeLauncher::InitTraingIceSlice}, // 冰上训练
+        {VIEW_TRAININGFITNESS,
+         &NativeLauncher::InitTraingFitnessSlice}, // 健身训练
+        {VIEW_TRAININGDANCE, &NativeLauncher::InitTraingDanceSlice}, // 舞蹈训练
+        {VIEW_TRAININGREST, &NativeLauncher::InitTraingRestSlice}, // 休闲训练
+        {VIEW_TRAININGBALL, &NativeLauncher::InitTraingBallSlice}, // 球类训练
+        {VIEW_TRAININGAQUATIC,
+         &NativeLauncher::InitTraingAquaticSlice}, // 水上训练
+        {VIEW_TRAININGOTHER, &NativeLauncher::InitTraingOtherSlice}, // 水上训练
+        /* --------------------------------------------------------------------------
+         */
         /*消息通知*/
         {VIEW_MESSAGE, &NativeLauncher::InitMessageSlice},
         {VIEW_MESSAGE_SHOW, &NativeLauncher::InitMessageShowSlice},
@@ -435,6 +466,8 @@ namespace OHOS
         {VIEW_SAFE_MODE, &NativeLauncher::InitSafeModeSlice},
         /*语音助手*/
         {VIEW_ASSISTANT, &NativeLauncher::InitAssistantSlice},
+        /*时间格式*/
+        {VIEW_SET_TIME_FORMAT, &NativeLauncher::InitSetTimeFormatSlice},
         /* -------------------------------------------------------------------------- */
         /*智能助手*/
         {VIEW_OFFLINEVOICE, &NativeLauncher::InitOfflineVoice},
@@ -1239,7 +1272,7 @@ namespace OHOS
     // 检测异常 [异常数]
     void NativeLauncher::InitCheckInvalidSlice(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitCheckInvalidSlice");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitCheckInvalidSlice");
         SliceProxy *checkinvalidView = new AbilitySliceProxy<CheckInvalidView, CheckInvalidPresenter>;
         if (checkinvalidView == nullptr)
         {
@@ -1251,7 +1284,7 @@ namespace OHOS
     // 检测异常 [无效数]
     void NativeLauncher::InitCheckAbnormalSlice(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitCheckAbnormalSlice");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitCheckAbnormalSlice");
         SliceProxy *checkabnromalView = new AbilitySliceProxy<CheckAbnormalView, CheckAbnormalPresenter>;
         if (checkabnromalView == nullptr)
         {
@@ -1263,7 +1296,7 @@ namespace OHOS
     // 血氧监测界面
     void NativeLauncher::InitBloodCheckSlice(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitBloodCheckSlice");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitBloodCheckSlice");
         SliceProxy *bloodCheckView = new AbilitySliceProxy<BloodDetectionView, BloodDetectionPresenter>;
         if (bloodCheckView == nullptr)
         {
@@ -1275,7 +1308,7 @@ namespace OHOS
     // 血氧监测结果
     void NativeLauncher::InitBloodResultSlice(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitBloodResultSlice");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitBloodResultSlice");
         SliceProxy *bloodResultView = new AbilitySliceProxy<BloodResultView, BloodResultPresenter>;
         if (bloodResultView == nullptr)
         {
@@ -1287,7 +1320,7 @@ namespace OHOS
     // 心率监测界面
     void NativeLauncher::InitHeartCheckSlice(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitHeartCheckSlice");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitHeartCheckSlice");
         SliceProxy *HeartCheckView = new AbilitySliceProxy<HeartDetectionView, HeartDetectionPresenter>;
         if (HeartCheckView == nullptr)
         {
@@ -1299,7 +1332,7 @@ namespace OHOS
     // 心率监测结果
     void NativeLauncher::InitHeartResultSlice(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitHeartResultSlice");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitHeartResultSlice");
         SliceProxy *heartResultView = new AbilitySliceProxy<HeartResultView, HeartResultPresenter>;
         if (heartResultView == nullptr)
         {
@@ -1311,7 +1344,7 @@ namespace OHOS
     // 心率检查图表
     void NativeLauncher::InitHeartChartSlice(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitHeartChartSlice");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitHeartChartSlice");
         SliceProxy *heartchartView = new AbilitySliceProxy<HeartChartView, HeartChartPresenter>;
         if (heartchartView == nullptr)
         {
@@ -1323,7 +1356,7 @@ namespace OHOS
     // 密码锁
     void NativeLauncher::InitCodedlockSlice(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitCodedlockSlice");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitCodedlockSlice");
         SliceProxy *codedlockView = new AbilitySliceProxy<CodedLockView, CodedLockPresenter>;
         if (codedlockView == nullptr)
         {
@@ -1335,7 +1368,7 @@ namespace OHOS
     // 安全模式
     void NativeLauncher::InitSafeModeSlice(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSafeModeSlice");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSafeModeSlice");
         SliceProxy *safemodeView = new AbilitySliceProxy<SafeModeManagerView, SafeModeManagerPresenter>;
         if (safemodeView == nullptr)
         {
@@ -1347,7 +1380,7 @@ namespace OHOS
     //语音助手
     void NativeLauncher::InitAssistantSlice(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitAssistantSlice");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitAssistantSlice");
         SliceProxy *assistantView = new AbilitySliceProxy<AssistantView, AssistantPresenter>;
         if (assistantView == nullptr)
         {
@@ -1355,6 +1388,17 @@ namespace OHOS
         }
         NativeAbility::GetInstance().AddSliceProxy(VIEW_ASSISTANT, assistantView);
     }
+    //时间格式
+    void NativeLauncher::InitSetTimeFormatSlice()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSetTimeFormatSlice");
+        SliceProxy *setTimeFormatView = new AbilitySliceProxy<SetTimeFormatView, SetTimeFormatPresenter>;
+        if (setTimeFormatView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "setTimeFormatView is nullptr");
+        }
+        NativeAbility::GetInstance().AddSliceProxy(VIEW_SET_TIME_FORMAT,setTimeFormatView);
+    }
     /* -------------------------------------------------------------------------- */
     // 查找手机
     void NativeLauncher::InitFindPhoneSlice(void)
diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_time_format/include/SetTimeFormatModel.h b/code/sdk/application/wearable/fd230app/nativeui/set_time_format/include/SetTimeFormatModel.h
new file mode 100644 (file)
index 0000000..7314165
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) CompanyNameMagicTag 2024. All rights reserved.
+ * Description: SetTimeFormatModel.h
+ * Author:
+ * Create: 2024-06-06
+ */
+
+#ifndef SET_time_format_MODEL_H
+#define SET_time_format_MODEL_H
+#include "components/ui_view.h"
+
+namespace OHOS {
+
+enum class TimeFormat {
+  TIME_FORMAT_24H, // 24小时制
+  TIME_FORMAT_12H, // 12小时制
+  MAX_FORMAT_NUM,
+};
+
+class SetTimeFormatModel {
+public:
+  static SetTimeFormatModel &GetInstance() {
+    static SetTimeFormatModel model;
+    return model;
+  }
+
+  void SetStyle(TimeFormat style);
+  TimeFormat GetTimeStyle();
+
+private:
+  SetTimeFormatModel();
+  ~SetTimeFormatModel();
+  SetTimeFormatModel(const SetTimeFormatModel &) = delete;
+  SetTimeFormatModel &operator=(const SetTimeFormatModel &) = delete;
+};
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_time_format/include/SetTimeFormatPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/set_time_format/include/SetTimeFormatPresenter.h
new file mode 100644 (file)
index 0000000..dd91b32
--- /dev/null
@@ -0,0 +1,32 @@
+
+
+#ifndef SET_TimeFormat_PRESENTER_H
+#define SET_TimeFormat_PRESENTER_H
+
+#include "components/ui_view.h"
+#include "Presenter.h"
+
+#include "set_time_format/include/SetTimeFormatModel.h"
+#include "set_time_format/include/SetTimeFormatView.h"
+#include "set_time_format/include/SetTimeFormatPresenter.h"
+namespace OHOS
+{
+    class SetTimeFormatModel;
+    class SetTimeFormatView;
+    class SetTimeFormatPresenter : public Presenter<SetTimeFormatView, SetTimeFormatModel>,
+                                  public UIView::OnClickListener,
+                                  public RootView::OnKeyActListener,
+                                  public UIView::OnDragListener
+    {
+    public:
+        SetTimeFormatPresenter();
+        ~SetTimeFormatPresenter();
+        SetTimeFormatPresenter(const SetTimeFormatPresenter &) = delete;
+        SetTimeFormatPresenter &operator=(const SetTimeFormatPresenter &) = delete;
+        bool OnClick(UIView &view, const ClickEvent &event) override;
+        bool OnDrag(UIView &view, const DragEvent &event) override;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
+    };
+
+} // OHOS
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_time_format/include/SetTimeFormatView.h b/code/sdk/application/wearable/fd230app/nativeui/set_time_format/include/SetTimeFormatView.h
new file mode 100644 (file)
index 0000000..da583f6
--- /dev/null
@@ -0,0 +1,54 @@
+
+
+#ifndef SET_Time_Format_VIEW_H
+#define SET_Time_Format_VIEW_H
+#include "components/ui_button.h"
+#include "components/ui_label.h"
+#include "components/ui_toggle_button.h"
+#include "components/ui_view.h"
+#include "components/ui_view_group.h"
+
+#include "View.h"
+#include "components/ui_image_view.h"
+#include "components/ui_label_ext.h"
+
+#include "set_time_format/include/SetTimeFormatModel.h"
+
+namespace OHOS {
+class SetTimeFormatPresenter;
+class SetTimeFormatView : public View<SetTimeFormatPresenter> {
+public:
+  SetTimeFormatView();
+  ~SetTimeFormatView() override;
+  SetTimeFormatView(const SetTimeFormatView &) = delete;
+  SetTimeFormatView &operator=(const SetTimeFormatView &) = delete;
+
+  void OnStart() override;
+  void OnSetUpView() override;
+  void OnStop() override;
+  void OnClick(UIView &view);
+
+private:
+  UILabelExt labelTitle_;
+
+  UILabelExt labelFormat24H_;
+  UILabelExt labelFormat12H_;
+
+  UIToggleButton btnFormat24H_;
+  UIToggleButton btnFormat12H_;
+
+  UIImageView Format24H_Image_;
+  UIImageView Format12H_Image_;
+
+  struct {
+    UIToggleButton *btn;
+    TimeFormat style;
+  }
+
+  styleTable_[static_cast<int>(TimeFormat::MAX_FORMAT_NUM)] = {
+      {&btnFormat24H_, TimeFormat::TIME_FORMAT_24H},
+      {&btnFormat12H_, TimeFormat::TIME_FORMAT_12H},
+  };
+};
+} // OHOS
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_time_format/src/SetTimeFormatModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_time_format/src/SetTimeFormatModel.cpp
new file mode 100644 (file)
index 0000000..e119ae6
--- /dev/null
@@ -0,0 +1,40 @@
+
+#include "set_time_format/include/SetTimeFormatModel.h"
+
+#include "custom_runtime.h"
+#include "custom_utils.h"
+
+#include "wearable_log.h"
+
+namespace OHOS {
+
+//设置时间格式
+void SetTimeFormatModel::SetStyle(TimeFormat style) {
+  // 12小时显示
+  if (style == TimeFormat::TIME_FORMAT_12H) {
+    uapi_dev_runtime_set_time_hour_show_model(12);
+    WEARABLE_LOGE("SetTimeFormatModel", "SetStyle: 12H");
+  }
+  // 24小时显示
+  else if (style == TimeFormat::TIME_FORMAT_24H) {
+    uapi_dev_runtime_set_time_hour_show_model(24);
+    WEARABLE_LOGE("SetTimeFormatModel", "SetStyle: 24H");
+  }
+
+  return;
+}
+//获取时间格式
+TimeFormat SetTimeFormatModel::GetTimeStyle() {
+  if (uapi_dev_runtime_get_time_hour_show_model() == 24) {
+    WEARABLE_LOGE("SetTimeFormatModel", "GetStyle: 24H");
+    return TimeFormat::TIME_FORMAT_24H;
+  } else {
+    WEARABLE_LOGE("SetTimeFormatModel", "GetStyle: 12H");
+    return TimeFormat::TIME_FORMAT_12H;
+  }
+}
+
+SetTimeFormatModel::SetTimeFormatModel() {}
+
+SetTimeFormatModel::~SetTimeFormatModel() {}
+} // namespace OHOS
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp
new file mode 100644 (file)
index 0000000..28f9d1b
--- /dev/null
@@ -0,0 +1,48 @@
+
+#include "set_time_format/include/SetTimeFormatPresenter.h"
+#include "set_time_format/include/SetTimeFormatModel.h"
+#include "set_time_format/include/SetTimeFormatView.h"
+
+#include "KeyInputListener.h"
+#include "common/key_code.h"
+#include "custom_utils.h"
+
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+
+namespace OHOS {
+SetTimeFormatPresenter::SetTimeFormatPresenter() {
+  Attach(&SetTimeFormatModel::GetInstance());
+}
+
+SetTimeFormatPresenter::~SetTimeFormatPresenter() {}
+
+bool SetTimeFormatPresenter::OnClick(UIView &view, const ClickEvent &event) {
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetTimeFormatPresenter::OnClick");
+  view_->OnClick(view);
+  return true;
+}
+
+bool SetTimeFormatPresenter::OnDrag(UIView &view, const DragEvent &event) {
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetTimeFormatPresenter::OnDrag");
+  UNUSED(view);
+  if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) &&
+      (event.GetDeltaX() > X_DRAG_OFFSET) &&
+      (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) {
+    NativeAbility::GetInstance().Back();
+  }
+  return true;
+}
+
+bool SetTimeFormatPresenter::OnKeyAct(UIView &view, const KeyEvent &event) {
+  unsigned short keyID = event.GetKeyId();
+  unsigned short keyState = event.GetState();
+  // 如果是power键,且是亮屏状态,按键释放就返回上一级
+  if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) &&
+      keyState == 1 && uapi_get_screen_state() == 0) {
+    // 回退
+    NativeAbility::GetInstance().Back();
+  }
+  return true;
+}
+} // namespace OHOS
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_time_format/src/SetTimeFormatView.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_time_format/src/SetTimeFormatView.cpp
new file mode 100644 (file)
index 0000000..aaad3cc
--- /dev/null
@@ -0,0 +1,141 @@
+/*** 
+ * @Date: 2024-07-05 11:09:20
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-09-05 18:09:22
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/set_dial_style/src/SetTimeFormatView.cpp
+ */
+
+
+#include "set_time_format/include/SetTimeFormatModel.h"
+#include "set_time_format/include/SetTimeFormatView.h"
+#include "set_time_format/include/SetTimeFormatPresenter.h"
+
+#include "UiConfig.h"
+#include "ui_resource_string.h"
+namespace OHOS
+{
+    SetTimeFormatView::SetTimeFormatView()
+    {
+    }
+
+    SetTimeFormatView::~SetTimeFormatView()
+    {
+    }
+
+    void SetTimeFormatView::OnStart()
+    {
+        View<SetTimeFormatPresenter>::OnStart();
+        SetContainerView(new UIViewGroup);
+        if (container_ == nullptr)
+        {
+            return;
+        }
+        container_->SetDraggable(true);
+        container_->SetPosition(0, 0, 466, 466);
+        container_->SetOnDragListener(presenter_);
+        // 增加按键监听
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)(presenter_);
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+        container_->SetTouchable(true);
+    }
+
+    void SetTimeFormatView::OnSetUpView()
+    {
+        if (container_ == nullptr)
+        {
+            return;
+        }
+        View<SetTimeFormatPresenter>::OnSetUpView();
+
+        Format24H_Image_.SetPosition(43, 120, 380, 100);
+        Format24H_Image_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+        Format24H_Image_.SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+        Format24H_Image_.SetStyle(STYLE_BORDER_RADIUS, 100);
+        container_->Add(&Format24H_Image_);
+
+        Format12H_Image_.SetPosition(43, 240, 380, 100);
+        Format12H_Image_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+        Format12H_Image_.SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+        Format12H_Image_.SetStyle(STYLE_BORDER_RADIUS, 100);
+        container_->Add(&Format12H_Image_);
+
+        labelTitle_.SetPosition(83, 50, 300, 60);
+        labelTitle_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+        // labelTitle_.SetTextId(STR_BROWSING_SPECIAL_EFFECTS);
+        labelTitle_.SetText("设置时间格式");//TODO:多国语言
+        labelTitle_.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); // 居中
+        labelTitle_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        container_->Add(&labelTitle_);
+
+        labelFormat24H_.SetPosition(90, 153, 200, 60);
+        labelFormat24H_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+        // labelFormat24H_.SetTextId(STR_OVERLAY_FLOW);
+        labelFormat24H_.SetText("24小时显示");//TODO:多国语言
+        container_->Add(&labelFormat24H_);
+
+        labelFormat12H_.SetPosition(90, 273, 200, 60);
+        labelFormat12H_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+        // labelFormat12H_.SetTextId(STR_Format12H);
+        labelFormat12H_.SetText("12小时显示");//TODO:多国语言
+        container_->Add(&labelFormat12H_);
+
+        btnFormat24H_.SetPosition(298, 145, 100, 50);
+        btnFormat24H_.SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE);
+        container_->Add(&btnFormat24H_);
+        btnFormat12H_.SetPosition(298, 265, 100, 50);
+        btnFormat12H_.SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE);
+        container_->Add(&btnFormat12H_);
+
+        const TimeFormat style = SetTimeFormatModel::GetInstance().GetTimeStyle();
+        int len = sizeof(styleTable_) / sizeof(styleTable_[0]);
+        for (int i = 0; i < len; ++i)
+        {
+            if (style == styleTable_[i].style)
+            {
+                styleTable_[i].btn->SetState(true);
+            }
+            else
+            {
+                styleTable_[i].btn->SetState(false);
+            }
+        }
+
+        btnFormat24H_.SetOnClickListener(presenter_);
+        btnFormat12H_.SetOnClickListener(presenter_);
+    }
+
+    void SetTimeFormatView::OnStop()
+    {
+        View<SetTimeFormatPresenter>::OnStop();
+        if (container_ != nullptr)
+        {
+            container_->RemoveAll();
+            delete container_;
+            container_ = nullptr;
+        }
+    }
+
+    void SetTimeFormatView::OnClick(UIView &view)
+    {
+        const UIToggleButton *ptr = dynamic_cast<UIToggleButton *>(&view);
+        if (ptr == nullptr)
+        {
+            return;
+        }
+        int len = sizeof(styleTable_) / sizeof(styleTable_[0]);
+        for (int i = 0; i < len; ++i)
+        {
+            if (ptr == styleTable_[i].btn)
+            {
+                styleTable_[i].btn->SetState(true);
+                SetTimeFormatModel::GetInstance().SetStyle(styleTable_[i].style);
+            }
+            else
+            {
+                styleTable_[i].btn->SetState(false);
+            }
+        }
+        // 切换到切换表盘Slice
+        // NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL);
+    }
+} // OHOS
\ No newline at end of file
index ac06afb..71a1a5c 100644 (file)
@@ -11,6 +11,7 @@
 #include "DialModelWeather.h"
 #include "DialModelWeatherStr.h"
 #include "ConfigModel.h"
+#include "custom_runtime.h"
 namespace OHOS
 {
 #if __cplusplus
@@ -146,6 +147,13 @@ namespace OHOS
         localtime_r(&seconds, &pTM);
 
         int hour = pTM.tm_hour;
+        //需要判断显示的格式
+        if (uapi_dev_runtime_get_time_hour_show_model() ==  12)
+        {
+            if (pTM.tm_hour > 12)
+                hour = pTM.tm_hour - 12 ;
+        }
+
         int minute = pTM.tm_min;
 
         std::string weatherTime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute);