From f0587cf46727870a67b4accfd555b9b44d2eba42 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Thu, 16 Jan 2025 14:33:56 +0800 Subject: [PATCH] =?utf8?q?=E8=AE=A1=E7=AE=97=E5=99=A8=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../calculator/include/CalculatorView.h | 4 +- .../calculator/src/CalculatorModel.cpp | 8 +- .../calculator/src/CalculatorPresenter.cpp | 2 +- .../calculator/src/CalculatorView.cpp | 96 ++++++++++--------- 4 files changed, 57 insertions(+), 53 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorView.h b/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorView.h index a19cda1fc..7249f9cfc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorView.h @@ -29,7 +29,9 @@ namespace OHOS { -class CalculatorView : public View { +class CalculatorView : + public UIViewGroup, +public View { public: CalculatorView(); ~CalculatorView(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorModel.cpp index cdcaed1de..340263843 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorModel.cpp @@ -33,7 +33,7 @@ CalculatorModel::~CalculatorModel() void CalculatorModel:: number_push_stack(double data) { - printf("%lf\r\n",data); + // printf("%lf\r\n",data); if(!symbolStack.empty()) { if(symbolStack.top()=='-') @@ -51,7 +51,7 @@ void CalculatorModel:: number_push_stack(double data) void CalculatorModel:: symbol_stack_top_uddata(char data) { - printf("%c\r\n",data); + // printf("%c\r\n",data); if(!symbolStack.empty()) { symbolStack.pop(); @@ -75,7 +75,7 @@ uint8_t CalculatorModel::get_stcak_size() void CalculatorModel:: symbol_push_stack(char symbol) { - printf("%c\r\n",symbol); + // printf("%c\r\n",symbol); if(numberStack.empty()) { @@ -135,7 +135,7 @@ double CalculatorModel:: calculate_stack() } sum=number_/sum; } - printf("sum:%lf\r\n",sum); + // printf("sum:%lf\r\n",sum); } return sum; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorPresenter.cpp index f6f5c352d..61234d7dc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorPresenter.cpp @@ -58,7 +58,7 @@ void CalculatorPresenter::OnStop(void) bool CalculatorPresenter::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick %s",view.GetViewId()); if (strcmp(view.GetViewId(), "0") == 0) { CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); return true; diff --git a/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorView.cpp b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorView.cpp index e416bd277..dfda271e8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorView.cpp @@ -82,7 +82,10 @@ static int8_t roll_falg_2=0;//0.1s一次变换 if(roll_falg<=0) { if(CalculatorView::GetInstance()) - CalculatorView::GetInstance()->show_hint_label(false); + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&CalculatorView::show_hint_label, CalculatorView::GetInstance(),false)); + } + if(g_pMainView->call_roll_timer) { @@ -99,7 +102,9 @@ static void label_Timer_CallBack_move(int data) if(roll_falg_2<=0) { if(CalculatorView::GetInstance()) - CalculatorView::GetInstance()->show_long_label(); + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&CalculatorView::show_long_label, CalculatorView::GetInstance())); + } if(g_pMainView->call_roll_timer_move) { @@ -120,16 +125,16 @@ CalculatorView *CalculatorView::GetInstance() void CalculatorView::show_hint_label(bool data) { - hint->SetVisible(data); - RootView::GetInstance()->Invalidate(); + hint->SetVisible(data); + Invalidate(); } void CalculatorView::show_long_label(void) { - number->SetText(number_string.c_str()); + number->SetText(number_string.c_str()); number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); - RootView::GetInstance()->Invalidate(); + Invalidate(); } void CalculatorView::start_call_roll_timer() @@ -162,13 +167,13 @@ void CalculatorView::start_call_roll_timer_move() osStatus_t retTimer; if(call_roll_timer_move) { - roll_falg_2=10; + roll_falg_2=15; } else { - roll_falg_2=10; + roll_falg_2=15; - call_roll_timer_move = osTimerNew((osTimerFunc_t)label_Timer_CallBack, osTimerPeriodic, NULL, NULL); + call_roll_timer_move = osTimerNew((osTimerFunc_t)label_Timer_CallBack_move, osTimerPeriodic, NULL, NULL); tick =100;// osMs2Tick(1000); retTimer = osTimerStart(call_roll_timer_move, tick); if (retTimer != osOK && call_roll_timer_move != NULL) { @@ -207,7 +212,7 @@ void CalculatorView::number_text_updata_buf(const char *buf) } - if(number_string.length()>20) + if(number_string.length()>15) { //超出长度限制 start_call_roll_timer(); @@ -217,21 +222,22 @@ void CalculatorView::number_text_updata_buf(const char *buf) number_string=number_string+buf; - if(number_string.length()>12) - { - number->SetText(number_string.c_str()+number_string.length()-12); - number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); - number_falg=1; - RootView::GetInstance()->Invalidate(); - return; - } + // if(number_string.length()>12) + // { + // number->SetText(number_string.c_str()+number_string.length()-12); + // number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + // number_falg=1; + // start_call_roll_timer_move(); + // Invalidate(); + // return; + // } number->SetText(number_string.c_str()); - number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); number_falg=1; - RootView::GetInstance()->Invalidate(); + Invalidate(); return; } @@ -246,7 +252,8 @@ void CalculatorView::symbol_text_updata_buf(const char *buf) } char new_buf[64]={0}; - const char*text_buf=number_string.c_str(); + + std::string text_buf=number_string; if(number_falg==0) { if(strcmp(buf,"÷")==0) @@ -256,13 +263,13 @@ void CalculatorView::symbol_text_updata_buf(const char *buf) number_string=new_buf; number->SetText(buf); - number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); - RootView::GetInstance()->Invalidate(); + Invalidate(); return; } - double number_float=strtod(text_buf,NULL); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%lf %s",number_float,text_buf); + double number_float=strtod(text_buf.c_str(),NULL); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%lf %s",number_float,text_buf.c_str()); char new_buf_[64]={0}; sprintf_s(new_buf_,64,"%.010lf",number_float); @@ -274,7 +281,7 @@ void CalculatorView::symbol_text_updata_buf(const char *buf) { number_float =CalculatorModel::GetInstance()->calculate_stack(); CalculatorModel::GetInstance()->number_push_stack(number_float); - RootView::GetInstance()->Invalidate(); + Invalidate(); } @@ -282,9 +289,9 @@ void CalculatorView::symbol_text_updata_buf(const char *buf) number_string=new_buf; number->SetText(new_buf); - number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); - RootView::GetInstance()->Invalidate(); + Invalidate(); if(strcmp(buf,"÷")==0) CalculatorModel::GetInstance()->symbol_push_stack('/'); @@ -307,15 +314,15 @@ void CalculatorView::symbol_text_updata_single_buf(const char *buf) char new_buf[64]={0}; - char*text_buf=(char *)number_string.c_str(); + std::string text_buf=number_string; - double number_float=strtod(text_buf,NULL); + double number_float=strtod(text_buf.c_str(),NULL); if(buf[0]=='C') { CalculatorModel::GetInstance()->clean_stack(); number->SetText(""); number_string=""; - RootView::GetInstance()->Invalidate(); + Invalidate(); } else if (buf[0]=='%') { @@ -330,7 +337,7 @@ void CalculatorView::symbol_text_updata_single_buf(const char *buf) decimal_places++; } - printf("该浮点数的小数部分有 %d %lf 位。\n", decimal_places,number_float); + // printf("该浮点数的小数部分有 %d %lf 位。\n", decimal_places,number_float); switch (decimal_places) { case 0: @@ -363,17 +370,14 @@ void CalculatorView::symbol_text_updata_single_buf(const char *buf) } number_string=new_buf; number->SetText(new_buf); - number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); - RootView::GetInstance()->Invalidate(); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + Invalidate(); } else if (buf[0]=='D') { - // number_float=0; - // sprintf_s(new_buf,16,"%.00lf",number_float); - text_buf[number_string.length()-1]='\0'; - number_string=text_buf; - number->SetText(text_buf); - number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + number_string.pop_back(); + number->SetText(number_string.c_str()); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); if(number_falg==0) { CalculatorModel::GetInstance()->symbol_stack_pop(); @@ -385,7 +389,7 @@ void CalculatorView::symbol_text_updata_single_buf(const char *buf) } - RootView::GetInstance()->Invalidate(); + Invalidate(); } return; @@ -401,12 +405,12 @@ void CalculatorView::symbol_text_updata_calculate_buf(const char *buf) } char new_buf[64]={0}; - const char*text_buf=number_string.c_str(); + std::string text_buf=number_string; double number_float=0; if(text_buf[0]>='0' && text_buf[0]<='9') { - number_float=strtod(text_buf,NULL); + number_float=strtod(text_buf.c_str(),NULL); char new_buf_[64]={0}; sprintf_s(new_buf_,64,"%.010lf",number_float); number_float=strtod(new_buf_,NULL); @@ -428,8 +432,6 @@ void CalculatorView::symbol_text_updata_calculate_buf(const char *buf) { decimal_places++; } - - printf("该浮点数的小数部分有 %d %lf 位。\n", decimal_places,number_float); switch (decimal_places) { case 0: @@ -467,8 +469,8 @@ void CalculatorView::symbol_text_updata_calculate_buf(const char *buf) number_string=new_buf; number->SetText(new_buf); - number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); - RootView::GetInstance()->Invalidate(); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + Invalidate(); // number->SetText(""); -- 2.17.1