WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLangues");
}
#endif
- /* -------------------------------------------------------------------------- */
-
/* ------------------------------- ConfigModel ------------------------------ */
ConfigModel::GetInstance()->LoadJsonData();
/* -------------------------------------------------------------------------- */
{VIEW_WEATHER, PNG_APPLIST_WEATHER_IMAGE, PNG_APPLIST_WEATHER_IMAGE, "天气", nullptr},
{VIEW_RECORD, PNG_APPLIST_RECORD_IMAGE, PNG_APPLIST_RECORD_IMAGE, "录音", nullptr},
{VIEW_SETTING, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_SETTING_IMAGE, "设置", nullptr},
- {VIEW_ROTATE, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_UI_SAMPLE_IMAGE, "模拟表冠", nullptr},
+ {VIEW_DIALUPDATE, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_UI_SAMPLE_IMAGE, "表盘切换", nullptr},
#ifdef SUPPORT_ALIPAY_SEC
{VIEW_MAIN_ALIPAY, PNG_APPLIST_ALIPAY_IMAGE, PNG_APPLIST_ALIPAY_IMAGE, "支付宝", nullptr},
#endif
#include <string>
+#define MAX_DIALNUM 4
+typedef struct
+{
+ const char *title;
+ const char *thumbnailPath;
+ const char *dialPath;
+} DialInfo;
+enum class DialPathType
+{
+ DIAL_KUMI = 0,
+ DIAL_GALAXY,
+ DIAL_DOG,
+ DIAL_MAOMAO,
+ DIAL_DEFAULT
+};
+extern DialInfo dialInfo[MAX_DIALNUM];
+
namespace OHOS
{
class DialUpdateModel
public:
static DialUpdateModel *GetInstance();
- std::string GetDialConfigPath();
- void UpdateDialConfigPath(const std::string &newPath);
-
+ uint8_t GetDialConfigPath(); // 获取当前表盘信息,方便切换表盘
+ bool LoadDialConfigFromJson(); // 加载json
+ void UpdateDialConfigPath(uint8_t dialpathid); // 切换表盘接口
private:
DialUpdateModel();
DialUpdateModel(const DialUpdateModel &);
DialUpdateModel &operator=(const DialUpdateModel &);
virtual ~DialUpdateModel();
-
- std::string dialConfigPath = "user/res/dials/galaxy.bin";; // Member variable to store the dial configuration path
+ std::string dialConfigPath = "user/res/dialupdate/dial_config.json"; // JSON文件路径
+ uint8_t Current_dial = 0; // 目前表盘
};
}
void OnStop() override;
DialViewGroup *dialGroup_ = nullptr;
static DialUpdatePresenter *GetInstance();
+ uint8_t GetShowId();
private:
bool OnClick(UIView &view, const ClickEvent &event) override;
bool OnDrag(UIView &view, const DragEvent &event) override;
+ bool OnDragEnd(UIView &view, const DragEvent &event) override;
DialUpdateModel *g_pdialupdatemodel;
+ uint8_t showid = 0; // 表盘展示Id,默认从第一个开始
};
} // namespace OHOS
-#endif // SLEEPDETAIL_PRESENTER_H
\ No newline at end of file
+#endif
\ No newline at end of file
void TestPicker();
void GetTestView();
+ void SetView();
private:
-
UIViewGroup *container_ = nullptr;
UILabel *label1_ = nullptr;
UIImageView *image1_ = nullptr;
UIButton *button3_ = nullptr;
UIButton *button1_ = nullptr;
UIButton *button2_ = nullptr;
+
+ std::string labelStr; // 表盘名称
+ std::string dialpath; // 展示表盘
+ uint8_t dialId; // 表盘Id
};
}
*/
#include "dialupdate/include/DialUpdateModel.h"
+#include <iostream>
+#include <fstream>
+#include "cJSON.h"
+#include "wearable_log.h"
+// 表盘名称||表盘缩约图||表盘路径
+DialInfo dialInfo[MAX_DIALNUM] = {
+ {"KUMI表盘", "user/res/dialupdate/KUMI.bin", "user/res/dials/KUMI.bin"},
+ {"星空表盘", "user/res/dialupdate/galaxy.bin", "user/res/dials/galaxy.bin"},
+ {"小狗表盘", "user/res/dialupdate/dog.bin", "user/res/dials/dog.bin"},
+ {"招财猫", "user/res/dialupdate/maomao.bin", "user/res/dials/maomao.bin"}};
+
+ //{"默认表盘", "user/res/dialupdate/defult_dial.bin", "user/res/dials/defult_dial.bin"}
namespace OHOS
{
DialUpdateModel::DialUpdateModel() {}
static DialUpdateModel instance;
return &instance;
}
- std::string DialUpdateModel::GetDialConfigPath()
+
+ /**
+ * @brief 获取当前表盘配置Id
+ * @return 当前表盘配置Id
+ */
+ uint8_t DialUpdateModel::GetDialConfigPath()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetDialConfigPath:%d", Current_dial);
+ return Current_dial;
+ }
+
+ /**
+ * @brief 更新表盘配置Id
+ * @param dialpathid 新的表盘Id
+ */
+ void DialUpdateModel::UpdateDialConfigPath(uint8_t dialpathid)
{
- return dialConfigPath;
+ Current_dial = dialpathid; // 更新表盘Id
+
+ cJSON *root = cJSON_CreateObject();
+ cJSON_AddNumberToObject(root, "Current_dial", Current_dial);
+ FILE *file = fopen(dialConfigPath.c_str(), "w");
+ if (!file)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to UpdateDial JSON file for writing");
+ cJSON_Delete(root);
+ return;
+ }
+ char *jsonString = cJSON_Print(root);
+ fputs(jsonString, file);
+ fclose(file);
+ cJSON_Delete(root);
+ free(jsonString);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateDialConfigPath:%d", Current_dial);
}
- void DialUpdateModel::UpdateDialConfigPath(const std::string &newPath)
+
+ /**
+ * @brief 从JSON文件中加载表盘配置
+ * @return 加载是否成功
+ */
+ bool DialUpdateModel::LoadDialConfigFromJson()
{
- dialConfigPath = newPath;
+ cJSON *cjson_json = NULL;
+ std::ifstream file(dialConfigPath);
+ if (file.is_open())
+ {
+ std::string json_string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
+ file.close();
+ // 解析JSON数据
+ cjson_json = cJSON_Parse(json_string.c_str());
+ if (!cjson_json)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to parse JSON file");
+ return false;
+ }
+ // 从cJSON对象中提取所需的值
+ Current_dial = cJSON_GetObjectItem(cjson_json, "Current_dial")->valueint;
+ // 删除cJSON对象
+ cJSON_Delete(cjson_json);
+ }
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadDialConfigFromJson:%d", Current_dial);
+ return true;
}
+
}
DialUpdatePresenter::~DialUpdatePresenter()
{
-
g_pDialUpdatePresenter = nullptr;
}
DialUpdatePresenter *DialUpdatePresenter::GetInstance()
{
-
- return g_pDialUpdatePresenter;
- }
-
- void DialUpdatePresenter::OnStart()
- {
-
- Presenter<DialUpdateView>::OnStart();
- }
-
- void DialUpdatePresenter::OnPause(void)
- {
-
- Presenter<DialUpdateView>::OnPause();
+ static DialUpdatePresenter instance;
+ return &instance;
}
- void DialUpdatePresenter::OnResume(void)
+ uint8_t DialUpdatePresenter::GetShowId()
{
-
- Presenter<DialUpdateView>::OnResume();
+ return showid;
}
- void DialUpdatePresenter::OnStop(void)
+ // 退出切换表盘界面
+ bool DialUpdatePresenter::OnDrag(UIView &view, const DragEvent &event)
{
-
- Presenter<DialUpdateView>::OnStop();
+ return true;
}
- bool DialUpdatePresenter::OnDrag(UIView &view, const DragEvent &event)
+ bool DialUpdatePresenter::OnDragEnd(UIView &view, const DragEvent &event)
{
if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP)
{
NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
}
+ // 右滑
+ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+ {
+ if (showid == MAX_DIALNUM - 1)
+ {
+ showid = 0;
+ }
+ else
+ {
+ showid++;
+ }
+ DialUpdateView::GetInstance()->SetView();
+ RootView::GetInstance()->Invalidate(); // 刷新界面
+ }
+ // 左滑
+ if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT)
+ {
+ if (showid == 0)
+ {
+ showid = MAX_DIALNUM - 1;
+ }
+ else
+ {
+ showid--;
+ }
+ DialUpdateView::GetInstance()->SetView();
+ RootView::GetInstance()->Invalidate(); // 刷新界面
+ }
UNUSED(view);
return true;
}
bool DialUpdatePresenter::OnClick(UIView &view, const ClickEvent &event)
{
- std::string filepath;
+ // 切换表盘按键
if (strcmp(view.GetViewId(), "button_choose") == 0)
{
- filepath = "user/res/dials/KUMI.bin";
// 检查是否需要更新表盘路径
- std::string currentPath = g_pdialupdatemodel->GetDialConfigPath();
- if (currentPath != filepath)
+ uint8_t currentid = g_pdialupdatemodel->GetDialConfigPath();
+ if (showid != currentid)
{
- g_pdialupdatemodel->UpdateDialConfigPath(filepath);
+ g_pdialupdatemodel->UpdateDialConfigPath(showid);
}
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filepath:%s || currentPath:%s ", filepath.c_str(), currentPath.c_str());
- NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filepath:%d || currentPath:%d ", showid, currentid);
+ NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TRANSITION_ZOOM);
}
- if (strcmp(view.GetViewId(), "flowerbudbutton") == 0)
+ // 检查点击的按钮并展示相应的表盘
+ else if (strcmp(view.GetViewId(), "button_right") == 0)
{
-
- NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+ if (showid == MAX_DIALNUM - 1)
+ {
+ showid = 0;
+ }
+ else
+ {
+ showid++;
+ }
+ DialUpdateView::GetInstance()->SetView();
+ RootView::GetInstance()->Invalidate(); // 刷新界面
}
- if (strcmp(view.GetViewId(), "maomaobutton") == 0)
+ else if (strcmp(view.GetViewId(), "button_left") == 0)
{
-
- NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+ if (showid == 0)
+ {
+ showid = MAX_DIALNUM - 1;
+ }
+ else
+ {
+ showid--;
+ }
+ DialUpdateView::GetInstance()->SetView();
+ RootView::GetInstance()->Invalidate(); // 刷新界面
}
- if (strcmp(view.GetViewId(), "momobutton") == 0)
- {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showid:%d ", showid, showid);
+ return true;
+ }
- NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
- }
- if (strcmp(view.GetViewId(), "maliaobutton") == 0)
- {
+ void DialUpdatePresenter::OnStart()
+ {
- NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
- }
- return true;
+ Presenter<DialUpdateView>::OnStart();
+ }
+
+ void DialUpdatePresenter::OnPause(void)
+ {
+
+ Presenter<DialUpdateView>::OnPause();
+ }
+
+ void DialUpdatePresenter::OnResume(void)
+ {
+
+ Presenter<DialUpdateView>::OnResume();
+ }
+
+ void DialUpdatePresenter::OnStop(void)
+ {
+
+ Presenter<DialUpdateView>::OnStop();
}
-}
\ No newline at end of file
+}
*/
#include "dialupdate/include/DialUpdateView.h"
+#include "dialupdate/include/DialUpdateModel.h"
#include "wearable_log.h"
+#include <string>
+
+extern DialInfo dialInfo[MAX_DIALNUM];
namespace OHOS
{
{
TestPicker();
}
+ void DialUpdateView::SetView()
+ {
+ dialId = DialUpdatePresenter::GetInstance()->GetShowId();
+ labelStr = dialInfo[dialId].title;
+ dialpath = dialInfo[dialId].thumbnailPath;
+ label1_->SetText(labelStr.c_str());
+ image1_->SetSrc(dialpath.c_str());
+ }
void DialUpdateView::TestPicker()
{
+ /* -------------------------------- 加载展示表盘信息 -------------------------------- */
+ labelStr = dialInfo[dialId].title;
+ dialpath = dialInfo[dialId].thumbnailPath;
+ if (labelStr.empty() || dialpath.empty())
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DialInfo is error!");
+ return;
+ }
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TestPicker");
if (container_ == nullptr)
{
container_->SetPosition(0, 0, 466, 466);
container_->SetStyle(STYLE_BACKGROUND_OPA, 0);
}
-
+ /* -------------------------------------------------------------------------- */
// Add Label to App
if (label1_ == nullptr)
{
label1_->Resize(200, 60); // widget's width and height
label1_->SetViewId("label_title"); // Set style
label1_->SetStyle(STYLE_TEXT_FONT, 26);
-
// Set additional property
- label1_->SetText("经典表盘");
+ label1_->SetText(labelStr.c_str());
label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
label1_->SetRollSpeed(0);
// Add to rootView
container_->Add(label1_);
label1_->SetVisible(true);
-
// Add ImageView to App
if (image1_ == nullptr)
{
image1_->SetPosition(103, 103); // widget's left position and top position
image1_->Resize(100, 100); // widget's width and height
image1_->SetViewId("image1"); // Set style
-
// Set additional property
- char *image1imagesPath = "/user/res/dialupdate/KUMI.bin";
-
- image1_->SetSrc(image1imagesPath);
-
+ image1_->SetSrc(dialpath.c_str());
// Add to rootView
container_->Add(image1_);
image1_->SetVisible(true);
container_->Add(button2_);
button2_->SetVisible(true);
}
-
void DialUpdateView::OnStart()
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DialUpdateView");
container_->SetOnDragListener(draglistener);
container_->SetTouchable(true);
container_->SetDraggable(true);
+ // 取到展示表盘id
+ dialId = DialUpdatePresenter::GetInstance()->GetShowId();
GetTestView();
RootView::GetInstance()->Add(container_);
}
void OnStop() override;
virtual void Notify() override;
bool OnClick(UIView &view, const ClickEvent &event) override;
+ bool OnLongPress(UIView &view, const LongPressEvent &event) override;
virtual void OnSwipe(UISwipeView &view) override;
void SetPage(int8_t id);
void SetTaskPeroid(int page);
WeatherControlView *weatherControlView{nullptr};
TraingView *traingView{nullptr};
ApplistCardView *applistCardView{nullptr};
+ UIButton*changebut{nullptr};
/* -------------------------------------------------------------------------- */
UICardPage *recordCard[MAX_CARD]{nullptr};
bool pageStatus[MAX_CARD]{false};
keyActListener_ = nullptr;
}
}
-
+ //长按进入切换表盘页面
+ bool MainPresenterSample::OnLongPress(UIView &view, const LongPressEvent &event)
+ {
+ UNUSED(event);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnLongPress OnLongPress");
+ NativeAbility::GetInstance().ChangeSlice(VIEW_DIALUPDATE, TRANSITION_ZOOM);
+ return true;
+ }
bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event)
{
UNUSED(event);
{
#if USE_OFFLINE_DIAL
DialModelTime::GetInstance()->UpdateTime();
- //DialModelPower::GetInstance()->UpdatePower();
+ // DialModelPower::GetInstance()->UpdatePower();
dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData();
#else
dynamic_cast<MainClockView *>(view_->GetViewById(WATCH_FACE))->UpdateTime();
#include "MainViewSample.h"
#include "graphic_service.h"
#include "dialupdate/include/DialUpdateModel.h"
-
+extern DialInfo dialInfo[MAX_DIALNUM];
namespace OHOS
{
{
#if USE_OFFLINE_DIAL
mainClockView = new DialViewGroup();
- #if 0
+#if 0
std::string filePath = dynamic_cast<MainPresenterSample *>(presenter_)->GetDialPath();
if (filePath.size() == 0)
{
filePath = RES_PATH "/dials/dog.bin";
}
- #endif
- std::string filePath = DialUpdateModel::GetInstance()->GetDialConfigPath();
- if (filePath.size() == 0)
- {
- filePath = RES_PATH "/dials/KUMI.bin";
- }
+#endif
+ // DialUpdateModel::GetInstance()->LoadDialConfigFromJson();
+ uint8_t fileid = DialUpdateModel::GetInstance()->GetDialConfigPath();
+ std::string filePath = dialInfo[fileid].dialPath;
mainClockView->SetDial(filePath);
+
#else
mainClockView = new MainClockView();
#endif
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView new fail");
return nullptr;
}
+
+#if 1
+ if (changebut == nullptr)
+ {
+ changebut = new UIButton();
+ }
+ changebut->SetPosition(0, 0); // widget's left position and top position
+ changebut->Resize(466, 466); // widget's width and height
+ changebut->SetViewId("button1"); // Set style
+ changebut->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+ changebut->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+ // Set additional property
+ changebut->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfff6eeee, UIButton::PRESSED);
+ changebut->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED);
+ changebut->SetStyleForState(STYLE_BORDER_COLOR, 0xfff3e8e8, UIButton::PRESSED);
+ changebut->SetStyleForState(STYLE_BORDER_OPA, 0x00, UIButton::PRESSED);
+ // Add the CallBack about events
+ UIView::OnLongPressListener *button1LongPress = static_cast<UIView::OnLongPressListener *>(MainPresenterSample::GetInstance());
+ changebut->SetOnLongPressListener(button1LongPress);
+ // Add to rootView
+ mainClockView->Add(changebut);
+ changebut->SetVisible(true);
+#endif
return mainClockView;
}
SystemView::GetInstance()->ChangeView(SYSTEMVIEW, SUPERVISEVIEW);\r
return true;\r
}\r
+#if 0\r
else if (strcmp(view.GetViewId(), SYSTEM_LANGUAGE) == 0)\r
{\r
SystemView::GetInstance()->ChangeView(SYSTEMVIEW, SYSTEMLANGUAGEVIEW);\r
return true;\r
}\r
+#endif\r
else if (strcmp(view.GetViewId(), FACTORY_RESET) == 0)\r
{\r
SystemView::GetInstance()->ChangeView(SYSTEMVIEW, FACTORYRESETVIEW);\r
// 用来监听语言切换\r
bool RadiobuttonOnChangeListener::OnChange(UICheckBox::UICheckBoxState state)\r
{\r
-\r
+#if 0\r
// 获取字体单例\r
UIFont *uiFont = UIFont::GetInstance();\r
if (uiFont == nullptr)\r
default:\r
break;\r
}\r
+#endif\r
return true;\r
}\r
}
\ No newline at end of file
// 3.跳转到系统语言界面\r
bool SystemView::ChangeSystemLanguageView(int16_t thisView)\r
{\r
+#if 1\r
if (SystemScrollView[thisView] == nullptr)\r
{\r
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::ChangeSystemLanguageView");\r
SystemScrollView[thisView] = p_SystemLanguageView->SystemLanguageViewInit();\r
RootView::GetInstance()->Add(SystemScrollView[thisView]);\r
}\r
+#endif\r
return true;\r
}\r
\r
--- /dev/null
+{
+ "Current_dial": 0
+}
\ No newline at end of file