From 6066fdc744ebc7d4a51b8c9eebf0947b172d1426 Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Wed, 1 Apr 2026 17:21:55 +0800 Subject: [PATCH] =?utf8?q?=E5=9B=9E=E9=80=80Ability=E4=BF=AE=E6=94=B9?= =?utf8?q?=EF=BC=8C=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9=E5=85=B6=E4=BD=BF?= =?utf8?q?=E7=94=A8=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../fd272/nativeabilityfwk/CMakeLists.txt | 1 + .../fd272/nativeabilityfwk/include/Ability.h | 148 +- .../include/AbilityNavigationApi.h | 66 + .../fd272/nativeabilityfwk/src/Ability.cpp | 46 +- .../src/AbilityNavigation.cpp | 178 ++ .../nativeabilityfwk/src/AbilitySlice.cpp | 1 + .../nativeabilityfwk/src/NativeAbility.cpp | 1 + .../add_card/src/AddCardPresenter.cpp | 5 +- .../nativeui/alarm/src/AlarmPresenter.cpp | 1133 +++++------ .../nativeui/alarm/src/MainAlarmView.cpp | 3 +- .../nativeui/alipay/src/AlipayMainView.cpp | 1671 +++++++-------- .../nativeui/alipay/src/AlipayPresenter.cpp | 1192 +++++------ .../nativeui/applist/src/ApplistPresenter.cpp | 9 +- .../nativeui/applist/src/ApplistView.cpp | 9 +- .../assistant/src/AssistantPresenter.cpp | 5 +- .../src/BloodDetectionPresenter.cpp | 3 +- .../bloodoxygen/src/BloodOxygenModel.cpp | 3 +- .../bloodoxygen/src/BloodResultPresenter.cpp | 7 +- .../bluetooth/src/BluetoothPresenter.cpp | 525 ++--- .../bluetooth/src/MainBluetoothView.cpp | 933 ++++----- .../src/BrightnessLevelPresenter.cpp | 5 +- .../calculator/src/CalculatorPresenter.cpp | 5 +- .../calendar/src/CalendarPresenter.cpp | 5 +- .../nativeui/callerlog/src/CallerLogModel.cpp | 5 +- .../src/BluetoothServiceOptionsPresenter.cpp | 5 +- .../src/ClassicBlueToothPresenter.cpp | 345 ++-- .../compass/src/MainCompassPresenter.cpp | 5 +- .../nativeui/countdown/src/CountDownModel.cpp | 1671 +++++++-------- .../countdown/src/MainCountDownPresenter.cpp | 631 +++--- .../src/DisplayBrightnessPresent.cpp | 693 +++---- .../dnotdisturb/src/DnotDisturbPresenter.cpp | 9 +- .../src/EphemerisDownloadPresenter.cpp | 9 +- .../findphone/src/FindPhonePresenter.cpp | 7 +- .../flashlight/src/FlashlightPresenter.cpp | 5 +- .../nativeui/goal/src/Maingoalpresenter.cpp | 5 +- .../health/CheckAbnormalPresenter.cpp | 7 +- .../nativeui/health/CheckInvalidPresenter.cpp | 7 +- .../heartrate/src/HeartChartPresenter.cpp | 3 +- .../heartrate/src/HeartDetectionPresenter.cpp | 3 +- .../heartrate/src/HeartResultPresenter.cpp | 7 +- .../nativeui/hrv/src/HrvPresenter.cpp | 5 +- .../languagecode/src/LanguageSwitchModel.cpp | 3 +- .../src/LanguageSwitchPresenter.cpp | 7 +- .../nativeui/main/src/MainPresenterSample.cpp | 6 +- .../main/src/dropdown/DropDownCardPage1.cpp | 13 +- .../main/src/dropdown/DropDownCardPage2.cpp | 5 +- .../makephone/src/MainCallingPresenter.cpp | 3 +- .../message/src/MessageControlPresenter.cpp | 5 +- .../nativeui/message/src/MessagePresenter.cpp | 9 +- .../message/src/MessageShowPresenter.cpp | 7 +- .../src/MotionRecognitionPresenter.cpp | 5 +- .../musicplayer/src/MusicPlayerPresenter.cpp | 5 +- .../src/NetworkAndCallPresenter.cpp | 5 +- .../nativeui/phone/src/CallLogAdapter.cpp | 3 +- .../phone/src/DialingMethodPresenter.cpp | 9 +- .../nativeui/phone/src/MainPhonePresenter.cpp | 13 +- .../nativeui/phone/src/PhoneCallPresenter.cpp | 469 ++--- .../nativeui/phone/src/PhoneDirPresenter.cpp | 211 +- .../player/src/MusicPlayerSourceView.cpp | 1089 +++++----- .../src/RebootAndShutdownModel.cpp | 17 +- .../src/RebootAndShutdownPresenter.cpp | 5 +- .../record/src/RecordingPresenter.cpp | 1783 +++++++++-------- .../src/RespiratoryTrainingPresenter.cpp | 7 +- .../src/SafeModeManagerPresenter.cpp | 3 +- .../nativeui/saveele/src/SaveElePresenter.cpp | 169 +- .../schedule/src/SchedulePresenter.cpp | 283 +-- .../set_aod/src/SetAodDialPresenter.cpp | 5 +- .../set_dial/src/SetDialPresenter.cpp | 5 +- .../src/SetDialStylePresenter.cpp | 3 +- .../src/SetTimeFormatPresenter.cpp | 5 +- .../settings/src/SettingPresenter.cpp | 7 +- .../sleep/src/SleepControlPresenter.cpp | 5 +- .../sleepmode/src/SleepModePresenter.cpp | 7 +- .../src/CallVolumePresenter.cpp | 221 +- .../src/SoundAndVibrationPresenter.cpp | 349 ++-- .../src/SystemVolumePresenter.cpp | 225 +-- .../stopwatch/src/MainStopWatchPresenter.cpp | 753 +++---- .../stress/src/stressTestPresenter.cpp | 5 +- .../nativeui/system/src/SystemPresenter.cpp | 601 +++--- .../systemupdate/src/SystemUpdateModel.cpp | 5 +- .../src/SystemUpdatePresenter.cpp | 7 +- .../takephotos/src/TakephotosModel.cpp | 5 +- .../takephotos/src/TakephotosPresenter.cpp | 7 +- .../themestyle/src/ThemeStylePresenter.cpp | 11 +- .../traing/src/TraingEnddataPresenter.cpp | 3 +- .../nativeui/traing/src/TraingModel.cpp | 5 +- .../traing/src/TraingNomalPresenter.cpp | 501 ++--- .../nativeui/traing/src/TraingPresenter.cpp | 11 +- .../traing/src/TraingSetPresenter.cpp | 461 ++--- .../src/TraingEphemerisNotePresenter.cpp | 3 +- .../src/TraingGPSnotePresenter.cpp | 3 +- .../training_card/src/TraingCardPresenter.cpp | 1349 ++++++------- .../src/Training_CardPresenter.cpp | 9 +- .../src/TraingAquaticPresenter.cpp | 7 +- .../src/TraingBallPresenter.cpp | 7 +- .../src/TraingDancePresenter.cpp | 7 +- .../src/TraingFitnessPresenter.cpp | 7 +- .../src/TraingIcePresenter.cpp | 7 +- .../src/TraingLimitPresenter.cpp | 223 ++- .../src/TraingMorePresenter.cpp | 351 ++-- .../src/TraingOtherPresenter.cpp | 7 +- .../src/TraingRestPresenter.cpp | 7 +- .../src/TraingRecordPresenter.cpp | 9 +- .../watchQRcode/src/WatchQRCodePresenter.cpp | 5 +- .../weather/src/MainWeatherPresenter.cpp | 263 +-- .../womenhealth/src/WomenHealthMainPage.cpp | 1 + .../womenhealth/src/WomenHealthPresenter.cpp | 6 +- .../src/WomenHealthSettingPage.cpp | 1 + 108 files changed, 9583 insertions(+), 9406 deletions(-) create mode 100644 code/sdk/application/wearable/fd272/nativeabilityfwk/include/AbilityNavigationApi.h create mode 100644 code/sdk/application/wearable/fd272/nativeabilityfwk/src/AbilityNavigation.cpp diff --git a/code/sdk/application/wearable/fd272/nativeabilityfwk/CMakeLists.txt b/code/sdk/application/wearable/fd272/nativeabilityfwk/CMakeLists.txt index b59c59744..4c1c9a50c 100644 --- a/code/sdk/application/wearable/fd272/nativeabilityfwk/CMakeLists.txt +++ b/code/sdk/application/wearable/fd272/nativeabilityfwk/CMakeLists.txt @@ -26,6 +26,7 @@ set(PRIVATE_HEADER set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/Ability.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/AbilityNavigation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/AbilitySlice.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/NativeAbility.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/StartNative.cpp diff --git a/code/sdk/application/wearable/fd272/nativeabilityfwk/include/Ability.h b/code/sdk/application/wearable/fd272/nativeabilityfwk/include/Ability.h index bd82b42a2..f6a6877ef 100644 --- a/code/sdk/application/wearable/fd272/nativeabilityfwk/include/Ability.h +++ b/code/sdk/application/wearable/fd272/nativeabilityfwk/include/Ability.h @@ -25,15 +25,9 @@ #include "SliceProxy.h" #include "SlicePageManager.h" -#include "utils/utils_list.h" -#include -#include "TransitionType.h" -#include "soc_osal.h" -#include "stack" -#include "AppViewIDs.h" namespace OHOS { const static uint16_t gSliceInvalid = 0; -const static uint16_t gPageInvalid = 0; +const static uint16_t gPageInvalid = 0; const static uint16_t gSliceDefaultPriority = 4; // 页面默认是最低优先级 class Ability { @@ -108,21 +102,9 @@ public: uint16_t GetPreSliceId(void) { if (allSlices_.Size() < 2) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "[DEBUG] GetPreSliceId - allSlices_ size < 2 (%d), returning invalid", allSlices_.Size()); return gSliceInvalid; } - uint16_t preSliceId = static_cast(allSlices_[allSlices_.Size() - 2] & SLICE_MASK); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "[DEBUG] GetPreSliceId - allSlices_ size: %d, preSliceId: %d", allSlices_.Size(), preSliceId); - - // 打印 allSlices_ 的完整内容用于调试 - // printf("[DEBUG] allSlices_ content: ["); - // for (int i = 0; i < allSlices_.Size(); i++) { - // printf("%d", allSlices_[i] & SLICE_MASK); - // if (i < allSlices_.Size() - 1) printf(", "); - // } - // printf("]\n"); - - return preSliceId; + return static_cast(allSlices_[allSlices_.Size() - 2] & SLICE_MASK); } void UpdateCurSlicePageId(uint16_t pageId); @@ -159,130 +141,6 @@ public: void PauseSlice(); void StopSliceTransition(); void BackToPreSlice(); - - /* -------------------------------------------------------------------------- */ - /// @brief 当从一个切片(Slice)进入另一个切片时被调用。 - /// @param sliceId sliceId - /// @param transitionId 切换的动画类型 - /// @param priority 切换优先级 - void EnterSlice(uint16_t sliceId,const TransitionType transitionId = TransitionType::TRANSITION_INVALID, - const uint16_t priority = gSliceDefaultPriority,bool enableSlideBack = false) { - // 获取当前SliceID - uint16_t curSliceId = GetCurSliceId(); - if (curSliceId != defaultTargetId_) { // 假定defaultSliceId_是“主页”或启动Slice的ID - backStack_.push(curSliceId); - } - ChangeSlice(sliceId,transitionId,priority,enableSlideBack); // 切换到新的Slice - } - - uint16_t GettopSliceId(void) { - if (!backStack_.empty() ) { - return backStack_.top(); - } - return 0; - } - - - // 处理后退操作 - - /// @brief 处理后退操作。 - /// @param transitionId 切换的动画类型 - /// @param priority 切换优先级 - bool Back(const TransitionType transitionId = TransitionType::TRANSITION_INVALID, - const uint16_t priority = gSliceDefaultPriority,bool enableSlideBack = false) { - - if (!backStack_.empty()) { - uint16_t preSlice = backStack_.top(); - backStack_.pop(); - ChangeSlice(preSlice,transitionId,priority,enableSlideBack); - return true; - } - else - { - backStack_.push(defaultTargetId_); // 将默认主界面的 ID 推入栈中 - // 退回到defaultSliceId_ - ChangeSlice(defaultTargetId_, transitionId, priority,enableSlideBack); - return false; // 返回false表示无前一个slice,退回到默认slice - } - } - - /// @brief 处理后退多级切片的操作。 - /// @param count 指定的后退级数 - /// @param transitionId 切换的动画类型 - /// @param priority 切换优先级 - bool BackCountSlice(int count,const TransitionType transitionId = TransitionType::TRANSITION_INVALID, - const uint16_t priority = gSliceDefaultPriority) { - //如果指定的后退级数 count 为 0 ,直接返回 false 。 - // if(count == 0) { - // return false; - // } - while(!backStack_.empty() && count != 0) //当 count 不为 0 且 backStack_ 栈不为空时,弹出栈顶元素 count 次。 - { - backStack_.pop(); - count--; - } - if(!backStack_.empty()) - { - // 如果此时 backStack_ 栈不为空,取出栈顶的切片 ID ,并调用 ChangeSlice 切换到该切片,返回 true 。 - uint16_t preSlice = backStack_.top(); - ChangeSlice(preSlice,transitionId,priority); - backStack_.pop(); - return true; - } - else - { - //如果 backStack_ 栈为空,切换到默认切片,返回 false 。 - ChangeSlice(defaultTargetId_, transitionId, priority); - return false; // 返回false表示无前一个slice,退回到默认slice - } - } - //仅用于打电话结束恢复时使用 - bool Back_CountSlice_make_phone(const TransitionType transitionId = TransitionType::TRANSITION_INVALID, - const uint16_t priority = gSliceDefaultPriority); - - - bool make_phone_push(uint16_t preSlice) { - if(backStack_.empty()) - { - backStack_.push(preSlice); - } - else - { - uint8_t top_id= backStack_.top(); - if(top_id!=preSlice) - backStack_.push(preSlice); - } - - return false; - } - - /*清空后退栈*/ - void ClearSliceIdStack(void) - { - while(!backStack_.empty()) - { - backStack_.pop(); - } - if (backStack_.empty()) { - backStack_.push(defaultTargetId_); // 将默认主界面的 ID 推入栈中 - } - } - - /*打印栈中元素*/ - void showsStackSliceId() - { - printf("\n%d\n",backStack_.size()); - std::stack tempStack = backStack_; - printf("\n["); - while(!tempStack.empty()) - { - printf("%d,",tempStack.top()); - tempStack.pop(); - } - printf("]\n"); - printf("\n%d\n",backStack_.size()); - } - /* -------------------------------------------------------------------------- */ protected: // targetId consists of slice id and page id @@ -319,8 +177,6 @@ protected: uint16_t curSlicePriority_ = gSliceDefaultPriority; void PostChangeSlice(uint32_t targetId, TransitionType type); Ability::ProxyStruct* Find(const uint16_t sliceId); -private: - std::stack backStack_;//这个栈会在每次进入一个新的Slice时将其ID压入栈顶,当用户请求后退时,栈顶的Slice ID会被弹出,以此来访问前一个Slice。 }; } #endif // NATIVEABILITYFWK_ABILITY_H diff --git a/code/sdk/application/wearable/fd272/nativeabilityfwk/include/AbilityNavigationApi.h b/code/sdk/application/wearable/fd272/nativeabilityfwk/include/AbilityNavigationApi.h new file mode 100644 index 000000000..73d655145 --- /dev/null +++ b/code/sdk/application/wearable/fd272/nativeabilityfwk/include/AbilityNavigationApi.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NATIVEABILITYFWK_ABILITY_NAVIGATION_API_H +#define NATIVEABILITYFWK_ABILITY_NAVIGATION_API_H + +#include + +#include "Ability.h" +#include "TransitionType.h" + +#ifdef __cplusplus +/* If this header is included inside extern "C", navigation API must still use C++ linkage. */ +extern "C++" { +#endif + +namespace OHOS { + +/** Keeps mirrored default target in sync with Ability (call sites use Ability::defaultTargetId_, not public). */ +void AbilityNavigationSyncDefaultTarget(uint32_t fullTargetId); + +namespace AbilityNavigation { + +void EnterSlice(uint16_t sliceId, TransitionType transitionId = TransitionType::TRANSITION_INVALID, + uint16_t priority = gSliceDefaultPriority, bool enableSlideBack = false); + +uint16_t GettopSliceId(void); + +bool Back(TransitionType transitionId = TransitionType::TRANSITION_INVALID, + uint16_t priority = gSliceDefaultPriority, bool enableSlideBack = false); + +bool BackCountSlice(int count, TransitionType transitionId = TransitionType::TRANSITION_INVALID, + uint16_t priority = gSliceDefaultPriority); + +bool Back_CountSlice_make_phone(TransitionType transitionId = TransitionType::TRANSITION_INVALID, + uint16_t priority = gSliceDefaultPriority); + +bool make_phone_push(uint16_t preSlice); + +void ClearSliceIdStack(void); + +void showsStackSliceId(); + +/** Product hook used from Ability::SwitchSlice (main / incoming-call back-stack rules). */ +void NotifySwitchSliceBeforeTransition(Ability* ability, uint16_t sliceId); + +} // namespace AbilityNavigation +} // namespace OHOS + +#ifdef __cplusplus +} // extern "C++" +#endif + +#endif // NATIVEABILITYFWK_ABILITY_NAVIGATION_API_H diff --git a/code/sdk/application/wearable/fd272/nativeabilityfwk/src/Ability.cpp b/code/sdk/application/wearable/fd272/nativeabilityfwk/src/Ability.cpp index d9a5baaae..1568e144e 100644 --- a/code/sdk/application/wearable/fd272/nativeabilityfwk/src/Ability.cpp +++ b/code/sdk/application/wearable/fd272/nativeabilityfwk/src/Ability.cpp @@ -25,6 +25,9 @@ #include "PageTransitionMgr.h" #include "gfx_utils/list.h" #include "AbilitySlice.h" +#include "AbilityNavigationApi.h" + +#include namespace OHOS { void Ability::AddSliceProxy(const uint16_t sliceId, SliceProxy* proxy) @@ -44,6 +47,7 @@ void Ability::AddSliceProxy(const uint16_t sliceId, SliceProxy* proxy) void Ability::StartSlice(uint32_t targetId) { + AbilityNavigationSyncDefaultTarget(defaultTargetId_); if (targetId <= gSliceInvalid) { return; } @@ -163,6 +167,7 @@ void Ability::SwitchSlice(uint16_t sliceId, uint16_t pageId, TransitionType type WEARABLE_LOGE(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "slice %d is not registered", sliceId); return; } + AbilityNavigationSyncDefaultTarget(defaultTargetId_); #ifdef JS_ENABLE ElementName *elementName = OHOS::AbilityMsClient::GetInstance().GetTopAbility(); if (elementName != nullptr && strcmp(elementName->bundleName, "com.huawei.launcher") != 0) { @@ -175,22 +180,7 @@ void Ability::SwitchSlice(uint16_t sliceId, uint16_t pageId, TransitionType type #endif // showsStackSliceId(); - if (sliceId == VIEW_MAIN) - { - ClearSliceIdStack(); /*凡是回到主界面都要清空栈*/ - } - - if (sliceId == VIEW_INCOMING_CALL) - { - uint16_t id=GetCurSliceId(); - if(id==VIEW_REBOOTANDSHUTDOWN && VIEW_INCOMING_CALL==GettopSliceId() ) - { - ClearSliceIdStack(); - } - - if(id!=VIEW_INCOMING_CALL && id!=VIEW_BLUETOOTH_EARPHONE) - make_phone_push(id); - } + AbilityNavigation::NotifySwitchSliceBeforeTransition(this, sliceId); TransitionTarget target; target.sliceInfo = sliceId | (static_cast(pageId) << PAGE_OFFSET); @@ -311,28 +301,4 @@ void Ability::BackToPreSlice() SwitchSlice(sliceId, pageId); } -bool Ability::Back_CountSlice_make_phone(const TransitionType transitionId, - const uint16_t priority ) { - if(!backStack_.empty()) - { - // 如果此时 backStack_ 栈不为空,取出栈顶的切片 ID ,并调用 ChangeSlice 切换到该切片,返回 true 。 - uint16_t preSlice = backStack_.top(); - backStack_.pop(); - - #ifdef CUSTOM_ZHIHUI - if(preSlice!=VIEW_INCOMING_CALL) - ChangeSlice(preSlice); - else - ChangeSlice(defaultTargetId_); - #endif - return true; - } - else - { - //如果 backStack_ 栈为空,切换到默认切片,返回 false 。 - ChangeSlice(defaultTargetId_); - return false; // 返回false表示无前一个slice,退回到默认slice - } - } - } // namespace OHOS diff --git a/code/sdk/application/wearable/fd272/nativeabilityfwk/src/AbilityNavigation.cpp b/code/sdk/application/wearable/fd272/nativeabilityfwk/src/AbilityNavigation.cpp new file mode 100644 index 000000000..b0048e3cd --- /dev/null +++ b/code/sdk/application/wearable/fd272/nativeabilityfwk/src/AbilityNavigation.cpp @@ -0,0 +1,178 @@ +/* + * Copyright (c) CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AbilityNavigationApi.h" + +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "Slice.h" + +#include +#include + +namespace OHOS { + +static uint32_t gMirroredDefaultTargetId = gSliceInvalid; +static std::stack gBackStack; + +void AbilityNavigationSyncDefaultTarget(uint32_t fullTargetId) +{ + gMirroredDefaultTargetId = fullTargetId; +} + +namespace { +inline uint16_t DefaultHomeSliceId(uint32_t targetId) +{ + return static_cast(targetId & SLICE_MASK); +} + +inline NativeAbility& Na() +{ + return NativeAbility::GetInstance(); +} + +inline bool IsNativeSingleton(Ability* p) +{ + return p == static_cast(&NativeAbility::GetInstance()); +} +} // namespace + +namespace AbilityNavigation { + +void EnterSlice(uint16_t sliceId, const TransitionType transitionId, const uint16_t priority, bool enableSlideBack) +{ + uint16_t curSliceId = Na().GetCurSliceId(); + if (curSliceId != DefaultHomeSliceId(gMirroredDefaultTargetId)) { + gBackStack.push(curSliceId); + } + Na().ChangeSlice(sliceId, transitionId, priority, enableSlideBack); +} + +uint16_t GettopSliceId(void) +{ + if (!gBackStack.empty()) { + return gBackStack.top(); + } + return 0; +} + +bool Back(const TransitionType transitionId, const uint16_t priority, bool enableSlideBack) +{ + if (!gBackStack.empty()) { + uint16_t preSlice = gBackStack.top(); + gBackStack.pop(); + Na().ChangeSlice(preSlice, transitionId, priority, enableSlideBack); + return true; + } + const uint16_t home = DefaultHomeSliceId(gMirroredDefaultTargetId); + gBackStack.push(home); + Na().ChangeSlice(home, transitionId, priority, enableSlideBack); + return false; +} + +bool BackCountSlice(int count, const TransitionType transitionId, const uint16_t priority) +{ + while (!gBackStack.empty() && count != 0) { + gBackStack.pop(); + count--; + } + if (!gBackStack.empty()) { + uint16_t preSlice = gBackStack.top(); + Na().ChangeSlice(preSlice, transitionId, priority, false); + gBackStack.pop(); + return true; + } + Na().ChangeSlice(DefaultHomeSliceId(gMirroredDefaultTargetId), transitionId, priority, false); + return false; +} + +bool make_phone_push(uint16_t preSlice) +{ + if (gBackStack.empty()) { + gBackStack.push(preSlice); + } else { + uint16_t topId = gBackStack.top(); + if (topId != preSlice) { + gBackStack.push(preSlice); + } + } + return false; +} + +void ClearSliceIdStack(void) +{ + while (!gBackStack.empty()) { + gBackStack.pop(); + } + if (gBackStack.empty()) { + gBackStack.push(DefaultHomeSliceId(gMirroredDefaultTargetId)); + } +} + +void showsStackSliceId() +{ + printf("\n%u\n", static_cast(gBackStack.size())); + std::stack tempStack = gBackStack; + printf("\n["); + while (!tempStack.empty()) { + printf("%u,", static_cast(tempStack.top())); + tempStack.pop(); + } + printf("]\n"); + printf("\n%u\n", static_cast(gBackStack.size())); +} + +bool Back_CountSlice_make_phone(const TransitionType transitionId, const uint16_t priority) +{ + const uint16_t home = DefaultHomeSliceId(gMirroredDefaultTargetId); + if (!gBackStack.empty()) { + uint16_t preSlice = gBackStack.top(); + gBackStack.pop(); +#ifdef CUSTOM_ZHIHUI + if (preSlice != VIEW_INCOMING_CALL) { + Na().ChangeSlice(preSlice, transitionId, priority, false); + } else { + Na().ChangeSlice(home, transitionId, priority, false); + } +#else + Na().ChangeSlice(preSlice, transitionId, priority, false); +#endif + return true; + } + Na().ChangeSlice(home, transitionId, priority, false); + return false; +} + +void NotifySwitchSliceBeforeTransition(Ability* ability, uint16_t sliceId) +{ + if (!IsNativeSingleton(ability)) { + return; + } + if (sliceId == VIEW_MAIN) { + ClearSliceIdStack(); + } + if (sliceId == VIEW_INCOMING_CALL) { + uint16_t id = Na().GetCurSliceId(); + if (id == VIEW_REBOOTANDSHUTDOWN && VIEW_INCOMING_CALL == GettopSliceId()) { + ClearSliceIdStack(); + } + if (id != VIEW_INCOMING_CALL && id != VIEW_BLUETOOTH_EARPHONE) { + make_phone_push(id); + } + } +} + +} // namespace AbilityNavigation +} // namespace OHOS diff --git a/code/sdk/application/wearable/fd272/nativeabilityfwk/src/AbilitySlice.cpp b/code/sdk/application/wearable/fd272/nativeabilityfwk/src/AbilitySlice.cpp index 25d0c1247..6a0e08759 100644 --- a/code/sdk/application/wearable/fd272/nativeabilityfwk/src/AbilitySlice.cpp +++ b/code/sdk/application/wearable/fd272/nativeabilityfwk/src/AbilitySlice.cpp @@ -14,6 +14,7 @@ #include "View.h" #include "Presenter.h" #include "key/include/KeyInputListener.h" +#include "AppViewIDs.h" namespace OHOS { const uint16_t SLICE_MASK = 0xFFFF; diff --git a/code/sdk/application/wearable/fd272/nativeabilityfwk/src/NativeAbility.cpp b/code/sdk/application/wearable/fd272/nativeabilityfwk/src/NativeAbility.cpp index 0f62c487d..cdbd7bd10 100644 --- a/code/sdk/application/wearable/fd272/nativeabilityfwk/src/NativeAbility.cpp +++ b/code/sdk/application/wearable/fd272/nativeabilityfwk/src/NativeAbility.cpp @@ -14,6 +14,7 @@ */ #include "NativeAbility.h" +#include "AppViewIDs.h" #include "NativeLauncher.h" #include "ability_info.h" #include "ability_state.h" diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/add_card/src/AddCardPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/add_card/src/AddCardPresenter.cpp index cd99156b4..d6c72e969 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/add_card/src/AddCardPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/add_card/src/AddCardPresenter.cpp @@ -14,6 +14,7 @@ #include "key/include/KeyInputListener.h" #include "custom_utils.h" #include "common/key_code.h" +#include "AbilityNavigationApi.h" namespace OHOS { @@ -52,7 +53,7 @@ namespace OHOS (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { // 回退 - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); return true; } return false; @@ -139,7 +140,7 @@ namespace OHOS if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { // 回退 - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/alarm/src/AlarmPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/alarm/src/AlarmPresenter.cpp index 8ca33aed9..64a952042 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/alarm/src/AlarmPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/alarm/src/AlarmPresenter.cpp @@ -1,567 +1,568 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: Alarm - * Author: - * Create: 2021-09-11 - */ - - -// #include "AlarmPresenter.h" -#include "alarm/include/AlarmPresenter.h" -#include "alarm/include/MainAlarmView.h" -#include "NativeRegisterManager.h" -#include "ChangeSliceListener.h" -#include "string" -#include "iostream" -#include "sstream" -#include -#include "uicomponents/UIComponents.h" -namespace OHOS { - -REGIST_MENU_PRO(VIEW_MAIN_ALARM, MainAlarmView, AlarmPresenter, PNG_APPLIST_ALARM_IMAGE_BIG, PNG_APPLIST_ALARM_IMAGE,PNG_APPLIST_ALARM_IMAGE, "闹钟",STR_ALARM); - -static AlarmPresenter *g_pAlarmPresenter = nullptr; - -constexpr int16_t CLOSE_SWITCHES = 0; -constexpr int16_t OPEN_SWITCHES = 1; -constexpr int16_t SET_ZERO = 0; -constexpr uint16_t THE_FIRST_ALARM = 0; -constexpr uint16_t SECOND_ALARM = 1; -constexpr uint16_t THIRD_ALARM = 2; -constexpr uint16_t FOURTH_ALARM = 3; -constexpr uint16_t FIVE_ALARM = 4; -constexpr uint16_t SIX_ALARM = 5; -constexpr uint16_t UNUSED_NUM = 6; -constexpr int16_t FIRST_ALARM = 0; -constexpr uint8_t WEEK_BIT6 = 6; -constexpr uint8_t WEEK_BIT5 = 5; -constexpr uint8_t WEEK_BIT4 = 4; -constexpr uint8_t WEEK_BIT3 = 3; -constexpr uint8_t WEEK_BIT2 = 2; -constexpr uint8_t WEEK_BIT1 = 1; -constexpr uint8_t WEEK_BIT0 = 0; -constexpr uint16_t ALARM_MAX_NUM = 5; // 最大闹钟数 -constexpr int32_t WEEK_BUTTON_MAX_NUM = 7; // 星期按钮的最大个数 -constexpr uint16_t CLOCK_NUM = 5; -constexpr uint8_t CANCEL_DATA = 0; -constexpr uint8_t SELECT_DATA = 1; -constexpr uint8_t SLIDING_LENGTH = 30; - -AlarmPresenter::AlarmPresenter() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter new"); - OHOS::AlarmClockModel::GetInstance()->InitAlarmData(); - g_pAlarmPresenter = this; -} - -AlarmPresenter::~AlarmPresenter() -{ - g_pAlarmPresenter = nullptr; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::~AlarmPresenter"); -} - -ColorType AlarmPresenter::ShadowBlue() -{ - return Color::GetColorFromRGB(0x17, 0x8F, 0xF8); -} - -AlarmPresenter *AlarmPresenter::GetInstance() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter GetInstance"); - return g_pAlarmPresenter; -} - -void AlarmPresenter::OnTimePickerStoped(UITimePicker &picker) -{ - std::string hour(picker.GetSelectHour()); - std::string minute(picker.GetSelectMinute()); - timeHour = stoi(hour); - timeMin = stoi(minute); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::OnTimePickerStoped the hour is %u,and the minute is %u", timeHour, timeMin); -} - -void AlarmPresenter::OnTimePickerInaction(uint32_t hour, uint32_t min) -{ - timeHour = hour; - timeMin = min; -} - -void AlarmPresenter::PlayRing(void *arg) -{ - UNUSED(arg); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainAlarmView::playRing"); -} - -int16_t AlarmPresenter::GetInterStatus(void) -{ - return interListener; -} - -void AlarmPresenter::ClickSetTime(uint16_t num) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter VIEW_ALARM_SET_TIME"); - UNUSED(num); - uint32_t clockTime; - if (!(AlarmClockModel::GetInstance()->GetClockTime(alarmListener, &clockTime))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickSetTime error"); - return; - } - MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_CONFIG, CHANGE_INTERFACE_SET_TIME); - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickSetTime new MainAlarmView::GetInstance() error"); - return; - } - AlarmSetTimeView::GetInstance()->RefreshSetTime(clockTime); - if (AlarmSetTimeView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickSetTime new AlarmSetTimeView::GetInstance() error"); - return; - } -} - -void AlarmPresenter::ClickSetWeek(uint16_t num) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter VIEW_ALARM_SET_WEEK"); - UNUSED(num); - uint8_t clockWeek; - if (!(AlarmClockModel::GetInstance()->GetClockWeek(alarmListener, &clockWeek))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickSetWeek error"); - return; - } - interListener = SET_TIME_LISTENER; - MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_CONFIG, CHANGE_INTERFACE_SET_WEEK); - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickSetWeek new MainAlarmView::GetInstance() error"); - return; - } - memset_s(alarmWeek, sizeof(alarmWeek), 0, sizeof(alarmWeek)); - AlarmSetWeekView::GetInstance()->RefreshSetWeek1(); - if (AlarmSetWeekView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickSetWeek new AlarmSetWeekView::GetInstance() error"); - return; - } - AlarmSetWeekView::GetInstance()->RefreshSetWeek2(clockWeek); -} - -void AlarmPresenter::ClickAlarmClockDelete(uint16_t num) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmClockDelete"); - UNUSED(num); - MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_CONFIG, CHANGE_INTERFACE_JUDGE); - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmClockDelete new MainAlarmView::GetInstance() error"); - return; - } -} - -void AlarmPresenter::ClickJudgeDelete(uint16_t num) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter JUDGE_DELETE"); - UNUSED(num); - MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_JUDGE, MAIN_INTERFACE); - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickJudgeDelete new MainAlarmView::GetInstance() error"); - return; - } -} - -void AlarmPresenter::ClickJudgeTrue(uint16_t num) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter JUDGE_DELETE"); - UNUSED(num); - uint32_t clockTime; - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:%d,%d", __LINE__, alarmListener, clockQty); - AlarmClockModel::GetInstance()->DeleteClockModel(alarmListener); - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickJudgeTrue new MainAlarmView::GetInstance() error"); - return; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "clockQty = %d", clockQty); - clockQty--; - AlarmClockModel::GetInstance()->SetSerialRdc(); - MainAlarmView::GetInstance()->RefreshAlarm(); - // MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_JUDGE, MAIN_INTERFACE); - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_ALARM); - - - - // MainAlarmView::GetInstance()->RefreshAlarm(); - // clockQty--; - // for (uint16_t alarmNum = 0; alarmNum < clockQty; alarmNum++) { - // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:%d", __LINE__, alarmNum); - - // if (!(AlarmClockModel::GetInstance()->GetClockTime(alarmNum, &clockTime))) { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickJudgeTrue error"); - // return; - // } - // MainAlarmView::GetInstance()->RefreshAlarm(); - // } - // AlarmClockModel::GetInstance()->SetSerialRdc(); - // MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_JUDGE, MAIN_INTERFACE); -} - -void AlarmPresenter::ClickAlarmTimeOk(uint16_t num) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ALARM_OK"); - UNUSED(num); - AlarmClockModel::GetInstance()->SetAlarmTime(timeHour, timeMin, alarmListener); - uint32_t clockTime = ((timeHour << 16) | timeMin); // 闹钟时间小时的存储位需要右移16位 - uint8_t clockWeek; - if (!(AlarmClockModel::GetInstance()->GetClockWeek(alarmListener, &clockWeek))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmTimeOk error"); - return; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter time = %u", clockTime); - AlarmClockModel::GetInstance()->DelAlarmDelay(alarmListener); - - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmTimeOk new MainAlarmView::GetInstance() error"); - return; - } - AlarmClockModel::GetInstance()->ButtonStatusRing(alarmListener, true); - MainAlarmView::GetInstance()->RefreshAlarm(); - if (AlarmConfigView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmTimeOk new AlarmConfigView::GetInstance() error"); - return; - } - AlarmConfigView::GetInstance()->RefreshConfig(clockTime, clockWeek, UNUSED_NUM); - MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_SET_TIME, CHANGE_INTERFACE_CONFIG); -} - -void AlarmPresenter::ClickAlarmClock(uint16_t num) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter AlarmClock1"); - clockQty = AlarmClockModel::GetInstance()->GetAlarmNum(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "------AlarmPresenter alarmNumbel = %u", clockQty); - setListener = SET_TIME_LISTENER; - alarmListener = num; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter alarmListener = %u", alarmListener); - uint32_t clockTime; - uint8_t clockWeek; - if (!(AlarmClockModel::GetInstance()->GetClockTime(alarmListener, &clockTime))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmClock error"); - return; - } - if (!(AlarmClockModel::GetInstance()->GetClockWeek(alarmListener, &clockWeek))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmClock error"); - return; - } - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmClock new MainAlarmView::GetInstance() error"); - return; - } - MainAlarmView::GetInstance()->ChangeView(MAIN_INTERFACE, CHANGE_INTERFACE_CONFIG); - if (AlarmConfigView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmClock new AlarmConfigView::GetInstance() error"); - return; - } - AlarmConfigView::GetInstance()->RefreshConfig(clockTime, clockWeek, num); -} - -// 处理闹钟星期设置确认按钮的点击事件 -void AlarmPresenter::ClickAlarmWeekOk(uint16_t num) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ALARM_WEEK_OK"); - UNUSED(num); - uint32_t clockTime; - uint8_t clockWeek = ((alarmWeek[WEEK_BIT6] << WEEK_BIT6) | (alarmWeek[WEEK_BIT5] << WEEK_BIT5) | (alarmWeek[WEEK_BIT4] << WEEK_BIT4) | - (alarmWeek[WEEK_BIT3] << WEEK_BIT3) | (alarmWeek[WEEK_BIT2] << WEEK_BIT2) | (alarmWeek[WEEK_BIT1] << WEEK_BIT1) | alarmWeek[WEEK_BIT0]); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk setListener = %u!", setListener); - - if (setListener == SET_TIME_LISTENER) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk set time!"); - if (!(AlarmClockModel::GetInstance()->GetClockTime(alarmListener, &clockTime))) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmWeekOk error"); - return; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk time = %d", clockTime); - AlarmClockModel::GetInstance()->SetAlarmWeek(clockWeek, alarmListener); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk week = %u", clockWeek); - AlarmConfigView::GetInstance()->RefreshConfig(clockTime, clockWeek, UNUSED_NUM); - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmWeekOk new MainAlarmView::GetInstance() error"); - return; - } - AlarmClockModel::GetInstance()->ButtonStatusRing(alarmListener, true); - MainAlarmView::GetInstance()->RefreshAlarm(); - MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_SET_WEEK, CHANGE_INTERFACE_CONFIG); // 跳转到闹钟配置界面 - } else if (setListener == NEW_TIME_LISTENER) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk new time!"); - alarmListener = clockQty; - clockQty++; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "******************ClickAlarmWeekOk alarmListener = %d***************", alarmListener); - AlarmClockModel::GetInstance()->SetSerialAdd(); - AlarmClockModel::GetInstance()->SetAlarmInfo(timeHour, timeMin, clockWeek, alarmListener, setListener); - if (!(AlarmClockModel::GetInstance()->GetClockTime(alarmListener, &clockTime))) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmWeekOk error"); - return; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk time = %d", clockTime); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk week = %u", clockWeek); - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmWeekOk new MainAlarmView::GetInstance() error"); - return; - } - MainAlarmView::GetInstance()->RefreshAlarm(); - MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_SET_WEEK, MAIN_INTERFACE); // 跳转到闹钟主界面 - } -} - -// 处理闹钟新建按钮的点击事件 -void AlarmPresenter::ClickAlarmNewTime(uint16_t num) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ALARM_NEW_TIME"); - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNewTime new MainAlarmView::GetInstance() error"); - return; - } - clockQty = AlarmClockModel::GetInstance()->GetAlarmNum(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter alarmNumbel = %u", clockQty); - UNUSED(num); - if (clockQty >= ALARM_MAX_NUM) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter new alarm max"); - MainAlarmView::GetInstance()->ChangeView(MAIN_INTERFACE, CHANGE_INTERFACE_MAXCLOCK); - return; - } - setListener = NEW_TIME_LISTENER; - timeHour = 0; - timeMin = 0; - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNewTime new MainAlarmView::GetInstance() error"); - return; - } - MainAlarmView::GetInstance()->ChangeView(MAIN_INTERFACE, CHANGE_INTERFACE_NEW_TIME); - if (AlarmNewTimeView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNewTime new AlarmNewTimeView::GetInstance() error"); - return; - } - AlarmNewTimeView::GetInstance()->RefreshNewTime(); -} - -// 新建闹钟时:时间设置页面的下一步按钮点击事件处理函数 - -void AlarmPresenter::ClickAlarmNext(uint16_t num) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ALARM_NEXT"); - UNUSED(num); - for (int i = 0; i < WEEK_BUTTON_MAX_NUM; i++) { - alarmWeek[i] = 0; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "alarmWeek[%d] = %u", i, alarmWeek[i]); - } - interListener = NEW_TIME_LISTENER; - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNext new MainAlarmView::GetInstance() error"); - return; - } - MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_NEW_TIME, CHANGE_INTERFACE_SET_WEEK);// 跳转到星期设置界面 - if (AlarmNewTimeView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNext new AlarmNewTimeView::GetInstance() error"); - return; - } - if (AlarmSetWeekView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNext new AlarmSetWeekView::GetInstance() error"); - return; - } - AlarmSetWeekView::GetInstance()->RefreshSetWeek1(); -} - -void AlarmPresenter::OnResume() -{ - RootView::GetInstance()->SetOnKeyActListener(this); -} - -bool AlarmPresenter::OnDrag(UIView& view, const DragEvent& event) -{ - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - int16_t deltaX; - int16_t deltaY; - deltaX = event.GetDeltaX(); - deltaY = event.GetDeltaY(); - if (MATH_ABS(deltaX) >= MATH_ABS(deltaY) && MATH_ABS(deltaX) > SLIDING_LENGTH) { - // MainAlarmView::GetInstance()->DropView(view); - X_DRAG_FLAG = true; - } - } - return true; -} - -bool AlarmPresenter::OnDragEnd(UIView& view, const DragEvent& event) -{ - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnDragEnd %p",&view); - MainAlarmView::GetInstance()->DropView(view); - X_DRAG_FLAG = false; - } - return true; -} - -struct AlarmPresentMapper1 { - const char *viewId; - void (AlarmPresenter::*func)(uint16_t); -}; - -static const AlarmPresentMapper1 PresentMapper[] = { - {SET_TIME, &AlarmPresenter::ClickSetTime}, - {SET_WEEK, &AlarmPresenter::ClickSetWeek}, - {ALARM_CLOCK_DELETE, &AlarmPresenter::ClickAlarmClockDelete}, - {JUDGE_DELETE, &AlarmPresenter::ClickJudgeDelete}, - {JUDGE_TRUE, &AlarmPresenter::ClickJudgeTrue}, - {ALARM_OK, &AlarmPresenter::ClickAlarmTimeOk}, - {ADD_BUTTON, &AlarmPresenter::ClickAlarmNewTime}, - {ALARM_NEXT, &AlarmPresenter::ClickAlarmNext}, - {ALARM_WEEK_OK, &AlarmPresenter::ClickAlarmWeekOk}, - {ALARM_CLOCK[THE_FIRST_ALARM], &AlarmPresenter::ClickAlarmClock}, - {ALARM_CLOCK[SECOND_ALARM], &AlarmPresenter::ClickAlarmClock}, - {ALARM_CLOCK[THIRD_ALARM], &AlarmPresenter::ClickAlarmClock}, - {ALARM_CLOCK[FOURTH_ALARM], &AlarmPresenter::ClickAlarmClock}, - {ALARM_CLOCK[FIVE_ALARM], &AlarmPresenter::ClickAlarmClock}, - {ALARM_CLOCK[SIX_ALARM], &AlarmPresenter::ClickAlarmClock}, -}; - -bool AlarmPresenter::ClickFuncId(const char *buttonName) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonName = %s", buttonName); - uint16_t num; - for (uint16_t i = 0; i < sizeof(PresentMapper) / sizeof(PresentMapper[0]); i++) { - for (num = 0; num < CLOCK_NUM; num++) { - if (strcmp(buttonName, ALARM_CLOCK[num]) == 0) { - break; - } - } - if (strcmp(buttonName, PresentMapper[i].viewId) == 0) { - (this->*(PresentMapper[i].func))(num); - return true; - } - } - return false; -} - -bool AlarmPresenter::ClickFuncView(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickFuncView view = %s", view.GetViewId()); - for (int num = 0; num < WEEK_BUTTON_MAX_NUM; num++) { - if (strcmp(view.GetViewId(), WEEK_BUTTON_VIEWID[num]) == 0) { - alarmWeek[num] = alarmWeek[num] ? CANCEL_DATA: SELECT_DATA; - if (alarmWeek[num] == CANCEL_DATA) { // 取消选中 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "alarmWeek[num] = %u", alarmWeek[num]); - view.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x19, 0x19, 0x19).full); - dynamic_cast(view).SetStyleForState(STYLE_BACKGROUND_COLOR, - Color::GetColorFromRGB(0x19, 0x19, 0x19).full, UIButton::PRESSED); - } else if (alarmWeek[num] == SELECT_DATA) { // 选中 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "alarmWeek[num] = %u", alarmWeek[num]); - view.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x0d, 0x62, 0xff).full); - dynamic_cast(view).SetStyleForState(STYLE_BACKGROUND_COLOR, - Color::GetColorFromRGB(0x4f, 0xc3, 0x4c).full, UIButton::PRESSED); - } - } - } - view.Invalidate(); - return true; -} - -bool AlarmPresenter::OnKeyAct(UIView &view, const KeyEvent &event) -{ - UNUSED(view); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::OnKeyAct"); - uint16_t keyID = event.GetKeyId(); - uint16_t keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; -} - -void AlarmPresenter::ClickDeleteButtonAlarmClockDelete(uint16_t num) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:%d", __LINE__, num); - if (MainAlarmView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickDeleteButtonAlarmClockDelete error"); - return; - } - UNUSED(num); - alarmListener = num; - MainAlarmView::GetInstance()->ChangeView(MAIN_INTERFACE, CHANGE_INTERFACE_JUDGE); -} - -static const AlarmPresentMapper1 DeleteButtonPresentMapper[] = -{ - {ALARM_ITEM_DELETE[THE_FIRST_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, - {ALARM_ITEM_DELETE[SECOND_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, - {ALARM_ITEM_DELETE[THIRD_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, - {ALARM_ITEM_DELETE[FOURTH_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, - {ALARM_ITEM_DELETE[FIVE_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, - {ALARM_ITEM_DELETE[SIX_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, -}; - -bool AlarmPresenter::OnClick(UIView &view, const ClickEvent &event) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::OnClick "); - - uint16_t num; - for (num = 0; num < CLOCK_NUM; num++) - { - if (0 == strcmp(view.GetViewId(), ALARM_ITEM_DELETE[num])) // 闹钟删除按钮 - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:%d", __LINE__, num); - (this->*(DeleteButtonPresentMapper[num].func))(num); - return true; - } - } - - bool jug = ClickFuncId(view.GetViewId()); - if (!jug) { - ClickFuncView(view); - } - return true; -} - -bool AlarmStatusBtnChangeListener::OnChange(UICheckBox::UICheckBoxState state) -{ - if (MainAlarmView::GetInstance()->GetRefreshStatus()) { - return true; - } - switch (state) { - case UICheckBox::SELECTED: - AlarmClockModel::GetInstance()->ButtonStatusRing(alarmStatusNum, true); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmStatusBtnChangeListener::OnChange true"); - break; - - case UICheckBox::UNSELECTED: - AlarmClockModel::GetInstance()->ButtonStatusRing(alarmStatusNum, false); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmStatusBtnChangeListener::OnChange false"); - break; - default: - break; - } - return true; -} - -void AlarmPresenter::OnSwipe(UISwipeView &view) -{ - UNUSED(view); - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::OnSwipe "); - view.SetIntercept((0 == view.GetCurrentPage()) ? false : true); -} - -void AlarmPresenter::UpdateAlarmInfoByAppSet(void) -{ - NativeAbility::GetInstance().Back(); -} - -void AlarmPresenter::RefreshAlarmStatus(int i) -{ - uint8_t alarmEnable = 0; - bool alarmStatus; - alarmStatus = AlarmClockModel::GetInstance()->GetClockStatus(i, &alarmEnable); - if (!alarmStatus) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter:: GetClockStatus fail! i = %d", i); - } - if( MainAlarmView::GetInstance()) - { - MainAlarmView::GetInstance()->RefreshAlarmStatus(alarmEnable, i); - } -} +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: Alarm + * Author: + * Create: 2021-09-11 + */ + + +// #include "AlarmPresenter.h" +#include "alarm/include/AlarmPresenter.h" +#include "alarm/include/MainAlarmView.h" +#include "NativeRegisterManager.h" +#include "ChangeSliceListener.h" +#include "string" +#include "iostream" +#include "sstream" +#include +#include "uicomponents/UIComponents.h" +#include "AbilityNavigationApi.h" +namespace OHOS { + +REGIST_MENU_PRO(VIEW_MAIN_ALARM, MainAlarmView, AlarmPresenter, PNG_APPLIST_ALARM_IMAGE_BIG, PNG_APPLIST_ALARM_IMAGE,PNG_APPLIST_ALARM_IMAGE, "闹钟",STR_ALARM); + +static AlarmPresenter *g_pAlarmPresenter = nullptr; + +constexpr int16_t CLOSE_SWITCHES = 0; +constexpr int16_t OPEN_SWITCHES = 1; +constexpr int16_t SET_ZERO = 0; +constexpr uint16_t THE_FIRST_ALARM = 0; +constexpr uint16_t SECOND_ALARM = 1; +constexpr uint16_t THIRD_ALARM = 2; +constexpr uint16_t FOURTH_ALARM = 3; +constexpr uint16_t FIVE_ALARM = 4; +constexpr uint16_t SIX_ALARM = 5; +constexpr uint16_t UNUSED_NUM = 6; +constexpr int16_t FIRST_ALARM = 0; +constexpr uint8_t WEEK_BIT6 = 6; +constexpr uint8_t WEEK_BIT5 = 5; +constexpr uint8_t WEEK_BIT4 = 4; +constexpr uint8_t WEEK_BIT3 = 3; +constexpr uint8_t WEEK_BIT2 = 2; +constexpr uint8_t WEEK_BIT1 = 1; +constexpr uint8_t WEEK_BIT0 = 0; +constexpr uint16_t ALARM_MAX_NUM = 5; // 最大闹钟数 +constexpr int32_t WEEK_BUTTON_MAX_NUM = 7; // 星期按钮的最大个数 +constexpr uint16_t CLOCK_NUM = 5; +constexpr uint8_t CANCEL_DATA = 0; +constexpr uint8_t SELECT_DATA = 1; +constexpr uint8_t SLIDING_LENGTH = 30; + +AlarmPresenter::AlarmPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter new"); + OHOS::AlarmClockModel::GetInstance()->InitAlarmData(); + g_pAlarmPresenter = this; +} + +AlarmPresenter::~AlarmPresenter() +{ + g_pAlarmPresenter = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::~AlarmPresenter"); +} + +ColorType AlarmPresenter::ShadowBlue() +{ + return Color::GetColorFromRGB(0x17, 0x8F, 0xF8); +} + +AlarmPresenter *AlarmPresenter::GetInstance() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter GetInstance"); + return g_pAlarmPresenter; +} + +void AlarmPresenter::OnTimePickerStoped(UITimePicker &picker) +{ + std::string hour(picker.GetSelectHour()); + std::string minute(picker.GetSelectMinute()); + timeHour = stoi(hour); + timeMin = stoi(minute); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::OnTimePickerStoped the hour is %u,and the minute is %u", timeHour, timeMin); +} + +void AlarmPresenter::OnTimePickerInaction(uint32_t hour, uint32_t min) +{ + timeHour = hour; + timeMin = min; +} + +void AlarmPresenter::PlayRing(void *arg) +{ + UNUSED(arg); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainAlarmView::playRing"); +} + +int16_t AlarmPresenter::GetInterStatus(void) +{ + return interListener; +} + +void AlarmPresenter::ClickSetTime(uint16_t num) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter VIEW_ALARM_SET_TIME"); + UNUSED(num); + uint32_t clockTime; + if (!(AlarmClockModel::GetInstance()->GetClockTime(alarmListener, &clockTime))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickSetTime error"); + return; + } + MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_CONFIG, CHANGE_INTERFACE_SET_TIME); + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickSetTime new MainAlarmView::GetInstance() error"); + return; + } + AlarmSetTimeView::GetInstance()->RefreshSetTime(clockTime); + if (AlarmSetTimeView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickSetTime new AlarmSetTimeView::GetInstance() error"); + return; + } +} + +void AlarmPresenter::ClickSetWeek(uint16_t num) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter VIEW_ALARM_SET_WEEK"); + UNUSED(num); + uint8_t clockWeek; + if (!(AlarmClockModel::GetInstance()->GetClockWeek(alarmListener, &clockWeek))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickSetWeek error"); + return; + } + interListener = SET_TIME_LISTENER; + MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_CONFIG, CHANGE_INTERFACE_SET_WEEK); + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickSetWeek new MainAlarmView::GetInstance() error"); + return; + } + memset_s(alarmWeek, sizeof(alarmWeek), 0, sizeof(alarmWeek)); + AlarmSetWeekView::GetInstance()->RefreshSetWeek1(); + if (AlarmSetWeekView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickSetWeek new AlarmSetWeekView::GetInstance() error"); + return; + } + AlarmSetWeekView::GetInstance()->RefreshSetWeek2(clockWeek); +} + +void AlarmPresenter::ClickAlarmClockDelete(uint16_t num) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmClockDelete"); + UNUSED(num); + MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_CONFIG, CHANGE_INTERFACE_JUDGE); + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmClockDelete new MainAlarmView::GetInstance() error"); + return; + } +} + +void AlarmPresenter::ClickJudgeDelete(uint16_t num) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter JUDGE_DELETE"); + UNUSED(num); + MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_JUDGE, MAIN_INTERFACE); + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickJudgeDelete new MainAlarmView::GetInstance() error"); + return; + } +} + +void AlarmPresenter::ClickJudgeTrue(uint16_t num) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter JUDGE_DELETE"); + UNUSED(num); + uint32_t clockTime; + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:%d,%d", __LINE__, alarmListener, clockQty); + AlarmClockModel::GetInstance()->DeleteClockModel(alarmListener); + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickJudgeTrue new MainAlarmView::GetInstance() error"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "clockQty = %d", clockQty); + clockQty--; + AlarmClockModel::GetInstance()->SetSerialRdc(); + MainAlarmView::GetInstance()->RefreshAlarm(); + // MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_JUDGE, MAIN_INTERFACE); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_ALARM); + + + + // MainAlarmView::GetInstance()->RefreshAlarm(); + // clockQty--; + // for (uint16_t alarmNum = 0; alarmNum < clockQty; alarmNum++) { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:%d", __LINE__, alarmNum); + + // if (!(AlarmClockModel::GetInstance()->GetClockTime(alarmNum, &clockTime))) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickJudgeTrue error"); + // return; + // } + // MainAlarmView::GetInstance()->RefreshAlarm(); + // } + // AlarmClockModel::GetInstance()->SetSerialRdc(); + // MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_JUDGE, MAIN_INTERFACE); +} + +void AlarmPresenter::ClickAlarmTimeOk(uint16_t num) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ALARM_OK"); + UNUSED(num); + AlarmClockModel::GetInstance()->SetAlarmTime(timeHour, timeMin, alarmListener); + uint32_t clockTime = ((timeHour << 16) | timeMin); // 闹钟时间小时的存储位需要右移16位 + uint8_t clockWeek; + if (!(AlarmClockModel::GetInstance()->GetClockWeek(alarmListener, &clockWeek))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmTimeOk error"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter time = %u", clockTime); + AlarmClockModel::GetInstance()->DelAlarmDelay(alarmListener); + + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmTimeOk new MainAlarmView::GetInstance() error"); + return; + } + AlarmClockModel::GetInstance()->ButtonStatusRing(alarmListener, true); + MainAlarmView::GetInstance()->RefreshAlarm(); + if (AlarmConfigView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmTimeOk new AlarmConfigView::GetInstance() error"); + return; + } + AlarmConfigView::GetInstance()->RefreshConfig(clockTime, clockWeek, UNUSED_NUM); + MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_SET_TIME, CHANGE_INTERFACE_CONFIG); +} + +void AlarmPresenter::ClickAlarmClock(uint16_t num) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter AlarmClock1"); + clockQty = AlarmClockModel::GetInstance()->GetAlarmNum(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "------AlarmPresenter alarmNumbel = %u", clockQty); + setListener = SET_TIME_LISTENER; + alarmListener = num; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter alarmListener = %u", alarmListener); + uint32_t clockTime; + uint8_t clockWeek; + if (!(AlarmClockModel::GetInstance()->GetClockTime(alarmListener, &clockTime))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmClock error"); + return; + } + if (!(AlarmClockModel::GetInstance()->GetClockWeek(alarmListener, &clockWeek))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmClock error"); + return; + } + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmClock new MainAlarmView::GetInstance() error"); + return; + } + MainAlarmView::GetInstance()->ChangeView(MAIN_INTERFACE, CHANGE_INTERFACE_CONFIG); + if (AlarmConfigView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmClock new AlarmConfigView::GetInstance() error"); + return; + } + AlarmConfigView::GetInstance()->RefreshConfig(clockTime, clockWeek, num); +} + +// 处理闹钟星期设置确认按钮的点击事件 +void AlarmPresenter::ClickAlarmWeekOk(uint16_t num) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ALARM_WEEK_OK"); + UNUSED(num); + uint32_t clockTime; + uint8_t clockWeek = ((alarmWeek[WEEK_BIT6] << WEEK_BIT6) | (alarmWeek[WEEK_BIT5] << WEEK_BIT5) | (alarmWeek[WEEK_BIT4] << WEEK_BIT4) | + (alarmWeek[WEEK_BIT3] << WEEK_BIT3) | (alarmWeek[WEEK_BIT2] << WEEK_BIT2) | (alarmWeek[WEEK_BIT1] << WEEK_BIT1) | alarmWeek[WEEK_BIT0]); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk setListener = %u!", setListener); + + if (setListener == SET_TIME_LISTENER) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk set time!"); + if (!(AlarmClockModel::GetInstance()->GetClockTime(alarmListener, &clockTime))) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmWeekOk error"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk time = %d", clockTime); + AlarmClockModel::GetInstance()->SetAlarmWeek(clockWeek, alarmListener); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk week = %u", clockWeek); + AlarmConfigView::GetInstance()->RefreshConfig(clockTime, clockWeek, UNUSED_NUM); + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmWeekOk new MainAlarmView::GetInstance() error"); + return; + } + AlarmClockModel::GetInstance()->ButtonStatusRing(alarmListener, true); + MainAlarmView::GetInstance()->RefreshAlarm(); + MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_SET_WEEK, CHANGE_INTERFACE_CONFIG); // 跳转到闹钟配置界面 + } else if (setListener == NEW_TIME_LISTENER) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk new time!"); + alarmListener = clockQty; + clockQty++; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "******************ClickAlarmWeekOk alarmListener = %d***************", alarmListener); + AlarmClockModel::GetInstance()->SetSerialAdd(); + AlarmClockModel::GetInstance()->SetAlarmInfo(timeHour, timeMin, clockWeek, alarmListener, setListener); + if (!(AlarmClockModel::GetInstance()->GetClockTime(alarmListener, &clockTime))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ClickAlarmWeekOk error"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk time = %d", clockTime); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickAlarmWeekOk week = %u", clockWeek); + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmWeekOk new MainAlarmView::GetInstance() error"); + return; + } + MainAlarmView::GetInstance()->RefreshAlarm(); + MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_SET_WEEK, MAIN_INTERFACE); // 跳转到闹钟主界面 + } +} + +// 处理闹钟新建按钮的点击事件 +void AlarmPresenter::ClickAlarmNewTime(uint16_t num) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ALARM_NEW_TIME"); + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNewTime new MainAlarmView::GetInstance() error"); + return; + } + clockQty = AlarmClockModel::GetInstance()->GetAlarmNum(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter alarmNumbel = %u", clockQty); + UNUSED(num); + if (clockQty >= ALARM_MAX_NUM) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter new alarm max"); + MainAlarmView::GetInstance()->ChangeView(MAIN_INTERFACE, CHANGE_INTERFACE_MAXCLOCK); + return; + } + setListener = NEW_TIME_LISTENER; + timeHour = 0; + timeMin = 0; + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNewTime new MainAlarmView::GetInstance() error"); + return; + } + MainAlarmView::GetInstance()->ChangeView(MAIN_INTERFACE, CHANGE_INTERFACE_NEW_TIME); + if (AlarmNewTimeView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNewTime new AlarmNewTimeView::GetInstance() error"); + return; + } + AlarmNewTimeView::GetInstance()->RefreshNewTime(); +} + +// 新建闹钟时:时间设置页面的下一步按钮点击事件处理函数 + +void AlarmPresenter::ClickAlarmNext(uint16_t num) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter ALARM_NEXT"); + UNUSED(num); + for (int i = 0; i < WEEK_BUTTON_MAX_NUM; i++) { + alarmWeek[i] = 0; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "alarmWeek[%d] = %u", i, alarmWeek[i]); + } + interListener = NEW_TIME_LISTENER; + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNext new MainAlarmView::GetInstance() error"); + return; + } + MainAlarmView::GetInstance()->ChangeView(CHANGE_INTERFACE_NEW_TIME, CHANGE_INTERFACE_SET_WEEK);// 跳转到星期设置界面 + if (AlarmNewTimeView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNext new AlarmNewTimeView::GetInstance() error"); + return; + } + if (AlarmSetWeekView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickAlarmNext new AlarmSetWeekView::GetInstance() error"); + return; + } + AlarmSetWeekView::GetInstance()->RefreshSetWeek1(); +} + +void AlarmPresenter::OnResume() +{ + RootView::GetInstance()->SetOnKeyActListener(this); +} + +bool AlarmPresenter::OnDrag(UIView& view, const DragEvent& event) +{ + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + int16_t deltaX; + int16_t deltaY; + deltaX = event.GetDeltaX(); + deltaY = event.GetDeltaY(); + if (MATH_ABS(deltaX) >= MATH_ABS(deltaY) && MATH_ABS(deltaX) > SLIDING_LENGTH) { + // MainAlarmView::GetInstance()->DropView(view); + X_DRAG_FLAG = true; + } + } + return true; +} + +bool AlarmPresenter::OnDragEnd(UIView& view, const DragEvent& event) +{ + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnDragEnd %p",&view); + MainAlarmView::GetInstance()->DropView(view); + X_DRAG_FLAG = false; + } + return true; +} + +struct AlarmPresentMapper1 { + const char *viewId; + void (AlarmPresenter::*func)(uint16_t); +}; + +static const AlarmPresentMapper1 PresentMapper[] = { + {SET_TIME, &AlarmPresenter::ClickSetTime}, + {SET_WEEK, &AlarmPresenter::ClickSetWeek}, + {ALARM_CLOCK_DELETE, &AlarmPresenter::ClickAlarmClockDelete}, + {JUDGE_DELETE, &AlarmPresenter::ClickJudgeDelete}, + {JUDGE_TRUE, &AlarmPresenter::ClickJudgeTrue}, + {ALARM_OK, &AlarmPresenter::ClickAlarmTimeOk}, + {ADD_BUTTON, &AlarmPresenter::ClickAlarmNewTime}, + {ALARM_NEXT, &AlarmPresenter::ClickAlarmNext}, + {ALARM_WEEK_OK, &AlarmPresenter::ClickAlarmWeekOk}, + {ALARM_CLOCK[THE_FIRST_ALARM], &AlarmPresenter::ClickAlarmClock}, + {ALARM_CLOCK[SECOND_ALARM], &AlarmPresenter::ClickAlarmClock}, + {ALARM_CLOCK[THIRD_ALARM], &AlarmPresenter::ClickAlarmClock}, + {ALARM_CLOCK[FOURTH_ALARM], &AlarmPresenter::ClickAlarmClock}, + {ALARM_CLOCK[FIVE_ALARM], &AlarmPresenter::ClickAlarmClock}, + {ALARM_CLOCK[SIX_ALARM], &AlarmPresenter::ClickAlarmClock}, +}; + +bool AlarmPresenter::ClickFuncId(const char *buttonName) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonName = %s", buttonName); + uint16_t num; + for (uint16_t i = 0; i < sizeof(PresentMapper) / sizeof(PresentMapper[0]); i++) { + for (num = 0; num < CLOCK_NUM; num++) { + if (strcmp(buttonName, ALARM_CLOCK[num]) == 0) { + break; + } + } + if (strcmp(buttonName, PresentMapper[i].viewId) == 0) { + (this->*(PresentMapper[i].func))(num); + return true; + } + } + return false; +} + +bool AlarmPresenter::ClickFuncView(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickFuncView view = %s", view.GetViewId()); + for (int num = 0; num < WEEK_BUTTON_MAX_NUM; num++) { + if (strcmp(view.GetViewId(), WEEK_BUTTON_VIEWID[num]) == 0) { + alarmWeek[num] = alarmWeek[num] ? CANCEL_DATA: SELECT_DATA; + if (alarmWeek[num] == CANCEL_DATA) { // 取消选中 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "alarmWeek[num] = %u", alarmWeek[num]); + view.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x19, 0x19, 0x19).full); + dynamic_cast(view).SetStyleForState(STYLE_BACKGROUND_COLOR, + Color::GetColorFromRGB(0x19, 0x19, 0x19).full, UIButton::PRESSED); + } else if (alarmWeek[num] == SELECT_DATA) { // 选中 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "alarmWeek[num] = %u", alarmWeek[num]); + view.SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x0d, 0x62, 0xff).full); + dynamic_cast(view).SetStyleForState(STYLE_BACKGROUND_COLOR, + Color::GetColorFromRGB(0x4f, 0xc3, 0x4c).full, UIButton::PRESSED); + } + } + } + view.Invalidate(); + return true; +} + +bool AlarmPresenter::OnKeyAct(UIView &view, const KeyEvent &event) +{ + UNUSED(view); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::OnKeyAct"); + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; +} + +void AlarmPresenter::ClickDeleteButtonAlarmClockDelete(uint16_t num) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:%d", __LINE__, num); + if (MainAlarmView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::ClickDeleteButtonAlarmClockDelete error"); + return; + } + UNUSED(num); + alarmListener = num; + MainAlarmView::GetInstance()->ChangeView(MAIN_INTERFACE, CHANGE_INTERFACE_JUDGE); +} + +static const AlarmPresentMapper1 DeleteButtonPresentMapper[] = +{ + {ALARM_ITEM_DELETE[THE_FIRST_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, + {ALARM_ITEM_DELETE[SECOND_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, + {ALARM_ITEM_DELETE[THIRD_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, + {ALARM_ITEM_DELETE[FOURTH_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, + {ALARM_ITEM_DELETE[FIVE_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, + {ALARM_ITEM_DELETE[SIX_ALARM], &AlarmPresenter::ClickDeleteButtonAlarmClockDelete}, +}; + +bool AlarmPresenter::OnClick(UIView &view, const ClickEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::OnClick "); + + uint16_t num; + for (num = 0; num < CLOCK_NUM; num++) + { + if (0 == strcmp(view.GetViewId(), ALARM_ITEM_DELETE[num])) // 闹钟删除按钮 + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:%d", __LINE__, num); + (this->*(DeleteButtonPresentMapper[num].func))(num); + return true; + } + } + + bool jug = ClickFuncId(view.GetViewId()); + if (!jug) { + ClickFuncView(view); + } + return true; +} + +bool AlarmStatusBtnChangeListener::OnChange(UICheckBox::UICheckBoxState state) +{ + if (MainAlarmView::GetInstance()->GetRefreshStatus()) { + return true; + } + switch (state) { + case UICheckBox::SELECTED: + AlarmClockModel::GetInstance()->ButtonStatusRing(alarmStatusNum, true); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmStatusBtnChangeListener::OnChange true"); + break; + + case UICheckBox::UNSELECTED: + AlarmClockModel::GetInstance()->ButtonStatusRing(alarmStatusNum, false); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmStatusBtnChangeListener::OnChange false"); + break; + default: + break; + } + return true; +} + +void AlarmPresenter::OnSwipe(UISwipeView &view) +{ + UNUSED(view); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter::OnSwipe "); + view.SetIntercept((0 == view.GetCurrentPage()) ? false : true); +} + +void AlarmPresenter::UpdateAlarmInfoByAppSet(void) +{ + OHOS::AbilityNavigation::Back(); +} + +void AlarmPresenter::RefreshAlarmStatus(int i) +{ + uint8_t alarmEnable = 0; + bool alarmStatus; + alarmStatus = AlarmClockModel::GetInstance()->GetClockStatus(i, &alarmEnable); + if (!alarmStatus) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmPresenter:: GetClockStatus fail! i = %d", i); + } + if( MainAlarmView::GetInstance()) + { + MainAlarmView::GetInstance()->RefreshAlarmStatus(alarmEnable, i); + } +} } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/alarm/src/MainAlarmView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/alarm/src/MainAlarmView.cpp index ff64b327e..d3acda604 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/alarm/src/MainAlarmView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/alarm/src/MainAlarmView.cpp @@ -12,6 +12,7 @@ #include "ui_resource_string.h" #include "ConfigModel.h" #include "languagecode/LanguageInit.h" +#include "AbilityNavigationApi.h" namespace OHOS { static MainAlarmView *g_MainAlarmView = nullptr; @@ -712,7 +713,7 @@ void MainAlarmView::DropView(UIView& view) // CancelScanHandle();暂时屏蔽自动销毁界面 } else if (&view == container[MAIN_INTERFACE]) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainAlarmView::DropView::container[MAIN_INTERFACE]"); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/alipay/src/AlipayMainView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/alipay/src/AlipayMainView.cpp index 111b865b8..ca0f8d48f 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/alipay/src/AlipayMainView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/alipay/src/AlipayMainView.cpp @@ -1,836 +1,837 @@ -/** - * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. - * Description: alipay app main view. - * Author: - * Create: - */ - -#include "alipay/include/AlipayMainView.h" -#include "UiConfig.h" -#include "alipay_feature.h" -#include "custom_utils.h" -#include "alipay/include/AlipayC.h" - -bool is_Alipay_bind(void) -{ - if( OHOS:: AlipayMainView::GetInstance()) - { - int16 theView = OHOS::AlipayMainView::GetInstance()->GetWhichInter(); - if(theView==OHOS::ALIPAY_BIND_VIEW) - { - return true; - } - else - { - return false; - } - } - return false; -} - -namespace OHOS { -#define ALIPAY_BIND_SUCCESS_RES_TIMER_LENGTH 3000 -#define ALIPAY_BIND_FAILURE_RES_TIMER_LENGTH 8000 - -static AlipayMainView *g_alipayMainView = nullptr; - -static const int16 LABEL_FIRST_X = 200; -static const int16 LABEL_FIRST_Y = 60; -static const int16 LABEL_FIRST_WIDTH = 150; -static const int16 LABEL_FIRST_HEIGHT = 45; -static const int16 LABEL_FIRST_FONT = 35; - -AlipayMainView::AlipayMainView() -{ - g_alipayMainView = this; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::AlipayMainView"); -} - -AlipayMainView::~AlipayMainView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::~AlipayMainView"); - int16 numGroup; - for (numGroup = ALIPAY_SET_ZERO; numGroup < ALIPAY_INTERFACES_MAX; numGroup++) { - if (container[numGroup] != nullptr) { - container[numGroup] = nullptr; - } - } - DeleteViceInter(); - group = nullptr; - g_alipayMainView = nullptr; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::~AlipayMainView"); -} - -AlipayMainView *AlipayMainView::GetInstance(void) -{ - return g_alipayMainView; -} - -void AlipayMainView::OnStart() -{ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::OnStart"); - if(Alipay_is_init()==false) - return; - - alipayInterfacesId startView; - bool bindFlag = AlipayModel::GetInstance()->AlipayGetBindstate(); - if (!bindFlag) { - alipayBind = new AlipayBind(presenter_); - if (alipayBind == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView:: OnStart alipayBind null error!"); - return; - } - alipayBind->InitView(); - startView = ALIPAY_BIND_VIEW; - container[startView] = alipayBind; - //如果是绑定界面则打开广播 - start_alipay_ble_service(); - AlipayModel::GetInstance()->AlipayStartBind(); - } else { - alipayList = new AlipayList(presenter_); - if (alipayList == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView:: OnStart alipayList null error!"); - return; - } - alipayList->InitListView(); - startView = ALIPAY_LIST_VIEW; - container[startView] = alipayList; - } - AlipayModel::GetInstance()->SetAlipayInterLis(startView); - group = container[startView]; - alipayWhichInter = startView; - - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::OnStart group null error!"); - return; - } - AddViewToRootContainer(group); - return; -} - -void AlipayMainView::DeleteViceInter(void) -{ - if (alipayBind != nullptr) { - delete alipayBind; - alipayBind = nullptr; - } - if (alipayExitBind != nullptr) { - delete alipayExitBind; - alipayExitBind = nullptr; - } - if (alipayBindRes != nullptr) { - delete alipayBindRes; - alipayBindRes = nullptr; - } - if (alipayBindAni != nullptr) { - delete alipayBindAni; - alipayBindAni = nullptr; - } - - if (alipayPayCode != nullptr) { - delete alipayPayCode; - alipayPayCode = nullptr; - } - if (alipayBarCode != nullptr) { - delete alipayBarCode; - alipayBarCode = nullptr; - } - if (alipaySetting != nullptr) { - delete alipaySetting; - alipaySetting = nullptr; - } - if (alipayExitBindSetting != nullptr) { - delete alipayExitBindSetting; - alipayExitBindSetting = nullptr; - } - if (alipayUnbindFinish != nullptr) { - delete alipayUnbindFinish; - alipayUnbindFinish = nullptr; - } - - if (alipayHelp != nullptr) { - delete alipayHelp; - alipayHelp = nullptr; - } - - if (alipayList != nullptr) { - delete alipayList; - alipayList = nullptr; - } - - if (alipayGetTransList != nullptr) { - delete alipayGetTransList; - alipayGetTransList = nullptr; - } - if (alipayTransTips != nullptr) { - delete alipayTransTips; - alipayTransTips = nullptr; - } - if (alipayTransCode != nullptr) { - delete alipayTransCode; - alipayTransCode = nullptr; - } - if (alipayTransEnable != nullptr) { - delete alipayTransEnable; - alipayTransEnable = nullptr; - } - if (alipayTransRes != nullptr) { - delete alipayTransRes; - alipayTransRes = nullptr; - } - if (alipayTransList != nullptr) { - delete alipayTransList; - alipayTransList = nullptr; - } - - if (alipayTransAni != nullptr) { - delete alipayTransAni; - alipayTransAni = nullptr; - } - - return; -} - -int16 AlipayMainView::GetWhichInter(void) -{ - return alipayWhichInter; -} - -int16 AlipayMainView::GetListenInter(void) -{ - return interListen; -} -//当前定义为给按键专用 -void AlipayMainView::DropView(uint8_t type) -{ - - if(alipayWhichInter==ALIPAY_BIND_ANI_VIEW) - { - ChangeView(ALIPAY_BIND_ANI_VIEW, ALIPAY_BIND_EXIT_VIEW); - } - else - { - AlipayModel::GetInstance()->AlipayStopSwitchTimer(); - AlipayModel::GetInstance()->AlipayStopBindTimer(); - AlipayModel::GetInstance()->AlipayStopdisconnecTimer(); - NativeAbility::GetInstance().Back(); - } -} -void AlipayMainView::DropView(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView"); - if (&view == container[ALIPAY_PAY_BARCODE_VIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_PAY_BARCODE_VIEW]"); - ChangeView(ALIPAY_PAY_BARCODE_VIEW, ALIPAY_PAY_VIEW); - } else if (&view == container[ALIPAY_PAY_VIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_PAY_VIEW]"); - AlipayModel::GetInstance()->AlipayStopSwitchTimer(); - ChangeView(ALIPAY_PAY_VIEW, ALIPAY_LIST_VIEW); - } else if (&view == container[ALIPAY_SETTING_VIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_SETTING_VIEW]"); - ChangeView(ALIPAY_SETTING_VIEW, ALIPAY_LIST_VIEW); - } else if (&view == container[ALIPAY_HELP_VIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_HELP_VIEW]"); - ChangeView(ALIPAY_HELP_VIEW, ALIPAY_LIST_VIEW); - } else if (&view == container[ALIPAY_BIND_ANI_VIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_BIND_ANI_VIEW]"); - ChangeView(ALIPAY_BIND_ANI_VIEW, ALIPAY_BIND_EXIT_VIEW); - } else if (&view == container[ALIPAY_LIST_VIEW] || &view == container[ALIPAY_BIND_VIEW]) { - AlipayModel::GetInstance()->AlipayStopSwitchTimer(); - AlipayModel::GetInstance()->AlipayStopBindTimer(); - AlipayModel::GetInstance()->AlipayStopdisconnecTimer(); - NativeAbility::GetInstance().Back(); - } else if (&view == container[ALIPAY_TRANS_LIST_VIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_TRANS_LIST_VIEW]"); - ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_LIST_VIEW); - } else if (&view == container[ALIPAY_TRANS_VIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_TRANS_VIEW]"); - ChangeView(ALIPAY_TRANS_VIEW, ALIPAY_TRANS_LIST_VIEW); - } else if (&view == container[ALIPAY_TRANS_ENABLE_VIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_TRANS_ENABLE_VIEW]"); - AlipayModel::GetInstance()->AlipayTransStopGetListsTimer(); - ChangeView(ALIPAY_TRANS_ENABLE_VIEW, ALIPAY_LIST_VIEW); - } - - return; -} - -void AlipayMainView::SwitchView(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::SwitchView"); - if (&view == container[ALIPAY_PAY_VIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_PAY_VIEW]"); - ChangeView(ALIPAY_PAY_VIEW, ALIPAY_PAY_BARCODE_VIEW); - } else if (&view == container[ALIPAY_BIND_RES_VIEW] && presenter_->AlipayGetBindFlag()) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_BIND_VIEW]"); - AlipayModel::GetInstance()->AlipayStopSwitchTimer(); - ChangeView(ALIPAY_BIND_RES_VIEW, ALIPAY_LIST_VIEW); - } - return; -} - -bool AlipayMainView::ChangePayView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangePayView"); - AlipayModel::GetInstance()->AlipayStartSwitchTimer(60000); - if (container[thisView] == nullptr) { - alipayPayCode = new AlipayPayCode(presenter_); - if (alipayPayCode == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangePayView alipayPayCode null error!"); - return false; - } - if (!alipayPayCode->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangePayView InitView null error!"); - return false; - } - - container[thisView] = alipayPayCode; - AddViewToRootContainer(container[thisView]); - } else { - uint8_t payStr[ALIPAY_GET_PAY_STR_MAX_LENGTH] = { 0 }; - presenter_->AlipayGetPayCode(payStr); - alipayPayCode->AlipayRefreshQrcode((const char *)payStr); - } - - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeSettingView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeSettingView"); - if (container[thisView] == nullptr) { - alipaySetting = new AlipaySetting(presenter_); - if (alipaySetting == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeSettingView alipayPayCode null error!"); - return false; - } - if (!alipaySetting->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeSettingView InitView null error!"); - return false; - } - - container[thisView] = alipaySetting; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeHelpView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeHelpView"); - if (container[thisView] == nullptr) { - alipayHelp = new AlipayHelp(presenter_); - if (alipayHelp == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeHelpView alipayHelp null error!"); - return false; - } - if (!alipayHelp->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeHelpView InitView null error!"); - return false; - } - - container[thisView] = alipayHelp; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeBindAniView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindAniView"); - if (container[thisView] == nullptr) { - alipayBindAni = new AlipayBindAni(presenter_); - if (alipayBindAni == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindAniView alipayBindAni null error!"); - return false; - } - if (!alipayBindAni->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindAniView InitView null error!"); - return false; - } - - container[thisView] = alipayBindAni; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeBindExitView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindExitView"); - if (container[thisView] == nullptr) { - alipayExitBind = new AlipayExitBind(presenter_); - if (alipayExitBind == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindExitView alipayExitBind null error!"); - return false; - } - if (!alipayExitBind->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindExitView InitView null error!"); - return false; - } - - container[thisView] = alipayExitBind; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeBindResView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindResView"); - if (container[thisView] == nullptr) { - alipayBindRes = new AlipayBindRes(presenter_); - if (alipayBindRes == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindResView alipayBindRes null error!"); - return false; - } - if (!alipayBindRes->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindResView InitView null error!"); - return false; - } - - container[thisView] = alipayBindRes; - - AddViewToRootContainer(container[thisView]); - } - alipayBindRes->AlipayRefreshBindRes(); - if (presenter_->AlipayGetBindFlag()) { - AlipayModel::GetInstance()->AlipayStartSwitchTimer(ALIPAY_BIND_SUCCESS_RES_TIMER_LENGTH); - } else { - AlipayModel::GetInstance()->AlipayStartSwitchTimer(ALIPAY_BIND_FAILURE_RES_TIMER_LENGTH); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeUnbindView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeUnbindView"); - if (container[thisView] == nullptr) { - alipayExitBindSetting = new AlipayUnbind(presenter_); - if (alipayExitBindSetting == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "AlipayMainView::ChangeUnbindView alipayExitBindSetting null error!"); - return false; - } - if (!alipayExitBindSetting->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeUnbindView InitView null error!"); - return false; - } - - container[thisView] = alipayExitBindSetting; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeUnbindFinishView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeUnbindFinishView"); - AlipayModel::GetInstance()->AlipayUnbind(); - if (container[thisView] == nullptr) { - alipayUnbindFinish = new AlipayUnbindFinish(presenter_); - if (alipayUnbindFinish == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "AlipayMainView::ChangeUnbindFinishView alipayUnbindFinish null error!"); - return false; - } - if (!alipayUnbindFinish->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeUnbindFinishView InitView null error!"); - return false; - } - - container[thisView] = alipayUnbindFinish; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeBindView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindView"); - AlipayModel::GetInstance()->AlipayStartBind(); - - /**启动alipay蓝牙服务*/ - //需要重新打开广播 - start_alipay_ble_service(); - - if (container[thisView] == nullptr) { - alipayBind = new AlipayBind(presenter_); - if (alipayBind == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindView alipayBind null error!"); - return false; - } - if (!alipayBind->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindView InitView null error!"); - return false; - } - - container[thisView] = alipayBind; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeTransView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransView"); - if (container[thisView] == nullptr) { - alipayTransCode = new AlipayTransCode(presenter_); - if (alipayTransCode == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransView alipayTransCode null error!"); - return false; - } - if (!alipayTransCode->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransView InitView null error!"); - return false; - } - - container[thisView] = alipayTransCode; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeTransListView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransListView"); - if (container[thisView] == nullptr) { - alipayTransList = new AlipayTransList(presenter_); - if (alipayTransList == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransListView alipayTransList null error!"); - return false; - } - if (!alipayTransList->InitListView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransListView InitView null error!"); - return false; - } - - container[thisView] = alipayTransList; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeTransEnableView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransEnableView"); - if (container[thisView] == nullptr) { - alipayTransEnable = new AlipayTransEnable(presenter_); - if (alipayTransEnable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "AlipayMainView::ChangeTransEnableView alipayTransEnable null error!"); - return false; - } - if (!alipayTransEnable->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransEnableView InitView null error!"); - return false; - } - - container[thisView] = alipayTransEnable; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeTransTipsView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransTipsView"); - if (container[thisView] == nullptr) { - alipayTransTips = new AlipayTransTips(presenter_); - if (alipayTransTips == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransTipsView alipayTransTips null error!"); - return false; - } - if (!alipayTransTips->InitTipsView(presenter_->AlipayGetSwitchIndex())) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransTipsView InitView null error!"); - return false; - } - - container[thisView] = alipayTransTips; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeTransResView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransResView"); - if (container[thisView] == nullptr) { - alipayTransRes = new AlipayTransRes(presenter_); - if (alipayTransRes == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransResView alipayTransRes null error!"); - return false; - } - if (!alipayTransRes->InitResView(presenter_->AlipayGetSwitchIndex())) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransResView InitView null error!"); - return false; - } - - container[thisView] = alipayTransRes; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeGetTransListView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeGetTransListView"); - if (container[thisView] == nullptr) { - alipayGetTransList = new AlipayGetTransList(presenter_); - if (alipayGetTransList == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "AlipayMainView::ChangeGetTransListView alipayGetTransList null error!"); - return false; - } - if (!alipayGetTransList->InitGetView(presenter_->AlipayGetSwitchIndex())) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeGetTransListView InitView null error!"); - return false; - } - - container[thisView] = alipayGetTransList; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeTransAniView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransProcessView"); - if (container[thisView] == nullptr) { - alipayTransAni = new AlipayTransAni(presenter_); - if (alipayTransAni == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransProcessView alipayTransAni null error!"); - return false; - } - if (!alipayTransAni->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransProcessView InitView null error!"); - return false; - } - - container[thisView] = alipayTransAni; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeBarCodeView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBarView"); - AlipayModel::GetInstance()->AlipayStartSwitchTimer(60000); - if (container[thisView] == nullptr) { - alipayBarCode = new AlipayBarCode(presenter_); - if (alipayBarCode == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBarView alipayPayCode null error!"); - return false; - } - if (!alipayBarCode->InitView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBarView InitView null error!"); - return false; - } - - container[thisView] = alipayBarCode; - - AddViewToRootContainer(container[thisView]); - } else { - uint8_t barStr[ALIPAY_GET_PAY_STR_MAX_LENGTH] = { 0 }; - presenter_->AlipayGetPayCode(barStr); - AlipayBarCode::GetInstance()->AlipayRefreshBarcode((const char *)barStr); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -bool AlipayMainView::ChangeListView(int16 thisView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeListView"); - if (container[thisView] == nullptr) { - alipayList = new AlipayList(presenter_); - if (alipayList == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeListView alipayList null error!"); - return false; - } - if (!alipayList->InitListView()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeListView InitView null error!"); - return false; - } - - container[thisView] = alipayList; - - AddViewToRootContainer(container[thisView]); - } - alipayWhichInter = thisView; - alipayWhichMea = thisView; - return true; -} - -struct AlipayViewMapper { - const int16 viewId; - bool (AlipayMainView::*func)(int16 thisView); -}; - -static const AlipayViewMapper ViewMapper[] = { - {ALIPAY_PAY_VIEW, &AlipayMainView::ChangePayView}, - {ALIPAY_SETTING_VIEW, &AlipayMainView::ChangeSettingView}, - {ALIPAY_PAY_BARCODE_VIEW, &AlipayMainView::ChangeBarCodeView}, - {ALIPAY_LIST_VIEW, &AlipayMainView::ChangeListView}, - {ALIPAY_HELP_VIEW, &AlipayMainView::ChangeHelpView}, - {ALIPAY_BIND_ANI_VIEW, &AlipayMainView::ChangeBindAniView}, - {ALIPAY_BIND_EXIT_VIEW, &AlipayMainView::ChangeBindExitView}, - {ALIPAY_BIND_RES_VIEW, &AlipayMainView::ChangeBindResView}, - {ALIPAY_SETTING_UNBIND_VIEW, &AlipayMainView::ChangeUnbindView}, - {ALIPAY_SETTING_FINISH_VIEW, &AlipayMainView::ChangeUnbindFinishView}, - {ALIPAY_BIND_VIEW, &AlipayMainView::ChangeBindView}, - {ALIPAY_TRANS_VIEW, &AlipayMainView::ChangeTransView}, - {ALIPAY_TRANS_LIST_VIEW, &AlipayMainView::ChangeTransListView}, - {ALIPAY_TRANS_ENABLE_VIEW, &AlipayMainView::ChangeTransEnableView}, - {ALIPAY_TRANS_TIPS_VIEW, &AlipayMainView::ChangeTransTipsView}, - {ALIPAY_TRANS_RES_VIEW, &AlipayMainView::ChangeTransResView}, - {ALIPAY_GET_TRANS_LIST_VIEW, &AlipayMainView::ChangeGetTransListView}, - {ALIPAY_TRANS_ANI_VIEW, &AlipayMainView::ChangeTransAniView}, - -}; - -bool AlipayMainView::ClickFunc(int16 interface) -{ - int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]); - for (int i = 0; i < funcSize; i++) { - if (interface == ViewMapper[i].viewId) { - bool jug = (this->*(ViewMapper[i].func))(interface); - if (!jug) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainAlarmView:: ChangeInterFace[%d] false", interface); - return false; - } - return true; - } - } - return false; -} - -static const int16 DestroyMapper[] = { - ALIPAY_TRANS_TIPS_VIEW, - ALIPAY_TRANS_RES_VIEW, - ALIPAY_GET_TRANS_LIST_VIEW, - ALIPAY_TRANS_VIEW, - ALIPAY_TRANS_LIST_VIEW, - ALIPAY_SETTING_VIEW, -}; - -void AlipayMainView::DestroyTempView(int16 hideView) -{ - int viewSize = sizeof(DestroyMapper) / sizeof(DestroyMapper[0]); - for (int i = 0; i < viewSize; i++) { - if (hideView == DestroyMapper[i]) { - GetRootContainer()->Remove(container[hideView]); - container[hideView] = nullptr; - break; - } - } - if (hideView == ALIPAY_TRANS_TIPS_VIEW) { - #if 0 - if(AlipayModel::GetInstance()->AlipayGetSwitchIndex() == ALIPAY_TRANS_TIPS_LIST_UNKNOW) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DestroyTempView ALIPAY_TRANS_TIPS_UNKNOW"); - AlipayModel::GetInstance()->delete_all_files_in_folder("/user/alipay/"); - } - #endif - delete alipayTransTips; - alipayTransTips = nullptr; - } else if (hideView == ALIPAY_TRANS_RES_VIEW) { - delete alipayTransRes; - alipayTransRes = nullptr; - } else if (hideView == ALIPAY_GET_TRANS_LIST_VIEW) { - delete alipayGetTransList; - alipayGetTransList = nullptr; - } else if (hideView == ALIPAY_TRANS_VIEW) { - delete alipayTransCode; - alipayTransCode = nullptr; - } else if (hideView == ALIPAY_TRANS_LIST_VIEW) { - delete alipayTransList; - alipayTransList = nullptr; - } else if (hideView == ALIPAY_SETTING_VIEW) { - delete alipaySetting; - alipaySetting = nullptr; - } -} - -void AlipayMainView::ChangeView(int16 hideView, int16 showView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeView hideView = %d, showView = %d", hideView, - showView); - if (container[hideView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeView hideView container is null: %x.", - container[hideView]); - return; - } - if (hideView > ALIPAY_INTERFACES_MAX) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeView Overstep ones bounds"); - return; - } - interListen = hideView; - if (!ClickFunc(showView)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeView ClickFunc error"); - return; - } - - container[hideView]->SetVisible(false); - container[showView]->SetVisible(true); - - if(hideView==ALIPAY_BIND_VIEW) - { - stop_alipay_ble_service(); - } - - AlipayModel::GetInstance()->SetAlipayInterLis(showView); - - Draw(); - DestroyTempView(hideView); - return; -} +/** + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: alipay app main view. + * Author: + * Create: + */ + +#include "alipay/include/AlipayMainView.h" +#include "UiConfig.h" +#include "alipay_feature.h" +#include "custom_utils.h" +#include "alipay/include/AlipayC.h" +#include "AbilityNavigationApi.h" + +bool is_Alipay_bind(void) +{ + if( OHOS:: AlipayMainView::GetInstance()) + { + int16 theView = OHOS::AlipayMainView::GetInstance()->GetWhichInter(); + if(theView==OHOS::ALIPAY_BIND_VIEW) + { + return true; + } + else + { + return false; + } + } + return false; +} + +namespace OHOS { +#define ALIPAY_BIND_SUCCESS_RES_TIMER_LENGTH 3000 +#define ALIPAY_BIND_FAILURE_RES_TIMER_LENGTH 8000 + +static AlipayMainView *g_alipayMainView = nullptr; + +static const int16 LABEL_FIRST_X = 200; +static const int16 LABEL_FIRST_Y = 60; +static const int16 LABEL_FIRST_WIDTH = 150; +static const int16 LABEL_FIRST_HEIGHT = 45; +static const int16 LABEL_FIRST_FONT = 35; + +AlipayMainView::AlipayMainView() +{ + g_alipayMainView = this; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::AlipayMainView"); +} + +AlipayMainView::~AlipayMainView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::~AlipayMainView"); + int16 numGroup; + for (numGroup = ALIPAY_SET_ZERO; numGroup < ALIPAY_INTERFACES_MAX; numGroup++) { + if (container[numGroup] != nullptr) { + container[numGroup] = nullptr; + } + } + DeleteViceInter(); + group = nullptr; + g_alipayMainView = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::~AlipayMainView"); +} + +AlipayMainView *AlipayMainView::GetInstance(void) +{ + return g_alipayMainView; +} + +void AlipayMainView::OnStart() +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::OnStart"); + if(Alipay_is_init()==false) + return; + + alipayInterfacesId startView; + bool bindFlag = AlipayModel::GetInstance()->AlipayGetBindstate(); + if (!bindFlag) { + alipayBind = new AlipayBind(presenter_); + if (alipayBind == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView:: OnStart alipayBind null error!"); + return; + } + alipayBind->InitView(); + startView = ALIPAY_BIND_VIEW; + container[startView] = alipayBind; + //如果是绑定界面则打开广播 + start_alipay_ble_service(); + AlipayModel::GetInstance()->AlipayStartBind(); + } else { + alipayList = new AlipayList(presenter_); + if (alipayList == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView:: OnStart alipayList null error!"); + return; + } + alipayList->InitListView(); + startView = ALIPAY_LIST_VIEW; + container[startView] = alipayList; + } + AlipayModel::GetInstance()->SetAlipayInterLis(startView); + group = container[startView]; + alipayWhichInter = startView; + + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::OnStart group null error!"); + return; + } + AddViewToRootContainer(group); + return; +} + +void AlipayMainView::DeleteViceInter(void) +{ + if (alipayBind != nullptr) { + delete alipayBind; + alipayBind = nullptr; + } + if (alipayExitBind != nullptr) { + delete alipayExitBind; + alipayExitBind = nullptr; + } + if (alipayBindRes != nullptr) { + delete alipayBindRes; + alipayBindRes = nullptr; + } + if (alipayBindAni != nullptr) { + delete alipayBindAni; + alipayBindAni = nullptr; + } + + if (alipayPayCode != nullptr) { + delete alipayPayCode; + alipayPayCode = nullptr; + } + if (alipayBarCode != nullptr) { + delete alipayBarCode; + alipayBarCode = nullptr; + } + if (alipaySetting != nullptr) { + delete alipaySetting; + alipaySetting = nullptr; + } + if (alipayExitBindSetting != nullptr) { + delete alipayExitBindSetting; + alipayExitBindSetting = nullptr; + } + if (alipayUnbindFinish != nullptr) { + delete alipayUnbindFinish; + alipayUnbindFinish = nullptr; + } + + if (alipayHelp != nullptr) { + delete alipayHelp; + alipayHelp = nullptr; + } + + if (alipayList != nullptr) { + delete alipayList; + alipayList = nullptr; + } + + if (alipayGetTransList != nullptr) { + delete alipayGetTransList; + alipayGetTransList = nullptr; + } + if (alipayTransTips != nullptr) { + delete alipayTransTips; + alipayTransTips = nullptr; + } + if (alipayTransCode != nullptr) { + delete alipayTransCode; + alipayTransCode = nullptr; + } + if (alipayTransEnable != nullptr) { + delete alipayTransEnable; + alipayTransEnable = nullptr; + } + if (alipayTransRes != nullptr) { + delete alipayTransRes; + alipayTransRes = nullptr; + } + if (alipayTransList != nullptr) { + delete alipayTransList; + alipayTransList = nullptr; + } + + if (alipayTransAni != nullptr) { + delete alipayTransAni; + alipayTransAni = nullptr; + } + + return; +} + +int16 AlipayMainView::GetWhichInter(void) +{ + return alipayWhichInter; +} + +int16 AlipayMainView::GetListenInter(void) +{ + return interListen; +} +//当前定义为给按键专用 +void AlipayMainView::DropView(uint8_t type) +{ + + if(alipayWhichInter==ALIPAY_BIND_ANI_VIEW) + { + ChangeView(ALIPAY_BIND_ANI_VIEW, ALIPAY_BIND_EXIT_VIEW); + } + else + { + AlipayModel::GetInstance()->AlipayStopSwitchTimer(); + AlipayModel::GetInstance()->AlipayStopBindTimer(); + AlipayModel::GetInstance()->AlipayStopdisconnecTimer(); + OHOS::AbilityNavigation::Back(); + } +} +void AlipayMainView::DropView(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView"); + if (&view == container[ALIPAY_PAY_BARCODE_VIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_PAY_BARCODE_VIEW]"); + ChangeView(ALIPAY_PAY_BARCODE_VIEW, ALIPAY_PAY_VIEW); + } else if (&view == container[ALIPAY_PAY_VIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_PAY_VIEW]"); + AlipayModel::GetInstance()->AlipayStopSwitchTimer(); + ChangeView(ALIPAY_PAY_VIEW, ALIPAY_LIST_VIEW); + } else if (&view == container[ALIPAY_SETTING_VIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_SETTING_VIEW]"); + ChangeView(ALIPAY_SETTING_VIEW, ALIPAY_LIST_VIEW); + } else if (&view == container[ALIPAY_HELP_VIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_HELP_VIEW]"); + ChangeView(ALIPAY_HELP_VIEW, ALIPAY_LIST_VIEW); + } else if (&view == container[ALIPAY_BIND_ANI_VIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_BIND_ANI_VIEW]"); + ChangeView(ALIPAY_BIND_ANI_VIEW, ALIPAY_BIND_EXIT_VIEW); + } else if (&view == container[ALIPAY_LIST_VIEW] || &view == container[ALIPAY_BIND_VIEW]) { + AlipayModel::GetInstance()->AlipayStopSwitchTimer(); + AlipayModel::GetInstance()->AlipayStopBindTimer(); + AlipayModel::GetInstance()->AlipayStopdisconnecTimer(); + OHOS::AbilityNavigation::Back(); + } else if (&view == container[ALIPAY_TRANS_LIST_VIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_TRANS_LIST_VIEW]"); + ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_LIST_VIEW); + } else if (&view == container[ALIPAY_TRANS_VIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_TRANS_VIEW]"); + ChangeView(ALIPAY_TRANS_VIEW, ALIPAY_TRANS_LIST_VIEW); + } else if (&view == container[ALIPAY_TRANS_ENABLE_VIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_TRANS_ENABLE_VIEW]"); + AlipayModel::GetInstance()->AlipayTransStopGetListsTimer(); + ChangeView(ALIPAY_TRANS_ENABLE_VIEW, ALIPAY_LIST_VIEW); + } + + return; +} + +void AlipayMainView::SwitchView(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::SwitchView"); + if (&view == container[ALIPAY_PAY_VIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_PAY_VIEW]"); + ChangeView(ALIPAY_PAY_VIEW, ALIPAY_PAY_BARCODE_VIEW); + } else if (&view == container[ALIPAY_BIND_RES_VIEW] && presenter_->AlipayGetBindFlag()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DropView::container[ALIPAY_BIND_VIEW]"); + AlipayModel::GetInstance()->AlipayStopSwitchTimer(); + ChangeView(ALIPAY_BIND_RES_VIEW, ALIPAY_LIST_VIEW); + } + return; +} + +bool AlipayMainView::ChangePayView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangePayView"); + AlipayModel::GetInstance()->AlipayStartSwitchTimer(60000); + if (container[thisView] == nullptr) { + alipayPayCode = new AlipayPayCode(presenter_); + if (alipayPayCode == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangePayView alipayPayCode null error!"); + return false; + } + if (!alipayPayCode->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangePayView InitView null error!"); + return false; + } + + container[thisView] = alipayPayCode; + AddViewToRootContainer(container[thisView]); + } else { + uint8_t payStr[ALIPAY_GET_PAY_STR_MAX_LENGTH] = { 0 }; + presenter_->AlipayGetPayCode(payStr); + alipayPayCode->AlipayRefreshQrcode((const char *)payStr); + } + + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeSettingView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeSettingView"); + if (container[thisView] == nullptr) { + alipaySetting = new AlipaySetting(presenter_); + if (alipaySetting == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeSettingView alipayPayCode null error!"); + return false; + } + if (!alipaySetting->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeSettingView InitView null error!"); + return false; + } + + container[thisView] = alipaySetting; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeHelpView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeHelpView"); + if (container[thisView] == nullptr) { + alipayHelp = new AlipayHelp(presenter_); + if (alipayHelp == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeHelpView alipayHelp null error!"); + return false; + } + if (!alipayHelp->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeHelpView InitView null error!"); + return false; + } + + container[thisView] = alipayHelp; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeBindAniView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindAniView"); + if (container[thisView] == nullptr) { + alipayBindAni = new AlipayBindAni(presenter_); + if (alipayBindAni == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindAniView alipayBindAni null error!"); + return false; + } + if (!alipayBindAni->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindAniView InitView null error!"); + return false; + } + + container[thisView] = alipayBindAni; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeBindExitView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindExitView"); + if (container[thisView] == nullptr) { + alipayExitBind = new AlipayExitBind(presenter_); + if (alipayExitBind == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindExitView alipayExitBind null error!"); + return false; + } + if (!alipayExitBind->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindExitView InitView null error!"); + return false; + } + + container[thisView] = alipayExitBind; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeBindResView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindResView"); + if (container[thisView] == nullptr) { + alipayBindRes = new AlipayBindRes(presenter_); + if (alipayBindRes == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindResView alipayBindRes null error!"); + return false; + } + if (!alipayBindRes->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindResView InitView null error!"); + return false; + } + + container[thisView] = alipayBindRes; + + AddViewToRootContainer(container[thisView]); + } + alipayBindRes->AlipayRefreshBindRes(); + if (presenter_->AlipayGetBindFlag()) { + AlipayModel::GetInstance()->AlipayStartSwitchTimer(ALIPAY_BIND_SUCCESS_RES_TIMER_LENGTH); + } else { + AlipayModel::GetInstance()->AlipayStartSwitchTimer(ALIPAY_BIND_FAILURE_RES_TIMER_LENGTH); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeUnbindView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeUnbindView"); + if (container[thisView] == nullptr) { + alipayExitBindSetting = new AlipayUnbind(presenter_); + if (alipayExitBindSetting == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AlipayMainView::ChangeUnbindView alipayExitBindSetting null error!"); + return false; + } + if (!alipayExitBindSetting->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeUnbindView InitView null error!"); + return false; + } + + container[thisView] = alipayExitBindSetting; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeUnbindFinishView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeUnbindFinishView"); + AlipayModel::GetInstance()->AlipayUnbind(); + if (container[thisView] == nullptr) { + alipayUnbindFinish = new AlipayUnbindFinish(presenter_); + if (alipayUnbindFinish == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AlipayMainView::ChangeUnbindFinishView alipayUnbindFinish null error!"); + return false; + } + if (!alipayUnbindFinish->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeUnbindFinishView InitView null error!"); + return false; + } + + container[thisView] = alipayUnbindFinish; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeBindView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindView"); + AlipayModel::GetInstance()->AlipayStartBind(); + + /**启动alipay蓝牙服务*/ + //需要重新打开广播 + start_alipay_ble_service(); + + if (container[thisView] == nullptr) { + alipayBind = new AlipayBind(presenter_); + if (alipayBind == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindView alipayBind null error!"); + return false; + } + if (!alipayBind->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBindView InitView null error!"); + return false; + } + + container[thisView] = alipayBind; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeTransView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransView"); + if (container[thisView] == nullptr) { + alipayTransCode = new AlipayTransCode(presenter_); + if (alipayTransCode == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransView alipayTransCode null error!"); + return false; + } + if (!alipayTransCode->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransView InitView null error!"); + return false; + } + + container[thisView] = alipayTransCode; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeTransListView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransListView"); + if (container[thisView] == nullptr) { + alipayTransList = new AlipayTransList(presenter_); + if (alipayTransList == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransListView alipayTransList null error!"); + return false; + } + if (!alipayTransList->InitListView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransListView InitView null error!"); + return false; + } + + container[thisView] = alipayTransList; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeTransEnableView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransEnableView"); + if (container[thisView] == nullptr) { + alipayTransEnable = new AlipayTransEnable(presenter_); + if (alipayTransEnable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AlipayMainView::ChangeTransEnableView alipayTransEnable null error!"); + return false; + } + if (!alipayTransEnable->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransEnableView InitView null error!"); + return false; + } + + container[thisView] = alipayTransEnable; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeTransTipsView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransTipsView"); + if (container[thisView] == nullptr) { + alipayTransTips = new AlipayTransTips(presenter_); + if (alipayTransTips == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransTipsView alipayTransTips null error!"); + return false; + } + if (!alipayTransTips->InitTipsView(presenter_->AlipayGetSwitchIndex())) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransTipsView InitView null error!"); + return false; + } + + container[thisView] = alipayTransTips; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeTransResView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransResView"); + if (container[thisView] == nullptr) { + alipayTransRes = new AlipayTransRes(presenter_); + if (alipayTransRes == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransResView alipayTransRes null error!"); + return false; + } + if (!alipayTransRes->InitResView(presenter_->AlipayGetSwitchIndex())) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransResView InitView null error!"); + return false; + } + + container[thisView] = alipayTransRes; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeGetTransListView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeGetTransListView"); + if (container[thisView] == nullptr) { + alipayGetTransList = new AlipayGetTransList(presenter_); + if (alipayGetTransList == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AlipayMainView::ChangeGetTransListView alipayGetTransList null error!"); + return false; + } + if (!alipayGetTransList->InitGetView(presenter_->AlipayGetSwitchIndex())) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeGetTransListView InitView null error!"); + return false; + } + + container[thisView] = alipayGetTransList; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeTransAniView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransProcessView"); + if (container[thisView] == nullptr) { + alipayTransAni = new AlipayTransAni(presenter_); + if (alipayTransAni == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransProcessView alipayTransAni null error!"); + return false; + } + if (!alipayTransAni->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeTransProcessView InitView null error!"); + return false; + } + + container[thisView] = alipayTransAni; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeBarCodeView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBarView"); + AlipayModel::GetInstance()->AlipayStartSwitchTimer(60000); + if (container[thisView] == nullptr) { + alipayBarCode = new AlipayBarCode(presenter_); + if (alipayBarCode == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBarView alipayPayCode null error!"); + return false; + } + if (!alipayBarCode->InitView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeBarView InitView null error!"); + return false; + } + + container[thisView] = alipayBarCode; + + AddViewToRootContainer(container[thisView]); + } else { + uint8_t barStr[ALIPAY_GET_PAY_STR_MAX_LENGTH] = { 0 }; + presenter_->AlipayGetPayCode(barStr); + AlipayBarCode::GetInstance()->AlipayRefreshBarcode((const char *)barStr); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +bool AlipayMainView::ChangeListView(int16 thisView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeListView"); + if (container[thisView] == nullptr) { + alipayList = new AlipayList(presenter_); + if (alipayList == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeListView alipayList null error!"); + return false; + } + if (!alipayList->InitListView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeListView InitView null error!"); + return false; + } + + container[thisView] = alipayList; + + AddViewToRootContainer(container[thisView]); + } + alipayWhichInter = thisView; + alipayWhichMea = thisView; + return true; +} + +struct AlipayViewMapper { + const int16 viewId; + bool (AlipayMainView::*func)(int16 thisView); +}; + +static const AlipayViewMapper ViewMapper[] = { + {ALIPAY_PAY_VIEW, &AlipayMainView::ChangePayView}, + {ALIPAY_SETTING_VIEW, &AlipayMainView::ChangeSettingView}, + {ALIPAY_PAY_BARCODE_VIEW, &AlipayMainView::ChangeBarCodeView}, + {ALIPAY_LIST_VIEW, &AlipayMainView::ChangeListView}, + {ALIPAY_HELP_VIEW, &AlipayMainView::ChangeHelpView}, + {ALIPAY_BIND_ANI_VIEW, &AlipayMainView::ChangeBindAniView}, + {ALIPAY_BIND_EXIT_VIEW, &AlipayMainView::ChangeBindExitView}, + {ALIPAY_BIND_RES_VIEW, &AlipayMainView::ChangeBindResView}, + {ALIPAY_SETTING_UNBIND_VIEW, &AlipayMainView::ChangeUnbindView}, + {ALIPAY_SETTING_FINISH_VIEW, &AlipayMainView::ChangeUnbindFinishView}, + {ALIPAY_BIND_VIEW, &AlipayMainView::ChangeBindView}, + {ALIPAY_TRANS_VIEW, &AlipayMainView::ChangeTransView}, + {ALIPAY_TRANS_LIST_VIEW, &AlipayMainView::ChangeTransListView}, + {ALIPAY_TRANS_ENABLE_VIEW, &AlipayMainView::ChangeTransEnableView}, + {ALIPAY_TRANS_TIPS_VIEW, &AlipayMainView::ChangeTransTipsView}, + {ALIPAY_TRANS_RES_VIEW, &AlipayMainView::ChangeTransResView}, + {ALIPAY_GET_TRANS_LIST_VIEW, &AlipayMainView::ChangeGetTransListView}, + {ALIPAY_TRANS_ANI_VIEW, &AlipayMainView::ChangeTransAniView}, + +}; + +bool AlipayMainView::ClickFunc(int16 interface) +{ + int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]); + for (int i = 0; i < funcSize; i++) { + if (interface == ViewMapper[i].viewId) { + bool jug = (this->*(ViewMapper[i].func))(interface); + if (!jug) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainAlarmView:: ChangeInterFace[%d] false", interface); + return false; + } + return true; + } + } + return false; +} + +static const int16 DestroyMapper[] = { + ALIPAY_TRANS_TIPS_VIEW, + ALIPAY_TRANS_RES_VIEW, + ALIPAY_GET_TRANS_LIST_VIEW, + ALIPAY_TRANS_VIEW, + ALIPAY_TRANS_LIST_VIEW, + ALIPAY_SETTING_VIEW, +}; + +void AlipayMainView::DestroyTempView(int16 hideView) +{ + int viewSize = sizeof(DestroyMapper) / sizeof(DestroyMapper[0]); + for (int i = 0; i < viewSize; i++) { + if (hideView == DestroyMapper[i]) { + GetRootContainer()->Remove(container[hideView]); + container[hideView] = nullptr; + break; + } + } + if (hideView == ALIPAY_TRANS_TIPS_VIEW) { + #if 0 + if(AlipayModel::GetInstance()->AlipayGetSwitchIndex() == ALIPAY_TRANS_TIPS_LIST_UNKNOW) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::DestroyTempView ALIPAY_TRANS_TIPS_UNKNOW"); + AlipayModel::GetInstance()->delete_all_files_in_folder("/user/alipay/"); + } + #endif + delete alipayTransTips; + alipayTransTips = nullptr; + } else if (hideView == ALIPAY_TRANS_RES_VIEW) { + delete alipayTransRes; + alipayTransRes = nullptr; + } else if (hideView == ALIPAY_GET_TRANS_LIST_VIEW) { + delete alipayGetTransList; + alipayGetTransList = nullptr; + } else if (hideView == ALIPAY_TRANS_VIEW) { + delete alipayTransCode; + alipayTransCode = nullptr; + } else if (hideView == ALIPAY_TRANS_LIST_VIEW) { + delete alipayTransList; + alipayTransList = nullptr; + } else if (hideView == ALIPAY_SETTING_VIEW) { + delete alipaySetting; + alipaySetting = nullptr; + } +} + +void AlipayMainView::ChangeView(int16 hideView, int16 showView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeView hideView = %d, showView = %d", hideView, + showView); + if (container[hideView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeView hideView container is null: %x.", + container[hideView]); + return; + } + if (hideView > ALIPAY_INTERFACES_MAX) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeView Overstep ones bounds"); + return; + } + interListen = hideView; + if (!ClickFunc(showView)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayMainView::ChangeView ClickFunc error"); + return; + } + + container[hideView]->SetVisible(false); + container[showView]->SetVisible(true); + + if(hideView==ALIPAY_BIND_VIEW) + { + stop_alipay_ble_service(); + } + + AlipayModel::GetInstance()->SetAlipayInterLis(showView); + + Draw(); + DestroyTempView(hideView); + return; +} } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp index 602217ba0..de42077ef 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/alipay/src/AlipayPresenter.cpp @@ -1,596 +1,598 @@ -/** - * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. - * Description: alipay presenter. - * Author: - * Create: - */ - -#include "alipay/include/AlipayPresenter.h" -#include "alipay/include/AlipayMainView.h" -#include "ChangeSliceListener.h" -#include "graphic_service.h" -#include "string" -#include "iostream" -#include "sstream" -#include "errcode.h" -#include "pm_definition.h" -#include "alipay/include/AlipayList/AlipayListView.h" -#include "alipay/include/AlipayList/AlipayListItemView.h" -#include "alipay/include/AlipayTrans/AlipayTransListItemView.h" -#include "alipay/include/AlipayTrans/AlipayTransListView.h" -#include "NativeRegisterManager.h" -#include "custom_utils.h" -#include "common/key_code.h" -#include "gfx_utils/mem_check.h" -#include "alipay/include/AlipayC.h" -#include "ui_resource_string.h" -namespace OHOS { - -// REGIST_MENU_PRO(VIEW_MAIN_ALIPAY, AlipayMainView, AlipayPresenter, -// PNG_APPLIST_ALIPAY_IMAGE_BIG, PNG_APPLIST_ALIPAY_IMAGE,PNG_APPLIST_ALIPAY_IMAGE, "支付宝", STR_ALIPAY); - - #ifdef __cplusplus - extern "C" - { -#endif - -#include "pm.h" -#include "pm_veto.h" - - void remove_ALIPAY_vote(void) - { - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_ALIPAY); - if (cnt == 1) - { - uapi_pm_remove_sleep_veto(PM_ID_ALIPAY); - } - } - - void add_ALIPAY_vote(void) - { - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_ALIPAY); - if (cnt == 0) - { - uapi_pm_add_sleep_veto(PM_ID_ALIPAY); - } - } - -#ifdef __cplusplus - } -#endif - -static AlipayPresenter *g_alipayPresenter = nullptr; - -ColorType AlipayPresenter::CyanColor() -{ - return Color::GetColorFromRGB(0x1C, 0xF4, 0xED); -} - -AlipayPresenter::AlipayPresenter() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter new"); - alipayMode_ = AlipayModel::GetInstance(); - g_alipayPresenter = this; -} - -AlipayPresenter::~AlipayPresenter() -{ - g_alipayPresenter = nullptr; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::~AlipayPresenter"); -} - -AlipayPresenter *AlipayPresenter::GetInstance() -{ - return g_alipayPresenter; -} - -void AlipayPresenter::OnStart() -{ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter OnStart"); - if(Alipay_is_init()==false) - return; - /* -------------------------------- 设置支付宝界面常亮 ------------------------------- */ - add_ALIPAY_vote(); - alipayMode_->AlipayScreenControl(true); - /* -------------------------------------------------------------------------- */ - alipayMode_->AlipayExitLpm(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " alipayMode_->AlipayExitLpm()"); - - if (!alipayMode_->AlipayInitModel()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::OnStart AlipayInitModel fail."); - NativeAbility::GetInstance().Back(); - return; - } -} - -void AlipayPresenter::OnResume(void) -{ - svr_alipay_create_task(); - // 增加按键监听 - RootView::GetInstance()->SetOnKeyActListener(this); -} - -void AlipayPresenter::OnStop(void) -{ - - /**关闭alipay蓝牙服务*/ - stop_alipay_ble_service(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter OnStop"); - svr_alipay_destroy_task(); - alipayMode_->AlipayDeinitModel(); - alipayMode_->AlipayEnterLpm(); - /* -------------------------------- 恢复屏幕保持亮屏的时间 ------------------------------- */ - remove_ALIPAY_vote(); - alipayMode_->AlipayScreenControl(false); -} - -bool AlipayPresenter::OnDrag(UIView &view, const DragEvent &event) -{ - if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && - (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - view_->DropView(view); - } - if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) { - view_->SwitchView(view); - } - return true; -} - -void AlipayPresenter::ClickExitAlipay(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickExitAlipay start"); - AlipayModel::GetInstance()->AlipayFinishBind(); - NativeAbility::GetInstance().Back(); - return; -} - -void AlipayPresenter::ClickJumpPay(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickPromptWear start"); - view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_PAY_VIEW); - return; -} - -/** - * @brief 点击跳转到交通卡相关视图的处理函数 - * - * 当用户点击跳转到交通卡相关视图的按钮时,此函数会被调用。 - * 它会尝试获取本地交通卡交易列表,根据获取结果决定跳转到不同的视图。 - * - * @param view 被点击的视图对象 - */ -void AlipayPresenter::ClickJumpTrans(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpTrans start"); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "点击跳转到交通卡相关视图的操作开始"); - int32_t ret = alipayMode_->AlipayGetLocalTranslist(); //获取本地交通卡交易列表 - if (ret != 0) { //获取本地交通卡交易列表失败 - AlipaySetSwitchIndex(ALIPAY_TRANS_GET_LIST_FIRST); //设置切换索引为首次获取交通卡交易列表 - view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_GET_TRANS_LIST_VIEW); //将当前视图从列表视图切换到获取交通卡交易列表视图 - } else if (ret == 0) { - int32_t get_res = alipayMode_->AlipayGetLastTranscode(); //从支付宝获取最后一次交易的交易码 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpTrans get_res:%d", get_res); - if (get_res == 0) { - view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_TRANS_VIEW); - } else { - view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_TRANS_LIST_VIEW); - } - } - return; -} - -void AlipayPresenter::ClickRefreshList(UIView &view) -{ - //刷新交通卡列表 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickRefreshList start"); - alipayMode_->AlipaySendMsg(ALIPAY_MSG_UPDATA_TRANS_LIST); - view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_ANI_VIEW); - return; -} - -void AlipayPresenter::ClickBackList(UIView &view) -{ - //获取乘车码列表视图退回到列表视图 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickBackList start"); - view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_LIST_VIEW); - return; -} - -void AlipayPresenter::ClickUpdateList(UIView &view) -{ - //获取交通卡列表 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickUpdateList start"); - // 发送更新交通卡列表的消息 - alipayMode_->AlipaySendMsg(ALIPAY_MSG_UPDATA_TRANS_LIST); - // 从获取交通卡列表视图切换到交通卡动画视图 - view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_TRANS_ANI_VIEW); - return; -} - -void AlipayPresenter::ClickTransJumpHelp(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransJumpHelp start"); - view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_HELP_VIEW); - return; -} - -void AlipayPresenter::ClickTranstBackList(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTranstBackList start"); - int16_t currentView = alipayMode_->GetAlipayInterLis(); - view_->ChangeView(currentView, ALIPAY_LIST_VIEW); - return; -} - -void AlipayPresenter::ClickTransToTransList(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransJumpHelp start"); - int16_t currentView = alipayMode_->GetAlipayInterLis(); - view_->ChangeView(currentView, ALIPAY_TRANS_LIST_VIEW); - return; -} -void AlipayPresenter::ClickTransToAlipayBind(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransJumpHelp start"); - AlipayModel::GetInstance()->AlipayUnbind();//调用解绑接口 - int16_t currentView = alipayMode_->GetAlipayInterLis(); - view_->ChangeView(currentView, ALIPAY_BIND_VIEW); - return; -} - -//点击刷新按钮 -void AlipayPresenter::ClickTransToTransCode(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransToTransCode start"); - AlipayTransListItemView *alipayTransListItemView = static_cast(&view); - uint32_t index = alipayTransListItemView->GetAlipayTransListIndex(); - if (index >= AlipayGetCardSum()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransToTransCode index error:%u", index); - return; - } - AlipaySetCardNum(index); - int32_t ret = alipayMode_->AlipayCheckTransCard(index); - if (ret != 0) { - alipayMode_->AlipaySendMsg(ALIPAY_MSG_UPDATA_SPECIAL_CARD); - view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_ANI_VIEW); - return; - } - - ret = alipayMode_->AlipayGetTransCode(index); - if (ret == 0) { - view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_VIEW); - } else if (ret == ALIPAY_TRANS_CODE_NET_ERROR) { - AlipaySetSwitchIndex(ALIPAY_TRANS_RES_CODE); - view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_RES_VIEW); - } else { - if (ret == ALIPAY_TRANS_CODE_DATA_LIMIT) { - AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_SECURE); - } else if (ret == ALIPAY_TRANS_CODE_NOT_SUPPORT) { - AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_NOT_SUPPORT); - } else { - AlipayModel::GetInstance()->AlipaySetSpecificErrorCode(ret); - AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_LIST_UNKNOW); - } - view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_TIPS_VIEW); - } - return; -} - -/// @brief 处理用户点击重试获取支付宝交易码 -/// @param view -void AlipayPresenter::ClickRetryTransCode(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickRetryTransCode start"); - uint32_t index = AlipayGetCardNum(); //获取当前选中的交通卡索引 - int32_t ret = alipayMode_->AlipayGetTransCode(index); //尝试重新获取交易码 - if (ret == 0) { - view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_TRANS_VIEW); //成功获取交易码,跳转到交易码视图 - } else if (ret == ALIPAY_TRANS_CODE_NET_ERROR) { - AlipaySetSwitchIndex(ALIPAY_TRANS_RES_CODE); - view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_TRANS_RES_VIEW); //网络错误,跳转到交易码获取失败视图 - } else { - if (ret == ALIPAY_TRANS_CODE_DATA_LIMIT) { - AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_SECURE); //数据限制错误:设置安全提示 - } else if (ret == ALIPAY_TRANS_CODE_NOT_SUPPORT) { - AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_NOT_SUPPORT); //不支持的错误:设置不支持提示 - } else { - AlipayModel::GetInstance()->AlipaySetSpecificErrorCode(ret); - AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_LIST_UNKNOW); //未知错误:设置未知错误提示 - } - view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_TRANS_TIPS_VIEW); //切换到相应的错误提示视图 - } - return; -} - -void AlipayPresenter::ClickTransJumpGetList(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransJumpGetList start"); - AlipaySetSwitchIndex(ALIPAY_TRANS_GET_LIST_CLICK_DETAIL); - view_->ChangeView(ALIPAY_TRANS_RES_VIEW, ALIPAY_GET_TRANS_LIST_VIEW); - return; -} - -void AlipayPresenter::ClickTransJumpGetCode(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransJumpGetCode start"); - AlipaySetSwitchIndex(ALIPAY_TRANS_GET_LIST_CODE_DETAIL); - view_->ChangeView(ALIPAY_TRANS_RES_VIEW, ALIPAY_GET_TRANS_LIST_VIEW); - return; -} - -void AlipayPresenter::ClickTransCodeBackList(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransCodeBackList start"); - view_->ChangeView(ALIPAY_TRANS_VIEW, ALIPAY_TRANS_LIST_VIEW); - return; -} - -void AlipayPresenter::ClickJumpSetting(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpSetting start"); - view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_SETTING_VIEW); - return; -} - -void AlipayPresenter::ClickJumpHelp(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpHelp start"); - view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_HELP_VIEW); - return; -} - -void AlipayPresenter::ClickJumpBindAni(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpBindAni start"); - view_->ChangeView(ALIPAY_BIND_EXIT_VIEW, ALIPAY_BIND_ANI_VIEW); - return; -} - -void AlipayPresenter::ClickJumpUnbind(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpUnbind start"); - view_->ChangeView(ALIPAY_SETTING_VIEW, ALIPAY_SETTING_UNBIND_VIEW); - return; -} - -void AlipayPresenter::ClickJumpBindFinish(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpBindFinish start"); - view_->ChangeView(ALIPAY_SETTING_UNBIND_VIEW, ALIPAY_SETTING_FINISH_VIEW); - return; -} - -void AlipayPresenter::ClickBackUnbind(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickBackUnbind start"); - view_->ChangeView(ALIPAY_SETTING_UNBIND_VIEW, ALIPAY_SETTING_VIEW); - return; -} - -void AlipayPresenter::ClickBackBindCode(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickBackBindCode start"); - view_->ChangeView(ALIPAY_SETTING_FINISH_VIEW, ALIPAY_BIND_VIEW); - return; -} - -void AlipayPresenter::ClickRefreshQrcode(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickRefreshQrcode start"); - AlipayPayCode *alipayPayCodeView = AlipayPayCode::GetInstance(); - if (alipayPayCodeView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "AlipayPresenter::ClickRefreshQrcode AlipayPayCode::GetInstance() nullptr"); - return; - } - alipayMode_->AlipayStartSwitchTimer(60000); - uint8_t str[ALIPAY_GET_PAY_STR_MAX_LENGTH] = {0}; - AlipayGetPayCode(str); - alipayPayCodeView->AlipayRefreshQrcode((const char *)str); - return; -} - -void AlipayPresenter::ClickRefreshBarcode(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickRefreshBarcode start"); - AlipayBarCode *alipayBarCodeView = AlipayBarCode::GetInstance(); - if (alipayBarCodeView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "AlipayPresenter::ClickRefreshBarcode AlipayBarCode::GetInstance() nullptr"); - return; - } - alipayMode_->AlipayStartSwitchTimer(60000); - uint8_t str[ALIPAY_GET_PAY_STR_MAX_LENGTH] = {0}; - AlipayGetPayCode(str); - alipayBarCodeView->AlipayRefreshBarcode((const char *)str); - - return; -} - -void AlipayPresenter::ClickGetBindStr(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickGetBindStr start"); - uint8_t str[ALIPAY_GET_BIND_STR_MAX_LENGTH] = {0}; - int32_t ret = AlipayGetBindCode(str); - if (ret == 0) { - view_->ChangeView(ALIPAY_GET_BIND_FAILURE_VIEW, ALIPAY_BIND_VIEW); - } - return; -} - -void AlipayPresenter::ClickSwitchBar(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickSwitchBar start"); - view_->ChangeView(ALIPAY_PAY_VIEW, ALIPAY_PAY_BARCODE_VIEW); - return; -} - -void AlipayPresenter::ClickSwitchQr(UIView &view) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickSwitchQR start"); - view_->ChangeView(ALIPAY_PAY_BARCODE_VIEW, ALIPAY_PAY_VIEW); - return; -} - -struct AlipayPresentMapper1 { - const char *viewId; - void (AlipayPresenter::*func)(UIView &view); -}; - -static const AlipayPresentMapper1 PresentMapper[] = { - {ALIPAY_INTER_EXIT, &AlipayPresenter::ClickExitAlipay}, - {ALIPAY_LIST_PAY_BUTTON, &AlipayPresenter::ClickJumpPay}, - {ALIPAY_PAY_SWITCH_BAR, &AlipayPresenter::ClickSwitchBar}, - {ALIPAY_PAY_SWITCH_QR, &AlipayPresenter::ClickSwitchQr}, - {ALIPAY_LIST_SETTING_BUTTON, &AlipayPresenter::ClickJumpSetting}, - {ALIPAY_LIST_HELP_BUTTON, &AlipayPresenter::ClickJumpHelp}, - {ALIPAY_BIND_CONTINUE, &AlipayPresenter::ClickJumpBindAni}, - {ALIPAY_UNBIND_BUTTON, &AlipayPresenter::ClickJumpUnbind}, - {ALIPAY_SETTING_UNBIND, &AlipayPresenter::ClickJumpBindFinish}, - {ALIPAY_SETTING_CANCEL, &AlipayPresenter::ClickBackUnbind}, - {ALIPAY_SETTING_FINISH, &AlipayPresenter::ClickBackBindCode}, - {ALIPAY_PAY_QRCODE, &AlipayPresenter::ClickRefreshQrcode}, - {ALIPAY_BIND_BUTTON, &AlipayPresenter::ClickGetBindStr}, - {ALIPAY_PAY_BARCODE, &AlipayPresenter::ClickRefreshBarcode}, - {ALIPAY_LIST_TRANS_BUTTON, &AlipayPresenter::ClickJumpTrans}, - {ALIPAY_TRANS_REFRESH_LIST, &AlipayPresenter::ClickRefreshList}, - {ALIPAY_TRANS_GET_LIST_EXIT, &AlipayPresenter::ClickBackList}, - {ALIPAY_TRANS_GET_LIST_FINISH, &AlipayPresenter::ClickUpdateList}, - {ALIPAY_TRANS_GET_LIST_DETAIL, &AlipayPresenter::ClickTransJumpHelp}, - {ALIPAY_TRANS_CERTAIN_BACK_LIST, &AlipayPresenter::ClickTranstBackList}, - {ALIPAY_TRANS_CERTAIN_TO_TRANS, &AlipayPresenter::ClickTransToTransList}, - {ALIPAY_TRANS_CERTAIN_TO_BIND, &AlipayPresenter::ClickTransToAlipayBind}, - {ALIPAY_TRANS_LIST_BUTTON, &AlipayPresenter::ClickTransToTransCode}, - {ALIPAY_TRANS_RETRY_TRANS_CODE, &AlipayPresenter::ClickRetryTransCode}, - {ALIPAY_TRANS_LIST_RES_DETAIL, &AlipayPresenter::ClickTransJumpGetList}, - {ALIPAY_TRANS_CODE_RES_DETAIL, &AlipayPresenter::ClickTransJumpGetCode}, - {ALIPAY_TRANS_CODE_BACK_LIST, &AlipayPresenter::ClickTransCodeBackList}, -}; - -bool AlipayPresenter::ClickFuncId(UIView &view) -{ - if (view.GetViewId() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickFuncId buttonName nullptr error!"); - return false; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickFuncId buttonName = %s", view.GetViewId()); - for (uint16 i = 0; i < sizeof(PresentMapper) / sizeof(PresentMapper[0]); i++) { - if (strcmp(view.GetViewId(), PresentMapper[i].viewId) == 0) { - (this->*(PresentMapper[i].func))(view); - return true; - } - } - return false; -} - -bool AlipayPresenter::OnClick(UIView &view, const ClickEvent &event) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::OnClick %s", view.GetViewId()); - UNUSED(event); - - ClickFuncId(view); - return true; -} - -bool AlipayPresenter::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 == 1 && uapi_get_screen_state() == 0) - { - view_->DropView(0); - - } - return true; - -} - -int32_t AlipayPresenter::AlipayGetPayCode(uint8_t *payStr) -{ - return alipayMode_->AlipayGetPayCode(payStr); -} - -int32_t AlipayPresenter::AlipayGetNickName(uint8_t *nickName) -{ - return alipayMode_->AlipayGetNickName(nickName); -} - -int32_t AlipayPresenter::AlipayGetBindCode(uint8_t *bindStr) -{ - return alipayMode_->AlipayGetBindCode(bindStr); -} - -int32_t AlipayPresenter::AlipayGetIdName(uint8_t *idStr) -{ - return alipayMode_->AlipayGetIdName(idStr); -} - -//通过获取帮助码串生成二维码 -int32_t AlipayPresenter::AlipayGetAidCode(int8_t *aidStr) -{ - return alipayMode_->AlipayGetAidCode(aidStr); -} - -bool AlipayPresenter::AlipayGetBindFlag(void) -{ - return alipayMode_->AlipayGetBindFlag(); -} - -void AlipayPresenter::AlipaySetBindFlag(bool bindFlag) -{ - alipayMode_->AlipaySetBindFlag(bindFlag); -} - -uint32_t AlipayPresenter::AlipayGetSwitchIndex(void) -{ - return alipayMode_->AlipayGetSwitchIndex(); -} -void AlipayPresenter::AlipaySetSwitchIndex(uint32_t switchIndex) -{ - alipayMode_->AlipaySetSwitchIndex(switchIndex); -} - -//获取 -uint32_t AlipayPresenter::AlipayGetCardNum(void) -{ - return alipayMode_->AlipayGetCardNum(); -} - -void AlipayPresenter::AlipaySetCardNum(uint32_t cardNum) -{ - alipayMode_->AlipaySetCardNum(cardNum); -} - -uint32_t AlipayPresenter::AlipayGetCardSum(void) -{ - return alipayMode_->AlipayGetCardSum(); -} - -void AlipayPresenter::AlipaySetCardSum(uint32_t cardSum) -{ - alipayMode_->AlipaySetCardSum(cardSum); -} - -char* AlipayPresenter::AlipayGetCardTitle(uint32_t index) -{ - return alipayMode_->AlipayGetCardTitle(index); -} - -uint8_t* AlipayPresenter::AlipayGetTransCode(void) -{ - return alipayMode_->AlipayGetTransCode(); -} - -uint32_t AlipayPresenter::AlipayGetTransCodeLen(void) -{ - return alipayMode_->AlipayGetTransCodeLen(); -} - -char* AlipayPresenter::AlipayGetCardTitle(void) -{ - return alipayMode_->AlipayGetCardTitle(); -} - +/** + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: alipay presenter. + * Author: + * Create: + */ + +#include "alipay/include/AlipayPresenter.h" +#include "alipay/include/AlipayMainView.h" +#include "ChangeSliceListener.h" +#include "graphic_service.h" +#include "string" +#include "iostream" +#include "sstream" +#include "errcode.h" +#include "pm_definition.h" +#include "alipay/include/AlipayList/AlipayListView.h" +#include "alipay/include/AlipayList/AlipayListItemView.h" +#include "alipay/include/AlipayTrans/AlipayTransListItemView.h" +#include "alipay/include/AlipayTrans/AlipayTransListView.h" +#include "NativeRegisterManager.h" +#include "custom_utils.h" +#include "common/key_code.h" +#include "gfx_utils/mem_check.h" +#include "alipay/include/AlipayC.h" +#include "ui_resource_string.h" +#include "AbilityNavigationApi.h" + +namespace OHOS { + +// REGIST_MENU_PRO(VIEW_MAIN_ALIPAY, AlipayMainView, AlipayPresenter, +// PNG_APPLIST_ALIPAY_IMAGE_BIG, PNG_APPLIST_ALIPAY_IMAGE,PNG_APPLIST_ALIPAY_IMAGE, "支付宝", STR_ALIPAY); + + #ifdef __cplusplus + extern "C" + { +#endif + +#include "pm.h" +#include "pm_veto.h" + + void remove_ALIPAY_vote(void) + { + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_ALIPAY); + if (cnt == 1) + { + uapi_pm_remove_sleep_veto(PM_ID_ALIPAY); + } + } + + void add_ALIPAY_vote(void) + { + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_ALIPAY); + if (cnt == 0) + { + uapi_pm_add_sleep_veto(PM_ID_ALIPAY); + } + } + +#ifdef __cplusplus + } +#endif + +static AlipayPresenter *g_alipayPresenter = nullptr; + +ColorType AlipayPresenter::CyanColor() +{ + return Color::GetColorFromRGB(0x1C, 0xF4, 0xED); +} + +AlipayPresenter::AlipayPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter new"); + alipayMode_ = AlipayModel::GetInstance(); + g_alipayPresenter = this; +} + +AlipayPresenter::~AlipayPresenter() +{ + g_alipayPresenter = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::~AlipayPresenter"); +} + +AlipayPresenter *AlipayPresenter::GetInstance() +{ + return g_alipayPresenter; +} + +void AlipayPresenter::OnStart() +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter OnStart"); + if(Alipay_is_init()==false) + return; + /* -------------------------------- 设置支付宝界面常亮 ------------------------------- */ + add_ALIPAY_vote(); + alipayMode_->AlipayScreenControl(true); + /* -------------------------------------------------------------------------- */ + alipayMode_->AlipayExitLpm(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " alipayMode_->AlipayExitLpm()"); + + if (!alipayMode_->AlipayInitModel()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::OnStart AlipayInitModel fail."); + OHOS::AbilityNavigation::Back(); + return; + } +} + +void AlipayPresenter::OnResume(void) +{ + svr_alipay_create_task(); + // 增加按键监听 + RootView::GetInstance()->SetOnKeyActListener(this); +} + +void AlipayPresenter::OnStop(void) +{ + + /**关闭alipay蓝牙服务*/ + stop_alipay_ble_service(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter OnStop"); + svr_alipay_destroy_task(); + alipayMode_->AlipayDeinitModel(); + alipayMode_->AlipayEnterLpm(); + /* -------------------------------- 恢复屏幕保持亮屏的时间 ------------------------------- */ + remove_ALIPAY_vote(); + alipayMode_->AlipayScreenControl(false); +} + +bool AlipayPresenter::OnDrag(UIView &view, const DragEvent &event) +{ + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + view_->DropView(view); + } + if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) { + view_->SwitchView(view); + } + return true; +} + +void AlipayPresenter::ClickExitAlipay(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickExitAlipay start"); + AlipayModel::GetInstance()->AlipayFinishBind(); + OHOS::AbilityNavigation::Back(); + return; +} + +void AlipayPresenter::ClickJumpPay(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickPromptWear start"); + view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_PAY_VIEW); + return; +} + +/** + * @brief 点击跳转到交通卡相关视图的处理函数 + * + * 当用户点击跳转到交通卡相关视图的按钮时,此函数会被调用。 + * 它会尝试获取本地交通卡交易列表,根据获取结果决定跳转到不同的视图。 + * + * @param view 被点击的视图对象 + */ +void AlipayPresenter::ClickJumpTrans(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpTrans start"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "点击跳转到交通卡相关视图的操作开始"); + int32_t ret = alipayMode_->AlipayGetLocalTranslist(); //获取本地交通卡交易列表 + if (ret != 0) { //获取本地交通卡交易列表失败 + AlipaySetSwitchIndex(ALIPAY_TRANS_GET_LIST_FIRST); //设置切换索引为首次获取交通卡交易列表 + view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_GET_TRANS_LIST_VIEW); //将当前视图从列表视图切换到获取交通卡交易列表视图 + } else if (ret == 0) { + int32_t get_res = alipayMode_->AlipayGetLastTranscode(); //从支付宝获取最后一次交易的交易码 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpTrans get_res:%d", get_res); + if (get_res == 0) { + view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_TRANS_VIEW); + } else { + view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_TRANS_LIST_VIEW); + } + } + return; +} + +void AlipayPresenter::ClickRefreshList(UIView &view) +{ + //刷新交通卡列表 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickRefreshList start"); + alipayMode_->AlipaySendMsg(ALIPAY_MSG_UPDATA_TRANS_LIST); + view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_ANI_VIEW); + return; +} + +void AlipayPresenter::ClickBackList(UIView &view) +{ + //获取乘车码列表视图退回到列表视图 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickBackList start"); + view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_LIST_VIEW); + return; +} + +void AlipayPresenter::ClickUpdateList(UIView &view) +{ + //获取交通卡列表 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickUpdateList start"); + // 发送更新交通卡列表的消息 + alipayMode_->AlipaySendMsg(ALIPAY_MSG_UPDATA_TRANS_LIST); + // 从获取交通卡列表视图切换到交通卡动画视图 + view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_TRANS_ANI_VIEW); + return; +} + +void AlipayPresenter::ClickTransJumpHelp(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransJumpHelp start"); + view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_HELP_VIEW); + return; +} + +void AlipayPresenter::ClickTranstBackList(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTranstBackList start"); + int16_t currentView = alipayMode_->GetAlipayInterLis(); + view_->ChangeView(currentView, ALIPAY_LIST_VIEW); + return; +} + +void AlipayPresenter::ClickTransToTransList(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransJumpHelp start"); + int16_t currentView = alipayMode_->GetAlipayInterLis(); + view_->ChangeView(currentView, ALIPAY_TRANS_LIST_VIEW); + return; +} +void AlipayPresenter::ClickTransToAlipayBind(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransJumpHelp start"); + AlipayModel::GetInstance()->AlipayUnbind();//调用解绑接口 + int16_t currentView = alipayMode_->GetAlipayInterLis(); + view_->ChangeView(currentView, ALIPAY_BIND_VIEW); + return; +} + +//点击刷新按钮 +void AlipayPresenter::ClickTransToTransCode(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransToTransCode start"); + AlipayTransListItemView *alipayTransListItemView = static_cast(&view); + uint32_t index = alipayTransListItemView->GetAlipayTransListIndex(); + if (index >= AlipayGetCardSum()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransToTransCode index error:%u", index); + return; + } + AlipaySetCardNum(index); + int32_t ret = alipayMode_->AlipayCheckTransCard(index); + if (ret != 0) { + alipayMode_->AlipaySendMsg(ALIPAY_MSG_UPDATA_SPECIAL_CARD); + view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_ANI_VIEW); + return; + } + + ret = alipayMode_->AlipayGetTransCode(index); + if (ret == 0) { + view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_VIEW); + } else if (ret == ALIPAY_TRANS_CODE_NET_ERROR) { + AlipaySetSwitchIndex(ALIPAY_TRANS_RES_CODE); + view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_RES_VIEW); + } else { + if (ret == ALIPAY_TRANS_CODE_DATA_LIMIT) { + AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_SECURE); + } else if (ret == ALIPAY_TRANS_CODE_NOT_SUPPORT) { + AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_NOT_SUPPORT); + } else { + AlipayModel::GetInstance()->AlipaySetSpecificErrorCode(ret); + AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_LIST_UNKNOW); + } + view_->ChangeView(ALIPAY_TRANS_LIST_VIEW, ALIPAY_TRANS_TIPS_VIEW); + } + return; +} + +/// @brief 处理用户点击重试获取支付宝交易码 +/// @param view +void AlipayPresenter::ClickRetryTransCode(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickRetryTransCode start"); + uint32_t index = AlipayGetCardNum(); //获取当前选中的交通卡索引 + int32_t ret = alipayMode_->AlipayGetTransCode(index); //尝试重新获取交易码 + if (ret == 0) { + view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_TRANS_VIEW); //成功获取交易码,跳转到交易码视图 + } else if (ret == ALIPAY_TRANS_CODE_NET_ERROR) { + AlipaySetSwitchIndex(ALIPAY_TRANS_RES_CODE); + view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_TRANS_RES_VIEW); //网络错误,跳转到交易码获取失败视图 + } else { + if (ret == ALIPAY_TRANS_CODE_DATA_LIMIT) { + AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_SECURE); //数据限制错误:设置安全提示 + } else if (ret == ALIPAY_TRANS_CODE_NOT_SUPPORT) { + AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_NOT_SUPPORT); //不支持的错误:设置不支持提示 + } else { + AlipayModel::GetInstance()->AlipaySetSpecificErrorCode(ret); + AlipaySetSwitchIndex(ALIPAY_TRANS_TIPS_LIST_UNKNOW); //未知错误:设置未知错误提示 + } + view_->ChangeView(ALIPAY_GET_TRANS_LIST_VIEW, ALIPAY_TRANS_TIPS_VIEW); //切换到相应的错误提示视图 + } + return; +} + +void AlipayPresenter::ClickTransJumpGetList(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransJumpGetList start"); + AlipaySetSwitchIndex(ALIPAY_TRANS_GET_LIST_CLICK_DETAIL); + view_->ChangeView(ALIPAY_TRANS_RES_VIEW, ALIPAY_GET_TRANS_LIST_VIEW); + return; +} + +void AlipayPresenter::ClickTransJumpGetCode(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransJumpGetCode start"); + AlipaySetSwitchIndex(ALIPAY_TRANS_GET_LIST_CODE_DETAIL); + view_->ChangeView(ALIPAY_TRANS_RES_VIEW, ALIPAY_GET_TRANS_LIST_VIEW); + return; +} + +void AlipayPresenter::ClickTransCodeBackList(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickTransCodeBackList start"); + view_->ChangeView(ALIPAY_TRANS_VIEW, ALIPAY_TRANS_LIST_VIEW); + return; +} + +void AlipayPresenter::ClickJumpSetting(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpSetting start"); + view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_SETTING_VIEW); + return; +} + +void AlipayPresenter::ClickJumpHelp(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpHelp start"); + view_->ChangeView(ALIPAY_LIST_VIEW, ALIPAY_HELP_VIEW); + return; +} + +void AlipayPresenter::ClickJumpBindAni(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpBindAni start"); + view_->ChangeView(ALIPAY_BIND_EXIT_VIEW, ALIPAY_BIND_ANI_VIEW); + return; +} + +void AlipayPresenter::ClickJumpUnbind(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpUnbind start"); + view_->ChangeView(ALIPAY_SETTING_VIEW, ALIPAY_SETTING_UNBIND_VIEW); + return; +} + +void AlipayPresenter::ClickJumpBindFinish(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickJumpBindFinish start"); + view_->ChangeView(ALIPAY_SETTING_UNBIND_VIEW, ALIPAY_SETTING_FINISH_VIEW); + return; +} + +void AlipayPresenter::ClickBackUnbind(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickBackUnbind start"); + view_->ChangeView(ALIPAY_SETTING_UNBIND_VIEW, ALIPAY_SETTING_VIEW); + return; +} + +void AlipayPresenter::ClickBackBindCode(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickBackBindCode start"); + view_->ChangeView(ALIPAY_SETTING_FINISH_VIEW, ALIPAY_BIND_VIEW); + return; +} + +void AlipayPresenter::ClickRefreshQrcode(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickRefreshQrcode start"); + AlipayPayCode *alipayPayCodeView = AlipayPayCode::GetInstance(); + if (alipayPayCodeView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AlipayPresenter::ClickRefreshQrcode AlipayPayCode::GetInstance() nullptr"); + return; + } + alipayMode_->AlipayStartSwitchTimer(60000); + uint8_t str[ALIPAY_GET_PAY_STR_MAX_LENGTH] = {0}; + AlipayGetPayCode(str); + alipayPayCodeView->AlipayRefreshQrcode((const char *)str); + return; +} + +void AlipayPresenter::ClickRefreshBarcode(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickRefreshBarcode start"); + AlipayBarCode *alipayBarCodeView = AlipayBarCode::GetInstance(); + if (alipayBarCodeView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AlipayPresenter::ClickRefreshBarcode AlipayBarCode::GetInstance() nullptr"); + return; + } + alipayMode_->AlipayStartSwitchTimer(60000); + uint8_t str[ALIPAY_GET_PAY_STR_MAX_LENGTH] = {0}; + AlipayGetPayCode(str); + alipayBarCodeView->AlipayRefreshBarcode((const char *)str); + + return; +} + +void AlipayPresenter::ClickGetBindStr(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickGetBindStr start"); + uint8_t str[ALIPAY_GET_BIND_STR_MAX_LENGTH] = {0}; + int32_t ret = AlipayGetBindCode(str); + if (ret == 0) { + view_->ChangeView(ALIPAY_GET_BIND_FAILURE_VIEW, ALIPAY_BIND_VIEW); + } + return; +} + +void AlipayPresenter::ClickSwitchBar(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickSwitchBar start"); + view_->ChangeView(ALIPAY_PAY_VIEW, ALIPAY_PAY_BARCODE_VIEW); + return; +} + +void AlipayPresenter::ClickSwitchQr(UIView &view) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickSwitchQR start"); + view_->ChangeView(ALIPAY_PAY_BARCODE_VIEW, ALIPAY_PAY_VIEW); + return; +} + +struct AlipayPresentMapper1 { + const char *viewId; + void (AlipayPresenter::*func)(UIView &view); +}; + +static const AlipayPresentMapper1 PresentMapper[] = { + {ALIPAY_INTER_EXIT, &AlipayPresenter::ClickExitAlipay}, + {ALIPAY_LIST_PAY_BUTTON, &AlipayPresenter::ClickJumpPay}, + {ALIPAY_PAY_SWITCH_BAR, &AlipayPresenter::ClickSwitchBar}, + {ALIPAY_PAY_SWITCH_QR, &AlipayPresenter::ClickSwitchQr}, + {ALIPAY_LIST_SETTING_BUTTON, &AlipayPresenter::ClickJumpSetting}, + {ALIPAY_LIST_HELP_BUTTON, &AlipayPresenter::ClickJumpHelp}, + {ALIPAY_BIND_CONTINUE, &AlipayPresenter::ClickJumpBindAni}, + {ALIPAY_UNBIND_BUTTON, &AlipayPresenter::ClickJumpUnbind}, + {ALIPAY_SETTING_UNBIND, &AlipayPresenter::ClickJumpBindFinish}, + {ALIPAY_SETTING_CANCEL, &AlipayPresenter::ClickBackUnbind}, + {ALIPAY_SETTING_FINISH, &AlipayPresenter::ClickBackBindCode}, + {ALIPAY_PAY_QRCODE, &AlipayPresenter::ClickRefreshQrcode}, + {ALIPAY_BIND_BUTTON, &AlipayPresenter::ClickGetBindStr}, + {ALIPAY_PAY_BARCODE, &AlipayPresenter::ClickRefreshBarcode}, + {ALIPAY_LIST_TRANS_BUTTON, &AlipayPresenter::ClickJumpTrans}, + {ALIPAY_TRANS_REFRESH_LIST, &AlipayPresenter::ClickRefreshList}, + {ALIPAY_TRANS_GET_LIST_EXIT, &AlipayPresenter::ClickBackList}, + {ALIPAY_TRANS_GET_LIST_FINISH, &AlipayPresenter::ClickUpdateList}, + {ALIPAY_TRANS_GET_LIST_DETAIL, &AlipayPresenter::ClickTransJumpHelp}, + {ALIPAY_TRANS_CERTAIN_BACK_LIST, &AlipayPresenter::ClickTranstBackList}, + {ALIPAY_TRANS_CERTAIN_TO_TRANS, &AlipayPresenter::ClickTransToTransList}, + {ALIPAY_TRANS_CERTAIN_TO_BIND, &AlipayPresenter::ClickTransToAlipayBind}, + {ALIPAY_TRANS_LIST_BUTTON, &AlipayPresenter::ClickTransToTransCode}, + {ALIPAY_TRANS_RETRY_TRANS_CODE, &AlipayPresenter::ClickRetryTransCode}, + {ALIPAY_TRANS_LIST_RES_DETAIL, &AlipayPresenter::ClickTransJumpGetList}, + {ALIPAY_TRANS_CODE_RES_DETAIL, &AlipayPresenter::ClickTransJumpGetCode}, + {ALIPAY_TRANS_CODE_BACK_LIST, &AlipayPresenter::ClickTransCodeBackList}, +}; + +bool AlipayPresenter::ClickFuncId(UIView &view) +{ + if (view.GetViewId() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickFuncId buttonName nullptr error!"); + return false; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::ClickFuncId buttonName = %s", view.GetViewId()); + for (uint16 i = 0; i < sizeof(PresentMapper) / sizeof(PresentMapper[0]); i++) { + if (strcmp(view.GetViewId(), PresentMapper[i].viewId) == 0) { + (this->*(PresentMapper[i].func))(view); + return true; + } + } + return false; +} + +bool AlipayPresenter::OnClick(UIView &view, const ClickEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::OnClick %s", view.GetViewId()); + UNUSED(event); + + ClickFuncId(view); + return true; +} + +bool AlipayPresenter::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 == 1 && uapi_get_screen_state() == 0) + { + view_->DropView(0); + + } + return true; + +} + +int32_t AlipayPresenter::AlipayGetPayCode(uint8_t *payStr) +{ + return alipayMode_->AlipayGetPayCode(payStr); +} + +int32_t AlipayPresenter::AlipayGetNickName(uint8_t *nickName) +{ + return alipayMode_->AlipayGetNickName(nickName); +} + +int32_t AlipayPresenter::AlipayGetBindCode(uint8_t *bindStr) +{ + return alipayMode_->AlipayGetBindCode(bindStr); +} + +int32_t AlipayPresenter::AlipayGetIdName(uint8_t *idStr) +{ + return alipayMode_->AlipayGetIdName(idStr); +} + +//通过获取帮助码串生成二维码 +int32_t AlipayPresenter::AlipayGetAidCode(int8_t *aidStr) +{ + return alipayMode_->AlipayGetAidCode(aidStr); +} + +bool AlipayPresenter::AlipayGetBindFlag(void) +{ + return alipayMode_->AlipayGetBindFlag(); +} + +void AlipayPresenter::AlipaySetBindFlag(bool bindFlag) +{ + alipayMode_->AlipaySetBindFlag(bindFlag); +} + +uint32_t AlipayPresenter::AlipayGetSwitchIndex(void) +{ + return alipayMode_->AlipayGetSwitchIndex(); +} +void AlipayPresenter::AlipaySetSwitchIndex(uint32_t switchIndex) +{ + alipayMode_->AlipaySetSwitchIndex(switchIndex); +} + +//获取 +uint32_t AlipayPresenter::AlipayGetCardNum(void) +{ + return alipayMode_->AlipayGetCardNum(); +} + +void AlipayPresenter::AlipaySetCardNum(uint32_t cardNum) +{ + alipayMode_->AlipaySetCardNum(cardNum); +} + +uint32_t AlipayPresenter::AlipayGetCardSum(void) +{ + return alipayMode_->AlipayGetCardSum(); +} + +void AlipayPresenter::AlipaySetCardSum(uint32_t cardSum) +{ + alipayMode_->AlipaySetCardSum(cardSum); +} + +char* AlipayPresenter::AlipayGetCardTitle(uint32_t index) +{ + return alipayMode_->AlipayGetCardTitle(index); +} + +uint8_t* AlipayPresenter::AlipayGetTransCode(void) +{ + return alipayMode_->AlipayGetTransCode(); +} + +uint32_t AlipayPresenter::AlipayGetTransCodeLen(void) +{ + return alipayMode_->AlipayGetTransCodeLen(); +} + +char* AlipayPresenter::AlipayGetCardTitle(void) +{ + return alipayMode_->AlipayGetCardTitle(); +} + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/applist/src/ApplistPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/applist/src/ApplistPresenter.cpp index 4a68adfa1..1d8bff999 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/applist/src/ApplistPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/applist/src/ApplistPresenter.cpp @@ -23,6 +23,7 @@ #include #include "custom_runtime.h" #include "graphic_service.h" +#include "AbilityNavigationApi.h" namespace OHOS { REGIST_SLICE(VIEW_APPLIST, ApplistView, ApplistPresenter); @@ -79,8 +80,8 @@ REGIST_SLICE(VIEW_APPLIST, ApplistView, ApplistPresenter); AppViewId viewId = itemView->GetViewId(); if (FloatMore(hexagonsView->GetGlobalScale(), 2.0f)) { // 2.0 threshold for beginning transition hexagonsView->StopRotateAnimator(); - // NativeAbility::GetInstance().EnterSlice(viewId, TransitionType::TRANSITION_HEXAGONS); - NativeAbility::GetInstance().EnterSlice(viewId); + // OHOS::AbilityNavigation::EnterSlice(viewId, TransitionType::TRANSITION_HEXAGONS); + OHOS::AbilityNavigation::EnterSlice(viewId); hexagonsView->ClearFocus(); } return true; @@ -169,8 +170,8 @@ REGIST_SLICE(VIEW_APPLIST, ApplistView, ApplistPresenter); if(VIEW_DNOTDISTURB == viewId) return false; } - // NativeAbility::GetInstance().EnterSlice(viewId, type); - NativeAbility::GetInstance().EnterSlice(viewId); + // OHOS::AbilityNavigation::EnterSlice(viewId, type); + OHOS::AbilityNavigation::EnterSlice(viewId); return true; } else if (viewId == VIEW_EXTERN_APP) diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/applist/src/ApplistView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/applist/src/ApplistView.cpp index d36c98cf2..f8c80b0fa 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/applist/src/ApplistView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/applist/src/ApplistView.cpp @@ -418,12 +418,17 @@ void ApplistView::ArcScaleListStyleOnStop(void) presenter_->SetArcListHeadItemY(arclistHeadY); //设置头部Y坐标 presenter_->SetArcListStartIndex(arclistHeadIndex); //设置头部Index } + +} // namespace OHOS (std headers must not be included inside OHOS) + /* -------------------------------------------------------------------------- */ /* ----------------------------------- 拨号盘 ---------------------------------- */ #include -#include "cmath" -#include "vector" +#include +#include + +namespace OHOS { // 圆形表的圆心坐标和半径 static const int CIRCLE_CENTER_X = 233; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/assistant/src/AssistantPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/assistant/src/AssistantPresenter.cpp index 1eac753b9..11ed3d027 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/assistant/src/AssistantPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/assistant/src/AssistantPresenter.cpp @@ -2,6 +2,7 @@ #include "AppViewIDs.h" #include "key/include/KeyInputListener.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include "components/ui_label_ext.h" #include "custom_utils.h" @@ -45,7 +46,7 @@ bool AssistantPresenter::OnDrag(UIView &view, const DragEvent &event) { (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { /*在主界面进行退出*/ if (&view == p_AssistantView->GetAssistantScrollView(ASSISTANT_MAIN_VIEW)) { - NativeAbility::GetInstance().Back( + OHOS::AbilityNavigation::Back( TransitionType::TRANSITION_BACK_TO_HEXAGONS); } /*在其他界面返回主界面*/ @@ -132,7 +133,7 @@ bool AssistantPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back( + OHOS::AbilityNavigation::Back( TransitionType::TRANSITION_BACK_TO_HEXAGONS); } return true; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodDetectionPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodDetectionPresenter.cpp index 0853c8b51..cef871f6f 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodDetectionPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodDetectionPresenter.cpp @@ -10,6 +10,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" @@ -59,7 +60,7 @@ namespace OHOS } void BloodDetectionPresenter::NavigateBack() { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } void BloodDetectionPresenter::OnResume() diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp index eab51e09d..00ba4ae34 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp @@ -18,6 +18,7 @@ #include "ConfigModel.h" #include "main/include/MainViewSample.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #ifdef SUPPORT_BATTERY_SERVICE #include "battery_hal.h" #endif @@ -208,7 +209,7 @@ void BloodOxygenModel::Blood_Result() { case BloodResult::SUCCESS: { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 成功"); Blood_Save(); - NativeAbility::GetInstance().Back(); // 成功 + OHOS::AbilityNavigation::Back(); // 成功 break; } case BloodResult::NOT_WORN: // 未佩戴状态 diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodResultPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodResultPresenter.cpp index d6a15feec..5f4cba13e 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodResultPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/bloodoxygen/src/BloodResultPresenter.cpp @@ -53,6 +53,7 @@ #include "gfx_utils/mem_check.h" #include "NativeRegisterManager.h" #include "uicomponents/UIComponents.h" +#include "AbilityNavigationApi.h" #define BLOODKEYABLE 1 namespace OHOS { @@ -123,7 +124,7 @@ namespace OHOS if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); return true; } return false; @@ -137,7 +138,7 @@ namespace OHOS keyState == 1 && uapi_get_screen_state() == 0) { // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -161,7 +162,7 @@ namespace OHOS } else { - NativeAbility::GetInstance().EnterSlice(VIEW_BLOOD_CHECK); + OHOS::AbilityNavigation::EnterSlice(VIEW_BLOOD_CHECK); } } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodPresenter::OnClick"); diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp index 8e568908a..13bad1ce8 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp @@ -1,262 +1,263 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: BluetoothPresenter view - * Author: - * Create: 2021-10-13 - */ - -#include "wearable_log.h" -#include "UiConfig.h" -#include "bluetooth/include/BluetoothPresenter.h" -#include "bluetooth/include/BluetoothReconnectView.h" -#include "bluetooth/include/MainBluetoothView.h" -#include "UiConfig.h" -#include "bluetooth/include/BluetoothModel.h" -#include "custom_utils.h" -#include "common/key_code.h" - -#include "NativeRegisterManager.h" -namespace OHOS -{ - - REGIST_SLICE(VIEW_BLUETOOTH_EARPHONE, MainBluetoothView, BluetoothPresenter); - -static BluetoothPresenter *g_pBluetoothPresenter = nullptr; - -BluetoothPresenter::BluetoothPresenter() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter new"); - g_pBluetoothPresenter = this; - bluetoothMode_ = BluetoothModel::GetInstance(); -} - -BluetoothPresenter::~BluetoothPresenter() -{ - g_pBluetoothPresenter = nullptr; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::~BluetoothPresenter"); -} - -void BluetoothPresenter::OnStop(void) -{ - BluetoothEarPhoneView *bluetoothEarPhoneView = BluetoothEarPhoneView::GetInstance(); - if (bluetoothEarPhoneView != nullptr) { - bluetoothEarPhoneView->StopBtDiscovery(); - return; - } -} - -void BluetoothPresenter::OnResume() -{ - RootView::GetInstance()->SetOnKeyActListener(this); -} - -BluetoothPresenter *BluetoothPresenter::GetInstance() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter GetInstance"); - return g_pBluetoothPresenter; -} - -void BluetoothPresenter::ClickRescanButton(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_RESCAN_BUTTON"); - // 跳转正在搜索界面 - view_->ChangeView(BLUETOOTHEARLISTVIEW, BLUETOOTHEARPHONEVIEW); -} - -void BluetoothPresenter::ClickNewEquipmentButton(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_NEWEQUIPMENT_BUTTON"); - bluetoothMode_->SetTagReturnToDeviceListView(true); - view_->ChangeView(BLUETOOTHDEVICELISTVIEW, BLUETOOTHEARPHONEVIEW); -} - -//点击取消连接按钮 -void BluetoothPresenter::ClickCancelConnedRequestButton(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_CANCELCONNEDREQUEST_BUTTON"); - BluetoothCaseInfo *caseInfo = bluetoothMode_->GetTempMacValue(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton Addr: %02x%02x%02x%02x%02x%02x", - caseInfo->addr[5], caseInfo->addr[4], caseInfo->addr[3], /* mac下标 0 1 2 3 4 5 */ - caseInfo->addr[2], caseInfo->addr[1], caseInfo->addr[0]); /* mac下标 0 1 2 3 4 5 */ - errcode_t retVal = gap_disconnect_remote_device((const bd_addr_t *)caseInfo->addr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton gap_disconnect_remote_device retVal = %d", retVal); - - bluetoothMode_->SetTagScanDeviceClicked(false); - // 刷新列表 - BluetoothEarListView *bluetoothEarListView = BluetoothEarListView::GetInstance(); - if (bluetoothEarListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton bluetoothEarListView nullptr"); - return; - } - if (bluetoothEarListView->GetScanUIList() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton GetScanUIList nullptr"); - return; - } - bluetoothEarListView->GetScanUIList()->RefreshList(); - bluetoothEarListView->SetCancelConnedRequestButtonRemove(); - bluetoothEarListView->SetTitleLabel("扫描完成"); - - BluetoothItemView *pbItermView = bluetoothMode_->GetConnectionView(); - if (pbItermView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandleBeforeChangeView The GetConnectionView get failed."); - return; - } - pbItermView->ConnectAnimatorStop(); - bluetoothMode_->SetConnectionView(nullptr); - bluetoothEarListView->SetNewEquipmentButtonAdd(); - -} - -//点击取消配对 -void BluetoothPresenter::ClickUnpairButton(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_UNPAIR_BUTTON"); - bluetoothMode_->SetTagConnectNew(false); - BluetoothOptionsView *bluetoothOptionsView = BluetoothOptionsView::GetInstance(); - if (bluetoothOptionsView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothOptionsView GetInstance fail"); - return; - } - bluetoothOptionsView->SetUnpair(); // 取消配对 - // 删除对应设备列表节点 - bd_addr_t bdAddr = bluetoothOptionsView->GetCurrentAddr(); - List &bluetoothCaseList = bluetoothMode_->GetConnedDevicesCase(); - ListNode *node = bluetoothCaseList.Begin(); - if (node == nullptr) { - return; - } - while (node != bluetoothCaseList.End()) { - if ((bdAddr.addr[0] == node->data_.addr[0]) && (bdAddr.addr[1] == node->data_.addr[1]) - && (bdAddr.addr[2] == node->data_.addr[2]) && (bdAddr.addr[3] == node->data_.addr[3]) - && (bdAddr.addr[4] == node->data_.addr[4]) && (bdAddr.addr[5] == node->data_.addr[5])) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bdAddr true"); - bluetoothCaseList.Remove(node); - } - node = node->next_; - } - // 跳转并刷新列表 - view_->ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW); -} - -/*已连接的蓝牙耳机设备视图中【重新连接或断开连接】按钮*/ -void BluetoothPresenter::ClickOptionsOneButton(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_OPTIONONE_BUTTON"); - BluetoothOptionsView *bluetoothOptionsView = BluetoothOptionsView::GetInstance(); - if (bluetoothOptionsView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothOptionsView GetInstance fail"); - return; - } - bluetoothMode_->SetBtStatus(); - if (bluetoothMode_->GetAclConnected()) { - bluetoothMode_->SetTagConnectNew(false); - bluetoothOptionsView->SetBtDisconnect();/*断开与该远程设备的连接*/ - view_->ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW); - } else { - bluetoothMode_->SetTagReconnectJump(true); - // 重连动画 - view_->ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHRECONNECTVIEW); - // 判断是否已有连接 - bd_addr_t *lastAddr = bluetoothMode_->GetLastConnedAddr(); - if (bt_is_acl_connected(lastAddr)) { - bluetoothMode_->SetTagConnectNew(true); - bluetoothOptionsView->SetBtDisconnect(); - } else { - BluetoothCaseInfo *caseInfo = bluetoothMode_->GetTempMacValue(); - errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice((const bd_addr_t *)&caseInfo->addr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickOptionsOneButton ConnectRemoteDevice retVal = %d", retVal); - } - } -} - -void BluetoothPresenter::ClickSuccBackButton(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_SUCC_BACK_BUTTON"); - view_->ChangeView(TIPSSUCCMESSAGEVIEW, BLUETOOTHDEVICELISTVIEW); -} - -void BluetoothPresenter::ClickFailBackButton(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_FAIL_BACK_BUTTON"); - view_->ChangeView(TIPSFAILMESSAGEVIEW, BLUETOOTHEARPHONEVIEW); -} - -void BluetoothPresenter::ClickConnfailBackButton(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_CONN_FAIL_BACK_BUTTON"); - view_->ChangeView(TIPSCONNFAILMESSAGEVIEW, BLUETOOTHRECONNECTVIEW); - BluetoothCaseInfo *caseInfo = bluetoothMode_->GetTempMacValue(); - errcode_t retVal = bluetoothMode_->ConnectRemoteDevice((const bd_addr_t *)&caseInfo->addr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickConnfailBackButton ConnectRemoteDevice retVal = %d", retVal); -} - -bool BluetoothPresenter::OnDrag(UIView& view, const DragEvent& event) -{ - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - int16_t deltaX; - int16_t deltaY; - deltaX = event.GetDeltaX(); - deltaY = event.GetDeltaY(); - if (MATH_ABS(deltaX) >= MATH_ABS(deltaY) && MATH_ABS(deltaX) > 30) { - X_DRAG_FLAG = true; - } - } - return true; -} - -bool BluetoothPresenter::OnDragEnd(UIView& view, const DragEvent& event) -{ - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) { - view_->DropView(view); - X_DRAG_FLAG = false; - } - return true; -} - -bool BluetoothPresenter::OnClick(UIView &view, const ClickEvent &event) -{ - UNUSED(event); - if (strcmp(view.GetViewId(), BLUETOOTH_RESCAN_BUTTON) == 0) { - ClickRescanButton();//扫描出的耳机列表界面中的[重新扫描按钮]被点击 - } else if (strcmp(view.GetViewId(), BLUETOOTH_NEWEQUIPMENT_BUTTON) == 0) { - ClickNewEquipmentButton();//已连接设备列表界面中的[重新扫描按钮]被点击 - } else if (strcmp(view.GetViewId(), BLUETOOTH_CANCELCONNEDREQUEST_BUTTON) == 0) { - ClickCancelConnedRequestButton(); - } else if (strcmp(view.GetViewId(), BLUETOOTH_UNPAIR_BUTTON) == 0) { - ClickUnpairButton();//查看已连接的蓝牙耳机设备界面的[取消配对按]钮被点击 - } else if (strcmp(view.GetViewId(), BLUETOOTH_OPTIONONE_BUTTON) == 0) { - ClickOptionsOneButton(); - } else if (strcmp(view.GetViewId(), BLUETOOTH_SUCC_BACK_BUTTON) == 0) { - ClickSuccBackButton();//点击连接成功的确定按钮 - } else if (strcmp(view.GetViewId(), BLUETOOTH_FAIL_BACK_BUTTON) == 0) { - ClickFailBackButton(); //点击重新搜索按钮 - } else if (strcmp(view.GetViewId(), BLUETOOTH_CONN_FAIL_BACK_BUTTON) == 0) { - ClickConnfailBackButton();//连接失败的重试按钮 - } - return true; -} - -bool BluetoothPresenter::OnKeyAct(UIView &view, const KeyEvent &event) -{ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnKeyAct"); - uint16 keyID = event.GetKeyId(); - uint16 keyState = event.GetState(); - // 如果是power键就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - //如果是按键退出,退出时需要做一些清理工作 - BluetoothEarPhoneView *bluetoothEarPhoneView = BluetoothEarPhoneView::GetInstance(); - if(bluetoothEarPhoneView) - { - bluetoothEarPhoneView->BtAnimatorStop(); //停止搜索动画 - bluetoothEarPhoneView->StopBtDiscovery();//停止定时器 - BluetoothModel::GetInstance()->SetTagConnectView(false); //清除标志位 - BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false); - } - NativeAbility::GetInstance().Back(); - } - return true; -} - - -}; +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: BluetoothPresenter view + * Author: + * Create: 2021-10-13 + */ + +#include "wearable_log.h" +#include "UiConfig.h" +#include "bluetooth/include/BluetoothPresenter.h" +#include "bluetooth/include/BluetoothReconnectView.h" +#include "bluetooth/include/MainBluetoothView.h" +#include "UiConfig.h" +#include "bluetooth/include/BluetoothModel.h" +#include "custom_utils.h" +#include "common/key_code.h" + +#include "NativeRegisterManager.h" +#include "AbilityNavigationApi.h" +namespace OHOS +{ + + REGIST_SLICE(VIEW_BLUETOOTH_EARPHONE, MainBluetoothView, BluetoothPresenter); + +static BluetoothPresenter *g_pBluetoothPresenter = nullptr; + +BluetoothPresenter::BluetoothPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter new"); + g_pBluetoothPresenter = this; + bluetoothMode_ = BluetoothModel::GetInstance(); +} + +BluetoothPresenter::~BluetoothPresenter() +{ + g_pBluetoothPresenter = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::~BluetoothPresenter"); +} + +void BluetoothPresenter::OnStop(void) +{ + BluetoothEarPhoneView *bluetoothEarPhoneView = BluetoothEarPhoneView::GetInstance(); + if (bluetoothEarPhoneView != nullptr) { + bluetoothEarPhoneView->StopBtDiscovery(); + return; + } +} + +void BluetoothPresenter::OnResume() +{ + RootView::GetInstance()->SetOnKeyActListener(this); +} + +BluetoothPresenter *BluetoothPresenter::GetInstance() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter GetInstance"); + return g_pBluetoothPresenter; +} + +void BluetoothPresenter::ClickRescanButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_RESCAN_BUTTON"); + // 跳转正在搜索界面 + view_->ChangeView(BLUETOOTHEARLISTVIEW, BLUETOOTHEARPHONEVIEW); +} + +void BluetoothPresenter::ClickNewEquipmentButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_NEWEQUIPMENT_BUTTON"); + bluetoothMode_->SetTagReturnToDeviceListView(true); + view_->ChangeView(BLUETOOTHDEVICELISTVIEW, BLUETOOTHEARPHONEVIEW); +} + +//点击取消连接按钮 +void BluetoothPresenter::ClickCancelConnedRequestButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_CANCELCONNEDREQUEST_BUTTON"); + BluetoothCaseInfo *caseInfo = bluetoothMode_->GetTempMacValue(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton Addr: %02x%02x%02x%02x%02x%02x", + caseInfo->addr[5], caseInfo->addr[4], caseInfo->addr[3], /* mac下标 0 1 2 3 4 5 */ + caseInfo->addr[2], caseInfo->addr[1], caseInfo->addr[0]); /* mac下标 0 1 2 3 4 5 */ + errcode_t retVal = gap_disconnect_remote_device((const bd_addr_t *)caseInfo->addr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton gap_disconnect_remote_device retVal = %d", retVal); + + bluetoothMode_->SetTagScanDeviceClicked(false); + // 刷新列表 + BluetoothEarListView *bluetoothEarListView = BluetoothEarListView::GetInstance(); + if (bluetoothEarListView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton bluetoothEarListView nullptr"); + return; + } + if (bluetoothEarListView->GetScanUIList() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton GetScanUIList nullptr"); + return; + } + bluetoothEarListView->GetScanUIList()->RefreshList(); + bluetoothEarListView->SetCancelConnedRequestButtonRemove(); + bluetoothEarListView->SetTitleLabel("扫描完成"); + + BluetoothItemView *pbItermView = bluetoothMode_->GetConnectionView(); + if (pbItermView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandleBeforeChangeView The GetConnectionView get failed."); + return; + } + pbItermView->ConnectAnimatorStop(); + bluetoothMode_->SetConnectionView(nullptr); + bluetoothEarListView->SetNewEquipmentButtonAdd(); + +} + +//点击取消配对 +void BluetoothPresenter::ClickUnpairButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_UNPAIR_BUTTON"); + bluetoothMode_->SetTagConnectNew(false); + BluetoothOptionsView *bluetoothOptionsView = BluetoothOptionsView::GetInstance(); + if (bluetoothOptionsView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothOptionsView GetInstance fail"); + return; + } + bluetoothOptionsView->SetUnpair(); // 取消配对 + // 删除对应设备列表节点 + bd_addr_t bdAddr = bluetoothOptionsView->GetCurrentAddr(); + List &bluetoothCaseList = bluetoothMode_->GetConnedDevicesCase(); + ListNode *node = bluetoothCaseList.Begin(); + if (node == nullptr) { + return; + } + while (node != bluetoothCaseList.End()) { + if ((bdAddr.addr[0] == node->data_.addr[0]) && (bdAddr.addr[1] == node->data_.addr[1]) + && (bdAddr.addr[2] == node->data_.addr[2]) && (bdAddr.addr[3] == node->data_.addr[3]) + && (bdAddr.addr[4] == node->data_.addr[4]) && (bdAddr.addr[5] == node->data_.addr[5])) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bdAddr true"); + bluetoothCaseList.Remove(node); + } + node = node->next_; + } + // 跳转并刷新列表 + view_->ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW); +} + +/*已连接的蓝牙耳机设备视图中【重新连接或断开连接】按钮*/ +void BluetoothPresenter::ClickOptionsOneButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_OPTIONONE_BUTTON"); + BluetoothOptionsView *bluetoothOptionsView = BluetoothOptionsView::GetInstance(); + if (bluetoothOptionsView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothOptionsView GetInstance fail"); + return; + } + bluetoothMode_->SetBtStatus(); + if (bluetoothMode_->GetAclConnected()) { + bluetoothMode_->SetTagConnectNew(false); + bluetoothOptionsView->SetBtDisconnect();/*断开与该远程设备的连接*/ + view_->ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW); + } else { + bluetoothMode_->SetTagReconnectJump(true); + // 重连动画 + view_->ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHRECONNECTVIEW); + // 判断是否已有连接 + bd_addr_t *lastAddr = bluetoothMode_->GetLastConnedAddr(); + if (bt_is_acl_connected(lastAddr)) { + bluetoothMode_->SetTagConnectNew(true); + bluetoothOptionsView->SetBtDisconnect(); + } else { + BluetoothCaseInfo *caseInfo = bluetoothMode_->GetTempMacValue(); + errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice((const bd_addr_t *)&caseInfo->addr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickOptionsOneButton ConnectRemoteDevice retVal = %d", retVal); + } + } +} + +void BluetoothPresenter::ClickSuccBackButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_SUCC_BACK_BUTTON"); + view_->ChangeView(TIPSSUCCMESSAGEVIEW, BLUETOOTHDEVICELISTVIEW); +} + +void BluetoothPresenter::ClickFailBackButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_FAIL_BACK_BUTTON"); + view_->ChangeView(TIPSFAILMESSAGEVIEW, BLUETOOTHEARPHONEVIEW); +} + +void BluetoothPresenter::ClickConnfailBackButton(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_CONN_FAIL_BACK_BUTTON"); + view_->ChangeView(TIPSCONNFAILMESSAGEVIEW, BLUETOOTHRECONNECTVIEW); + BluetoothCaseInfo *caseInfo = bluetoothMode_->GetTempMacValue(); + errcode_t retVal = bluetoothMode_->ConnectRemoteDevice((const bd_addr_t *)&caseInfo->addr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickConnfailBackButton ConnectRemoteDevice retVal = %d", retVal); +} + +bool BluetoothPresenter::OnDrag(UIView& view, const DragEvent& event) +{ + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + int16_t deltaX; + int16_t deltaY; + deltaX = event.GetDeltaX(); + deltaY = event.GetDeltaY(); + if (MATH_ABS(deltaX) >= MATH_ABS(deltaY) && MATH_ABS(deltaX) > 30) { + X_DRAG_FLAG = true; + } + } + return true; +} + +bool BluetoothPresenter::OnDragEnd(UIView& view, const DragEvent& event) +{ + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) { + view_->DropView(view); + X_DRAG_FLAG = false; + } + return true; +} + +bool BluetoothPresenter::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + if (strcmp(view.GetViewId(), BLUETOOTH_RESCAN_BUTTON) == 0) { + ClickRescanButton();//扫描出的耳机列表界面中的[重新扫描按钮]被点击 + } else if (strcmp(view.GetViewId(), BLUETOOTH_NEWEQUIPMENT_BUTTON) == 0) { + ClickNewEquipmentButton();//已连接设备列表界面中的[重新扫描按钮]被点击 + } else if (strcmp(view.GetViewId(), BLUETOOTH_CANCELCONNEDREQUEST_BUTTON) == 0) { + ClickCancelConnedRequestButton(); + } else if (strcmp(view.GetViewId(), BLUETOOTH_UNPAIR_BUTTON) == 0) { + ClickUnpairButton();//查看已连接的蓝牙耳机设备界面的[取消配对按]钮被点击 + } else if (strcmp(view.GetViewId(), BLUETOOTH_OPTIONONE_BUTTON) == 0) { + ClickOptionsOneButton(); + } else if (strcmp(view.GetViewId(), BLUETOOTH_SUCC_BACK_BUTTON) == 0) { + ClickSuccBackButton();//点击连接成功的确定按钮 + } else if (strcmp(view.GetViewId(), BLUETOOTH_FAIL_BACK_BUTTON) == 0) { + ClickFailBackButton(); //点击重新搜索按钮 + } else if (strcmp(view.GetViewId(), BLUETOOTH_CONN_FAIL_BACK_BUTTON) == 0) { + ClickConnfailBackButton();//连接失败的重试按钮 + } + return true; +} + +bool BluetoothPresenter::OnKeyAct(UIView &view, const KeyEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + //如果是按键退出,退出时需要做一些清理工作 + BluetoothEarPhoneView *bluetoothEarPhoneView = BluetoothEarPhoneView::GetInstance(); + if(bluetoothEarPhoneView) + { + bluetoothEarPhoneView->BtAnimatorStop(); //停止搜索动画 + bluetoothEarPhoneView->StopBtDiscovery();//停止定时器 + BluetoothModel::GetInstance()->SetTagConnectView(false); //清除标志位 + BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false); + } + OHOS::AbilityNavigation::Back(); + } + return true; +} + + +}; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp index 2844ae4d2..9efa53af4 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp @@ -1,466 +1,467 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainBluetooth view - * Author: - * Create: 2021-10-13 - */ -#include "bluetooth/include/MainBluetoothView.h" -#include "bluetooth/include/BluetoothModel.h" -#include "wearable_log.h" - -namespace OHOS { - -static MainBluetoothView *g_pMainBluetoothView = nullptr; - -MainBluetoothView::MainBluetoothView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::MainBluetoothView"); - preProcessView[BLUETOOTHEARPHONEVIEW] = &MainBluetoothView::ChangeBluetoothEarPhoneView; - preProcessView[BLUETOOTHEARLISTVIEW] = &MainBluetoothView::ChangeBluetoothEarListView; - preProcessView[BLUETOOTHDEVICELISTVIEW] = &MainBluetoothView::ChangeBluetoothDeviceListView; - preProcessView[BLUETOOTHEOPTIONSVIEW] = &MainBluetoothView::ChangeBluetoothOptionsView; - preProcessView[BLUETOOTHRECONNECTVIEW] = &MainBluetoothView::ChangeBluetoothReconnectView; - preProcessView[TIPSSUCCMESSAGEVIEW] = &MainBluetoothView::ChangeTipsSuccMessageView; - preProcessView[TIPSCONNFAILMESSAGEVIEW] = &MainBluetoothView::ChangeTipsConnFailMessageView; - preProcessView[TIPSFAILMESSAGEVIEW] = &MainBluetoothView::ChangeTipsFailMessageView; - preProcessView[BLUETOOTHEVIEW] = nullptr; - - g_pMainBluetoothView = this; -} - -MainBluetoothView::~MainBluetoothView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::~MainBluetoothView"); - delete bluetoothEarPhoneView; - bluetoothEarPhoneView = nullptr; - delete bluetoothOptionsView; - bluetoothOptionsView = nullptr; - delete bluetoothEarListView; - bluetoothEarListView = nullptr; - delete bluetoothReconnectView; - bluetoothReconnectView = nullptr; - delete bluetoothDeviceListView; - bluetoothDeviceListView = nullptr; - delete tipsSuccMessageView; - tipsSuccMessageView = nullptr; - delete tipsConnFailMessageView; - tipsConnFailMessageView = nullptr; - delete tipsFailMessageView; - tipsFailMessageView = nullptr; - g_pMainBluetoothView = nullptr; -} - -MainBluetoothView *MainBluetoothView::GetInstance() -{ - return g_pMainBluetoothView; -} - -void MainBluetoothView::OnStart() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::~OnStart"); - - - BluetoothModel *bluetoothModel = BluetoothModel::GetInstance(); - if (bluetoothModel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::InitView bluetoothModel nullptr err"); - return; - } - bluetoothModel->SetBluetoothCalleridStatus(CALLERSETTING); - bluetoothModel->SetTagConnectView(true); - List &bluetoothCaseList = BluetoothModel::GetInstance()->GetConnedDevicesCase(); - BluetoothModel::GetInstance()->SetTagReturnToDeviceListView(false); - int16_t unusedValue = BLUETOOTHEVIEW_MAX; - bool ret = bluetoothCaseList.IsEmpty(); - if (!ret) { - ChangeView(unusedValue, BLUETOOTHDEVICELISTVIEW); //已连接设备列表不为空 ->切换到“已连接过的蓝牙设备列表视图” - } else { - ChangeView(unusedValue, BLUETOOTHEARPHONEVIEW);//若一个都没有连接过就进行搜索 - } - return; -} - - -/*跳转到已连接过的蓝牙设备列表视图*/ -bool MainBluetoothView::ChangeBluetoothDeviceListView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothDeviceListView"); - bluetoothDeviceListView = new BluetoothDeviceListView(); - if (bluetoothDeviceListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothDeviceListView new fail"); - return false; - } - UIViewGroup *group = bluetoothDeviceListView->CreateBluetoothDeviceListView(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Device group nullptr fail"); - return false; - } - container[thisView] = group; - AddViewToRootContainer(container[thisView]); - } - // else { - // // 刷新列表 - // UIList *deviceList = bluetoothDeviceListView->GetDeviceUIList(); - // if (deviceList == nullptr) { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick deviceList nullptr"); - // return false; - // } - // deviceList->RefreshList(); - // } - if(bluetoothDeviceListView) { - bluetoothDeviceListView->RefreshBluetoothDeviceListView(); - } - return true; -} - -bool MainBluetoothView::ChangeTipsFailMessageView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsFailMessageView"); - tipsFailMessageView = new TipsFailMessageView(); - if (tipsFailMessageView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsFailMessageView new fail"); - return false; - } - // init view - UIViewGroup *group = tipsFailMessageView->CreateTipsFailMessageView(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - AddViewToRootContainer(container[thisView]); - } - return true; -} - -bool MainBluetoothView::ChangeTipsConnFailMessageView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsConnFailMessageView"); - tipsConnFailMessageView = new TipsConnFailMessageView(); - if (tipsConnFailMessageView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsConnFailMessageView new fail"); - return false; - } - // init view - UIViewGroup *group = tipsConnFailMessageView->ShowUpViewInit(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - AddViewToRootContainer(container[thisView]); - } - if (bluetoothReconnectView == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback bluetoothReconnectView == nullptr"); - } else { - container[BLUETOOTHRECONNECTVIEW]->SetVisible(false); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsConnFailMessageView SetVisible(false)"); - } - return true; -} - -//连接成功界面 -bool MainBluetoothView::ChangeTipsSuccMessageView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsSuccMessageView"); - tipsSuccMessageView = new TipsSuccMessageView(); - if (tipsSuccMessageView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsSuccMessageView new fail"); - return false; - } - // init view - UIViewGroup *group = tipsSuccMessageView->ShowUpViewInit(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - AddViewToRootContainer(container[thisView]); - } - return true; -} - -//搜索界面 -bool MainBluetoothView::ChangeBluetoothEarPhoneView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothEarPhoneView"); - bluetoothEarPhoneView = new BluetoothEarPhoneView(); - if (bluetoothEarPhoneView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarPhoneView new fail"); - return false; - } - UIViewGroup *group = bluetoothEarPhoneView->InitShowUpView(); // init view - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - AddViewToRootContainer(container[thisView]); - } - // 动画开始 - bluetoothEarPhoneView->BtAnimatorStart(); - // 蓝牙扫描&清空列表 - bluetoothEarPhoneView->BtEnable(); - return true; -} - -//扫描出来的设备列表界面 -bool MainBluetoothView::ChangeBluetoothEarListView(int16_t hideView, int16_t thisView) -{ - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothEarListView"); - bluetoothEarListView = new BluetoothEarListView(); - if (bluetoothEarListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarListView new fail"); - return false; - } - UIViewGroup *group = bluetoothEarListView->InitShowUpView(); // init view - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - AddViewToRootContainer(container[thisView]); - } - // else { - // // 刷新列表 - // UIList *scanList = bluetoothEarListView->GetScanUIList(); - // if (scanList == nullptr) { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick scanList nullptr"); - // return false; - // } - // scanList->RefreshList(); - // } - // ResetEarListView(hideView); - if(bluetoothEarListView) { - bluetoothEarListView->RefreshBluetoothEarListView(); - } - return true; -} - -bool MainBluetoothView::ChangeBluetoothOptionsView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothOptionsView"); - bluetoothOptionsView = new BluetoothOptionsView(); - if (bluetoothOptionsView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothOptionsView new fail"); - return false; - } - // init view - UIViewGroup *group = bluetoothOptionsView->CreateBluetoothOptionsView(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - AddViewToRootContainer(container[thisView]); - } - return true; -} - -//重新连接界面 -bool MainBluetoothView::ChangeBluetoothReconnectView(int16_t hideView, int16_t thisView) -{ - UNUSED(hideView); - if (container[thisView] == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothReconnectView"); - bluetoothReconnectView = new BluetoothReconnectView(); - if (bluetoothReconnectView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothReconnectView new fail"); - return false; - } - UIViewGroup *group = bluetoothReconnectView->InitShowUpView(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; - } - container[thisView] = group; - AddViewToRootContainer(container[thisView]); - } - BluetoothModel::GetInstance()->SetTagDisconnectView(true); - bluetoothReconnectView->RefreshBluetoothNameLabel(); - bluetoothReconnectView->BtReconnectStart(); - return true; -} - -/*连接失败和蓝牙重连视图都跳转到已连接的蓝牙设备列表视图*/ -void MainBluetoothView::CorrespondingJump(int16_t hideView) -{ - BluetoothModel *bluetoothModel = BluetoothModel::GetInstance(); - if (bluetoothModel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView bluetoothModel == nullptr"); - return; - } - ChangeView(hideView, BLUETOOTHDEVICELISTVIEW);/*查看已连接过的蓝牙耳机设备视图*/ - - // if (bluetoothModel->GetTagReconnectJump()) { - // ChangeView(hideView, BLUETOOTHEOPTIONSVIEW);/*查看已连接过的蓝牙耳机设备视图*/ - // } else { - // std::list &bluetoothScanList = BluetoothModel::GetInstance()->GetCase(); - // bool ret = bluetoothScanList.empty(); - // if (!ret) { - // ChangeView(hideView, BLUETOOTHEARLISTVIEW);/*扫描出的耳机列表界面*/ - // } else { - // ChangeView(hideView, BLUETOOTHEARPHONEVIEW);/*搜索界面*/ - // } - // } - return; -} - -void MainBluetoothView::ChangeSettingView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::ChangeSettingView"); - BluetoothModel::GetInstance()->SetTagConnectView(false); - BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false); - // NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); - NativeAbility::GetInstance().Back(); -} - -void MainBluetoothView::DropEarPhoneView() -{ - if (bluetoothEarPhoneView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView bluetoothEarPhoneView == nullptr"); - return; - } - bluetoothEarPhoneView->BtAnimatorStop(); - bluetoothEarPhoneView->StopBtDiscovery(); - bool ret = BluetoothModel::GetInstance()->IsTagReturnToDeviceListView(); - if (ret) { - ChangeView(BLUETOOTHEARPHONEVIEW, BLUETOOTHDEVICELISTVIEW);//返回到已连接的设备列表界面 - } else { - ChangeSettingView(); //退出蓝牙耳机界面 - } -} - -void MainBluetoothView::DropEarListView() -{ - bool ret = BluetoothModel::GetInstance()->IsTagScanDeviceClicked(); - if (ret) { - BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropEarListView Addr: %02x%02x%02x%02x%02x%02x", - caseInfo->addr[5], caseInfo->addr[4], caseInfo->addr[3], /* mac下标 0 1 2 3 4 5 */ - caseInfo->addr[2], caseInfo->addr[1], caseInfo->addr[0]); /* mac下标 0 1 2 3 4 5 */ - errcode_t retVal = gap_disconnect_remote_device((const bd_addr_t *)caseInfo->addr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropEarListView gap_disconnect_remote_device retVal = %d", retVal); - } - if (bluetoothEarPhoneView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView bluetoothEarPhoneView == nullptr"); - return; - } - bluetoothEarPhoneView->StopBtDiscovery(); - BluetoothItemView *pbItermView = BluetoothModel::GetInstance()->GetConnectionView(); - if (pbItermView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DropView The GetConnectionView get failed."); - } else { - pbItermView->ConnectAnimatorStop(); - BluetoothModel::GetInstance()->SetConnectionView(nullptr); - } - ChangeSettingView(); -} - -void MainBluetoothView::DropView(UIView& view) -{ - if (&view == container[BLUETOOTHEARPHONEVIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHEARPHONEVIEW]"); - DropEarPhoneView();//搜索界面右滑退出操作 - } else if (&view == container[BLUETOOTHEOPTIONSVIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHEOPTIONSVIEW]"); - ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW);//查看已连接过的蓝牙耳机设备视图->已连接过的蓝牙耳机设备视图 - } else if (&view == container[TIPSCONNFAILMESSAGEVIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[TIPSCONNFAILMESSAGEVIEW]"); - ChangeView(TIPSCONNFAILMESSAGEVIEW, BLUETOOTHDEVICELISTVIEW);/*连接失败的提示视图 ->已连接过的蓝牙耳机设备视图*/ - } else if (&view == container[TIPSSUCCMESSAGEVIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[TIPSSUCCMESSAGEVIEW]"); - ChangeView(TIPSSUCCMESSAGEVIEW, BLUETOOTHDEVICELISTVIEW);//连接成功的提示视图->已连接过的蓝牙设备列表视图 - } else if (&view == container[TIPSFAILMESSAGEVIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[TIPSFAILMESSAGEVIEW]"); - // ChangeView(TIPSFAILMESSAGEVIEW, BLUETOOTHEARPHONEVIEW);//未搜索到蓝牙耳机界面->搜索界面 - ChangeSettingView();//未搜索到蓝牙耳机界面->退出蓝牙耳机界面 - } else if (&view == container[BLUETOOTHEARLISTVIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHEARLISTVIEW]"); - DropEarListView(); - } else if (&view == container[BLUETOOTHDEVICELISTVIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHDEVICELISTVIEW]"); - ChangeSettingView();//已连接过的蓝牙设备列表视图 -> 退出蓝牙耳机界面 - } else if (&view == container[BLUETOOTHRECONNECTVIEW]) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHRECONNECTVIEW]"); - BluetoothModel::GetInstance()->SetTagDisconnectView(false); - CorrespondingJump(BLUETOOTHRECONNECTVIEW); - bluetoothReconnectView->BtReconnectStop();/*停止动画*/ - } -} - -void MainBluetoothView::ResetEarListView(int16_t hideView) -{ - if (bluetoothEarListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::ResetEarListView bluetoothEarListView == nullptr"); - return; - } - bluetoothEarListView->SetCancelConnedRequestButtonRemove(); - if (hideView == BLUETOOTHEARPHONEVIEW) { - bluetoothEarListView->SetTitleLabel("正在扫描"); - bluetoothEarListView->SetNewEquipmentButtonRemove(); - } else if (hideView == TIPSCONNFAILMESSAGEVIEW) { - bluetoothEarListView->SetTitleLabel("扫描完成"); - bluetoothEarListView->SetNewEquipmentButtonAdd(); - RootView::GetInstance()->Invalidate(); - } -} - -bool MainBluetoothView::CheckViewParam(int16_t hideView, int16_t showView) -{ - if (showView < 0 || showView >= BLUETOOTHEVIEW_MAX) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::CheckViewParam showView err."); - return false; - } - - if (hideView < 0 || hideView > BLUETOOTHEVIEW_MAX) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::CheckViewParam hideView err."); - return false; - } - - if (hideView == BLUETOOTHEARLISTVIEW || showView == BLUETOOTHEARLISTVIEW) { - BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false); - } - - return true; -} - -void MainBluetoothView::ChangeView(int16_t hideView, int16_t showView) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::ChangeView %d, %d", hideView, showView); - - if (!CheckViewParam(hideView, showView)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::CheckViewParam failed."); - return; - } - - PreprosssChangeView tmpPreProcessView = preProcessView[showView]; - - if (!(this->*tmpPreProcessView)(hideView, showView)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::ChangeView %d %dfailed", showView, hideView); - return; - } - if (hideView != BLUETOOTHEVIEW_MAX) { - if (container[hideView] == nullptr) { - return; - } - container[hideView]->SetVisible(false); - } - container[showView]->SetVisible(true); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView:: ChangeView end!!!%d", showView); - RootView::GetInstance()->Invalidate(); - BluetoothModel::GetInstance()->SetCurView(showView); -} -} +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainBluetooth view + * Author: + * Create: 2021-10-13 + */ +#include "bluetooth/include/MainBluetoothView.h" +#include "bluetooth/include/BluetoothModel.h" +#include "wearable_log.h" +#include "AbilityNavigationApi.h" + +namespace OHOS { + +static MainBluetoothView *g_pMainBluetoothView = nullptr; + +MainBluetoothView::MainBluetoothView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::MainBluetoothView"); + preProcessView[BLUETOOTHEARPHONEVIEW] = &MainBluetoothView::ChangeBluetoothEarPhoneView; + preProcessView[BLUETOOTHEARLISTVIEW] = &MainBluetoothView::ChangeBluetoothEarListView; + preProcessView[BLUETOOTHDEVICELISTVIEW] = &MainBluetoothView::ChangeBluetoothDeviceListView; + preProcessView[BLUETOOTHEOPTIONSVIEW] = &MainBluetoothView::ChangeBluetoothOptionsView; + preProcessView[BLUETOOTHRECONNECTVIEW] = &MainBluetoothView::ChangeBluetoothReconnectView; + preProcessView[TIPSSUCCMESSAGEVIEW] = &MainBluetoothView::ChangeTipsSuccMessageView; + preProcessView[TIPSCONNFAILMESSAGEVIEW] = &MainBluetoothView::ChangeTipsConnFailMessageView; + preProcessView[TIPSFAILMESSAGEVIEW] = &MainBluetoothView::ChangeTipsFailMessageView; + preProcessView[BLUETOOTHEVIEW] = nullptr; + + g_pMainBluetoothView = this; +} + +MainBluetoothView::~MainBluetoothView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::~MainBluetoothView"); + delete bluetoothEarPhoneView; + bluetoothEarPhoneView = nullptr; + delete bluetoothOptionsView; + bluetoothOptionsView = nullptr; + delete bluetoothEarListView; + bluetoothEarListView = nullptr; + delete bluetoothReconnectView; + bluetoothReconnectView = nullptr; + delete bluetoothDeviceListView; + bluetoothDeviceListView = nullptr; + delete tipsSuccMessageView; + tipsSuccMessageView = nullptr; + delete tipsConnFailMessageView; + tipsConnFailMessageView = nullptr; + delete tipsFailMessageView; + tipsFailMessageView = nullptr; + g_pMainBluetoothView = nullptr; +} + +MainBluetoothView *MainBluetoothView::GetInstance() +{ + return g_pMainBluetoothView; +} + +void MainBluetoothView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::~OnStart"); + + + BluetoothModel *bluetoothModel = BluetoothModel::GetInstance(); + if (bluetoothModel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::InitView bluetoothModel nullptr err"); + return; + } + bluetoothModel->SetBluetoothCalleridStatus(CALLERSETTING); + bluetoothModel->SetTagConnectView(true); + List &bluetoothCaseList = BluetoothModel::GetInstance()->GetConnedDevicesCase(); + BluetoothModel::GetInstance()->SetTagReturnToDeviceListView(false); + int16_t unusedValue = BLUETOOTHEVIEW_MAX; + bool ret = bluetoothCaseList.IsEmpty(); + if (!ret) { + ChangeView(unusedValue, BLUETOOTHDEVICELISTVIEW); //已连接设备列表不为空 ->切换到“已连接过的蓝牙设备列表视图” + } else { + ChangeView(unusedValue, BLUETOOTHEARPHONEVIEW);//若一个都没有连接过就进行搜索 + } + return; +} + + +/*跳转到已连接过的蓝牙设备列表视图*/ +bool MainBluetoothView::ChangeBluetoothDeviceListView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothDeviceListView"); + bluetoothDeviceListView = new BluetoothDeviceListView(); + if (bluetoothDeviceListView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothDeviceListView new fail"); + return false; + } + UIViewGroup *group = bluetoothDeviceListView->CreateBluetoothDeviceListView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Device group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + // else { + // // 刷新列表 + // UIList *deviceList = bluetoothDeviceListView->GetDeviceUIList(); + // if (deviceList == nullptr) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick deviceList nullptr"); + // return false; + // } + // deviceList->RefreshList(); + // } + if(bluetoothDeviceListView) { + bluetoothDeviceListView->RefreshBluetoothDeviceListView(); + } + return true; +} + +bool MainBluetoothView::ChangeTipsFailMessageView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsFailMessageView"); + tipsFailMessageView = new TipsFailMessageView(); + if (tipsFailMessageView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsFailMessageView new fail"); + return false; + } + // init view + UIViewGroup *group = tipsFailMessageView->CreateTipsFailMessageView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +bool MainBluetoothView::ChangeTipsConnFailMessageView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsConnFailMessageView"); + tipsConnFailMessageView = new TipsConnFailMessageView(); + if (tipsConnFailMessageView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsConnFailMessageView new fail"); + return false; + } + // init view + UIViewGroup *group = tipsConnFailMessageView->ShowUpViewInit(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + if (bluetoothReconnectView == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback bluetoothReconnectView == nullptr"); + } else { + container[BLUETOOTHRECONNECTVIEW]->SetVisible(false); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsConnFailMessageView SetVisible(false)"); + } + return true; +} + +//连接成功界面 +bool MainBluetoothView::ChangeTipsSuccMessageView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeTipsSuccMessageView"); + tipsSuccMessageView = new TipsSuccMessageView(); + if (tipsSuccMessageView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsSuccMessageView new fail"); + return false; + } + // init view + UIViewGroup *group = tipsSuccMessageView->ShowUpViewInit(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +//搜索界面 +bool MainBluetoothView::ChangeBluetoothEarPhoneView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothEarPhoneView"); + bluetoothEarPhoneView = new BluetoothEarPhoneView(); + if (bluetoothEarPhoneView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarPhoneView new fail"); + return false; + } + UIViewGroup *group = bluetoothEarPhoneView->InitShowUpView(); // init view + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + // 动画开始 + bluetoothEarPhoneView->BtAnimatorStart(); + // 蓝牙扫描&清空列表 + bluetoothEarPhoneView->BtEnable(); + return true; +} + +//扫描出来的设备列表界面 +bool MainBluetoothView::ChangeBluetoothEarListView(int16_t hideView, int16_t thisView) +{ + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothEarListView"); + bluetoothEarListView = new BluetoothEarListView(); + if (bluetoothEarListView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarListView new fail"); + return false; + } + UIViewGroup *group = bluetoothEarListView->InitShowUpView(); // init view + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + // else { + // // 刷新列表 + // UIList *scanList = bluetoothEarListView->GetScanUIList(); + // if (scanList == nullptr) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick scanList nullptr"); + // return false; + // } + // scanList->RefreshList(); + // } + // ResetEarListView(hideView); + if(bluetoothEarListView) { + bluetoothEarListView->RefreshBluetoothEarListView(); + } + return true; +} + +bool MainBluetoothView::ChangeBluetoothOptionsView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothOptionsView"); + bluetoothOptionsView = new BluetoothOptionsView(); + if (bluetoothOptionsView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothOptionsView new fail"); + return false; + } + // init view + UIViewGroup *group = bluetoothOptionsView->CreateBluetoothOptionsView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + return true; +} + +//重新连接界面 +bool MainBluetoothView::ChangeBluetoothReconnectView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeBluetoothReconnectView"); + bluetoothReconnectView = new BluetoothReconnectView(); + if (bluetoothReconnectView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothReconnectView new fail"); + return false; + } + UIViewGroup *group = bluetoothReconnectView->InitShowUpView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + AddViewToRootContainer(container[thisView]); + } + BluetoothModel::GetInstance()->SetTagDisconnectView(true); + bluetoothReconnectView->RefreshBluetoothNameLabel(); + bluetoothReconnectView->BtReconnectStart(); + return true; +} + +/*连接失败和蓝牙重连视图都跳转到已连接的蓝牙设备列表视图*/ +void MainBluetoothView::CorrespondingJump(int16_t hideView) +{ + BluetoothModel *bluetoothModel = BluetoothModel::GetInstance(); + if (bluetoothModel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView bluetoothModel == nullptr"); + return; + } + ChangeView(hideView, BLUETOOTHDEVICELISTVIEW);/*查看已连接过的蓝牙耳机设备视图*/ + + // if (bluetoothModel->GetTagReconnectJump()) { + // ChangeView(hideView, BLUETOOTHEOPTIONSVIEW);/*查看已连接过的蓝牙耳机设备视图*/ + // } else { + // std::list &bluetoothScanList = BluetoothModel::GetInstance()->GetCase(); + // bool ret = bluetoothScanList.empty(); + // if (!ret) { + // ChangeView(hideView, BLUETOOTHEARLISTVIEW);/*扫描出的耳机列表界面*/ + // } else { + // ChangeView(hideView, BLUETOOTHEARPHONEVIEW);/*搜索界面*/ + // } + // } + return; +} + +void MainBluetoothView::ChangeSettingView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::ChangeSettingView"); + BluetoothModel::GetInstance()->SetTagConnectView(false); + BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false); + // NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + OHOS::AbilityNavigation::Back(); +} + +void MainBluetoothView::DropEarPhoneView() +{ + if (bluetoothEarPhoneView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView bluetoothEarPhoneView == nullptr"); + return; + } + bluetoothEarPhoneView->BtAnimatorStop(); + bluetoothEarPhoneView->StopBtDiscovery(); + bool ret = BluetoothModel::GetInstance()->IsTagReturnToDeviceListView(); + if (ret) { + ChangeView(BLUETOOTHEARPHONEVIEW, BLUETOOTHDEVICELISTVIEW);//返回到已连接的设备列表界面 + } else { + ChangeSettingView(); //退出蓝牙耳机界面 + } +} + +void MainBluetoothView::DropEarListView() +{ + bool ret = BluetoothModel::GetInstance()->IsTagScanDeviceClicked(); + if (ret) { + BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropEarListView Addr: %02x%02x%02x%02x%02x%02x", + caseInfo->addr[5], caseInfo->addr[4], caseInfo->addr[3], /* mac下标 0 1 2 3 4 5 */ + caseInfo->addr[2], caseInfo->addr[1], caseInfo->addr[0]); /* mac下标 0 1 2 3 4 5 */ + errcode_t retVal = gap_disconnect_remote_device((const bd_addr_t *)caseInfo->addr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropEarListView gap_disconnect_remote_device retVal = %d", retVal); + } + if (bluetoothEarPhoneView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView bluetoothEarPhoneView == nullptr"); + return; + } + bluetoothEarPhoneView->StopBtDiscovery(); + BluetoothItemView *pbItermView = BluetoothModel::GetInstance()->GetConnectionView(); + if (pbItermView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DropView The GetConnectionView get failed."); + } else { + pbItermView->ConnectAnimatorStop(); + BluetoothModel::GetInstance()->SetConnectionView(nullptr); + } + ChangeSettingView(); +} + +void MainBluetoothView::DropView(UIView& view) +{ + if (&view == container[BLUETOOTHEARPHONEVIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHEARPHONEVIEW]"); + DropEarPhoneView();//搜索界面右滑退出操作 + } else if (&view == container[BLUETOOTHEOPTIONSVIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHEOPTIONSVIEW]"); + ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW);//查看已连接过的蓝牙耳机设备视图->已连接过的蓝牙耳机设备视图 + } else if (&view == container[TIPSCONNFAILMESSAGEVIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[TIPSCONNFAILMESSAGEVIEW]"); + ChangeView(TIPSCONNFAILMESSAGEVIEW, BLUETOOTHDEVICELISTVIEW);/*连接失败的提示视图 ->已连接过的蓝牙耳机设备视图*/ + } else if (&view == container[TIPSSUCCMESSAGEVIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[TIPSSUCCMESSAGEVIEW]"); + ChangeView(TIPSSUCCMESSAGEVIEW, BLUETOOTHDEVICELISTVIEW);//连接成功的提示视图->已连接过的蓝牙设备列表视图 + } else if (&view == container[TIPSFAILMESSAGEVIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[TIPSFAILMESSAGEVIEW]"); + // ChangeView(TIPSFAILMESSAGEVIEW, BLUETOOTHEARPHONEVIEW);//未搜索到蓝牙耳机界面->搜索界面 + ChangeSettingView();//未搜索到蓝牙耳机界面->退出蓝牙耳机界面 + } else if (&view == container[BLUETOOTHEARLISTVIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHEARLISTVIEW]"); + DropEarListView(); + } else if (&view == container[BLUETOOTHDEVICELISTVIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHDEVICELISTVIEW]"); + ChangeSettingView();//已连接过的蓝牙设备列表视图 -> 退出蓝牙耳机界面 + } else if (&view == container[BLUETOOTHRECONNECTVIEW]) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHRECONNECTVIEW]"); + BluetoothModel::GetInstance()->SetTagDisconnectView(false); + CorrespondingJump(BLUETOOTHRECONNECTVIEW); + bluetoothReconnectView->BtReconnectStop();/*停止动画*/ + } +} + +void MainBluetoothView::ResetEarListView(int16_t hideView) +{ + if (bluetoothEarListView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::ResetEarListView bluetoothEarListView == nullptr"); + return; + } + bluetoothEarListView->SetCancelConnedRequestButtonRemove(); + if (hideView == BLUETOOTHEARPHONEVIEW) { + bluetoothEarListView->SetTitleLabel("正在扫描"); + bluetoothEarListView->SetNewEquipmentButtonRemove(); + } else if (hideView == TIPSCONNFAILMESSAGEVIEW) { + bluetoothEarListView->SetTitleLabel("扫描完成"); + bluetoothEarListView->SetNewEquipmentButtonAdd(); + RootView::GetInstance()->Invalidate(); + } +} + +bool MainBluetoothView::CheckViewParam(int16_t hideView, int16_t showView) +{ + if (showView < 0 || showView >= BLUETOOTHEVIEW_MAX) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::CheckViewParam showView err."); + return false; + } + + if (hideView < 0 || hideView > BLUETOOTHEVIEW_MAX) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::CheckViewParam hideView err."); + return false; + } + + if (hideView == BLUETOOTHEARLISTVIEW || showView == BLUETOOTHEARLISTVIEW) { + BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false); + } + + return true; +} + +void MainBluetoothView::ChangeView(int16_t hideView, int16_t showView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::ChangeView %d, %d", hideView, showView); + + if (!CheckViewParam(hideView, showView)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::CheckViewParam failed."); + return; + } + + PreprosssChangeView tmpPreProcessView = preProcessView[showView]; + + if (!(this->*tmpPreProcessView)(hideView, showView)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::ChangeView %d %dfailed", showView, hideView); + return; + } + if (hideView != BLUETOOTHEVIEW_MAX) { + if (container[hideView] == nullptr) { + return; + } + container[hideView]->SetVisible(false); + } + container[showView]->SetVisible(true); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView:: ChangeView end!!!%d", showView); + RootView::GetInstance()->Invalidate(); + BluetoothModel::GetInstance()->SetCurView(showView); +} +} diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/brightnesslevel/src/BrightnessLevelPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/brightnesslevel/src/BrightnessLevelPresenter.cpp index 7f679ca22..d6fd11cca 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/brightnesslevel/src/BrightnessLevelPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/brightnesslevel/src/BrightnessLevelPresenter.cpp @@ -8,6 +8,7 @@ #include "brightnesslevel/include/BrightnessLevelPresenter.h" #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include @@ -73,7 +74,7 @@ namespace OHOS UNUSED(view); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -87,7 +88,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/calculator/src/CalculatorPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/calculator/src/CalculatorPresenter.cpp index 37de86716..f819dbc6e 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/calculator/src/CalculatorPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/calculator/src/CalculatorPresenter.cpp @@ -12,6 +12,7 @@ #include "custom_utils.h" #include "NativeRegisterManager.h" #include "uicomponents/UIComponents.h" +#include "AbilityNavigationApi.h" namespace OHOS { // REGIST_MENU_PRO( VIEW_CALCULATOR, CalculatorView, CalculatorPresenter, @@ -159,7 +160,7 @@ bool CalculatorPresenter::OnDragEnd(OHOS::UIView& view, const OHOS::DragEvent& e if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { if(event.GetPreLastPoint().x-event.GetStartPoint().x>150) - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -173,7 +174,7 @@ bool CalculatorPresenter::OnKeyAct(UIView &view, const KeyEvent &event) if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/calendar/src/CalendarPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/calendar/src/CalendarPresenter.cpp index b4c586498..487ea9848 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/calendar/src/CalendarPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/calendar/src/CalendarPresenter.cpp @@ -12,6 +12,7 @@ #include "calendar/include/CalendarPresenter.h" #include "custom_utils.h" #include "NativeRegisterManager.h" +#include "AbilityNavigationApi.h" namespace OHOS { @@ -63,7 +64,7 @@ namespace OHOS if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { if (event.GetPreLastPoint().x - event.GetStartPoint().x > 100) - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) { @@ -87,7 +88,7 @@ namespace OHOS if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/callerlog/src/CallerLogModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/callerlog/src/CallerLogModel.cpp index 4c6b0c3fb..64526c126 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/callerlog/src/CallerLogModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/callerlog/src/CallerLogModel.cpp @@ -39,6 +39,7 @@ #endif #include "custom_save_runtime.h" +#include "AbilityNavigationApi.h" #ifdef __cplusplus extern "C" { @@ -202,11 +203,11 @@ void StatusReset(void) PhoneServiceScreenCtr(false); if(NativeAbility::GetInstance().GetCurSliceId() == VIEW_INCOMING_CALL) { - NativeAbility::GetInstance().Back_CountSlice_make_phone(); + OHOS::AbilityNavigation::Back_CountSlice_make_phone(); } else if (!uapi_dev_runtime_get_train_status())// || NativeAbility::GetInstance().GetCurSliceId() == VIEW_BLUETOOTH_EARPHONE ) { - NativeAbility::GetInstance().ClearSliceIdStack(); + OHOS::AbilityNavigation::ClearSliceIdStack(); } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp index 73894734b..1e92a4274 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp @@ -1,5 +1,6 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include #include @@ -150,7 +151,7 @@ namespace OHOS if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) { if (!BluetoothServiceOptionsView::GetInstance()->get_connectview_Visible()) - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); X_DRAG_FLAG = false; } @@ -166,7 +167,7 @@ namespace OHOS if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { if (!BluetoothServiceOptionsView::GetInstance()->get_connectview_Visible()) - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp index e5b6e55d4..bba80e1b6 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp @@ -1,172 +1,173 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-04-25 11:50:57 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-05 11:47:17 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp - */ -#include "classicbluetooth/include/ClassicBlueToothPresenter.h" -#include "classicbluetooth/include/ClassicBlueToothView.h" -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "custom_utils.h" -#include "common/key_code.h" -#include -#include "wearable_log.h" -#include "ConfigModel.h" -#include -#include "bluetooth/include/BluetoothModel.h" -#include "custom_runtime.h" -#include "ConfigModelC.h" -#include "phoneservice/include/PhoneService.h" -#include "NativeRegisterManager.h" -namespace OHOS -{ - REGIST_SLICE(VIEW_CLASSIC_BLUETOOTH, ClassicBlueToothView, ClassicBlueToothPresenter); - - // 当前Presenter属性实例化的内存指针 - static ClassicBlueToothPresenter *g_pClassicBlueToothPresenter = nullptr; - ClassicBlueToothPresenter::ClassicBlueToothPresenter() - { - g_pClassicBlueToothPresenter = this; - } - - ClassicBlueToothPresenter::~ClassicBlueToothPresenter() - { - g_pClassicBlueToothPresenter = nullptr; - } - - ClassicBlueToothPresenter *ClassicBlueToothPresenter::GetInstance() - { - return g_pClassicBlueToothPresenter; - } - - void ClassicBlueToothPresenter::OnStart() - { - } - - void ClassicBlueToothPresenter::OnPause(void) - { - Presenter::OnPause(); - } - - void ClassicBlueToothPresenter::OnResume(void) - { - RootView::GetInstance()->SetOnKeyActListener(this); - } - - void ClassicBlueToothPresenter::OnStop(void) - { - } - - bool ClassicBlueToothPresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(event); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnClick"); - ClassicBlueToothView *classicBlueToothView = ClassicBlueToothView::GetInstance(); - if (classicBlueToothView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::GetInstance"); - return false; - } - else if (strcmp(view.GetViewId(), BLUETOOTHSERVICEOPTIONSBUTTON) == 0) - { - if (classicBlueToothView->GetTradionalBlueToothToggleButton()->GetState() == true) - { - NativeAbility::GetInstance().EnterSlice(VIEW_BLUETOOTH_SERVICE_OPTIONS); - } - } - - return true; - } - - bool ClassicBlueToothPresenter::OnDrag(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnDrag"); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - X_DRAG_FLAG = true; - } - return true; - } - - bool ClassicBlueToothPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnDragEnd"); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) - { - NativeAbility::GetInstance().Back(); - X_DRAG_FLAG = false; - } - - return true; - } - - bool ClassicBlueToothPresenter::OnChange(UICheckBox::UICheckBoxState state) - { -#ifdef CUSTOM_ZHIHUI - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnChange"); - bd_addr_t bdaddr = {0}; - switch (state) - { - case UICheckBox::SELECTED: - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Enabled"); - start_custom_ble_service(); // 主动开启蓝牙 - // 开启完增加回连 - - uapi_get_br_address(&bdaddr); - if (uapi_dev_runtime_get_bt_powerstat() && (cm_get_HFP_switch() || cm_get_A2DP_switch())) - { - if (cm_get_HFP_switch() && cm_get_A2DP_switch() && false == bt_is_acl_connected(&bdaddr) && !(bdaddr.addr[0] == 0 && bdaddr.addr[1] == 0 && bdaddr.addr[2] == 0 && bdaddr.addr[3] == 0 && bdaddr.addr[4] == 0 && bdaddr.addr[5] == 0)) - { - int ret = gap_reconnect_media_device(&bdaddr); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " gap_reconnect_media_device ret = %u %02x %02x %02x ", ret, bdaddr.addr[5], bdaddr.addr[4], bdaddr.addr[3]); - } - else - { - - if (cm_get_A2DP_switch()) - { - uapi_a2dp_snk_connect(); - } - if (cm_get_HFP_switch()) - { - uapi_hfp_connect(); - } - - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect!!! \r\n"); - } - } - - ConfigModel::GetInstance()->SetClassicBlueToothState(true); - break; - case UICheckBox::UNSELECTED: - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Disabled"); - - stop_custom_ble_service(); - - ConfigModel::GetInstance()->SetClassicBlueToothState(false); - break; - default: - break; - } -#endif - return true; - } - - bool ClassicBlueToothPresenter::OnKeyAct(UIView &view, const KeyEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnKeyAct"); - uint16 keyID = event.GetKeyId(); - uint16 keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; - } - -} +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-25 11:50:57 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-11-05 11:47:17 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp + */ +#include "classicbluetooth/include/ClassicBlueToothPresenter.h" +#include "classicbluetooth/include/ClassicBlueToothView.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "custom_utils.h" +#include "common/key_code.h" +#include +#include "wearable_log.h" +#include "ConfigModel.h" +#include +#include "bluetooth/include/BluetoothModel.h" +#include "custom_runtime.h" +#include "ConfigModelC.h" +#include "phoneservice/include/PhoneService.h" +#include "NativeRegisterManager.h" +namespace OHOS +{ + REGIST_SLICE(VIEW_CLASSIC_BLUETOOTH, ClassicBlueToothView, ClassicBlueToothPresenter); + + // 当前Presenter属性实例化的内存指针 + static ClassicBlueToothPresenter *g_pClassicBlueToothPresenter = nullptr; + ClassicBlueToothPresenter::ClassicBlueToothPresenter() + { + g_pClassicBlueToothPresenter = this; + } + + ClassicBlueToothPresenter::~ClassicBlueToothPresenter() + { + g_pClassicBlueToothPresenter = nullptr; + } + + ClassicBlueToothPresenter *ClassicBlueToothPresenter::GetInstance() + { + return g_pClassicBlueToothPresenter; + } + + void ClassicBlueToothPresenter::OnStart() + { + } + + void ClassicBlueToothPresenter::OnPause(void) + { + Presenter::OnPause(); + } + + void ClassicBlueToothPresenter::OnResume(void) + { + RootView::GetInstance()->SetOnKeyActListener(this); + } + + void ClassicBlueToothPresenter::OnStop(void) + { + } + + bool ClassicBlueToothPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnClick"); + ClassicBlueToothView *classicBlueToothView = ClassicBlueToothView::GetInstance(); + if (classicBlueToothView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::GetInstance"); + return false; + } + else if (strcmp(view.GetViewId(), BLUETOOTHSERVICEOPTIONSBUTTON) == 0) + { + if (classicBlueToothView->GetTradionalBlueToothToggleButton()->GetState() == true) + { + OHOS::AbilityNavigation::EnterSlice(VIEW_BLUETOOTH_SERVICE_OPTIONS); + } + } + + return true; + } + + bool ClassicBlueToothPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + X_DRAG_FLAG = true; + } + return true; + } + + bool ClassicBlueToothPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) + { + OHOS::AbilityNavigation::Back(); + X_DRAG_FLAG = false; + } + + return true; + } + + bool ClassicBlueToothPresenter::OnChange(UICheckBox::UICheckBoxState state) + { +#ifdef CUSTOM_ZHIHUI + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnChange"); + bd_addr_t bdaddr = {0}; + switch (state) + { + case UICheckBox::SELECTED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Enabled"); + start_custom_ble_service(); // 主动开启蓝牙 + // 开启完增加回连 + + uapi_get_br_address(&bdaddr); + if (uapi_dev_runtime_get_bt_powerstat() && (cm_get_HFP_switch() || cm_get_A2DP_switch())) + { + if (cm_get_HFP_switch() && cm_get_A2DP_switch() && false == bt_is_acl_connected(&bdaddr) && !(bdaddr.addr[0] == 0 && bdaddr.addr[1] == 0 && bdaddr.addr[2] == 0 && bdaddr.addr[3] == 0 && bdaddr.addr[4] == 0 && bdaddr.addr[5] == 0)) + { + int ret = gap_reconnect_media_device(&bdaddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " gap_reconnect_media_device ret = %u %02x %02x %02x ", ret, bdaddr.addr[5], bdaddr.addr[4], bdaddr.addr[3]); + } + else + { + + if (cm_get_A2DP_switch()) + { + uapi_a2dp_snk_connect(); + } + if (cm_get_HFP_switch()) + { + uapi_hfp_connect(); + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect!!! \r\n"); + } + } + + ConfigModel::GetInstance()->SetClassicBlueToothState(true); + break; + case UICheckBox::UNSELECTED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Disabled"); + + stop_custom_ble_service(); + + ConfigModel::GetInstance()->SetClassicBlueToothState(false); + break; + default: + break; + } +#endif + return true; + } + + bool ClassicBlueToothPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; + } + +} diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp index 4b1b281b2..3a0b0521b 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp @@ -15,6 +15,7 @@ #include "UiConfig.h" #include "NativeRegisterManager.h" #include "ui_resource_string.h" +#include "AbilityNavigationApi.h" namespace OHOS { @@ -58,7 +59,7 @@ bool MainCompassPresenter::OnDragEnd(UIView& view, const DragEvent& event) UNUSED(view); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainCompassPresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -71,7 +72,7 @@ bool MainCompassPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 如果是power键就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/CountDownModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/CountDownModel.cpp index 624856725..ecf0cc7d5 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/CountDownModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/CountDownModel.cpp @@ -1,835 +1,836 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-04-07 18:15:53 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-12-18 17:42:19 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp - */ -#include "countdown/include/CountDownModel.h" -#include -#include -#include -#include "wearable_log.h" -#include "countdown/include/MainCountDownView.h" -#include -#include "ConfigModel.h" -#include "ui_resource_string.h" -#include "custom_runtime.h" -#include "uiservice/include/ui_service.h" -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include -#include -#include -#include "vibrator_service.h" -namespace OHOS -{ - /* -------------------------------------------------------------------------- */ - // 声明定时器变量 - static osTimerId_t g_timer = nullptr; - int CountDownModel::g_CountDownTimes = {0}; - int CountDownModel::totalSeconds = 0; //总的倒计时时间 - uint64_t CountDownModel::startTime = 0; - uint64_t CountDownModel::pauseTime = 0; - uint64_t CountDownModel::endTime = 0; - static constexpr int32 NUM_TEN = 10; // 主要用于格式化输出,当小时、分钟或秒小于10时,在其前面添加一个’0’以保持常规时间格式,例如“09:05:03”。 - static constexpr int16 NUM_TIME_MIN = 60; - static constexpr int16 NUM_TIME_HOUR = 3600; - static constexpr int32 NUM_TIME_DAY = 86400; - - /* -------------------------------------------------------------------------- */ - // 定义了 GetInstance() 方法来获取 CountDownModel 的实例,确保只有一个全局实例存在。 - CountDownModel *CountDownModel::GetInstance() - { - static CountDownModel instance; - return &instance; - } - - // 函数用于解析"HH:MM:SS"格式的时间字符串,并更新g_CountDownTimes - void CountDownModel::ParseCountDownTime(const char *countdowntime) - { - int hours, minutes, seconds; - - // 使用sscanf从字符串中读取格式化数据 - // "%2d:%2d:%2d"用于检查两个数字,后面跟一个冒号,这样的模式重复两次,从而捕获三个整数 - if (sscanf(countdowntime, "%2d:%2d:%2d", &hours, &minutes, &seconds) == 3) - { - // 解析成功,现在转换为总秒数 - g_CountDownTimes = hours * NUM_TIME_HOUR + minutes * NUM_TIME_MIN + seconds; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "g_CountDownTimes = %d", g_CountDownTimes); - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::ParseCountDownTime Parsing failure"); - } - } - - std::string CountDownModel::ParseRingTime(const std::string &timeStr) - { - int hours, minutes, seconds; - std::string formattedTime; - // 使用 sscanf 从字符串中读取时间数据 - if (sscanf(timeStr.c_str(), "%2d:%2d:%2d", &hours, &minutes, &seconds) == 3) - { - // 如果小时部分为0,则格式化去掉小时部分 - if (hours == 0) - { - formattedTime = (minutes < NUM_TEN ? "0" : "") + std::to_string(minutes) + ":" + (seconds < NUM_TEN ? "0" : "") + std::to_string(seconds); - } - else - { - // 如果小时部分不为0,保持原有格式 - formattedTime = timeStr; - } - } - else - { - // 解析失败逻辑处理:可以选择记录错误、返回原字符串或其他合适的处理方式 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrimTimeFormat Parsing failure: Invalid format"); - formattedTime = timeStr; // 例子中选择返回原字符串 - } - return formattedTime; - } - - // 设置倒计时时间 - void CountDownModel::SetCountDownTime(const std::string &countdowntime) - { - CountTime = countdowntime; - CountTimeBackup = countdowntime; - ParseCountDownTime(CountTime.c_str()); - } - - // 获取倒计时时间 - std::string CountDownModel::GetCountDownTime(void) - { - return CountTime; - } - - std::string CountDownModel::GetBackupCountDownTime(void) - { - return CountTimeBackup; - } - - // 设置响铃时间 - void CountDownModel::SetRingTime(const std::string &ringtime) - { - RingTime = ParseRingTime(ringtime); - } - - // 获取响铃时间 - std::string CountDownModel::GetRingTime(void) - { - return RingTime; - } - - /* - * @brief 初始化音乐播放器以播放一个指定的铃声文件 - * @param {char*} RingMusicName 铃声文件 - */ - int CountDownModel::CountDownRingPlayerInit(const char *RingMusicName) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDownRingPlayerInit"); - /* ------------------------------- 1.播放文件路径设置 ------------------------------- */ - uri = RingMusicName; - /* -------------------------------- 2.播放器对象创建 ------------------------------- */ - if (playerCtr.get() == nullptr) - { - playerCtr = std::make_shared(); - if (playerCtr.get() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr new fail"); - return OHOS_FAILURE; - } - } - /* ------------------------------- 3.播放器回调对象创建 ------------------------------ */ - if (playerCallback.get() == nullptr) - { - playerCallback = std::make_shared(); - if (playerCallback.get() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCallback new fail"); - return OHOS_FAILURE; - } - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CountDownModel] PlayerInit success!"); - return OHOS_SUCCESS; - } - - /* - * @brief 对铃声播放器进行设置并开始播放铃声。 - */ - int CountDownModel::InitializeAndPlayRingtone(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CountDownModel::InitializeAndPlayRingtone"); - /* -------------------------------- 1.检查播放器实例 ------------------------------- */ - int32_t ret; - int32_t state; - if (playerCtr.get() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr.get() == nullptr"); - return OHOS_FAILURE; - } - playerCtr->GetPlayerState(state); - /* -------------------------------- 2.设置播放器回调 ------------------------------- */ - playerCtr->SetPlayerCallback(playerCallback); - /* -------------------------------- 3.创建并设置音频源 -------------------------------- */ - source = std::make_shared(uri, header); - if (source.get() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] source.get() == fail"); - return OHOS_FAILURE; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Player url:%s", uri.c_str()); - playerCtr->SetSource(*source); - /* --------------------------------- 4.配置播放器 -------------------------------- */ - playerCtr->SetAudioStreamType(AUDIO_STREAM_NOTIFICATION_SYSTEM); // 设置播放器的音频流类型 - playerCtr->Prepare(); // 准备播放器对象以播放音频。 - /* -------------------------------- 5.请求音频焦点 -------------------------------- */ - AudioManager &amIntance = AudioManager::GetInstance(); - sessionId = amIntance.MakeSessionId(); - if (sessionId == AUDIO_SESSION_ID_NONE) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] sessionId invalid!!"); - return OHOS_FAILURE; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CountDownModel] MakeSessionId = %d", sessionId); - playerInterruptListener = std::make_shared(); // 创建音频中断监听器 - if (playerInterruptListener.get() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerInterruptListener playerInterruptListener.get() == nullptr"); - return OHOS_FAILURE; - } - playerInterruptListener->SetOwner(playerCtr); - interrupt = {AUDIO_STREAM_NOTIFICATION_SYSTEM, sessionId, playerInterruptListener}; - // 激活音频中断 5s超时 - if (amIntance.ActivateAudioInterrupt(interrupt) == INTERRUPT_FAILED) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ActivateAudioInterrupt faild"); - return OHOS_FAILURE; - } - // playerCtr->SetVolume(50, 50); // 将左声道和右声道音量都设置为50 - playerCtr->SetAudioSessionId(sessionId); - // 播放 - ret = playerCtr->Play(); - if(ret == 0) - { - //如果倒计时铃声播放成功,记录该事件 - uapi_save_runtime_log(RUNTIME_LOG_RING_PLAY_START_COUNTDOWN);//TOOD* - } - playerCtr->EnableSingleLooping(true); // 设置是否循环播放 - return OHOS_SUCCESS; - } - - /* - * @brief 开始铃声的播放 - */ - int CountDownModel::StartRingtonePlayback(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CountDownModel::StartRingtonePlayback"); - if (CountDownRingPlayerInit(RingMusicPath) != OHOS_SUCCESS) - { - // 错误处理,例如记录日志或者返回错误状态码 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDownRingPlayerInit error!!"); - return OHOS_FAILURE; - } - - if (InitializeAndPlayRingtone() != OHOS_SUCCESS) - { - // 错误处理,例如记录日志或者返回错误状态码 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::InitializeAndPlayRingtone error!!"); - return OHOS_FAILURE; - } - return OHOS_SUCCESS; - } - - /* - * @brief 停止播放铃声,重置并释放播放器资源,并去激活之前设置的音频中断。 - */ - int CountDownModel::StopRingtonePlaybackAndReleaseResources(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CountDownModel::StopRingtonePlaybackAndReleaseResources"); - int32_t ret = 0; - int32_t state = 0; - AudioManager &amIntance = AudioManager::GetInstance(); - if (playerCtr.get() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr.get() == nullptr"); - return OHOS_FAILURE; - } - playerCtr->GetPlayerState(state); - if (state == PlayerStates::PLAYER_STARTED || state == PlayerStates::PLAYER_PAUSED) - { - ret = playerCtr->Stop(); - if (ret != 0) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Failed to stop the player"); - return OHOS_FAILURE; - } - //如果倒计时铃声停止播放成功,记录该事件 - uapi_save_runtime_log(RUNTIME_LOG_RING_PLAY_STOP_COUNTDOWN);//TOOD* - } - ret = playerCtr->Reset(); - if (ret != 0) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Failed to reset the player"); - return OHOS_FAILURE; - } - ret = playerCtr->Release(); - playerCtr.reset(); - if (ret != 0) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Failed to release the player"); - return OHOS_FAILURE; - } - if (amIntance.DeactivateAudioInterrupt(interrupt) != 0) - { - return OHOS_FAILURE; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reset, ret:%d", ret); - return OHOS_SUCCESS; - } - - int CountDownModel::ResetRingtonePlayback(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CountDownModel::ResetRingtonePlayback"); - int32_t ret = 0; - int32_t state = 0; - if (playerCtr.get() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr is null"); - return OHOS_FAILURE; - } - playerCtr->GetPlayerState(state); - if (state == PlayerStates::PLAYER_STARTED || state == PlayerStates::PLAYER_PAUSED) - { - ret = playerCtr->Stop(); - if (ret != 0) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Failed to stop the player"); - return OHOS_FAILURE; - } - } - ret = playerCtr->Reset(); - if (ret != 0) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Failed to reset the player"); - return OHOS_FAILURE; - } - return OHOS_SUCCESS; - } - - template - static void PostRingtoneEvent(Func function) - { - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(function, CountDownModel::GetInstance())); - } - - /*触发铃声的开始*/ - void CountDownModel::RequestStartRingtone(void) - { - if (uapi_sleep_mode_flag_get()) - { - return; - } - if (true != ConfigModel::GetInstance()->GetDnotdisturb()) - { - PostRingtoneEvent(&CountDownModel::StartRingtonePlayback); - } - } - - /*触发铃声的停止*/ - void CountDownModel::RequestStopRingtone(void) - { - // PostRingtoneEvent(&CountDownModel::StopRingtonePlaybackAndReleaseResources); - } - - // 判断计时器是否结束 - bool CountDownModel::CountDownTimerIsEnd() // 计时器是否结束 - { - if (g_timer == nullptr) - { - return true; - } - return false; - } - // 获取是否需要跳转到开始到计时界面 - bool CountDownModel::GetChanageToStartCountDownView() - { - return IsChanageToStartCountDownViewFlag; - } - - // 设置是否需要跳转到开始到计时界面 - void CountDownModel::SetChanageToStartCountDownView(bool val) - { - IsChanageToStartCountDownViewFlag = val; - } - - bool CountDownModel::CountDownViewIsExit() // 计时器界面是否退出 - { - MainCountDownView *g_CountDownView = MainCountDownView::GetInstance(); - if (g_CountDownView == nullptr) - { - return true; - } - return false; - } - - // 处理倒计时到期时的一些操作 - void CountDownModel::HandCountDownEndOperator(void) - { - StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); - if (p_StartCountDownView) - { - CountDown_StopTimer(); // 停止定时器 - uapi_set_screen_on_api(); // 点亮屏幕 - // CountDownModel::GetInstance()->RequestStartRingtone(); // 播放铃声 - CountDownModel::GetInstance()->CountDown_VibratorTimerStart(); // 触发震动 - - StartCountDownView::GetInstance()->GetPlayOrPauseToggleButton()->SetVisible(false); - p_StartCountDownView->GetRepeatButton()->SetVisible(true); - /*倒计时结束 显示大图标 */ - p_StartCountDownView->ShowEndView(true); - } - } - - bool CountDownModel::GetCountDownTimerIsPause() - { - return CountDownTimerIsPauseFlag; - } - void CountDownModel::SetCountDownTimerIsPause(bool val) - { - CountDownTimerIsPauseFlag = val; - } - /* ----------------------------------- 定时器 ---------------------------------- */ - - /* - * @brief 显示计时器(时、分、秒) - */ - const char *CountDownModel::DisplayCountDownDuration() - { - countdownDuration.clear(); // 更正为clear(),更加表明意图,与erase()等价 - std::string hours; - std::string minute; - std::string seconds; - - if (g_CountDownTimes >= NUM_TIME_DAY) - { - g_CountDownTimes = 0; - } - - int hour = g_CountDownTimes / NUM_TIME_HOUR; - int min = (g_CountDownTimes % NUM_TIME_HOUR) / NUM_TIME_MIN; - int sec = (g_CountDownTimes % NUM_TIME_HOUR) % NUM_TIME_MIN; - - hours = (hour < NUM_TEN) ? "0" + std::to_string(hour) : std::to_string(hour); - minute = (min < NUM_TEN) ? "0" + std::to_string(min) : std::to_string(min); - seconds = (sec < NUM_TEN) ? "0" + std::to_string(sec) : std::to_string(sec); - countdownDuration = hours + ":" + minute + ":" + seconds; - - return countdownDuration.c_str(); // 返回 std::string 的 c_str(),但需要注意生命周期 - } - /* - * @brief 在这里添加定时器到期后的处理逻辑 - */ - static void CountDown_TimerCallbackProc(int data) - { - if (CountDownModel::GetInstance()->CountDownViewIsExit()) // 如果已经退出了界面定时器还在跑,就先跳转Slice - { - CountDownModel::GetInstance()->CountDown_StopTimer(); // 停止定时器 - CountDownModel::GetInstance()->SetChanageToStartCountDownView(true); - NativeAbility::GetInstance().EnterSlice(VIEW_MAIN_COUNTDOWN); - } - else - { - StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); - if (p_StartCountDownView) - { - CountDownModel::GetInstance()->HandCountDownEndOperator(); - } - } - return; - } - - /* - * @brief 计时器回调函数 - */ - static void CountDown_TimerCallback(int data) - { - - /*拿系统时间实现倒计时功能*/ - bool isRunning = CountDownModel::GetInstance()->GetisRunning(); - bool isPaused = CountDownModel::GetInstance()->GetisPaused(); - - if (isRunning && !isPaused) - { - uint64_t currentTime = CountDownModel::GetInstance()->get_current_time(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentTime(ms):%llu,endTime(ms):%llu",currentTime,CountDownModel::endTime); - if (currentTime >= CountDownModel::endTime) { - CountDownModel::g_CountDownTimes = 0; - // 这里可以添加倒计时结束后的操作,比如发出提示音等 - GraphicService::GetInstance()->PostGraphicEvent(std::bind(CountDown_TimerCallbackProc, data)); - return; - } - uint64_t remainingMs = CountDownModel::endTime - currentTime; - CountDownModel::g_CountDownTimes = static_cast((remainingMs + 999) / 1000); // ceil to seconds - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "当前时间戳(ms):%u,倒计时剩余时间(s):%d", currentTime, CountDownModel::g_CountDownTimes); - } - } - - uint64_t CountDownModel::get_current_time() - { - uint32_t time = 0; - if (uapi_get_timestampe_ss(&time) != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get timestamp"); - return 0; - } // 秒级时间戳转换成毫秒级时间戳 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentTime(ms)转换前:%u",time); - uint64_t timeMs = static_cast(time) * 1000; // 秒级时间戳转换成毫秒级时间戳 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentTime(ms)转换后:%llu",timeMs); - return timeMs; - } - - void CountDownModel::countdownstart() - { - isRunning = true; - isPaused = false; - CountDownModel::totalSeconds = CountDownModel::g_CountDownTimes; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "totalSeconds:%u",CountDownModel::get_current_time()); - CountDownModel::startTime = get_current_time(); //获取开始时间戳 - CountDownModel::endTime = CountDownModel::startTime + static_cast(g_CountDownTimes) * 1000; //获取结束时间戳(ms) - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "startTime(ms):%llu,endTime(ms):%llu,totalSeconds:%d",CountDownModel::startTime,CountDownModel::endTime,CountDownModel::totalSeconds); - - } - - void CountDownModel::countdownpause() - { - if (isRunning &&!isPaused) { - isPaused = true; - CountDownModel::pauseTime = get_current_time(); - } - } - void CountDownModel::countdownresume() - { - if (isRunning && isPaused) { - isPaused = false; - uint64_t currentTime = get_current_time(); - uint64_t pauseDuration = currentTime - CountDownModel::pauseTime; - CountDownModel::endTime = CountDownModel::endTime + pauseDuration; - if (currentTime >= CountDownModel::endTime) { - CountDownModel::g_CountDownTimes = 0; - } else { - uint64_t remainingMs = CountDownModel::endTime - currentTime; - CountDownModel::g_CountDownTimes = static_cast((remainingMs + 999) / 1000); // ceil to seconds - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "startTime(ms):%llu,pauseDuration(ms):%llu,endTime(ms):%llu", - CountDownModel::startTime, pauseDuration, CountDownModel::endTime); - } - } - - void CountDownModel::countdownstop() - { - isRunning = false; - isPaused = false; - } - - /* - * @brief 开启定时器函数 - * @param interval 时间间隔,单位ms - */ - void CountDownModel::CountDown_StartTimer(uint32_t interval) - { - /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_timer != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer already exists!!"); - return; - } - - countdownstart(); - - /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_timer = osTimerNew((osTimerFunc_t)CountDown_TimerCallback, osTimerPeriodic, nullptr, nullptr); - // 检查定时器创建是否成功 - if (g_timer == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer create failed!!"); - return; - } - - /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ - int tick = osMs2Tick(interval); - - /* --------------------------------- 4.启动定时器 -------------------------------- */ - // g_timerStartTimestamp = GetCurrentTimestamp(); // 假设GetCurrentTimestamp()是获取当前时间戳的函数 - osStatus_t ret = osTimerStart(g_timer, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_StartTimer] osTimerDelete failed, ret = %lx!!", ret); - if (g_timer != nullptr) - { - ret = osTimerDelete(g_timer); - } - g_timer = nullptr; - return; - } - return; - } - - /* - * @brief 停止定时器 - */ - void CountDownModel::CountDown_StopTimer(void) - { - // 检查定时器是否存在 - if (g_timer != nullptr) - { - countdownstop(); - - osTimerStop(g_timer); - // 删除定时器并置为 nullptr - osStatus_t ret = osTimerDelete(g_timer); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret); - } - g_timer = nullptr; - g_CountDownTimes = 0; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stop timer success!!"); - } - } - /* - * @brief 暂停定时器 - */ - void CountDownModel::CountDown_PauseTimer(void) - { - // 检查定时器是否存在 - if (g_timer != nullptr) - { - countdownpause(); - - // 暂停定时器,但不删除它 - osStatus_t ret = osTimerStop(g_timer); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_PauseTimer osTimerStop failed, ret = %lx!!", ret); - } - } - } - - /* - * @brief 恢复定时器 - */ - void CountDownModel::CountDown_ResumeTimer(uint32_t interval) - { - // 检查定时器是否存在 - if (g_timer != nullptr) - { - countdownresume(); - - int tick = osMs2Tick(interval); - // 恢复定时器 - osStatus_t ret = osTimerStart(g_timer, tick); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_ResumeTimer osTimerStart failed, ret = %lx!!", ret); - } - } - } - - static osTimerId_t g_vibrator_timer = nullptr; - static void CountDown_VibratorTimerCallbackProc(void *arg) - { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerCallbackProc"); - // 触发震动 - custom_VibratorFunc_int(0); - custom_VibratorFunc_int(0); - } - - static void CountDown_VibratorTimerCallback(void *arg) - { - GraphicService::GetInstance()->PostGraphicEvent(std::bind(CountDown_VibratorTimerCallbackProc, arg)); - } - - void CountDownModel::CountDown_VibratorTimerStart(uint32_t interval) - { - // 检查定时器是否存在 - if (g_vibrator_timer != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStart Timer already exists!!"); - return; - } - g_vibrator_timer = osTimerNew((osTimerFunc_t)CountDown_VibratorTimerCallback, osTimerPeriodic, nullptr, nullptr); - // 检查定时器创建是否成功 - if (g_vibrator_timer == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStart Timer create failed!!"); - return; - } - - int tick = osMs2Tick(interval); - osStatus_t ret = osTimerStart(g_vibrator_timer, tick); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_VibratorTimerStart] osTimerStart failed, ret = %lx!!", ret); - if (g_vibrator_timer != nullptr) - { - ret = osTimerDelete(g_vibrator_timer); - } - g_vibrator_timer = nullptr; - return; - } - return; - } - - void CountDownModel::CountDown_VibratorTimerStop(void) - { - // 检查定时器是否存在 - if (g_vibrator_timer != nullptr) - { - osTimerStop(g_vibrator_timer); - // 删除定时器并置为 nullptr - osStatus_t ret = osTimerDelete(g_vibrator_timer); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStop osTimerDelete failed, ret = %lx!!", ret); - } - g_vibrator_timer = nullptr; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stop vibrator timer success!!"); - } - } - - bool CountDownModel::isNeedVibratorTimerStop() - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "isNeedVibratorTimerStop"); - if (playerCtr.get() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr.get() == nullptr"); - return OHOS_FAILURE; - } - int32_t state = 0; - playerCtr->GetPlayerState(state); - if (state != PlayerStates::PLAYER_STARTED) - { - return true; - } - return false; - } - - - - /* ----------------------- CountDownRingPlayerListener ---------------------- */ - - void CountDownRingPlayerListener::SetOwner(std::shared_ptr player) - { - player_ = player; - } - - /*重置标志位*/ - void CountDownRingPlayerListener::RestFlag() - { - isPaused_ = false; - isDelayed_ = false; - isResumed_ = false; - isBeginStopped_ = false; - isEndStopped_ = false; - } - - bool CountDownRingPlayerListener::IsPaused() - { - return isPaused_; - } - - bool CountDownRingPlayerListener::IsDelayed() - { - return isDelayed_; - } - - bool CountDownRingPlayerListener::IsResumed() - { - return isResumed_; - } - - bool CountDownRingPlayerListener::IsBeginStopped() - { - return isBeginStopped_; - } - - bool CountDownRingPlayerListener::IsEndStopped() - { - return isEndStopped_; - } - - static void Start(void) - { - CountDownModel::GetInstance()->RequestStartRingtone(); - } - - static void Stop(void) - { - CountDownModel::GetInstance()->RequestStopRingtone(); - } - - /*开始计时器铃声播放*/ - void CountDownRingPlayerListener::StartCountDownRing(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CountDownRingPlayerListener::StartCountDownRing] start"); - GraphicService::GetInstance()->PostGraphicEvent(Start); - } - - /*停止计时器铃声播放*/ - void CountDownRingPlayerListener::StopCountDownRing(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CountDownRingPlayerListener::StopCountDownRing] start"); - GraphicService::GetInstance()->PostGraphicEvent(Stop); - } - - /*响应外部的音频中断事件*/ - void CountDownRingPlayerListener::OnInterrupt(int32_t type, int32_t hint) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnInterrupt go in, type %d, hint %d.", type, hint); - if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_PAUSE) - { - isDelayed_ = true; - } - - if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_STOP) - { - StopCountDownRing(); - } - else if (type == INTERRUPT_TYPE_END && isDelayed_ == true) - { - // 重新开始计时器的铃声播放 - StartCountDownRing(); - isDelayed_ = false; - } - return; - } - - /* --------------------- CountDownRingPlayerCallbackImpl -------------------- */ - void CountDownRingPlayerCallbackImpl::OnPlaybackComplete(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnPlaybackComplete"); - // CountDownModel::GetInstance()->RequestStopRingtone(); - // CountDownModel::GetInstance()->RequestStartRingtone(); - } - - void CountDownRingPlayerCallbackImpl::OnError(int32_t errorType, int32_t errorCode) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnError test, errorType %d, errorCode %d", errorType, errorCode); - // 此处实现代码处理错误事件 - } - - void CountDownRingPlayerCallbackImpl::OnInfo(int type, int extra) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnInfo test, type %d, extra %d.", type, extra); - // 此处实现代码处理普通事件 - } - - void CountDownRingPlayerCallbackImpl::OnRewindToComplete(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRewindToComplete test"); - // 此处实现代码处理进度控制完成的事件 - } -} +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-07 18:15:53 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-12-18 17:42:19 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp + */ +#include "countdown/include/CountDownModel.h" +#include +#include +#include +#include "wearable_log.h" +#include "countdown/include/MainCountDownView.h" +#include +#include "ConfigModel.h" +#include "ui_resource_string.h" +#include "custom_runtime.h" +#include "uiservice/include/ui_service.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include +#include +#include +#include "vibrator_service.h" +namespace OHOS +{ + /* -------------------------------------------------------------------------- */ + // 声明定时器变量 + static osTimerId_t g_timer = nullptr; + int CountDownModel::g_CountDownTimes = {0}; + int CountDownModel::totalSeconds = 0; //总的倒计时时间 + uint64_t CountDownModel::startTime = 0; + uint64_t CountDownModel::pauseTime = 0; + uint64_t CountDownModel::endTime = 0; + static constexpr int32 NUM_TEN = 10; // 主要用于格式化输出,当小时、分钟或秒小于10时,在其前面添加一个’0’以保持常规时间格式,例如“09:05:03”。 + static constexpr int16 NUM_TIME_MIN = 60; + static constexpr int16 NUM_TIME_HOUR = 3600; + static constexpr int32 NUM_TIME_DAY = 86400; + + /* -------------------------------------------------------------------------- */ + // 定义了 GetInstance() 方法来获取 CountDownModel 的实例,确保只有一个全局实例存在。 + CountDownModel *CountDownModel::GetInstance() + { + static CountDownModel instance; + return &instance; + } + + // 函数用于解析"HH:MM:SS"格式的时间字符串,并更新g_CountDownTimes + void CountDownModel::ParseCountDownTime(const char *countdowntime) + { + int hours, minutes, seconds; + + // 使用sscanf从字符串中读取格式化数据 + // "%2d:%2d:%2d"用于检查两个数字,后面跟一个冒号,这样的模式重复两次,从而捕获三个整数 + if (sscanf(countdowntime, "%2d:%2d:%2d", &hours, &minutes, &seconds) == 3) + { + // 解析成功,现在转换为总秒数 + g_CountDownTimes = hours * NUM_TIME_HOUR + minutes * NUM_TIME_MIN + seconds; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "g_CountDownTimes = %d", g_CountDownTimes); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::ParseCountDownTime Parsing failure"); + } + } + + std::string CountDownModel::ParseRingTime(const std::string &timeStr) + { + int hours, minutes, seconds; + std::string formattedTime; + // 使用 sscanf 从字符串中读取时间数据 + if (sscanf(timeStr.c_str(), "%2d:%2d:%2d", &hours, &minutes, &seconds) == 3) + { + // 如果小时部分为0,则格式化去掉小时部分 + if (hours == 0) + { + formattedTime = (minutes < NUM_TEN ? "0" : "") + std::to_string(minutes) + ":" + (seconds < NUM_TEN ? "0" : "") + std::to_string(seconds); + } + else + { + // 如果小时部分不为0,保持原有格式 + formattedTime = timeStr; + } + } + else + { + // 解析失败逻辑处理:可以选择记录错误、返回原字符串或其他合适的处理方式 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrimTimeFormat Parsing failure: Invalid format"); + formattedTime = timeStr; // 例子中选择返回原字符串 + } + return formattedTime; + } + + // 设置倒计时时间 + void CountDownModel::SetCountDownTime(const std::string &countdowntime) + { + CountTime = countdowntime; + CountTimeBackup = countdowntime; + ParseCountDownTime(CountTime.c_str()); + } + + // 获取倒计时时间 + std::string CountDownModel::GetCountDownTime(void) + { + return CountTime; + } + + std::string CountDownModel::GetBackupCountDownTime(void) + { + return CountTimeBackup; + } + + // 设置响铃时间 + void CountDownModel::SetRingTime(const std::string &ringtime) + { + RingTime = ParseRingTime(ringtime); + } + + // 获取响铃时间 + std::string CountDownModel::GetRingTime(void) + { + return RingTime; + } + + /* + * @brief 初始化音乐播放器以播放一个指定的铃声文件 + * @param {char*} RingMusicName 铃声文件 + */ + int CountDownModel::CountDownRingPlayerInit(const char *RingMusicName) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDownRingPlayerInit"); + /* ------------------------------- 1.播放文件路径设置 ------------------------------- */ + uri = RingMusicName; + /* -------------------------------- 2.播放器对象创建 ------------------------------- */ + if (playerCtr.get() == nullptr) + { + playerCtr = std::make_shared(); + if (playerCtr.get() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr new fail"); + return OHOS_FAILURE; + } + } + /* ------------------------------- 3.播放器回调对象创建 ------------------------------ */ + if (playerCallback.get() == nullptr) + { + playerCallback = std::make_shared(); + if (playerCallback.get() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCallback new fail"); + return OHOS_FAILURE; + } + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CountDownModel] PlayerInit success!"); + return OHOS_SUCCESS; + } + + /* + * @brief 对铃声播放器进行设置并开始播放铃声。 + */ + int CountDownModel::InitializeAndPlayRingtone(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CountDownModel::InitializeAndPlayRingtone"); + /* -------------------------------- 1.检查播放器实例 ------------------------------- */ + int32_t ret; + int32_t state; + if (playerCtr.get() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr.get() == nullptr"); + return OHOS_FAILURE; + } + playerCtr->GetPlayerState(state); + /* -------------------------------- 2.设置播放器回调 ------------------------------- */ + playerCtr->SetPlayerCallback(playerCallback); + /* -------------------------------- 3.创建并设置音频源 -------------------------------- */ + source = std::make_shared(uri, header); + if (source.get() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] source.get() == fail"); + return OHOS_FAILURE; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Player url:%s", uri.c_str()); + playerCtr->SetSource(*source); + /* --------------------------------- 4.配置播放器 -------------------------------- */ + playerCtr->SetAudioStreamType(AUDIO_STREAM_NOTIFICATION_SYSTEM); // 设置播放器的音频流类型 + playerCtr->Prepare(); // 准备播放器对象以播放音频。 + /* -------------------------------- 5.请求音频焦点 -------------------------------- */ + AudioManager &amIntance = AudioManager::GetInstance(); + sessionId = amIntance.MakeSessionId(); + if (sessionId == AUDIO_SESSION_ID_NONE) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] sessionId invalid!!"); + return OHOS_FAILURE; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CountDownModel] MakeSessionId = %d", sessionId); + playerInterruptListener = std::make_shared(); // 创建音频中断监听器 + if (playerInterruptListener.get() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerInterruptListener playerInterruptListener.get() == nullptr"); + return OHOS_FAILURE; + } + playerInterruptListener->SetOwner(playerCtr); + interrupt = {AUDIO_STREAM_NOTIFICATION_SYSTEM, sessionId, playerInterruptListener}; + // 激活音频中断 5s超时 + if (amIntance.ActivateAudioInterrupt(interrupt) == INTERRUPT_FAILED) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ActivateAudioInterrupt faild"); + return OHOS_FAILURE; + } + // playerCtr->SetVolume(50, 50); // 将左声道和右声道音量都设置为50 + playerCtr->SetAudioSessionId(sessionId); + // 播放 + ret = playerCtr->Play(); + if(ret == 0) + { + //如果倒计时铃声播放成功,记录该事件 + uapi_save_runtime_log(RUNTIME_LOG_RING_PLAY_START_COUNTDOWN);//TOOD* + } + playerCtr->EnableSingleLooping(true); // 设置是否循环播放 + return OHOS_SUCCESS; + } + + /* + * @brief 开始铃声的播放 + */ + int CountDownModel::StartRingtonePlayback(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CountDownModel::StartRingtonePlayback"); + if (CountDownRingPlayerInit(RingMusicPath) != OHOS_SUCCESS) + { + // 错误处理,例如记录日志或者返回错误状态码 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDownRingPlayerInit error!!"); + return OHOS_FAILURE; + } + + if (InitializeAndPlayRingtone() != OHOS_SUCCESS) + { + // 错误处理,例如记录日志或者返回错误状态码 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::InitializeAndPlayRingtone error!!"); + return OHOS_FAILURE; + } + return OHOS_SUCCESS; + } + + /* + * @brief 停止播放铃声,重置并释放播放器资源,并去激活之前设置的音频中断。 + */ + int CountDownModel::StopRingtonePlaybackAndReleaseResources(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CountDownModel::StopRingtonePlaybackAndReleaseResources"); + int32_t ret = 0; + int32_t state = 0; + AudioManager &amIntance = AudioManager::GetInstance(); + if (playerCtr.get() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr.get() == nullptr"); + return OHOS_FAILURE; + } + playerCtr->GetPlayerState(state); + if (state == PlayerStates::PLAYER_STARTED || state == PlayerStates::PLAYER_PAUSED) + { + ret = playerCtr->Stop(); + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Failed to stop the player"); + return OHOS_FAILURE; + } + //如果倒计时铃声停止播放成功,记录该事件 + uapi_save_runtime_log(RUNTIME_LOG_RING_PLAY_STOP_COUNTDOWN);//TOOD* + } + ret = playerCtr->Reset(); + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Failed to reset the player"); + return OHOS_FAILURE; + } + ret = playerCtr->Release(); + playerCtr.reset(); + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Failed to release the player"); + return OHOS_FAILURE; + } + if (amIntance.DeactivateAudioInterrupt(interrupt) != 0) + { + return OHOS_FAILURE; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reset, ret:%d", ret); + return OHOS_SUCCESS; + } + + int CountDownModel::ResetRingtonePlayback(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CountDownModel::ResetRingtonePlayback"); + int32_t ret = 0; + int32_t state = 0; + if (playerCtr.get() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr is null"); + return OHOS_FAILURE; + } + playerCtr->GetPlayerState(state); + if (state == PlayerStates::PLAYER_STARTED || state == PlayerStates::PLAYER_PAUSED) + { + ret = playerCtr->Stop(); + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Failed to stop the player"); + return OHOS_FAILURE; + } + } + ret = playerCtr->Reset(); + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Failed to reset the player"); + return OHOS_FAILURE; + } + return OHOS_SUCCESS; + } + + template + static void PostRingtoneEvent(Func function) + { + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(function, CountDownModel::GetInstance())); + } + + /*触发铃声的开始*/ + void CountDownModel::RequestStartRingtone(void) + { + if (uapi_sleep_mode_flag_get()) + { + return; + } + if (true != ConfigModel::GetInstance()->GetDnotdisturb()) + { + PostRingtoneEvent(&CountDownModel::StartRingtonePlayback); + } + } + + /*触发铃声的停止*/ + void CountDownModel::RequestStopRingtone(void) + { + // PostRingtoneEvent(&CountDownModel::StopRingtonePlaybackAndReleaseResources); + } + + // 判断计时器是否结束 + bool CountDownModel::CountDownTimerIsEnd() // 计时器是否结束 + { + if (g_timer == nullptr) + { + return true; + } + return false; + } + // 获取是否需要跳转到开始到计时界面 + bool CountDownModel::GetChanageToStartCountDownView() + { + return IsChanageToStartCountDownViewFlag; + } + + // 设置是否需要跳转到开始到计时界面 + void CountDownModel::SetChanageToStartCountDownView(bool val) + { + IsChanageToStartCountDownViewFlag = val; + } + + bool CountDownModel::CountDownViewIsExit() // 计时器界面是否退出 + { + MainCountDownView *g_CountDownView = MainCountDownView::GetInstance(); + if (g_CountDownView == nullptr) + { + return true; + } + return false; + } + + // 处理倒计时到期时的一些操作 + void CountDownModel::HandCountDownEndOperator(void) + { + StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); + if (p_StartCountDownView) + { + CountDown_StopTimer(); // 停止定时器 + uapi_set_screen_on_api(); // 点亮屏幕 + // CountDownModel::GetInstance()->RequestStartRingtone(); // 播放铃声 + CountDownModel::GetInstance()->CountDown_VibratorTimerStart(); // 触发震动 + + StartCountDownView::GetInstance()->GetPlayOrPauseToggleButton()->SetVisible(false); + p_StartCountDownView->GetRepeatButton()->SetVisible(true); + /*倒计时结束 显示大图标 */ + p_StartCountDownView->ShowEndView(true); + } + } + + bool CountDownModel::GetCountDownTimerIsPause() + { + return CountDownTimerIsPauseFlag; + } + void CountDownModel::SetCountDownTimerIsPause(bool val) + { + CountDownTimerIsPauseFlag = val; + } + /* ----------------------------------- 定时器 ---------------------------------- */ + + /* + * @brief 显示计时器(时、分、秒) + */ + const char *CountDownModel::DisplayCountDownDuration() + { + countdownDuration.clear(); // 更正为clear(),更加表明意图,与erase()等价 + std::string hours; + std::string minute; + std::string seconds; + + if (g_CountDownTimes >= NUM_TIME_DAY) + { + g_CountDownTimes = 0; + } + + int hour = g_CountDownTimes / NUM_TIME_HOUR; + int min = (g_CountDownTimes % NUM_TIME_HOUR) / NUM_TIME_MIN; + int sec = (g_CountDownTimes % NUM_TIME_HOUR) % NUM_TIME_MIN; + + hours = (hour < NUM_TEN) ? "0" + std::to_string(hour) : std::to_string(hour); + minute = (min < NUM_TEN) ? "0" + std::to_string(min) : std::to_string(min); + seconds = (sec < NUM_TEN) ? "0" + std::to_string(sec) : std::to_string(sec); + countdownDuration = hours + ":" + minute + ":" + seconds; + + return countdownDuration.c_str(); // 返回 std::string 的 c_str(),但需要注意生命周期 + } + /* + * @brief 在这里添加定时器到期后的处理逻辑 + */ + static void CountDown_TimerCallbackProc(int data) + { + if (CountDownModel::GetInstance()->CountDownViewIsExit()) // 如果已经退出了界面定时器还在跑,就先跳转Slice + { + CountDownModel::GetInstance()->CountDown_StopTimer(); // 停止定时器 + CountDownModel::GetInstance()->SetChanageToStartCountDownView(true); + OHOS::AbilityNavigation::EnterSlice(VIEW_MAIN_COUNTDOWN); + } + else + { + StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); + if (p_StartCountDownView) + { + CountDownModel::GetInstance()->HandCountDownEndOperator(); + } + } + return; + } + + /* + * @brief 计时器回调函数 + */ + static void CountDown_TimerCallback(int data) + { + + /*拿系统时间实现倒计时功能*/ + bool isRunning = CountDownModel::GetInstance()->GetisRunning(); + bool isPaused = CountDownModel::GetInstance()->GetisPaused(); + + if (isRunning && !isPaused) + { + uint64_t currentTime = CountDownModel::GetInstance()->get_current_time(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentTime(ms):%llu,endTime(ms):%llu",currentTime,CountDownModel::endTime); + if (currentTime >= CountDownModel::endTime) { + CountDownModel::g_CountDownTimes = 0; + // 这里可以添加倒计时结束后的操作,比如发出提示音等 + GraphicService::GetInstance()->PostGraphicEvent(std::bind(CountDown_TimerCallbackProc, data)); + return; + } + uint64_t remainingMs = CountDownModel::endTime - currentTime; + CountDownModel::g_CountDownTimes = static_cast((remainingMs + 999) / 1000); // ceil to seconds + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "当前时间戳(ms):%u,倒计时剩余时间(s):%d", currentTime, CountDownModel::g_CountDownTimes); + } + } + + uint64_t CountDownModel::get_current_time() + { + uint32_t time = 0; + if (uapi_get_timestampe_ss(&time) != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get timestamp"); + return 0; + } // 秒级时间戳转换成毫秒级时间戳 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentTime(ms)转换前:%u",time); + uint64_t timeMs = static_cast(time) * 1000; // 秒级时间戳转换成毫秒级时间戳 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "currentTime(ms)转换后:%llu",timeMs); + return timeMs; + } + + void CountDownModel::countdownstart() + { + isRunning = true; + isPaused = false; + CountDownModel::totalSeconds = CountDownModel::g_CountDownTimes; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "totalSeconds:%u",CountDownModel::get_current_time()); + CountDownModel::startTime = get_current_time(); //获取开始时间戳 + CountDownModel::endTime = CountDownModel::startTime + static_cast(g_CountDownTimes) * 1000; //获取结束时间戳(ms) + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "startTime(ms):%llu,endTime(ms):%llu,totalSeconds:%d",CountDownModel::startTime,CountDownModel::endTime,CountDownModel::totalSeconds); + + } + + void CountDownModel::countdownpause() + { + if (isRunning &&!isPaused) { + isPaused = true; + CountDownModel::pauseTime = get_current_time(); + } + } + void CountDownModel::countdownresume() + { + if (isRunning && isPaused) { + isPaused = false; + uint64_t currentTime = get_current_time(); + uint64_t pauseDuration = currentTime - CountDownModel::pauseTime; + CountDownModel::endTime = CountDownModel::endTime + pauseDuration; + if (currentTime >= CountDownModel::endTime) { + CountDownModel::g_CountDownTimes = 0; + } else { + uint64_t remainingMs = CountDownModel::endTime - currentTime; + CountDownModel::g_CountDownTimes = static_cast((remainingMs + 999) / 1000); // ceil to seconds + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "startTime(ms):%llu,pauseDuration(ms):%llu,endTime(ms):%llu", + CountDownModel::startTime, pauseDuration, CountDownModel::endTime); + } + } + + void CountDownModel::countdownstop() + { + isRunning = false; + isPaused = false; + } + + /* + * @brief 开启定时器函数 + * @param interval 时间间隔,单位ms + */ + void CountDownModel::CountDown_StartTimer(uint32_t interval) + { + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ + if (g_timer != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer already exists!!"); + return; + } + + countdownstart(); + + /* --------------------------------- 2.创建定时器 -------------------------------- */ + g_timer = osTimerNew((osTimerFunc_t)CountDown_TimerCallback, osTimerPeriodic, nullptr, nullptr); + // 检查定时器创建是否成功 + if (g_timer == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer create failed!!"); + return; + } + + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ + int tick = osMs2Tick(interval); + + /* --------------------------------- 4.启动定时器 -------------------------------- */ + // g_timerStartTimestamp = GetCurrentTimestamp(); // 假设GetCurrentTimestamp()是获取当前时间戳的函数 + osStatus_t ret = osTimerStart(g_timer, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_StartTimer] osTimerDelete failed, ret = %lx!!", ret); + if (g_timer != nullptr) + { + ret = osTimerDelete(g_timer); + } + g_timer = nullptr; + return; + } + return; + } + + /* + * @brief 停止定时器 + */ + void CountDownModel::CountDown_StopTimer(void) + { + // 检查定时器是否存在 + if (g_timer != nullptr) + { + countdownstop(); + + osTimerStop(g_timer); + // 删除定时器并置为 nullptr + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret); + } + g_timer = nullptr; + g_CountDownTimes = 0; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stop timer success!!"); + } + } + /* + * @brief 暂停定时器 + */ + void CountDownModel::CountDown_PauseTimer(void) + { + // 检查定时器是否存在 + if (g_timer != nullptr) + { + countdownpause(); + + // 暂停定时器,但不删除它 + osStatus_t ret = osTimerStop(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_PauseTimer osTimerStop failed, ret = %lx!!", ret); + } + } + } + + /* + * @brief 恢复定时器 + */ + void CountDownModel::CountDown_ResumeTimer(uint32_t interval) + { + // 检查定时器是否存在 + if (g_timer != nullptr) + { + countdownresume(); + + int tick = osMs2Tick(interval); + // 恢复定时器 + osStatus_t ret = osTimerStart(g_timer, tick); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_ResumeTimer osTimerStart failed, ret = %lx!!", ret); + } + } + } + + static osTimerId_t g_vibrator_timer = nullptr; + static void CountDown_VibratorTimerCallbackProc(void *arg) + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerCallbackProc"); + // 触发震动 + custom_VibratorFunc_int(0); + custom_VibratorFunc_int(0); + } + + static void CountDown_VibratorTimerCallback(void *arg) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(CountDown_VibratorTimerCallbackProc, arg)); + } + + void CountDownModel::CountDown_VibratorTimerStart(uint32_t interval) + { + // 检查定时器是否存在 + if (g_vibrator_timer != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStart Timer already exists!!"); + return; + } + g_vibrator_timer = osTimerNew((osTimerFunc_t)CountDown_VibratorTimerCallback, osTimerPeriodic, nullptr, nullptr); + // 检查定时器创建是否成功 + if (g_vibrator_timer == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStart Timer create failed!!"); + return; + } + + int tick = osMs2Tick(interval); + osStatus_t ret = osTimerStart(g_vibrator_timer, tick); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_VibratorTimerStart] osTimerStart failed, ret = %lx!!", ret); + if (g_vibrator_timer != nullptr) + { + ret = osTimerDelete(g_vibrator_timer); + } + g_vibrator_timer = nullptr; + return; + } + return; + } + + void CountDownModel::CountDown_VibratorTimerStop(void) + { + // 检查定时器是否存在 + if (g_vibrator_timer != nullptr) + { + osTimerStop(g_vibrator_timer); + // 删除定时器并置为 nullptr + osStatus_t ret = osTimerDelete(g_vibrator_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDown_VibratorTimerStop osTimerDelete failed, ret = %lx!!", ret); + } + g_vibrator_timer = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stop vibrator timer success!!"); + } + } + + bool CountDownModel::isNeedVibratorTimerStop() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "isNeedVibratorTimerStop"); + if (playerCtr.get() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] playerCtr.get() == nullptr"); + return OHOS_FAILURE; + } + int32_t state = 0; + playerCtr->GetPlayerState(state); + if (state != PlayerStates::PLAYER_STARTED) + { + return true; + } + return false; + } + + + + /* ----------------------- CountDownRingPlayerListener ---------------------- */ + + void CountDownRingPlayerListener::SetOwner(std::shared_ptr player) + { + player_ = player; + } + + /*重置标志位*/ + void CountDownRingPlayerListener::RestFlag() + { + isPaused_ = false; + isDelayed_ = false; + isResumed_ = false; + isBeginStopped_ = false; + isEndStopped_ = false; + } + + bool CountDownRingPlayerListener::IsPaused() + { + return isPaused_; + } + + bool CountDownRingPlayerListener::IsDelayed() + { + return isDelayed_; + } + + bool CountDownRingPlayerListener::IsResumed() + { + return isResumed_; + } + + bool CountDownRingPlayerListener::IsBeginStopped() + { + return isBeginStopped_; + } + + bool CountDownRingPlayerListener::IsEndStopped() + { + return isEndStopped_; + } + + static void Start(void) + { + CountDownModel::GetInstance()->RequestStartRingtone(); + } + + static void Stop(void) + { + CountDownModel::GetInstance()->RequestStopRingtone(); + } + + /*开始计时器铃声播放*/ + void CountDownRingPlayerListener::StartCountDownRing(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CountDownRingPlayerListener::StartCountDownRing] start"); + GraphicService::GetInstance()->PostGraphicEvent(Start); + } + + /*停止计时器铃声播放*/ + void CountDownRingPlayerListener::StopCountDownRing(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CountDownRingPlayerListener::StopCountDownRing] start"); + GraphicService::GetInstance()->PostGraphicEvent(Stop); + } + + /*响应外部的音频中断事件*/ + void CountDownRingPlayerListener::OnInterrupt(int32_t type, int32_t hint) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnInterrupt go in, type %d, hint %d.", type, hint); + if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_PAUSE) + { + isDelayed_ = true; + } + + if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_STOP) + { + StopCountDownRing(); + } + else if (type == INTERRUPT_TYPE_END && isDelayed_ == true) + { + // 重新开始计时器的铃声播放 + StartCountDownRing(); + isDelayed_ = false; + } + return; + } + + /* --------------------- CountDownRingPlayerCallbackImpl -------------------- */ + void CountDownRingPlayerCallbackImpl::OnPlaybackComplete(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnPlaybackComplete"); + // CountDownModel::GetInstance()->RequestStopRingtone(); + // CountDownModel::GetInstance()->RequestStartRingtone(); + } + + void CountDownRingPlayerCallbackImpl::OnError(int32_t errorType, int32_t errorCode) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnError test, errorType %d, errorCode %d", errorType, errorCode); + // 此处实现代码处理错误事件 + } + + void CountDownRingPlayerCallbackImpl::OnInfo(int type, int extra) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnInfo test, type %d, extra %d.", type, extra); + // 此处实现代码处理普通事件 + } + + void CountDownRingPlayerCallbackImpl::OnRewindToComplete(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRewindToComplete test"); + // 此处实现代码处理进度控制完成的事件 + } +} diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/MainCountDownPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/MainCountDownPresenter.cpp index 0ee80e0b4..1d97b1b82 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/MainCountDownPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/countdown/src/MainCountDownPresenter.cpp @@ -1,316 +1,317 @@ -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "UiConfig.h" -#include "countdown/include/MainCountDownPresenter.h" -#include "countdown/include/CountDownModel.h" -#include "countdown/include/StartCountDownView.h" -#include "common/key_code.h" -#include "custom_utils.h" -#include "NativeRegisterManager.h" - -namespace OHOS -{ - REGIST_MENU_PRO(VIEW_MAIN_COUNTDOWN, MainCountDownView, MainCountDownPresenter, - PNG_APPLIST_COUNTDOWN_IMAGE_BIG, PNG_APPLIST_COUNTDOWN_IMAGE,PNG_APPLIST_COUNTDOWN_IMAGE, "计时器", STR_TIMER); - - static constexpr const char *OneMinuteTime = "00:01:00"; // 1分钟 - static constexpr const char *FiveMinuteTime = "00:05:00"; // 5分钟 - static constexpr const char *TenMinuteTime = "00:10:00"; // 10分钟 - static constexpr const char *ThirtyMinuteTime = "00:30:00"; // 30分钟 - - // 当前Presenter属性实例化的内存指针 - static MainCountDownPresenter *g_pMainCountDownPresenter = nullptr; - MainCountDownPresenter::MainCountDownPresenter() - { - g_pMainCountDownPresenter = this; - } - - MainCountDownPresenter::~MainCountDownPresenter() - { - g_pMainCountDownPresenter = nullptr; - } - - MainCountDownPresenter *MainCountDownPresenter::GetInstance() - { - - return g_pMainCountDownPresenter; - } - - void MainCountDownPresenter::OnStart() - { - // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 长亮屏 - } - - void MainCountDownPresenter::OnPause(void) - { - - Presenter::OnPause(); - } - - void MainCountDownPresenter::OnResume(void) - { - - RootView::GetInstance()->SetOnKeyActListener(this); - } - - void MainCountDownPresenter::OnStop(void) - { - // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 取消长亮屏 - CountDownModel::GetInstance()->StopRingtonePlaybackAndReleaseResources(); // 清理播放器资源 - } - - bool MainCountDownPresenter::OnDrag(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownPresenter::OnDrag"); - UNUSED(view); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - MainCountDownPresenter::X_DRAG_FLAG = true; - } - return true; - } - - bool MainCountDownPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownPresenter::OnDragEnd"); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainCountDownPresenter::X_DRAG_FLAG) - { - if (strcmp(view.GetViewId(), MAINCOUNTDOWNVIEW) == 0) - { - NativeAbility::GetInstance().Back(); - } - else if (strcmp(view.GetViewId(), COUNTDOWN_TIMECONFIG_VIEW) == 0) - { - MainCountDownView::GetInstance()->ChangeView(TIMECONFIG_COUNTDOWN, MAIN_COUNTDOWN); - } - MainCountDownPresenter::X_DRAG_FLAG = false; - } - return true; - } - - static bool SetCountDownAndChangeView(MainCountDownView *p_MainCountDownView, const std::string &timeValue) - { - CountDownModel *model = CountDownModel::GetInstance(); - model->SetCountDownTime(timeValue); - model->SetRingTime(timeValue); - - // Update label texts if necessary - if (p_MainCountDownView->GetStartCountDownView() != nullptr) - { - p_MainCountDownView->GetStartCountDownView()->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->GetCountDownTime().c_str()); - p_MainCountDownView->GetStartCountDownView()->GetShowTheRingTimelabel()->SetText(CountDownModel::GetInstance()->GetRingTime().c_str()); - p_MainCountDownView->GetStartCountDownView()->GetPlayOrPauseToggleButton()->SetVisible(true); - p_MainCountDownView->GetStartCountDownView()->GetRepeatButton()->SetVisible(false); - } - - p_MainCountDownView->ChangeView(MAIN_COUNTDOWN, START_COUNTDOWN); - return true; - } - - bool MainCountDownPresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(event); - - MainCountDownView *p_MainCountDownView = MainCountDownView::GetInstance(); - StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); - - if (p_MainCountDownView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCountDownView::GetInstance fail!!"); - return false; - } - - if (strcmp(view.GetViewId(), COUNTDOWN_LABELBUTTON_VIEWID) == 0) - { - p_MainCountDownView->ChangeView(MAIN_COUNTDOWN, TIMECONFIG_COUNTDOWN); - return true; - } - - /*四个快速开始倒计时按钮*/ - if (strcmp(view.GetViewId(), COUNTDOWN_ONE_MINUTE_BUTTON_VIEWID) == 0) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_ONE_MINUTE_BUTTON_VIEWID"); - return SetCountDownAndChangeView(p_MainCountDownView, OneMinuteTime); - } - else if (strcmp(view.GetViewId(), COUNTDOWN_FIVE_MINUTE_BUTTON_VIEWID) == 0) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_FIVE_MINUTE_BUTTON_VIEWID"); - return SetCountDownAndChangeView(p_MainCountDownView, FiveMinuteTime); - } - else if (strcmp(view.GetViewId(), COUNTDOWN_TEN_MINUTE_BUTTON_VIEWID) == 0) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_TEN_MINUTE_BUTTON_VIEWID"); - return SetCountDownAndChangeView(p_MainCountDownView, TenMinuteTime); - } - else if (strcmp(view.GetViewId(), COUNTDOWN_THIRTY_MINUTE_BUTTON_VIEWID) == 0) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_THIRTY_MINUTE_BUTTON_VIEWID"); - return SetCountDownAndChangeView(p_MainCountDownView, ThirtyMinuteTime); - } - - if (strcmp(view.GetViewId(), STARTCOUNTDOWN_BUTTON) == 0) // 在自定义倒计时界面点击开始按钮跳转到开始倒计时界面 - { - UITimePicker *timePicker = CountDownTimeConfigView::GetInstance()->GetTimePicker(); - - std::string timeValue = timePicker->GetSelectValue(); - if (nullptr != timePicker && ("00:00:00" != timeValue)) - { - CountDownModel::GetInstance()->SetCountDownTime(timePicker->GetSelectValue()); // 设置倒计时时间 - CountDownModel::GetInstance()->SetRingTime(timePicker->GetSelectValue()); // 设置响铃时间 - } - - if (strcmp(CountDownModel::GetInstance()->GetCountDownTime().c_str(), "00:00:00") == 0) // 如果自定义时间设置为0 - { - p_MainCountDownView->ChangeView(TIMECONFIG_COUNTDOWN, COUNTDOWN_TIMENOTNULL); - return true; - } - else - { - p_MainCountDownView->ChangeView(TIMECONFIG_COUNTDOWN, START_COUNTDOWN); - if (p_StartCountDownView != nullptr) - { - std::string CountDownTime = CountDownModel::GetInstance()->GetCountDownTime(); - std::string RingTime = CountDownModel::GetInstance()->GetRingTime(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownTime = %s RingTime = %s", CountDownTime.c_str(), RingTime.c_str()); - p_StartCountDownView->GetShowCountDownTimelabel()->SetText(CountDownTime.c_str()); - p_StartCountDownView->GetShowTheRingTimelabel()->SetText(RingTime.c_str()); - p_StartCountDownView->GetPlayOrPauseToggleButton()->SetVisible(true); - p_StartCountDownView->GetRepeatButton()->SetVisible(false); - } - - return true; - } - } - - if (strcmp(view.GetViewId(), COUNTDOWNTIMENOTNULLVIEWRETURNBUTTON) == 0) // 从倒计时不为空视图退到自定义倒计时界面 - { - p_MainCountDownView->ChangeView(COUNTDOWN_TIMENOTNULL, TIMECONFIG_COUNTDOWN); - /*结束视图恢复*/ - if (p_StartCountDownView == nullptr) - return false; - p_StartCountDownView->ShowEndView(false); - return true; - } - - if (strcmp(view.GetViewId(), STARTCOUNTDOWNVIEWRETURNBUTTON) == 0) // 从开始倒计时视图退到倒计时主视图 - { - CountDownModel::GetInstance()->CountDown_VibratorTimerStop();//重新开始倒计时要将震动关闭 - - CountDownModel::GetInstance()->SetCountDownTime("00:00:00"); - CountDownModel::GetInstance()->SetRingTime("00:00:00"); - CountDownModel::GetInstance()->CountDown_StopTimer(); - CountDownModel::GetInstance()->StopRingtonePlaybackAndReleaseResources(); - p_StartCountDownView->GetPlayOrPauseToggleButton()->SetTouchable(true); - p_StartCountDownView->GetPlayOrPauseToggleButton()->SetState(false); - p_MainCountDownView->ChangeView(START_COUNTDOWN, MAIN_COUNTDOWN); - p_StartCountDownView->ShowEndView(false); - - return true; - } - - // repeat button cb - if (0 == strcmp(view.GetViewId(), RepeatButtonViewID)) - { - // close prompt - CountDownModel::GetInstance()->StopRingtonePlaybackAndReleaseResources(); - - CountDownModel::GetInstance()->CountDown_VibratorTimerStop();//重新开始倒计时要将震动关闭 - - /*结束视图恢复*/ - if (p_StartCountDownView == nullptr) - return false; - p_StartCountDownView->ShowEndView(false); - - // set param & change view - CountDownModel *model = CountDownModel::GetInstance(); - const std::string timeValue = model->GetBackupCountDownTime(); - model->SetCountDownTime(timeValue); - model->SetRingTime(timeValue); - - if (nullptr != p_MainCountDownView->GetStartCountDownView()) - { - p_MainCountDownView->GetStartCountDownView()->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->GetCountDownTime().c_str()); - p_MainCountDownView->GetStartCountDownView()->GetShowTheRingTimelabel()->SetText(CountDownModel::GetInstance()->GetRingTime().c_str()); - - p_MainCountDownView->GetStartCountDownView()->GetPlayOrPauseToggleButton()->SetVisible(true); - p_MainCountDownView->GetStartCountDownView()->GetPlayOrPauseToggleButton()->SetState(true); - p_MainCountDownView->GetStartCountDownView()->GetRepeatButton()->SetVisible(false); - } - - // start timer - CountDownModel::GetInstance()->CountDown_StartTimer(COUNTDOWN_TIMER_DURATION); - - return true; - } - - return true; - } - - // 增加按键事件 - bool MainCountDownPresenter::OnKeyAct(UIView &view, const KeyEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownPresenter::OnKeyAct"); - uint16_t keyID = event.GetKeyId(); - uint16_t keyState = event.GetState(); - // 如果是power键就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; - } - - bool MainCountDownPresenter::OnChange(UICheckBox::UICheckBoxState state) - { - CountDownModel *p_CountDownModel = CountDownModel::GetInstance(); - StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); - if (p_CountDownModel == nullptr || p_StartCountDownView == nullptr) - return false; - - switch (state) - { - case UICheckBox::SELECTED: - p_CountDownModel->SetCountDownTimerIsPause(false); - p_CountDownModel->CountDown_StartTimer(COUNTDOWN_TIMER_DURATION); - p_CountDownModel->CountDown_ResumeTimer(COUNTDOWN_TIMER_DURATION); - if (p_StartCountDownView->GetShowCountDownTimelabel()) { - p_StartCountDownView->GetShowCountDownTimelabel()->SetText( - CountDownModel::GetInstance()->DisplayCountDownDuration()); - } - /*视图恢复*/ - p_StartCountDownView->SetImageAndLabel(true); - p_StartCountDownView->ShowEndView(false); - break; - case UICheckBox::UNSELECTED: - p_CountDownModel->SetCountDownTimerIsPause(true); - p_CountDownModel->CountDown_PauseTimer(); - /*进行视图隐藏*/ - p_StartCountDownView->SetImageAndLabel(false); - break; - default: - break; - } - return true; - } - - void MainCountDownPresenter::OnTimePickerStoped(UITimePicker &picker) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "picker.GetSelectValue = %s", picker.GetSelectValue()); - CountDownModel::GetInstance()->SetCountDownTime(picker.GetSelectValue()); // 设置倒计时时间 - CountDownModel::GetInstance()->SetRingTime(picker.GetSelectValue()); // 设置响铃时间 - } - void MainCountDownPresenter::Notify() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownPresenter::Notify"); - if (CountDownModel::GetInstance()->CountDownTimerIsEnd()) // 倒计时timer已经停止直接退出不刷新 - { - return; - } - StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); - if (p_StartCountDownView && p_StartCountDownView->GetShowCountDownTimelabel()) - { - // 更新显示 - p_StartCountDownView->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->DisplayCountDownDuration()); - } - } +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "UiConfig.h" +#include "countdown/include/MainCountDownPresenter.h" +#include "countdown/include/CountDownModel.h" +#include "countdown/include/StartCountDownView.h" +#include "common/key_code.h" +#include "custom_utils.h" +#include "NativeRegisterManager.h" + +namespace OHOS +{ + REGIST_MENU_PRO(VIEW_MAIN_COUNTDOWN, MainCountDownView, MainCountDownPresenter, + PNG_APPLIST_COUNTDOWN_IMAGE_BIG, PNG_APPLIST_COUNTDOWN_IMAGE,PNG_APPLIST_COUNTDOWN_IMAGE, "计时器", STR_TIMER); + + static constexpr const char *OneMinuteTime = "00:01:00"; // 1分钟 + static constexpr const char *FiveMinuteTime = "00:05:00"; // 5分钟 + static constexpr const char *TenMinuteTime = "00:10:00"; // 10分钟 + static constexpr const char *ThirtyMinuteTime = "00:30:00"; // 30分钟 + + // 当前Presenter属性实例化的内存指针 + static MainCountDownPresenter *g_pMainCountDownPresenter = nullptr; + MainCountDownPresenter::MainCountDownPresenter() + { + g_pMainCountDownPresenter = this; + } + + MainCountDownPresenter::~MainCountDownPresenter() + { + g_pMainCountDownPresenter = nullptr; + } + + MainCountDownPresenter *MainCountDownPresenter::GetInstance() + { + + return g_pMainCountDownPresenter; + } + + void MainCountDownPresenter::OnStart() + { + // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 长亮屏 + } + + void MainCountDownPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void MainCountDownPresenter::OnResume(void) + { + + RootView::GetInstance()->SetOnKeyActListener(this); + } + + void MainCountDownPresenter::OnStop(void) + { + // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 取消长亮屏 + CountDownModel::GetInstance()->StopRingtonePlaybackAndReleaseResources(); // 清理播放器资源 + } + + bool MainCountDownPresenter::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownPresenter::OnDrag"); + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + MainCountDownPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool MainCountDownPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainCountDownPresenter::X_DRAG_FLAG) + { + if (strcmp(view.GetViewId(), MAINCOUNTDOWNVIEW) == 0) + { + OHOS::AbilityNavigation::Back(); + } + else if (strcmp(view.GetViewId(), COUNTDOWN_TIMECONFIG_VIEW) == 0) + { + MainCountDownView::GetInstance()->ChangeView(TIMECONFIG_COUNTDOWN, MAIN_COUNTDOWN); + } + MainCountDownPresenter::X_DRAG_FLAG = false; + } + return true; + } + + static bool SetCountDownAndChangeView(MainCountDownView *p_MainCountDownView, const std::string &timeValue) + { + CountDownModel *model = CountDownModel::GetInstance(); + model->SetCountDownTime(timeValue); + model->SetRingTime(timeValue); + + // Update label texts if necessary + if (p_MainCountDownView->GetStartCountDownView() != nullptr) + { + p_MainCountDownView->GetStartCountDownView()->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->GetCountDownTime().c_str()); + p_MainCountDownView->GetStartCountDownView()->GetShowTheRingTimelabel()->SetText(CountDownModel::GetInstance()->GetRingTime().c_str()); + p_MainCountDownView->GetStartCountDownView()->GetPlayOrPauseToggleButton()->SetVisible(true); + p_MainCountDownView->GetStartCountDownView()->GetRepeatButton()->SetVisible(false); + } + + p_MainCountDownView->ChangeView(MAIN_COUNTDOWN, START_COUNTDOWN); + return true; + } + + bool MainCountDownPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + + MainCountDownView *p_MainCountDownView = MainCountDownView::GetInstance(); + StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); + + if (p_MainCountDownView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCountDownView::GetInstance fail!!"); + return false; + } + + if (strcmp(view.GetViewId(), COUNTDOWN_LABELBUTTON_VIEWID) == 0) + { + p_MainCountDownView->ChangeView(MAIN_COUNTDOWN, TIMECONFIG_COUNTDOWN); + return true; + } + + /*四个快速开始倒计时按钮*/ + if (strcmp(view.GetViewId(), COUNTDOWN_ONE_MINUTE_BUTTON_VIEWID) == 0) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_ONE_MINUTE_BUTTON_VIEWID"); + return SetCountDownAndChangeView(p_MainCountDownView, OneMinuteTime); + } + else if (strcmp(view.GetViewId(), COUNTDOWN_FIVE_MINUTE_BUTTON_VIEWID) == 0) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_FIVE_MINUTE_BUTTON_VIEWID"); + return SetCountDownAndChangeView(p_MainCountDownView, FiveMinuteTime); + } + else if (strcmp(view.GetViewId(), COUNTDOWN_TEN_MINUTE_BUTTON_VIEWID) == 0) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_TEN_MINUTE_BUTTON_VIEWID"); + return SetCountDownAndChangeView(p_MainCountDownView, TenMinuteTime); + } + else if (strcmp(view.GetViewId(), COUNTDOWN_THIRTY_MINUTE_BUTTON_VIEWID) == 0) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_THIRTY_MINUTE_BUTTON_VIEWID"); + return SetCountDownAndChangeView(p_MainCountDownView, ThirtyMinuteTime); + } + + if (strcmp(view.GetViewId(), STARTCOUNTDOWN_BUTTON) == 0) // 在自定义倒计时界面点击开始按钮跳转到开始倒计时界面 + { + UITimePicker *timePicker = CountDownTimeConfigView::GetInstance()->GetTimePicker(); + + std::string timeValue = timePicker->GetSelectValue(); + if (nullptr != timePicker && ("00:00:00" != timeValue)) + { + CountDownModel::GetInstance()->SetCountDownTime(timePicker->GetSelectValue()); // 设置倒计时时间 + CountDownModel::GetInstance()->SetRingTime(timePicker->GetSelectValue()); // 设置响铃时间 + } + + if (strcmp(CountDownModel::GetInstance()->GetCountDownTime().c_str(), "00:00:00") == 0) // 如果自定义时间设置为0 + { + p_MainCountDownView->ChangeView(TIMECONFIG_COUNTDOWN, COUNTDOWN_TIMENOTNULL); + return true; + } + else + { + p_MainCountDownView->ChangeView(TIMECONFIG_COUNTDOWN, START_COUNTDOWN); + if (p_StartCountDownView != nullptr) + { + std::string CountDownTime = CountDownModel::GetInstance()->GetCountDownTime(); + std::string RingTime = CountDownModel::GetInstance()->GetRingTime(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownTime = %s RingTime = %s", CountDownTime.c_str(), RingTime.c_str()); + p_StartCountDownView->GetShowCountDownTimelabel()->SetText(CountDownTime.c_str()); + p_StartCountDownView->GetShowTheRingTimelabel()->SetText(RingTime.c_str()); + p_StartCountDownView->GetPlayOrPauseToggleButton()->SetVisible(true); + p_StartCountDownView->GetRepeatButton()->SetVisible(false); + } + + return true; + } + } + + if (strcmp(view.GetViewId(), COUNTDOWNTIMENOTNULLVIEWRETURNBUTTON) == 0) // 从倒计时不为空视图退到自定义倒计时界面 + { + p_MainCountDownView->ChangeView(COUNTDOWN_TIMENOTNULL, TIMECONFIG_COUNTDOWN); + /*结束视图恢复*/ + if (p_StartCountDownView == nullptr) + return false; + p_StartCountDownView->ShowEndView(false); + return true; + } + + if (strcmp(view.GetViewId(), STARTCOUNTDOWNVIEWRETURNBUTTON) == 0) // 从开始倒计时视图退到倒计时主视图 + { + CountDownModel::GetInstance()->CountDown_VibratorTimerStop();//重新开始倒计时要将震动关闭 + + CountDownModel::GetInstance()->SetCountDownTime("00:00:00"); + CountDownModel::GetInstance()->SetRingTime("00:00:00"); + CountDownModel::GetInstance()->CountDown_StopTimer(); + CountDownModel::GetInstance()->StopRingtonePlaybackAndReleaseResources(); + p_StartCountDownView->GetPlayOrPauseToggleButton()->SetTouchable(true); + p_StartCountDownView->GetPlayOrPauseToggleButton()->SetState(false); + p_MainCountDownView->ChangeView(START_COUNTDOWN, MAIN_COUNTDOWN); + p_StartCountDownView->ShowEndView(false); + + return true; + } + + // repeat button cb + if (0 == strcmp(view.GetViewId(), RepeatButtonViewID)) + { + // close prompt + CountDownModel::GetInstance()->StopRingtonePlaybackAndReleaseResources(); + + CountDownModel::GetInstance()->CountDown_VibratorTimerStop();//重新开始倒计时要将震动关闭 + + /*结束视图恢复*/ + if (p_StartCountDownView == nullptr) + return false; + p_StartCountDownView->ShowEndView(false); + + // set param & change view + CountDownModel *model = CountDownModel::GetInstance(); + const std::string timeValue = model->GetBackupCountDownTime(); + model->SetCountDownTime(timeValue); + model->SetRingTime(timeValue); + + if (nullptr != p_MainCountDownView->GetStartCountDownView()) + { + p_MainCountDownView->GetStartCountDownView()->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->GetCountDownTime().c_str()); + p_MainCountDownView->GetStartCountDownView()->GetShowTheRingTimelabel()->SetText(CountDownModel::GetInstance()->GetRingTime().c_str()); + + p_MainCountDownView->GetStartCountDownView()->GetPlayOrPauseToggleButton()->SetVisible(true); + p_MainCountDownView->GetStartCountDownView()->GetPlayOrPauseToggleButton()->SetState(true); + p_MainCountDownView->GetStartCountDownView()->GetRepeatButton()->SetVisible(false); + } + + // start timer + CountDownModel::GetInstance()->CountDown_StartTimer(COUNTDOWN_TIMER_DURATION); + + return true; + } + + return true; + } + + // 增加按键事件 + bool MainCountDownPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownPresenter::OnKeyAct"); + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; + } + + bool MainCountDownPresenter::OnChange(UICheckBox::UICheckBoxState state) + { + CountDownModel *p_CountDownModel = CountDownModel::GetInstance(); + StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); + if (p_CountDownModel == nullptr || p_StartCountDownView == nullptr) + return false; + + switch (state) + { + case UICheckBox::SELECTED: + p_CountDownModel->SetCountDownTimerIsPause(false); + p_CountDownModel->CountDown_StartTimer(COUNTDOWN_TIMER_DURATION); + p_CountDownModel->CountDown_ResumeTimer(COUNTDOWN_TIMER_DURATION); + if (p_StartCountDownView->GetShowCountDownTimelabel()) { + p_StartCountDownView->GetShowCountDownTimelabel()->SetText( + CountDownModel::GetInstance()->DisplayCountDownDuration()); + } + /*视图恢复*/ + p_StartCountDownView->SetImageAndLabel(true); + p_StartCountDownView->ShowEndView(false); + break; + case UICheckBox::UNSELECTED: + p_CountDownModel->SetCountDownTimerIsPause(true); + p_CountDownModel->CountDown_PauseTimer(); + /*进行视图隐藏*/ + p_StartCountDownView->SetImageAndLabel(false); + break; + default: + break; + } + return true; + } + + void MainCountDownPresenter::OnTimePickerStoped(UITimePicker &picker) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "picker.GetSelectValue = %s", picker.GetSelectValue()); + CountDownModel::GetInstance()->SetCountDownTime(picker.GetSelectValue()); // 设置倒计时时间 + CountDownModel::GetInstance()->SetRingTime(picker.GetSelectValue()); // 设置响铃时间 + } + void MainCountDownPresenter::Notify() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownPresenter::Notify"); + if (CountDownModel::GetInstance()->CountDownTimerIsEnd()) // 倒计时timer已经停止直接退出不刷新 + { + return; + } + StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); + if (p_StartCountDownView && p_StartCountDownView->GetShowCountDownTimelabel()) + { + // 更新显示 + p_StartCountDownView->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->DisplayCountDownDuration()); + } + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp index 7934bb5bf..1688cc108 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp @@ -1,347 +1,348 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-03-30 09:14:38 - * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-07-14 15:27:15 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp - */ -#include "AppViewIDs.h" -#include "UiConfig.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "NativeAbility.h" -#include "graphic_math.h" -#include "string.h" -#include "displaybrightness/include/DisplayBrightnessPresenter.h" -#ifdef SUPPORT_CAT1_SERVICE -#include "cat1_ctl.h" -#endif -#include "displaybrightness/include/DisplayBrightnessModel.h" -#include "power_display_service.h" -#include "common/key_code.h" -#include -#include "map" -#include "iostream" -#include "string" -#include "ConfigModel.h" -#include "ConfigModelC.h" -#include "custom_runtime.h" - -#include "NativeRegisterManager.h" -#ifdef SUPPORT_CYWEE_SERVICE -#include "cywee_service.h" -#endif -namespace OHOS -{ - REGIST_SLICE(VIEW_DISPLAY_BRIGHTNESS, DisplayBrightnessView, DisplayBrightnessPresenter); - // 当前Presenter属性实例化的内存指针 - static DisplayBrightnessPresenter *g_pDisplayBrightnessPresenter = nullptr; - - DisplayBrightnessPresenter::DisplayBrightnessPresenter() - { - - g_pDisplayBrightnessPresenter = this; - } - - DisplayBrightnessPresenter::~DisplayBrightnessPresenter() - { - - g_pDisplayBrightnessPresenter = nullptr; - } - - DisplayBrightnessPresenter *DisplayBrightnessPresenter::GetInstance() - { - - return g_pDisplayBrightnessPresenter; - } - - /// @brief 设置抬腕亮屏状态 - /// @param value - void DisplayBrightnessPresenter::SetRaiseToBrightnessState(bool value) - { - DisplayBrightnessView *displayBrightnessView = DisplayBrightnessView::GetInstance(); - if (displayBrightnessView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetRaiseToBrightnessState displayBrightnessView GetInstance fail"); - return; - } - displayBrightnessView->SetRaiseToBrightnessCheckBoxButtonState(value != false ? UICheckBox::UICheckBoxState::SELECTED : UICheckBox::UICheckBoxState::UNSELECTED); - } - - /// @brief 根据value值设置哪个按钮被选中 - /// @param value - void DisplayBrightnessPresenter::SetScreenDurationRadioButtonSelectStatus(uint32_t value) - { - ScreenDurationView *p_ScreenDurationView = ScreenDurationView::GetInstance(); - if (p_ScreenDurationView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView GetInstance fail"); - return; - } - - // 映射表将value映射到特定的单选按钮 - const std::map radioButtonMap = { - {SCREENDURATION_FIVE, ScreenDurationRadioButton1}, - {SCREENDURATION_TEN, ScreenDurationRadioButton2}, - {SCREENDURATION_FIFTEENTH, ScreenDurationRadioButton3}, - {SCREENDURATION_THIRTY, ScreenDurationRadioButton4}, - {SCREENDURATION_SIXTY, ScreenDurationRadioButton5}, - {SCREENDURATION_THREE_HUNDRED, ScreenDurationRadioButton6}, - }; - - auto iter = radioButtonMap.find(value); - if (iter != radioButtonMap.end()) - { - p_ScreenDurationView->SetRadioButtonSelectStatus(iter->second); - } - else - { - // 处理未知值 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unexpected duration value"); - } - } - - /* - * @brief 根据value值出设置选择的亮屏时长内容 - */ - void DisplayBrightnessPresenter::SetSelectScreenDurationLabel(uint32_t value) - { - DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); - if (p_DisplayBrightnessView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView GetInstance fail"); - return; - } - - if (p_DisplayBrightnessView->GetSelectScreenDurationLabel() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_DisplayBrightnessView->GetSelectScreenDurationLabel() is nullptr!"); - return; - } - - const std::map durationMap = { - {SCREENDURATION_FIVE, STR_5_SECONDS}, - {SCREENDURATION_TEN, STR_10_SECONDS}, - {SCREENDURATION_FIFTEENTH, STR_15_SECONDS}, - {SCREENDURATION_THIRTY, STR_30_SECONDS}, - {SCREENDURATION_SIXTY, STR_60_SECONDS}, - {SCREENDURATION_THREE_HUNDRED, STR_300_SECONDS}}; - - auto iter = durationMap.find(value); - if (iter != durationMap.end()) - { - p_DisplayBrightnessView->GetSelectScreenDurationLabel()->SetTextId(iter->second); - } - else - { - // Handle unexpected value - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unexpected duration value"); - } - - p_DisplayBrightnessView->GetSelectScreenDurationLabel()->Invalidate(); - return; - } - - void DisplayBrightnessPresenter::OnStart() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnStart"); - } - - void DisplayBrightnessPresenter::OnResume(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnResume"); - RootView::GetInstance()->SetOnKeyActListener(this); - } - - bool DisplayBrightnessPresenter::OnClick(UIView &view, const ClickEvent &event) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnClick"); - DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); - if (p_DisplayBrightnessView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetInstance fail!!"); - return false; - } - if (strcmp(view.GetViewId(), BRINGHTNESSCONTROLBUTTON_VIEW) == 0) - { - if(uapi_sleep_mode_flag_get()) - { - return false; - } - NativeAbility::GetInstance().EnterSlice(VIEW_BRIGHTNESSLEVEL); /*切换到亮度调节slice*/ - } - else if (strcmp(view.GetViewId(), SCREENDURATIONBUTTON_VIEWID) == 0) - { - p_DisplayBrightnessView->ChangeView(DISPLAYBRIGHTNESSVIEW, SCREENDURATIONVIEW); // 屏幕与亮度视图切换到亮屏时长视图 - } - return true; - } - - bool DisplayBrightnessPresenter::OnDrag(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnDrag"); - UNUSED(view); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - DisplayBrightnessPresenter::X_DRAG_FLAG = true; - } - return true; - } - - bool DisplayBrightnessPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnDragEnd"); - DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); - if (p_DisplayBrightnessView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView GetInstance fail"); - return false; - } - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && DisplayBrightnessPresenter::X_DRAG_FLAG) - { - if (strcmp(view.GetViewId(), SCREENDURATIONSCROLLVIEW) == 0) - { - p_DisplayBrightnessView->ChangeView(SCREENDURATIONVIEW, DISPLAYBRIGHTNESSVIEW); - } - else if (strcmp(view.GetViewId(), DISPLAY_BRIGHTNESS_VIEW) == 0) - { - NativeAbility::GetInstance().Back(); - } - DisplayBrightnessPresenter::X_DRAG_FLAG = false; - } - return true; - } - - /*处理抬腕亮屏开关*/ - bool DisplayBrightnessPresenter::OnChange(UICheckBox::UICheckBoxState state) - { - switch (state) - { - case UICheckBox::SELECTED: - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Raise to Wake switched on!"); -#ifdef SUPPORT_CYWEE_SERVICE - cywee_hand_wake_switch(WRIST_RAISE_TO_WAKE_ENABLED); // 关闭抬腕亮屏,和息屏 -#endif - mmi_flip_wrist_switch_set(true); - break; - case UICheckBox::UNSELECTED: - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Raise to Wake switched off!"); -#ifdef SUPPORT_CYWEE_SERVICE - cywee_hand_wake_switch(WRIST_RAISE_TO_WAKE_DISENABLED); // 关闭抬腕亮屏,和息屏 -#endif - mmi_flip_wrist_switch_set(false); - break; - default: - break; - } - return true; - } - - bool DisplayBrightnessPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnKeyAct"); - unsigned short keyID = event.GetKeyId(); - unsigned short keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; - } - - /* - * @brief 用于处理亮屏时长单选按钮的状态改变.根据用户选择的单选按钮,更新屏幕持续显示时间 - */ - bool ScreenDurationRadiobuttonOnChangeListener::OnChange(UICheckBox::UICheckBoxState state) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenDurationRadiobuttonOnChangeListener::OnChange"); - if (state != UICheckBox::SELECTED) - { - return true; // 如果不是选中状态,无需处理 - } - - DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); - if (p_DisplayBrightnessView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetInstance fail!"); - return false; - } - - ScreenDurationView *p_ScreenDurationView = p_DisplayBrightnessView->GetScreenDurationView(); - if (p_ScreenDurationView == nullptr) - { - return false; // 相关视图不存在,直接返回 - } - - // 关联单选按钮视图和对应的持续时间 - std::map durationMap = { - {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton1), SCREENDURATION_FIVE}, - {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton2), SCREENDURATION_TEN}, - {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton3), SCREENDURATION_FIFTEENTH}, - {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton4), SCREENDURATION_THIRTY}, - {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton5), SCREENDURATION_SIXTY}, - {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton6), SCREENDURATION_THREE_HUNDRED}}; - - auto it = durationMap.find((UIView *)m_view); - if (it != durationMap.end()) - { - uapi_setScreenDuration(it->second); - DisplayBrightnessModel::GetInstance()->SetScreenDurationTime(it->second); - // 此处可以根据需要,添加对 WEARABLE_LOGE 的调用,打印日志 - DisplayBrightnessPresenter::GetInstance()->SetSelectScreenDurationLabel(it->second); - } - else - { - // 如果没有找到对应的映射项,可能是逻辑错误或数据不一致 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "No matching screen duration found for selected radiobutton."); - } - - return true; - } - - bool ScreenDurationRadiobuttonOnChangeListener::OnClick(UIView &view, const ClickEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenDurationRadiobuttonOnChangeListener::OnClick"); - UIButton *button = dynamic_cast(&view); - if (button == nullptr) - { - return false; - } - - DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); - if (p_DisplayBrightnessView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetInstance fail!"); - return false; - } - - ScreenDurationView *p_ScreenDurationView = p_DisplayBrightnessView->GetScreenDurationView(); - if (p_ScreenDurationView == nullptr) - { - return false; // 相关视图不存在,直接返回 - } - // 关联单选按钮视图和对应的持续时间 - std::map durationMap = { - {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton1), ScreenDurationRadioButton1}, - {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton2), ScreenDurationRadioButton2}, - {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton3), ScreenDurationRadioButton3}, - {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton4), ScreenDurationRadioButton4}, - {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton5), ScreenDurationRadioButton5}, - {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton6), ScreenDurationRadioButton6}}; - - auto it = durationMap.find((UIButton *)button); - if (it != durationMap.end()) - { - p_ScreenDurationView->SetRadioButtonSelectStatus(it->second); - } - else - { - // 如果没有找到对应的映射项,可能是逻辑错误或数据不一致 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Logic error or data inconsistency."); - } - - return true; - } +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-07-14 15:27:15 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp + */ +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "graphic_math.h" +#include "string.h" +#include "displaybrightness/include/DisplayBrightnessPresenter.h" +#ifdef SUPPORT_CAT1_SERVICE +#include "cat1_ctl.h" +#endif +#include "displaybrightness/include/DisplayBrightnessModel.h" +#include "power_display_service.h" +#include "common/key_code.h" +#include +#include "map" +#include "iostream" +#include "string" +#include "ConfigModel.h" +#include "ConfigModelC.h" +#include "custom_runtime.h" + +#include "NativeRegisterManager.h" +#ifdef SUPPORT_CYWEE_SERVICE +#include "cywee_service.h" +#endif +namespace OHOS +{ + REGIST_SLICE(VIEW_DISPLAY_BRIGHTNESS, DisplayBrightnessView, DisplayBrightnessPresenter); + // 当前Presenter属性实例化的内存指针 + static DisplayBrightnessPresenter *g_pDisplayBrightnessPresenter = nullptr; + + DisplayBrightnessPresenter::DisplayBrightnessPresenter() + { + + g_pDisplayBrightnessPresenter = this; + } + + DisplayBrightnessPresenter::~DisplayBrightnessPresenter() + { + + g_pDisplayBrightnessPresenter = nullptr; + } + + DisplayBrightnessPresenter *DisplayBrightnessPresenter::GetInstance() + { + + return g_pDisplayBrightnessPresenter; + } + + /// @brief 设置抬腕亮屏状态 + /// @param value + void DisplayBrightnessPresenter::SetRaiseToBrightnessState(bool value) + { + DisplayBrightnessView *displayBrightnessView = DisplayBrightnessView::GetInstance(); + if (displayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetRaiseToBrightnessState displayBrightnessView GetInstance fail"); + return; + } + displayBrightnessView->SetRaiseToBrightnessCheckBoxButtonState(value != false ? UICheckBox::UICheckBoxState::SELECTED : UICheckBox::UICheckBoxState::UNSELECTED); + } + + /// @brief 根据value值设置哪个按钮被选中 + /// @param value + void DisplayBrightnessPresenter::SetScreenDurationRadioButtonSelectStatus(uint32_t value) + { + ScreenDurationView *p_ScreenDurationView = ScreenDurationView::GetInstance(); + if (p_ScreenDurationView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView GetInstance fail"); + return; + } + + // 映射表将value映射到特定的单选按钮 + const std::map radioButtonMap = { + {SCREENDURATION_FIVE, ScreenDurationRadioButton1}, + {SCREENDURATION_TEN, ScreenDurationRadioButton2}, + {SCREENDURATION_FIFTEENTH, ScreenDurationRadioButton3}, + {SCREENDURATION_THIRTY, ScreenDurationRadioButton4}, + {SCREENDURATION_SIXTY, ScreenDurationRadioButton5}, + {SCREENDURATION_THREE_HUNDRED, ScreenDurationRadioButton6}, + }; + + auto iter = radioButtonMap.find(value); + if (iter != radioButtonMap.end()) + { + p_ScreenDurationView->SetRadioButtonSelectStatus(iter->second); + } + else + { + // 处理未知值 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unexpected duration value"); + } + } + + /* + * @brief 根据value值出设置选择的亮屏时长内容 + */ + void DisplayBrightnessPresenter::SetSelectScreenDurationLabel(uint32_t value) + { + DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView GetInstance fail"); + return; + } + + if (p_DisplayBrightnessView->GetSelectScreenDurationLabel() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_DisplayBrightnessView->GetSelectScreenDurationLabel() is nullptr!"); + return; + } + + const std::map durationMap = { + {SCREENDURATION_FIVE, STR_5_SECONDS}, + {SCREENDURATION_TEN, STR_10_SECONDS}, + {SCREENDURATION_FIFTEENTH, STR_15_SECONDS}, + {SCREENDURATION_THIRTY, STR_30_SECONDS}, + {SCREENDURATION_SIXTY, STR_60_SECONDS}, + {SCREENDURATION_THREE_HUNDRED, STR_300_SECONDS}}; + + auto iter = durationMap.find(value); + if (iter != durationMap.end()) + { + p_DisplayBrightnessView->GetSelectScreenDurationLabel()->SetTextId(iter->second); + } + else + { + // Handle unexpected value + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unexpected duration value"); + } + + p_DisplayBrightnessView->GetSelectScreenDurationLabel()->Invalidate(); + return; + } + + void DisplayBrightnessPresenter::OnStart() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnStart"); + } + + void DisplayBrightnessPresenter::OnResume(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnResume"); + RootView::GetInstance()->SetOnKeyActListener(this); + } + + bool DisplayBrightnessPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnClick"); + DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetInstance fail!!"); + return false; + } + if (strcmp(view.GetViewId(), BRINGHTNESSCONTROLBUTTON_VIEW) == 0) + { + if(uapi_sleep_mode_flag_get()) + { + return false; + } + OHOS::AbilityNavigation::EnterSlice(VIEW_BRIGHTNESSLEVEL); /*切换到亮度调节slice*/ + } + else if (strcmp(view.GetViewId(), SCREENDURATIONBUTTON_VIEWID) == 0) + { + p_DisplayBrightnessView->ChangeView(DISPLAYBRIGHTNESSVIEW, SCREENDURATIONVIEW); // 屏幕与亮度视图切换到亮屏时长视图 + } + return true; + } + + bool DisplayBrightnessPresenter::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnDrag"); + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + DisplayBrightnessPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool DisplayBrightnessPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnDragEnd"); + DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView GetInstance fail"); + return false; + } + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && DisplayBrightnessPresenter::X_DRAG_FLAG) + { + if (strcmp(view.GetViewId(), SCREENDURATIONSCROLLVIEW) == 0) + { + p_DisplayBrightnessView->ChangeView(SCREENDURATIONVIEW, DISPLAYBRIGHTNESSVIEW); + } + else if (strcmp(view.GetViewId(), DISPLAY_BRIGHTNESS_VIEW) == 0) + { + OHOS::AbilityNavigation::Back(); + } + DisplayBrightnessPresenter::X_DRAG_FLAG = false; + } + return true; + } + + /*处理抬腕亮屏开关*/ + bool DisplayBrightnessPresenter::OnChange(UICheckBox::UICheckBoxState state) + { + switch (state) + { + case UICheckBox::SELECTED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Raise to Wake switched on!"); +#ifdef SUPPORT_CYWEE_SERVICE + cywee_hand_wake_switch(WRIST_RAISE_TO_WAKE_ENABLED); // 关闭抬腕亮屏,和息屏 +#endif + mmi_flip_wrist_switch_set(true); + break; + case UICheckBox::UNSELECTED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Raise to Wake switched off!"); +#ifdef SUPPORT_CYWEE_SERVICE + cywee_hand_wake_switch(WRIST_RAISE_TO_WAKE_DISENABLED); // 关闭抬腕亮屏,和息屏 +#endif + mmi_flip_wrist_switch_set(false); + break; + default: + break; + } + return true; + } + + bool DisplayBrightnessPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnKeyAct"); + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; + } + + /* + * @brief 用于处理亮屏时长单选按钮的状态改变.根据用户选择的单选按钮,更新屏幕持续显示时间 + */ + bool ScreenDurationRadiobuttonOnChangeListener::OnChange(UICheckBox::UICheckBoxState state) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenDurationRadiobuttonOnChangeListener::OnChange"); + if (state != UICheckBox::SELECTED) + { + return true; // 如果不是选中状态,无需处理 + } + + DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetInstance fail!"); + return false; + } + + ScreenDurationView *p_ScreenDurationView = p_DisplayBrightnessView->GetScreenDurationView(); + if (p_ScreenDurationView == nullptr) + { + return false; // 相关视图不存在,直接返回 + } + + // 关联单选按钮视图和对应的持续时间 + std::map durationMap = { + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton1), SCREENDURATION_FIVE}, + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton2), SCREENDURATION_TEN}, + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton3), SCREENDURATION_FIFTEENTH}, + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton4), SCREENDURATION_THIRTY}, + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton5), SCREENDURATION_SIXTY}, + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton6), SCREENDURATION_THREE_HUNDRED}}; + + auto it = durationMap.find((UIView *)m_view); + if (it != durationMap.end()) + { + uapi_setScreenDuration(it->second); + DisplayBrightnessModel::GetInstance()->SetScreenDurationTime(it->second); + // 此处可以根据需要,添加对 WEARABLE_LOGE 的调用,打印日志 + DisplayBrightnessPresenter::GetInstance()->SetSelectScreenDurationLabel(it->second); + } + else + { + // 如果没有找到对应的映射项,可能是逻辑错误或数据不一致 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "No matching screen duration found for selected radiobutton."); + } + + return true; + } + + bool ScreenDurationRadiobuttonOnChangeListener::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenDurationRadiobuttonOnChangeListener::OnClick"); + UIButton *button = dynamic_cast(&view); + if (button == nullptr) + { + return false; + } + + DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetInstance fail!"); + return false; + } + + ScreenDurationView *p_ScreenDurationView = p_DisplayBrightnessView->GetScreenDurationView(); + if (p_ScreenDurationView == nullptr) + { + return false; // 相关视图不存在,直接返回 + } + // 关联单选按钮视图和对应的持续时间 + std::map durationMap = { + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton1), ScreenDurationRadioButton1}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton2), ScreenDurationRadioButton2}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton3), ScreenDurationRadioButton3}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton4), ScreenDurationRadioButton4}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton5), ScreenDurationRadioButton5}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton6), ScreenDurationRadioButton6}}; + + auto it = durationMap.find((UIButton *)button); + if (it != durationMap.end()) + { + p_ScreenDurationView->SetRadioButtonSelectStatus(it->second); + } + else + { + // 如果没有找到对应的映射项,可能是逻辑错误或数据不一致 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Logic error or data inconsistency."); + } + + return true; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/dnotdisturb/src/DnotDisturbPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/dnotdisturb/src/DnotDisturbPresenter.cpp index 0512882f2..bb1311d02 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/dnotdisturb/src/DnotDisturbPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/dnotdisturb/src/DnotDisturbPresenter.cpp @@ -7,6 +7,7 @@ */ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "UiConfig.h" #include "dnotdisturb/include/DnotDisturbView.h" #include "dnotdisturb/include/DnotDisturbPresenter.h" @@ -71,7 +72,7 @@ namespace OHOS UNUSED(event); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && DnotDisturbPresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); DnotDisturbPresenter::X_DRAG_FLAG = false; } return true; @@ -93,9 +94,9 @@ namespace OHOS } else if (&view == p_DnotDisturbView->GetButtonOff()) { - // NativeAbility::GetInstance().Back(); + // OHOS::AbilityNavigation::Back(); } - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); return true; } @@ -108,7 +109,7 @@ namespace OHOS // 如果是power键就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadPresenter.cpp index 017719032..06e8842b9 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadPresenter.cpp @@ -9,6 +9,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "NativeRegisterManager.h" #include "wearable_log.h" @@ -121,7 +122,7 @@ bool EphemerisDownloadPresenter::OnClick(UIView &view, if (ble_connect_stat == 0) { //蓝牙未连接,跳转到查找手机Slice显示蓝牙未连接提示 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Bluetooth not connected, jump to find phone slice"); - NativeAbility::GetInstance().EnterSlice(VIEW_FIND_PHONE); + OHOS::AbilityNavigation::EnterSlice(VIEW_FIND_PHONE); return true; } @@ -143,7 +144,7 @@ bool EphemerisDownloadPresenter::OnClick(UIView &view, } //点击返回按键 else if (strcmp(view.GetViewId(), BACK_ID) == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -165,7 +166,7 @@ bool EphemerisDownloadPresenter::OnDrag(UIView &view, const DragEvent &event) { currentView_ = EphemerisDownloadView::EPHEMERIS_VIEW_MAIN; } } else if (dir == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } } return true; @@ -185,7 +186,7 @@ bool EphemerisDownloadPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { currentView_ = EphemerisDownloadView::EPHEMERIS_VIEW_MAIN; } } else { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } } return true; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/findphone/src/FindPhonePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/findphone/src/FindPhonePresenter.cpp index d6e544b4d..294851552 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/findphone/src/FindPhonePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/findphone/src/FindPhonePresenter.cpp @@ -10,6 +10,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "findphone/include/FindPhonePresenter.h" #include "findphone/include/FindPhoneModel.h" #include "findphone/include/FindPhoneView.h" @@ -92,7 +93,7 @@ namespace OHOS UNUSED(event); if (strcmp(view.GetViewId(), FINDPHONE_LABELBUTTON) == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -114,7 +115,7 @@ namespace OHOS UNUSED(event); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && FindPhonePresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); FindPhonePresenter::X_DRAG_FLAG = false; } return true; @@ -129,7 +130,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/flashlight/src/FlashlightPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/flashlight/src/FlashlightPresenter.cpp index 5761f3de2..f45c4b341 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/flashlight/src/FlashlightPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/flashlight/src/FlashlightPresenter.cpp @@ -8,6 +8,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "UiConfig.h" #include "flashlight/include/FlashlightPresenter.h" #include "flashlight/include/FlashlightModel.h" @@ -97,7 +98,7 @@ namespace OHOS return true; } - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); X_DRAG_FLAG = false; } return true; @@ -176,7 +177,7 @@ namespace OHOS // 如果是power键就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/goal/src/Maingoalpresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/goal/src/Maingoalpresenter.cpp index 509187730..10a25759b 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/goal/src/Maingoalpresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/goal/src/Maingoalpresenter.cpp @@ -1,5 +1,6 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "goal/include/Maingoalpresenter.h" #include "common/key_code.h" #include "common/key_code.h" @@ -68,7 +69,7 @@ namespace OHOS UNUSED(view); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MaingoalPresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); X_DRAG_FLAG = false; } return true; @@ -92,7 +93,7 @@ namespace OHOS // 如果是power键就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.cpp index 0101b4fc4..ea90c5fcd 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.cpp @@ -39,6 +39,7 @@ #include #include "UiConfig.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "gfx_utils/graphic_math.h" #include "custom_runtime.h" @@ -104,7 +105,7 @@ namespace OHOS if (strcmp(view.GetViewId(), CLICK_BLOOD_STOP) == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } if (strcmp(view.GetViewId(), CLICK_BLOOD_RE) == 0) { @@ -144,7 +145,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -166,7 +167,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CheckAbnormalPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); X_DRAG_FLAG = false; } return true; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.cpp index 4e1af3771..8167876b0 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.cpp @@ -39,6 +39,7 @@ #include #include "UiConfig.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "gfx_utils/graphic_math.h" #include "custom_runtime.h" @@ -99,7 +100,7 @@ namespace OHOS if (strcmp(view.GetViewId(), CLICK_HEALTH_KONW) == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -113,7 +114,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -135,7 +136,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CheckInvalidPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); X_DRAG_FLAG = false; } return true; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartChartPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartChartPresenter.cpp index a296af4a5..d38920181 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartChartPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartChartPresenter.cpp @@ -16,6 +16,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" @@ -59,7 +60,7 @@ namespace OHOS } void HeartChartPresenter::NavigateBack() { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } void HeartChartPresenter::OnStart() { diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartDetectionPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartDetectionPresenter.cpp index 11b1a0337..40f1c4a75 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartDetectionPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartDetectionPresenter.cpp @@ -10,6 +10,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" @@ -49,7 +50,7 @@ namespace OHOS } void HeartDetectionPresenter::NavigateBack() { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } void HeartDetectionPresenter::OnStart() { diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartResultPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartResultPresenter.cpp index cd360ca7f..88c0d0b87 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartResultPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartResultPresenter.cpp @@ -49,6 +49,7 @@ #include "health/health_service/health_service.h" #include "NativeRegisterManager.h" +#include "AbilityNavigationApi.h" #define BLOODKEYABLE 1 namespace OHOS @@ -123,7 +124,7 @@ namespace OHOS if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); return true; } return false; @@ -136,7 +137,7 @@ namespace OHOS if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -160,7 +161,7 @@ namespace OHOS } else { - NativeAbility::GetInstance().EnterSlice(VIEW_HEART_CHECK); + OHOS::AbilityNavigation::EnterSlice(VIEW_HEART_CHECK); } } WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartPresenter::OnClick"); diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/hrv/src/HrvPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/hrv/src/HrvPresenter.cpp index 3173f3906..9f4a4d806 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/hrv/src/HrvPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/hrv/src/HrvPresenter.cpp @@ -12,6 +12,7 @@ #include "hrv/include/HrvPresenter.h" #include "custom_utils.h" #include "NativeRegisterManager.h" +#include "AbilityNavigationApi.h" namespace OHOS { @@ -63,7 +64,7 @@ bool HrvPresenter::OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HrvPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } // if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) // { @@ -87,7 +88,7 @@ bool HrvPresenter::OnKeyAct(UIView &view, const KeyEvent &event) if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/languagecode/src/LanguageSwitchModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/languagecode/src/LanguageSwitchModel.cpp index a0ce602fc..aa5c9db58 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/languagecode/src/LanguageSwitchModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/languagecode/src/LanguageSwitchModel.cpp @@ -10,6 +10,7 @@ #include "languagecode/LanguageInit.h" #include "ConfigModel.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "languagecode/include/LanguageSwitchView.h" #include "AppViewIDs.h" namespace OHOS @@ -50,7 +51,7 @@ namespace OHOS set_hint_code(id); set_hint_flag(true); #ifdef CUSTOM_ZHIHUI - NativeAbility::GetInstance().EnterSlice(VIEW_LANGUAGE_SWITCH); + OHOS::AbilityNavigation::EnterSlice(VIEW_LANGUAGE_SWITCH); #endif } } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/languagecode/src/LanguageSwitchPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/languagecode/src/LanguageSwitchPresenter.cpp index 1213671cd..437b3b183 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/languagecode/src/LanguageSwitchPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/languagecode/src/LanguageSwitchPresenter.cpp @@ -7,6 +7,7 @@ */ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "languagecode/include/LanguageSwitchPresenter.h" #include "languagecode/include/LanguageSwitchListitemView.h" #include "languagecode/include/LanguageSwitchModel.h" @@ -83,7 +84,7 @@ namespace OHOS UNUSED(view); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && LanguageSwitchPresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); LanguageSwitchPresenter::X_DRAG_FLAG = false; } return true; @@ -145,7 +146,7 @@ namespace OHOS if (ConfigModel::GetInstance()->GetisFirstTimeStart() == true) { #ifdef CUSTOM_ZHIHUI - NativeAbility::GetInstance().EnterSlice(VIEW_WATCH_QR_CODE); + OHOS::AbilityNavigation::EnterSlice(VIEW_WATCH_QR_CODE); #endif } } @@ -198,7 +199,7 @@ namespace OHOS if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { #ifdef CUSTOM_ZHIHUI - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); #endif #ifdef SUPPORT_BLE_SERVICE br_adv_start(20); diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/MainPresenterSample.cpp index 892b63a00..d1d2cdde1 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/MainPresenterSample.cpp @@ -60,7 +60,9 @@ #include "battery_hal.h" #endif } - + +#include "AbilityNavigationApi.h" + namespace OHOS { REGIST_SLICE(VIEW_MAIN, MainViewSample, MainPresenterSample); @@ -233,7 +235,7 @@ } if (g_jumpView.count(curViewId) != 0) { - NativeAbility::GetInstance().EnterSlice(g_jumpView[curViewId]); + OHOS::AbilityNavigation::EnterSlice(g_jumpView[curViewId]); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dropdown/DropDownCardPage1.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dropdown/DropDownCardPage1.cpp index 7c62e9277..c7458ecf4 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dropdown/DropDownCardPage1.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dropdown/DropDownCardPage1.cpp @@ -11,6 +11,7 @@ #include "string" #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "main/include/MainModel.h" #include #include @@ -61,11 +62,11 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DropDownCardPage1::OnClick %s ", view.GetViewId()); if (viewId == DROPDOWN_BT_TOGGLEBUTTON_VIEWID) // 蓝牙开关 { - NativeAbility::GetInstance().EnterSlice(VIEW_CLASSIC_BLUETOOTH); + OHOS::AbilityNavigation::EnterSlice(VIEW_CLASSIC_BLUETOOTH); } else if (viewId == DROPDOWN_FINDPHONE_TOGGLEBUTTON_VIEWID) { - // NativeAbility::GetInstance().EnterSlice(VIEW_FIND_PHONE); + // OHOS::AbilityNavigation::EnterSlice(VIEW_FIND_PHONE); } else if (viewId == DROPDOWN_APPLIST_DISPLAY_TOGGLEBUTTON_VIEWID) { @@ -74,7 +75,7 @@ namespace OHOS else if (viewId == DROPDOWN_SAVEPOWER_TOGGLEBUTTON_VIEWID) // 省电模式开关 { - NativeAbility::GetInstance().EnterSlice(VIEW_SAVEELE); + OHOS::AbilityNavigation::EnterSlice(VIEW_SAVEELE); } else if (viewId == DROPDOWN_SLEEP_TOGGLEBUTTON_VIEWID) // 睡眠开关 { @@ -85,7 +86,7 @@ namespace OHOS } else { - NativeAbility::GetInstance().EnterSlice(VIEW_SLEEPMODE); + OHOS::AbilityNavigation::EnterSlice(VIEW_SLEEPMODE); } } else if (viewId == DROPDOWN_DNOTDISTURB_TOGGLEBUTTON_VIEWID) // 勿扰开关 @@ -93,7 +94,7 @@ namespace OHOS if (DnotDisturbModel::GetInstance().GetDoNotDisturbModeEnabled() == false) { - NativeAbility::GetInstance().EnterSlice(VIEW_DNOTDISTURB); + OHOS::AbilityNavigation::EnterSlice(VIEW_DNOTDISTURB); } else { @@ -104,7 +105,7 @@ namespace OHOS } else if (viewId == DROPDOWN_SETTING_TOGGLEBUTTON_VIEWID) // 设置 { - NativeAbility::GetInstance().EnterSlice(VIEW_SETTING); + OHOS::AbilityNavigation::EnterSlice(VIEW_SETTING); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dropdown/DropDownCardPage2.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dropdown/DropDownCardPage2.cpp index 350bccd94..102d867fa 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dropdown/DropDownCardPage2.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dropdown/DropDownCardPage2.cpp @@ -11,6 +11,7 @@ #include "string" #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "themestyle/include/ThemeStyleModel.h" #include "main/include/dropdown/DropDownCardPageUiConfig.h" namespace OHOS @@ -72,11 +73,11 @@ namespace OHOS std::string viewId = view.GetViewId(); if (viewId == DROPDOWN_FINDPHONE_TOGGLEBUTTON_VIEWID) { - NativeAbility::GetInstance().EnterSlice(VIEW_FIND_PHONE); + OHOS::AbilityNavigation::EnterSlice(VIEW_FIND_PHONE); } else if (viewId == DROPDOWN_LIGHTING_TOGGLEBUTTON_VIEWID) { - NativeAbility::GetInstance().EnterSlice(VIEW_FLASHLIGHT); + OHOS::AbilityNavigation::EnterSlice(VIEW_FLASHLIGHT); } else if (viewId == DROPDOWN_APPLIST_DISPLAY_TOGGLEBUTTON_VIEWID) { diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/makephone/src/MainCallingPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/makephone/src/MainCallingPresenter.cpp index 5709289df..a98892c31 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/makephone/src/MainCallingPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/makephone/src/MainCallingPresenter.cpp @@ -33,6 +33,7 @@ #endif #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "dial_sos_c.h" @@ -357,7 +358,7 @@ bool MainCallingPresenter::OnClick(UIView& view, const ClickEvent& event) } else if (strcmp(view.GetViewId(), "callingheadset") == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_BLUETOOTH_EARPHONE); + OHOS::AbilityNavigation::EnterSlice(VIEW_BLUETOOTH_EARPHONE); } // #endif diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessageControlPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessageControlPresenter.cpp index 2179f2c8b..def98daa6 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessageControlPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessageControlPresenter.cpp @@ -19,6 +19,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "UiConfig.h" @@ -45,7 +46,7 @@ namespace OHOS { // 执行全部删除操作 messageModel.ClearAllMessages(); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); return true; } @@ -65,7 +66,7 @@ namespace OHOS { messageModel.SetCurrentIndex(index); messageModel.SetMessageAsRead(); - NativeAbility::GetInstance().EnterSlice(VIEW_MESSAGE_SHOW); // 切换到详情界面 + OHOS::AbilityNavigation::EnterSlice(VIEW_MESSAGE_SHOW); // 切换到详情界面 return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessagePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessagePresenter.cpp index 9d84be286..b1750e2ca 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessagePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessagePresenter.cpp @@ -11,6 +11,7 @@ #include "gfx_utils/graphic_log.h" #include "wearable_log.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" @@ -82,7 +83,7 @@ namespace OHOS if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } if(event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) { @@ -106,7 +107,7 @@ namespace OHOS { // 执行全部删除操作 model->ClearAllMessages(); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); return true; } @@ -126,7 +127,7 @@ namespace OHOS { model->SetCurrentIndex(index); model->SetMessageAsRead(); - NativeAbility::GetInstance().EnterSlice(VIEW_MESSAGE_SHOW); // 切换到详情界面 + OHOS::AbilityNavigation::EnterSlice(VIEW_MESSAGE_SHOW); // 切换到详情界面 return true; } WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error: Index %d is out of bounds.", index); @@ -142,7 +143,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessageShowPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessageShowPresenter.cpp index 3fa01dd29..e8a1e2533 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessageShowPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/message/src/MessageShowPresenter.cpp @@ -9,6 +9,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "message/include/MessageShowPresenter.h" #include "components/ui_abstract_scroll_bar.h" #include "gfx_utils/graphic_log.h" @@ -56,7 +57,7 @@ namespace OHOS (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { // NativeAbility::GetInstance().ChangeSlice(VIEW_MESSAGE); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -70,7 +71,7 @@ namespace OHOS MessageModel::GetInstance().DeleteCurrentMessage(); // NativeAbility::GetInstance().ChangeSlice(VIEW_MESSAGE); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -83,7 +84,7 @@ namespace OHOS if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/motionrecognition/src/MotionRecognitionPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/motionrecognition/src/MotionRecognitionPresenter.cpp index 233bdc9de..a92dc1e74 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/motionrecognition/src/MotionRecognitionPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/motionrecognition/src/MotionRecognitionPresenter.cpp @@ -7,6 +7,7 @@ */ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "motionrecognition/include/MotionRecognitionPresenter.h" #include "motionrecognition/include/MotionRecognitionView.h" #include "common/key_code.h" @@ -143,7 +144,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); X_DRAG_FLAG = false; } return true; @@ -158,7 +159,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/musicplayer/src/MusicPlayerPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/musicplayer/src/MusicPlayerPresenter.cpp index caed17c59..84f1b8a03 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/musicplayer/src/MusicPlayerPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/musicplayer/src/MusicPlayerPresenter.cpp @@ -8,6 +8,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include #include "UiConfig.h" @@ -97,7 +98,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MusicPlayerPresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); MusicPlayerPresenter::X_DRAG_FLAG = false; } return true; @@ -112,7 +113,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/networkandcall/src/NetworkAndCallPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/networkandcall/src/NetworkAndCallPresenter.cpp index 216c31f4e..e9b84bf17 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/networkandcall/src/NetworkAndCallPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/networkandcall/src/NetworkAndCallPresenter.cpp @@ -7,6 +7,7 @@ */ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "networkandcall/include/NetworkAndCallPresenter.h" #include "common/key_code.h" #include @@ -173,7 +174,7 @@ namespace OHOS } else { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } } return true; @@ -187,7 +188,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/CallLogAdapter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/CallLogAdapter.cpp index 4e15188fb..74aa676a2 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/CallLogAdapter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/CallLogAdapter.cpp @@ -19,6 +19,7 @@ #include "phone/include/phoneaddressmodel.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "AppViewIDs.h" namespace OHOS { @@ -168,7 +169,7 @@ namespace OHOS CallLogInfo itemData = *it; set_address_number((char *)itemData.tel); - NativeAbility::GetInstance().EnterSlice(VIEW_DIALING_METHOD); + OHOS::AbilityNavigation::EnterSlice(VIEW_DIALING_METHOD); return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/DialingMethodPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/DialingMethodPresenter.cpp index 261b5ac9e..a7b15bd0c 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/DialingMethodPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/DialingMethodPresenter.cpp @@ -7,6 +7,7 @@ */ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "phone/include/DialingMethodView.h" #include "phone/include/DialingMethodPresenter.h" #include "common/key_code.h" @@ -85,7 +86,7 @@ namespace OHOS }else { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_cat1_get_power_stat"); - NativeAbility::GetInstance().EnterSlice(VIEW_PHONECALL); + OHOS::AbilityNavigation::EnterSlice(VIEW_PHONECALL); } } @@ -114,7 +115,7 @@ namespace OHOS DialingMethodView::GetInstance()->fail_Dial_show(1); } else - NativeAbility::GetInstance().EnterSlice(VIEW_PHONECALL); + OHOS::AbilityNavigation::EnterSlice(VIEW_PHONECALL); } } @@ -173,7 +174,7 @@ namespace OHOS } else { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); TelephonyInitInterface::X_DRAG_FLAG = false; //set_address_number(NULL); } @@ -192,7 +193,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); //set_address_number(NULL); } return true; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/MainPhonePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/MainPhonePresenter.cpp index 62784557d..056ccb6cf 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/MainPhonePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/MainPhonePresenter.cpp @@ -7,6 +7,7 @@ */ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "phone/include/MainPhonePresenter.h" #include "phone/include/MainPhoneView.h" #include "common/key_code.h" @@ -78,12 +79,12 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s OnClick", curViewId.c_str()); set_address_number(NULL); - NativeAbility::GetInstance().EnterSlice(VIEW_DIALING_METHOD); + OHOS::AbilityNavigation::EnterSlice(VIEW_DIALING_METHOD); } else if (curViewId == FREQUENTLYCONTACTEDBUTTON_VIEWID) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s OnClick", curViewId.c_str()); - // NativeAbility::GetInstance().EnterSlice(VIEW_PHONEDIR); + // OHOS::AbilityNavigation::EnterSlice(VIEW_PHONEDIR); } else if (curViewId==DELETE_ALL_VIEWID) { @@ -101,7 +102,7 @@ namespace OHOS else { set_address_number((char *)view.GetViewId()); - NativeAbility::GetInstance().EnterSlice(VIEW_DIALING_METHOD); + OHOS::AbilityNavigation::EnterSlice(VIEW_DIALING_METHOD); } return true; } @@ -142,8 +143,8 @@ namespace OHOS else { //if(event.GetPreLastPoint().x-event.GetStartPoint().x>200) - NativeAbility::GetInstance().Back(); - //NativeAbility::GetInstance().EnterSlice(VIEW_APPLIST); + OHOS::AbilityNavigation::Back(); + //OHOS::AbilityNavigation::EnterSlice(VIEW_APPLIST); TelephonyInitInterface::X_DRAG_FLAG = false; } @@ -172,7 +173,7 @@ namespace OHOS if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/PhoneCallPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/PhoneCallPresenter.cpp index 7d90ee335..24aced96c 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/PhoneCallPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/PhoneCallPresenter.cpp @@ -1,235 +1,236 @@ -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include"ui_resource_string.h" -#include "NativeAbility.h" -#include "string" -#include "phone/include/PhoneCallPresenter.h" -#include -#ifdef SUPPORT_CAT1_SERVICE -#include "cat1_UI_hal.h" -#include "cat1_porting.h" -#endif -#include "phoneservice/include/PhoneService.h" -#include "phone/include/PhoneCallView.h" -#include "phone/include/TelephonyInitInterface.h" -#include "common/key_code.h" -#include - -#include "NativeRegisterManager.h" - -namespace OHOS -{ - REGIST_SLICE(VIEW_PHONECALL, PhoneCallView, PhoneCallPresenter); - - // 当前Presenter属性实例化的内存指针 - static PhoneCallPresenter *g_pPhoneCallPresenter = nullptr; - - PhoneCallPresenter::PhoneCallPresenter() - { - g_pPhoneCallPresenter = this; - } - - PhoneCallPresenter::~PhoneCallPresenter() - { - - g_pPhoneCallPresenter = nullptr; - } - - PhoneCallPresenter *PhoneCallPresenter::GetInstance() - { - - return g_pPhoneCallPresenter; - } - - void PhoneCallPresenter::OnStart() - { - } - - void PhoneCallPresenter::OnResume(void) - { - RootView::GetInstance()->SetOnKeyActListener(this); - } - - bool PhoneCallPresenter::OnDrag(UIView &view, const DragEvent &event) - { - - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) - { - //NativeAbility::GetInstance().Back(); - //NativeAbility::GetInstance().Back(); - NativeAbility::GetInstance().BackCountSlice(1);// EnterSlice(VIEW_MAIN_PHONE); - } - - - - - // if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && - // (event.GetStartPoint().y > 300)) - // { - // NativeAbility::GetInstance().ChangeSlice(VIEW_PHONECALLING); - // } - UNUSED(view); - return true; - } - - bool PhoneCallPresenter::OnLongPress(UIView& view, const LongPressEvent& event) - { - const char *viewId = view.GetViewId(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnLongPress"); - if (strcmp(viewId, BUTTON7) == 0) - { - // 点击7键,将字符'7'追加到号码字符串中 - phoneNumber += "*"; - } - if (strcmp(viewId, BUTTON9) == 0) - { - // 点击7键,将字符'7'追加到号码字符串中 - phoneNumber += "#"; - } - if (strcmp(viewId, BUTTON0) == 0) - { - // 点击7键,将字符'7'追加到号码字符串中 - phoneNumber += "+"; - } - printf("**************************\n"); - printf("per phoneNumber: %s\n", phoneNumber.c_str()); - - PhoneCallView::GetInstance()->ReLabel(); - - // view.Invalidate(); - // RootView::GetInstance()->Invalidate(); - - printf("now phoneNumber: %s\n", phoneNumber.c_str()); - printf("**************************\n"); - - - return true; - } - - bool PhoneCallPresenter::OnClick(UIView &view, const ClickEvent &event) - { - - - // 获取控件id - const char *viewId = view.GetViewId(); - - // 根据控件id处理点击事件 - if (strcmp(viewId, BUTTONCALL) == 0) - { - - if(phoneNumber.length()<=2) - { - return false; - } - - if(TelephonyInitInterface::DIALINGMETHOD == DIALINGMETHOD_USINGWATCHSIM) - { - #ifdef SUPPORT_CAT1_SERVICE - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DIALINGMETHOD_USINGWATCHSIM"); - cat1_UI_call_dial((char *)phoneNumber.c_str()); - #endif - - } - else if(TelephonyInitInterface::DIALINGMETHOD == DIALINGMETHOD_USINGPHONE) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DIALINGMETHOD_USINGPHONE"); - DialCall((unsigned char *)phoneNumber.c_str(),phoneNumber.length()); - } - - } - else if (strcmp(viewId, BUTTONDEL) == 0) - { - // 点击删除键,从号码字符串中删除最后一个字符 - if (!phoneNumber.empty()) - { - phoneNumber.pop_back(); - } - } - else - { - if (strcmp(viewId, BUTTON0) == 0) - { - // 点击0键,将字符'0'追加到号码字符串中 - phoneNumber += "0"; - printf("----0-----\n"); - } - else if (strcmp(viewId, BUTTON1) == 0) - { - // 点击1键,将字符'1'追加到号码字符串中 - phoneNumber += "1"; - printf("----1-----\n"); - } - else if (strcmp(viewId, BUTTON2) == 0) - { - // 点击2键,将字符'2'追加到号码字符串中 - phoneNumber += "2"; - printf("----2-----\n"); - } - else if (strcmp(viewId, BUTTON3) == 0) - { - // 点击3键,将字符'3'追加到号码字符串中 - phoneNumber += "3"; - } - else if (strcmp(viewId, BUTTON4) == 0) - { - // 点击4键,将字符'4'追加到号码字符串中 - phoneNumber += "4"; - } - else if (strcmp(viewId, BUTTON5) == 0) - { - // 点击5键,将字符'5'追加到号码字符串中 - phoneNumber += "5"; - } - else if (strcmp(viewId, BUTTON6) == 0) - { - // 点击6键,将字符'6'追加到号码字符串中 - phoneNumber += "6"; - } - else if (strcmp(viewId, BUTTON7) == 0) - { - // 点击7键,将字符'7'追加到号码字符串中 - phoneNumber += "7"; - } - else if (strcmp(viewId, BUTTON8) == 0) - { - // 点击8键,将字符'8'追加到号码字符串中 - phoneNumber += "8"; - } - else if (strcmp(viewId, BUTTON9) == 0) - { - // 点击9键,将字符'9'追加到号码字符串中 - phoneNumber += "9"; - } - - } - printf("**************************\n"); - printf("per phoneNumber: %s\n", phoneNumber.c_str()); - - PhoneCallView::GetInstance()->ReLabel(); - - // view.Invalidate(); - // RootView::GetInstance()->Invalidate(); - - printf("now phoneNumber: %s\n", phoneNumber.c_str()); - printf("**************************\n"); - - - return true; - } - - - bool PhoneCallPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DialingMethodPresenter::OnKeyAct"); - unsigned short keyID = event.GetKeyId(); - unsigned short keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().BackCountSlice(1); - } - return true; - } +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include"ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "string" +#include "phone/include/PhoneCallPresenter.h" +#include +#ifdef SUPPORT_CAT1_SERVICE +#include "cat1_UI_hal.h" +#include "cat1_porting.h" +#endif +#include "phoneservice/include/PhoneService.h" +#include "phone/include/PhoneCallView.h" +#include "phone/include/TelephonyInitInterface.h" +#include "common/key_code.h" +#include + +#include "NativeRegisterManager.h" + +namespace OHOS +{ + REGIST_SLICE(VIEW_PHONECALL, PhoneCallView, PhoneCallPresenter); + + // 当前Presenter属性实例化的内存指针 + static PhoneCallPresenter *g_pPhoneCallPresenter = nullptr; + + PhoneCallPresenter::PhoneCallPresenter() + { + g_pPhoneCallPresenter = this; + } + + PhoneCallPresenter::~PhoneCallPresenter() + { + + g_pPhoneCallPresenter = nullptr; + } + + PhoneCallPresenter *PhoneCallPresenter::GetInstance() + { + + return g_pPhoneCallPresenter; + } + + void PhoneCallPresenter::OnStart() + { + } + + void PhoneCallPresenter::OnResume(void) + { + RootView::GetInstance()->SetOnKeyActListener(this); + } + + bool PhoneCallPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + { + //OHOS::AbilityNavigation::Back(); + //OHOS::AbilityNavigation::Back(); + OHOS::AbilityNavigation::BackCountSlice(1);// EnterSlice(VIEW_MAIN_PHONE); + } + + + + + // if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && + // (event.GetStartPoint().y > 300)) + // { + // NativeAbility::GetInstance().ChangeSlice(VIEW_PHONECALLING); + // } + UNUSED(view); + return true; + } + + bool PhoneCallPresenter::OnLongPress(UIView& view, const LongPressEvent& event) + { + const char *viewId = view.GetViewId(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnLongPress"); + if (strcmp(viewId, BUTTON7) == 0) + { + // 点击7键,将字符'7'追加到号码字符串中 + phoneNumber += "*"; + } + if (strcmp(viewId, BUTTON9) == 0) + { + // 点击7键,将字符'7'追加到号码字符串中 + phoneNumber += "#"; + } + if (strcmp(viewId, BUTTON0) == 0) + { + // 点击7键,将字符'7'追加到号码字符串中 + phoneNumber += "+"; + } + printf("**************************\n"); + printf("per phoneNumber: %s\n", phoneNumber.c_str()); + + PhoneCallView::GetInstance()->ReLabel(); + + // view.Invalidate(); + // RootView::GetInstance()->Invalidate(); + + printf("now phoneNumber: %s\n", phoneNumber.c_str()); + printf("**************************\n"); + + + return true; + } + + bool PhoneCallPresenter::OnClick(UIView &view, const ClickEvent &event) + { + + + // 获取控件id + const char *viewId = view.GetViewId(); + + // 根据控件id处理点击事件 + if (strcmp(viewId, BUTTONCALL) == 0) + { + + if(phoneNumber.length()<=2) + { + return false; + } + + if(TelephonyInitInterface::DIALINGMETHOD == DIALINGMETHOD_USINGWATCHSIM) + { + #ifdef SUPPORT_CAT1_SERVICE + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DIALINGMETHOD_USINGWATCHSIM"); + cat1_UI_call_dial((char *)phoneNumber.c_str()); + #endif + + } + else if(TelephonyInitInterface::DIALINGMETHOD == DIALINGMETHOD_USINGPHONE) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DIALINGMETHOD_USINGPHONE"); + DialCall((unsigned char *)phoneNumber.c_str(),phoneNumber.length()); + } + + } + else if (strcmp(viewId, BUTTONDEL) == 0) + { + // 点击删除键,从号码字符串中删除最后一个字符 + if (!phoneNumber.empty()) + { + phoneNumber.pop_back(); + } + } + else + { + if (strcmp(viewId, BUTTON0) == 0) + { + // 点击0键,将字符'0'追加到号码字符串中 + phoneNumber += "0"; + printf("----0-----\n"); + } + else if (strcmp(viewId, BUTTON1) == 0) + { + // 点击1键,将字符'1'追加到号码字符串中 + phoneNumber += "1"; + printf("----1-----\n"); + } + else if (strcmp(viewId, BUTTON2) == 0) + { + // 点击2键,将字符'2'追加到号码字符串中 + phoneNumber += "2"; + printf("----2-----\n"); + } + else if (strcmp(viewId, BUTTON3) == 0) + { + // 点击3键,将字符'3'追加到号码字符串中 + phoneNumber += "3"; + } + else if (strcmp(viewId, BUTTON4) == 0) + { + // 点击4键,将字符'4'追加到号码字符串中 + phoneNumber += "4"; + } + else if (strcmp(viewId, BUTTON5) == 0) + { + // 点击5键,将字符'5'追加到号码字符串中 + phoneNumber += "5"; + } + else if (strcmp(viewId, BUTTON6) == 0) + { + // 点击6键,将字符'6'追加到号码字符串中 + phoneNumber += "6"; + } + else if (strcmp(viewId, BUTTON7) == 0) + { + // 点击7键,将字符'7'追加到号码字符串中 + phoneNumber += "7"; + } + else if (strcmp(viewId, BUTTON8) == 0) + { + // 点击8键,将字符'8'追加到号码字符串中 + phoneNumber += "8"; + } + else if (strcmp(viewId, BUTTON9) == 0) + { + // 点击9键,将字符'9'追加到号码字符串中 + phoneNumber += "9"; + } + + } + printf("**************************\n"); + printf("per phoneNumber: %s\n", phoneNumber.c_str()); + + PhoneCallView::GetInstance()->ReLabel(); + + // view.Invalidate(); + // RootView::GetInstance()->Invalidate(); + + printf("now phoneNumber: %s\n", phoneNumber.c_str()); + printf("**************************\n"); + + + return true; + } + + + bool PhoneCallPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DialingMethodPresenter::OnKeyAct"); + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::BackCountSlice(1); + } + return true; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/PhoneDirPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/PhoneDirPresenter.cpp index ec297e0d7..05695cb21 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/PhoneDirPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/phone/src/PhoneDirPresenter.cpp @@ -1,106 +1,107 @@ -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include"ui_resource_string.h" -#include "NativeAbility.h" -#include "phone/include/phoneaddressmodel.h" -#include "phone/include/PhoneDirPresenter.h" -#include "phone/include/PhoneDirView.h" -#include "components/ui_button.h" -#include "components/ui_label_button_ext.h" -#include "common/key_code.h" -#include -#include "NativeRegisterManager.h" - -namespace OHOS -{ - REGIST_SLICE(VIEW_PHONEDIR, PhoneDirView, PhoneDirPresenter); - - // 当前Presenter属性实例化的内存指针 - static PhoneDirPresenter *g_pPhoneDirPresenter = nullptr; - static bool Set_onepage_address=false; - - PhoneDirPresenter::PhoneDirPresenter() - { - - g_pPhoneDirPresenter = this; - } - - PhoneDirPresenter::~PhoneDirPresenter() - { - - g_pPhoneDirPresenter = nullptr; - } - - PhoneDirPresenter *PhoneDirPresenter::GetInstance() - { - - return g_pPhoneDirPresenter; - } - - void PhoneDirPresenter::OnStart() - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneDirPresenter::"); - Set_onepage_address=false; - } - - bool PhoneDirPresenter::OnDrag(UIView &view, const DragEvent &event) - { - - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) - { - if(strcmp( view.GetViewId(),"container_one_page")==0) - { - PhoneDirView::GetInstance()->Set_onepage_address(view.GetViewId()); - } - else - { - NativeAbility::GetInstance().Back(); - } - - - } - UNUSED(view); - return true; - } - - - bool PhoneDirPresenter::OnClick(UIView &view, const ClickEvent &event) - { - //if(strview.GetViewId()) - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneDirPresenter----------%s ---",view.GetViewId()); - - if(PhoneDirView::GetInstance()->get_container_one_page_is_Visible()==false) - { - PhoneDirView::GetInstance()->Set_onepage_address(view.GetViewId()); - Set_onepage_address=true; - } - else - { - set_address_number( (char *)view.GetViewId()); - NativeAbility::GetInstance().EnterSlice(VIEW_DIALING_METHOD); - } - - - - - // 根据控件id查找是哪个控件触发了点击回调 - // if (strcmp(view.GetViewId(), 控件ID) == 0) - return true; - } - - - bool PhoneDirPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DialingMethodPresenter::OnKeyAct"); - unsigned short keyID = event.GetKeyId(); - unsigned short keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; - } +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include"ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "phone/include/phoneaddressmodel.h" +#include "phone/include/PhoneDirPresenter.h" +#include "phone/include/PhoneDirView.h" +#include "components/ui_button.h" +#include "components/ui_label_button_ext.h" +#include "common/key_code.h" +#include +#include "NativeRegisterManager.h" + +namespace OHOS +{ + REGIST_SLICE(VIEW_PHONEDIR, PhoneDirView, PhoneDirPresenter); + + // 当前Presenter属性实例化的内存指针 + static PhoneDirPresenter *g_pPhoneDirPresenter = nullptr; + static bool Set_onepage_address=false; + + PhoneDirPresenter::PhoneDirPresenter() + { + + g_pPhoneDirPresenter = this; + } + + PhoneDirPresenter::~PhoneDirPresenter() + { + + g_pPhoneDirPresenter = nullptr; + } + + PhoneDirPresenter *PhoneDirPresenter::GetInstance() + { + + return g_pPhoneDirPresenter; + } + + void PhoneDirPresenter::OnStart() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneDirPresenter::"); + Set_onepage_address=false; + } + + bool PhoneDirPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + { + if(strcmp( view.GetViewId(),"container_one_page")==0) + { + PhoneDirView::GetInstance()->Set_onepage_address(view.GetViewId()); + } + else + { + OHOS::AbilityNavigation::Back(); + } + + + } + UNUSED(view); + return true; + } + + + bool PhoneDirPresenter::OnClick(UIView &view, const ClickEvent &event) + { + //if(strview.GetViewId()) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneDirPresenter----------%s ---",view.GetViewId()); + + if(PhoneDirView::GetInstance()->get_container_one_page_is_Visible()==false) + { + PhoneDirView::GetInstance()->Set_onepage_address(view.GetViewId()); + Set_onepage_address=true; + } + else + { + set_address_number( (char *)view.GetViewId()); + OHOS::AbilityNavigation::EnterSlice(VIEW_DIALING_METHOD); + } + + + + + // 根据控件id查找是哪个控件触发了点击回调 + // if (strcmp(view.GetViewId(), 控件ID) == 0) + return true; + } + + + bool PhoneDirPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DialingMethodPresenter::OnKeyAct"); + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/player/src/MusicPlayerSourceView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/player/src/MusicPlayerSourceView.cpp index e4d902a4d..2786d6d4f 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/player/src/MusicPlayerSourceView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/player/src/MusicPlayerSourceView.cpp @@ -1,544 +1,545 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: bluetooth view 设置页面 - * Create: 2021-09-5 - */ -#include "player/include/MusicPlayerSourceView.h" -#include "player/include/PlayersView.h" -#include "player/include/PlayersModel.h" -#include "UiConfig.h" -#include "bluetooth/include/BluetoothEarPhoneView.h" -#include "player/include/PlayersPresenter.h" -#include "ui_resource_image.h" -#include "ui_resource_string.h" -#include "settings/include/SettingModel.h" -#include "ui_resource_string.h" -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "main/include/MainModel.h" -namespace OHOS -{ - static MusicPlayerSourceView *g_bluetoothView{nullptr}; - MusicPlayerSourceView::MusicPlayerSourceView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::MusicPlayerSourceView"); - g_bluetoothView = this; - } - - MusicPlayerSourceView::~MusicPlayerSourceView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::~MusicPlayerSourceView"); - ClearAll(); - g_bluetoothView = nullptr; - } - - MusicPlayerSourceView *MusicPlayerSourceView::GetInstance(void) - { - return g_bluetoothView; - } - - bool MusicPlayerSourceView::OnClick(UIView &view, const ClickEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::OnClick"); - UILabelButton *button = dynamic_cast(&view); - if (!button) - { - return false; - } - PlayersPresenter *playersPresenter = PlayersPresenter::GetInstance(); - if (!playersPresenter) - { - return false; - } - PlayersView *playersView = PlayersView::GetInstance(); - if (!playersView) - { - return false; - } - ImageInfo *image; - bool phonebluetoothcon = SettingModel::GetInstance().GetPhoneConnectStatus(); // 获取手机连接状态 - #ifdef SUPPORT_BLE_SERVICE - bool a2dp = uapi_a2dp_snk_get_device_connect_state(); // 获取a2dp连接状态 - #else - bool a2dp = false; - #endif - - if (button == phoneLableButton) // 若点击的是手机音乐按钮 - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick phoneLableButton"); - if (!PlayersModel::GetInstance()->GetMusicSource()) // 切换到手机音乐 - { - PlayersModel::GetInstance()->SetMusicSource(true); - UpdateBluetoothHeadSetViewIsVisible(); - playersView->StopCurPlayingMusic(); - // 1.a2dp未连接,向手机发起a2dp连接 - // 如果蓝牙没连接直接是跳转到蓝牙连接失败视图,连接了就有一个主动去连手机的a2dp过程,5秒超市 - // if (!phonebluetoothcon) - // { - // playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUSIC_BLUETOOTH_DISCONN_VIEW); - // } - // else if (phonebluetoothcon && !a2dp) // 如果手机蓝牙已连接但手表与手机的a2dp未连接手表主动去连接a2dp - // { - // /* -------------------------------------------------------------------------- */ - // uapi_a2dp_snk_connect(); // 切换通道主动连接atdp - // /* -------------------------------------------------------------------------- */ - // playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); - // } - // else if (phonebluetoothcon && a2dp) - // { - // playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MAIN_MUSICPLAYER_VIEW); - // } - /* -------------------------------------------------------------------------- */ - // uapi_a2dp_snk_connect(); // 切换通道主动连接atdp - /* -------------------------------------------------------------------------- */ - playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); - } - else // 如果已经选择了手机音乐,再次点击就回到 “音乐播放器主视图” - { - playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MAIN_MUSICPLAYER_VIEW); - } - } - else if (button == watchLableButton) // 若点击的是手表音乐按钮 - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick watchLableButton"); - if (PlayersModel::GetInstance()->GetMusicSource()) // 切换到手表音乐 - { - PlayersModel::GetInstance()->SetMusicSource(false); - UpdateBluetoothHeadSetViewIsVisible(); - /* -------------------------------------------------------------------------- */ - PlayersModel::GetInstance()->set_phone_music_play_state(AVRCP_KEY_STOP);//切换到手机音乐停止音乐 - /* -------------------------------------------------------------------------- */ - playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); - } - else // 如果已经选择了手表音乐,再次点击就回到 “音乐播放器主视图” - { - playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MAIN_MUSICPLAYER_VIEW); - } - } - else if (button == bluetoothHeadsetLableButton) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick bluetoothHeadsetLableButton"); - NativeAbility::GetInstance().EnterSlice(VIEW_BLUETOOTH_EARPHONE); - // 配置主界面回退界面 - // MainModel::GetInstance().SetFromSetCardView(true); - // MainModel::GetInstance().SetFromCardId(MUSIC_PLAYER); - } - - return true; - } - - void MusicPlayerSourceView::ClearAll() - { - if (group != nullptr) - { - group->RemoveAll(); - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - if (titleLabel != nullptr) - { - delete titleLabel; - titleLabel = nullptr; - } - if (phoneLableButton != nullptr) - { - delete phoneLableButton; - phoneLableButton = nullptr; - } - if (watchLableButton != nullptr) - { - delete watchLableButton; - watchLableButton = nullptr; - } - if (bluetoothHeadsetLableButton != nullptr) - { - delete bluetoothHeadsetLableButton; - bluetoothHeadsetLableButton = nullptr; - } - if (phoneImage != nullptr) - { - delete phoneImage; - phoneImage = nullptr; - } - if (watchImage != nullptr) - { - delete watchImage; - watchImage = nullptr; - } - if (bluetoothHeadsetImage != nullptr) - { - delete bluetoothHeadsetImage; - bluetoothHeadsetImage = nullptr; - } - if (phoneLabel != nullptr) - { - delete phoneLabel; - phoneLabel = nullptr; - } - if (watchLabel != nullptr) - { - delete watchLabel; - watchLabel = nullptr; - } - if (bluetoothHeadsetLabel != nullptr) - { - delete bluetoothHeadsetLabel; - bluetoothHeadsetLabel = nullptr; - } - if (bluetoothHeadsetConnectState != nullptr) - { - delete bluetoothHeadsetConnectState; - bluetoothHeadsetConnectState = nullptr; - } - scrollView->ClearFocus(); - delete scrollView; - scrollView = nullptr; - } - ImageCacheManager::GetInstance().UnloadOneInMultiRes(PLAYER_PHONE_WHITE, PLAYER_IAMGES); - ImageCacheManager::GetInstance().UnloadOneInMultiRes(PLAYER_LOCAL_MUSIC_WHITE, PLAYER_IAMGES); - ImageCacheManager::GetInstance().UnloadOneInMultiRes(PLAYER_EARPHONE_WHITE, PLAYER_IAMGES); - if (dragListener) - { - delete dragListener; - dragListener = nullptr; - } - delete group; - group = nullptr; - } - } - - UILabelExt *MusicPlayerSourceView::MusicPlayerSourceViewLabelInit(LabelConfig &labelconfig) - { - UILabelExt *label = new UILabelExt(); - if (label == nullptr) - { - return nullptr; - } - label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); - label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); - label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); - label->SetTextId(labelconfig.textId); - label->SetLineBreakMode(labelconfig.lineBreakMode); - // label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetRollSpeed(23); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); - return label; - } - - UILabelButton *MusicPlayerSourceView::MusicPlayerSourceViewLabelButtonInit(ButtonConfig &buttonconfig) - { - UILabelButton *button = new UILabelButton(); - if (button == nullptr) - { - return nullptr; - } - button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); - button->SetViewId(buttonconfig.viewId); - button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - button->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); - button->SetOnClickListener(this); - if (buttonconfig.flag) - { - button->SetImagePosition(300, 30); - button->SetImageSrc(PNG_CHECKBOX_OFF_IMAGE, PNG_CHECKBOX_OFF_IMAGE); - } - else - { - button->SetImagePosition(326, 37); - button->SetImageSrc(PNG_SETTING_NEXT_IMAGE, PNG_SETTING_NEXT_IMAGE); - } - return button; - } - - bool MusicPlayerSourceView::CreateMusicPlayerSourceViewLabelButton(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::CreateMusicPlayerSourceViewLabelButton"); - ButtonConfig buttonconfig = { - .x = 43, - .y = 120, - .w = 380, - .h = 100, - .viewId = PHONE_MUSIC_LABEL_BUTTON, - .flag = true, - }; - phoneLableButton = MusicPlayerSourceViewLabelButtonInit(buttonconfig); - if (nullptr == phoneLableButton) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneLableButton new fail!!"); - return false; - } - /* ---------------------------- watchLableButton ---------------------------- */ - buttonconfig.y += 120; - buttonconfig.viewId = WATCH_MUSIC_LABEL_BUTTON; - watchLableButton = MusicPlayerSourceViewLabelButtonInit(buttonconfig); - if (nullptr == watchLableButton) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "watchLableButton new fail!!"); - return false; - } - /* ----------------------- bluetoothHeadsetLableButton ---------------------- */ - buttonconfig.y += 120; - buttonconfig.viewId = BLUETOOTH_HEADSET_LABEL_BUTTON; - buttonconfig.flag = false; - bluetoothHeadsetLableButton = MusicPlayerSourceViewLabelButtonInit(buttonconfig); - if (nullptr == bluetoothHeadsetLableButton) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothHeadsetLableButton new fail!!"); - return false; - } - - return true; - } - - bool MusicPlayerSourceView::CreateMusicPlayerSourceViewLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::CreateMusicPlayerSourceViewLabel"); - LabelConfig labelConfig = { - .left = 83, - .top = 50, - .width = 300, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_MUSIC_SOURCE, /*音乐来源*/ - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - titleLabel = MusicPlayerSourceViewLabelInit(labelConfig); - if (nullptr == titleLabel) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail!!"); - return false; - } - titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - /* ------------------------------- phoneLabel ------------------------------- */ - labelConfig = { - .left = 143, - .top = 153, - .width = 180, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_MOBILE_MUSIC, /*手机音乐*/ - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - phoneLabel = MusicPlayerSourceViewLabelInit(labelConfig); - if (nullptr == phoneLabel) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneLabel new fail!!"); - return false; - } - /* ------------------------------- watchLabel ------------------------------- */ - labelConfig.top += 120; - labelConfig.textId = STR_WATCH_MUSIC; // 手表音乐 - watchLabel = MusicPlayerSourceViewLabelInit(labelConfig); - if (nullptr == watchLabel) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "watchLabel new fail!!"); - return false; - } - /* -------------------------- bluetoothHeadsetLabel ------------------------- */ - labelConfig.top = 381; - labelConfig.textId = STR_BLUETOOTH_HEADPHONES; // 蓝牙耳机 - bluetoothHeadsetLabel = MusicPlayerSourceViewLabelInit(labelConfig); - if (nullptr == bluetoothHeadsetLabel) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothHeadsetLabel new fail!!"); - return false; - } - /* ---------------------- bluetoothHeadsetConnectState ---------------------- */ - labelConfig.top = 413; - labelConfig.fontSize = 23; - labelConfig.lineHeigh = 27; - labelConfig.textId = (SettingModel::GetInstance().GetEarPhoneConnectStatus()) ? STR_PAIRED : STR_NOT_PAIRED; - bluetoothHeadsetConnectState = MusicPlayerSourceViewLabelInit(labelConfig); - if (nullptr == bluetoothHeadsetConnectState) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothHeadsetConnectState new fail!!"); - return false; - } - return true; - } - - bool MusicPlayerSourceView::CreateMusicPlayerSourceViewImage(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::CreateMusicPlayerSourceViewImage"); - ImageInfo *image; - /* ------------------------------- phoneImage ------------------------------- */ - int x = 83; - int y = 150; - int w = 40; - int h = 40; - phoneImage = new UIImageView(); - if (phoneImage == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage new fail"); - return false; - } - phoneImage->SetPosition(x, y, w, h); - if (!PlayersView::LoadPlayerImage(phoneImage, PLAYER_PHONE_WHITE)) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage LoadPlayerImage fail"); - return false; - } - /* ------------------------------- watchImage ------------------------------- */ - y += 120; - watchImage = new UIImageView(); - if (watchImage == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "watchImage new fail"); - return false; - } - watchImage->SetPosition(x, y, w, h); - if (!PlayersView::LoadPlayerImage(watchImage, PLAYER_LOCAL_MUSIC_WHITE)) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage LoadPlayerImage fail"); - return false; - } - /* -------------------------- bluetoothHeadsetImage ------------------------- */ - y += 120; - bluetoothHeadsetImage = new UIImageView(); - if (bluetoothHeadsetImage == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothHeadsetImage new fail"); - return false; - } - bluetoothHeadsetImage->SetPosition(x, y, w, h); - if (!PlayersView::LoadPlayerImage(bluetoothHeadsetImage, PLAYER_EARPHONE_WHITE)) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage LoadPlayerImage fail"); - return false; - } - return true; - } - - UIViewGroup *MusicPlayerSourceView::CreateMusicPlayerSourceView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::CreateMusicPlayerSourceView"); - if (group == nullptr) - { - group = new UIViewGroup(); - if (group == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); - return nullptr; - } - } - group->SetPosition(0, 0, 466, 466); - group->SetStyle(STYLE_BACKGROUND_OPA, 0); - group->SetTouchable(true); - group->SetDraggable(true); - group->SetIntercept(true); - group->SetViewId(MUSIC_PLAYER_SOURCE_VIEW); - if (dragListener == nullptr) - { - dragListener = static_cast(new PlayerOnDragListener()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dragListener new fail"); - return nullptr; - } - } - group->SetOnDragListener(dragListener); - /* -------------------------------------------------------------------------- */ - if (scrollView == nullptr) - { - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView new fail"); - return nullptr; - } - } - scrollView->SetPosition(0, 0, 466, 466); - scrollView->SetScrollBlankSize(75); - scrollView->SetReboundSize(35); - scrollView->SetThrowDrag(true); - scrollView->SetMaxScrollDistance(1000); - scrollView->SetDragACCLevel(5); - scrollView->SetSwipeACCLevel(200); /*设置手指抬起屏幕后的补偿距离。*/ - scrollView->SetDirection(UIScrollView::VERTICAL); - scrollView->RequestFocus(); - scrollView->SetRotateFactor(1.0); - group->Add(scrollView); - - if (!CreateMusicPlayerSourceViewLabelButton() || !CreateMusicPlayerSourceViewLabel() || !CreateMusicPlayerSourceViewImage()) - { - return nullptr; - } - - UpdateBluetoothHeadsetConnectLabel(); - UpdateBluetoothHeadSetViewIsVisible(); - /* ----------------------------------- Add ---------------------------------- */ - - scrollView->Add(titleLabel); - scrollView->Add(phoneLableButton); - scrollView->Add(watchLableButton); - scrollView->Add(bluetoothHeadsetLableButton); - scrollView->Add(phoneImage); - scrollView->Add(watchImage); - scrollView->Add(bluetoothHeadsetImage); - scrollView->Add(phoneLabel); - scrollView->Add(watchLabel); - scrollView->Add(bluetoothHeadsetLabel); - scrollView->Add(bluetoothHeadsetConnectState); - /* -------------------------------------------------------------------------- */ - return group; - } - - void MusicPlayerSourceView::UpdateBluetoothHeadSetViewIsVisible(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::UpdateBluetoothHeadSetViewIsVisible"); - bool value = PlayersModel::GetInstance()->GetMusicSource(); - if (bluetoothHeadsetLabel && bluetoothHeadsetImage && bluetoothHeadsetLableButton && bluetoothHeadsetConnectState) - { - bluetoothHeadsetLabel->SetVisible(value ? false : true); - bluetoothHeadsetImage->SetVisible(value ? false : true); - bluetoothHeadsetLableButton->SetVisible(value ? false : true); - bluetoothHeadsetConnectState->SetVisible(value ? false : true); - } - if (phoneLableButton && watchLableButton) - { - if (value) - { - phoneLableButton->SetImageSrc(PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_ON_IMAGE); - watchLableButton->SetImageSrc(PNG_CHECKBOX_OFF_IMAGE, PNG_CHECKBOX_OFF_IMAGE); - } - else - { - phoneLableButton->SetImageSrc(PNG_CHECKBOX_OFF_IMAGE, PNG_CHECKBOX_OFF_IMAGE); - watchLableButton->SetImageSrc(PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_ON_IMAGE); - } - } - scrollView->Invalidate(); - } - - /*更新蓝牙耳机连接状态*/ - void MusicPlayerSourceView::UpdateBluetoothHeadsetConnectLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::UpdateBluetoothHeadsetConnectLabel"); - if (bluetoothHeadsetConnectState) - { - bool state = SettingModel::GetInstance().GetEarPhoneConnectStatus(); - List &bluetoothCaseList = BluetoothModel::GetInstance()->GetConnedDevicesCase(); - bool ConnedDevicesListIsEmpty = bluetoothCaseList.IsEmpty(); - if (ConnedDevicesListIsEmpty) // 如果已连接设备列表为空,则显示未配对 - { - bluetoothHeadsetConnectState->SetTextId(STR_NOT_PAIRED); - bluetoothHeadsetConnectState->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); - bluetoothHeadsetConnectState->Invalidate(); - } - else // 否则则显示连接状态 - { - bluetoothHeadsetConnectState->SetTextId(state ? STR_CONNECTED : STR_DISCONNECTED); - bluetoothHeadsetConnectState->SetTextColor(state ? Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff) : Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); - bluetoothHeadsetConnectState->Invalidate(); - } - } - } - - UIScrollView *MusicPlayerSourceView::GetMusicPlayerSourcescrollView(void) - { - return scrollView; - } -} +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: bluetooth view 设置页面 + * Create: 2021-09-5 + */ +#include "player/include/MusicPlayerSourceView.h" +#include "player/include/PlayersView.h" +#include "player/include/PlayersModel.h" +#include "UiConfig.h" +#include "bluetooth/include/BluetoothEarPhoneView.h" +#include "player/include/PlayersPresenter.h" +#include "ui_resource_image.h" +#include "ui_resource_string.h" +#include "settings/include/SettingModel.h" +#include "ui_resource_string.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "main/include/MainModel.h" +namespace OHOS +{ + static MusicPlayerSourceView *g_bluetoothView{nullptr}; + MusicPlayerSourceView::MusicPlayerSourceView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::MusicPlayerSourceView"); + g_bluetoothView = this; + } + + MusicPlayerSourceView::~MusicPlayerSourceView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::~MusicPlayerSourceView"); + ClearAll(); + g_bluetoothView = nullptr; + } + + MusicPlayerSourceView *MusicPlayerSourceView::GetInstance(void) + { + return g_bluetoothView; + } + + bool MusicPlayerSourceView::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::OnClick"); + UILabelButton *button = dynamic_cast(&view); + if (!button) + { + return false; + } + PlayersPresenter *playersPresenter = PlayersPresenter::GetInstance(); + if (!playersPresenter) + { + return false; + } + PlayersView *playersView = PlayersView::GetInstance(); + if (!playersView) + { + return false; + } + ImageInfo *image; + bool phonebluetoothcon = SettingModel::GetInstance().GetPhoneConnectStatus(); // 获取手机连接状态 + #ifdef SUPPORT_BLE_SERVICE + bool a2dp = uapi_a2dp_snk_get_device_connect_state(); // 获取a2dp连接状态 + #else + bool a2dp = false; + #endif + + if (button == phoneLableButton) // 若点击的是手机音乐按钮 + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick phoneLableButton"); + if (!PlayersModel::GetInstance()->GetMusicSource()) // 切换到手机音乐 + { + PlayersModel::GetInstance()->SetMusicSource(true); + UpdateBluetoothHeadSetViewIsVisible(); + playersView->StopCurPlayingMusic(); + // 1.a2dp未连接,向手机发起a2dp连接 + // 如果蓝牙没连接直接是跳转到蓝牙连接失败视图,连接了就有一个主动去连手机的a2dp过程,5秒超市 + // if (!phonebluetoothcon) + // { + // playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUSIC_BLUETOOTH_DISCONN_VIEW); + // } + // else if (phonebluetoothcon && !a2dp) // 如果手机蓝牙已连接但手表与手机的a2dp未连接手表主动去连接a2dp + // { + // /* -------------------------------------------------------------------------- */ + // uapi_a2dp_snk_connect(); // 切换通道主动连接atdp + // /* -------------------------------------------------------------------------- */ + // playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); + // } + // else if (phonebluetoothcon && a2dp) + // { + // playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MAIN_MUSICPLAYER_VIEW); + // } + /* -------------------------------------------------------------------------- */ + // uapi_a2dp_snk_connect(); // 切换通道主动连接atdp + /* -------------------------------------------------------------------------- */ + playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); + } + else // 如果已经选择了手机音乐,再次点击就回到 “音乐播放器主视图” + { + playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MAIN_MUSICPLAYER_VIEW); + } + } + else if (button == watchLableButton) // 若点击的是手表音乐按钮 + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick watchLableButton"); + if (PlayersModel::GetInstance()->GetMusicSource()) // 切换到手表音乐 + { + PlayersModel::GetInstance()->SetMusicSource(false); + UpdateBluetoothHeadSetViewIsVisible(); + /* -------------------------------------------------------------------------- */ + PlayersModel::GetInstance()->set_phone_music_play_state(AVRCP_KEY_STOP);//切换到手机音乐停止音乐 + /* -------------------------------------------------------------------------- */ + playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); + } + else // 如果已经选择了手表音乐,再次点击就回到 “音乐播放器主视图” + { + playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MAIN_MUSICPLAYER_VIEW); + } + } + else if (button == bluetoothHeadsetLableButton) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick bluetoothHeadsetLableButton"); + OHOS::AbilityNavigation::EnterSlice(VIEW_BLUETOOTH_EARPHONE); + // 配置主界面回退界面 + // MainModel::GetInstance().SetFromSetCardView(true); + // MainModel::GetInstance().SetFromCardId(MUSIC_PLAYER); + } + + return true; + } + + void MusicPlayerSourceView::ClearAll() + { + if (group != nullptr) + { + group->RemoveAll(); + if (scrollView != nullptr) + { + scrollView->RemoveAll(); + if (titleLabel != nullptr) + { + delete titleLabel; + titleLabel = nullptr; + } + if (phoneLableButton != nullptr) + { + delete phoneLableButton; + phoneLableButton = nullptr; + } + if (watchLableButton != nullptr) + { + delete watchLableButton; + watchLableButton = nullptr; + } + if (bluetoothHeadsetLableButton != nullptr) + { + delete bluetoothHeadsetLableButton; + bluetoothHeadsetLableButton = nullptr; + } + if (phoneImage != nullptr) + { + delete phoneImage; + phoneImage = nullptr; + } + if (watchImage != nullptr) + { + delete watchImage; + watchImage = nullptr; + } + if (bluetoothHeadsetImage != nullptr) + { + delete bluetoothHeadsetImage; + bluetoothHeadsetImage = nullptr; + } + if (phoneLabel != nullptr) + { + delete phoneLabel; + phoneLabel = nullptr; + } + if (watchLabel != nullptr) + { + delete watchLabel; + watchLabel = nullptr; + } + if (bluetoothHeadsetLabel != nullptr) + { + delete bluetoothHeadsetLabel; + bluetoothHeadsetLabel = nullptr; + } + if (bluetoothHeadsetConnectState != nullptr) + { + delete bluetoothHeadsetConnectState; + bluetoothHeadsetConnectState = nullptr; + } + scrollView->ClearFocus(); + delete scrollView; + scrollView = nullptr; + } + ImageCacheManager::GetInstance().UnloadOneInMultiRes(PLAYER_PHONE_WHITE, PLAYER_IAMGES); + ImageCacheManager::GetInstance().UnloadOneInMultiRes(PLAYER_LOCAL_MUSIC_WHITE, PLAYER_IAMGES); + ImageCacheManager::GetInstance().UnloadOneInMultiRes(PLAYER_EARPHONE_WHITE, PLAYER_IAMGES); + if (dragListener) + { + delete dragListener; + dragListener = nullptr; + } + delete group; + group = nullptr; + } + } + + UILabelExt *MusicPlayerSourceView::MusicPlayerSourceViewLabelInit(LabelConfig &labelconfig) + { + UILabelExt *label = new UILabelExt(); + if (label == nullptr) + { + return nullptr; + } + label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); + label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); + label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); + label->SetTextId(labelconfig.textId); + label->SetLineBreakMode(labelconfig.lineBreakMode); + // label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetRollSpeed(23); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; + } + + UILabelButton *MusicPlayerSourceView::MusicPlayerSourceViewLabelButtonInit(ButtonConfig &buttonconfig) + { + UILabelButton *button = new UILabelButton(); + if (button == nullptr) + { + return nullptr; + } + button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); + button->SetViewId(buttonconfig.viewId); + button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + button->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + button->SetOnClickListener(this); + if (buttonconfig.flag) + { + button->SetImagePosition(300, 30); + button->SetImageSrc(PNG_CHECKBOX_OFF_IMAGE, PNG_CHECKBOX_OFF_IMAGE); + } + else + { + button->SetImagePosition(326, 37); + button->SetImageSrc(PNG_SETTING_NEXT_IMAGE, PNG_SETTING_NEXT_IMAGE); + } + return button; + } + + bool MusicPlayerSourceView::CreateMusicPlayerSourceViewLabelButton(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::CreateMusicPlayerSourceViewLabelButton"); + ButtonConfig buttonconfig = { + .x = 43, + .y = 120, + .w = 380, + .h = 100, + .viewId = PHONE_MUSIC_LABEL_BUTTON, + .flag = true, + }; + phoneLableButton = MusicPlayerSourceViewLabelButtonInit(buttonconfig); + if (nullptr == phoneLableButton) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneLableButton new fail!!"); + return false; + } + /* ---------------------------- watchLableButton ---------------------------- */ + buttonconfig.y += 120; + buttonconfig.viewId = WATCH_MUSIC_LABEL_BUTTON; + watchLableButton = MusicPlayerSourceViewLabelButtonInit(buttonconfig); + if (nullptr == watchLableButton) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "watchLableButton new fail!!"); + return false; + } + /* ----------------------- bluetoothHeadsetLableButton ---------------------- */ + buttonconfig.y += 120; + buttonconfig.viewId = BLUETOOTH_HEADSET_LABEL_BUTTON; + buttonconfig.flag = false; + bluetoothHeadsetLableButton = MusicPlayerSourceViewLabelButtonInit(buttonconfig); + if (nullptr == bluetoothHeadsetLableButton) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothHeadsetLableButton new fail!!"); + return false; + } + + return true; + } + + bool MusicPlayerSourceView::CreateMusicPlayerSourceViewLabel(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::CreateMusicPlayerSourceViewLabel"); + LabelConfig labelConfig = { + .left = 83, + .top = 50, + .width = 300, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .textId = STR_MUSIC_SOURCE, /*音乐来源*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + titleLabel = MusicPlayerSourceViewLabelInit(labelConfig); + if (nullptr == titleLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail!!"); + return false; + } + titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + /* ------------------------------- phoneLabel ------------------------------- */ + labelConfig = { + .left = 143, + .top = 153, + .width = 180, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .textId = STR_MOBILE_MUSIC, /*手机音乐*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + phoneLabel = MusicPlayerSourceViewLabelInit(labelConfig); + if (nullptr == phoneLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneLabel new fail!!"); + return false; + } + /* ------------------------------- watchLabel ------------------------------- */ + labelConfig.top += 120; + labelConfig.textId = STR_WATCH_MUSIC; // 手表音乐 + watchLabel = MusicPlayerSourceViewLabelInit(labelConfig); + if (nullptr == watchLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "watchLabel new fail!!"); + return false; + } + /* -------------------------- bluetoothHeadsetLabel ------------------------- */ + labelConfig.top = 381; + labelConfig.textId = STR_BLUETOOTH_HEADPHONES; // 蓝牙耳机 + bluetoothHeadsetLabel = MusicPlayerSourceViewLabelInit(labelConfig); + if (nullptr == bluetoothHeadsetLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothHeadsetLabel new fail!!"); + return false; + } + /* ---------------------- bluetoothHeadsetConnectState ---------------------- */ + labelConfig.top = 413; + labelConfig.fontSize = 23; + labelConfig.lineHeigh = 27; + labelConfig.textId = (SettingModel::GetInstance().GetEarPhoneConnectStatus()) ? STR_PAIRED : STR_NOT_PAIRED; + bluetoothHeadsetConnectState = MusicPlayerSourceViewLabelInit(labelConfig); + if (nullptr == bluetoothHeadsetConnectState) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothHeadsetConnectState new fail!!"); + return false; + } + return true; + } + + bool MusicPlayerSourceView::CreateMusicPlayerSourceViewImage(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::CreateMusicPlayerSourceViewImage"); + ImageInfo *image; + /* ------------------------------- phoneImage ------------------------------- */ + int x = 83; + int y = 150; + int w = 40; + int h = 40; + phoneImage = new UIImageView(); + if (phoneImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage new fail"); + return false; + } + phoneImage->SetPosition(x, y, w, h); + if (!PlayersView::LoadPlayerImage(phoneImage, PLAYER_PHONE_WHITE)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage LoadPlayerImage fail"); + return false; + } + /* ------------------------------- watchImage ------------------------------- */ + y += 120; + watchImage = new UIImageView(); + if (watchImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "watchImage new fail"); + return false; + } + watchImage->SetPosition(x, y, w, h); + if (!PlayersView::LoadPlayerImage(watchImage, PLAYER_LOCAL_MUSIC_WHITE)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage LoadPlayerImage fail"); + return false; + } + /* -------------------------- bluetoothHeadsetImage ------------------------- */ + y += 120; + bluetoothHeadsetImage = new UIImageView(); + if (bluetoothHeadsetImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothHeadsetImage new fail"); + return false; + } + bluetoothHeadsetImage->SetPosition(x, y, w, h); + if (!PlayersView::LoadPlayerImage(bluetoothHeadsetImage, PLAYER_EARPHONE_WHITE)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage LoadPlayerImage fail"); + return false; + } + return true; + } + + UIViewGroup *MusicPlayerSourceView::CreateMusicPlayerSourceView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::CreateMusicPlayerSourceView"); + if (group == nullptr) + { + group = new UIViewGroup(); + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } + } + group->SetPosition(0, 0, 466, 466); + group->SetStyle(STYLE_BACKGROUND_OPA, 0); + group->SetTouchable(true); + group->SetDraggable(true); + group->SetIntercept(true); + group->SetViewId(MUSIC_PLAYER_SOURCE_VIEW); + if (dragListener == nullptr) + { + dragListener = static_cast(new PlayerOnDragListener()); + if (dragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dragListener new fail"); + return nullptr; + } + } + group->SetOnDragListener(dragListener); + /* -------------------------------------------------------------------------- */ + if (scrollView == nullptr) + { + scrollView = new UIScrollView(); + if (scrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView new fail"); + return nullptr; + } + } + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetScrollBlankSize(75); + scrollView->SetReboundSize(35); + scrollView->SetThrowDrag(true); + scrollView->SetMaxScrollDistance(1000); + scrollView->SetDragACCLevel(5); + scrollView->SetSwipeACCLevel(200); /*设置手指抬起屏幕后的补偿距离。*/ + scrollView->SetDirection(UIScrollView::VERTICAL); + scrollView->RequestFocus(); + scrollView->SetRotateFactor(1.0); + group->Add(scrollView); + + if (!CreateMusicPlayerSourceViewLabelButton() || !CreateMusicPlayerSourceViewLabel() || !CreateMusicPlayerSourceViewImage()) + { + return nullptr; + } + + UpdateBluetoothHeadsetConnectLabel(); + UpdateBluetoothHeadSetViewIsVisible(); + /* ----------------------------------- Add ---------------------------------- */ + + scrollView->Add(titleLabel); + scrollView->Add(phoneLableButton); + scrollView->Add(watchLableButton); + scrollView->Add(bluetoothHeadsetLableButton); + scrollView->Add(phoneImage); + scrollView->Add(watchImage); + scrollView->Add(bluetoothHeadsetImage); + scrollView->Add(phoneLabel); + scrollView->Add(watchLabel); + scrollView->Add(bluetoothHeadsetLabel); + scrollView->Add(bluetoothHeadsetConnectState); + /* -------------------------------------------------------------------------- */ + return group; + } + + void MusicPlayerSourceView::UpdateBluetoothHeadSetViewIsVisible(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::UpdateBluetoothHeadSetViewIsVisible"); + bool value = PlayersModel::GetInstance()->GetMusicSource(); + if (bluetoothHeadsetLabel && bluetoothHeadsetImage && bluetoothHeadsetLableButton && bluetoothHeadsetConnectState) + { + bluetoothHeadsetLabel->SetVisible(value ? false : true); + bluetoothHeadsetImage->SetVisible(value ? false : true); + bluetoothHeadsetLableButton->SetVisible(value ? false : true); + bluetoothHeadsetConnectState->SetVisible(value ? false : true); + } + if (phoneLableButton && watchLableButton) + { + if (value) + { + phoneLableButton->SetImageSrc(PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_ON_IMAGE); + watchLableButton->SetImageSrc(PNG_CHECKBOX_OFF_IMAGE, PNG_CHECKBOX_OFF_IMAGE); + } + else + { + phoneLableButton->SetImageSrc(PNG_CHECKBOX_OFF_IMAGE, PNG_CHECKBOX_OFF_IMAGE); + watchLableButton->SetImageSrc(PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_ON_IMAGE); + } + } + scrollView->Invalidate(); + } + + /*更新蓝牙耳机连接状态*/ + void MusicPlayerSourceView::UpdateBluetoothHeadsetConnectLabel(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerSourceView::UpdateBluetoothHeadsetConnectLabel"); + if (bluetoothHeadsetConnectState) + { + bool state = SettingModel::GetInstance().GetEarPhoneConnectStatus(); + List &bluetoothCaseList = BluetoothModel::GetInstance()->GetConnedDevicesCase(); + bool ConnedDevicesListIsEmpty = bluetoothCaseList.IsEmpty(); + if (ConnedDevicesListIsEmpty) // 如果已连接设备列表为空,则显示未配对 + { + bluetoothHeadsetConnectState->SetTextId(STR_NOT_PAIRED); + bluetoothHeadsetConnectState->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + bluetoothHeadsetConnectState->Invalidate(); + } + else // 否则则显示连接状态 + { + bluetoothHeadsetConnectState->SetTextId(state ? STR_CONNECTED : STR_DISCONNECTED); + bluetoothHeadsetConnectState->SetTextColor(state ? Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff) : Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + bluetoothHeadsetConnectState->Invalidate(); + } + } + } + + UIScrollView *MusicPlayerSourceView::GetMusicPlayerSourcescrollView(void) + { + return scrollView; + } +} diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp index d7dceefb0..18c606fa6 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp @@ -12,6 +12,7 @@ #include "wearable_log.h" #include "ConfigModel.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include #include "settings/include/SettingModel.h" #include @@ -245,7 +246,7 @@ namespace OHOS } // 切换到关机/重启卡片 - NativeAbility::GetInstance().EnterSlice(VIEW_REBOOTANDSHUTDOWN); + OHOS::AbilityNavigation::EnterSlice(VIEW_REBOOTANDSHUTDOWN); } static void HandlePowerKeyLongPress(void) @@ -403,7 +404,7 @@ namespace OHOS { if (curSliceId != VIEW_CODED_LOCK) { - NativeAbility::GetInstance().EnterSlice(VIEW_CODED_LOCK); + OHOS::AbilityNavigation::EnterSlice(VIEW_CODED_LOCK); } return; } @@ -414,7 +415,7 @@ namespace OHOS return; } // 全局切换到Ai语音界面 - NativeAbility::GetInstance().EnterSlice(VIEW_AI_VOICE); + OHOS::AbilityNavigation::EnterSlice(VIEW_AI_VOICE); } else { @@ -482,7 +483,7 @@ namespace OHOS { if (curSliceId != VIEW_CODED_LOCK) { - NativeAbility::GetInstance().EnterSlice(VIEW_CODED_LOCK); + OHOS::AbilityNavigation::EnterSlice(VIEW_CODED_LOCK); } return; } @@ -554,14 +555,14 @@ namespace OHOS { if (curSliceId != VIEW_CODED_LOCK) { - NativeAbility::GetInstance().EnterSlice(VIEW_CODED_LOCK); + OHOS::AbilityNavigation::EnterSlice(VIEW_CODED_LOCK); } return; } } if (curSliceId != VIEW_AI_VOICE) { - NativeAbility::GetInstance().EnterSlice(VIEW_AI_VOICE); + OHOS::AbilityNavigation::EnterSlice(VIEW_AI_VOICE); } } else @@ -630,13 +631,13 @@ namespace OHOS { if (curSliceId != VIEW_CODED_LOCK) { - NativeAbility::GetInstance().EnterSlice(VIEW_CODED_LOCK); + OHOS::AbilityNavigation::EnterSlice(VIEW_CODED_LOCK); } return; } } // 全局切换安全模式界面 - NativeAbility::GetInstance().EnterSlice(VIEW_SAFE_MODE); + OHOS::AbilityNavigation::EnterSlice(VIEW_SAFE_MODE); } } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownPresenter.cpp index 7315eb7be..d795b87fd 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownPresenter.cpp @@ -7,6 +7,7 @@ */ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include #include "UiConfig.h" @@ -143,7 +144,7 @@ namespace OHOS { if (strcmp(view.GetViewId(), REBOOT_AND_SHUTDOWN_GROUPVIEW) == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } else if (strcmp(view.GetViewId(), FACTORY_RESET_GROUPVIEW) == 0) { @@ -229,7 +230,7 @@ namespace OHOS { if (!isShutDownImageAnimatorStart) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } } return true; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/record/src/RecordingPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/record/src/RecordingPresenter.cpp index b30f64440..f6b373b53 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/record/src/RecordingPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/record/src/RecordingPresenter.cpp @@ -1,892 +1,893 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-03-30 09:14:38 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-12-18 14:33:46 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp - */ - -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "NativeAbility.h" -#include "graphic_math.h" -#include "string.h" -#include "record/include/RecordingPresenter.h" -#include -#include "custom_utils.h" -#include "record/include/RecordingListitemView.h" -#include -#include -#include "record/include/RecordingModel.h" -#include -#include -#include "NativeRegisterManager.h" - -namespace OHOS -{ - REGIST_MENU_PRO(VIEW_RECORD, RecordingView, RecordingPresenter, - PNG_APPLIST_RECORD_IMAGE_BIG, PNG_APPLIST_RECORD_IMAGE,PNG_APPLIST_RECORD_IMAGE, "录音", STR_RECORD); - - - // 当前Presenter属性实例化的内存指针 - static RecordingPresenter *g_pRecordPresenter = nullptr; - - RecordingPresenter::RecordingPresenter() - { - p_RecordingModel = RecordingModel::GetInstance(); - g_pRecordPresenter = this; - } - - RecordingPresenter::~RecordingPresenter() - { - p_RecordingModel->ClearRecordingPlayer(); - StopRecord(); - g_pRecordPresenter = nullptr; - } - - RecordingPresenter *RecordingPresenter::GetInstance() - { - return g_pRecordPresenter; - } - - void RecordingPresenter::OnStart() - { - // 初始化录音信息 - p_RecordingModel->InitRecordingListItem(); - p_RecordingModel->AudioInit(); - p_RecordingModel->SendCheckRecordingSpaceOutCmd(); //进入录音视图后发送指令查看录音空间是否已满 - // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); - } - void RecordingPresenter::OnResume(void) - { - RootView::GetInstance()->SetOnKeyActListener(this); - if(RecordingVolumeSettingView::GetInstance()) - { - if(RecordingVolumeSettingView::GetInstance()->GetSoundAndVibrationVolumeSettingView()) - { - if(RecordingVolumeSettingView::GetInstance()->GetSoundAndVibrationVolumeSettingView()->GetVolumeProcess()) - { - RecordingVolumeSettingView::GetInstance()->GetSoundAndVibrationVolumeSettingView()->GetVolumeProcess()->RequestFocus(); - } - } - } - } - - bool RecordingPresenter::OnDrag(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnDrag"); - UNUSED(view); - UNUSED(event); - return true; - } - - bool RecordingPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnDragEnd"); - - RecordingView *p_RecordingView = RecordingView::GetInstance(); - if (p_RecordingView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView GetInstance fail"); - return false; - } - - UIScrollView *scrollView = static_cast(&view); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView is nullptr"); - return false; - } - - auto currentView = p_RecordingView->GetCurrentViewType(scrollView); - - switch (event.GetDragDirection()) - { - case DragEvent::DIRECTION_LEFT_TO_RIGHT: // 右滑退出 - switch (currentView) - { - case RECORDINGVIEW: - NativeAbility::GetInstance().Back(); - break; - case RECORDINGPLAYERVIEW: - p_RecordingView->ChangeView(RECORDINGPLAYERVIEW, RECORDINGLISTVIEW); // 录音播放视图(subView)->录音列表视图(subView) - break; - case RECORDINGDELETEVIEW: - p_RecordingView->ChangeView(RECORDINGDELETEVIEW, RECORDINGPLAYERVIEW); // 录音删除视图(subView)->录音播放视图(subView) - break; - case RECORDINGVOLUMESETTINGVIEW: - p_RecordingView->ChangeView(RECORDINGVOLUMESETTINGVIEW, RECORDINGPLAYERVIEW); // 声音设置视图(subView)->录音播放视图(subView) - break; - case RECORDINGEXCELIMIT: - p_RecordingView->ChangeView(RECORDINGEXCELIMIT, RECORDINGVIEW); - break; - default: - break; - } - break; - case DragEvent::DIRECTION_BOTTOM_TO_TOP: - if (currentView == RECORDINGVIEW) - { - p_RecordingView->ChangeView(RECORDINGVIEW, RECORDINGLISTVIEW); - } - break; - default: - break; - } - - return true; - } - - /// @brief 解析时间 - /// @param numericDateTime "19700101000641"; // 输入的数字形式日期时间 - /// @param formattedDateTime - /// @return - int RecordingPresenter::convertNumericDateTime(const char *numericDateTime, char *formattedDateTime) - { - if (strlen(numericDateTime) != 14) - { - return 0; // 如果输入的数字长度不为14,则转换失败 - } - - struct tm timeinfo = {0}; - if (strptime(numericDateTime, "%Y%m%d%H%M%S", &timeinfo) == NULL) - { - return 0; // 解析失败 - } - - // 格式化输出为上午/下午几点几分几秒 - // strftime(formattedDateTime, 80, "%p %I点%M分%S秒", &timeinfo); - strftime(formattedDateTime, 80, "%p%H%M%S", &timeinfo); - return 1; // 转换成功 - } - -#ifdef __cplusplus - extern "C" - { -#endif - int32_t AudioCaptureSample(int32_t argc, const char *argv[]); - -#ifdef __cplusplus - }; -#endif - - /*开始录音*/ - void RecordingPresenter::StartRecord(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingView StartRecord"); - char *args[6] = {0}; - const char *defaultArgs[6] = {"01", "mp3", "16000", "1", "16", nullptr}; // 默认参数数组 - for (int i = 0; i < 5; ++i) - { - args[i] = (char *)malloc(16); // 分配内存 - sprintf(args[i], "%s", defaultArgs[i]); // 设置默认参数值 - } - args[5] = (char *)malloc(100); // 分配内存 - /* -------------------------------------------------------------------------- */ - int num = p_RecordingModel->getMaxRecordingNumber(); - std::string recordfileNme; - // if (num < 9) - // { - // recordfileNme = "record_0" + std::to_string(num + 1); - // } - // else - // { - // recordfileNme = "record_" + std::to_string(num + 1); - // } - recordfileNme = std::to_string(num + 1); - p_RecordingModel->SetRecordFileName(recordfileNme); - sprintf(args[5], "%s%s.mp3", RecordingModel::GetInstance()->GetRecordDirectory(), recordfileNme.c_str()); - /* ---------------------------------- 开始录音 ---------------------------------- */ - uapi_save_runtime_log(RUNTIME_LOG_RECORD_START);//TOOD* - AudioCaptureSample(6, (const char **)args); - /* --------------------------------- 跳转到录音界面 -------------------------------- */ - view_->ChangeView(RECORDINGVIEW, RECORDGOINGVIEW); - p_RecordingModel->Recording_StartTimer(); - RecordGoingView::GetInstance()->GetRecordingDurationLabel()->SetText("00:00:00"); - /* ---------------------------------- 释放内存 ---------------------------------- */ - for (int i = 0; i < 6; ++i) - { - free(args[i]); - } - } - - // 停止录音 - void RecordingPresenter::StopRecord(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingView StopRecord"); - int32_t argc = 1; - uint8_t *argv = (uint8_t *)"stop"; - AudioCaptureSample(argc, (const char **)&argv); - uapi_save_runtime_log(RUNTIME_LOG_RECORD_STOP);//TOOD* - /* ---------------------------------- 停止定时器 --------------------------------- */ - p_RecordingModel->Recording_StopTimer(); - /* --------------------------------- 录音数量加1 --------------------------------- */ - p_RecordingModel->SetRecordingListNum(p_RecordingModel->GetRecordingListNum() + 1); - /* --------------------------------- 设置录音信息 --------------------------------- */ - // int num = p_RecordingModel->GetRecordingListNum(); // 保存录音的下标 - std::string recordingFileName = p_RecordingModel->GetRecordFileName(); // 录音文件名 - // std::string yyymmhhh_date = RecordingModel::GetInstance()->Getyyyymmhhh_date(); // 保存录音年月日时间 - // std::string TotalRecordDuration = RecordingModel::recordTempDuration; // 录音的总时长 - // RecordingInfo info = {0}; - // strncpy_s(info.recordingFileName, 32, recordingFileName.c_str(), recordingFileName.length()); - // strncpy_s(info.recordingDuration, 16, TotalRecordDuration.c_str(), TotalRecordDuration.length()); - // strncpy_s(info.recordingTime, 16, yyymmhhh_date.c_str(), yyymmhhh_date.length()); - p_RecordingModel->RecordDataWriteToFile(recordingFileName.c_str()); - RecordingModel::GetInstance()->InitRecordingListItem(); - - p_RecordingModel->SendCheckRecordingSpaceOutCmd(); //录音完后发送指令查看录音空间是否已满 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView StopRecord over!!"); - } - - //弹窗警告 - void RecordingPresenter::showWarning(void) - { - if(view_) - { - view_->ChangeView(RecordingModel::GetInstance()->GetCurView(), RECORDINGEXCELIMIT); - } - } - - bool RecordingPresenter::OnClick(UIView &view, const ClickEvent &event) - { - RecordingView *p_RecordingView = RecordingView::GetInstance(); - if (p_RecordingView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView GetInstance fail"); - return false; - } - - if (strcmp(view.GetViewId(), RECORD_BUTTON) == 0) - { - int g_TotalUsedTime = RecordingModel::GetInstance()->GetUsedRecordingTime(); // 已用时间 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "g_TotalUsedTime:%d", g_TotalUsedTime); - if (p_RecordingModel->CheckRecordingTimeOut(g_TotalUsedTime) || p_RecordingModel->GetRecordingListNum() >= MAX_RECORDING_NUM || - p_RecordingModel->GetCheckRecordingSpaceOut()) - { - view_->ChangeView(RECORDINGVIEW, RECORDINGEXCELIMIT); - return true; - } - StartRecord(); - return true; - } - else if (strcmp(view.GetViewId(), RECORD_GOING_BUTTON_VIEWID) == 0) - { - StopRecord(); - view_->ChangeView(RECORDGOINGVIEW, RECORDINGVIEW); - return true; - } - else if (strcmp(view.GetViewId(), RECORD_DELETE_ON_BUTTON_VIEWID) == 0) // 若点击的是录音删除按钮 - { - int index = p_RecordingModel->GetClickRecordingIndex(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index = %d", index); - // std::string delete_path = RecordingModel::GetInstance()->GetRecordDirectory(); - // std::string delete_filename = p_RecordingModel->GetFileNames()[index] + ".mp3"; - // std::string fileName = delete_path + delete_filename; - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index = %d ", index); - // uapi_delete_files(fileName.c_str());//删除录音文件 - p_RecordingModel->UpdateRecordingInfo(); - - p_RecordingView->ChangeView(RECORDINGDELETEVIEW, RECORDINGLISTVIEW); - return true; - } - else if (strcmp(view.GetViewId(), RECORD_DELETE_OFF_BUTTON_VIEWID) == 0) - { - p_RecordingView->ChangeView(RECORDINGDELETEVIEW, RECORDINGPLAYERVIEW); - return true; - } - else if (strcmp(view.GetViewId(), RECORDINGNUMLIMITBUTTONVIEW) == 0) - { - p_RecordingView->ChangeView(RECORDINGEXCELIMIT, RECORDINGVIEW); - return true; - } - return true; - } - - bool RecordingPresenter::OnKeyAct(UIView &view, const KeyEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPresenter::OnKeyAct"); - uint16 keyID = event.GetKeyId(); - uint16_t keyState = event.GetState(); - // 如果是power键就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; - } - - void RecordingPresenter::Notify() - { - //如果是在正在录音视图且正在录音视图为可见 - if(view_->GetRecordingViewScrollView(RECORDGOINGVIEW) && view_->GetRecordingViewScrollView(RECORDGOINGVIEW)->IsVisible()) - { - if(RecordGoingView::GetInstance()->GetRecordingDurationLabel()) - { - RecordGoingView::GetInstance()->GetRecordingDurationLabel()->SetText(RecordingModel::GetInstance()->DisplayRecordDuration()); - } - } - } - - - void RecordingPresenter::SetCircleProgress() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPresenter::SetCircleProgress"); - RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); - if (p_RecordingPlayerView == nullptr) - { - return; - } - UICircleProgress *playbackProgress = p_RecordingPlayerView->GetPlayerProgressBar(); - if (playbackProgress == nullptr) - { - return; - } - int32_t playerState; - playerState = p_RecordingModel->GetRecordingPlayerState(); - state_ = p_RecordingPlayerView->GetPlayerButtonState(); - if ((playerState != PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::SELECTED)) - { - p_RecordingPlayerView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); - } - else if ((playerState == PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::UNSELECTED)) - { - p_RecordingPlayerView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); - } - if (state_ == UICheckBox::UICheckBoxState::SELECTED) - { - p_RecordingModel->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_); - p_RecordingModel->GetDuration(playerMusicDuration_); - if (playerMusicDuration_ != 0) - { - playerProgressValue_ = (playerCurrentTime_ * 100) / playerMusicDuration_; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressValue_ %lld", playerProgressValue_); - } - else - { - playerProgressValue_ = 100; // 100: max progress value - } - p_RecordingModel->SetCircleProgress(playerProgressValue_); - p_RecordingPlayerView->SetPlayerProgressBarValue(playerProgressValue_); - } - } - - void RecordingPresenter::UpdateRecordProcess() - { - if (view_ == nullptr) - { - return; - } - if (view_->GetRecordingViewScrollView(RECORDINGPLAYERVIEW)) - { - if (view_->GetRecordingViewScrollView(RECORDINGPLAYERVIEW)->IsVisible()) - { - SetCircleProgress(); - } - } - } - // 录音列表点击监听 - bool RecordListViewListener::OnClick(UIView &view, const ClickEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordListViewListener::OnClick"); - UNUSED(event); - RecordingListitemView *p_RecordingListitemView = static_cast(&view); - int index = p_RecordingListitemView->GetRecordingListIndex(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordListViewListener::OnClick index:%d", index); - if (index >= RecordingModel::GetInstance()->GetRecordingListNum()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordListViewListener::OnClick is no index"); - return false; - } - /* -------------------------------- 保存被点击录音下标 ------------------------------- */ - RecordingModel *p_RecordingModel = RecordingModel::GetInstance(); - if (p_RecordingModel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingModel GetInstance fail"); - return false; - } - p_RecordingModel->SetClickRecordingIndex(index); // 标记当前要播放录音的index_ - RecordingView *p_RecordingView = RecordingView::GetInstance(); - if (p_RecordingView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView GetInstance fail"); - return false; - } - p_RecordingView->ChangeView(RECORDINGLISTVIEW, RECORDINGPLAYERVIEW); // 切换到录音播放界面 - RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); - if (p_RecordingPlayerView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingPlayerView GetInstance fail"); - return false; - } - p_RecordingPlayerView->ResetComponentStatus(); - /* ------------------------ 播放录音 ------------------------ */ - if (p_RecordingModel->RecordingListOnClickPlay() != OHOS_SUCCESS) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_RecordingModel->RecordingListOnClickPlay fail!!"); - return false; - } - - return true; - } - - // 录音列表拖拽中监听 - bool RecordListViewListener::OnDrag(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordListViewListener::OnDrag"); - UNUSED(view); - UNUSED(event); - // if ((event.GetDeltaY() > X_DRAG_OFFSET) && (event.GetDeltaY() > (DOUBLES * MATH_ABS(event.GetDeltaX())))) // 如果滑动的为直线 - // { - // RecordListViewListener::X_DRAG_FLAG = true; - // } - return true; - } - - // 录音列表拖拽结束监听 - bool RecordListViewListener::OnDragEnd(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordListViewListener::OnDragEnd"); - std::string viewId = view.GetViewId(); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) - { - if (RecordingView::GetInstance() != nullptr && viewId == RECORDLISTSCROLLVIEW) - { - RecordingView::GetInstance()->ChangeView(RECORDINGLISTVIEW, RECORDINGVIEW); - // RecordListViewListener::X_DRAG_FLAG = false; - } - } - return true; - } - - void RecordingPlayerViewOnClickListener::PlayerButtonOnClick(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerViewOnClickListener PlayerButtonOnClick,%d",__LINE__); - - RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); - if (p_RecordingPlayerView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingPlayerView GetInstance fail"); - return; - } - - RecordingModel *p_RecordingModel = RecordingModel::GetInstance(); - if (p_RecordingModel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_RecordingModel GetInstance fail"); - return; - } - - int ret; - uint8_t state = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; - int32_t playerState; - - state = p_RecordingPlayerView->GetPlayerButtonState(); - playerState = p_RecordingModel->GetRecordingPlayerState(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonState = %d playerState = %d", state, playerState); - - if (state == UICheckBox::UICheckBoxState::SELECTED) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "state == SELECTED"); - - if (playerState == PlayerStates::PLAYER_PAUSED) - { - ret = p_RecordingModel->GetPlayerCtr()->Play(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Play, ret:%d", ret); - } - else - { - ret = p_RecordingModel->RecordingPlayerStat(); // 本地播放 - if (ret != 0) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerStat err, ret:%d", ret); - } - } - } - else - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "state == UNSELECTED"); - ret = p_RecordingModel->GetPlayerCtr()->Pause(); // 本地暂停 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Pause, ret:%d", ret); - } - } - - bool RecordingPlayerViewOnClickListener::OnClick(UIView &view, const ClickEvent &event) - { - RecordingView *p_RecordingView = RecordingView::GetInstance(); - if (p_RecordingView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView GetInstance fail"); - return false; - } - - RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); - if (p_RecordingPlayerView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingPlayerView GetInstance fail"); - return false; - } - - RecordingModel *p_RecordingModel = RecordingModel::GetInstance(); - if (p_RecordingModel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_RecordingModel GetInstance fail"); - return false; - } - - if (strcmp(view.GetViewId(), RECORD_PLAY_PAUSE_CHECKBOX_VIEWID) == 0) // 播放和暂停按钮被点击 - { - PlayerButtonOnClick(); - } - else if (strcmp(view.GetViewId(), RECORD_PLAY_PROVE_BUTTON_VIEWID) == 0) // 上一首按钮被点击 - { - p_RecordingModel->PreviousPlayout(); - p_RecordingPlayerView->ResetComponentStatus(); - } - else if (strcmp(view.GetViewId(), RECORD_PLAY_NEXT_BUTTON_VIEWID) == 0) // 下一首按钮被点击 - { - p_RecordingModel->NextPlayout(); - p_RecordingPlayerView->ResetComponentStatus(); - } - else if (strcmp(view.GetViewId(), RECORD_PLAY_DELETE_BUTTON_VIEWID) == 0) // 删除按钮被点击 - { - p_RecordingView->ChangeView(RECORDINGPLAYERVIEW, RECORDINGDELETEVIEW); - } - else if (strcmp(view.GetViewId(), RECORD_PLAY_VOLUME_BUTTON_VIEWID) == 0) // 音量按钮被点击 - { - p_RecordingView->ChangeView(RECORDINGPLAYERVIEW, RECORDINGVOLUMESETTINGVIEW); - } - return true; - } - - /* -------------------- RecordingPlayerInterruptListener -------------------- */ - /* - * @brief 音频中断类的构造函数 - */ - RecordingPlayerInterruptListener::RecordingPlayerInterruptListener() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::RecordingPlayerInterruptListener"); - } - - RecordingPlayerInterruptListener::~RecordingPlayerInterruptListener() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::~RecordingPlayerInterruptListener"); - } - /* - * 函数的调用通常发生在音频播放器或者任何使用音频资源的应用程序遇到外部中断事件时。 - * 这些中断事件可能包括电话来电、音乐播放器之间的音频焦点切换、系统声音(如闹钟)的播放,或者其他任何需要暂停当前活动以响应的情况。 - * @brief 处理录音播放器中断的方法,可能会根据传入的参数进行不同的操作。 - * @param type 中断的类型 - * @param hint 处理中断的额外提示 - */ - void RecordingPlayerInterruptListener::OnInterrupt(int32_t type, int32_t hint) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::OnInterrupt"); - if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_PAUSE) // 这表明当某个中断事件开始时,如果接收到暂停的提示,应当暂停播放器的播放。 - { - PausePlayer(); - } - - if (type == INTERRUPT_TYPE_END && hint == INTERRUPT_HINT_RESUME) // 这意味着一旦中断事件结束,并且有指示可以恢复播放的提示,就尝试恢复播放器的播放。 - { - ResumePlayer(); - } - - if (hint == INTERRUPT_HINT_STOP) // 只要提示为INTERRUPT_HINT_STOP,首先调用ResetFlag方法重置相关标志。 - { - ResetFlag(); - if (type == INTERRUPT_TYPE_BEGIN) // 这表示如果在中断开始时接收到停止的提示,应当停止播放器的播放并标记该事件。 - { - isBeginStopped_ = true; - StopPlayer(); - } - else if (type == INTERRUPT_TYPE_END) // 记录中断结束时播放器已被停止 - { - isEndStopped_ = true; - } - } - } - - /* - * @brief 获取与该监听器相关联的播放器。 - */ - std::shared_ptr RecordingPlayerInterruptListener::GetPlayer() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::GetPlayer"); - - return player_; - } - - /* - * @brief 设置录音播放器的所有者。 - */ - void RecordingPlayerInterruptListener::SetOwner(std::shared_ptr player) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::SetOwner"); - - player_ = player; - } - - /* - * @brief 设置播放器是否处于暂停状态 - */ - void RecordingPlayerInterruptListener::SetPaused(bool value) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::SetPaused"); - - isPaused_ = value; - } - - /* - * @brief 设置播放器是否已恢复播放状态。 - */ - void RecordingPlayerInterruptListener::SetResumed(bool value) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::SetResumed"); - isResumed_ = value; - } - - /* - * @brief 重置标志位 - */ - void RecordingPlayerInterruptListener::ResetFlag(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::RestFlag"); - - isPaused_ = false; - isDelayed_ = false; - isResumed_ = false; - isBeginStopped_ = false; - isEndStopped_ = false; - } - - /* - * @brief 返回播放器是否处于暂停状态的布尔值 - */ - bool RecordingPlayerInterruptListener::IsPaused() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::IsPaused"); - - return isPaused_; - } - - /* - * @brief 返回播放器是否处于延迟状态的布尔值。 - */ - bool RecordingPlayerInterruptListener::IsDelayed() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::IsDelayed"); - - return isDelayed_; - } - - /* - * @brief 返回播放器是否已恢复播放状态的布尔值 - */ - bool RecordingPlayerInterruptListener::IsResumed() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::IsDelayed"); - - return isResumed_; - } - - /* - * @brief 返回播放器是否已开始停止的布尔值。 - */ - bool RecordingPlayerInterruptListener::IsBeginStopped() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::IsBeginStopped"); - - return isBeginStopped_; - } - - /* - * @brief 返回播放器是否已结束停止的布尔值。 - */ - bool RecordingPlayerInterruptListener::IsEndStopped() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::IsEndStopped"); - - return isEndStopped_; - } - - static void PlayerPostGraphicEvent(void (*fun)(void)) - { - GraphicService::GetInstance()->PostGraphicEvent(*fun); - } - - static void Pause(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::PausePlayer] start"); - int32_t state; - int32_t ret; - std::shared_ptr PlayerIntrptListener = - OHOS::RecordingModel::GetInstance()->GetRecordingPlayerIntrptListener(); - if (PlayerIntrptListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener] PlayerIntrptListener is null"); - return; - } - - std::shared_ptr player = PlayerIntrptListener->GetPlayer(); - if (player.get() == nullptr) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::PausePlayer] player is nullptr"); - return; - } - - RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); - - player->GetPlayerState(state); - if (state == PLAYER_STARTED) - { - ret = player->Pause(); - if (ret == 0) - { - if (p_RecordingPlayerView == nullptr) - { - RecordingModel::GetInstance()->SetRecordingPlayButtonState(false); - } - else - { - p_RecordingPlayerView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); - } - PlayerIntrptListener->ResetFlag(); - PlayerIntrptListener->SetPaused(true); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::PausePlayer]"); - } - } - } - - static void Resume(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::ResumePlayer] start"); - int32_t state; - int32_t ret; - /* ----------------------------- 1.获取播放器中断监听器实例 ----------------------------- */ - std::shared_ptr PlayerIntrptListener = - OHOS::RecordingModel::GetInstance()->GetRecordingPlayerIntrptListener(); - if (PlayerIntrptListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener] PlayerIntrptListener is null"); - return; - } - /* ------------------------------- 2.获取播放器实例 ------------------------------- */ - std::shared_ptr player = PlayerIntrptListener->GetPlayer(); - if (player.get() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::ResumePlayer] player is nullptr"); - return; - } - - /* ------------------------------- 3.获取播放器视图实例 ------------------------------ */ - RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); - /* --------------------------------- 4.检查播放器状态 -------------------------------- */ - player->GetPlayerState(state); - if (state == PLAYER_PAUSED && PlayerIntrptListener->IsPaused() == true) - { - /* -------------------------------- 5.尝试恢复播放 -------------------------------- */ - ret = player->Play(); - if (ret == 0) - { - if (p_RecordingPlayerView == nullptr) - { - RecordingModel::GetInstance()->SetRecordingPlayButtonState(true); - } - else - { - p_RecordingPlayerView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); - } - /* ------------------------------- 6.重置中断监听器状态 ------------------------------ */ - PlayerIntrptListener->ResetFlag(); - PlayerIntrptListener->SetResumed(true); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::ResumePlayer]"); - } - } - } - - static void Stop(void) - { - RecordingModel::GetInstance()->RecordingPlayerStop(); - RecordingModel::GetInstance()->ClearActivateAudioInterrupt(); - } - - /* - * @brief 暂停播放器 - */ - void RecordingPlayerInterruptListener::PausePlayer(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::PausePlayer"); - - PlayerPostGraphicEvent(Pause); - } - - /* - * @brief 恢复播放器。 - */ - void RecordingPlayerInterruptListener::ResumePlayer(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::ResumePlayer"); - - PlayerPostGraphicEvent(Resume); - } - - /* - * @brief 停止播放器 - */ - void RecordingPlayerInterruptListener::StopPlayer(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::StopPlayer"); - - PlayerPostGraphicEvent(Stop); - } - /* ---------------------------------- 播放器回调 --------------------------------- */ - RecordingPlayerCallbackImpl::RecordingPlayerCallbackImpl() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::RecordingPlayerCallbackImpl"); - } - - RecordingPlayerCallbackImpl::~RecordingPlayerCallbackImpl() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::~RecordingPlayerCallbackImpl"); - } - - void RecordingPlayerCallbackImpl::OnPlaybackComplete() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::OnPlaybackComplete"); - /* --------------------------- 处实现代码用于处理文件播放完成的事件 --------------------------- */ - /* ----------------------- 用户在回调函数中不能有阻塞操作,也不能调用播放器接口 ----------------------- */ - // 此处实现代码用于处理文件播放完成的事件 - RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); - if (p_RecordingPlayerView != nullptr) - { - if (p_RecordingPlayerView->GetPlayerProgressBar() != nullptr) - { - p_RecordingPlayerView->GetPlayerProgressBar()->SetValue(100); // 100:进度100% - p_RecordingPlayerView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); - p_RecordingPlayerView->GetPlayerProgressBar()->Invalidate(); - } - } - usleep(20000); - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&OHOS::RecordingModel::RecordingPlayerReset, OHOS::RecordingModel::GetInstance())); - } - - void RecordingPlayerCallbackImpl::OnError(int32_t errorType, int32_t errorCode) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::OnError"); - /* ------------------------------ 此处实现代码用于处理错误事件 ------------------------------ */ - } - - void RecordingPlayerCallbackImpl::OnInfo(int type, int extra) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::OnInfo"); - /* ------------------------------- 此处实现代码用于处理普通事件 ------------------------------ */ - } - - void RecordingPlayerCallbackImpl::OnRewindToComplete() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::OnRewindToComplete"); - /* ---------------------------- 此处实现代码用于处理进度控制完成的事件 ---------------------------- */ - } +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-12-18 14:33:46 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp + */ + +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "graphic_math.h" +#include "string.h" +#include "record/include/RecordingPresenter.h" +#include +#include "custom_utils.h" +#include "record/include/RecordingListitemView.h" +#include +#include +#include "record/include/RecordingModel.h" +#include +#include +#include "NativeRegisterManager.h" + +namespace OHOS +{ + REGIST_MENU_PRO(VIEW_RECORD, RecordingView, RecordingPresenter, + PNG_APPLIST_RECORD_IMAGE_BIG, PNG_APPLIST_RECORD_IMAGE,PNG_APPLIST_RECORD_IMAGE, "录音", STR_RECORD); + + + // 当前Presenter属性实例化的内存指针 + static RecordingPresenter *g_pRecordPresenter = nullptr; + + RecordingPresenter::RecordingPresenter() + { + p_RecordingModel = RecordingModel::GetInstance(); + g_pRecordPresenter = this; + } + + RecordingPresenter::~RecordingPresenter() + { + p_RecordingModel->ClearRecordingPlayer(); + StopRecord(); + g_pRecordPresenter = nullptr; + } + + RecordingPresenter *RecordingPresenter::GetInstance() + { + return g_pRecordPresenter; + } + + void RecordingPresenter::OnStart() + { + // 初始化录音信息 + p_RecordingModel->InitRecordingListItem(); + p_RecordingModel->AudioInit(); + p_RecordingModel->SendCheckRecordingSpaceOutCmd(); //进入录音视图后发送指令查看录音空间是否已满 + // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); + } + void RecordingPresenter::OnResume(void) + { + RootView::GetInstance()->SetOnKeyActListener(this); + if(RecordingVolumeSettingView::GetInstance()) + { + if(RecordingVolumeSettingView::GetInstance()->GetSoundAndVibrationVolumeSettingView()) + { + if(RecordingVolumeSettingView::GetInstance()->GetSoundAndVibrationVolumeSettingView()->GetVolumeProcess()) + { + RecordingVolumeSettingView::GetInstance()->GetSoundAndVibrationVolumeSettingView()->GetVolumeProcess()->RequestFocus(); + } + } + } + } + + bool RecordingPresenter::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnDrag"); + UNUSED(view); + UNUSED(event); + return true; + } + + bool RecordingPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnDragEnd"); + + RecordingView *p_RecordingView = RecordingView::GetInstance(); + if (p_RecordingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView GetInstance fail"); + return false; + } + + UIScrollView *scrollView = static_cast(&view); + if (scrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView is nullptr"); + return false; + } + + auto currentView = p_RecordingView->GetCurrentViewType(scrollView); + + switch (event.GetDragDirection()) + { + case DragEvent::DIRECTION_LEFT_TO_RIGHT: // 右滑退出 + switch (currentView) + { + case RECORDINGVIEW: + OHOS::AbilityNavigation::Back(); + break; + case RECORDINGPLAYERVIEW: + p_RecordingView->ChangeView(RECORDINGPLAYERVIEW, RECORDINGLISTVIEW); // 录音播放视图(subView)->录音列表视图(subView) + break; + case RECORDINGDELETEVIEW: + p_RecordingView->ChangeView(RECORDINGDELETEVIEW, RECORDINGPLAYERVIEW); // 录音删除视图(subView)->录音播放视图(subView) + break; + case RECORDINGVOLUMESETTINGVIEW: + p_RecordingView->ChangeView(RECORDINGVOLUMESETTINGVIEW, RECORDINGPLAYERVIEW); // 声音设置视图(subView)->录音播放视图(subView) + break; + case RECORDINGEXCELIMIT: + p_RecordingView->ChangeView(RECORDINGEXCELIMIT, RECORDINGVIEW); + break; + default: + break; + } + break; + case DragEvent::DIRECTION_BOTTOM_TO_TOP: + if (currentView == RECORDINGVIEW) + { + p_RecordingView->ChangeView(RECORDINGVIEW, RECORDINGLISTVIEW); + } + break; + default: + break; + } + + return true; + } + + /// @brief 解析时间 + /// @param numericDateTime "19700101000641"; // 输入的数字形式日期时间 + /// @param formattedDateTime + /// @return + int RecordingPresenter::convertNumericDateTime(const char *numericDateTime, char *formattedDateTime) + { + if (strlen(numericDateTime) != 14) + { + return 0; // 如果输入的数字长度不为14,则转换失败 + } + + struct tm timeinfo = {0}; + if (strptime(numericDateTime, "%Y%m%d%H%M%S", &timeinfo) == NULL) + { + return 0; // 解析失败 + } + + // 格式化输出为上午/下午几点几分几秒 + // strftime(formattedDateTime, 80, "%p %I点%M分%S秒", &timeinfo); + strftime(formattedDateTime, 80, "%p%H%M%S", &timeinfo); + return 1; // 转换成功 + } + +#ifdef __cplusplus + extern "C" + { +#endif + int32_t AudioCaptureSample(int32_t argc, const char *argv[]); + +#ifdef __cplusplus + }; +#endif + + /*开始录音*/ + void RecordingPresenter::StartRecord(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingView StartRecord"); + char *args[6] = {0}; + const char *defaultArgs[6] = {"01", "mp3", "16000", "1", "16", nullptr}; // 默认参数数组 + for (int i = 0; i < 5; ++i) + { + args[i] = (char *)malloc(16); // 分配内存 + sprintf(args[i], "%s", defaultArgs[i]); // 设置默认参数值 + } + args[5] = (char *)malloc(100); // 分配内存 + /* -------------------------------------------------------------------------- */ + int num = p_RecordingModel->getMaxRecordingNumber(); + std::string recordfileNme; + // if (num < 9) + // { + // recordfileNme = "record_0" + std::to_string(num + 1); + // } + // else + // { + // recordfileNme = "record_" + std::to_string(num + 1); + // } + recordfileNme = std::to_string(num + 1); + p_RecordingModel->SetRecordFileName(recordfileNme); + sprintf(args[5], "%s%s.mp3", RecordingModel::GetInstance()->GetRecordDirectory(), recordfileNme.c_str()); + /* ---------------------------------- 开始录音 ---------------------------------- */ + uapi_save_runtime_log(RUNTIME_LOG_RECORD_START);//TOOD* + AudioCaptureSample(6, (const char **)args); + /* --------------------------------- 跳转到录音界面 -------------------------------- */ + view_->ChangeView(RECORDINGVIEW, RECORDGOINGVIEW); + p_RecordingModel->Recording_StartTimer(); + RecordGoingView::GetInstance()->GetRecordingDurationLabel()->SetText("00:00:00"); + /* ---------------------------------- 释放内存 ---------------------------------- */ + for (int i = 0; i < 6; ++i) + { + free(args[i]); + } + } + + // 停止录音 + void RecordingPresenter::StopRecord(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingView StopRecord"); + int32_t argc = 1; + uint8_t *argv = (uint8_t *)"stop"; + AudioCaptureSample(argc, (const char **)&argv); + uapi_save_runtime_log(RUNTIME_LOG_RECORD_STOP);//TOOD* + /* ---------------------------------- 停止定时器 --------------------------------- */ + p_RecordingModel->Recording_StopTimer(); + /* --------------------------------- 录音数量加1 --------------------------------- */ + p_RecordingModel->SetRecordingListNum(p_RecordingModel->GetRecordingListNum() + 1); + /* --------------------------------- 设置录音信息 --------------------------------- */ + // int num = p_RecordingModel->GetRecordingListNum(); // 保存录音的下标 + std::string recordingFileName = p_RecordingModel->GetRecordFileName(); // 录音文件名 + // std::string yyymmhhh_date = RecordingModel::GetInstance()->Getyyyymmhhh_date(); // 保存录音年月日时间 + // std::string TotalRecordDuration = RecordingModel::recordTempDuration; // 录音的总时长 + // RecordingInfo info = {0}; + // strncpy_s(info.recordingFileName, 32, recordingFileName.c_str(), recordingFileName.length()); + // strncpy_s(info.recordingDuration, 16, TotalRecordDuration.c_str(), TotalRecordDuration.length()); + // strncpy_s(info.recordingTime, 16, yyymmhhh_date.c_str(), yyymmhhh_date.length()); + p_RecordingModel->RecordDataWriteToFile(recordingFileName.c_str()); + RecordingModel::GetInstance()->InitRecordingListItem(); + + p_RecordingModel->SendCheckRecordingSpaceOutCmd(); //录音完后发送指令查看录音空间是否已满 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView StopRecord over!!"); + } + + //弹窗警告 + void RecordingPresenter::showWarning(void) + { + if(view_) + { + view_->ChangeView(RecordingModel::GetInstance()->GetCurView(), RECORDINGEXCELIMIT); + } + } + + bool RecordingPresenter::OnClick(UIView &view, const ClickEvent &event) + { + RecordingView *p_RecordingView = RecordingView::GetInstance(); + if (p_RecordingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView GetInstance fail"); + return false; + } + + if (strcmp(view.GetViewId(), RECORD_BUTTON) == 0) + { + int g_TotalUsedTime = RecordingModel::GetInstance()->GetUsedRecordingTime(); // 已用时间 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "g_TotalUsedTime:%d", g_TotalUsedTime); + if (p_RecordingModel->CheckRecordingTimeOut(g_TotalUsedTime) || p_RecordingModel->GetRecordingListNum() >= MAX_RECORDING_NUM || + p_RecordingModel->GetCheckRecordingSpaceOut()) + { + view_->ChangeView(RECORDINGVIEW, RECORDINGEXCELIMIT); + return true; + } + StartRecord(); + return true; + } + else if (strcmp(view.GetViewId(), RECORD_GOING_BUTTON_VIEWID) == 0) + { + StopRecord(); + view_->ChangeView(RECORDGOINGVIEW, RECORDINGVIEW); + return true; + } + else if (strcmp(view.GetViewId(), RECORD_DELETE_ON_BUTTON_VIEWID) == 0) // 若点击的是录音删除按钮 + { + int index = p_RecordingModel->GetClickRecordingIndex(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index = %d", index); + // std::string delete_path = RecordingModel::GetInstance()->GetRecordDirectory(); + // std::string delete_filename = p_RecordingModel->GetFileNames()[index] + ".mp3"; + // std::string fileName = delete_path + delete_filename; + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index = %d ", index); + // uapi_delete_files(fileName.c_str());//删除录音文件 + p_RecordingModel->UpdateRecordingInfo(); + + p_RecordingView->ChangeView(RECORDINGDELETEVIEW, RECORDINGLISTVIEW); + return true; + } + else if (strcmp(view.GetViewId(), RECORD_DELETE_OFF_BUTTON_VIEWID) == 0) + { + p_RecordingView->ChangeView(RECORDINGDELETEVIEW, RECORDINGPLAYERVIEW); + return true; + } + else if (strcmp(view.GetViewId(), RECORDINGNUMLIMITBUTTONVIEW) == 0) + { + p_RecordingView->ChangeView(RECORDINGEXCELIMIT, RECORDINGVIEW); + return true; + } + return true; + } + + bool RecordingPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; + } + + void RecordingPresenter::Notify() + { + //如果是在正在录音视图且正在录音视图为可见 + if(view_->GetRecordingViewScrollView(RECORDGOINGVIEW) && view_->GetRecordingViewScrollView(RECORDGOINGVIEW)->IsVisible()) + { + if(RecordGoingView::GetInstance()->GetRecordingDurationLabel()) + { + RecordGoingView::GetInstance()->GetRecordingDurationLabel()->SetText(RecordingModel::GetInstance()->DisplayRecordDuration()); + } + } + } + + + void RecordingPresenter::SetCircleProgress() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPresenter::SetCircleProgress"); + RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); + if (p_RecordingPlayerView == nullptr) + { + return; + } + UICircleProgress *playbackProgress = p_RecordingPlayerView->GetPlayerProgressBar(); + if (playbackProgress == nullptr) + { + return; + } + int32_t playerState; + playerState = p_RecordingModel->GetRecordingPlayerState(); + state_ = p_RecordingPlayerView->GetPlayerButtonState(); + if ((playerState != PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::SELECTED)) + { + p_RecordingPlayerView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); + } + else if ((playerState == PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::UNSELECTED)) + { + p_RecordingPlayerView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); + } + if (state_ == UICheckBox::UICheckBoxState::SELECTED) + { + p_RecordingModel->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_); + p_RecordingModel->GetDuration(playerMusicDuration_); + if (playerMusicDuration_ != 0) + { + playerProgressValue_ = (playerCurrentTime_ * 100) / playerMusicDuration_; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressValue_ %lld", playerProgressValue_); + } + else + { + playerProgressValue_ = 100; // 100: max progress value + } + p_RecordingModel->SetCircleProgress(playerProgressValue_); + p_RecordingPlayerView->SetPlayerProgressBarValue(playerProgressValue_); + } + } + + void RecordingPresenter::UpdateRecordProcess() + { + if (view_ == nullptr) + { + return; + } + if (view_->GetRecordingViewScrollView(RECORDINGPLAYERVIEW)) + { + if (view_->GetRecordingViewScrollView(RECORDINGPLAYERVIEW)->IsVisible()) + { + SetCircleProgress(); + } + } + } + // 录音列表点击监听 + bool RecordListViewListener::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordListViewListener::OnClick"); + UNUSED(event); + RecordingListitemView *p_RecordingListitemView = static_cast(&view); + int index = p_RecordingListitemView->GetRecordingListIndex(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordListViewListener::OnClick index:%d", index); + if (index >= RecordingModel::GetInstance()->GetRecordingListNum()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordListViewListener::OnClick is no index"); + return false; + } + /* -------------------------------- 保存被点击录音下标 ------------------------------- */ + RecordingModel *p_RecordingModel = RecordingModel::GetInstance(); + if (p_RecordingModel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingModel GetInstance fail"); + return false; + } + p_RecordingModel->SetClickRecordingIndex(index); // 标记当前要播放录音的index_ + RecordingView *p_RecordingView = RecordingView::GetInstance(); + if (p_RecordingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView GetInstance fail"); + return false; + } + p_RecordingView->ChangeView(RECORDINGLISTVIEW, RECORDINGPLAYERVIEW); // 切换到录音播放界面 + RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); + if (p_RecordingPlayerView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingPlayerView GetInstance fail"); + return false; + } + p_RecordingPlayerView->ResetComponentStatus(); + /* ------------------------ 播放录音 ------------------------ */ + if (p_RecordingModel->RecordingListOnClickPlay() != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_RecordingModel->RecordingListOnClickPlay fail!!"); + return false; + } + + return true; + } + + // 录音列表拖拽中监听 + bool RecordListViewListener::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordListViewListener::OnDrag"); + UNUSED(view); + UNUSED(event); + // if ((event.GetDeltaY() > X_DRAG_OFFSET) && (event.GetDeltaY() > (DOUBLES * MATH_ABS(event.GetDeltaX())))) // 如果滑动的为直线 + // { + // RecordListViewListener::X_DRAG_FLAG = true; + // } + return true; + } + + // 录音列表拖拽结束监听 + bool RecordListViewListener::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordListViewListener::OnDragEnd"); + std::string viewId = view.GetViewId(); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + if (RecordingView::GetInstance() != nullptr && viewId == RECORDLISTSCROLLVIEW) + { + RecordingView::GetInstance()->ChangeView(RECORDINGLISTVIEW, RECORDINGVIEW); + // RecordListViewListener::X_DRAG_FLAG = false; + } + } + return true; + } + + void RecordingPlayerViewOnClickListener::PlayerButtonOnClick(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerViewOnClickListener PlayerButtonOnClick,%d",__LINE__); + + RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); + if (p_RecordingPlayerView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingPlayerView GetInstance fail"); + return; + } + + RecordingModel *p_RecordingModel = RecordingModel::GetInstance(); + if (p_RecordingModel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_RecordingModel GetInstance fail"); + return; + } + + int ret; + uint8_t state = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; + int32_t playerState; + + state = p_RecordingPlayerView->GetPlayerButtonState(); + playerState = p_RecordingModel->GetRecordingPlayerState(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonState = %d playerState = %d", state, playerState); + + if (state == UICheckBox::UICheckBoxState::SELECTED) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "state == SELECTED"); + + if (playerState == PlayerStates::PLAYER_PAUSED) + { + ret = p_RecordingModel->GetPlayerCtr()->Play(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Play, ret:%d", ret); + } + else + { + ret = p_RecordingModel->RecordingPlayerStat(); // 本地播放 + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayerStat err, ret:%d", ret); + } + } + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "state == UNSELECTED"); + ret = p_RecordingModel->GetPlayerCtr()->Pause(); // 本地暂停 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Pause, ret:%d", ret); + } + } + + bool RecordingPlayerViewOnClickListener::OnClick(UIView &view, const ClickEvent &event) + { + RecordingView *p_RecordingView = RecordingView::GetInstance(); + if (p_RecordingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView GetInstance fail"); + return false; + } + + RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); + if (p_RecordingPlayerView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingPlayerView GetInstance fail"); + return false; + } + + RecordingModel *p_RecordingModel = RecordingModel::GetInstance(); + if (p_RecordingModel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_RecordingModel GetInstance fail"); + return false; + } + + if (strcmp(view.GetViewId(), RECORD_PLAY_PAUSE_CHECKBOX_VIEWID) == 0) // 播放和暂停按钮被点击 + { + PlayerButtonOnClick(); + } + else if (strcmp(view.GetViewId(), RECORD_PLAY_PROVE_BUTTON_VIEWID) == 0) // 上一首按钮被点击 + { + p_RecordingModel->PreviousPlayout(); + p_RecordingPlayerView->ResetComponentStatus(); + } + else if (strcmp(view.GetViewId(), RECORD_PLAY_NEXT_BUTTON_VIEWID) == 0) // 下一首按钮被点击 + { + p_RecordingModel->NextPlayout(); + p_RecordingPlayerView->ResetComponentStatus(); + } + else if (strcmp(view.GetViewId(), RECORD_PLAY_DELETE_BUTTON_VIEWID) == 0) // 删除按钮被点击 + { + p_RecordingView->ChangeView(RECORDINGPLAYERVIEW, RECORDINGDELETEVIEW); + } + else if (strcmp(view.GetViewId(), RECORD_PLAY_VOLUME_BUTTON_VIEWID) == 0) // 音量按钮被点击 + { + p_RecordingView->ChangeView(RECORDINGPLAYERVIEW, RECORDINGVOLUMESETTINGVIEW); + } + return true; + } + + /* -------------------- RecordingPlayerInterruptListener -------------------- */ + /* + * @brief 音频中断类的构造函数 + */ + RecordingPlayerInterruptListener::RecordingPlayerInterruptListener() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::RecordingPlayerInterruptListener"); + } + + RecordingPlayerInterruptListener::~RecordingPlayerInterruptListener() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::~RecordingPlayerInterruptListener"); + } + /* + * 函数的调用通常发生在音频播放器或者任何使用音频资源的应用程序遇到外部中断事件时。 + * 这些中断事件可能包括电话来电、音乐播放器之间的音频焦点切换、系统声音(如闹钟)的播放,或者其他任何需要暂停当前活动以响应的情况。 + * @brief 处理录音播放器中断的方法,可能会根据传入的参数进行不同的操作。 + * @param type 中断的类型 + * @param hint 处理中断的额外提示 + */ + void RecordingPlayerInterruptListener::OnInterrupt(int32_t type, int32_t hint) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::OnInterrupt"); + if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_PAUSE) // 这表明当某个中断事件开始时,如果接收到暂停的提示,应当暂停播放器的播放。 + { + PausePlayer(); + } + + if (type == INTERRUPT_TYPE_END && hint == INTERRUPT_HINT_RESUME) // 这意味着一旦中断事件结束,并且有指示可以恢复播放的提示,就尝试恢复播放器的播放。 + { + ResumePlayer(); + } + + if (hint == INTERRUPT_HINT_STOP) // 只要提示为INTERRUPT_HINT_STOP,首先调用ResetFlag方法重置相关标志。 + { + ResetFlag(); + if (type == INTERRUPT_TYPE_BEGIN) // 这表示如果在中断开始时接收到停止的提示,应当停止播放器的播放并标记该事件。 + { + isBeginStopped_ = true; + StopPlayer(); + } + else if (type == INTERRUPT_TYPE_END) // 记录中断结束时播放器已被停止 + { + isEndStopped_ = true; + } + } + } + + /* + * @brief 获取与该监听器相关联的播放器。 + */ + std::shared_ptr RecordingPlayerInterruptListener::GetPlayer() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::GetPlayer"); + + return player_; + } + + /* + * @brief 设置录音播放器的所有者。 + */ + void RecordingPlayerInterruptListener::SetOwner(std::shared_ptr player) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::SetOwner"); + + player_ = player; + } + + /* + * @brief 设置播放器是否处于暂停状态 + */ + void RecordingPlayerInterruptListener::SetPaused(bool value) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::SetPaused"); + + isPaused_ = value; + } + + /* + * @brief 设置播放器是否已恢复播放状态。 + */ + void RecordingPlayerInterruptListener::SetResumed(bool value) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::SetResumed"); + isResumed_ = value; + } + + /* + * @brief 重置标志位 + */ + void RecordingPlayerInterruptListener::ResetFlag(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::RestFlag"); + + isPaused_ = false; + isDelayed_ = false; + isResumed_ = false; + isBeginStopped_ = false; + isEndStopped_ = false; + } + + /* + * @brief 返回播放器是否处于暂停状态的布尔值 + */ + bool RecordingPlayerInterruptListener::IsPaused() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::IsPaused"); + + return isPaused_; + } + + /* + * @brief 返回播放器是否处于延迟状态的布尔值。 + */ + bool RecordingPlayerInterruptListener::IsDelayed() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::IsDelayed"); + + return isDelayed_; + } + + /* + * @brief 返回播放器是否已恢复播放状态的布尔值 + */ + bool RecordingPlayerInterruptListener::IsResumed() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::IsDelayed"); + + return isResumed_; + } + + /* + * @brief 返回播放器是否已开始停止的布尔值。 + */ + bool RecordingPlayerInterruptListener::IsBeginStopped() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::IsBeginStopped"); + + return isBeginStopped_; + } + + /* + * @brief 返回播放器是否已结束停止的布尔值。 + */ + bool RecordingPlayerInterruptListener::IsEndStopped() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::IsEndStopped"); + + return isEndStopped_; + } + + static void PlayerPostGraphicEvent(void (*fun)(void)) + { + GraphicService::GetInstance()->PostGraphicEvent(*fun); + } + + static void Pause(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::PausePlayer] start"); + int32_t state; + int32_t ret; + std::shared_ptr PlayerIntrptListener = + OHOS::RecordingModel::GetInstance()->GetRecordingPlayerIntrptListener(); + if (PlayerIntrptListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener] PlayerIntrptListener is null"); + return; + } + + std::shared_ptr player = PlayerIntrptListener->GetPlayer(); + if (player.get() == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::PausePlayer] player is nullptr"); + return; + } + + RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); + + player->GetPlayerState(state); + if (state == PLAYER_STARTED) + { + ret = player->Pause(); + if (ret == 0) + { + if (p_RecordingPlayerView == nullptr) + { + RecordingModel::GetInstance()->SetRecordingPlayButtonState(false); + } + else + { + p_RecordingPlayerView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); + } + PlayerIntrptListener->ResetFlag(); + PlayerIntrptListener->SetPaused(true); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::PausePlayer]"); + } + } + } + + static void Resume(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::ResumePlayer] start"); + int32_t state; + int32_t ret; + /* ----------------------------- 1.获取播放器中断监听器实例 ----------------------------- */ + std::shared_ptr PlayerIntrptListener = + OHOS::RecordingModel::GetInstance()->GetRecordingPlayerIntrptListener(); + if (PlayerIntrptListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener] PlayerIntrptListener is null"); + return; + } + /* ------------------------------- 2.获取播放器实例 ------------------------------- */ + std::shared_ptr player = PlayerIntrptListener->GetPlayer(); + if (player.get() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::ResumePlayer] player is nullptr"); + return; + } + + /* ------------------------------- 3.获取播放器视图实例 ------------------------------ */ + RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); + /* --------------------------------- 4.检查播放器状态 -------------------------------- */ + player->GetPlayerState(state); + if (state == PLAYER_PAUSED && PlayerIntrptListener->IsPaused() == true) + { + /* -------------------------------- 5.尝试恢复播放 -------------------------------- */ + ret = player->Play(); + if (ret == 0) + { + if (p_RecordingPlayerView == nullptr) + { + RecordingModel::GetInstance()->SetRecordingPlayButtonState(true); + } + else + { + p_RecordingPlayerView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); + } + /* ------------------------------- 6.重置中断监听器状态 ------------------------------ */ + PlayerIntrptListener->ResetFlag(); + PlayerIntrptListener->SetResumed(true); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RecordingPlayerInterruptListener::ResumePlayer]"); + } + } + } + + static void Stop(void) + { + RecordingModel::GetInstance()->RecordingPlayerStop(); + RecordingModel::GetInstance()->ClearActivateAudioInterrupt(); + } + + /* + * @brief 暂停播放器 + */ + void RecordingPlayerInterruptListener::PausePlayer(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::PausePlayer"); + + PlayerPostGraphicEvent(Pause); + } + + /* + * @brief 恢复播放器。 + */ + void RecordingPlayerInterruptListener::ResumePlayer(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::ResumePlayer"); + + PlayerPostGraphicEvent(Resume); + } + + /* + * @brief 停止播放器 + */ + void RecordingPlayerInterruptListener::StopPlayer(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerInterruptListener::StopPlayer"); + + PlayerPostGraphicEvent(Stop); + } + /* ---------------------------------- 播放器回调 --------------------------------- */ + RecordingPlayerCallbackImpl::RecordingPlayerCallbackImpl() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::RecordingPlayerCallbackImpl"); + } + + RecordingPlayerCallbackImpl::~RecordingPlayerCallbackImpl() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::~RecordingPlayerCallbackImpl"); + } + + void RecordingPlayerCallbackImpl::OnPlaybackComplete() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::OnPlaybackComplete"); + /* --------------------------- 处实现代码用于处理文件播放完成的事件 --------------------------- */ + /* ----------------------- 用户在回调函数中不能有阻塞操作,也不能调用播放器接口 ----------------------- */ + // 此处实现代码用于处理文件播放完成的事件 + RecordingPlayerView *p_RecordingPlayerView = RecordingPlayerView::GetInstance(); + if (p_RecordingPlayerView != nullptr) + { + if (p_RecordingPlayerView->GetPlayerProgressBar() != nullptr) + { + p_RecordingPlayerView->GetPlayerProgressBar()->SetValue(100); // 100:进度100% + p_RecordingPlayerView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); + p_RecordingPlayerView->GetPlayerProgressBar()->Invalidate(); + } + } + usleep(20000); + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(&OHOS::RecordingModel::RecordingPlayerReset, OHOS::RecordingModel::GetInstance())); + } + + void RecordingPlayerCallbackImpl::OnError(int32_t errorType, int32_t errorCode) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::OnError"); + /* ------------------------------ 此处实现代码用于处理错误事件 ------------------------------ */ + } + + void RecordingPlayerCallbackImpl::OnInfo(int type, int extra) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::OnInfo"); + /* ------------------------------- 此处实现代码用于处理普通事件 ------------------------------ */ + } + + void RecordingPlayerCallbackImpl::OnRewindToComplete() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordingPlayerCallbackImpl::OnRewindToComplete"); + /* ---------------------------- 此处实现代码用于处理进度控制完成的事件 ---------------------------- */ + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/respiratorytraining/src/RespiratoryTrainingPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/respiratorytraining/src/RespiratoryTrainingPresenter.cpp index 47123a52d..bd1d378c5 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/respiratorytraining/src/RespiratoryTrainingPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/respiratorytraining/src/RespiratoryTrainingPresenter.cpp @@ -8,6 +8,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "respiratorytraining/include/RespiratoryTrainingPresenter.h" #include "respiratorytraining/include/RespiratoryTrainingView.h" #include "common/key_code.h" @@ -77,7 +78,7 @@ namespace OHOS std::string viewId = view.GetViewId(); if (viewId == RTCLABELBUTTON) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); return true; } std::map viewMap = { @@ -126,7 +127,7 @@ namespace OHOS } else { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } RespiratoryTrainingPresenter::X_DRAG_FLAG = false; } @@ -142,7 +143,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/safemodemanager/src/SafeModeManagerPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/safemodemanager/src/SafeModeManagerPresenter.cpp index c7b91c640..f85d82d7d 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/safemodemanager/src/SafeModeManagerPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/safemodemanager/src/SafeModeManagerPresenter.cpp @@ -2,6 +2,7 @@ #include "AppViewIDs.h" #include "key/include/KeyInputListener.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include "components/ui_label_ext.h" #include "custom_utils.h" @@ -270,7 +271,7 @@ bool SafeModeManagerPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - // NativeAbility::GetInstance().Back(); + // OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/saveele/src/SaveElePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/saveele/src/SaveElePresenter.cpp index cede84e5f..66fb26070 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/saveele/src/SaveElePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/saveele/src/SaveElePresenter.cpp @@ -1,85 +1,86 @@ - -#include "AppViewIDs.h" -#include "key/include/KeyInputListener.h" -#include "NativeAbility.h" -#include "common/key_code.h" -#include "components/ui_label_ext.h" -#include "custom_utils.h" -#include "ui_resource_string.h" - -#include "gfx_utils/mem_check.h" -#include "saveele/include/SaveElePresenter.h" -#include "vibrator_service.h" -#include "NativeRegisterManager.h" - -namespace OHOS -{ - REGIST_SLICE(VIEW_SAVEELE, SaveEleView, SaveElePresenter); - -// 当前Presenter属性实例化的内存指针 -static SaveElePresenter *g_pSaveElePresenter = nullptr; - -SaveElePresenter::SaveElePresenter() { -#ifdef MEM_CHECK - MemCheck::GetInstance()->EnableLeakCheck(true); -#endif - g_pSaveElePresenter = this; -} - -SaveElePresenter::~SaveElePresenter() { -#ifdef MEM_CHECK - MemCheck::GetInstance()->EnableLeakCheck(false); -#endif - g_pSaveElePresenter = nullptr; -} - -SaveElePresenter *SaveElePresenter::GetInstance() { - - return g_pSaveElePresenter; -} - -void SaveElePresenter::OnStart() { Presenter::OnStart(); } - - -void SaveElePresenter::OnResume() { - RootView::GetInstance()->SetOnKeyActListener(this); -} - -bool SaveElePresenter::OnDrag(UIView &view, const DragEvent &event) { - - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 20) && - (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().Back(); - } - UNUSED(view); - return true; -} - -bool SaveElePresenter::OnClick(UIView &view, const ClickEvent &event) { - if (strcmp(view.GetViewId(), SAVEBUTTONNO) == 0) { - NativeAbility::GetInstance().Back(); - } - if (strcmp(view.GetViewId(), SAVEBUTTONOK) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_SAVEBAT); - } - return true; -} -bool SaveElePresenter::OnKeyAct(UIView &view, const KeyEvent &event) { - unsigned short keyID = event.GetKeyId(); - unsigned short keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && - keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); - } - return true; -} - -bool SaveElePresenter::OnRotateEnd(UIView &view, const RotateEvent &event) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "VolumeSliderEventListener::OnRotateEnd"); -// custom_VibratorFunc_int(0); - return true; -} + +#include "AppViewIDs.h" +#include "key/include/KeyInputListener.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "common/key_code.h" +#include "components/ui_label_ext.h" +#include "custom_utils.h" +#include "ui_resource_string.h" + +#include "gfx_utils/mem_check.h" +#include "saveele/include/SaveElePresenter.h" +#include "vibrator_service.h" +#include "NativeRegisterManager.h" + +namespace OHOS +{ + REGIST_SLICE(VIEW_SAVEELE, SaveEleView, SaveElePresenter); + +// 当前Presenter属性实例化的内存指针 +static SaveElePresenter *g_pSaveElePresenter = nullptr; + +SaveElePresenter::SaveElePresenter() { +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif + g_pSaveElePresenter = this; +} + +SaveElePresenter::~SaveElePresenter() { +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif + g_pSaveElePresenter = nullptr; +} + +SaveElePresenter *SaveElePresenter::GetInstance() { + + return g_pSaveElePresenter; +} + +void SaveElePresenter::OnStart() { Presenter::OnStart(); } + + +void SaveElePresenter::OnResume() { + RootView::GetInstance()->SetOnKeyActListener(this); +} + +bool SaveElePresenter::OnDrag(UIView &view, const DragEvent &event) { + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && + (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { + OHOS::AbilityNavigation::Back(); + } + UNUSED(view); + return true; +} + +bool SaveElePresenter::OnClick(UIView &view, const ClickEvent &event) { + if (strcmp(view.GetViewId(), SAVEBUTTONNO) == 0) { + OHOS::AbilityNavigation::Back(); + } + if (strcmp(view.GetViewId(), SAVEBUTTONOK) == 0) { + NativeAbility::GetInstance().ChangeSlice(VIEW_SAVEBAT); + } + return true; +} +bool SaveElePresenter::OnKeyAct(UIView &view, const KeyEvent &event) { + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && + keyState == 1 && uapi_get_screen_state() == 0) { + OHOS::AbilityNavigation::Back(); + } + return true; +} + +bool SaveElePresenter::OnRotateEnd(UIView &view, const RotateEvent &event) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "VolumeSliderEventListener::OnRotateEnd"); +// custom_VibratorFunc_int(0); + return true; +} } // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/schedule/src/SchedulePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/schedule/src/SchedulePresenter.cpp index 1cbb07261..530b5f015 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/schedule/src/SchedulePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/schedule/src/SchedulePresenter.cpp @@ -1,142 +1,143 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-20 15:11:17 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-12-13 16:28:48 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/SchedulePresenter.cpp - */ -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "common/key_code.h" -#include -#include "UiConfig.h" -#include "schedule/include/SchedulePresenter.h" -#include "schedule/include/ScheduleView.h" -#include "NativeRegisterManager.h" -namespace OHOS -{ - REGIST_MENU_PRO(VIEW_SCHEDULE, ScheduleView, SchedulePresenter, - PNG_APPLIST_SCHEDULE_IMAGE_BIG, PNG_APPLIST_SCHEDULE_IMAGE,PNG_APPLIST_SCHEDULE_IMAGE, "日程", STR_SCHEDULE); - - // 当前Presenter属性实例化的内存指针 - static SchedulePresenter * p_SchedulePresenterInstance = nullptr; - - SchedulePresenter::SchedulePresenter() - { - ScheduleModel_ = &ScheduleModel::GetInstance(); - p_SchedulePresenterInstance = this; - } - - SchedulePresenter::~SchedulePresenter() - { - p_SchedulePresenterInstance = nullptr; - } - - SchedulePresenter *SchedulePresenter::GetInstance() - { - return p_SchedulePresenterInstance; - } - - // 启动时执行的逻辑 - void SchedulePresenter::OnStart() - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SchedulePresenter::OnStart"); - } - - void SchedulePresenter::OnResume() - { - RootView::GetInstance()->SetOnKeyActListener(this); - } - - bool SchedulePresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(event); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:OnClick", __LINE__); - - // if (nullptr == &view) - // { - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:OnClick", __LINE__); - // return false; - // } - - if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_ContentDeleteButton_)) - { - view_->DisplayDeleteScreen(); - return true; - } - if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_ContentCloseButton_)) - { - view_->DisplayDataOrNoScreen(); - return true; - } - - if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_DeleteCancelButton_)) - { - view_->DisplayContentScreen(); - return true; - } - if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_DeleteOKButton_)) - { - ScheduleModel_->ScheduleOriginalDataSetByUI(view_->ContentScreenItemIndexGet() / 2); - view_->ItemListContentUpdate(); - view_->DisplayDataOrNoScreen(); - view_->ItemListScrollByUpdate(); - return true; - } - - ScheduleListItem * item = static_cast(&view); - view_->ContentScreenItemIndexSet(item->GetViewIndex()); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:OnClick,index:%d", __LINE__,item->GetViewIndex()); - view_->DisplayContentScreen(); - - return true; - } - - bool SchedulePresenter::OnDrag(UIView &view, const DragEvent &event) - { - UNUSED(view); - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SchedulePresenter::OnDrag"); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - SchedulePresenter::X_DRAG_FLAG = true; - } - return true; - } - - bool SchedulePresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - UNUSED(view); - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SchedulePresenter::OnDragEnd"); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SchedulePresenter::X_DRAG_FLAG) - { - if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_ContentGroup_)) - { - view_->DisplayDataOrNoScreen(); - return true; - } - if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_DeleteGroup_)) - { - view_->DisplayContentScreen(); - return true; - } - - NativeAbility::GetInstance().Back(); - SchedulePresenter::X_DRAG_FLAG = false; - } - return true; - } - - bool SchedulePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 - { - UNUSED(view); - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SchedulePresenter::OnKeyAct"); - uint16_t keyID = event.GetKeyId(); - uint16_t keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; - } +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-06-20 15:11:17 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-12-13 16:28:48 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/SchedulePresenter.cpp + */ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "common/key_code.h" +#include +#include "UiConfig.h" +#include "schedule/include/SchedulePresenter.h" +#include "schedule/include/ScheduleView.h" +#include "NativeRegisterManager.h" +namespace OHOS +{ + REGIST_MENU_PRO(VIEW_SCHEDULE, ScheduleView, SchedulePresenter, + PNG_APPLIST_SCHEDULE_IMAGE_BIG, PNG_APPLIST_SCHEDULE_IMAGE,PNG_APPLIST_SCHEDULE_IMAGE, "日程", STR_SCHEDULE); + + // 当前Presenter属性实例化的内存指针 + static SchedulePresenter * p_SchedulePresenterInstance = nullptr; + + SchedulePresenter::SchedulePresenter() + { + ScheduleModel_ = &ScheduleModel::GetInstance(); + p_SchedulePresenterInstance = this; + } + + SchedulePresenter::~SchedulePresenter() + { + p_SchedulePresenterInstance = nullptr; + } + + SchedulePresenter *SchedulePresenter::GetInstance() + { + return p_SchedulePresenterInstance; + } + + // 启动时执行的逻辑 + void SchedulePresenter::OnStart() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SchedulePresenter::OnStart"); + } + + void SchedulePresenter::OnResume() + { + RootView::GetInstance()->SetOnKeyActListener(this); + } + + bool SchedulePresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:OnClick", __LINE__); + + // if (nullptr == &view) + // { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:OnClick", __LINE__); + // return false; + // } + + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_ContentDeleteButton_)) + { + view_->DisplayDeleteScreen(); + return true; + } + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_ContentCloseButton_)) + { + view_->DisplayDataOrNoScreen(); + return true; + } + + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_DeleteCancelButton_)) + { + view_->DisplayContentScreen(); + return true; + } + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_DeleteOKButton_)) + { + ScheduleModel_->ScheduleOriginalDataSetByUI(view_->ContentScreenItemIndexGet() / 2); + view_->ItemListContentUpdate(); + view_->DisplayDataOrNoScreen(); + view_->ItemListScrollByUpdate(); + return true; + } + + ScheduleListItem * item = static_cast(&view); + view_->ContentScreenItemIndexSet(item->GetViewIndex()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:OnClick,index:%d", __LINE__,item->GetViewIndex()); + view_->DisplayContentScreen(); + + return true; + } + + bool SchedulePresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SchedulePresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + SchedulePresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool SchedulePresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SchedulePresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SchedulePresenter::X_DRAG_FLAG) + { + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_ContentGroup_)) + { + view_->DisplayDataOrNoScreen(); + return true; + } + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_DeleteGroup_)) + { + view_->DisplayContentScreen(); + return true; + } + + OHOS::AbilityNavigation::Back(); + SchedulePresenter::X_DRAG_FLAG = false; + } + return true; + } + + bool SchedulePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SchedulePresenter::OnKeyAct"); + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_aod/src/SetAodDialPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_aod/src/SetAodDialPresenter.cpp index 9eff7956c..62031bdf1 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_aod/src/SetAodDialPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_aod/src/SetAodDialPresenter.cpp @@ -1,5 +1,6 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "set_aod/include/SetAodDialPresenter.h" #include "set_aod/include/SetAodDialView.h" #include "common/key_code.h" @@ -97,7 +98,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); X_DRAG_FLAG = false; } return true; @@ -112,7 +113,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp index 637580dc1..d12ccdfad 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp @@ -25,6 +25,7 @@ #endif #include "NativeRegisterManager.h" +#include "AbilityNavigationApi.h" namespace OHOS { @@ -63,7 +64,7 @@ namespace OHOS model->SaveDialSetting(pageIndex); /*切换当前表盘*/ NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - NativeAbility::GetInstance().ClearSliceIdStack(); // 清空Slice栈 + OHOS::AbilityNavigation::ClearSliceIdStack(); // 清空Slice栈 } bool SetDialPresenter::OnClick(UIView &view, const ClickEvent &event) @@ -131,7 +132,7 @@ namespace OHOS if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { // 回退 - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_dial_style/src/SetDialStylePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_dial_style/src/SetDialStylePresenter.cpp index 997cdf289..6da132c9c 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_dial_style/src/SetDialStylePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_dial_style/src/SetDialStylePresenter.cpp @@ -6,6 +6,7 @@ #include "key/include/KeyInputListener.h" #include "custom_utils.h" #include "common/key_code.h" +#include "AbilityNavigationApi.h" namespace OHOS { @@ -59,7 +60,7 @@ namespace OHOS if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { // 回退 - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp index 80ea2a70b..020b8ad1d 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp @@ -9,6 +9,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "NativeRegisterManager.h" @@ -40,7 +41,7 @@ bool SetTimeFormatPresenter::OnDrag(UIView &view, const DragEvent &event) { if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -52,7 +53,7 @@ bool SetTimeFormatPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { // 回退 - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/settings/src/SettingPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/settings/src/SettingPresenter.cpp index 57f445f03..d9ad7931b 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/settings/src/SettingPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/settings/src/SettingPresenter.cpp @@ -18,6 +18,7 @@ #include "common/key_code.h" #include #include "NativeRegisterManager.h" +#include "AbilityNavigationApi.h" namespace OHOS { @@ -112,7 +113,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); X_DRAG_FLAG = false; } return true; @@ -126,7 +127,7 @@ namespace OHOS uint16 keyState = event.GetState(); if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -140,7 +141,7 @@ namespace OHOS AppViewId viewId = settingItemView->GetViewId(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d\n", viewId); - NativeAbility::GetInstance().EnterSlice(viewId); // Test + OHOS::AbilityNavigation::EnterSlice(viewId); // Test return true; } } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/sleep/src/SleepControlPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/sleep/src/SleepControlPresenter.cpp index a74562438..049c93aa5 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/sleep/src/SleepControlPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/sleep/src/SleepControlPresenter.cpp @@ -6,6 +6,7 @@ */ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "sleep/include/SleepControlPresenter.h" #include "common/key_code.h" #include "common/key_code.h" @@ -73,7 +74,7 @@ namespace OHOS UNUSED(view); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SleepControlPresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -96,7 +97,7 @@ namespace OHOS // 如果是power键就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/sleepmode/src/SleepModePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/sleepmode/src/SleepModePresenter.cpp index 968a9075e..6ac74d384 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/sleepmode/src/SleepModePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/sleepmode/src/SleepModePresenter.cpp @@ -1,6 +1,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "UiConfig.h" #include "sleepmode/include/SleepModePresenter.h" #include "common/key_code.h" @@ -56,7 +57,7 @@ namespace OHOS UNUSED(event); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SleepModePresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); SleepModePresenter::X_DRAG_FLAG = false; } return true; @@ -71,7 +72,7 @@ namespace OHOS SleepModeModel_->SetSleepModeEnabled(); } - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); return true; } @@ -84,7 +85,7 @@ namespace OHOS // 如果是power键就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/CallVolumePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/CallVolumePresenter.cpp index d330488ff..5dad4eaf6 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/CallVolumePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/CallVolumePresenter.cpp @@ -1,110 +1,111 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-03-30 09:14:38 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-19 18:58:32 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp - */ -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "NativeAbility.h" -#include "graphic_math.h" -#include "soundandvibration/include/CallVolumePresenter.h" -#include "common/key_code.h" -#include "custom_utils.h" -#include -#include -#include "NativeRegisterManager.h" -// 系统音量 -namespace OHOS -{ - REGIST_SLICE(VIEW_CALL_VOLUME, CallVolumeView, CallVolumePresenter); - // 当前Presenter属性实例化的内存指针 - static CallVolumePresenter *g_pCallVolumePresenter = nullptr; - - CallVolumePresenter::CallVolumePresenter() - { - - g_pCallVolumePresenter = this; - } - - CallVolumePresenter::~CallVolumePresenter() - { - - g_pCallVolumePresenter = nullptr; - } - - CallVolumePresenter *CallVolumePresenter::GetInstance() - { - - return g_pCallVolumePresenter; - } - - void CallVolumePresenter::OnStart() - { - - } - - void CallVolumePresenter::OnPause(void) - { - - Presenter::OnPause(); - } - - void CallVolumePresenter::OnResume(void) - { - - RootView::GetInstance()->SetOnKeyActListener(this); - } - - void CallVolumePresenter::OnStop(void) - { - - } - - bool CallVolumePresenter::OnDrag(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CallVolumePresenter::OnDrag"); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - CallVolumePresenter::X_DRAG_FLAG = true; - } - return true; - } - - bool CallVolumePresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CallVolumePresenter::OnDragEnd"); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && CallVolumePresenter::X_DRAG_FLAG) - { - NativeAbility::GetInstance().Back(); - CallVolumePresenter::X_DRAG_FLAG = false; - } - return true; - } - - bool CallVolumePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CallVolumePresenter::OnKeyAct"); - uint16 keyID = event.GetKeyId(); - uint16 keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; - } - - bool CallVolumePresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(view); - UNUSED(event); - return true; - } - -} +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-19 18:58:32 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp + */ +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "graphic_math.h" +#include "soundandvibration/include/CallVolumePresenter.h" +#include "common/key_code.h" +#include "custom_utils.h" +#include +#include +#include "NativeRegisterManager.h" +// 系统音量 +namespace OHOS +{ + REGIST_SLICE(VIEW_CALL_VOLUME, CallVolumeView, CallVolumePresenter); + // 当前Presenter属性实例化的内存指针 + static CallVolumePresenter *g_pCallVolumePresenter = nullptr; + + CallVolumePresenter::CallVolumePresenter() + { + + g_pCallVolumePresenter = this; + } + + CallVolumePresenter::~CallVolumePresenter() + { + + g_pCallVolumePresenter = nullptr; + } + + CallVolumePresenter *CallVolumePresenter::GetInstance() + { + + return g_pCallVolumePresenter; + } + + void CallVolumePresenter::OnStart() + { + + } + + void CallVolumePresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void CallVolumePresenter::OnResume(void) + { + + RootView::GetInstance()->SetOnKeyActListener(this); + } + + void CallVolumePresenter::OnStop(void) + { + + } + + bool CallVolumePresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CallVolumePresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + CallVolumePresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool CallVolumePresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CallVolumePresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && CallVolumePresenter::X_DRAG_FLAG) + { + OHOS::AbilityNavigation::Back(); + CallVolumePresenter::X_DRAG_FLAG = false; + } + return true; + } + + bool CallVolumePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CallVolumePresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; + } + + bool CallVolumePresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } + +} diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp index b449c7a9a..84b6a920a 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp @@ -1,175 +1,176 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-02-19 10:39:11 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-05 14:42:21 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp - */ - -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "NativeAbility.h" -#include "graphic_math.h" -#include "string.h" -#include "soundandvibration/include/SoundAndVibrationPresenter.h" -#include "common/key_code.h" -#include "custom_utils.h" -#include "ConfigModel.h" -#include -#include "soundandvibration/include/SoundAndVibrationVolumeSettingC.h" -#include "UiConfig.h" -#include "vibrator_service.h" -#include "NativeRegisterManager.h" - -namespace OHOS -{ - REGIST_SLICE(VIEW_SOUND_VIBRATION, SoundAndVibrationView, SoundAndVibrationPresenter); - // 当前Presenter属性实例化的内存指针 - static SoundAndVibrationPresenter *g_pSoundAndVibrationPresenter = nullptr; - - SoundAndVibrationPresenter::SoundAndVibrationPresenter() - { - g_pSoundAndVibrationPresenter = this; - } - - SoundAndVibrationPresenter::~SoundAndVibrationPresenter() - { - g_pSoundAndVibrationPresenter = nullptr; - } - - SoundAndVibrationPresenter *SoundAndVibrationPresenter::GetInstance() - { - return g_pSoundAndVibrationPresenter; - } - - void SoundAndVibrationPresenter::OnStart() - { - } - - void SoundAndVibrationPresenter::OnPause(void) - { - Presenter::OnPause(); - } - - void SoundAndVibrationPresenter::OnResume(void) - { - if (view_ == nullptr) - { - return; - } - RootView::GetInstance()->SetOnKeyActListener(this); - } - - void SoundAndVibrationPresenter::OnStop(void) - { - } - - bool SoundAndVibrationPresenter::OnDrag(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RespiratoryTrainingPresenter::OnDrag"); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - SoundAndVibrationPresenter::X_DRAG_FLAG = true; - } - return true; - } - - bool SoundAndVibrationPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnDragEnd"); - std::string viewId = view.GetViewId(); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SoundAndVibrationPresenter::X_DRAG_FLAG) - { - if (viewId == VIBRATION_MODE_VIEWID) // 如果在震动提醒子视图 - { - view_->GetVibrationModeView()->UpdatePickerSelectIndex(); - SoundAndVibrationView::GetInstance()->ChangeView(VIBRATIONMODEVIEW, SOUNDANDVIBRATIONVIEW); - } - else - { - NativeAbility::GetInstance().Back(); - } - SoundAndVibrationPresenter::X_DRAG_FLAG = false; - } - - return true; - } - - bool SoundAndVibrationPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnKeyAct"); - uint16 keyID = event.GetKeyId(); - uint16 keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; - } - - bool SoundAndVibrationPresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(event); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnKeyAct"); - if (strcmp(view.GetViewId(), SYSTEM_VOLUME_BUTTON) == 0) - { - NativeAbility::GetInstance().EnterSlice(VIEW_SYSTEM_VOLUME); - } - else if (strcmp(view.GetViewId(), CALL_VOLUME_BUTTON) == 0) - { - NativeAbility::GetInstance().EnterSlice(VIEW_CALL_VOLUME); - } - else if (strcmp(view.GetViewId(), VIBRATION_REMINDER_BUTTON) == 0) - { - view_->ChangeView(SOUNDANDVIBRATIONVIEW, VIBRATIONMODEVIEW); - } - else if ((view_->GetVibrationModeView() != nullptr) && (&view == view_->GetVibrationModeView()->GetVibrationModeLabelButton())) - { - int VibrationMode = view_->GetVibrationModeView()->GetVibrationModePicker()->GetSelected(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VibrationMode = %d", VibrationMode); - SoundAndVibrationModel::GetInstance()->SetVibrationReminderToggleButtonStaus(VibrationMode); - custom_VibratorFunc_int(0); - custom_VibratorFunc_int(0); - view_->ChangeView(VIBRATIONMODEVIEW, SOUNDANDVIBRATIONVIEW); - } - return true; - } - - bool SoundAndVibrationPresenter::OnChange(UICheckBox::UICheckBoxState state) - { - SoundAndVibrationModel *p_SoundAndVibrationModel = SoundAndVibrationModel::GetInstance(); - switch (state) - { - case UICheckBox::SELECTED: - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SilentMode is enable!"); - p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(true); - break; - case UICheckBox::UNSELECTED: - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SilentMode is disable!"); - p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(false); - break; - default: - break; - } - return true; - } - - bool SoundAndVibrationPresenter::OnRotate(UIView &view, const RotateEvent &event) - { - UNUSED(view); - UNUSED(event); - return true; - } - - bool SoundAndVibrationPresenter::OnRotateEnd(UIView &view, const RotateEvent &event) - { - UNUSED(view); - UNUSED(event); - return true; - } +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-02-19 10:39:11 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-11-05 14:42:21 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp + */ + +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "graphic_math.h" +#include "string.h" +#include "soundandvibration/include/SoundAndVibrationPresenter.h" +#include "common/key_code.h" +#include "custom_utils.h" +#include "ConfigModel.h" +#include +#include "soundandvibration/include/SoundAndVibrationVolumeSettingC.h" +#include "UiConfig.h" +#include "vibrator_service.h" +#include "NativeRegisterManager.h" + +namespace OHOS +{ + REGIST_SLICE(VIEW_SOUND_VIBRATION, SoundAndVibrationView, SoundAndVibrationPresenter); + // 当前Presenter属性实例化的内存指针 + static SoundAndVibrationPresenter *g_pSoundAndVibrationPresenter = nullptr; + + SoundAndVibrationPresenter::SoundAndVibrationPresenter() + { + g_pSoundAndVibrationPresenter = this; + } + + SoundAndVibrationPresenter::~SoundAndVibrationPresenter() + { + g_pSoundAndVibrationPresenter = nullptr; + } + + SoundAndVibrationPresenter *SoundAndVibrationPresenter::GetInstance() + { + return g_pSoundAndVibrationPresenter; + } + + void SoundAndVibrationPresenter::OnStart() + { + } + + void SoundAndVibrationPresenter::OnPause(void) + { + Presenter::OnPause(); + } + + void SoundAndVibrationPresenter::OnResume(void) + { + if (view_ == nullptr) + { + return; + } + RootView::GetInstance()->SetOnKeyActListener(this); + } + + void SoundAndVibrationPresenter::OnStop(void) + { + } + + bool SoundAndVibrationPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RespiratoryTrainingPresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + SoundAndVibrationPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool SoundAndVibrationPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnDragEnd"); + std::string viewId = view.GetViewId(); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SoundAndVibrationPresenter::X_DRAG_FLAG) + { + if (viewId == VIBRATION_MODE_VIEWID) // 如果在震动提醒子视图 + { + view_->GetVibrationModeView()->UpdatePickerSelectIndex(); + SoundAndVibrationView::GetInstance()->ChangeView(VIBRATIONMODEVIEW, SOUNDANDVIBRATIONVIEW); + } + else + { + OHOS::AbilityNavigation::Back(); + } + SoundAndVibrationPresenter::X_DRAG_FLAG = false; + } + + return true; + } + + bool SoundAndVibrationPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; + } + + bool SoundAndVibrationPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnKeyAct"); + if (strcmp(view.GetViewId(), SYSTEM_VOLUME_BUTTON) == 0) + { + OHOS::AbilityNavigation::EnterSlice(VIEW_SYSTEM_VOLUME); + } + else if (strcmp(view.GetViewId(), CALL_VOLUME_BUTTON) == 0) + { + OHOS::AbilityNavigation::EnterSlice(VIEW_CALL_VOLUME); + } + else if (strcmp(view.GetViewId(), VIBRATION_REMINDER_BUTTON) == 0) + { + view_->ChangeView(SOUNDANDVIBRATIONVIEW, VIBRATIONMODEVIEW); + } + else if ((view_->GetVibrationModeView() != nullptr) && (&view == view_->GetVibrationModeView()->GetVibrationModeLabelButton())) + { + int VibrationMode = view_->GetVibrationModeView()->GetVibrationModePicker()->GetSelected(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VibrationMode = %d", VibrationMode); + SoundAndVibrationModel::GetInstance()->SetVibrationReminderToggleButtonStaus(VibrationMode); + custom_VibratorFunc_int(0); + custom_VibratorFunc_int(0); + view_->ChangeView(VIBRATIONMODEVIEW, SOUNDANDVIBRATIONVIEW); + } + return true; + } + + bool SoundAndVibrationPresenter::OnChange(UICheckBox::UICheckBoxState state) + { + SoundAndVibrationModel *p_SoundAndVibrationModel = SoundAndVibrationModel::GetInstance(); + switch (state) + { + case UICheckBox::SELECTED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SilentMode is enable!"); + p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(true); + break; + case UICheckBox::UNSELECTED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SilentMode is disable!"); + p_SoundAndVibrationModel->SetSilentModeToggleButtonStatus(false); + break; + default: + break; + } + return true; + } + + bool SoundAndVibrationPresenter::OnRotate(UIView &view, const RotateEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } + + bool SoundAndVibrationPresenter::OnRotateEnd(UIView &view, const RotateEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/SystemVolumePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/SystemVolumePresenter.cpp index a18245263..45a867447 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/SystemVolumePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/soundandvibration/src/SystemVolumePresenter.cpp @@ -1,112 +1,113 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-03-30 09:14:38 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-19 18:58:05 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp - * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE - */ -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "NativeAbility.h" -#include "graphic_math.h" -#include "string.h" -#include "soundandvibration/include/SystemVolumePresenter.h" - -#include "common/key_code.h" -#include "custom_utils.h" -#include -#include -#include "NativeRegisterManager.h" -// 系统音量 -namespace OHOS -{ - REGIST_SLICE(VIEW_SYSTEM_VOLUME, SystemVolumeView, SystemVolumePresenter); - // 当前Presenter属性实例化的内存指针 - static SystemVolumePresenter *g_pSystemVolumePresenter = nullptr; - - SystemVolumePresenter::SystemVolumePresenter() - { - - g_pSystemVolumePresenter = this; - } - - SystemVolumePresenter::~SystemVolumePresenter() - { - - g_pSystemVolumePresenter = nullptr; - } - - SystemVolumePresenter *SystemVolumePresenter::GetInstance() - { - - return g_pSystemVolumePresenter; - } - - void SystemVolumePresenter::OnStart() - { - - } - - void SystemVolumePresenter::OnPause(void) - { - - Presenter::OnPause(); - } - - void SystemVolumePresenter::OnResume(void) - { - - RootView::GetInstance()->SetOnKeyActListener(this); - } - - void SystemVolumePresenter::OnStop(void) - { - - } - - bool SystemVolumePresenter::OnDrag(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumePresenter::OnDrag"); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - SystemVolumePresenter::X_DRAG_FLAG = true; - } - return true; - } - - bool SystemVolumePresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumePresenter::OnDragEnd"); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SystemVolumePresenter::X_DRAG_FLAG) - { - NativeAbility::GetInstance().Back(); - SystemVolumePresenter::X_DRAG_FLAG = false; - } - return true; - } - - bool SystemVolumePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumePresenter::OnKeyAct"); - uint16 keyID = event.GetKeyId(); - uint16 keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; - } - - bool SystemVolumePresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(view); - UNUSED(event); - return true; - } -} +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-19 18:58:05 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "graphic_math.h" +#include "string.h" +#include "soundandvibration/include/SystemVolumePresenter.h" + +#include "common/key_code.h" +#include "custom_utils.h" +#include +#include +#include "NativeRegisterManager.h" +// 系统音量 +namespace OHOS +{ + REGIST_SLICE(VIEW_SYSTEM_VOLUME, SystemVolumeView, SystemVolumePresenter); + // 当前Presenter属性实例化的内存指针 + static SystemVolumePresenter *g_pSystemVolumePresenter = nullptr; + + SystemVolumePresenter::SystemVolumePresenter() + { + + g_pSystemVolumePresenter = this; + } + + SystemVolumePresenter::~SystemVolumePresenter() + { + + g_pSystemVolumePresenter = nullptr; + } + + SystemVolumePresenter *SystemVolumePresenter::GetInstance() + { + + return g_pSystemVolumePresenter; + } + + void SystemVolumePresenter::OnStart() + { + + } + + void SystemVolumePresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void SystemVolumePresenter::OnResume(void) + { + + RootView::GetInstance()->SetOnKeyActListener(this); + } + + void SystemVolumePresenter::OnStop(void) + { + + } + + bool SystemVolumePresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumePresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + SystemVolumePresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool SystemVolumePresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumePresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SystemVolumePresenter::X_DRAG_FLAG) + { + OHOS::AbilityNavigation::Back(); + SystemVolumePresenter::X_DRAG_FLAG = false; + } + return true; + } + + bool SystemVolumePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumePresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; + } + + bool SystemVolumePresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } +} diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp index dc6e8ecaf..86ee4775f 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp @@ -1,377 +1,378 @@ -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "UiConfig.h" -#include "stopwatch/include/MainStopWatchPresenter.h" -#include "stopwatch/include/StopWatchModel.h" -#include "common/key_code.h" -#include -/*秒表主视图*/ -#include "gfx_utils/mem_check.h" - -#include "NativeRegisterManager.h" -namespace OHOS -{ - REGIST_MENU_PRO(VIEW_MAIN_STOPWATCH, MainStopWatchView, MainStopWatchPresenter, - PNG_APPLIST_STOPWATCH_IMAGE_BIG, PNG_APPLIST_STOPWATCH_IMAGE, PNG_APPLIST_STOPWATCH_IMAGE, "秒表", STR_STOPWATCH); - - // 当前Presenter属性实例化的内存指针 - static MainStopWatchPresenter *g_pMainStopWatchPresenter = nullptr; - - MainStopWatchPresenter::MainStopWatchPresenter() - { - g_pMainStopWatchPresenter = this; -#ifdef MEM_CHECK - MemCheck::GetInstance()->EnableLeakCheck(true); -#endif - } - - MainStopWatchPresenter::~MainStopWatchPresenter() - { - StopWatchModel::GetInstance()->StopWatch_StopTimer(); // 退出删除并清理定时器资源 - g_pMainStopWatchPresenter = nullptr; -#ifdef MEM_CHECK - MemCheck::GetInstance()->EnableLeakCheck(false); -#endif - } - - MainStopWatchPresenter *MainStopWatchPresenter::GetInstance() - { - return g_pMainStopWatchPresenter; - } - - void MainStopWatchPresenter::OnStart() - { - // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 长亮屏 - } - - void MainStopWatchPresenter::OnPause(void) - { - - Presenter::OnPause(); - } - - void MainStopWatchPresenter::OnResume(void) - { - - RootView::GetInstance()->SetOnKeyActListener(this); - } - - void MainStopWatchPresenter::OnStop(void) - { - // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 取消长亮屏 - } - - /// @brief 设置复选框和按钮 - /// @param checkbox - /// @param button - void MainStopWatchPresenter::SetCheckBoxAndButton(UICheckBox *checkbox, UIButton *button) - { - m_checkbox = checkbox; - m_button = button; - } - - /// @brief 设置标签 - /// @param label1 - /// @param label2 - void MainStopWatchPresenter::SetLable(UILabel *label1, UILabel *label2) - { - m_stopWatchlabel = label1; - m_showTimelabel = label2; - } - - /// @brief 设置显示时间的标签样式 - /// @param label - /// @param x - /// @param y - /// @param TextFont - /// @param LineHeight - void MainStopWatchPresenter::SetShowTimeLableStyle(UILabel *label, int x, int y, int TextFont, int LineHeight) - { - label->SetPosition(x, y, 466, LineHeight); - label->SetStyle(STYLE_TEXT_FONT, TextFont); - label->SetStyle(STYLE_LINE_HEIGHT, LineHeight); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, TextFont); - label->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->Invalidate(); - } - - void MainStopWatchPresenter::SetList(UIList *list, TextAdapter *listadapter, List *listdata) - { - m_list = list; - m_listadapter = listadapter; - m_listdata = listdata; - } - - void MainStopWatchPresenter::SetImage(UIImageView *image) - { - m_image = image; - } - - bool MainStopWatchPresenter::OnDrag(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnDrag"); - UNUSED(view); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - MainStopWatchPresenter::X_DRAG_FLAG = true; - } - return true; - } - - bool MainStopWatchPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnDragEnd"); - UNUSED(view); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainStopWatchPresenter::X_DRAG_FLAG) - { - if (&view == view_->GetScrollView(MAIN_STOPWATCH)) - { - NativeAbility::GetInstance().Back(); - } - else if (&view == view_->GetScrollView(STOPWATCH_RECORD_CYCLE_TO_LIMIT)) - { - view_->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH); - } - else if (&view == view_->GetScrollView(STOPWATCH_RECORD_TIME_TO_LIMIT)) - { - view_->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH); - } - X_DRAG_FLAG = false; - } - return true; - } - - /* - * Converts a time string in the format "mm:ss.ms" to milliseconds. - * - * @param timeStr The time string to convert. - * @return The time in milliseconds. - */ - static unsigned long TimeStrToMilliseconds(const char *timeStr) - { - unsigned minutes, seconds, milliseconds; - - // Assuming the format is "mm:ss.ms" - if (sscanf(timeStr, "%u:%u.%u", &minutes, &seconds, &milliseconds) == 3) - { - // 将分钟转换为毫秒,将秒转换为毫秒,并将它们相加 - unsigned long totalMilliseconds = (minutes * 60 * 1000) + (seconds * 1000) + (milliseconds * 10); - return totalMilliseconds; - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Invalid time format."); - return 0; - } - } - - /*将毫秒级数转成格式为"mm:ss.ms"*/ - static void MillisecondsToTimeStr(unsigned long milliseconds, char *buffer) - { - unsigned minutes = milliseconds / (60 * 1000); - milliseconds %= (60 * 1000); // Remaining milliseconds after converting to minutes - unsigned seconds = milliseconds / 1000; - unsigned ms = milliseconds % 1000; // Remaining milliseconds after converting to seconds - - // Assuming ms needs to be in hundredths of a second for the ".ms" format - unsigned msHundredths = ms / 10; // Convert to hundredths of a second - - // Write the formatted time string to the buffer - sprintf(buffer, "%02u:%02u.%02u", minutes, seconds, msHundredths); - } - - bool MainStopWatchPresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(view); - MainStopWatchView *mainStopWatchView = MainStopWatchView::GetInstance(); - const char *clickedViewId = view.GetViewId(); - if (strcmp(clickedViewId, ResetOrMarkButton_MARK_VIEWID) == 0) // 点击标记按钮 - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordCycleNumber:%d\n", RecordCycleNumber); - if (RecordCycleNumber >= MAX_RECORD_LOOPS) // 到达最高记录圈数 - { - m_checkbox->SetState(UICheckBox::UNSELECTED); - mainStopWatchView->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_CYCLE_TO_LIMIT); - return true; - } - else - { - RecordCycleNumber += 1; - } - - if (isStartMark == false) // 第一次标记 - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "isStartMark = %d", isStartMark); - mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, false); - SetShowTimeLableStyle(m_showTimelabel, 0, 60, 65, 78); - mainStopWatchView->SetViewIsVisible(m_list, true); - mainStopWatchView->SetViewIsVisible(m_image, true); - isStartMark = true; - } - - uint64_t currentRecordTime = TimeStrToMilliseconds(MainStopWatchView::GetInstance()->GetShowTimelabel()->GetText()); // 获取当前时间 - uint64_t timeDifference = 0; // 时间差值 - if (lastRecordTime > 0) - { - // 如果不是第一次标记,则计算与上一次记录的时间差 - timeDifference = currentRecordTime - lastRecordTime; - } - // 将时间和时间差格式化为字符串,更新到UI - const char *formattedTime = MainStopWatchView::GetInstance()->GetShowTimelabel()->GetText(); - char formattedDiff[64] = {0}; - MillisecondsToTimeStr(timeDifference, formattedDiff); - // char *PickerData = (char *)malloc(128); - // if (lastRecordTime == 0) // 如果是第一次标记 - // { - // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedTime); - // } - // else - // { - // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedDiff); - // } - // m_listdata->PushFront(const_cast(PickerData)); - // m_listadapter->SetData(m_listdata); - // m_list->SetAdapter(m_listadapter); - // char PickerData[128]={0}; - // if (lastRecordTime == 0) // 如果是第一次标记 - // { - // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedTime); - // } - // else - // { - // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedDiff); - // } - - StopWatchItem item = {"", "", "", 0}; - char buffer[3] = {0}; // 足够存放两位数字及字符串结束符'\0' - std::sprintf(buffer, "%02d", RecordCycleNumber); - item.RecordCycleNumber = buffer; - item.formattedTime = std::string(formattedTime); - ; - item.formattedDiff = "+" + std::string((lastRecordTime == 0) ? formattedTime : formattedDiff); // lastRecordTime == 0,如果是第一次标记 - item.curSelectItemViewIndex = RecordCycleNumber - 1; - - view_->GetStopWatchAdapter()->setSelectedIndex(RecordCycleNumber - 1); - view_->GetStopWatchAdapter()->AddListItem(item); - m_list->SetAdapter(view_->GetStopWatchAdapter()); - m_list->SetStartIndex(RecordCycleNumber - 1); - m_list->SetSelectPosition(RecordCycleNumber); - m_list->RefreshList(); - // 保存当前时间为“上一次记录时间”,为下一次标记做准备 - lastRecordTime = currentRecordTime; - return true; - } - else if (strcmp(clickedViewId, ResetOrMarkButton_RESET2_VIEWID) == 0) // 点击重置按钮 - { - StopWatchModel::GetInstance()->StopWatch_StopTimer(); // 停止定时器 - mainStopWatchView->GetShowTimelabel()->SetText("00:00.00"); - lastRecordTime = 0; - view_->GetStopWatchAdapter()->ClearData(); - m_list->SetAdapter(nullptr); - m_list->RefreshList(); - - m_button->SetViewId(ResetOrMarkButton_RESET1_VIEWID); - m_button->SetImageSrc(ResetOrMarkButtonImg_Reset1, ResetOrMarkButtonImg_Reset1); - m_button->Invalidate(); - - if (isStartMark == true) // 重置标记 - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "isStartMark = %d", isStartMark); - mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, true); - SetShowTimeLableStyle(m_showTimelabel, 0, 160, 84, 94); - mainStopWatchView->SetViewIsVisible(m_image, false); - mainStopWatchView->SetViewIsVisible(m_list, false); - isStartMark = false; - } - - // if (m_listdata != nullptr) - // { - // // 遍历列表,释放每个元素所占用的内存 - // ListNode *node = m_listdata->Head(); - // int cnt = 0; - // while (node != m_listdata->End()) - // { - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d", ++cnt); - // const char *p = node->data_; - // free(const_cast(p)); - - // node = m_listdata->Remove(node); - // } - // m_listdata->Clear(); - // } - // else - // { - // // Handle error or log the issue - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: m_listdata is nullptr"); - // } - RecordCycleNumber = 0; - } - else if (strcmp(clickedViewId, CycleToLimitReturnButton_VIEWID) == 0) // 点击返回按钮 - { - mainStopWatchView->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH); - } - else if (strcmp(clickedViewId, TimeToLimitReturnButton_VIEWID) == 0) // 点击返回按钮 - { - mainStopWatchView->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH); - } - else if (strcmp(clickedViewId, PlayOrPausecheckBoxVIEWID) == 0) // 点击播放和暂停按钮 - { - if (StopWatchModel::GetInstance()->isReachMaxRecordTime()) // 到达最大时间不能再计时 - { - mainStopWatchView->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_TIME_TO_LIMIT); - } - } - return true; - } - - bool MainStopWatchPresenter::OnChange(UICheckBox::UICheckBoxState state) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnChange,state = %d", state); - if (state == UICheckBox::UICheckBoxState::SELECTED) - { - StopWatchModel::GetInstance()->StopWatch_StartTimer(STOPWATCH_TIMER_DURATION); // 开启定时器,如果定时器存在会直接返回 - StopWatchModel::GetInstance()->StopWatch_ResumeTimer(STOPWATCH_TIMER_DURATION); // 恢复定时器 - - m_button->SetViewId(ResetOrMarkButton_MARK_VIEWID); - m_button->SetImageSrc(ResetOrMarkButtonImg_Mark, ResetOrMarkButtonImg_Mark); - m_button->Invalidate(); // 图片重新赋值要刷新该区域 - TimerIsRunning = true; - } - else - { - StopWatchModel::GetInstance()->StopWatch_PauseTimer(); // 暂停定时器 - m_button->SetViewId(ResetOrMarkButton_RESET2_VIEWID); - m_button->SetImageSrc(ResetOrMarkButtonImg_Reset2, ResetOrMarkButtonImg_Reset2); - m_button->Invalidate(); - TimerIsRunning = false; - } - return true; - } - - // 增加按键事件 - bool MainStopWatchPresenter::OnKeyAct(UIView &view, const KeyEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnKeyAct"); - uint16_t keyID = event.GetKeyId(); - uint16_t keyState = event.GetState(); - // 如果是power键就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return false; - } - - void MainStopWatchPresenter::Notify() - { - if (view_->GetScrollView(MAIN_STOPWATCH) && view_->GetScrollView(MAIN_STOPWATCH)->IsVisible()) - { - if (TimerIsRunning) - { - view_->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration().c_str()); - view_->GetShowTimelabel()->Invalidate(); - } - } - } +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "UiConfig.h" +#include "stopwatch/include/MainStopWatchPresenter.h" +#include "stopwatch/include/StopWatchModel.h" +#include "common/key_code.h" +#include +/*秒表主视图*/ +#include "gfx_utils/mem_check.h" + +#include "NativeRegisterManager.h" +namespace OHOS +{ + REGIST_MENU_PRO(VIEW_MAIN_STOPWATCH, MainStopWatchView, MainStopWatchPresenter, + PNG_APPLIST_STOPWATCH_IMAGE_BIG, PNG_APPLIST_STOPWATCH_IMAGE, PNG_APPLIST_STOPWATCH_IMAGE, "秒表", STR_STOPWATCH); + + // 当前Presenter属性实例化的内存指针 + static MainStopWatchPresenter *g_pMainStopWatchPresenter = nullptr; + + MainStopWatchPresenter::MainStopWatchPresenter() + { + g_pMainStopWatchPresenter = this; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif + } + + MainStopWatchPresenter::~MainStopWatchPresenter() + { + StopWatchModel::GetInstance()->StopWatch_StopTimer(); // 退出删除并清理定时器资源 + g_pMainStopWatchPresenter = nullptr; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif + } + + MainStopWatchPresenter *MainStopWatchPresenter::GetInstance() + { + return g_pMainStopWatchPresenter; + } + + void MainStopWatchPresenter::OnStart() + { + // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 长亮屏 + } + + void MainStopWatchPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void MainStopWatchPresenter::OnResume(void) + { + + RootView::GetInstance()->SetOnKeyActListener(this); + } + + void MainStopWatchPresenter::OnStop(void) + { + // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 取消长亮屏 + } + + /// @brief 设置复选框和按钮 + /// @param checkbox + /// @param button + void MainStopWatchPresenter::SetCheckBoxAndButton(UICheckBox *checkbox, UIButton *button) + { + m_checkbox = checkbox; + m_button = button; + } + + /// @brief 设置标签 + /// @param label1 + /// @param label2 + void MainStopWatchPresenter::SetLable(UILabel *label1, UILabel *label2) + { + m_stopWatchlabel = label1; + m_showTimelabel = label2; + } + + /// @brief 设置显示时间的标签样式 + /// @param label + /// @param x + /// @param y + /// @param TextFont + /// @param LineHeight + void MainStopWatchPresenter::SetShowTimeLableStyle(UILabel *label, int x, int y, int TextFont, int LineHeight) + { + label->SetPosition(x, y, 466, LineHeight); + label->SetStyle(STYLE_TEXT_FONT, TextFont); + label->SetStyle(STYLE_LINE_HEIGHT, LineHeight); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, TextFont); + label->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->Invalidate(); + } + + void MainStopWatchPresenter::SetList(UIList *list, TextAdapter *listadapter, List *listdata) + { + m_list = list; + m_listadapter = listadapter; + m_listdata = listdata; + } + + void MainStopWatchPresenter::SetImage(UIImageView *image) + { + m_image = image; + } + + bool MainStopWatchPresenter::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnDrag"); + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + MainStopWatchPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool MainStopWatchPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnDragEnd"); + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainStopWatchPresenter::X_DRAG_FLAG) + { + if (&view == view_->GetScrollView(MAIN_STOPWATCH)) + { + OHOS::AbilityNavigation::Back(); + } + else if (&view == view_->GetScrollView(STOPWATCH_RECORD_CYCLE_TO_LIMIT)) + { + view_->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH); + } + else if (&view == view_->GetScrollView(STOPWATCH_RECORD_TIME_TO_LIMIT)) + { + view_->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH); + } + X_DRAG_FLAG = false; + } + return true; + } + + /* + * Converts a time string in the format "mm:ss.ms" to milliseconds. + * + * @param timeStr The time string to convert. + * @return The time in milliseconds. + */ + static unsigned long TimeStrToMilliseconds(const char *timeStr) + { + unsigned minutes, seconds, milliseconds; + + // Assuming the format is "mm:ss.ms" + if (sscanf(timeStr, "%u:%u.%u", &minutes, &seconds, &milliseconds) == 3) + { + // 将分钟转换为毫秒,将秒转换为毫秒,并将它们相加 + unsigned long totalMilliseconds = (minutes * 60 * 1000) + (seconds * 1000) + (milliseconds * 10); + return totalMilliseconds; + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Invalid time format."); + return 0; + } + } + + /*将毫秒级数转成格式为"mm:ss.ms"*/ + static void MillisecondsToTimeStr(unsigned long milliseconds, char *buffer) + { + unsigned minutes = milliseconds / (60 * 1000); + milliseconds %= (60 * 1000); // Remaining milliseconds after converting to minutes + unsigned seconds = milliseconds / 1000; + unsigned ms = milliseconds % 1000; // Remaining milliseconds after converting to seconds + + // Assuming ms needs to be in hundredths of a second for the ".ms" format + unsigned msHundredths = ms / 10; // Convert to hundredths of a second + + // Write the formatted time string to the buffer + sprintf(buffer, "%02u:%02u.%02u", minutes, seconds, msHundredths); + } + + bool MainStopWatchPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(view); + MainStopWatchView *mainStopWatchView = MainStopWatchView::GetInstance(); + const char *clickedViewId = view.GetViewId(); + if (strcmp(clickedViewId, ResetOrMarkButton_MARK_VIEWID) == 0) // 点击标记按钮 + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordCycleNumber:%d\n", RecordCycleNumber); + if (RecordCycleNumber >= MAX_RECORD_LOOPS) // 到达最高记录圈数 + { + m_checkbox->SetState(UICheckBox::UNSELECTED); + mainStopWatchView->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_CYCLE_TO_LIMIT); + return true; + } + else + { + RecordCycleNumber += 1; + } + + if (isStartMark == false) // 第一次标记 + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "isStartMark = %d", isStartMark); + mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, false); + SetShowTimeLableStyle(m_showTimelabel, 0, 60, 65, 78); + mainStopWatchView->SetViewIsVisible(m_list, true); + mainStopWatchView->SetViewIsVisible(m_image, true); + isStartMark = true; + } + + uint64_t currentRecordTime = TimeStrToMilliseconds(MainStopWatchView::GetInstance()->GetShowTimelabel()->GetText()); // 获取当前时间 + uint64_t timeDifference = 0; // 时间差值 + if (lastRecordTime > 0) + { + // 如果不是第一次标记,则计算与上一次记录的时间差 + timeDifference = currentRecordTime - lastRecordTime; + } + // 将时间和时间差格式化为字符串,更新到UI + const char *formattedTime = MainStopWatchView::GetInstance()->GetShowTimelabel()->GetText(); + char formattedDiff[64] = {0}; + MillisecondsToTimeStr(timeDifference, formattedDiff); + // char *PickerData = (char *)malloc(128); + // if (lastRecordTime == 0) // 如果是第一次标记 + // { + // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedTime); + // } + // else + // { + // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedDiff); + // } + // m_listdata->PushFront(const_cast(PickerData)); + // m_listadapter->SetData(m_listdata); + // m_list->SetAdapter(m_listadapter); + // char PickerData[128]={0}; + // if (lastRecordTime == 0) // 如果是第一次标记 + // { + // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedTime); + // } + // else + // { + // sprintf(PickerData, "%02d %s +%s", RecordCycleNumber, formattedTime, formattedDiff); + // } + + StopWatchItem item = {"", "", "", 0}; + char buffer[3] = {0}; // 足够存放两位数字及字符串结束符'\0' + std::sprintf(buffer, "%02d", RecordCycleNumber); + item.RecordCycleNumber = buffer; + item.formattedTime = std::string(formattedTime); + ; + item.formattedDiff = "+" + std::string((lastRecordTime == 0) ? formattedTime : formattedDiff); // lastRecordTime == 0,如果是第一次标记 + item.curSelectItemViewIndex = RecordCycleNumber - 1; + + view_->GetStopWatchAdapter()->setSelectedIndex(RecordCycleNumber - 1); + view_->GetStopWatchAdapter()->AddListItem(item); + m_list->SetAdapter(view_->GetStopWatchAdapter()); + m_list->SetStartIndex(RecordCycleNumber - 1); + m_list->SetSelectPosition(RecordCycleNumber); + m_list->RefreshList(); + // 保存当前时间为“上一次记录时间”,为下一次标记做准备 + lastRecordTime = currentRecordTime; + return true; + } + else if (strcmp(clickedViewId, ResetOrMarkButton_RESET2_VIEWID) == 0) // 点击重置按钮 + { + StopWatchModel::GetInstance()->StopWatch_StopTimer(); // 停止定时器 + mainStopWatchView->GetShowTimelabel()->SetText("00:00.00"); + lastRecordTime = 0; + view_->GetStopWatchAdapter()->ClearData(); + m_list->SetAdapter(nullptr); + m_list->RefreshList(); + + m_button->SetViewId(ResetOrMarkButton_RESET1_VIEWID); + m_button->SetImageSrc(ResetOrMarkButtonImg_Reset1, ResetOrMarkButtonImg_Reset1); + m_button->Invalidate(); + + if (isStartMark == true) // 重置标记 + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "isStartMark = %d", isStartMark); + mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, true); + SetShowTimeLableStyle(m_showTimelabel, 0, 160, 84, 94); + mainStopWatchView->SetViewIsVisible(m_image, false); + mainStopWatchView->SetViewIsVisible(m_list, false); + isStartMark = false; + } + + // if (m_listdata != nullptr) + // { + // // 遍历列表,释放每个元素所占用的内存 + // ListNode *node = m_listdata->Head(); + // int cnt = 0; + // while (node != m_listdata->End()) + // { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d", ++cnt); + // const char *p = node->data_; + // free(const_cast(p)); + + // node = m_listdata->Remove(node); + // } + // m_listdata->Clear(); + // } + // else + // { + // // Handle error or log the issue + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: m_listdata is nullptr"); + // } + RecordCycleNumber = 0; + } + else if (strcmp(clickedViewId, CycleToLimitReturnButton_VIEWID) == 0) // 点击返回按钮 + { + mainStopWatchView->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH); + } + else if (strcmp(clickedViewId, TimeToLimitReturnButton_VIEWID) == 0) // 点击返回按钮 + { + mainStopWatchView->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH); + } + else if (strcmp(clickedViewId, PlayOrPausecheckBoxVIEWID) == 0) // 点击播放和暂停按钮 + { + if (StopWatchModel::GetInstance()->isReachMaxRecordTime()) // 到达最大时间不能再计时 + { + mainStopWatchView->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_TIME_TO_LIMIT); + } + } + return true; + } + + bool MainStopWatchPresenter::OnChange(UICheckBox::UICheckBoxState state) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnChange,state = %d", state); + if (state == UICheckBox::UICheckBoxState::SELECTED) + { + StopWatchModel::GetInstance()->StopWatch_StartTimer(STOPWATCH_TIMER_DURATION); // 开启定时器,如果定时器存在会直接返回 + StopWatchModel::GetInstance()->StopWatch_ResumeTimer(STOPWATCH_TIMER_DURATION); // 恢复定时器 + + m_button->SetViewId(ResetOrMarkButton_MARK_VIEWID); + m_button->SetImageSrc(ResetOrMarkButtonImg_Mark, ResetOrMarkButtonImg_Mark); + m_button->Invalidate(); // 图片重新赋值要刷新该区域 + TimerIsRunning = true; + } + else + { + StopWatchModel::GetInstance()->StopWatch_PauseTimer(); // 暂停定时器 + m_button->SetViewId(ResetOrMarkButton_RESET2_VIEWID); + m_button->SetImageSrc(ResetOrMarkButtonImg_Reset2, ResetOrMarkButtonImg_Reset2); + m_button->Invalidate(); + TimerIsRunning = false; + } + return true; + } + + // 增加按键事件 + bool MainStopWatchPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnKeyAct"); + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return false; + } + + void MainStopWatchPresenter::Notify() + { + if (view_->GetScrollView(MAIN_STOPWATCH) && view_->GetScrollView(MAIN_STOPWATCH)->IsVisible()) + { + if (TimerIsRunning) + { + view_->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration().c_str()); + view_->GetShowTimelabel()->Invalidate(); + } + } + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/stress/src/stressTestPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/stress/src/stressTestPresenter.cpp index c80a3ee4f..36825f2b8 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/stress/src/stressTestPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/stress/src/stressTestPresenter.cpp @@ -1,5 +1,6 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include #include "UiConfig.h" @@ -105,7 +106,7 @@ namespace OHOS StressTestPresenter::X_DRAG_FLAG = false; if (view.GetViewId() == STRESSTESTSTANDBYVIEW_ID) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } else if (view.GetViewId() == STRESSTESTINGVIEW_ID) { @@ -128,7 +129,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/src/SystemPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/src/SystemPresenter.cpp index c1c990eaf..43119c132 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/src/SystemPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/src/SystemPresenter.cpp @@ -1,301 +1,302 @@ -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "NativeAbility.h" -#include "graphic_math.h" -#include "string.h" -#include "system/include/SystemPresenter.h" -#include "font/font_global_manager.h" -#include "font/ui_font.h" -#include "languagecode/LanguageInit.h" - -#include "common/key_code.h" -#include "custom_utils.h" -#include "languagecode/LanguageInit.h" -#include "ui_resource_string.h" -#include "ConfigModel.h" -#include "vibrator_service.h" -#include "broadcast_feature.h" - -#include "UiConfig.h" - -#include "NativeRegisterManager.h" - -namespace OHOS -{ - REGIST_SLICE(VIEW_SYSTEM, SystemView, SystemPresenter); - - // 当前Presenter属性实例化的内存指针 - static SystemPresenter *g_pSystemPresenter = nullptr; - - SystemPresenter::SystemPresenter() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::SystemPresenter"); - g_pSystemPresenter = this; - systemModel = SystemModel::GetInstance(); - } - - SystemPresenter::~SystemPresenter() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::~SystemPresenter"); - g_pSystemPresenter = nullptr; - } - - SystemPresenter *SystemPresenter::GetInstance() - { - - return g_pSystemPresenter; - } - - void SystemPresenter::OnStart(){} - - void SystemPresenter::OnResume() - { - RootView::GetInstance()->SetOnKeyActListener(this); - SystemView *p_SystemView = SystemView::GetInstance(); - if (p_SystemView != nullptr) { - p_SystemView->RequestFocusForCurrentView(); - } - } - - static uint32_t time = 0; - static uint32_t OnClick_num = 0; - - bool SystemPresenter::OnPress(UIView &view, const PressEvent &event) - { - return true; - } - - bool SystemPresenter::OnDrag(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnDrag"); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - SystemPresenter::X_DRAG_FLAG = true; - } - return true; - } - - bool SystemPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnDragEnd"); - SystemView *p_SystemView = SystemView::GetInstance(); - if (p_SystemView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SystemView::GetInstance fail!"); - return false; - } - - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SystemPresenter::X_DRAG_FLAG) - { - if (&view == p_SystemView->GetSystemScrollView(SYSTEMVIEW)) - { - NativeAbility::GetInstance().Back(); - } - else if (&view == p_SystemView->GetSystemScrollView(ABOUTTHEWATCHVIEW)) - { - p_SystemView->ChangeView(ABOUTTHEWATCHVIEW, SYSTEMVIEW); - } - else if (&view == p_SystemView->GetSystemScrollView(RESTARTVIEW)) - { - p_SystemView->ChangeView(RESTARTVIEW, SYSTEMVIEW); - } - else if (&view == p_SystemView->GetSystemScrollView(SHUTDOWNVIEW)) - { - p_SystemView->ChangeView(SHUTDOWNVIEW, SYSTEMVIEW); - } - else if (&view == p_SystemView->GetSystemScrollView(FACTORYRESETVIEW)) - { - p_SystemView->ChangeView(FACTORYRESETVIEW, SYSTEMVIEW); - } - else if (&view == p_SystemView->GetSystemScrollView(SUPERVISIONINFOVIEW)) - { - p_SystemView->ChangeView(SUPERVISIONINFOVIEW, SYSTEMVIEW); - } - SystemPresenter::X_DRAG_FLAG = false; - return true; - } - return false; - } - - // 该点击回调主要用于在系统视图界面进行跳转视图 - bool SystemPresenter::OnClick(UIView &view, const ClickEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnClick"); - SystemView *p_SystemView = SystemView::GetInstance(); - if (p_SystemView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SystemView::GetInstance fail!"); - return false; - } - - if (strcmp(view.GetViewId(), VIEW_ID_SUPERVISIONINFO_TITLE_BUTTON) == 0) // 点击进入监管信息界面 - { - p_SystemView->ChangeView(SYSTEMVIEW, SUPERVISIONINFOVIEW); - return true; - } - - if (strcmp(view.GetViewId(), SYSTEMABOUTTHEWATCHVIEWID) == 0) // 连续点击进入产测模式 - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchTitle"); - if (time == 0) - { - time = event.GetTimeStamp(); - OnClick_num = 1; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "222 %d", time); - } - else - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "111 %d", event.GetTimeStamp()); - if (event.GetTimeStamp() - time < 2000) - { - OnClick_num++; - - if (OnClick_num > 5) - { - // NativeAbility::GetInstance().ChangeSlice(VIEW_TEST); - CustomEventPublish(TOPIC_EVENT_DEBUGOUTPUT, NULL, 0); - } - } - else - { - time = 0; - } - } - return true; - } - else if (strcmp(view.GetViewId(), ABOUT_THE_WATCH) == 0) // 点击进入关于手表界面 - { - p_SystemView->ChangeView(SYSTEMVIEW, ABOUTTHEWATCHVIEW); - return true; - } - else if (strcmp(view.GetViewId(), SET_TIME_FORMAT) == 0) // 点击进入设置时间格式 - { - NativeAbility::GetInstance().EnterSlice(VIEW_SET_TIME_FORMAT); - return true; - } - else if (strcmp(view.GetViewId(), SYSTEM_UPGRADE) == 0) // 点击进入系统升级视图 - { - NativeAbility::GetInstance().EnterSlice(VIEW_SYSTEM_UPDATE); - return true; - } - else if (strcmp(view.GetViewId(), WATCH_QR_CODE) == 0) // 点击进入手表二维码视图 - { - NativeAbility::GetInstance().EnterSlice(VIEW_WATCH_QR_CODE); - return true; - } - else if (strcmp(view.GetViewId(), SYSTEM_LANGUAGE) == 0) // 点击进入系统语言界面 - { - NativeAbility::GetInstance().EnterSlice(VIEW_LANGUAGE_SWITCH); - return true; - } - else if (strcmp(view.GetViewId(), RESTART) == 0) // 点击进入重启界面 - { - p_SystemView->ChangeView(SYSTEMVIEW, RESTARTVIEW); - return true; - } - else if (strcmp(view.GetViewId(), SHUTDOWN) == 0) // 点击进入关机界面 - { - p_SystemView->ChangeView(SYSTEMVIEW, SHUTDOWNVIEW); - return true; - } - else if (strcmp(view.GetViewId(), FACTORY_RESET) == 0) // 点击进入恢复出厂设置界面 - { - p_SystemView->ChangeView(SYSTEMVIEW, FACTORYRESETVIEW); - return true; - } - else if (strcmp(view.GetViewId(), RESTARTVIEW_CHECKON) == 0) // 重启确认 - { - p_SystemView->ChangeView(RESTARTVIEW, SHUTDOWNANIMATIONVIEW); - - ShutDownImageAnimatorView::GetInstance()->ShutDownImageAnimator_Start(1); - isShutDownImageAnimatorStart = true; - return true; - } - else if (strcmp(view.GetViewId(), RESTARTVIEW_CHECKOFF) == 0) // 重启取消 - { - p_SystemView->ChangeView(RESTARTVIEW, SYSTEMVIEW); - return true; - } - else if (strcmp(view.GetViewId(), SHUTDOWN_CHECKON) == 0) // 关机确认 - { - p_SystemView->ChangeView(SHUTDOWNVIEW, SHUTDOWNANIMATIONVIEW); - - - ShutDownImageAnimatorView::GetInstance()->ShutDownImageAnimator_Start(0); - isShutDownImageAnimatorStart = true; - - return true; - } - else if (strcmp(view.GetViewId(), SHUTDOWN_CHECKOFF) == 0) // 关机取消 - { - p_SystemView->ChangeView(SHUTDOWNVIEW, SYSTEMVIEW); - return true; - } - else if (strcmp(view.GetViewId(), FACTORYRESET_CHECKON) == 0) // 恢复出厂设置确认 - { - custom_VibratorFunc_int(5); //恢复出厂增加震动 - p_SystemView->ChangeView(FACTORYRESETVIEW, SHUTDOWNANIMATIONVIEW); - ShutDownImageAnimatorView::GetInstance()->ShutDownImageAnimator_Start(2); - isShutDownImageAnimatorStart = true; - return true; - } - else if (strcmp(view.GetViewId(), FACTORYRESET_CHECKOFF) == 0) // 恢复出厂设置取消 - { - p_SystemView->ChangeView(FACTORYRESETVIEW, SYSTEMVIEW); - return true; - } - - // if (strcmp(view.GetViewId(), SYSTEM_UPGRADE_t) == 0) //点击是否立即升级 - // { - // SystemupgradeView::GetInstance()->statr_down_fwpkg(); - // } - // if (strcmp(view.GetViewId(), "labelButton1_exit") == 0) //稍后再说 - // { - // NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); - // } - return true; - } - - bool SystemPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnKeyAct"); - uint16 keyID = event.GetKeyId(); - uint16 keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - if (!isShutDownImageAnimatorStart) - { - NativeAbility::GetInstance().Back(); - } - } - return true; - } - - // void SystemPresenter::set_key_falg(bool falg) // 增加按键事件 - // { - // isSystemUpgradeState = falg; - // } -#ifdef __cplusplus -#if __cplusplus - extern "C" - { -#endif /* __cplusplus */ -#endif /* __cplusplus */ - - void factorytest_enter_test_view(int cmd) - { - if (cmd == 1) - NativeAbility::GetInstance().ChangeSlice(VIEW_TEST); - else - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - } - -#ifdef __cplusplus -#if __cplusplus - } -#endif /* __cplusplus */ -#endif /* __cplusplus */ +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "graphic_math.h" +#include "string.h" +#include "system/include/SystemPresenter.h" +#include "font/font_global_manager.h" +#include "font/ui_font.h" +#include "languagecode/LanguageInit.h" + +#include "common/key_code.h" +#include "custom_utils.h" +#include "languagecode/LanguageInit.h" +#include "ui_resource_string.h" +#include "ConfigModel.h" +#include "vibrator_service.h" +#include "broadcast_feature.h" + +#include "UiConfig.h" + +#include "NativeRegisterManager.h" + +namespace OHOS +{ + REGIST_SLICE(VIEW_SYSTEM, SystemView, SystemPresenter); + + // 当前Presenter属性实例化的内存指针 + static SystemPresenter *g_pSystemPresenter = nullptr; + + SystemPresenter::SystemPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::SystemPresenter"); + g_pSystemPresenter = this; + systemModel = SystemModel::GetInstance(); + } + + SystemPresenter::~SystemPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::~SystemPresenter"); + g_pSystemPresenter = nullptr; + } + + SystemPresenter *SystemPresenter::GetInstance() + { + + return g_pSystemPresenter; + } + + void SystemPresenter::OnStart(){} + + void SystemPresenter::OnResume() + { + RootView::GetInstance()->SetOnKeyActListener(this); + SystemView *p_SystemView = SystemView::GetInstance(); + if (p_SystemView != nullptr) { + p_SystemView->RequestFocusForCurrentView(); + } + } + + static uint32_t time = 0; + static uint32_t OnClick_num = 0; + + bool SystemPresenter::OnPress(UIView &view, const PressEvent &event) + { + return true; + } + + bool SystemPresenter::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + SystemPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool SystemPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnDragEnd"); + SystemView *p_SystemView = SystemView::GetInstance(); + if (p_SystemView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SystemView::GetInstance fail!"); + return false; + } + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SystemPresenter::X_DRAG_FLAG) + { + if (&view == p_SystemView->GetSystemScrollView(SYSTEMVIEW)) + { + OHOS::AbilityNavigation::Back(); + } + else if (&view == p_SystemView->GetSystemScrollView(ABOUTTHEWATCHVIEW)) + { + p_SystemView->ChangeView(ABOUTTHEWATCHVIEW, SYSTEMVIEW); + } + else if (&view == p_SystemView->GetSystemScrollView(RESTARTVIEW)) + { + p_SystemView->ChangeView(RESTARTVIEW, SYSTEMVIEW); + } + else if (&view == p_SystemView->GetSystemScrollView(SHUTDOWNVIEW)) + { + p_SystemView->ChangeView(SHUTDOWNVIEW, SYSTEMVIEW); + } + else if (&view == p_SystemView->GetSystemScrollView(FACTORYRESETVIEW)) + { + p_SystemView->ChangeView(FACTORYRESETVIEW, SYSTEMVIEW); + } + else if (&view == p_SystemView->GetSystemScrollView(SUPERVISIONINFOVIEW)) + { + p_SystemView->ChangeView(SUPERVISIONINFOVIEW, SYSTEMVIEW); + } + SystemPresenter::X_DRAG_FLAG = false; + return true; + } + return false; + } + + // 该点击回调主要用于在系统视图界面进行跳转视图 + bool SystemPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnClick"); + SystemView *p_SystemView = SystemView::GetInstance(); + if (p_SystemView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SystemView::GetInstance fail!"); + return false; + } + + if (strcmp(view.GetViewId(), VIEW_ID_SUPERVISIONINFO_TITLE_BUTTON) == 0) // 点击进入监管信息界面 + { + p_SystemView->ChangeView(SYSTEMVIEW, SUPERVISIONINFOVIEW); + return true; + } + + if (strcmp(view.GetViewId(), SYSTEMABOUTTHEWATCHVIEWID) == 0) // 连续点击进入产测模式 + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchTitle"); + if (time == 0) + { + time = event.GetTimeStamp(); + OnClick_num = 1; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "222 %d", time); + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "111 %d", event.GetTimeStamp()); + if (event.GetTimeStamp() - time < 2000) + { + OnClick_num++; + + if (OnClick_num > 5) + { + // NativeAbility::GetInstance().ChangeSlice(VIEW_TEST); + CustomEventPublish(TOPIC_EVENT_DEBUGOUTPUT, NULL, 0); + } + } + else + { + time = 0; + } + } + return true; + } + else if (strcmp(view.GetViewId(), ABOUT_THE_WATCH) == 0) // 点击进入关于手表界面 + { + p_SystemView->ChangeView(SYSTEMVIEW, ABOUTTHEWATCHVIEW); + return true; + } + else if (strcmp(view.GetViewId(), SET_TIME_FORMAT) == 0) // 点击进入设置时间格式 + { + OHOS::AbilityNavigation::EnterSlice(VIEW_SET_TIME_FORMAT); + return true; + } + else if (strcmp(view.GetViewId(), SYSTEM_UPGRADE) == 0) // 点击进入系统升级视图 + { + OHOS::AbilityNavigation::EnterSlice(VIEW_SYSTEM_UPDATE); + return true; + } + else if (strcmp(view.GetViewId(), WATCH_QR_CODE) == 0) // 点击进入手表二维码视图 + { + OHOS::AbilityNavigation::EnterSlice(VIEW_WATCH_QR_CODE); + return true; + } + else if (strcmp(view.GetViewId(), SYSTEM_LANGUAGE) == 0) // 点击进入系统语言界面 + { + OHOS::AbilityNavigation::EnterSlice(VIEW_LANGUAGE_SWITCH); + return true; + } + else if (strcmp(view.GetViewId(), RESTART) == 0) // 点击进入重启界面 + { + p_SystemView->ChangeView(SYSTEMVIEW, RESTARTVIEW); + return true; + } + else if (strcmp(view.GetViewId(), SHUTDOWN) == 0) // 点击进入关机界面 + { + p_SystemView->ChangeView(SYSTEMVIEW, SHUTDOWNVIEW); + return true; + } + else if (strcmp(view.GetViewId(), FACTORY_RESET) == 0) // 点击进入恢复出厂设置界面 + { + p_SystemView->ChangeView(SYSTEMVIEW, FACTORYRESETVIEW); + return true; + } + else if (strcmp(view.GetViewId(), RESTARTVIEW_CHECKON) == 0) // 重启确认 + { + p_SystemView->ChangeView(RESTARTVIEW, SHUTDOWNANIMATIONVIEW); + + ShutDownImageAnimatorView::GetInstance()->ShutDownImageAnimator_Start(1); + isShutDownImageAnimatorStart = true; + return true; + } + else if (strcmp(view.GetViewId(), RESTARTVIEW_CHECKOFF) == 0) // 重启取消 + { + p_SystemView->ChangeView(RESTARTVIEW, SYSTEMVIEW); + return true; + } + else if (strcmp(view.GetViewId(), SHUTDOWN_CHECKON) == 0) // 关机确认 + { + p_SystemView->ChangeView(SHUTDOWNVIEW, SHUTDOWNANIMATIONVIEW); + + + ShutDownImageAnimatorView::GetInstance()->ShutDownImageAnimator_Start(0); + isShutDownImageAnimatorStart = true; + + return true; + } + else if (strcmp(view.GetViewId(), SHUTDOWN_CHECKOFF) == 0) // 关机取消 + { + p_SystemView->ChangeView(SHUTDOWNVIEW, SYSTEMVIEW); + return true; + } + else if (strcmp(view.GetViewId(), FACTORYRESET_CHECKON) == 0) // 恢复出厂设置确认 + { + custom_VibratorFunc_int(5); //恢复出厂增加震动 + p_SystemView->ChangeView(FACTORYRESETVIEW, SHUTDOWNANIMATIONVIEW); + ShutDownImageAnimatorView::GetInstance()->ShutDownImageAnimator_Start(2); + isShutDownImageAnimatorStart = true; + return true; + } + else if (strcmp(view.GetViewId(), FACTORYRESET_CHECKOFF) == 0) // 恢复出厂设置取消 + { + p_SystemView->ChangeView(FACTORYRESETVIEW, SYSTEMVIEW); + return true; + } + + // if (strcmp(view.GetViewId(), SYSTEM_UPGRADE_t) == 0) //点击是否立即升级 + // { + // SystemupgradeView::GetInstance()->statr_down_fwpkg(); + // } + // if (strcmp(view.GetViewId(), "labelButton1_exit") == 0) //稍后再说 + // { + // NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + // } + return true; + } + + bool SystemPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + if (!isShutDownImageAnimatorStart) + { + OHOS::AbilityNavigation::Back(); + } + } + return true; + } + + // void SystemPresenter::set_key_falg(bool falg) // 增加按键事件 + // { + // isSystemUpgradeState = falg; + // } +#ifdef __cplusplus +#if __cplusplus + extern "C" + { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + + void factorytest_enter_test_view(int cmd) + { + if (cmd == 1) + NativeAbility::GetInstance().ChangeSlice(VIEW_TEST); + else + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + } + +#ifdef __cplusplus +#if __cplusplus + } +#endif /* __cplusplus */ +#endif /* __cplusplus */ } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/systemupdate/src/SystemUpdateModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/systemupdate/src/SystemUpdateModel.cpp index 68589b17f..d15c2730b 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/systemupdate/src/SystemUpdateModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/systemupdate/src/SystemUpdateModel.cpp @@ -27,6 +27,7 @@ #endif #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" namespace OHOS { static int fwpkg_size=0; @@ -122,7 +123,7 @@ namespace OHOS button_flag=OTA_BUTTON_GET_ABLE_DOWNLOAD_FAIL; } - NativeAbility::GetInstance().EnterSlice(VIEW_SYSTEM_UPDATE); + OHOS::AbilityNavigation::EnterSlice(VIEW_SYSTEM_UPDATE); //SystemUpdateView::GetInstance()->msg_text_set(ret); } break; @@ -133,7 +134,7 @@ namespace OHOS } else { - NativeAbility::GetInstance().EnterSlice(VIEW_SYSTEM_UPDATE); + OHOS::AbilityNavigation::EnterSlice(VIEW_SYSTEM_UPDATE); //SystemUpdateView::GetInstance()->msg_text_set(ret); } break; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/systemupdate/src/SystemUpdatePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/systemupdate/src/SystemUpdatePresenter.cpp index 149f918cf..05cd2bc0b 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/systemupdate/src/SystemUpdatePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/systemupdate/src/SystemUpdatePresenter.cpp @@ -8,6 +8,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "systemupdate/include/SystemUpdatePresenter.h" #include "systemupdate/include/SystemUpdateView.h" #include "common/key_code.h" @@ -77,7 +78,7 @@ namespace OHOS else if (&view == systemUpdateView->GetTryAgainLaterButton()) // 如果点击的是稍后再说按钮 { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetTryAgainLaterButton"); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; @@ -100,7 +101,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemUpdatePresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SystemUpdatePresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } @@ -114,7 +115,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/takephotos/src/TakephotosModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/takephotos/src/TakephotosModel.cpp index 5d747231b..5f8362ac3 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/takephotos/src/TakephotosModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/takephotos/src/TakephotosModel.cpp @@ -16,6 +16,7 @@ #include "takephotos/include/TakephotosModel.h" #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "broadcast_feature.h" #include "broadcast_service.h" #include "custom_utils.h" @@ -121,7 +122,7 @@ // } // else // { -// NativeAbility::GetInstance().EnterSlice(VIEW_TAKEPHOTOS); +// OHOS::AbilityNavigation::EnterSlice(VIEW_TAKEPHOTOS); // } // } // // 退出拍照 @@ -134,7 +135,7 @@ // { // // 点亮屏幕 // uapi_set_screen_on_api(); -// NativeAbility::GetInstance().Back(); +// OHOS::AbilityNavigation::Back(); // #ifdef SUPPORT_BLE_SERVICE // cameraSend(3); // #endif diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/takephotos/src/TakephotosPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/takephotos/src/TakephotosPresenter.cpp index ece8056aa..6231b2802 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/takephotos/src/TakephotosPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/takephotos/src/TakephotosPresenter.cpp @@ -8,6 +8,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include #include @@ -72,7 +73,7 @@ namespace OHOS (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); /*如果是拍照界面需要发送拍照结束的消息*/ if (TakephotosModel::GetInstance()->GetPopStaust() == PopupPhoto::TakePopup) @@ -92,7 +93,7 @@ namespace OHOS // 返回按键 if (strcmp(view.GetViewId(), BUTTONGO) == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); return true; } if (strcmp(view.GetViewId(), BUTTONTAKE) == 0) @@ -113,7 +114,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); /*如果是拍照界面需要发送拍照结束的消息*/ if (TakephotosModel::GetInstance()->GetPopStaust() == PopupPhoto::TakePopup) { diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/themestyle/src/ThemeStylePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/themestyle/src/ThemeStylePresenter.cpp index d398e03b8..e79ad957f 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/themestyle/src/ThemeStylePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/themestyle/src/ThemeStylePresenter.cpp @@ -13,6 +13,7 @@ #include #include "NativeRegisterManager.h" #include "uicomponents/UIComponents.h" +#include "AbilityNavigationApi.h" namespace OHOS { @@ -60,7 +61,7 @@ namespace OHOS std::string viewId = labelButtonExt->GetViewId(); if (viewId == THEMESTYLEVIEWEXIT) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); return true; } @@ -96,12 +97,12 @@ namespace OHOS uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); if (preSlice == VIEW_APPLIST) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } else { NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - NativeAbility::GetInstance().ClearSliceIdStack(); + OHOS::AbilityNavigation::ClearSliceIdStack(); } return true; @@ -124,7 +125,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RespiratoryTrainingPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && ThemeStylePresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); ThemeStylePresenter::X_DRAG_FLAG = false; } return true; @@ -138,7 +139,7 @@ namespace OHOS // 如果是power键就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingEnddataPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingEnddataPresenter.cpp index 0935250e9..1815b46bd 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingEnddataPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingEnddataPresenter.cpp @@ -2,6 +2,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" #include "common/key_code.h" @@ -57,7 +58,7 @@ namespace OHOS } else { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp index d3c6ddee5..4687c2647 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp @@ -12,6 +12,7 @@ #include "thread_adapter.h" #include "traing/training_card/include/TraingCardPresenter.h" #include "uicomponents/UIComponents.h" + #include "AbilityNavigationApi.h" #include "wearable_log.h" #include #include @@ -1869,7 +1870,7 @@ bool TraingModel::GetMomentum() { } // 进入运动倒计时 3 秒,结束后跳转运动卡片 CountdownPresenter::SetReturnSlice(VIEW_TRAININGCRAD); - NativeAbility::GetInstance().EnterSlice(VIEW_SPORT_COUNTDOWN); + OHOS::AbilityNavigation::EnterSlice(VIEW_SPORT_COUNTDOWN); // 配置运动项(先完成配置,再进 3 秒倒计时,倒计时结束进入运动界面) SetSportEvent(id); // 获取运动项目 @@ -3321,7 +3322,7 @@ void TraingModel::SetGpsOpen(bool open) { static void gnss_timer_callback(int data) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gnss_timer_callback %d", data); #if defined(SUPPORT_GNSS) - if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_SPORT_COUNTDOWN) { + if (OHOS::AbilityNavigation::GetCurSliceId() == VIEW_SPORT_COUNTDOWN) { return; // 当前在运动倒计时 slice,只正常定时,不操作 } #endif diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp index 5ec462d0d..53a5a3a2b 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp @@ -1,250 +1,251 @@ - - -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "NativeAbility.h" -#include "sport_countdown/CountdownPresenter.h" -#include "key/include/KeyInputListener.h" -#include "custom_utils.h" -#include "common/key_code.h" - -#include -#include -#include -#include -#include "traing/include/TraingNomalPresenter.h" -#include "traing/training_card/include/TraingCardPresenter.h" -#include "main/include/MainModel.h" -#include "UiConfig.h" -// #include "TraingNomalView.h" -#ifdef SUPPORT_GNSS -#include "ephemeris_download/include/EphemerisDownloadModel.h" -#endif - - -#if 0 - 点击开始按钮 - ↓ - 检查是否需要GPS - ↓ (需要GPS) - 检查星历是否有效 - ↓ (无效) → 跳转星历提醒界面 - ↓ (有效) - 检查GPS是否连接 - ↓ (未连接) → 跳转GPS提醒界面 - ↓ (已连接) - 跳转运动卡片 -#endif - -#include "NativeRegisterManager.h" -namespace OHOS -{ - - REGIST_SLICE(VIEW_TRAININGNOMAL, TraingNomalView, TraingNomalPresenter); - - // 当前Presenter属性实例化的内存指针 - static TraingNomalPresenter *g_pTraingNomalPresenter = nullptr; - - - TraingNomalPresenter::TraingNomalPresenter() - { - enter_flag = false; - g_pTraingNomalPresenter = this; - } - - TraingNomalPresenter::~TraingNomalPresenter() - { - g_pTraingNomalPresenter = nullptr; - } - - TraingNomalPresenter *TraingNomalPresenter::GetInstance() - { - return g_pTraingNomalPresenter; - } - - void TraingNomalPresenter::OnStart() - { - //判断是否是需要GPS的运动 - if(TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()) == true) - { - #if defined(SUPPORT_GNSS) - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开启gps定时器,频率:2秒/点"); - TraingModel::GetInstance()->gnss_start_timer(2 * 1000); // 2秒一个GPS点 - #endif - } - } - - void TraingNomalPresenter::OnResume(void) - { - RootView::GetInstance()->SetOnKeyActListener(this); - } - // 回退逻辑 - void TraingNomalPresenter::NavigateBack() - { - /* - 准备训练界面进入: - 1.[主界面] 进入 - 2.[traing] 进入 - 3.[更多]->[具体训练项]进入 - 4.[设置训练目标]进入 {不返回} - */ - NativeAbility::GetInstance().Back(); - - // 如果未进入运动卡片(进入的是提醒界面),清理GPS和心率资源 - // enter_flag = true 表示已进入运动卡片,资源由运动卡片管理 - // enter_flag = false 表示进入的是提醒界面,需要清理资源 - if(enter_flag == false){ - CleanupGPSResources(); - } - } - bool TraingNomalPresenter::OnDrag(UIView &view, const DragEvent &event) - { - UNUSED(view); - // 在拖拽过程中不处理退出,只允许事件继续传播 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingNomalPresenter::OnDrag"); - return true; - } - - bool TraingNomalPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - UNUSED(view); - // 在拖拽结束时判断是否满足退出条件 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingNomalPresenter::OnDragEnd"); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) - { - NavigateBack(); - } - return true; - } - - // 检查GPS相关条件,返回目标视图ID - AppViewId TraingNomalPresenter::CheckGPSAndNavigate() - { - AppViewId targetViewId = VIEW_TRAININGCRAD; - - // 判断是否需要GPS - if (!TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent())) - { - // 不需要GPS,直接进入运动卡片 - return targetViewId; - } - - #if defined(SUPPORT_GNSS) - // 需要GPS,先检查星历是否有效 - bool ephemeris_valid = EphemerisDownloadModel::GetInstance().GetValidityPeriod(); - if (!ephemeris_valid) - { - // 星历无效,进入星历提醒界面 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "星历无效,跳转到星历提醒界面"); - return VIEW_TRAINING_EPHEMERIS_NOTE; - } - - // 星历有效,再检查GPS连接状态 - bool gps_status = TraingModel::GetInstance()->GetGPSConnectState(); - if (!gps_status) - { - // GPS未连接,进入GPS提醒界面 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS未连接,跳转到GPS提醒界面"); - return VIEW_TRAINING_GPSNOTE; - } - - // 星历有效且GPS已连接,可以进入运动卡片 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS条件满足,进入运动卡片"); - #endif - - return targetViewId; - } - - // 清理GPS和心率相关资源 - void TraingNomalPresenter::CleanupGPSResources() - { - // 关闭心率 - TraingModel::GetInstance()->stop_heart_gps(); - #if defined(SUPPORT_GNSS) - // 关闭gps定时器 - TraingModel::GetInstance()->gnss_stop_timer(); - #endif - } - - // 启动运动相关资源 - void TraingNomalPresenter::StartSportResources() - { - // 获取运动项目 - ExerciseClass type = TraingModel::GetInstance()->GetSportId(); - // 开启对应的运动 - TraingCardPresenter::GetInstance()->OpenSensor(type); - // 设置为手表开启运动 - TraingModel::GetInstance()->SetSportOpenWay(false); - } - - bool TraingNomalPresenter::OnClick(UIView &view, const ClickEvent &event) - { - // 根据控件id查找是哪个控件触发了点击回调 - if (strcmp(view.GetViewId(), BUTTONSET) == 0) - { - // 训练准备 -> 训练设置 - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGSET); - return true; - } - - if (strcmp(view.GetViewId(), BUTTONGO) == 0) - { - // 检查GPS条件并确定目标视图 - AppViewId targetViewId = CheckGPSAndNavigate(); - - // 根据目标视图决定后续操作 - if (targetViewId == VIEW_TRAININGCRAD) - { - // 进入运动卡片:设置标志位并启动运动资源,先进入 3 秒运动倒计时 - // CountdownPresenter::SetReturnSlice(VIEW_TRAININGCRAD); - // NativeAbility::GetInstance().EnterSlice(VIEW_SPORT_COUNTDOWN); - enter_flag = true; - StartSportResources(); - // return true; - } - else - { - // 进入提醒界面:设置标志位为false - enter_flag = false; - - } - - // 执行跳转 - NativeAbility::GetInstance().ChangeSlice(targetViewId); - - - return true; - } - - return true; - } - bool TraingNomalPresenter::OnKeyAct(UIView &view, const KeyEvent &event) - { - unsigned short keyID = event.GetKeyId(); - unsigned short keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NavigateBack(); - } - return true; - } - - //修改为秒级定时器更新GPS定位状态 - void TraingNomalPresenter::OnTickEvent() - { - if(TraingNomalView::GetInstance() == nullptr) - { - return; - } - /*判断是否需要GPS*/ - if(TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()) == false) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "该运动项不需要GPS"); - return; - } - //获取gps定位状态 - TraingNomalView::GetInstance()->updateview(); - } -} + + +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "sport_countdown/CountdownPresenter.h" +#include "key/include/KeyInputListener.h" +#include "custom_utils.h" +#include "common/key_code.h" + +#include +#include +#include +#include +#include "traing/include/TraingNomalPresenter.h" +#include "traing/training_card/include/TraingCardPresenter.h" +#include "main/include/MainModel.h" +#include "UiConfig.h" +// #include "TraingNomalView.h" +#ifdef SUPPORT_GNSS +#include "ephemeris_download/include/EphemerisDownloadModel.h" +#endif + + +#if 0 + 点击开始按钮 + ↓ + 检查是否需要GPS + ↓ (需要GPS) + 检查星历是否有效 + ↓ (无效) → 跳转星历提醒界面 + ↓ (有效) + 检查GPS是否连接 + ↓ (未连接) → 跳转GPS提醒界面 + ↓ (已连接) + 跳转运动卡片 +#endif + +#include "NativeRegisterManager.h" +namespace OHOS +{ + + REGIST_SLICE(VIEW_TRAININGNOMAL, TraingNomalView, TraingNomalPresenter); + + // 当前Presenter属性实例化的内存指针 + static TraingNomalPresenter *g_pTraingNomalPresenter = nullptr; + + + TraingNomalPresenter::TraingNomalPresenter() + { + enter_flag = false; + g_pTraingNomalPresenter = this; + } + + TraingNomalPresenter::~TraingNomalPresenter() + { + g_pTraingNomalPresenter = nullptr; + } + + TraingNomalPresenter *TraingNomalPresenter::GetInstance() + { + return g_pTraingNomalPresenter; + } + + void TraingNomalPresenter::OnStart() + { + //判断是否是需要GPS的运动 + if(TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()) == true) + { + #if defined(SUPPORT_GNSS) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开启gps定时器,频率:2秒/点"); + TraingModel::GetInstance()->gnss_start_timer(2 * 1000); // 2秒一个GPS点 + #endif + } + } + + void TraingNomalPresenter::OnResume(void) + { + RootView::GetInstance()->SetOnKeyActListener(this); + } + // 回退逻辑 + void TraingNomalPresenter::NavigateBack() + { + /* + 准备训练界面进入: + 1.[主界面] 进入 + 2.[traing] 进入 + 3.[更多]->[具体训练项]进入 + 4.[设置训练目标]进入 {不返回} + */ + OHOS::AbilityNavigation::Back(); + + // 如果未进入运动卡片(进入的是提醒界面),清理GPS和心率资源 + // enter_flag = true 表示已进入运动卡片,资源由运动卡片管理 + // enter_flag = false 表示进入的是提醒界面,需要清理资源 + if(enter_flag == false){ + CleanupGPSResources(); + } + } + bool TraingNomalPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + // 在拖拽过程中不处理退出,只允许事件继续传播 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingNomalPresenter::OnDrag"); + return true; + } + + bool TraingNomalPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + // 在拖拽结束时判断是否满足退出条件 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingNomalPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + NavigateBack(); + } + return true; + } + + // 检查GPS相关条件,返回目标视图ID + AppViewId TraingNomalPresenter::CheckGPSAndNavigate() + { + AppViewId targetViewId = VIEW_TRAININGCRAD; + + // 判断是否需要GPS + if (!TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent())) + { + // 不需要GPS,直接进入运动卡片 + return targetViewId; + } + + #if defined(SUPPORT_GNSS) + // 需要GPS,先检查星历是否有效 + bool ephemeris_valid = EphemerisDownloadModel::GetInstance().GetValidityPeriod(); + if (!ephemeris_valid) + { + // 星历无效,进入星历提醒界面 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "星历无效,跳转到星历提醒界面"); + return VIEW_TRAINING_EPHEMERIS_NOTE; + } + + // 星历有效,再检查GPS连接状态 + bool gps_status = TraingModel::GetInstance()->GetGPSConnectState(); + if (!gps_status) + { + // GPS未连接,进入GPS提醒界面 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS未连接,跳转到GPS提醒界面"); + return VIEW_TRAINING_GPSNOTE; + } + + // 星历有效且GPS已连接,可以进入运动卡片 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS条件满足,进入运动卡片"); + #endif + + return targetViewId; + } + + // 清理GPS和心率相关资源 + void TraingNomalPresenter::CleanupGPSResources() + { + // 关闭心率 + TraingModel::GetInstance()->stop_heart_gps(); + #if defined(SUPPORT_GNSS) + // 关闭gps定时器 + TraingModel::GetInstance()->gnss_stop_timer(); + #endif + } + + // 启动运动相关资源 + void TraingNomalPresenter::StartSportResources() + { + // 获取运动项目 + ExerciseClass type = TraingModel::GetInstance()->GetSportId(); + // 开启对应的运动 + TraingCardPresenter::GetInstance()->OpenSensor(type); + // 设置为手表开启运动 + TraingModel::GetInstance()->SetSportOpenWay(false); + } + + bool TraingNomalPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONSET) == 0) + { + // 训练准备 -> 训练设置 + OHOS::AbilityNavigation::EnterSlice(VIEW_TRAININGSET); + return true; + } + + if (strcmp(view.GetViewId(), BUTTONGO) == 0) + { + // 检查GPS条件并确定目标视图 + AppViewId targetViewId = CheckGPSAndNavigate(); + + // 根据目标视图决定后续操作 + if (targetViewId == VIEW_TRAININGCRAD) + { + // 进入运动卡片:设置标志位并启动运动资源,先进入 3 秒运动倒计时 + // CountdownPresenter::SetReturnSlice(VIEW_TRAININGCRAD); + // OHOS::AbilityNavigation::EnterSlice(VIEW_SPORT_COUNTDOWN); + enter_flag = true; + StartSportResources(); + // return true; + } + else + { + // 进入提醒界面:设置标志位为false + enter_flag = false; + + } + + // 执行跳转 + NativeAbility::GetInstance().ChangeSlice(targetViewId); + + + return true; + } + + return true; + } + bool TraingNomalPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NavigateBack(); + } + return true; + } + + //修改为秒级定时器更新GPS定位状态 + void TraingNomalPresenter::OnTickEvent() + { + if(TraingNomalView::GetInstance() == nullptr) + { + return; + } + /*判断是否需要GPS*/ + if(TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()) == false) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "该运动项不需要GPS"); + return; + } + //获取gps定位状态 + TraingNomalView::GetInstance()->updateview(); + } +} diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingPresenter.cpp index a3d1b3028..fe7c8049a 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingPresenter.cpp @@ -9,6 +9,7 @@ #include "AppViewIDs.h" #include "key/include/KeyInputListener.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "common/key_code.h" #include "components/ui_label_ext.h" #include "custom_utils.h" @@ -58,7 +59,7 @@ void TraingPresenter::OnResume(void) void TraingPresenter::NavigateBack() { NativeAbility::GetInstance().ChangeSlice( VIEW_APPLIST, TransitionType::TRANSITION_INVALID); - NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素 + OHOS::AbilityNavigation::ClearSliceIdStack(); // 清空所有SLiceId栈元素 } bool TraingPresenter::OnDrag(UIView &view, const DragEvent &event) { return true; @@ -72,18 +73,18 @@ bool TraingPresenter::OnDragEnd(UIView &view, const DragEvent &event) { bool TraingPresenter::OnClick(UIView &view, const ClickEvent &event) { if (strcmp(view.GetViewId(), BUTTON1) == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL); + OHOS::AbilityNavigation::EnterSlice(VIEW_TRAININGNOMAL); TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORWALKING); } if (strcmp(view.GetViewId(), BUTTON3) == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL); + OHOS::AbilityNavigation::EnterSlice(VIEW_TRAININGNOMAL); TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORRUNNING); } if (strcmp(view.GetViewId(), BUTTONMORE) == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGMORE); + OHOS::AbilityNavigation::EnterSlice(VIEW_TRAININGMORE); } if (strcmp(view.GetViewId(), BUTTON2) == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL); + OHOS::AbilityNavigation::EnterSlice(VIEW_TRAININGNOMAL); TraingModel::GetInstance()->SetSportEvent( STR_EXERCISE_FREETRAINING); //修改为自由训练 } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingSetPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingSetPresenter.cpp index a4501004e..cd0d99272 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingSetPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingSetPresenter.cpp @@ -1,230 +1,231 @@ -/*** - * @Date: 2024-04-15 10:55:58 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-04-16 10:29:50 - * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetPresenter.cpp - */ -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "NativeAbility.h" -#include "key/include/KeyInputListener.h" -#include "custom_utils.h" -#include "common/key_code.h" - -#include -#include -#include -#include "traing/include/TraingSetPresenter.h" -#include "traing/training_card/include/TraingCardPresenter.h" -#include "traing/include/TraingModel.h" -#include "uicomponents/UIComponents.h" -// #include "TraingSetView.h" - -#define TAGTEST 0 -#include "NativeRegisterManager.h" -namespace OHOS -{ - - REGIST_SLICE(VIEW_TRAININGSET, TraingSetView, TraingSetPresenter); - - - // 当前Presenter属性实例化的内存指针 - static TraingSetPresenter *g_pTraingSetPresenter = nullptr; - - TraingSetPresenter::TraingSetPresenter() - { - - g_pTraingSetPresenter = this; - } - - TraingSetPresenter::~TraingSetPresenter() - { - - g_pTraingSetPresenter = nullptr; - } - - TraingSetPresenter *TraingSetPresenter::GetInstance() - { - - return g_pTraingSetPresenter; - } - - void TraingSetPresenter::OnStart() - { - - Presenter::OnStart(); - } - - void TraingSetPresenter::OnResume(void) - { - RootView::GetInstance()->SetOnKeyActListener(this); - } - void TraingSetPresenter::NavigateBack() - { - int CardID = TraingSetView::GetInstance()->GetCurrentViewId(); - // 不在设置页面 返回设置列表 - if (CardID != SET_VIEW) - { - TraingSetView::GetInstance()->ChangeView(CardID, SET_VIEW); - } - else - { - NativeAbility::GetInstance().Back(); - } - } - // 增加按键事件 - bool TraingSetPresenter::OnKeyAct(UIView &view, const KeyEvent &event) - { - unsigned short keyID = event.GetKeyId(); - unsigned short keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NavigateBack(); - } - return true; - } - bool TraingSetPresenter::OnDrag(UIView &view, const DragEvent &event) - { - return true; - } - bool TraingSetPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - int CardID = TraingSetView::GetInstance()->GetCurrentViewId(); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) - { - NavigateBack(); - } - UNUSED(view); - return true; - } - /* --------------------------------- 设置目标项处理 -------------------------------- */ - bool TraingSetPresenter::OnClick(UIView &view, const ClickEvent &event) - { - int CardID = TraingSetView::GetInstance()->GetCurrentViewId(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CardID[%d]", CardID); - switch (CardID) - { - case SET_VIEW: - if (strcmp(view.GetViewId(), BUTTONTIME) == 0) - { - TraingSetView::GetInstance()->ChangeView(SET_VIEW, SET_DURATION); - } - else if (strcmp(view.GetViewId(), BUTTONCALULI) == 0) - { - TraingSetView::GetInstance()->ChangeView(SET_VIEW, SET_CALORIES); - } - else if (strcmp(view.GetViewId(), BUTTONDISTANCE) == 0) - { - TraingSetView::GetInstance()->ChangeView(SET_VIEW, SET_DISTANCE); - } - else if (strcmp(view.GetViewId(), BUTTONSTEPS) == 0) - { - TraingSetView::GetInstance()->ChangeView(SET_VIEW, SET_STEPS); - } - break; - case SET_DURATION: - case SET_CALORIES: - case SET_DISTANCE: - case SET_STEPS: - if (strcmp(view.GetViewId(), GetButtonIdFromCard(CardID)) == 0) - { - // 获取训练目标值 - int tag = GetTagFromCard(CardID); - // 配置训练项 - TraingModel::GetInstance()->SetSportTag(GetExerciseTagFromCard(CardID), tag); -#if TAGTEST - TraingModel::GetInstance()->SetSportTag(ExerciseTag::STEP, 10); // 测试 -#endif - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetButtonIdFromCard:%d tag:%d \r\n", CardID, tag); - - // 回退到训练准备 - NativeAbility::GetInstance().Back(); -#if 0 - // 获取训练项目 - ExerciseClass type = TraingModel::GetInstance()->GetSportId(); - // 开启cywee - TraingCardPresenter::GetInstance()->OpenSensor(type); - // 设置为手表开启运动 - TraingModel::GetInstance()->SetSportOpenWay(false); -#endif - } - break; - default: - break; - } - return true; - } - - /** - * @brief 获取按键ID - */ - const char *TraingSetPresenter::GetButtonIdFromCard(int cardID) - { - switch (cardID) - { - case SET_DURATION: - return BUTTONTIMEOK; - case SET_CALORIES: - return BUTTONCALULIOK; - case SET_DISTANCE: - return BUTTONMILEOK; - case SET_STEPS: - return BUTTONSTEPOK; - default: - return ""; - } - } - - /** - * @brief 获取设置目标类型 - */ - ExerciseTag TraingSetPresenter::GetExerciseTagFromCard(int cardID) - { - switch (cardID) - { - case SET_DURATION: - return ExerciseTag::Duration; - case SET_CALORIES: - return ExerciseTag::Calories; - case SET_DISTANCE: - return ExerciseTag::Distance; - case SET_STEPS: - return ExerciseTag::Steps; - default: - return ExerciseTag::UNKNOW; - } - } - - /** - * @brief 获取设置目标 - */ - int TraingSetPresenter::GetTagFromCard(int cardID) - { - int selectedValue = 0; - - switch (cardID) - { - case SET_DURATION: - // 获取时间选择器中选定的时间值,并加1后乘以区间值 - selectedValue = TrainingSetTimeView::GetInstance()->GetTimePicker()->GetSelected(); - return (selectedValue + 1) * TIME_INTERVAL; - case SET_CALORIES: - // 获取卡路里选择器中选定的卡路里值,并加1后乘以区间值 - selectedValue = TrainingSetCaluliView::GetInstance()->GetCaluliPicker()->GetSelected(); - return (selectedValue + 1) * CALORIES_INTERVAL; - case SET_DISTANCE: - // 获取距离选择器中选定的距离值,并加1后乘以区间值 - selectedValue = TrainingSetMileView::GetInstance()->GetMilePicker()->GetSelected(); - return (selectedValue + 1) * DISTANCE_INTERVAL; - case SET_STEPS: - // 获取步数选择器中选定的步数值,并加1后乘以区间值 - selectedValue = TrainingSetStepView::GetInstance()->GetSetpPicker()->GetSelected(); - return (selectedValue + 1) * STEPS_INTERVAL; - default: - return 0; - } - } - -} +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-04-16 10:29:50 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetPresenter.cpp + */ +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "key/include/KeyInputListener.h" +#include "custom_utils.h" +#include "common/key_code.h" + +#include +#include +#include +#include "traing/include/TraingSetPresenter.h" +#include "traing/training_card/include/TraingCardPresenter.h" +#include "traing/include/TraingModel.h" +#include "uicomponents/UIComponents.h" +// #include "TraingSetView.h" + +#define TAGTEST 0 +#include "NativeRegisterManager.h" +namespace OHOS +{ + + REGIST_SLICE(VIEW_TRAININGSET, TraingSetView, TraingSetPresenter); + + + // 当前Presenter属性实例化的内存指针 + static TraingSetPresenter *g_pTraingSetPresenter = nullptr; + + TraingSetPresenter::TraingSetPresenter() + { + + g_pTraingSetPresenter = this; + } + + TraingSetPresenter::~TraingSetPresenter() + { + + g_pTraingSetPresenter = nullptr; + } + + TraingSetPresenter *TraingSetPresenter::GetInstance() + { + + return g_pTraingSetPresenter; + } + + void TraingSetPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingSetPresenter::OnResume(void) + { + RootView::GetInstance()->SetOnKeyActListener(this); + } + void TraingSetPresenter::NavigateBack() + { + int CardID = TraingSetView::GetInstance()->GetCurrentViewId(); + // 不在设置页面 返回设置列表 + if (CardID != SET_VIEW) + { + TraingSetView::GetInstance()->ChangeView(CardID, SET_VIEW); + } + else + { + OHOS::AbilityNavigation::Back(); + } + } + // 增加按键事件 + bool TraingSetPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NavigateBack(); + } + return true; + } + bool TraingSetPresenter::OnDrag(UIView &view, const DragEvent &event) + { + return true; + } + bool TraingSetPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + int CardID = TraingSetView::GetInstance()->GetCurrentViewId(); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + NavigateBack(); + } + UNUSED(view); + return true; + } + /* --------------------------------- 设置目标项处理 -------------------------------- */ + bool TraingSetPresenter::OnClick(UIView &view, const ClickEvent &event) + { + int CardID = TraingSetView::GetInstance()->GetCurrentViewId(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CardID[%d]", CardID); + switch (CardID) + { + case SET_VIEW: + if (strcmp(view.GetViewId(), BUTTONTIME) == 0) + { + TraingSetView::GetInstance()->ChangeView(SET_VIEW, SET_DURATION); + } + else if (strcmp(view.GetViewId(), BUTTONCALULI) == 0) + { + TraingSetView::GetInstance()->ChangeView(SET_VIEW, SET_CALORIES); + } + else if (strcmp(view.GetViewId(), BUTTONDISTANCE) == 0) + { + TraingSetView::GetInstance()->ChangeView(SET_VIEW, SET_DISTANCE); + } + else if (strcmp(view.GetViewId(), BUTTONSTEPS) == 0) + { + TraingSetView::GetInstance()->ChangeView(SET_VIEW, SET_STEPS); + } + break; + case SET_DURATION: + case SET_CALORIES: + case SET_DISTANCE: + case SET_STEPS: + if (strcmp(view.GetViewId(), GetButtonIdFromCard(CardID)) == 0) + { + // 获取训练目标值 + int tag = GetTagFromCard(CardID); + // 配置训练项 + TraingModel::GetInstance()->SetSportTag(GetExerciseTagFromCard(CardID), tag); +#if TAGTEST + TraingModel::GetInstance()->SetSportTag(ExerciseTag::STEP, 10); // 测试 +#endif + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetButtonIdFromCard:%d tag:%d \r\n", CardID, tag); + + // 回退到训练准备 + OHOS::AbilityNavigation::Back(); +#if 0 + // 获取训练项目 + ExerciseClass type = TraingModel::GetInstance()->GetSportId(); + // 开启cywee + TraingCardPresenter::GetInstance()->OpenSensor(type); + // 设置为手表开启运动 + TraingModel::GetInstance()->SetSportOpenWay(false); +#endif + } + break; + default: + break; + } + return true; + } + + /** + * @brief 获取按键ID + */ + const char *TraingSetPresenter::GetButtonIdFromCard(int cardID) + { + switch (cardID) + { + case SET_DURATION: + return BUTTONTIMEOK; + case SET_CALORIES: + return BUTTONCALULIOK; + case SET_DISTANCE: + return BUTTONMILEOK; + case SET_STEPS: + return BUTTONSTEPOK; + default: + return ""; + } + } + + /** + * @brief 获取设置目标类型 + */ + ExerciseTag TraingSetPresenter::GetExerciseTagFromCard(int cardID) + { + switch (cardID) + { + case SET_DURATION: + return ExerciseTag::Duration; + case SET_CALORIES: + return ExerciseTag::Calories; + case SET_DISTANCE: + return ExerciseTag::Distance; + case SET_STEPS: + return ExerciseTag::Steps; + default: + return ExerciseTag::UNKNOW; + } + } + + /** + * @brief 获取设置目标 + */ + int TraingSetPresenter::GetTagFromCard(int cardID) + { + int selectedValue = 0; + + switch (cardID) + { + case SET_DURATION: + // 获取时间选择器中选定的时间值,并加1后乘以区间值 + selectedValue = TrainingSetTimeView::GetInstance()->GetTimePicker()->GetSelected(); + return (selectedValue + 1) * TIME_INTERVAL; + case SET_CALORIES: + // 获取卡路里选择器中选定的卡路里值,并加1后乘以区间值 + selectedValue = TrainingSetCaluliView::GetInstance()->GetCaluliPicker()->GetSelected(); + return (selectedValue + 1) * CALORIES_INTERVAL; + case SET_DISTANCE: + // 获取距离选择器中选定的距离值,并加1后乘以区间值 + selectedValue = TrainingSetMileView::GetInstance()->GetMilePicker()->GetSelected(); + return (selectedValue + 1) * DISTANCE_INTERVAL; + case SET_STEPS: + // 获取步数选择器中选定的步数值,并加1后乘以区间值 + selectedValue = TrainingSetStepView::GetInstance()->GetSetpPicker()->GetSelected(); + return (selectedValue + 1) * STEPS_INTERVAL; + default: + return 0; + } + } + +} diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp index b04029dc9..3dcb7c3fd 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp @@ -2,6 +2,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "sport_countdown/CountdownPresenter.h" #include @@ -73,7 +74,7 @@ namespace OHOS if (strcmp(view.GetViewId(), BUTTONTRAIN) == 0) { CountdownPresenter::SetReturnSlice(VIEW_TRAININGCRAD); - NativeAbility::GetInstance().EnterSlice(VIEW_SPORT_COUNTDOWN); + OHOS::AbilityNavigation::EnterSlice(VIEW_SPORT_COUNTDOWN); ExerciseClass type = TraingModel::GetInstance()->GetSportId(); TraingCardPresenter::GetInstance()->OpenSensor(type); TraingModel::GetInstance()->SetSportOpenWay(false); diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnotePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnotePresenter.cpp index 0b6e3cbb7..16c715221 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnotePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnotePresenter.cpp @@ -3,6 +3,7 @@ #include "components/ui_label_ext.h" #include"ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "sport_countdown/CountdownPresenter.h" #include @@ -93,7 +94,7 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingGPSnotePresenter::OnClick BUTTONGO GPS未定位跳过,也走运动倒计时"); CountdownPresenter::SetReturnSlice(VIEW_TRAININGCRAD); - NativeAbility::GetInstance().EnterSlice(VIEW_SPORT_COUNTDOWN); + OHOS::AbilityNavigation::EnterSlice(VIEW_SPORT_COUNTDOWN); ExerciseClass type = TraingModel::GetInstance()->GetSportId(); TraingCardPresenter::GetInstance()->OpenSensor(type); TraingModel::GetInstance()->SetSportOpenWay(false); diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp index 6601ed471..7ca3a2d52 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp @@ -1,675 +1,676 @@ -/*** - * @Date: 2024-07-06 16:27:31 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-08-02 10:21:14 - * @FilePath: - * /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp - */ -/*** - * @Date: 2024-04-26 09:23:18 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-04-26 10:25:05 - * @FilePath: - * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp - */ - -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" - -#include "ConfigModel.h" -#include "custom_utils.h" -#include "graphic_service.h" -#include "traing/include/TraingModel.h" -#include "traing/training_card/include/TraingCardPresenter.h" -#include "traing/training_card/include/TrainingControlView.h" -#include "uicomponents/UIComponents.h" -#include "vibrator_service.h" -#include "UiConfig.h" - - #include - #include - #include - #include - #include - #include - #include "custom_runtime.h" - - extern "C" void do_cywee_service_check_msg(int cmd, int data[]); - - #define MAXSPORTID 176 - - #define DEFAULT_DASH "--" - #define DATATEST 0 - - extern "C" { - void StartTimer(); - void StopAndResetTimer(); - void PauseTimer(); - void ResumeTimer(); - } - #include "NativeRegisterManager.h" - - #ifdef SUPPORT_CYWEE_SERVICE - #include "cywee_service.h" - #endif - namespace OHOS { - - REGIST_SLICE(VIEW_TRAININGCRAD, TraingCardView, TraingCardPresenter); - - // 当前Presenter属性实例化的内存指针 - static TraingCardPresenter *g_pTraingCardPresenter = nullptr; - - TraingCardPresenter::TraingCardPresenter() { g_pTraingCardPresenter = this; } - - TraingCardPresenter::~TraingCardPresenter() { - // tag_ = 0; - g_pTraingCardPresenter = nullptr; - } - - TraingCardPresenter *TraingCardPresenter::GetInstance() { - static TraingCardPresenter instance; - return &instance; - } - - void TraingCardPresenter::OnStart() { - Presenter::OnStart(); - // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 长亮屏 - } - - void TraingCardPresenter::OnPause(void) { - - Presenter::OnPause(); - } - - void TraingCardPresenter::OnResume(void) { - - Presenter::OnResume(); - RootView::GetInstance()->SetOnKeyActListener(this); - } - - void TraingCardPresenter::OnStop(void) { - - Presenter::OnStop(); - // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 长亮屏 - } - -bool TraingCardPresenter::OnDragStart(UIView &view, const DragEvent &event) { - UNUSED(view); - UNUSED(event); - // 重置标志 - Y_DRAG_FLAG = false; - return false; -} - -bool TraingCardPresenter::OnDrag(UIView &view, const DragEvent &event) { - UNUSED(view); - // 拖动过程中判断是否是垂直滑动:垂直距离大于阈值,且垂直距离大于水平距离的2倍 - if ((event.GetDeltaY() > X_DRAG_OFFSET || event.GetDeltaY() < -X_DRAG_OFFSET) && - (MATH_ABS(event.GetDeltaY()) > (DOUBLES * MATH_ABS(event.GetDeltaX())))) { - Y_DRAG_FLAG = true; // 标记为垂直滑动 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Vertical drag detected (deltaY=%d, deltaX=%d), blocking horizontal swipe", - event.GetDeltaY(), event.GetDeltaX()); - } - return true; -} - -bool TraingCardPresenter::OnDragEnd(UIView &view, const DragEvent &event) { - UNUSED(view); - // 如果检测到垂直滑动,阻止水平滑动 - if (Y_DRAG_FLAG) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Vertical drag ended, blocking horizontal swipe"); - Y_DRAG_FLAG = false; - // 返回true阻止水平滑动事件 - return true; - } - Y_DRAG_FLAG = false; - return false; -} - - // 计时器更新timer - void TraingCardPresenter::ModifiesTime() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ModifiesTime begin"); - std ::string TimeStr = TraingModel::GetInstance()->DisplayMotionDuration(); - - /*灭屏状态不刷新UI*/ - if (uapi_get_screen_state() == 1) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_get_screen_state is off"); - return; - } - - if (TimeStr.empty()) { - WEARABLE_LOGE( - WEARABLE_LOG_MODULE_APP, - "TraingModel::GetInstance()->DisplayMotionDuration() nullptr"); - return; - } - if (TrainingControlView::GetInstance() != nullptr && - TrainingDataView::GetInstance() != nullptr) { - if (TrainingControlView::GetInstance()->GetTimeLabel() != nullptr) { - TrainingControlView::GetInstance()->GetTimeLabel()->SetText( - TimeStr.c_str()); - } - if (TrainingDataView::GetInstance()->GetTimeLabel() != nullptr) { - TrainingDataView::GetInstance()->GetTimeLabel()->SetText(TimeStr.c_str()); - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ModifiesTime end"); - } - } - - //计时器 - void TraingCardPresenter::UpdateTimeOfControl() { - std ::string TimeStr = TraingModel::GetInstance()->DisplayMotionDuration(); - if (TimeStr.empty()) { - WEARABLE_LOGE( - WEARABLE_LOG_MODULE_APP, - "TraingModel::GetInstance()->DisplayMotionDuration() nullptr"); - return; - } - if (TrainingControlView::GetInstance()->GetTimeLabel() != nullptr) { - TrainingControlView::GetInstance()->GetTimeLabel()->SetText( - TimeStr.c_str()); - } - //需要判断是否需要运动是否需要gps - bool isNeedGPS = TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()); - if(isNeedGPS == false) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "该运动项不需要GPS"); - return; - } - - if (TrainingControlView::GetInstance()->GetGpsStatusLabel() != nullptr) { - //获取GPS状态 - bool gpsStatus = TraingModel::GetInstance()->GetGPSConnectState(); - std::string gpsStatusStr; - if (gpsStatus) { - if(ConfigModel::GetInstance()->GetLanguage() == 0) - gpsStatusStr = "GPS定位成功"; - else - gpsStatusStr = "GPS Success"; - TrainingControlView::GetInstance()->GetGpsStatusLabel()->SetTextColor( - Color::Green()); - } else { - if(ConfigModel::GetInstance()->GetLanguage() == 0) - gpsStatusStr = "GPS未定位成功"; - else - gpsStatusStr = "GPS not found"; - TrainingControlView::GetInstance()->GetGpsStatusLabel()->SetTextColor( - Color::Red()); - } - TrainingControlView::GetInstance()->GetGpsStatusLabel()->SetText( - gpsStatusStr.c_str()); - } - } - void TraingCardPresenter::UpdateTimeOfData() { - std ::string TimeStr = TraingModel::GetInstance()->DisplayMotionDuration(); - if (TimeStr.empty()) { - WEARABLE_LOGE( - WEARABLE_LOG_MODULE_APP, - "TraingModel::GetInstance()->DisplayMotionDuration() nullptr"); - return; - } - if (TrainingDataView::GetInstance()->GetTimeLabel() != nullptr) { - TrainingDataView::GetInstance()->GetTimeLabel()->SetText(TimeStr.c_str()); - } - } - - /* --------------------------------- cywee库操作 - * -------------------------------- */ - /*开启cywee*/ - bool TraingCardPresenter::OpenSensor(ExerciseClass type) { - // 防止重复开启 - if (opensensorstuats) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OpenSensor is opening!!"); - return false; - } - // 根据不同的运动项目进行不同的运动 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingCardPresenter::OpenSensor!!"); - #ifdef SUPPORT_CYWEE_SERVICE - switch (type) { - case ExerciseClass::NORMAL: - cywee_sport_mode_change(CYWEE_SERVICE_CMD_NORMAL_MODE); - break; - case ExerciseClass::TREADMILL: - cywee_sport_mode_change(CYWEE_SERVICE_CMD_TREADMILL_MODE); - break; - case ExerciseClass::OUTDOOR: - cywee_sport_mode_change(CYWEE_SERVICE_CMD_OUTDOOR_RUNNING_MODE); - break; - case ExerciseClass::INDOOR: - cywee_sport_mode_change(CYWEE_SERVICE_CMD_INDOOR_RUNNING_MODE); - break; - case ExerciseClass::FITNESS_PEDOMETER: - cywee_sport_mode_change(CYWEE_SERVICE_CMD_FITNESS_PEDOMETER_MODE); - break; - case ExerciseClass::FREE_TRAINING: - cywee_sport_mode_change(CYWEE_SERVICE_CMD_FREE_TRAINING_MODE); - break; - default: - break; - } - #endif - opensensorstuats = true; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OpenSensor--%d!!", type); - return true; - } - - /*控制cywee*/ - bool TraingCardPresenter::ControlSensor(ExerciseState state) { - #ifdef SUPPORT_PPG_SERVICE - switch (state) { - case ExerciseState::End: - // 退出进入普通模式 - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NORMAL_MODE, NULL); - opensensorstuats = false; // 恢复标志位 - StopAndResetTimer(); // 关闭计时器 - break; - case ExerciseState::Pause: - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_PAUSE, 0); - break; - case ExerciseState::Continue: - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_RESUME, 0); - break; - default: - break; - } - #endif - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ControlSensor[%d]!!", state); - return true; - } - - void TraingCardPresenter::RefreshData(SportData *sportdata) { - if (sportdata == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sportdata is null"); - return; - } - - if (TrainingDetailView::GetInstance() == nullptr || - TrainingDataView::GetInstance() == nullptr) - return; - - std::string distanceStr; - if (sportdata->distance != 0) { - double distance_km = - sportdata->distance / 1000.0; // 转换为公里并保留两位小数 - std::stringstream ss; - ss << std::fixed << std::setprecision(2) << distance_km; - distanceStr = ss.str(); - } else { - distanceStr = DEFAULT_DASH; - } - - std::string heartStr = - (sportdata->heart != 0) ? std::to_string(sportdata->heart) : DEFAULT_DASH; - // 配速 pc 单位为秒/公里,显示为 分钟'秒"(如 5'30");慢于 60 分钟/公里时显示 --,避免异常递增 - const int PACE_MAX_SEC_PER_KM = 60 * 60; // 60 分钟/公里 = 3600 秒/公里 - std::string paceStr; - if (sportdata->pc > 0 && sportdata->pc <= PACE_MAX_SEC_PER_KM) { - int min = sportdata->pc / 60; - int sec = sportdata->pc % 60; - std::stringstream ss; - ss << min << "'" << std::setfill('0') << std::setw(2) << sec << "\""; - paceStr = ss.str(); - } else { - paceStr = DEFAULT_DASH; - } - std::string calorieStr = (sportdata->calories != 0) - ? std::to_string(sportdata->calories) - : DEFAULT_DASH; - // 训练强度刷新 - UIResourceTextId intensityid = TraingModel::GetInstance()->GetIntensity(); - TrainingDetailView::GetInstance()->Get_Intensity_Button()->SetTextId( - intensityid); - - TrainingDataView::GetInstance()->GetProgress()->SetValue( - sportdata->goaldegree); // 目标完成度 - TrainingDataView::GetInstance()->GetHeartLabel()->SetText( - heartStr.c_str()); // 心率 - TrainingDetailView::GetInstance()->GetCalorieLabel()->SetText( - calorieStr.c_str()); // 卡路里 - TrainingDetailView::GetInstance()->GetMileLabel()->SetText( - distanceStr.c_str()); // 距离 - TrainingDetailView::GetInstance()->GetStepLabel()->SetText( - paceStr.c_str()); // 配速(原步数位置) - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "[Calories: %s, Distance: %s, Pace: %s Intensityid: %d]", - calorieStr.c_str(), distanceStr.c_str(), paceStr.c_str(), - intensityid); - // 释放sportdata内存 - } - #if 1 - /*刷新 time 和 data */ - void TraingCardPresenter::updataview(void) { - // 如果未开启训练,直接退出 - if (TraingModel::GetInstance()->GetSportState() == ExerciseState::General) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "TraingModel::GetInstance()->GetSportState() == " - "ExerciseState::General "); - return; - } - - if (TraingCardView::GetInstance() == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "view_ == nullptr"); - return; - } - - Control_Card cardId = static_cast( - TraingCardView::GetInstance()->GetCurrentPage()); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "cardId %d", (int)cardId); - - switch (cardId) { - case Control_Card::CONTROL: { - UpdateTimeOfControl(); // 更新控制界面的时间 - break; - } - case Control_Card::DATA: { - UpdateDataView(); // 更新训练数据视图 - break; - } - default: - break; // 其他情况不处理 - } - } - #else - void TraingCardPresenter::Notify(void) { - // 如果未开启训练,直接退出 - if (TraingModel::GetInstance()->GetSportState() == ExerciseState::General || - view_ == nullptr) { - return; - } - - Control_Card cardId = static_cast(view_->GetCurrentPage()); - - switch (cardId) { - case Control_Card::CONTROL: { - UpdateTimeOfControl(); // 更新控制界面的时间 - break; - } - case Control_Card::DATA: { - UpdateDataView(); // 更新训练数据视图 - break; - } - default: - break; // 其他情况不处理 - } - } - #endif - void TraingCardPresenter::UpdateDataView() { - // 刷新计时 - UpdateTimeOfData(); - - // 刷新训练数据视图,显示当前时间 - GraphicService::GetInstance()->PostGraphicEvent(std::bind( - &TrainingDataView::UpdataTime, TrainingDataView::GetInstance())); - - TraingModel::GetInstance()->updata_goal(); - - // 刷新训练数据:心率、卡路里、距离、配速、训练强度、目标完成度 - SportData *sportdata = TraingModel::GetInstance()->GetSportdata(); - RefreshData(sportdata); - } - /* --------------------------------- 点击事件处理 - * --------------------------------- */ - bool TraingCardPresenter::OnClick(UIView &view, const ClickEvent &event) { - const std::string viewId = view.GetViewId(); - - // 定义点击事件映射 - static const std::unordered_map> - actionMap = { - // 暂停按键 - {BUTTONSTOP, - [&]() { - auto currentState = TraingModel::GetInstance()->GetSportState(); - if (currentState == ExerciseState::Continue || - currentState == ExerciseState::Start) { - handlePauseState(); - } else if (currentState == ExerciseState::Pause) { - handleContinueState(); - } - }}, - // 结束按键 - {BUTTONEND, - [&]() { - // ControlSensor(ExerciseState::Pause); - TraingCardView::GetInstance()->SetPopupViewStatus(EndPopup, true); - TraingCardView::GetInstance()->RefreshEndView(); - }}, - // 确定结束 - {BUTTONEXIT, [&]() { handleEndState(); }}, - // 返回 - {BUTTONBACK, - [&]() { - // ControlSensor(ExerciseState::Continue); - TraingCardView::GetInstance()->SetPopupViewStatus(EndPopup, false); - }}, - // 确定达到目标 - {BUTTONWINOK, - [&]() { - TraingCardView::GetInstance()->GetAnimator()->Stop(); - TraingCardView::GetInstance()->SetPopupViewStatus(GetTagPopup, - false); - }}, - // 确定心率提醒 - {BUTTONNOTE, - [&]() { - TraingCardView::GetInstance()->SetPopupViewStatus(HeartPopup, - false); - }}, - }; - - // 查找并执行对应的操作 - auto it = actionMap.find(viewId); - if (it != actionMap.end()) { - it->second(); // 执行操作 - return true; - } - - return false; // 没有匹配的操作 - } - void TraingCardPresenter::OnSwipe(UISwipeView &view) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TempPresenter::OnSwipe "); - UNUSED(view); - return; - } - bool TraingCardPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { - /*消耗按键事件*/ - return true; - } - /* -------------------------------- 协议发起运动处理 - * -------------------------------- */ - #ifdef SUPPORT_BLE_SERVICE - bool TraingCardPresenter::send_sport_cmd(training_ble *cmd) { - if (cmd == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "无效的运动命令 cmd 为空!"); - return false; - } - - // 获取当前的运动状态 - ExerciseState currentState = TraingModel::GetInstance()->GetSportState(); - ExerciseState cmdstate = static_cast(cmd->controlmd); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cmdstate:%d currentState:%d", - cmdstate, currentState); - int m_sportTag = 0; - switch (cmd->controlmd) { - case SETGOAL: - // 仅在一般状态下允许设置目标 - if (currentState == ExerciseState::General) { - if (cmd->sportTagType == 0) { - //训练目标->m 需要转换 km - m_sportTag = cmd->sportTag / 1000; - } else { - m_sportTag = cmd->sportTag; - } - TraingModel::GetInstance()->SetSportTag( - static_cast(cmd->sportTagType), m_sportTag); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "目标设置成功!\r\n"); - return true; - } - break; - - case SENDDATA: - // 随时允许发送实时数据 - TraingModel::GetInstance()->SendLiveData(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "实时数据发送成功!\r\n"); - return true; - - default: - break; - } - - // 仅在一般状态下允许开始运动 - if (cmdstate == ExerciseState::Start) { - if ((currentState == ExerciseState::General)) { - if (TraingCardView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble 开启运动"); - // 设置目标类型和项目有且只有一次 - switch (cmd->sportType) { - case 0: - TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORWALKING); - OpenSensor(ExerciseClass::OUTDOOR); - break; - case 1: - TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORRUNNING); - OpenSensor(ExerciseClass::OUTDOOR); - break; - case 2: - TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORBIKING); - OpenSensor(ExerciseClass::FREE_TRAINING); - break; - default: - break; - } - } - reply_APP_OpenSportModeCmd(true); - // 打印app开启的运动的数据 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"*************app开启运动******************"); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"sportType:%d",cmd->sportType); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"sportTagType:%d",cmd->sportTagType); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"sportTag:%d",cmd->sportTag); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"*******************************"); - handleStartState(); - uapi_set_screen_on_api(); // 亮屏 - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGCRAD); - return true; - } else { - - reply_APP_OpenSportModeCmd(false); - // return false; - } - } - // 仅在运动状态为开始或继续时允许暂停 - if (cmdstate == ExerciseState::Pause) { - if (currentState == ExerciseState::Start || - currentState == ExerciseState::Continue) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble 暂停运动"); - reply_APP_SportPasueResetCmd(TraingModel::GetInstance()->GetSportTime()); - handlePauseState(); - return true; - } - } - - // 仅在暂停状态下允许恢复运动 - if (cmdstate == ExerciseState::Continue && - currentState == ExerciseState::Pause) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble 恢复运动"); - reply_APP_SportPasueResetCmd(TraingModel::GetInstance()->GetSportTime()); - handleContinueState(); - return true; - } - - // 仅在运动状态为开始、继续或暂停时允许结束运动 - if (cmdstate == ExerciseState::End && - (currentState == ExerciseState::Start || - currentState == ExerciseState::Continue || - currentState == ExerciseState::Pause)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble 结束运动"); - uint32_t sport_time = TraingModel::GetInstance()->GetSportTime(); - reply_APP_SportStopModeCmd(sport_time); - handleEndState(); - return true; - } - - // 如果到达这里,命令未执行 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "cmd->sportType[%d],cmd->controlmd[%d],cmd->sportTagType[%d]," - "cmd->sportTag[%d]\r\n", - cmd->sportType, cmd->controlmd, cmd->sportTagType, - cmd->sportTag); - - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "由于状态限制,命令未执行 当前状态 %d。\r\n", currentState); - return false; // 没有执行任何命令 - } - #endif - /*训练结束*/ - void TraingCardPresenter::handleEndState() { - TraingModel::GetInstance()->SetSportState(ExerciseState::End); - ControlSensor(ExerciseState::End); - uapi_set_screen_on_api(); // 亮屏 - #if DATATEST - // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGENDDATA); - // 回退 - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); - return; - #endif - // 是否达到训练目标 - if (TraingModel::GetInstance()->GetMomentum()) { - // 进入训练详情 - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGENDDATA); - NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素 - uapi_dev_runtime_set_train_status_is_end_flag(1); - } else { - // 进入训练记录 - // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING_RECORD); - if (TraingModel::GetInstance()->GetEntryType() == APPLIST_ENTER) - NativeAbility::GetInstance().ChangeSlice( - VIEW_TRAINING, TransitionType::TRANSITION_BACK_TO_HEXAGONS); - else { - NativeAbility::GetInstance().ChangeSlice( - VIEW_MAIN, TransitionType::TRANSITION_BACK_TO_HEXAGONS); - NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素 - } - NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素 - } - } - - /*训练暂停*/ - void TraingCardPresenter::handlePauseState() { - uapi_set_screen_on_api(); // 亮屏 - TrainingControlView::GetInstance()->GetLabel()->SetTextId(STR_RESUME); - TrainingControlView::GetInstance()->GetButton()->SetImageSrc( - SPORT_CONTINUE_IMAGE, SPORT_CONTINUE_IMAGE); - TraingModel::GetInstance()->SetSportState(ExerciseState::Pause); - PauseTimer(); - ControlSensor(ExerciseState::Pause); - } - - /*训练继续*/ - void TraingCardPresenter::handleContinueState() { - uapi_set_screen_on_api(); // 亮屏 - TrainingControlView::GetInstance()->GetLabel()->SetTextId(STR_PAUSE); - TrainingControlView::GetInstance()->GetButton()->SetImageSrc( - SPORT_PAUSE_IMAGE, SPORT_PAUSE_IMAGE); - TraingModel::GetInstance()->SetSportState(ExerciseState::Continue); - ResumeTimer(); - ControlSensor(ExerciseState::Continue); - } - - /*训练开始*/ - void TraingCardPresenter::handleStartState() { - ControlSensor(ExerciseState::Start); - TraingModel::GetInstance()->SetSportOpenWay(true); - //开启心率 - TraingModel::GetInstance()->start_training_heart(); - #if defined(SUPPORT_GNSS) - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开启gps定时器,频率:2秒/点"); - TraingModel::GetInstance()->gnss_start_timer(2 * 1000); // 2秒一个GPS点 - #endif - // 快捷训练都属于健身类 - TraingModel::GetInstance()->SetSportType(Exercisetype::FITNESS); - } - - } // namespace OHOS +/*** + * @Date: 2024-07-06 16:27:31 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-02 10:21:14 + * @FilePath: + * /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp + */ +/*** + * @Date: 2024-04-26 09:23:18 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-04-26 10:25:05 + * @FilePath: + * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp + */ + +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" + +#include "ConfigModel.h" +#include "custom_utils.h" +#include "graphic_service.h" +#include "traing/include/TraingModel.h" +#include "traing/training_card/include/TraingCardPresenter.h" +#include "traing/training_card/include/TrainingControlView.h" +#include "uicomponents/UIComponents.h" +#include "vibrator_service.h" +#include "UiConfig.h" + + #include + #include + #include + #include + #include + #include + #include "custom_runtime.h" + + extern "C" void do_cywee_service_check_msg(int cmd, int data[]); + + #define MAXSPORTID 176 + + #define DEFAULT_DASH "--" + #define DATATEST 0 + + extern "C" { + void StartTimer(); + void StopAndResetTimer(); + void PauseTimer(); + void ResumeTimer(); + } + #include "NativeRegisterManager.h" + + #ifdef SUPPORT_CYWEE_SERVICE + #include "cywee_service.h" + #endif + namespace OHOS { + + REGIST_SLICE(VIEW_TRAININGCRAD, TraingCardView, TraingCardPresenter); + + // 当前Presenter属性实例化的内存指针 + static TraingCardPresenter *g_pTraingCardPresenter = nullptr; + + TraingCardPresenter::TraingCardPresenter() { g_pTraingCardPresenter = this; } + + TraingCardPresenter::~TraingCardPresenter() { + // tag_ = 0; + g_pTraingCardPresenter = nullptr; + } + + TraingCardPresenter *TraingCardPresenter::GetInstance() { + static TraingCardPresenter instance; + return &instance; + } + + void TraingCardPresenter::OnStart() { + Presenter::OnStart(); + // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 长亮屏 + } + + void TraingCardPresenter::OnPause(void) { + + Presenter::OnPause(); + } + + void TraingCardPresenter::OnResume(void) { + + Presenter::OnResume(); + RootView::GetInstance()->SetOnKeyActListener(this); + } + + void TraingCardPresenter::OnStop(void) { + + Presenter::OnStop(); + // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 长亮屏 + } + +bool TraingCardPresenter::OnDragStart(UIView &view, const DragEvent &event) { + UNUSED(view); + UNUSED(event); + // 重置标志 + Y_DRAG_FLAG = false; + return false; +} + +bool TraingCardPresenter::OnDrag(UIView &view, const DragEvent &event) { + UNUSED(view); + // 拖动过程中判断是否是垂直滑动:垂直距离大于阈值,且垂直距离大于水平距离的2倍 + if ((event.GetDeltaY() > X_DRAG_OFFSET || event.GetDeltaY() < -X_DRAG_OFFSET) && + (MATH_ABS(event.GetDeltaY()) > (DOUBLES * MATH_ABS(event.GetDeltaX())))) { + Y_DRAG_FLAG = true; // 标记为垂直滑动 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Vertical drag detected (deltaY=%d, deltaX=%d), blocking horizontal swipe", + event.GetDeltaY(), event.GetDeltaX()); + } + return true; +} + +bool TraingCardPresenter::OnDragEnd(UIView &view, const DragEvent &event) { + UNUSED(view); + // 如果检测到垂直滑动,阻止水平滑动 + if (Y_DRAG_FLAG) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Vertical drag ended, blocking horizontal swipe"); + Y_DRAG_FLAG = false; + // 返回true阻止水平滑动事件 + return true; + } + Y_DRAG_FLAG = false; + return false; +} + + // 计时器更新timer + void TraingCardPresenter::ModifiesTime() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ModifiesTime begin"); + std ::string TimeStr = TraingModel::GetInstance()->DisplayMotionDuration(); + + /*灭屏状态不刷新UI*/ + if (uapi_get_screen_state() == 1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_get_screen_state is off"); + return; + } + + if (TimeStr.empty()) { + WEARABLE_LOGE( + WEARABLE_LOG_MODULE_APP, + "TraingModel::GetInstance()->DisplayMotionDuration() nullptr"); + return; + } + if (TrainingControlView::GetInstance() != nullptr && + TrainingDataView::GetInstance() != nullptr) { + if (TrainingControlView::GetInstance()->GetTimeLabel() != nullptr) { + TrainingControlView::GetInstance()->GetTimeLabel()->SetText( + TimeStr.c_str()); + } + if (TrainingDataView::GetInstance()->GetTimeLabel() != nullptr) { + TrainingDataView::GetInstance()->GetTimeLabel()->SetText(TimeStr.c_str()); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ModifiesTime end"); + } + } + + //计时器 + void TraingCardPresenter::UpdateTimeOfControl() { + std ::string TimeStr = TraingModel::GetInstance()->DisplayMotionDuration(); + if (TimeStr.empty()) { + WEARABLE_LOGE( + WEARABLE_LOG_MODULE_APP, + "TraingModel::GetInstance()->DisplayMotionDuration() nullptr"); + return; + } + if (TrainingControlView::GetInstance()->GetTimeLabel() != nullptr) { + TrainingControlView::GetInstance()->GetTimeLabel()->SetText( + TimeStr.c_str()); + } + //需要判断是否需要运动是否需要gps + bool isNeedGPS = TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()); + if(isNeedGPS == false) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "该运动项不需要GPS"); + return; + } + + if (TrainingControlView::GetInstance()->GetGpsStatusLabel() != nullptr) { + //获取GPS状态 + bool gpsStatus = TraingModel::GetInstance()->GetGPSConnectState(); + std::string gpsStatusStr; + if (gpsStatus) { + if(ConfigModel::GetInstance()->GetLanguage() == 0) + gpsStatusStr = "GPS定位成功"; + else + gpsStatusStr = "GPS Success"; + TrainingControlView::GetInstance()->GetGpsStatusLabel()->SetTextColor( + Color::Green()); + } else { + if(ConfigModel::GetInstance()->GetLanguage() == 0) + gpsStatusStr = "GPS未定位成功"; + else + gpsStatusStr = "GPS not found"; + TrainingControlView::GetInstance()->GetGpsStatusLabel()->SetTextColor( + Color::Red()); + } + TrainingControlView::GetInstance()->GetGpsStatusLabel()->SetText( + gpsStatusStr.c_str()); + } + } + void TraingCardPresenter::UpdateTimeOfData() { + std ::string TimeStr = TraingModel::GetInstance()->DisplayMotionDuration(); + if (TimeStr.empty()) { + WEARABLE_LOGE( + WEARABLE_LOG_MODULE_APP, + "TraingModel::GetInstance()->DisplayMotionDuration() nullptr"); + return; + } + if (TrainingDataView::GetInstance()->GetTimeLabel() != nullptr) { + TrainingDataView::GetInstance()->GetTimeLabel()->SetText(TimeStr.c_str()); + } + } + + /* --------------------------------- cywee库操作 + * -------------------------------- */ + /*开启cywee*/ + bool TraingCardPresenter::OpenSensor(ExerciseClass type) { + // 防止重复开启 + if (opensensorstuats) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OpenSensor is opening!!"); + return false; + } + // 根据不同的运动项目进行不同的运动 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingCardPresenter::OpenSensor!!"); + #ifdef SUPPORT_CYWEE_SERVICE + switch (type) { + case ExerciseClass::NORMAL: + cywee_sport_mode_change(CYWEE_SERVICE_CMD_NORMAL_MODE); + break; + case ExerciseClass::TREADMILL: + cywee_sport_mode_change(CYWEE_SERVICE_CMD_TREADMILL_MODE); + break; + case ExerciseClass::OUTDOOR: + cywee_sport_mode_change(CYWEE_SERVICE_CMD_OUTDOOR_RUNNING_MODE); + break; + case ExerciseClass::INDOOR: + cywee_sport_mode_change(CYWEE_SERVICE_CMD_INDOOR_RUNNING_MODE); + break; + case ExerciseClass::FITNESS_PEDOMETER: + cywee_sport_mode_change(CYWEE_SERVICE_CMD_FITNESS_PEDOMETER_MODE); + break; + case ExerciseClass::FREE_TRAINING: + cywee_sport_mode_change(CYWEE_SERVICE_CMD_FREE_TRAINING_MODE); + break; + default: + break; + } + #endif + opensensorstuats = true; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OpenSensor--%d!!", type); + return true; + } + + /*控制cywee*/ + bool TraingCardPresenter::ControlSensor(ExerciseState state) { + #ifdef SUPPORT_PPG_SERVICE + switch (state) { + case ExerciseState::End: + // 退出进入普通模式 + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NORMAL_MODE, NULL); + opensensorstuats = false; // 恢复标志位 + StopAndResetTimer(); // 关闭计时器 + break; + case ExerciseState::Pause: + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_PAUSE, 0); + break; + case ExerciseState::Continue: + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_RESUME, 0); + break; + default: + break; + } + #endif + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ControlSensor[%d]!!", state); + return true; + } + + void TraingCardPresenter::RefreshData(SportData *sportdata) { + if (sportdata == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sportdata is null"); + return; + } + + if (TrainingDetailView::GetInstance() == nullptr || + TrainingDataView::GetInstance() == nullptr) + return; + + std::string distanceStr; + if (sportdata->distance != 0) { + double distance_km = + sportdata->distance / 1000.0; // 转换为公里并保留两位小数 + std::stringstream ss; + ss << std::fixed << std::setprecision(2) << distance_km; + distanceStr = ss.str(); + } else { + distanceStr = DEFAULT_DASH; + } + + std::string heartStr = + (sportdata->heart != 0) ? std::to_string(sportdata->heart) : DEFAULT_DASH; + // 配速 pc 单位为秒/公里,显示为 分钟'秒"(如 5'30");慢于 60 分钟/公里时显示 --,避免异常递增 + const int PACE_MAX_SEC_PER_KM = 60 * 60; // 60 分钟/公里 = 3600 秒/公里 + std::string paceStr; + if (sportdata->pc > 0 && sportdata->pc <= PACE_MAX_SEC_PER_KM) { + int min = sportdata->pc / 60; + int sec = sportdata->pc % 60; + std::stringstream ss; + ss << min << "'" << std::setfill('0') << std::setw(2) << sec << "\""; + paceStr = ss.str(); + } else { + paceStr = DEFAULT_DASH; + } + std::string calorieStr = (sportdata->calories != 0) + ? std::to_string(sportdata->calories) + : DEFAULT_DASH; + // 训练强度刷新 + UIResourceTextId intensityid = TraingModel::GetInstance()->GetIntensity(); + TrainingDetailView::GetInstance()->Get_Intensity_Button()->SetTextId( + intensityid); + + TrainingDataView::GetInstance()->GetProgress()->SetValue( + sportdata->goaldegree); // 目标完成度 + TrainingDataView::GetInstance()->GetHeartLabel()->SetText( + heartStr.c_str()); // 心率 + TrainingDetailView::GetInstance()->GetCalorieLabel()->SetText( + calorieStr.c_str()); // 卡路里 + TrainingDetailView::GetInstance()->GetMileLabel()->SetText( + distanceStr.c_str()); // 距离 + TrainingDetailView::GetInstance()->GetStepLabel()->SetText( + paceStr.c_str()); // 配速(原步数位置) + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "[Calories: %s, Distance: %s, Pace: %s Intensityid: %d]", + calorieStr.c_str(), distanceStr.c_str(), paceStr.c_str(), + intensityid); + // 释放sportdata内存 + } + #if 1 + /*刷新 time 和 data */ + void TraingCardPresenter::updataview(void) { + // 如果未开启训练,直接退出 + if (TraingModel::GetInstance()->GetSportState() == ExerciseState::General) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "TraingModel::GetInstance()->GetSportState() == " + "ExerciseState::General "); + return; + } + + if (TraingCardView::GetInstance() == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "view_ == nullptr"); + return; + } + + Control_Card cardId = static_cast( + TraingCardView::GetInstance()->GetCurrentPage()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "cardId %d", (int)cardId); + + switch (cardId) { + case Control_Card::CONTROL: { + UpdateTimeOfControl(); // 更新控制界面的时间 + break; + } + case Control_Card::DATA: { + UpdateDataView(); // 更新训练数据视图 + break; + } + default: + break; // 其他情况不处理 + } + } + #else + void TraingCardPresenter::Notify(void) { + // 如果未开启训练,直接退出 + if (TraingModel::GetInstance()->GetSportState() == ExerciseState::General || + view_ == nullptr) { + return; + } + + Control_Card cardId = static_cast(view_->GetCurrentPage()); + + switch (cardId) { + case Control_Card::CONTROL: { + UpdateTimeOfControl(); // 更新控制界面的时间 + break; + } + case Control_Card::DATA: { + UpdateDataView(); // 更新训练数据视图 + break; + } + default: + break; // 其他情况不处理 + } + } + #endif + void TraingCardPresenter::UpdateDataView() { + // 刷新计时 + UpdateTimeOfData(); + + // 刷新训练数据视图,显示当前时间 + GraphicService::GetInstance()->PostGraphicEvent(std::bind( + &TrainingDataView::UpdataTime, TrainingDataView::GetInstance())); + + TraingModel::GetInstance()->updata_goal(); + + // 刷新训练数据:心率、卡路里、距离、配速、训练强度、目标完成度 + SportData *sportdata = TraingModel::GetInstance()->GetSportdata(); + RefreshData(sportdata); + } + /* --------------------------------- 点击事件处理 + * --------------------------------- */ + bool TraingCardPresenter::OnClick(UIView &view, const ClickEvent &event) { + const std::string viewId = view.GetViewId(); + + // 定义点击事件映射 + static const std::unordered_map> + actionMap = { + // 暂停按键 + {BUTTONSTOP, + [&]() { + auto currentState = TraingModel::GetInstance()->GetSportState(); + if (currentState == ExerciseState::Continue || + currentState == ExerciseState::Start) { + handlePauseState(); + } else if (currentState == ExerciseState::Pause) { + handleContinueState(); + } + }}, + // 结束按键 + {BUTTONEND, + [&]() { + // ControlSensor(ExerciseState::Pause); + TraingCardView::GetInstance()->SetPopupViewStatus(EndPopup, true); + TraingCardView::GetInstance()->RefreshEndView(); + }}, + // 确定结束 + {BUTTONEXIT, [&]() { handleEndState(); }}, + // 返回 + {BUTTONBACK, + [&]() { + // ControlSensor(ExerciseState::Continue); + TraingCardView::GetInstance()->SetPopupViewStatus(EndPopup, false); + }}, + // 确定达到目标 + {BUTTONWINOK, + [&]() { + TraingCardView::GetInstance()->GetAnimator()->Stop(); + TraingCardView::GetInstance()->SetPopupViewStatus(GetTagPopup, + false); + }}, + // 确定心率提醒 + {BUTTONNOTE, + [&]() { + TraingCardView::GetInstance()->SetPopupViewStatus(HeartPopup, + false); + }}, + }; + + // 查找并执行对应的操作 + auto it = actionMap.find(viewId); + if (it != actionMap.end()) { + it->second(); // 执行操作 + return true; + } + + return false; // 没有匹配的操作 + } + void TraingCardPresenter::OnSwipe(UISwipeView &view) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TempPresenter::OnSwipe "); + UNUSED(view); + return; + } + bool TraingCardPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { + /*消耗按键事件*/ + return true; + } + /* -------------------------------- 协议发起运动处理 + * -------------------------------- */ + #ifdef SUPPORT_BLE_SERVICE + bool TraingCardPresenter::send_sport_cmd(training_ble *cmd) { + if (cmd == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "无效的运动命令 cmd 为空!"); + return false; + } + + // 获取当前的运动状态 + ExerciseState currentState = TraingModel::GetInstance()->GetSportState(); + ExerciseState cmdstate = static_cast(cmd->controlmd); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cmdstate:%d currentState:%d", + cmdstate, currentState); + int m_sportTag = 0; + switch (cmd->controlmd) { + case SETGOAL: + // 仅在一般状态下允许设置目标 + if (currentState == ExerciseState::General) { + if (cmd->sportTagType == 0) { + //训练目标->m 需要转换 km + m_sportTag = cmd->sportTag / 1000; + } else { + m_sportTag = cmd->sportTag; + } + TraingModel::GetInstance()->SetSportTag( + static_cast(cmd->sportTagType), m_sportTag); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "目标设置成功!\r\n"); + return true; + } + break; + + case SENDDATA: + // 随时允许发送实时数据 + TraingModel::GetInstance()->SendLiveData(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "实时数据发送成功!\r\n"); + return true; + + default: + break; + } + + // 仅在一般状态下允许开始运动 + if (cmdstate == ExerciseState::Start) { + if ((currentState == ExerciseState::General)) { + if (TraingCardView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble 开启运动"); + // 设置目标类型和项目有且只有一次 + switch (cmd->sportType) { + case 0: + TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORWALKING); + OpenSensor(ExerciseClass::OUTDOOR); + break; + case 1: + TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORRUNNING); + OpenSensor(ExerciseClass::OUTDOOR); + break; + case 2: + TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORBIKING); + OpenSensor(ExerciseClass::FREE_TRAINING); + break; + default: + break; + } + } + reply_APP_OpenSportModeCmd(true); + // 打印app开启的运动的数据 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"*************app开启运动******************"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"sportType:%d",cmd->sportType); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"sportTagType:%d",cmd->sportTagType); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"sportTag:%d",cmd->sportTag); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"*******************************"); + handleStartState(); + uapi_set_screen_on_api(); // 亮屏 + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGCRAD); + return true; + } else { + + reply_APP_OpenSportModeCmd(false); + // return false; + } + } + // 仅在运动状态为开始或继续时允许暂停 + if (cmdstate == ExerciseState::Pause) { + if (currentState == ExerciseState::Start || + currentState == ExerciseState::Continue) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble 暂停运动"); + reply_APP_SportPasueResetCmd(TraingModel::GetInstance()->GetSportTime()); + handlePauseState(); + return true; + } + } + + // 仅在暂停状态下允许恢复运动 + if (cmdstate == ExerciseState::Continue && + currentState == ExerciseState::Pause) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble 恢复运动"); + reply_APP_SportPasueResetCmd(TraingModel::GetInstance()->GetSportTime()); + handleContinueState(); + return true; + } + + // 仅在运动状态为开始、继续或暂停时允许结束运动 + if (cmdstate == ExerciseState::End && + (currentState == ExerciseState::Start || + currentState == ExerciseState::Continue || + currentState == ExerciseState::Pause)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble 结束运动"); + uint32_t sport_time = TraingModel::GetInstance()->GetSportTime(); + reply_APP_SportStopModeCmd(sport_time); + handleEndState(); + return true; + } + + // 如果到达这里,命令未执行 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "cmd->sportType[%d],cmd->controlmd[%d],cmd->sportTagType[%d]," + "cmd->sportTag[%d]\r\n", + cmd->sportType, cmd->controlmd, cmd->sportTagType, + cmd->sportTag); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "由于状态限制,命令未执行 当前状态 %d。\r\n", currentState); + return false; // 没有执行任何命令 + } + #endif + /*训练结束*/ + void TraingCardPresenter::handleEndState() { + TraingModel::GetInstance()->SetSportState(ExerciseState::End); + ControlSensor(ExerciseState::End); + uapi_set_screen_on_api(); // 亮屏 + #if DATATEST + // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGENDDATA); + // 回退 + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); + return; + #endif + // 是否达到训练目标 + if (TraingModel::GetInstance()->GetMomentum()) { + // 进入训练详情 + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGENDDATA); + OHOS::AbilityNavigation::ClearSliceIdStack(); // 清空所有SLiceId栈元素 + uapi_dev_runtime_set_train_status_is_end_flag(1); + } else { + // 进入训练记录 + // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING_RECORD); + if (TraingModel::GetInstance()->GetEntryType() == APPLIST_ENTER) + NativeAbility::GetInstance().ChangeSlice( + VIEW_TRAINING, TransitionType::TRANSITION_BACK_TO_HEXAGONS); + else { + NativeAbility::GetInstance().ChangeSlice( + VIEW_MAIN, TransitionType::TRANSITION_BACK_TO_HEXAGONS); + OHOS::AbilityNavigation::ClearSliceIdStack(); // 清空所有SLiceId栈元素 + } + OHOS::AbilityNavigation::ClearSliceIdStack(); // 清空所有SLiceId栈元素 + } + } + + /*训练暂停*/ + void TraingCardPresenter::handlePauseState() { + uapi_set_screen_on_api(); // 亮屏 + TrainingControlView::GetInstance()->GetLabel()->SetTextId(STR_RESUME); + TrainingControlView::GetInstance()->GetButton()->SetImageSrc( + SPORT_CONTINUE_IMAGE, SPORT_CONTINUE_IMAGE); + TraingModel::GetInstance()->SetSportState(ExerciseState::Pause); + PauseTimer(); + ControlSensor(ExerciseState::Pause); + } + + /*训练继续*/ + void TraingCardPresenter::handleContinueState() { + uapi_set_screen_on_api(); // 亮屏 + TrainingControlView::GetInstance()->GetLabel()->SetTextId(STR_PAUSE); + TrainingControlView::GetInstance()->GetButton()->SetImageSrc( + SPORT_PAUSE_IMAGE, SPORT_PAUSE_IMAGE); + TraingModel::GetInstance()->SetSportState(ExerciseState::Continue); + ResumeTimer(); + ControlSensor(ExerciseState::Continue); + } + + /*训练开始*/ + void TraingCardPresenter::handleStartState() { + ControlSensor(ExerciseState::Start); + TraingModel::GetInstance()->SetSportOpenWay(true); + //开启心率 + TraingModel::GetInstance()->start_training_heart(); + #if defined(SUPPORT_GNSS) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开启gps定时器,频率:2秒/点"); + TraingModel::GetInstance()->gnss_start_timer(2 * 1000); // 2秒一个GPS点 + #endif + // 快捷训练都属于健身类 + TraingModel::GetInstance()->SetSportType(Exercisetype::FITNESS); + } + + } // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/Training_CardPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/Training_CardPresenter.cpp index 52ad02ce4..a1aaf4c86 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/Training_CardPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/Training_CardPresenter.cpp @@ -19,6 +19,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "UiConfig.h" @@ -42,26 +43,26 @@ namespace OHOS } if (strcmp(view.GetViewId(), BUTTON1) == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL); + OHOS::AbilityNavigation::EnterSlice(VIEW_TRAININGNOMAL); // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORWALKING); } if (strcmp(view.GetViewId(), BUTTON2) == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL); + OHOS::AbilityNavigation::EnterSlice(VIEW_TRAININGNOMAL); // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); TraingModel::GetInstance()->SetSportEvent( STR_EXERCISE_FREETRAINING); } if (strcmp(view.GetViewId(), BUTTON3) == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL); + OHOS::AbilityNavigation::EnterSlice(VIEW_TRAININGNOMAL); // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORRUNNING); } if (strcmp(view.GetViewId(), BUTTONMORE) == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGMORE); + OHOS::AbilityNavigation::EnterSlice(VIEW_TRAININGMORE); // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE); } // 快捷训练都属于健身类 diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp index 1c506e1da..47b914484 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp @@ -4,6 +4,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" @@ -77,7 +78,7 @@ namespace OHOS { if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } UNUSED(view); return true; @@ -94,7 +95,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); if (viewId < VIEW_MAX_INTER_APP) { - NativeAbility::GetInstance().EnterSlice(viewId); + OHOS::AbilityNavigation::EnterSlice(viewId); return true; } return false; @@ -107,7 +108,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_ball/src/TraingBallPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_ball/src/TraingBallPresenter.cpp index 879f1d0c0..14f1f85ab 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_ball/src/TraingBallPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_ball/src/TraingBallPresenter.cpp @@ -4,6 +4,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" @@ -77,7 +78,7 @@ namespace OHOS { if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } UNUSED(view); return true; @@ -94,7 +95,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); if (viewId < VIEW_MAX_INTER_APP) { - NativeAbility::GetInstance().EnterSlice(viewId); + OHOS::AbilityNavigation::EnterSlice(viewId); return true; } return false; @@ -108,7 +109,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_dance/src/TraingDancePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_dance/src/TraingDancePresenter.cpp index b53d43ba6..693b1f639 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_dance/src/TraingDancePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_dance/src/TraingDancePresenter.cpp @@ -4,6 +4,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" @@ -76,7 +77,7 @@ namespace OHOS { if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } UNUSED(view); return true; @@ -93,7 +94,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); if (viewId < VIEW_MAX_INTER_APP) { - NativeAbility::GetInstance().EnterSlice(viewId); + OHOS::AbilityNavigation::EnterSlice(viewId); return true; } return false; @@ -107,7 +108,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_fitness/src/TraingFitnessPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_fitness/src/TraingFitnessPresenter.cpp index d7bb3e7ae..44de93418 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_fitness/src/TraingFitnessPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_fitness/src/TraingFitnessPresenter.cpp @@ -2,6 +2,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" @@ -74,7 +75,7 @@ namespace OHOS { if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } UNUSED(view); return true; @@ -90,7 +91,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); if (viewId < VIEW_MAX_INTER_APP) { - NativeAbility::GetInstance().EnterSlice(viewId); + OHOS::AbilityNavigation::EnterSlice(viewId); return true; } return false; @@ -104,7 +105,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_ice/src/TraingIcePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_ice/src/TraingIcePresenter.cpp index b7ff8443a..0e3b81505 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_ice/src/TraingIcePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_ice/src/TraingIcePresenter.cpp @@ -4,6 +4,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" @@ -76,7 +77,7 @@ namespace OHOS { if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } UNUSED(view); return true; @@ -92,7 +93,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); if (viewId < VIEW_MAX_INTER_APP) { - NativeAbility::GetInstance().EnterSlice(viewId); + OHOS::AbilityNavigation::EnterSlice(viewId); return true; } return false; @@ -106,7 +107,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_limit/src/TraingLimitPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_limit/src/TraingLimitPresenter.cpp index 143c5dfc4..062237303 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_limit/src/TraingLimitPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_limit/src/TraingLimitPresenter.cpp @@ -1,111 +1,112 @@ - -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "NativeAbility.h" - -#include "key/include/KeyInputListener.h" -#include "custom_utils.h" -#include "common/key_code.h" - -#include -#include -#include -#include "traing/training_list_limit/include/TraingLimitItemView.h" -#include "traing/training_list_limit/include/TraingLimitPresenter.h" -#include "traing/training_list_limit/include/TraingLimitView.h" -#include "traing/include/TraingModel.h" -#include "uicomponents/UIComponents.h" -// #include "TraingLimitView.h" - - -#include "NativeRegisterManager.h" -namespace OHOS -{ - REGIST_SLICE(VIEW_TRAININGLIMIT, TraingLimitView, TraingLimitPresenter); - - extern const char *Limit_buttons[]; - extern char *Limit_text[]; - - // 当前Presenter属性实例化的内存指针 - static TraingLimitPresenter *g_pTraingLimitPresenter = nullptr; - - TraingLimitPresenter::TraingLimitPresenter() - { - p_TraingLimitModel = &TraingLimitModel::GetInstance(); - g_pTraingLimitPresenter = this; - } - - TraingLimitPresenter::~TraingLimitPresenter() - { - - g_pTraingLimitPresenter = nullptr; - } - - TraingLimitPresenter *TraingLimitPresenter::GetInstance() - { - - return g_pTraingLimitPresenter; - } - - void TraingLimitPresenter::OnStart() - { - p_TraingLimitModel->InitTraingLimitListItem(); - if (view_ == nullptr) - { - return; - } - - const TraingLimitItem *itemInfo = p_TraingLimitModel->GetTraingLimitlistItems(); - - view_->RefreshTraingLimitList(itemInfo); - } - - - void TraingLimitPresenter::OnStop(void) - { - - Presenter::OnStop(); - } - bool TraingLimitPresenter::OnDrag(UIView &view, const DragEvent &event) - { - return true; - } - bool TraingLimitPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) - { - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE); - } - UNUSED(view); - return true; - } - - bool TraingLimitPresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(event); - TraingLimitItemView *itemView = static_cast(&view); - AppViewId viewId = itemView->GetTraingLimitIndex(); - UIResourceTextId sportid = itemView->GetTraingLimitId(); - TraingModel::GetInstance()->SetSportEvent(sportid); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); - if (viewId < VIEW_MAX_INTER_APP) - { - NativeAbility::GetInstance().EnterSlice(viewId); - return true; - } - return false; - } - bool TraingLimitPresenter::OnKeyAct(UIView &view, const KeyEvent &event) - { - unsigned short keyID = event.GetKeyId(); - unsigned short keyState = event.GetState(); - - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; - } -} + +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" + +#include "key/include/KeyInputListener.h" +#include "custom_utils.h" +#include "common/key_code.h" + +#include +#include +#include +#include "traing/training_list_limit/include/TraingLimitItemView.h" +#include "traing/training_list_limit/include/TraingLimitPresenter.h" +#include "traing/training_list_limit/include/TraingLimitView.h" +#include "traing/include/TraingModel.h" +#include "uicomponents/UIComponents.h" +// #include "TraingLimitView.h" + + +#include "NativeRegisterManager.h" +namespace OHOS +{ + REGIST_SLICE(VIEW_TRAININGLIMIT, TraingLimitView, TraingLimitPresenter); + + extern const char *Limit_buttons[]; + extern char *Limit_text[]; + + // 当前Presenter属性实例化的内存指针 + static TraingLimitPresenter *g_pTraingLimitPresenter = nullptr; + + TraingLimitPresenter::TraingLimitPresenter() + { + p_TraingLimitModel = &TraingLimitModel::GetInstance(); + g_pTraingLimitPresenter = this; + } + + TraingLimitPresenter::~TraingLimitPresenter() + { + + g_pTraingLimitPresenter = nullptr; + } + + TraingLimitPresenter *TraingLimitPresenter::GetInstance() + { + + return g_pTraingLimitPresenter; + } + + void TraingLimitPresenter::OnStart() + { + p_TraingLimitModel->InitTraingLimitListItem(); + if (view_ == nullptr) + { + return; + } + + const TraingLimitItem *itemInfo = p_TraingLimitModel->GetTraingLimitlistItems(); + + view_->RefreshTraingLimitList(itemInfo); + } + + + void TraingLimitPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + bool TraingLimitPresenter::OnDrag(UIView &view, const DragEvent &event) + { + return true; + } + bool TraingLimitPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE); + } + UNUSED(view); + return true; + } + + bool TraingLimitPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + TraingLimitItemView *itemView = static_cast(&view); + AppViewId viewId = itemView->GetTraingLimitIndex(); + UIResourceTextId sportid = itemView->GetTraingLimitId(); + TraingModel::GetInstance()->SetSportEvent(sportid); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); + if (viewId < VIEW_MAX_INTER_APP) + { + OHOS::AbilityNavigation::EnterSlice(viewId); + return true; + } + return false; + } + bool TraingLimitPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; + } +} diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_more/src/TraingMorePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_more/src/TraingMorePresenter.cpp index f89ca5596..49c130300 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_more/src/TraingMorePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_more/src/TraingMorePresenter.cpp @@ -1,175 +1,176 @@ - - -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "NativeAbility.h" - -#include "key/include/KeyInputListener.h" -#include "custom_utils.h" -#include "common/key_code.h" - -#include -#include -#include -#include "traing/training_list_more/include/TraingMoreItemView.h" -#include "traing/training_list_more/include/TraingMorePresenter.h" -#include "traing/training_list_more/include/TraingMoreView.h" -#include "traing/include/TraingModel.h" -#include "uicomponents/UIComponents.h" -#include "traing/include/TraingModel.h" -// #include "TraingMoreView.h" - -#include "NativeRegisterManager.h" -namespace OHOS -{ - REGIST_SLICE(VIEW_TRAININGMORE, TraingMoreView, TraingMorePresenter); - - extern const char *More_buttons[]; - extern char *More_text[]; - - // 当前Presenter属性实例化的内存指针 - static TraingMorePresenter *g_pTraingMorePresenter = nullptr; - - TraingMorePresenter::TraingMorePresenter() - { - p_TraingMoreModel = &TraingMoreModel::GetInstance(); - g_pTraingMorePresenter = this; - } - - TraingMorePresenter::~TraingMorePresenter() - { - - g_pTraingMorePresenter = nullptr; - } - - TraingMorePresenter *TraingMorePresenter::GetInstance() - { - - return g_pTraingMorePresenter; - } - - void TraingMorePresenter::OnStart() - { - p_TraingMoreModel->InitTraingMoreListItem(); - if (view_ == nullptr) - { - return; - } - - const TraingMoreItem *itemInfo = p_TraingMoreModel->GetTraingMorelistItems(); - - view_->RefreshTraingMoreList(itemInfo); - - } - void TraingMorePresenter::OnResume(void) - { - RootView::GetInstance()->SetOnKeyActListener(this); - if (TraingMoreView::GetInstance()->GetMoreList() != nullptr) - { - TraingMoreView::GetInstance()->GetMoreList()->RequestFocus(); - } - } - - void TraingMorePresenter::NavigateBack() - { - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - - // 根据前一界面切换 - if (preSlice == VIEW_TRAININGENDDATA) - { - if (TraingModel::GetInstance()->GetEntryType() == APPLIST_ENTER) - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING, TransitionType::TRANSITION_BACK_TO_HEXAGONS); - else - { - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TransitionType::TRANSITION_BACK_TO_HEXAGONS); - NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素 - } - } - else - { - NativeAbility::GetInstance().Back(); - } - } - bool TraingMorePresenter::OnDrag(UIView &view, const DragEvent &event) - { - return true; - } - bool TraingMorePresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) - { - NavigateBack(); - } - UNUSED(view); - return true; - } - - bool TraingMorePresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(event); - TraingMoreItemView *itemView = static_cast(&view); - AppViewId viewId = itemView->GetTraingMoreIndex(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); - /* - VIEW_TRAININGLIMIT, // 极限运动列表 - VIEW_TRAININGICE, // 冰上运动列表 - VIEW_TRAININGFITNESS, // 健身运动列表 - VIEW_TRAININGDANCE, // 舞蹈运动列表 - VIEW_TRAININGREST, // 休闲运动列表 - VIEW_TRAININGBALL, // 球类运动列表 - VIEW_TRAININGAQUATIC, // 水上运动列表 - VIEW_TRAININGOTHER, // 其他列表 - */ - // 设置训练类型 - switch (viewId) - { - // case VIEW_TRAININGLIMIT: - // TraingModel::GetInstance()->SetSportType(Exercisetype::EXTREME); - // break; - // case VIEW_TRAININGICE: 冰上运动已去除 - // TraingModel::GetInstance()->SetSportType(Exercisetype::ICE); - // break; - case VIEW_TRAININGFITNESS: - TraingModel::GetInstance()->SetSportType(Exercisetype::FITNESS); - break; - case VIEW_TRAININGDANCE: - TraingModel::GetInstance()->SetSportType(Exercisetype::DANCE); - break; - case VIEW_TRAININGREST: - TraingModel::GetInstance()->SetSportType(Exercisetype::LEISURE); - break; - case VIEW_TRAININGBALL: - TraingModel::GetInstance()->SetSportType(Exercisetype::BALL); - break; - case VIEW_TRAININGOTHER: - TraingModel::GetInstance()->SetSportType(Exercisetype::OTHER); - break; -#if 0 - case VIEW_TRAININGAQUATIC: - TraingModel::GetInstance()->SetSportType(Exercisetype::WATER); - break; -#endif - default: - break; - } - if (viewId < VIEW_MAX_INTER_APP) - { - NativeAbility::GetInstance().EnterSlice(viewId); - return true; - } - return false; - } - bool TraingMorePresenter::OnKeyAct(UIView &view, const KeyEvent &event) - { - unsigned short keyID = event.GetKeyId(); - unsigned short keyState = event.GetState(); - - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NavigateBack(); - } - return true; - } -} + + +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" + +#include "key/include/KeyInputListener.h" +#include "custom_utils.h" +#include "common/key_code.h" + +#include +#include +#include +#include "traing/training_list_more/include/TraingMoreItemView.h" +#include "traing/training_list_more/include/TraingMorePresenter.h" +#include "traing/training_list_more/include/TraingMoreView.h" +#include "traing/include/TraingModel.h" +#include "uicomponents/UIComponents.h" +#include "traing/include/TraingModel.h" +// #include "TraingMoreView.h" + +#include "NativeRegisterManager.h" +namespace OHOS +{ + REGIST_SLICE(VIEW_TRAININGMORE, TraingMoreView, TraingMorePresenter); + + extern const char *More_buttons[]; + extern char *More_text[]; + + // 当前Presenter属性实例化的内存指针 + static TraingMorePresenter *g_pTraingMorePresenter = nullptr; + + TraingMorePresenter::TraingMorePresenter() + { + p_TraingMoreModel = &TraingMoreModel::GetInstance(); + g_pTraingMorePresenter = this; + } + + TraingMorePresenter::~TraingMorePresenter() + { + + g_pTraingMorePresenter = nullptr; + } + + TraingMorePresenter *TraingMorePresenter::GetInstance() + { + + return g_pTraingMorePresenter; + } + + void TraingMorePresenter::OnStart() + { + p_TraingMoreModel->InitTraingMoreListItem(); + if (view_ == nullptr) + { + return; + } + + const TraingMoreItem *itemInfo = p_TraingMoreModel->GetTraingMorelistItems(); + + view_->RefreshTraingMoreList(itemInfo); + + } + void TraingMorePresenter::OnResume(void) + { + RootView::GetInstance()->SetOnKeyActListener(this); + if (TraingMoreView::GetInstance()->GetMoreList() != nullptr) + { + TraingMoreView::GetInstance()->GetMoreList()->RequestFocus(); + } + } + + void TraingMorePresenter::NavigateBack() + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + + // 根据前一界面切换 + if (preSlice == VIEW_TRAININGENDDATA) + { + if (TraingModel::GetInstance()->GetEntryType() == APPLIST_ENTER) + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING, TransitionType::TRANSITION_BACK_TO_HEXAGONS); + else + { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TransitionType::TRANSITION_BACK_TO_HEXAGONS); + OHOS::AbilityNavigation::ClearSliceIdStack(); // 清空所有SLiceId栈元素 + } + } + else + { + OHOS::AbilityNavigation::Back(); + } + } + bool TraingMorePresenter::OnDrag(UIView &view, const DragEvent &event) + { + return true; + } + bool TraingMorePresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + NavigateBack(); + } + UNUSED(view); + return true; + } + + bool TraingMorePresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + TraingMoreItemView *itemView = static_cast(&view); + AppViewId viewId = itemView->GetTraingMoreIndex(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); + /* + VIEW_TRAININGLIMIT, // 极限运动列表 + VIEW_TRAININGICE, // 冰上运动列表 + VIEW_TRAININGFITNESS, // 健身运动列表 + VIEW_TRAININGDANCE, // 舞蹈运动列表 + VIEW_TRAININGREST, // 休闲运动列表 + VIEW_TRAININGBALL, // 球类运动列表 + VIEW_TRAININGAQUATIC, // 水上运动列表 + VIEW_TRAININGOTHER, // 其他列表 + */ + // 设置训练类型 + switch (viewId) + { + // case VIEW_TRAININGLIMIT: + // TraingModel::GetInstance()->SetSportType(Exercisetype::EXTREME); + // break; + // case VIEW_TRAININGICE: 冰上运动已去除 + // TraingModel::GetInstance()->SetSportType(Exercisetype::ICE); + // break; + case VIEW_TRAININGFITNESS: + TraingModel::GetInstance()->SetSportType(Exercisetype::FITNESS); + break; + case VIEW_TRAININGDANCE: + TraingModel::GetInstance()->SetSportType(Exercisetype::DANCE); + break; + case VIEW_TRAININGREST: + TraingModel::GetInstance()->SetSportType(Exercisetype::LEISURE); + break; + case VIEW_TRAININGBALL: + TraingModel::GetInstance()->SetSportType(Exercisetype::BALL); + break; + case VIEW_TRAININGOTHER: + TraingModel::GetInstance()->SetSportType(Exercisetype::OTHER); + break; +#if 0 + case VIEW_TRAININGAQUATIC: + TraingModel::GetInstance()->SetSportType(Exercisetype::WATER); + break; +#endif + default: + break; + } + if (viewId < VIEW_MAX_INTER_APP) + { + OHOS::AbilityNavigation::EnterSlice(viewId); + return true; + } + return false; + } + bool TraingMorePresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NavigateBack(); + } + return true; + } +} diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_other/src/TraingOtherPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_other/src/TraingOtherPresenter.cpp index 9335eb5e2..1221072a7 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_other/src/TraingOtherPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_other/src/TraingOtherPresenter.cpp @@ -19,6 +19,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" @@ -92,7 +93,7 @@ namespace OHOS { if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } UNUSED(view); return true; @@ -108,7 +109,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); if (viewId < VIEW_MAX_INTER_APP) { - NativeAbility::GetInstance().EnterSlice(viewId); + OHOS::AbilityNavigation::EnterSlice(viewId); return true; } return false; @@ -121,7 +122,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_rest/src/TraingRestPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_rest/src/TraingRestPresenter.cpp index 8105b56f4..47db84395 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_rest/src/TraingRestPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_list_rest/src/TraingRestPresenter.cpp @@ -3,6 +3,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "key/include/KeyInputListener.h" #include "custom_utils.h" @@ -77,7 +78,7 @@ namespace OHOS { if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } UNUSED(view); return true; @@ -93,7 +94,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); if (viewId < VIEW_MAX_INTER_APP) { - NativeAbility::GetInstance().EnterSlice(viewId); + OHOS::AbilityNavigation::EnterSlice(viewId); return true; } return false; @@ -107,7 +108,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traingrecord/src/TraingRecordPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traingrecord/src/TraingRecordPresenter.cpp index 017eacd78..a13adeeb2 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traingrecord/src/TraingRecordPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traingrecord/src/TraingRecordPresenter.cpp @@ -8,6 +8,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_string.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include #include @@ -90,12 +91,12 @@ namespace OHOS else { NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TransitionType::TRANSITION_BACK_TO_HEXAGONS); - NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素 + OHOS::AbilityNavigation::ClearSliceIdStack(); // 清空所有SLiceId栈元素 } } else { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } } bool TraingRecordPresenter::OnDrag(UIView &view, const DragEvent &event) @@ -119,7 +120,7 @@ namespace OHOS { if (viewId == BUTTONGO) { - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGMORE); + OHOS::AbilityNavigation::EnterSlice(VIEW_TRAININGMORE); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "go to training"); return true; } @@ -151,7 +152,7 @@ namespace OHOS // 先设置运动数据,确保sportId_被正确更新,然后再进入界面 // 这样OnStart()中调用IsNeedGPS()时能正确判断 TraingModel::GetInstance()->SetSportdata(&sportData); - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGENDDATA); + OHOS::AbilityNavigation::EnterSlice(VIEW_TRAININGENDDATA); uapi_dev_runtime_set_train_status_is_end_flag(1); return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp index f198083b8..0cd97346a 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp @@ -1,6 +1,7 @@ #include "watchQRcode/include/WatchQRCodePresenter.h" #include "watchQRcode/include/WatchQRCodeView.h" #include "NativeAbility.h" +#include "AbilityNavigationApi.h" #include "wearable_log.h" #include "common/key_code.h" #include @@ -103,7 +104,7 @@ namespace OHOS UNUSED(view); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && WatchQRCodePresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); X_DRAG_FLAG = false; } return true; @@ -118,7 +119,7 @@ namespace OHOS // 如果是power键就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); #ifdef SUPPORT_BLE_SERVICE br_adv_start(20); #endif diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp index ac037c0b7..165ee95dd 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp @@ -1,132 +1,133 @@ -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "weather/include/MainWeatherPresenter.h" -#include "common/key_code.h" -#include "common/key_code.h" -#include -#include -#include "UiConfig.h" -#include "gfx_utils/mem_check.h" - -#include "NativeRegisterManager.h" -namespace OHOS -{ - REGIST_MENU_PRO(VIEW_WEATHER, MainWeatherView, MainWeatherPresenter, - PNG_APPLIST_WEATHER_IMAGE_BIG, PNG_APPLIST_WEATHER_IMAGE,PNG_APPLIST_WEATHER_IMAGE, "天气", STR_WEATHER); - - // 当前Presenter属性实例化的内存指针 - static MainWeatherPresenter *g_pMainWeatherPresenter = nullptr; - - MainWeatherPresenter::MainWeatherPresenter() - { - weatherModel = &WeatherModel::GetInstance(); - g_pMainWeatherPresenter = this; -#ifdef MEM_CHECK - MemCheck::GetInstance()->EnableLeakCheck(true); -#endif - } - - MainWeatherPresenter::~MainWeatherPresenter() - { - g_pMainWeatherPresenter = nullptr; -#ifdef MEM_CHECK - MemCheck::GetInstance()->EnableLeakCheck(false); -#endif - } - - MainWeatherPresenter *MainWeatherPresenter::GetInstance() - { - - return g_pMainWeatherPresenter; - } - - void MainWeatherPresenter::OnStart() - { - - } - - void MainWeatherPresenter::OnPause(void) - { - - Presenter::OnPause(); - } - - void MainWeatherPresenter::OnResume(void) - { - RootView::GetInstance()->SetOnKeyActListener(this); - } - - void MainWeatherPresenter::OnStop(void) - { - } - - bool MainWeatherPresenter::OnDrag(UIView &view, const DragEvent &event) - { - UNUSED(view); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - MainWeatherPresenter::X_DRAG_FLAG = true; - } - return true; - } - - bool MainWeatherPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MainWeatherPresenter::OnDragEnd"); - UNUSED(view); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainWeatherPresenter::X_DRAG_FLAG) - { - NativeAbility::GetInstance().Back(); - X_DRAG_FLAG = false; - } - return true; - } - - bool MainWeatherPresenter::OnClick(UIView &view, const ClickEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MainWeatherPresenter::OnClick"); - - UNUSED(view); - UNUSED(event); - return true; - } - - // 增加按键事件 - bool MainWeatherPresenter::OnKeyAct(UIView &view, const KeyEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); - uint16 keyID = event.GetKeyId(); - uint16_t keyState = event.GetState(); - // 如果是power键就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - } - return true; - } - - void MainWeatherPresenter::OnSwipe(UISwipeView &view) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherPresenter::OnSwipe,current tab index = %d", view.GetCurrentPage()); - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the view index = %d,dragging direction = %d,current tab index = %d", view.GetViewIndex(), view.GetDirection(), view.GetCurrentPage()); - if (view.GetCurrentPage() == MAINWEATHERVIEW) - { - WeatherModel::GetInstance().UpdateWeatherCurTime(); - } - } - - void WeatherControlViewOnSwipeListener::OnSwipe(UISwipeView &view) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlViewOnSwipeListener::OnSwipe,current tab index = %d", view.GetCurrentPage()); - // if (view.GetCurrentPage() == MAINWEATHERVIEW) - // { - // view.SetIntercept(false); - // //MainWeatherView::GetInstance()->GetFutureWeatherView()->GetFutureWeatherList()->RefreshList(); - // } - // else - // { - // view.SetIntercept(true); - // } - return; - } +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "AbilityNavigationApi.h" +#include "weather/include/MainWeatherPresenter.h" +#include "common/key_code.h" +#include "common/key_code.h" +#include +#include +#include "UiConfig.h" +#include "gfx_utils/mem_check.h" + +#include "NativeRegisterManager.h" +namespace OHOS +{ + REGIST_MENU_PRO(VIEW_WEATHER, MainWeatherView, MainWeatherPresenter, + PNG_APPLIST_WEATHER_IMAGE_BIG, PNG_APPLIST_WEATHER_IMAGE,PNG_APPLIST_WEATHER_IMAGE, "天气", STR_WEATHER); + + // 当前Presenter属性实例化的内存指针 + static MainWeatherPresenter *g_pMainWeatherPresenter = nullptr; + + MainWeatherPresenter::MainWeatherPresenter() + { + weatherModel = &WeatherModel::GetInstance(); + g_pMainWeatherPresenter = this; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif + } + + MainWeatherPresenter::~MainWeatherPresenter() + { + g_pMainWeatherPresenter = nullptr; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif + } + + MainWeatherPresenter *MainWeatherPresenter::GetInstance() + { + + return g_pMainWeatherPresenter; + } + + void MainWeatherPresenter::OnStart() + { + + } + + void MainWeatherPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void MainWeatherPresenter::OnResume(void) + { + RootView::GetInstance()->SetOnKeyActListener(this); + } + + void MainWeatherPresenter::OnStop(void) + { + } + + bool MainWeatherPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + MainWeatherPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool MainWeatherPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MainWeatherPresenter::OnDragEnd"); + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainWeatherPresenter::X_DRAG_FLAG) + { + OHOS::AbilityNavigation::Back(); + X_DRAG_FLAG = false; + } + return true; + } + + bool MainWeatherPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MainWeatherPresenter::OnClick"); + + UNUSED(view); + UNUSED(event); + return true; + } + + // 增加按键事件 + bool MainWeatherPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + OHOS::AbilityNavigation::Back(); + } + return true; + } + + void MainWeatherPresenter::OnSwipe(UISwipeView &view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherPresenter::OnSwipe,current tab index = %d", view.GetCurrentPage()); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the view index = %d,dragging direction = %d,current tab index = %d", view.GetViewIndex(), view.GetDirection(), view.GetCurrentPage()); + if (view.GetCurrentPage() == MAINWEATHERVIEW) + { + WeatherModel::GetInstance().UpdateWeatherCurTime(); + } + } + + void WeatherControlViewOnSwipeListener::OnSwipe(UISwipeView &view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlViewOnSwipeListener::OnSwipe,current tab index = %d", view.GetCurrentPage()); + // if (view.GetCurrentPage() == MAINWEATHERVIEW) + // { + // view.SetIntercept(false); + // //MainWeatherView::GetInstance()->GetFutureWeatherView()->GetFutureWeatherList()->RefreshList(); + // } + // else + // { + // view.SetIntercept(true); + // } + return; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthMainPage.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthMainPage.cpp index ba5a4c20e..a625c91db 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthMainPage.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthMainPage.cpp @@ -13,6 +13,7 @@ #include "wearable_log.h" #include "UiConfig.h" #include "NativeAbility.h" + #include "AppViewIDs.h" #include "ConfigModel.h" #include "languagecode/LanguageInit.h" diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthPresenter.cpp index 39b52f018..4292d5642 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthPresenter.cpp @@ -14,6 +14,8 @@ #include "womenhealth/include/WomenHealthSettingPage.h" #include "custom_utils.h" #include "NativeRegisterManager.h" +#include "AppViewIDs.h" +#include "AbilityNavigationApi.h" namespace OHOS { @@ -106,7 +108,7 @@ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { if (event.GetPreLastPoint().x - event.GetStartPoint().x > 100) - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } // if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) // { @@ -130,7 +132,7 @@ if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().Back(); + OHOS::AbilityNavigation::Back(); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthSettingPage.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthSettingPage.cpp index fca434495..bb57a608e 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthSettingPage.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/womenhealth/src/WomenHealthSettingPage.cpp @@ -10,6 +10,7 @@ #include "womenhealth/include/WomenHealthPresenter.h" #include "womenhealth/include/WomenHealthView.h" #include "NativeAbility.h" +#include "AppViewIDs.h" #include "SlicePageFactory.h" #include "UiConfig.h" #include "wearable_log.h" -- 2.17.1