From 01d99d33cb36a61ed6a39e8ff13e253d6c7d7e0d Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Mon, 2 Sep 2024 17:34:01 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E6=8B=A8=E6=89=93=E7=94=B5?= =?utf8?q?=E8=AF=9D=EF=BC=8C=E9=80=9A=E8=AE=AF=E5=BD=95=EF=BC=8CUI?= =?utf8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../calculator/include/CalculatorPresenter.h | 5 +- .../calculator/src/CalculatorPresenter.cpp | 18 +++- .../calculator/src/CalculatorView.cpp | 4 + .../phone/include/PhoneCallPresenter.h | 2 +- .../nativeui/phone/include/PhoneCallView.h | 6 ++ .../nativeui/phone/include/PhoneDirView.h | 2 + .../nativeui/phone/src/PhoneCallPresenter.cpp | 1 + .../nativeui/phone/src/PhoneCallView.cpp | 87 ++++++++++++++++++- .../nativeui/phone/src/PhoneDirView.cpp | 66 +++++++++----- 9 files changed, 161 insertions(+), 30 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorPresenter.h index c02f73966..97f69fec2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/include/CalculatorPresenter.h @@ -18,7 +18,8 @@ namespace OHOS { class CalculatorView; class CalculatorPresenter : public Presenter, public UIView::OnClickListener, - public UIView::OnDragListener + public UIView::OnDragListener, + public RootView::OnKeyActListener { public: CalculatorPresenter(); @@ -31,7 +32,7 @@ public: static CalculatorPresenter *GetInstance(void); bool OnClick(UIView &view, const ClickEvent &event) override; - + bool OnKeyAct(UIView &view, const KeyEvent &event) override; bool OnDragEnd(UIView &view, const DragEvent &event) override; 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 191f14643..ad2d1d8c3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorPresenter.cpp @@ -8,7 +8,8 @@ #include "calculator/include/CalculatorPresenter.h" #include "calculator/include/CalculatorView.h" #include "gfx_utils/mem_check.h" - +#include "common/key_code.h" +#include "custom_utils.h" namespace OHOS { static CalculatorPresenter *g_pMainView = nullptr; @@ -166,4 +167,19 @@ bool CalculatorPresenter::OnDragEnd(OHOS::UIView& view, const OHOS::DragEvent& e } return true; } + +bool CalculatorPresenter::OnKeyAct(UIView &view, const KeyEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + 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 index 95619d6a5..ee0164100 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/calculator/src/CalculatorView.cpp @@ -22,6 +22,7 @@ CalculatorView::CalculatorView() CalculatorView::~CalculatorView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "::CalculatorView::~CalculatorView "); + RootView::GetInstance()->ClearOnKeyActListener(); g_pMainView = nullptr; group->RemoveAll(); if(number) @@ -279,6 +280,9 @@ void CalculatorView::OnStart() WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CalculatorView::OnStart"); View::OnStart(); + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::CalculatorPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + group = new UIViewGroup(); if (group == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallingView::UIViewGroup::new group error"); diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallPresenter.h index d51b5a67d..54c4d3b2e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallPresenter.h @@ -28,7 +28,7 @@ namespace OHOS void UpdatePhoneNumberView(const std::string &number); static PhoneCallPresenter *GetInstance(); std::string phoneNumber; - + private: // 声明一个字符串变量用于存储用户输入的号码 diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallView.h b/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallView.h index f1575bf29..59b844848 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallView.h @@ -9,6 +9,7 @@ #include "components/ui_label_ext.h" #include "components/ui_image_view.h" #include "components/ui_button.h" +#include "cmsis_os2.h" #include "PhoneCallPresenter.h" namespace OHOS @@ -69,20 +70,25 @@ namespace OHOS void OnStop() override; void Invalidate(); void ReLabel(); + void ReLabel(uint8_t); void Init(); void DeInit(); void container_child_init(); void initButton(const ButtonInitParams ¶ms); void UpdateLabel(const std::string &text); void container_child_SetVisible(bool); + void start_call_roll_timer(); UIView *GetView(); + osTimerId_t call_roll_timer=NULL; private: + UIView::OnDragListener *draglistener{nullptr}; PhoneCallView(PhoneCallView &&) = delete; PhoneCallView &operator=(PhoneCallView &&) = delete; UIViewGroup *container_ = nullptr; UIViewGroup *container_child = nullptr; + UILabel *label_ = nullptr; UILabel *label_4G = nullptr; UILabel *label_BT = nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneDirView.h b/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneDirView.h index ee2ba9a00..ea71cb65a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneDirView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneDirView.h @@ -76,6 +76,8 @@ namespace OHOS UILabelExt *label1_no =nullptr; UILabelExt *label2_no=nullptr; UIImageView *image1_no=nullptr; + ImageInfo *image_boy ={nullptr}; + ImageInfo *image_girl={nullptr}; }; } // namespace OHOS #endif // PhoneDir_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallPresenter.cpp index 68e5a96f1..1857c17f9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallPresenter.cpp @@ -202,6 +202,7 @@ namespace OHOS // 点击9键,将字符'9'追加到号码字符串中 phoneNumber += "9"; } + } printf("**************************\n"); printf("per phoneNumber: %s\n", phoneNumber.c_str()); diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallView.cpp b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallView.cpp index 6dddc0bfd..d98534d7d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallView.cpp @@ -5,6 +5,8 @@ #include "ui_resource_image.h" #include #include "components/ui_button.h" +#include "osal_timer.h" +#include "cmsis_os2.h" namespace OHOS { @@ -90,8 +92,8 @@ namespace OHOS { label_ = new UILabel(); } - label_->SetPosition(115, 40); // widget's left position and top position - label_->Resize(236, 47); // widget's width and height + label_->SetPosition(115-3, 40); // widget's left position and top position + label_->Resize(236+6, 47); // widget's width and height label_->SetViewId("label1"); // Set style label_->SetStyle(STYLE_TEXT_FONT, 40); @@ -127,10 +129,82 @@ namespace OHOS initButton(params); } } + static int8_t roll_falg=0;//0.1s一次变换 + + static void label_Timer_CallBack(int data) + { + roll_falg--; + if(roll_falg<=0) + { + if(PhoneCallView::GetInstance()) + PhoneCallView::GetInstance()->ReLabel(0); + + if(g_pPhoneCallView->call_roll_timer) + { + osTimerStop(g_pPhoneCallView->call_roll_timer); + osTimerDelete(g_pPhoneCallView->call_roll_timer); + g_pPhoneCallView->call_roll_timer = NULL; + } + } + } + + void PhoneCallView::start_call_roll_timer() + { + uint32_t tick; + osStatus_t retTimer; + if(call_roll_timer) + { + roll_falg=10; + // osTimerStop(call_roll_timer); + // osTimerDelete(call_roll_timer); + + // call_roll_timer = osTimerNew((osTimerFunc_t)label_Timer_CallBack, osTimerPeriodic, NULL, NULL); + // tick =100;// osMs2Tick(1000); + // retTimer = osTimerStart(call_roll_timer, tick); + // if (retTimer != osOK && call_roll_timer != NULL) { + // osTimerDelete(call_roll_timer); + // call_roll_timer = NULL; + // return ; + // } + + } + else + { + roll_falg=10; + + call_roll_timer = osTimerNew((osTimerFunc_t)label_Timer_CallBack, osTimerPeriodic, NULL, NULL); + tick =100;// osMs2Tick(1000); + retTimer = osTimerStart(call_roll_timer, tick); + if (retTimer != osOK && call_roll_timer != NULL) { + osTimerDelete(call_roll_timer); + call_roll_timer = NULL; + return ; + } + } + + } void PhoneCallView::ReLabel() { + if(PhoneCallPresenter::GetInstance()->phoneNumber.length()>11) + { + label_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + label_->SetText(PhoneCallPresenter::GetInstance()->phoneNumber.c_str()+ + (PhoneCallPresenter::GetInstance()->phoneNumber.length()-11)); + start_call_roll_timer(); + + } + else + { + label_->SetText(PhoneCallPresenter::GetInstance()->phoneNumber.c_str()); + } + } + + void PhoneCallView::ReLabel(uint8_t data) + { + if(label_) label_->SetText(PhoneCallPresenter::GetInstance()->phoneNumber.c_str()); } + void PhoneCallView::DeInit() { printf("DeInit is ok !\n"); @@ -223,6 +297,15 @@ namespace OHOS delete buttondel_; buttondel_ = nullptr; } + if(call_roll_timer) + { + osTimerStop(call_roll_timer); + osTimerDelete(call_roll_timer); + call_roll_timer = NULL; + + } + roll_falg=0; + delete container_child; container_child = nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp index b170de595..f436ad9a3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp @@ -2,6 +2,7 @@ #include "phone/include/PhoneDirView.h" #include "ui_resource_string.h" +#include "common/image_cache_manager.h" #include "phone/include/phoneaddressmodel.h" #define PHONE_DIR_GIRL "/user/res/Phone/little-girl.bin" @@ -43,7 +44,10 @@ namespace OHOS button->SetViewId(buttonconfig.ViewId); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "----------%s ---",buttonconfig.ViewId); button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + + if(buttonconfig.ImageSrc) button->SetImageSrc(buttonconfig.ImageSrc, buttonconfig.ImageSrc); + button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); if(clickListener!=NULL) button->SetOnClickListener(clickListener); @@ -54,7 +58,7 @@ namespace OHOS button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, buttonconfig.Fontsize); button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - button->SetImagePosition(30, 25); + button->SetImagePosition(25, 25); return button; } @@ -81,7 +85,7 @@ namespace OHOS buttonconfig.ViewId =number_str[i]; buttonconfig.ImageSrc = addressbook_t.Contact_t[i].sex ? PHONE_DIR_BOY:PHONE_DIR_GIRL; - buttonconfig.label_x=120; + buttonconfig.label_x=107; buttonconfig.label_y=0; buttonconfig.Fontsize=30; buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT; @@ -98,25 +102,28 @@ namespace OHOS if (container_one_page == nullptr) { container_one_page = new UIScrollView(); container_one_page->SetPosition(0, 0,Screen::GetInstance().GetWidth(),Screen::GetInstance().GetHeight()); - container_one_page->SetStyle(STYLE_BACKGROUND_OPA, 0); + //container_one_page->SetStyle(STYLE_BACKGROUND_OPA, 0); container_one_page->SetViewId("container_one_page"); + container_one_page->SetScrollBlankSize(35); + container_one_page->SetReboundSize(35); + container_one_page->SetDirection(1); } // Add Label to App if (label1_phone_name == nullptr) { label1_phone_name = new UILabelExt(); } - label1_phone_name->SetPosition(0, 53); // widget's left position and top position - label1_phone_name->Resize(466, 55); // widget's width and height + label1_phone_name->SetPosition(0, 52); // widget's left position and top position + label1_phone_name->Resize(466, 30); // widget's width and height label1_phone_name->SetViewId("label1");// Set style - label1_phone_name->SetStyle(STYLE_TEXT_FONT, 50); + label1_phone_name->SetStyle(STYLE_TEXT_FONT, 30); // Set additional property label1_phone_name->SetText(addressbook_t.Contact_t[0].name); label1_phone_name->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); label1_phone_name->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label1_phone_name->SetRollSpeed(1); - label1_phone_name->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 50); + label1_phone_name->SetRollSpeed(70); + label1_phone_name->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // Add to rootView container_one_page->Add(label1_phone_name); @@ -126,11 +133,15 @@ namespace OHOS if (phone_name == nullptr) { phone_name = new UIImageView(); } - phone_name->SetPosition(170, 140); // widget's left position and top position - phone_name->Resize(109, 111); // widget's width and height + phone_name->SetPosition(158, 107); // widget's left position and top position + // phone_name->Resize(150, 150); // widget's width and height phone_name->SetViewId("phone_sex");// Set style - const char *Imagesrc=addressbook_t.Contact_t[0].sex ? PHONE_DIR_BOY_1:PHONE_DIR_GIRL_1; - phone_name->SetSrc(Imagesrc); + + image_boy = ImageCacheManager::GetInstance().LoadSingleRes(PHONE_DIR_BOY_1); + + image_girl = ImageCacheManager::GetInstance().LoadSingleRes(PHONE_DIR_GIRL_1); + + phone_name->SetSrc(addressbook_t.Contact_t[0].sex ? image_boy:image_girl); @@ -139,17 +150,17 @@ namespace OHOS container_one_page->SetVisible(false); container_one_page->SetDraggable(true); container_one_page->SetTouchable(true); - RootView::GetInstance()->Add(container_one_page); + UIView::OnClickListener *clickListener = static_cast(PhoneDirPresenter::GetInstance()); /* -------------------------------------------------------------------------- */ ButtonConfig_ext_t buttonconfig; - buttonconfig.x = 80; - buttonconfig.y = 300; - buttonconfig.w = 319; - buttonconfig.h = 106; + buttonconfig.x = 43; + buttonconfig.y = 277; + buttonconfig.w = 380; + buttonconfig.h = 100; int len =addressbook_t.Contact_t[0].phone_num; @@ -159,7 +170,7 @@ namespace OHOS char buf[32]={0}; sprintf(buf,"%s",i); buttonconfig.ViewId =buf; - + buttonconfig.ImageSrc=nullptr; buttonconfig.label_x=50; buttonconfig.label_y=0; buttonconfig.Fontsize=30; @@ -178,6 +189,7 @@ namespace OHOS container_one_page->SetOnDragListener(draglistener); + return; } @@ -192,13 +204,13 @@ namespace OHOS } - container_->SetVisible(false); + //container_->SetVisible(false); container_one_page->SetVisible(true); uint8_t id= atoi(idstr);//idstr[16]; if(addressbook_t.Contact_t[id].name) label1_phone_name->SetText(addressbook_t.Contact_t[id].name); - const char *Imagesrc=addressbook_t.Contact_t[id].sex ? PHONE_DIR_BOY_1:PHONE_DIR_GIRL_1; - phone_name->SetSrc(Imagesrc); + + phone_name->SetSrc(addressbook_t.Contact_t[0].sex ? image_boy:image_girl); int len =addressbook_t.Contact_t[id].phone_num; @@ -255,6 +267,9 @@ namespace OHOS delete phone_name; phone_name = nullptr; } + ImageCacheManager::GetInstance().UnloadSingleRes(PHONE_DIR_BOY_1); + + ImageCacheManager::GetInstance().UnloadSingleRes(PHONE_DIR_GIRL_1); if(label1_phone_name) { @@ -371,9 +386,10 @@ namespace OHOS container_->SetHeight(Screen::GetInstance().GetHeight()); container_->SetScrollBlankSize(35); - container_->SetReboundSize(50); + container_->SetReboundSize(35); container_->SetDirection(1); + // 创建 draglistener 实例并设置为拖动监听器 UIView::OnDragListener *draglistener = static_cast(PhoneDirPresenter::GetInstance()); if (draglistener == nullptr) @@ -389,7 +405,7 @@ namespace OHOS if (label1_ == nullptr) { label1_ = new UILabelExt(); - } + } label1_->SetPosition(0, 18); // widget's left position and top position label1_->Resize(466, 88); // widget's width and height label1_->SetViewId("label1");// Set style @@ -410,13 +426,15 @@ namespace OHOS } else { - initView_ext(73,95,319,106,120,NULL); + initView_ext(43,123,380,100,120,NULL); } RootView::GetInstance()->Add(container_); + if(container_one_page) + RootView::GetInstance()->Add(container_one_page); // 增加按键监听 RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::PhoneDirPresenter::GetInstance(); -- 2.17.1