From da82696029c81ee2583f15c9699162c94110fa98 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Tue, 30 Jul 2024 19:53:30 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E8=AE=A1=E7=AE=97=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../wearable/fd230app/CMakeLists.txt | 10 +- .../nativelauncher/include/AppViewIDs.h | 1 + .../nativelauncher/include/NativeLauncher.h | 1 + .../nativelauncher/include/UiConfig.h | 3 +- .../nativelauncher/src/NativeLauncher.cpp | 17 + .../nativeui/applist/src/ApplistModel.cpp | 1 + .../calculator/include/CalculatorModel.h | 43 +++ .../calculator/include/CalculatorPresenter.h | 43 +++ .../calculator/include/CalculatorView.h | 64 ++++ .../calculator/src/CalculatorModel.cpp | 139 ++++++++ .../calculator/src/CalculatorPresenter.cpp | 163 +++++++++ .../calculator/src/CalculatorView.cpp | 337 ++++++++++++++++++ .../mk_fs_image/fd230/fs/user/res/Vector.bin | 3 + 13 files changed, 822 insertions(+), 3 deletions(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorModel.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorPresenter.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorModel.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorView.cpp create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Vector.bin diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 0877e51d8..5cfdfb547 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -54,11 +54,13 @@ set(PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/producttest/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/themestyle/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/alipay/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/alipay/include/AlipayList ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/alipay/include/AlipayTrans - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/themestyle/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/calculator/include ${UI_SAMPLE_ROOT}/components ${CMAKE_CURRENT_SOURCE_DIR}/../service/smart_voice/smart_voice_service/interfaces/innerkits/native_c/include @@ -700,7 +702,11 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/goal/src/goalother.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/goal/src/goalhint.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/goal/src/goalControlView.cpp - #${CMAKE_CURRENT_SOURCE_DIR} /service/acc_service.c + + + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/calculator/src/CalculatorView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/calculator/src/CalculatorPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/calculator/src/CalculatorModel.cpp ) diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 86bbf70f1..12c79065a 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -121,6 +121,7 @@ typedef enum : uint16_t VIEW_DIALING_METHOD, // 拨号方式 VIEW_TEST, // 测试 VIEW_GOAL, // 每日目标 + VIEW_CALCULATOR, //计算器 /* -------------------------------------------------------------------------- */ #ifdef SUPPORT_ALIPAY_SEC VIEW_MAIN_ALIPAY, diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 335f76ea4..bb0149a96 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -110,6 +110,7 @@ namespace OHOS void InitMainPhoneSlice(void); void InitDialingMethodSlice(void); /* -------------------------------------------------------------------------- */ + void InitCalculatorSlice(void); void InittestSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h index cd673eeb3..8cfabc49f 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h @@ -307,10 +307,11 @@ namespace OHOS static constexpr const char *PNG_APPLIST_TACKEPHOTOS_IMAGE = APP_LIST_PATH "/assistant.bin"; // 遥控拍照 static constexpr const char *PNG_APPLIST_BLUETOOTH_IMAGE = APP_LIST_PATH "/Bluetooth.bin"; // 蓝牙 static constexpr const char *PNG_APPLIST_BREATHE_IMAGE = APP_LIST_PATH "/breathe.bin"; // 呼吸训练 - static constexpr const char *PNG_APPLIST_GOAL_IMAGE = APP_LIST_PATH "/sport.bin"; // 每日目标 + static constexpr const char *PNG_APPLIST_GOAL_IMAGE = APP_LIST_PATH "/sport.bin"; //每日目标 static constexpr const char *PNG_APPLIST_VOICE_IMAGE = APP_LIST_PATH "/voice.bin"; // 声音 static constexpr const char *PNG_APPLIST_AIVOICE_IMAGE = APP_LIST_PATH "/aivoice.bin"; // AI Voice(人工智能语音) static constexpr const char *PNG_APPLIST_SLEEP_IMAGE = APP_LIST_PATH "/sleeping.bin"; // 睡眠 + static constexpr const char *PNG_APPLIST_INFORMATION_IMAGE = APP_LIST_PATH "/information.bin"; // 计算器 // AppList hexagon icon static constexpr const char *PNG_APPLIST_DEFAULT_IMG = APP_RES_PATH "/regular_hexagon.bin"; diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index ad0dff95c..d0d78e0a0 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -72,6 +72,9 @@ #include "goal/include/Maingoalpresenter.h" #include "goal/include/Maingoalview.h" +#include "calculator/include/CalculatorPresenter.h" +#include "calculator/include/CalculatorView.h" + #include "system/include/SystemPresenter.h" #include "system/include/SystemView.h" @@ -323,6 +326,7 @@ namespace OHOS {VIEW_ROTATE, &NativeLauncher::InitRotateSlice}, // {VIEW_DIALUPDATE, &NativeLauncher::InitDialUpdateSlice}, //{VIEW_PHONE, &NativeLauncher::InitPhoneSlice}, // 电话 + {VIEW_PHONECALL, &NativeLauncher::InitPhoneCallSlice}, {VIEW_PHONEDIR, &NativeLauncher::InitPhoneDirSlice}, {VIEW_PHONECALLING, &NativeLauncher::InitPhoneCallingSlice}, @@ -331,6 +335,7 @@ namespace OHOS {VIEW_MAIN_PHONE, &NativeLauncher::InitMainPhoneSlice}, {VIEW_DIALING_METHOD, &NativeLauncher::InitDialingMethodSlice}, {VIEW_TEST, &NativeLauncher::InittestSlice}, + {VIEW_CALCULATOR,&NativeLauncher::InitCalculatorSlice}, /* -------------------------------------------------------------------------- */ /* ----------------------------------- 训练 ----------------------------------- */ @@ -960,6 +965,18 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_PHONERING, phoneringview); } + void NativeLauncher::InitCalculatorSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitPhoneRingSlice"); + SliceProxy *phoneringview = new AbilitySliceProxy; + if (phoneringview == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneringview"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_CALCULATOR, phoneringview); + } + /* ----------------------------------- 电话 ----------------------------------- */ void NativeLauncher::InitMainPhoneSlice(void) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp index eaf405e05..1c6ad8e3d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp @@ -63,6 +63,7 @@ namespace OHOS #ifdef SUPPORT_ALIPAY_SEC {VIEW_MAIN_ALIPAY, PNG_APPLIST_ALIPAY_IMAGE, PNG_APPLIST_ALIPAY_IMAGE, PNG_APPLIST_DEFAULT_IMG, "支付宝", STR_ALIPAY, nullptr}, #endif + {VIEW_CALCULATOR, PNG_APPLIST_INFORMATION_IMAGE, PNG_APPLIST_INFORMATION_IMAGE, PNG_APPLIST_DEFAULT_IMG, "计算器", STR_CALCULATOR, nullptr}, {VIEW_MESSAGE, PNG_APPLIST_MESSAGE_IMAGE, PNG_APPLIST_MESSAGE_IMAGE, PNG_APPLIST_DEFAULT_IMG, "消息通知", STR_MESSAGE_NOTIFICATION, nullptr}, {VIEW_COMPASS, PNG_APPLIST_COMPASS_IMAGE, PNG_APPLIST_COMPASS_IMAGE, PNG_APPLIST_DEFAULT_IMG, "指南针", STR_COMPASS, nullptr}, {VIEW_RECORD, PNG_APPLIST_RECORD_IMAGE, PNG_APPLIST_RECORD_IMAGE, PNG_APPLIST_DEFAULT_IMG, "录音", STR_RECORD, nullptr}, diff --git a/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorModel.h b/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorModel.h new file mode 100644 index 000000000..f3b884dc4 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorModel.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorModel.h + * Author: + * Create: 2021-10-12 + */ +#ifndef CALCULATOR_MODEL_H +#define CALCULATOR_MODEL_H + +#include "los_mux.h" +#include "string" +#include "PhoneService.h" +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include"ui_resource_string.h" +#include "message.h" +#include "msg_center.h" +#include "stack" + +namespace OHOS { + + +class CalculatorModel { +public: + static CalculatorModel *GetInstance(void); + + + void number_push_stack(float); + float symbol_push_stack(char symbol); + float calculate_stack(); + uint8_t get_stcak_size(); + void symbol_stack_top_uddata(float data); + void clean_stack(); +private: + CalculatorModel(); + CalculatorModel(const CalculatorModel &); + virtual ~CalculatorModel(); + std::stack numberStack; + std::stack symbolStack; + +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorPresenter.h new file mode 100644 index 000000000..c02f73966 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorPresenter.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorPresenter.h + * Author: + * Create: 2021-10-12 + */ + +#ifndef CALCULATOR_PRESENTER_H +#define CALCULATOR_PRESENTER_H + +#include "Presenter.h" +#include "ohos_types.h" +#include "CallerLogModel.h" +#include "BaseView.h" +#include "cmsis_os.h" + +namespace OHOS { +class CalculatorView; +class CalculatorPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener +{ +public: + CalculatorPresenter(); + ~CalculatorPresenter() override; + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static CalculatorPresenter *GetInstance(void); + bool OnClick(UIView &view, const ClickEvent &event) override; + + bool OnDragEnd(UIView &view, const DragEvent &event) override; + + +private: + +}; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorView.h b/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorView.h new file mode 100644 index 000000000..2b58c9afb --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorView.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorView.h + * Author: + * Create: 2021-10-12 + */ + +#ifndef CALCULATOR_VIEW_H +#define CALCULATOR_VIEW_H + +#include "View.h" +#include "CalculatorPresenter.h" +#include "CalculatorView.h" +#include "BaseView.h" +#include "components/ui_view_group.h" +#include "components/ui_image_animator.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_label_button.h" +#include "components/ui_list.h" +#include "components/abstract_adapter.h" +#include "components/ui_image_view.h" + +#include "PhoneService.h" +#include "vector.h" +#include "ChangeSliceListener.h" + +namespace OHOS { + +class CalculatorView : public View { +public: + CalculatorView(); + ~CalculatorView(); + + void OnStop() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStart() override; + static CalculatorView *GetInstance(); + void number_text_updata_buf(const char *buf); + void symbol_text_updata_buf(const char *buf); + void symbol_text_updata_single_buf(const char *buf); + void symbol_text_updata_calculate_buf(const char *buf); + +private: + uint8_t number_falg=0; + bool button_init(); + bool Label_init(); + UILabelButton *Button[20]={nullptr}; + + UIImageView *image1_{nullptr}; + + UIViewGroup *group{nullptr}; + UILabel *number{nullptr}; + + UIView::OnClickListener* clickLeftListener{nullptr}; + UIView:: OnDragListener* dragListener{nullptr}; + + +}; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorModel.cpp new file mode 100644 index 000000000..799bf7fdc --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorModel.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorModel.cpp + * Author: + * Create: 2021-10-12 + */ +#include "DialingScreenView.h" + +#include "service_id_define.h" +#include "cmsis_os.h" +#include "samgr_lite.h" +#include "CalculatorModel.h" + +#ifdef __cplusplus +extern "C" { +#endif + +using namespace OHOS; + + +static bool g_isWatchCallView = false; + +CalculatorModel::CalculatorModel() +{ + +} + +CalculatorModel::~CalculatorModel() +{ + +} + + +void CalculatorModel:: number_push_stack(float data) +{ + printf("%f\r\n",data); + if(!symbolStack.empty()) + { + if(symbolStack.top()=='-') + { + char symbol_= symbolStack.top(); + symbolStack.pop(); + data=-data; + symbolStack.push('+'); + + } + } + numberStack.push(data); +} + + +void CalculatorModel:: symbol_stack_top_uddata(float data) +{ + printf("%c\r\n",data); + if(!symbolStack.empty()) + { + symbolStack.pop(); + symbolStack.push(data); + } +} + +uint8_t CalculatorModel::get_stcak_size() +{ + return numberStack.size(); +} + +float CalculatorModel:: symbol_push_stack(char symbol) +{ + printf("%c\r\n",symbol); + + if(numberStack.empty()) + { + return 0; + } + symbolStack.push(symbol); + return 0; + +} + +void CalculatorModel:: clean_stack() +{ + while (!numberStack.empty()) + { + numberStack.pop(); + } + + while (!symbolStack.empty()) + { + symbolStack.pop(); + } +} + +float CalculatorModel:: calculate_stack() +{ + float sum=0; + if(numberStack.empty()) + return sum; + float number_1= numberStack.top(); + numberStack.pop(); + sum=number_1; + while (!numberStack.empty()) + { + float number_= numberStack.top(); + numberStack.pop(); + + if(symbolStack.empty()) + break; + char symbol= symbolStack.top(); + if(symbol=='+') + { + sum+=number_; + } + if(symbol=='x') + { + sum*=number_; + } + if(symbol=='-') + { + sum=-number_; + } + if(symbol=='/') + { + sum=number_/sum; + } + printf("sum:%f\r\n",sum); + } + return sum; +} + + +CalculatorModel *CalculatorModel::GetInstance(void) +{ + static CalculatorModel callLogModel; + return &callLogModel; +} + +#ifdef __cplusplus +} +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorPresenter.cpp new file mode 100644 index 000000000..31f9f0dfb --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorPresenter.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorPresenter.cpp + * Author: + * Create: 2021-10-12 + */ + +#include "calculator/include/CalculatorPresenter.h" +#include "calculator/include/CalculatorView.h" + + +namespace OHOS { + +static CalculatorPresenter *g_pMainView = nullptr; +CalculatorPresenter::CalculatorPresenter() +{ + g_pMainView = this; +} + +CalculatorPresenter::~CalculatorPresenter() +{ + g_pMainView = nullptr; +} + +CalculatorPresenter *CalculatorPresenter::GetInstance(void) +{ + return g_pMainView; +} + +void CalculatorPresenter::OnStart() +{ + Presenter::OnStart(); +} + +void CalculatorPresenter::OnResume(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnResume()"); + Presenter::OnResume(); + + return; +} + +void CalculatorPresenter::OnPause(void) {} + +void CalculatorPresenter::OnStop(void) +{ + +} + + +bool CalculatorPresenter::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick"); + if (strcmp(view.GetViewId(), "0") == 0) { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "1") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "2") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "3") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "4") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "5") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + + else if (strcmp(view.GetViewId(), "6") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "7") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + }else if (strcmp(view.GetViewId(), "8") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "9") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), ".") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "÷") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "x") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "+") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "-") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "C") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_single_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "%") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_single_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "=") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_calculate_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(),"D") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_single_buf(view.GetViewId()); + return true; + } + + return false; +} + +bool CalculatorPresenter::OnDragEnd(OHOS::UIView& view, const OHOS::DragEvent& event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCallingPresenter OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + if(event.GetPreLastPoint().x-event.GetStartPoint().x>150) + NativeAbility::GetInstance().Back(); + } + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorView.cpp b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorView.cpp new file mode 100644 index 000000000..9c84bbd94 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorView.cpp @@ -0,0 +1,337 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorView.cpp + * Author: + * Create: 2021-10-12 + */ + +#include "calculator/include/CalculatorView.h" +#include "calculator/include/CalculatorPresenter.h" +#include "calculator/include/CalculatorModel.h" +#include "wearable_log.h" + +namespace OHOS { + +static CalculatorView *g_pMainView = nullptr; +CalculatorView::CalculatorView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "::CalculatorView::CalculatorView "); + g_pMainView = this; +} + +CalculatorView::~CalculatorView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "::CalculatorView::~CalculatorView "); + g_pMainView = nullptr; + group->RemoveAll(); + if(number) + { + delete number; + number =nullptr; + } + for(int i=0;i<20;i++) + { + if(Button[i]) + { + delete Button[i]; + Button[i] =nullptr; + } + } + if(image1_) + { + delete image1_; + image1_=nullptr; + } +} + +CalculatorView *CalculatorView::GetInstance() +{ + return g_pMainView; +} + +void CalculatorView::number_text_updata_buf(const char *buf) +{ + char new_buf[16]={0}; + const char*text_buf=NULL; + if(number_falg==1) + text_buf=number->GetText(); + else + text_buf=""; + sprintf_s(new_buf,16,"%s%s",text_buf,buf); + number->SetText(new_buf); + number_falg=1; + RootView::GetInstance()->Invalidate(); + return; +} + +void CalculatorView::symbol_text_updata_buf(const char *buf) +{ + char new_buf[16]={0}; + const char*text_buf=number->GetText(); + if(number_falg==0) + { + if(strcmp(buf,"÷")==0) + CalculatorModel::GetInstance()->symbol_stack_top_uddata('/'); + else + CalculatorModel::GetInstance()->symbol_stack_top_uddata(buf[0]); + + number->SetText(buf); + RootView::GetInstance()->Invalidate(); + return; + } + float number_float=strtof(text_buf,NULL); + + CalculatorModel::GetInstance()->number_push_stack(number_float); + + if( CalculatorModel::GetInstance()->get_stcak_size()>=2) + { + number_float =CalculatorModel::GetInstance()->calculate_stack(); + CalculatorModel::GetInstance()->number_push_stack(number_float); + + RootView::GetInstance()->Invalidate(); + + } + + sprintf_s(new_buf,16,"%s",buf); + number->SetText(new_buf); + RootView::GetInstance()->Invalidate(); + + if(strcmp(buf,"÷")==0) + CalculatorModel::GetInstance()->symbol_push_stack('/'); + else + CalculatorModel::GetInstance()->symbol_push_stack(buf[0]); + + number_falg=0; + + return; +} + +void CalculatorView::symbol_text_updata_single_buf(const char *buf) +{ + char new_buf[16]={0}; + const char*text_buf=number->GetText(); + + float number_float=strtof(text_buf,NULL); + if(buf[0]=='C') + { + CalculatorModel::GetInstance()->clean_stack(); + number->SetText(""); + RootView::GetInstance()->Invalidate(); + } + else if (buf[0]=='%') + { + number_float=0.01*number_float; + sprintf_s(new_buf,16,"%.02f",number_float); + number->SetText(new_buf); + RootView::GetInstance()->Invalidate(); + } + else if (buf[0]=='D') + { + number_float=0; + sprintf_s(new_buf,16,"%.02f",number_float); + number->SetText(new_buf); + number_falg=2; + RootView::GetInstance()->Invalidate(); + } + + return; +} + +void CalculatorView::symbol_text_updata_calculate_buf(const char *buf) +{ + char new_buf[32]={0}; + const char*text_buf=number->GetText(); + float number_float=strtof(text_buf,NULL); + CalculatorModel::GetInstance()->number_push_stack(number_float); + + number_float =CalculatorModel::GetInstance()->calculate_stack(); + + // CalculatorModel::GetInstance()->number_push_stack(number_float); + number_falg=2; + + sprintf_s(new_buf,32,"%.02f",number_float); + number->SetText(new_buf); + RootView::GetInstance()->Invalidate(); + + + // number->SetText(""); + return; +} + + + + +static char *dial_id_str[]={"7","8","9","C","%","4","5","6","÷","x","1","2","3","-","+","","0",".","=",""}; + +bool CalculatorView::button_init() +{ + uint8_t showdial_i=0; + for(int i=0;i<4;i++) + { + for(int j=0;j<5;j++) + { + if(showdial_i==15 || showdial_i==19) + { + showdial_i++; + continue; + } + if (Button[showdial_i] == nullptr) { + Button[showdial_i] = new UILabelButton(); + } + if(Button[showdial_i]==nullptr) + { + return false; + } + Button[showdial_i]->SetPosition(17+(j*88), 140+(i*68)); // widget's left position and top position + + Button[showdial_i]->Resize(80, 60); // widget's width and height + Button[showdial_i]->SetViewId(dial_id_str[showdial_i]);// Set style + + Button[showdial_i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + if(j>2) + { + Button[showdial_i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xFFFF8A36); + if(i==0) + { + Button[showdial_i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xFFAAAAAA); + } + } + + Button[showdial_i]->SetText(dial_id_str[showdial_i]); + Button[showdial_i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); + Button[showdial_i]->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + group->Add(Button[showdial_i]); + Button[showdial_i]->SetVisible(true); + + clickLeftListener = (UIView::OnClickListener*)OHOS::CalculatorPresenter::GetInstance(); + if (clickLeftListener == nullptr) { + return false; + } + + Button[showdial_i]->SetOnClickListener(clickLeftListener); + + showdial_i++; + } + } + + return true; +} + +bool CalculatorView::Label_init() +{ + if (number == nullptr) { + number = new UILabel(); + } + if(number==nullptr) + { + return false; + } + number->SetPosition(61, 73); // widget's left position and top position + number->Resize(300, 60); // widget's width and height + number->SetViewId("label5");// Set style + number->SetStyle(STYLE_TEXT_FONT, 50); + + // Set additional property + number->SetText(""); + number->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + number->SetRollSpeed(0); + number->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 50); + + // Add to rootView + group->Add(number); + + number->SetVisible(true); + + if (image1_ == nullptr) { + image1_ = new UIImageView(); + } + image1_->SetPosition(378, 85); // widget's left position and top position + image1_->Resize(100, 100); // widget's width and height + image1_->SetViewId("D");// Set style + + + char* DimagesPath = "/user/res/Vector.bin"; + + image1_->SetSrc(DimagesPath); + clickLeftListener = (UIView::OnClickListener*)OHOS::CalculatorPresenter::GetInstance(); + if (clickLeftListener == nullptr) { + return false; + } + + image1_->SetOnClickListener(clickLeftListener); + image1_->SetTouchable(true); + // Add to rootView + group->Add(image1_); + + image1_->SetVisible(true); + return true; +} + +void CalculatorView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CalculatorView::OnStart"); + View::OnStart(); + + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallingView::UIViewGroup::new group error"); + return ; + } + group->SetPosition(0, 0); + group->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); // 454 : value + group->SetTouchable(true); + group->SetDraggable(true); + + dragListener = (UIView::OnDragListener*)OHOS::CalculatorPresenter::GetInstance(); + if (dragListener == nullptr) { + + return; + } + group->SetOnDragListener(dragListener); + + RootView::GetInstance()->Add(group); + + if(!button_init()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallingView::UIViewGroup::new group error"); + return; + } + if(!Label_init()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallingView::UIViewGroup::new group error"); + return; + } + + +} + + + +void CalculatorView::OnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CalculatorView::OnSetUpView"); + View::OnSetUpView(); + + Draw(); +} + + +void CalculatorView::OnTearDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CalculatorView::~OnTearDownView"); + View::OnTearDownView(); + return; +} + +void CalculatorView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CalculatorView::~OnStop"); + View::OnStop(); + + RootView::GetInstance()->ClearOnKeyActListener(); + RootView::GetInstance()->RemoveAll(); + return; +} +} \ No newline at end of file diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Vector.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Vector.bin new file mode 100644 index 000000000..24a084108 --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Vector.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4264942f5889388365faa3d1e88da4a5c9a6447d95107ce6143222e13cfa762 +size 600 -- 2.17.1