From: Caisking <3449750381@qq.com> Date: Mon, 8 Apr 2024 03:33:42 +0000 (+0800) Subject: 合并602Patch X-Git-Tag: release_V1.2.70_20241020_135402~1200^2~28 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=4ffd7894e69d766bc5a42d13239cc861b9ab277f;p=mirrors%2FFD230.git 合并602Patch --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 6a1bb4232..08e498629 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -5,6 +5,7 @@ set(UI_SAMPLE_ROOT ${ROOT_DIR}/middleware/services/gui/uikit/sample/uitest) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/nativelauncher/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativelauncher/include/slices/main ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/screennotify/include ) @@ -31,6 +32,10 @@ set(PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/temperature/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/offlinevoice/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/settings/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_desktop/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_dial/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/key/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phone/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/player/include @@ -68,6 +73,8 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits ${ROOT_DIR}/middleware/services/gui/lvgl/src/hal + ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/events + ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits/gfx_utils @@ -113,11 +120,16 @@ set(PRIVATE_HEADER ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audiomanager/interfaces/kits/audiocommon ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/player/interfaces/kits/ ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/utils/include + ${ROOT_DIR}/open_source/openharmony/utils/native/lite/include + ${ROOT_DIR}/open_source/openharmony/utils/native/lite/kv_store/innerkits ) set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativelauncher/src/NativeLauncher.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativelauncher/src/slices/main/MainPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativelauncher/src/slices/main/MainView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/MainViewSample.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/MainModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/MainPresenterSample.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/ModelListenerSample.cpp @@ -246,7 +258,26 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/settings/src/SettingView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/settings/src/SettingModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/settings/src/SettingItemView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_desktop/src/SetDesktopModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_desktop/src/SetDesktopPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_desktop/src/SetDesktopView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardAdapter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardItem.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardNoCardView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_card/src/SetCardDeleteView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/src/AddCardAdapter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/src/AddCardItem.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/src/AddCardModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/src/AddCardPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/add_card/src/AddCardView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_dial/src/SetDialModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_dial/src/SetDialPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_dial/src/SetDialView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/key/src/KeyInputListener.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/screennotify/src/ui_screennotify.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heart_blood/src/BloodCardView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heart_blood/src/HeartCardView.cpp @@ -394,6 +425,9 @@ set(SOURCES ${UI_SAMPLE_ROOT}/components/ui_test_cube_rotate/cube_rotate_view.cpp ${UI_SAMPLE_ROOT}/components/ui_test_cube_rotate/ui_test_cube_rotate.cpp ${UI_SAMPLE_ROOT}/components/ui_test_video_play/ui_test_video_play.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_hexagons_list/ui_test_hexagons_list.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_coverflow/ui_test_coverflow.cpp + ${UI_SAMPLE_ROOT}/components/ui_test_kaleidoscope/ui_test_kaleidoscope.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialRotateImgView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialOptionImgView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 4e8818d6e..f2982be75 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -122,7 +122,11 @@ typedef enum : uint16_t #ifdef SUPPORT_ALIPAY_SEC VIEW_MAIN_ALIPAY, #endif - VIEW_MAX_INTER_APP, // 在此之前添加native应用ID. + VIEW_SET_DESKTOP, + VIEW_SET_CARD, + VIEW_ADD_CARD, + VIEW_SET_DIAL, + VIEW_MAX_INTER_APP, // 在此之前添加native应用ID. VIEW_EXTERN_APP = 0xFFFE, // 三方应用 VIEW_INVALIDE_APP = 0xFFFF, } AppViewId; @@ -130,8 +134,7 @@ typedef enum : uint16_t /* * Slice页面优先级,越小优先级越高 */ -typedef enum : uint16_t -{ +typedef enum : uint16_t { PRIO_0 = 0, PRIO_1, PRIO_2, diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 830bad2a0..7d9210b47 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -11,6 +11,12 @@ namespace OHOS public: static NativeLauncher &GetInstance(void); void InitNativeLauncher(void); + void InitMainSlice(void); + void InitSetDesktopSlice(void); + void InitSetCardSlice(void); + void InitAddCardSlice(void); + void InitSetDialSlice(void); + void InitMainSampleSlice(void); void InitSettingSlice(void); void InitApplistSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h index 757e573d4..85fd3e91a 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h @@ -12,11 +12,28 @@ #include "ohos_types.h" #include "graphic_config.h" -namespace OHOS -{ -#ifndef UNUSED -#define UNUSED(x) ((void)(x)) -#endif +namespace OHOS { + static const int CARD_SETTING_COUNT_MAX = 5; + typedef enum { + WATCH_FACE = 0, /* 主表盘枚举值不能修改 */ + HEART_RATE, + COMPASS, + ACTIVITY, + MUSIC_PLAYER, + WEATHER, + BLOODOXGEN, + TRAINING, + MAX_CARD, + } CardId; + + typedef enum { + DIAL_CLOCK = 0, + DIAL_MAX, + } DialId; + + #ifndef UNUSED + #define UNUSED(x) ((void)(x)) + #endif #define LA_HORIZONTAL_RESOLUTION 400 // watch width #define LA_VERTICAL_RESOLUTION 400 // watch height @@ -36,9 +53,10 @@ namespace OHOS #define X_DRAG_OFFSET 20 #define DOUBLES 2 -#define APP_RES_PATH "/user/res" -#define APP_MUSIC_PATH "/user/music" -#define APP_VIDEO_PATH "/user/video" + #define APP_RES_PATH "/user/res" + #define APP_MUSIC_PATH "/user/music" + #define APP_VIDEO_PATH "/user/video" + #define APP_DIAL_PATH "/user/dial" static constexpr const char *CARD_CONFIG_PATH = "/user/cardconfig.bin"; static constexpr const char *CLOCK_IAMGES = APP_RES_PATH "/clock/clock.bin"; @@ -311,6 +329,19 @@ namespace OHOS static constexpr const char *PNG_SELECTION_BOX = APP_RES_PATH "/SELECTION_BOX.bin"; static constexpr const char *PNG_GANTAN = APP_RES_PATH "/GANTAN.bin"; static constexpr const char *PNG_RIGHT = APP_RES_PATH "/RIGHT.bin"; + /* -------------------------------------------------------------------------- */ + static constexpr const char *PNG_SETTTING_DESKTOP_IMAGE = APP_RES_PATH"/SETTTING_DESKTOP.bin"; + static constexpr const char *PNG_SET_DESKTOP_LIST_IMAGE = APP_RES_PATH"/SET_DESKTOP_LIST.bin"; + static constexpr const char *PNG_SET_DESKTOP_HEXAGONS_IMAGE = APP_RES_PATH"/SET_DESKTOP_HEXAGONS.bin"; + static constexpr const char *PNG_SET_DESKTOP_BG_IMAGE = APP_RES_PATH"/SET_DESKTOP_BG.bin"; + static constexpr const char *PNG_SET_CARD_ADD = APP_RES_PATH"/CARD_ADD.bin"; + static constexpr const char *PNG_SET_CARD_DEL = APP_RES_PATH"/CARD_DEL.bin"; + static constexpr const char *PNG_SET_CARD_HEART = APP_RES_PATH"/CARD_HEART.bin"; + static constexpr const char *PNG_SET_CARD_COMPASS = APP_RES_PATH"/CARD_COMPASS.bin"; + static constexpr const char *PNG_SET_CARD_ACTIVITY = APP_RES_PATH"/CARD_ACTIVITY.bin"; + static constexpr const char *PNG_SET_CARD_PLAYER = APP_RES_PATH"/CARD_PLAYER.bin"; + static constexpr const char *PNG_SET_DIAL_CLOCK = APP_RES_PATH"/DIAL_CLOCK.bin"; + } #endif // UI_CONFIG_H diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/slices/main/MainPresenter.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/slices/main/MainPresenter.h new file mode 100644 index 000000000..7e25bbdbe --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/slices/main/MainPresenter.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020-2021 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 MAIN_PRESENTER_H +#define MAIN_PRESENTER_H + +#include "Presenter.h" + +namespace OHOS { +class MainView; +class MainPresenter : public Presenter { +public: + MainPresenter(); + virtual ~MainPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; +}; +} + +#endif // MAIN_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/slices/main/MainView.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/slices/main/MainView.h new file mode 100644 index 000000000..6a13caea8 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/slices/main/MainView.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020-2021 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 MAIN_VIEW_H +#define MAIN_VIEW_H + +#include + +#include "View.h" +#include "window/window.h" +#include "components/ui_label.h" +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" + +#include "BaseView.h" +#include "ChangeSliceListener.h" + +namespace OHOS { +#define LA_HORIZONTAL_RESOLUTION 400 // watch width +#define LA_VERTICAL_RESOLUTION 400 // watch height +#define NORMAL_BUTTON_WIDTH 100 // normal button width +#define NORMAL_BUTTON_HEIGHT 50 // normal button height +#define UN_OPACITY 255 // UN_OPACITY +#define FONT_COMMON 20 // 20px + +class MainPresenter; +class MainView : public View { +public: + MainView(); + virtual ~MainView(); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; +}; +} // namespace OHOS +#endif // MAIN_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index ae32d0041..a27e9d6d4 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -16,6 +16,8 @@ #include "DialModelCharge.h" #include "NativeLauncher.h" +#include "MainView.h" +#include "MainPresenter.h" #include "SliceProxy.h" #include "AbilitySliceProxy.h" #include "wearable_log.h" @@ -222,13 +224,24 @@ #include "AlipayMainView.h" #include "AlipayPresenter.h" #endif -namespace OHOS +#include "SetDesktopView.h" +#include "SetDesktopPresenter.h" +#include "SetCardView.h" +#include "SetCardPresenter.h" +#include "AddCardView.h" +#include "AddCardPresenter.h" +#include "SetDialView.h" +#include "SetDialPresenter.h" +#ifdef JS_ENABLE +#include "product_adapter.h" +#endif + +namespace OHOS { +struct AppViewMapper { - struct AppViewMapper - { - AppViewId id; - void (NativeLauncher::*func)(void); - }; + AppViewId id; + void (NativeLauncher::*func)(void); +}; struct ViewIdToString { @@ -325,7 +338,10 @@ namespace OHOS #ifdef SUPPORT_ALIPAY_SEC {VIEW_MAIN_ALIPAY, &NativeLauncher::InitMainAlipaySlice}, #endif - + {VIEW_SET_DESKTOP, &NativeLauncher::InitSetDesktopSlice}, + {VIEW_SET_CARD, &NativeLauncher::InitSetCardSlice}, + {VIEW_ADD_CARD, &NativeLauncher::InitAddCardSlice}, + {VIEW_SET_DIAL, &NativeLauncher::InitSetDialSlice}, #if 0 {VIEW_MAIN_ACTIVITY, &NativeLauncher::InitActivitySlice}, {VIEW_OFFLINEVOICE, &NativeLauncher::InitOfflineVoice}, @@ -362,6 +378,9 @@ namespace OHOS void NativeLauncher::InitNativeLauncher() { + #ifdef JS_ENABLE + ACELite::ProductAdapter::SetScreenSize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); +#endif ConfigModel::GetInstance()->Init(); // 初始化语言 GraphicStartUp::InitFontEngine(MEM_POOL_UI_FONT, MEM_POOL_UI_FONT_SIZE, OHOS::VECTOR_FONT_DIR, DEFAULT_VECTOR_FONT_FILENAME); @@ -379,7 +398,7 @@ namespace OHOS PresenterTask::GetInstance()->Init(); PlayersModel::GetInstance()->AudioInit(); ActivityModel::GetInstance()->Init(); - ScreenModels::GetInstance()->InitCardConfig(); + ScreenModels::GetInstance()->InitKvStorage(); VocassistModel::GetInstance()->Init(); HeartModel::GetInstance()->Init(); BluetoothModel::GetInstance()->Init(); @@ -1115,5 +1134,54 @@ namespace OHOS } NativeAbility::GetInstance().AddSliceProxy(VIEW_MAIN_STOPWATCH, mainstopwatch); } - + + /* -------------------------------------------------------------------------- */ + void NativeLauncher::InitSetDesktopSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSetDesktopSlice"); + SliceProxy *setDesktopView = new AbilitySliceProxy; + if (setDesktopView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "setDesktopView"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SET_DESKTOP, setDesktopView); + } + + void NativeLauncher::InitSetCardSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSetCardSlice"); + SliceProxy *setCardView = new AbilitySliceProxy; + if (setCardView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "setCardView"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SET_CARD, setCardView); + } + + void NativeLauncher::InitAddCardSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitAddCardSlice"); + SliceProxy *addCardView = new AbilitySliceProxy; + if (addCardView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addCardView"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_ADD_CARD, addCardView); + } + + void NativeLauncher::InitSetDialSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSetDialSlice"); + SliceProxy *setDialView = new AbilitySliceProxy; + if (setDialView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "setCardView"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SET_DIAL, setDialView); + } + } diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/slices/main/MainPresenter.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/slices/main/MainPresenter.cpp new file mode 100644 index 000000000..dbfac37c0 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/slices/main/MainPresenter.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020-2021 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 "MainPresenter.h" +#include "MainView.h" + +namespace OHOS { + +MainPresenter::MainPresenter() {} + +MainPresenter::~MainPresenter() {} + +void MainPresenter::OnStart() +{ + Presenter::OnStart(); +} + +void MainPresenter::OnPause(void) +{ +} + +void MainPresenter::OnResume(void) +{ +} + +void MainPresenter::OnStop(void) +{ +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/slices/main/MainView.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/slices/main/MainView.cpp new file mode 100644 index 000000000..3e79969e1 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/slices/main/MainView.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2020-2021 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 "MainView.h" +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" + +#include "wearable_log.h" + +namespace OHOS { +MainView::MainView(){} + +MainView::~MainView(){} + +void MainView::OnStart() +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "MainView::OnStart"); + View::OnStart(); + + BaseView::RootView(Color::Black().full); + + UILabel *goSettings = new UILabel(); + goSettings->SetText("Settings"); + goSettings->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_COMMON); + goSettings->SetPosition(35, LA_VERTICAL_RESOLUTION); + goSettings->Resize(NORMAL_BUTTON_WIDTH, NORMAL_BUTTON_HEIGHT); + goSettings->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + goSettings->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + goSettings->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); + goSettings->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full); + goSettings->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + goSettings->SetStyle(STYLE_BORDER_RADIUS, 4); + goSettings->SetTouchable(true); + goSettings->SetOnTouchListener(new ChangeSliceListener(VIEW_MAIN)); + + UILabel *goAppList = new UILabel(); + goAppList->SetText("App List"); + goAppList->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_COMMON); + goAppList->SetPosition(165, LA_VERTICAL_RESOLUTION); + goAppList->Resize(NORMAL_BUTTON_WIDTH, NORMAL_BUTTON_HEIGHT); + goAppList->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + goAppList->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + goAppList->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); + goAppList->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full); + goAppList->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + goAppList->SetStyle(STYLE_BORDER_RADIUS, 4); + goAppList->SetTouchable(true); + goAppList->SetOnTouchListener(new ChangeSliceListener(VIEW_MAIN)); + + RootView::GetInstance()->Add(goSettings); + RootView::GetInstance()->Add(goAppList); +} + +void MainView::OnSetUpView() +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "MainView::OnSetUpView"); + View::OnSetUpView(); + + UIViewGroup *group = new UIViewGroup(); + group->SetPosition(0, 0, LA_HORIZONTAL_RESOLUTION, LA_VERTICAL_RESOLUTION); + group->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + + RootView::GetInstance()->Add(group); + Draw(); +} + +void MainView::OnTearDownView() +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "MainView::OnTearDownView"); + View::OnTearDownView(); + return; +} + +void MainView::OnStop() +{ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "MainView::OnStop"); + View::OnStop(); + + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + + RootView::GetInstance()->ClearOnKeyActListener(); + RootView::GetInstance()->RemoveAll(); + return; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardAdapter.h b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardAdapter.h new file mode 100644 index 000000000..34882c939 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardAdapter.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardAdapter.h + * Author: + * Create: 2021-09-18 + */ + +#ifndef ADD_CARD_ADAPTER_H +#define ADD_CARD_ADAPTER_H + +#include +#include +#include "components/ui_list.h" +#include "components/ui_label.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/abstract_adapter.h" +#include "UiConfig.h" +#include "wearable_log.h" +#include "AddCardItem.h" + +namespace OHOS { +class AddCardAdapter : public AbstractAdapter { +public: + explicit AddCardAdapter(); + virtual ~AddCardAdapter(); + + virtual uint16 GetCount(void) override; + + virtual UIView *GetView(UIView *inView, int16 index) override; + + virtual void AddListItem(const AddCardInfo &item); + + void SetItemClickListener(UIView::OnClickListener *itemClickListener) + { + itemClickListener_ = itemClickListener; + } + + void ClearItem(void); + +private: + std::list listData_; + UIView::OnClickListener *itemClickListener_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardItem.h b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardItem.h new file mode 100644 index 000000000..5ce44d585 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardItem.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardItem.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef ADD_CARD_ITEM_H +#define ADD_CARD_ITEM_H + +#include +#include +#include "components/ui_view.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button.h" +#include "UiConfig.h" + +namespace OHOS { +typedef struct { + CardId id; + bool addFlag; + const char *cardImg; +} AddCardInfo; + +class AddCardItem :public UIViewGroup { +public: + AddCardItem(); + virtual ~AddCardItem(); + void SetItemInfo(const AddCardInfo &cardInfo); + void SetOnClickListener(OnClickListener *onClickListener); + void UpdateItemInfo(bool addFlag); +private: + void SetUpChild(); + UIImageView cardImg_; + UILabelButton cardLabel_; + AddCardInfo cardInfo_; +}; + +} + +#endif // ADD_CARD_ITEM_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardModel.h b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardModel.h new file mode 100644 index 000000000..ae17e1a0f --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardModel.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardModel.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef ADD_CARD_MODEL_H +#define ADD_CARD_MODEL_H + +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "AddCardPresenter.h" +#include "MainModel.h" + +namespace OHOS { + class AddCardModel { + public: + static AddCardModel &GetInstance(void); + void SetSelectedCardIndex(uint8_t cardIndex); + uint8_t GetSelectedCardIndex(void) const; + void AddCardSetting(void); + private: + AddCardModel(); + AddCardModel(const AddCardModel &); + AddCardModel &operator=(const AddCardModel &); + virtual ~AddCardModel(); + uint8_t selectedCardIndex{0}; + + }; +} + +#endif // ADD_CARD_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardPresenter.h new file mode 100644 index 000000000..f8e6f885b --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardPresenter.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardPresenter.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef ADD_CARD_PRESENTER_H +#define ADD_CARD_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_list.h" +#include "components/ui_view.h" +#include "KeyInputListener.h" + +namespace OHOS { +static const char *ADD_CARD_ADD = "addcardadd"; +class AddCardView; +class AddCardModel; +class AddCardPresenter : public Presenter, + public UIView::OnClickListener, public UIView::OnDragListener, + public ListScrollListener { +public: + AddCardPresenter(); + virtual ~AddCardPresenter(); + + virtual void OnStart() override; + virtual void OnResume() override; + virtual void OnStop() override; + + bool OnClick(UIView &view, const ClickEvent &event) override; + virtual void OnScrollStart(int16_t index, UIView *view) override; + virtual void OnScrollEnd(int16_t index, UIView *view) override; + virtual void OnItemSelected(int16_t index, UIView* view) override; + virtual bool OnDrag(UIView& view, const DragEvent& event) override; +private: + KeyInputListener *keyActListenr{nullptr}; + AddCardModel *model{nullptr}; + +}; +} + +#endif // ADD_CARD_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardView.h b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardView.h new file mode 100644 index 000000000..63d51bba5 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardView.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardView.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef ADD_CARD_VIEW_H +#define ADD_CARD_VIEW_H + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +#include "window/window.h" +#include "BaseView.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "AddCardAdapter.h" +#include "AddCardModel.h" + +namespace OHOS { +class AddCardPresenter; + +class AddCardView : public View { +public: + AddCardView(); + virtual ~AddCardView(); + + static AddCardView *GetInstance() + { + static AddCardView instance; + return &instance; + } + + virtual void OnStart() override; + virtual void OnSetUpView() override; + virtual void OnTearDownView() override; + virtual void OnStop() override; + void RefreshCardList(void); +private: + void SetUpListInfo(void); + void SetUpListView(void); + UIList contentList_; + AddCardAdapter *addCardAdapter_{nullptr}; +}; +} +#endif // ADD_CARD_VIEW_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardAdapter.cpp new file mode 100644 index 000000000..d92f38ddb --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardAdapter.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardAdapter.cpp + * Author: + * Create: 2021-09-18 + */ + +#include "AddCardAdapter.h" + +namespace OHOS { +AddCardAdapter::AddCardAdapter() {} + +AddCardAdapter::~AddCardAdapter() +{ + listData_.clear(); +} + +uint16 AddCardAdapter::GetCount(void) +{ + return listData_.size(); +} + +void AddCardAdapter::ClearItem(void) +{ + listData_.clear(); +} + +UIView *AddCardAdapter::GetView(UIView *inView, int16 index) +{ + if (index >= (int16)listData_.size() || index < 0) { + return nullptr; + } + + std::list::iterator it = listData_.begin(); + for (int i = 0; i < index; i++) { + it++; + } + + AddCardItem *item = nullptr; + if (inView == nullptr) { + item = new AddCardItem(); + if (item == nullptr) { + return nullptr; + } + } else { + item = static_cast(inView); + } + + item->SetItemInfo(*it); + item->SetViewIndex(index); + item->SetOnClickListener(itemClickListener_); + return item; +} + +void AddCardAdapter::AddListItem(const AddCardInfo &item) +{ + listData_.push_back(item); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardItem.cpp b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardItem.cpp new file mode 100644 index 000000000..67e287ec8 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardItem.cpp @@ -0,0 +1,58 @@ +#include "AddCardItem.h" +#include "AddCardPresenter.h" +#include "wearable_log.h" + +namespace OHOS { + AddCardItem::AddCardItem() + { + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + SetUpChild(); + Add(&cardImg_); + Add(&cardLabel_); + } + + AddCardItem::~AddCardItem() + { + Remove(&cardImg_); + Remove(&cardLabel_); + } + + void AddCardItem::SetUpChild() + { + cardImg_.SetPosition(87, 60); + cardImg_.Resize(280, 280); + cardImg_.SetResizeMode(UIImageView::FILL); + cardImg_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + cardLabel_.SetPosition(175, 360); + cardLabel_.Resize(100, 50); + cardLabel_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + } + + void AddCardItem::SetItemInfo(const AddCardInfo &cardInfo) + { + cardInfo_ = cardInfo; + cardImg_.SetSrc(cardInfo.cardImg); + if (cardInfo.addFlag) { + cardLabel_.SetText("已添加"); + } else { + cardLabel_.SetText("添加"); + } + } + + void AddCardItem::UpdateItemInfo(bool addFlag) + { + if (addFlag) { + cardLabel_.SetText("已添加"); + cardInfo_.addFlag = addFlag; + Invalidate(); + } + } + + void AddCardItem::SetOnClickListener(OnClickListener *onClickListener) + { + cardLabel_.SetOnClickListener(onClickListener); + } + +}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardModel.cpp new file mode 100644 index 000000000..fa052decb --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardModel.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardModel.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "AddCardModel.h" +#include "kv_store.h" +#include "securec.h" + +namespace OHOS { + AddCardModel::AddCardModel() {} + + AddCardModel::~AddCardModel() {} + + AddCardModel &AddCardModel::GetInstance() + { + static AddCardModel instance; + return instance; + } + + void AddCardModel::SetSelectedCardIndex(uint8_t cardIndex) + { + selectedCardIndex = cardIndex; + } + + uint8_t AddCardModel::GetSelectedCardIndex(void) const + { + return selectedCardIndex; + } + + void AddCardModel::AddCardSetting(void) + { + MainModel::GetInstance().AddCardSetting(selectedCardIndex); + } +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardPresenter.cpp new file mode 100644 index 000000000..c815867e6 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardPresenter.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardPresenter.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "AddCardView.h" +#include "AddCardModel.h" +#include "AddCardPresenter.h" + +namespace OHOS { + AddCardPresenter::AddCardPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::AddCardPresenter"); + model = &AddCardModel::GetInstance(); + } + + AddCardPresenter::~AddCardPresenter() { + } + + void AddCardPresenter::OnStart() + { + Presenter::OnStart(); + } + + void AddCardPresenter::OnResume(void) + { + } + + void AddCardPresenter::OnStop(void) + { + } + + bool AddCardPresenter::OnDrag(UIView& view, const DragEvent& event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnDrag"); + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnDrag ChangeSlice"); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + } + return false; + } + + bool AddCardPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnClick"); + model->AddCardSetting(); + view_->RefreshCardList(); + return true; + } + + void AddCardPresenter::OnScrollStart(int16_t index, UIView *view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnScrollStart index = %d", index); + return; + } + + void AddCardPresenter::OnScrollEnd(int16_t index, UIView *view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnScrollEnd index = %d", index); + if (view == nullptr) { + return; + } + model->SetSelectedCardIndex(index); + } + + void AddCardPresenter::OnItemSelected(int16_t index, UIView* view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnItemSelected index = %d", index); + if (view == nullptr) { + return; + } + } + +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardView.cpp new file mode 100644 index 000000000..a696032d2 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardView.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: AddCardView.cpp + * Author: + * Create: 2021-11-23 + */ + +#include +#include "AddCardView.h" +#include "AddCardPresenter.h" + +namespace OHOS { +AddCardView::AddCardView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::AddCardView"); +} + +AddCardView::~AddCardView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::~AddCardView"); + if (addCardAdapter_ != nullptr) { + delete addCardAdapter_; + addCardAdapter_ = nullptr; + } +} + +void AddCardView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::OnStart"); + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + addCardAdapter_ = new AddCardAdapter(); + addCardAdapter_->SetItemClickListener(presenter_); + SetUpListInfo(); + SetUpListView(); +} + +void AddCardView::OnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::OnSetUpView"); + View::OnSetUpView(); +} + +void AddCardView::OnTearDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::OnTearDownView"); + View::OnTearDownView(); +} + +void AddCardView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardView::OnStop"); + View::OnStop(); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } +} + +void AddCardView::SetUpListInfo(void) +{ + MainModel::GetInstance().InitCardSettings(); + uint8_t cardCount = MainModel::GetInstance().GetCardSettingCount(); + CardId *cardSettings = MainModel::GetInstance().GetCardSettings(); + addCardAdapter_->ClearItem(); + for (uint8_t i = WATCH_FACE + 1; i < MAX_CARD; i++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "All:cardId = %d", i); + const CardInfo *info = MainModel::GetInstance().GetCardInfo((CardId)i); + if (info != nullptr) { + AddCardInfo addInfo; + addInfo.id = info->id; + addInfo.cardImg = info->cardImg; + addInfo.addFlag = false; + for (uint8_t j = 0; j < cardCount; j++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Settings:cardId = %d", cardSettings[j]); + if (cardSettings[j] == i) { + addInfo.addFlag = true; + break; + } + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpListInfo::%d %s %d", + addInfo.id, addInfo.cardImg, addInfo.addFlag); + addCardAdapter_->AddListItem(addInfo); + } + } +} + +void AddCardView::SetUpListView(void) +{ + contentList_.SetPosition(0, 0); + contentList_.Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + contentList_.SetScrollBlankSize(VERTICAL_RESOLUTION / 2); + contentList_.SetSelectPosition(VERTICAL_RESOLUTION / 2); + contentList_.SetDraggable(true); + contentList_.SetThrowDrag(true); + contentList_.EnableAutoAlign(true); + contentList_.SetScrollStateListener(presenter_); + contentList_.SetOnDragListener(presenter_); + contentList_.SetMaxScrollDistance(1000); + contentList_.SetAdapter(addCardAdapter_); + contentList_.SetVisible(true); + container_->Add(&contentList_); +} + +void AddCardView::RefreshCardList(void) +{ + SetUpListInfo(); + contentList_.RefreshList(); +} + +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/include/AppItemView.h b/code/sdk/application/wearable/fd230app/nativeui/applist/include/AppItemView.h index 12c5591dc..6e5dc5e85 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/include/AppItemView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/include/AppItemView.h @@ -35,6 +35,20 @@ private: UILabel label_; AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr }; }; + +class HexagonsItemView : public UIImageView { +public: + explicit HexagonsItemView(); + virtual ~HexagonsItemView(); + void SetItemInfo(const AppItem &itemInfo); + AppViewId GetViewId(); + const char *GetAppUid(); +private: + HexagonsItemView(const HexagonsItemView &); + HexagonsItemView &operator = (const HexagonsItemView &); + AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr }; +}; + } #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistModel.h b/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistModel.h index 435c1910e..0f888a720 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistModel.h @@ -38,7 +38,7 @@ class ApplistModel { public: static ApplistModel &GetInstance(void); - void initApplist(); + void Init(); const AppItem *GetApplistItems() const; uint8 GetAppListNum() const; void ResolvingJSAppItems(void); @@ -48,7 +48,7 @@ public: int GetHeadItemY(void); void ApplistUpdate(void); void SetPresenter(ApplistPresenter *p); - + bool GetIsUseListStyle(void); private: ApplistModel(); ApplistModel(const ApplistModel &); @@ -63,6 +63,7 @@ private: uint16_t startIndex = 0; int headItemY = 0; + bool initFlag{false}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistPresenter.h index 844f49840..c0d53a29d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistPresenter.h @@ -17,7 +17,8 @@ #include "KeyInputListener.h" namespace OHOS { - class ApplistPresenter : public Presenter, public UIView::OnClickListener { + class ApplistPresenter : public Presenter, public UIView::OnClickListener, + public ListScrollListener { public: ApplistPresenter(); virtual ~ApplistPresenter(); @@ -28,17 +29,18 @@ namespace OHOS { virtual void OnStop() override; bool OnClick(UIView &view, const ClickEvent &event) override; + void OnItemSelected(int16 index, UIView *view) override; void SetStartIndex(uint16_t index); uint16_t GetStartIndex(void); void SetHeadItemY(int y); int GetHeadItemY(void); uint8_t GetListItemNum(void); ApplistView* GetAppListView(); - ApplistModel *GetApplistModelPtr(void) - { - return model; - } + bool GetIsUseListStyle(void); + private: + AppItemView *itemViewSele{nullptr}; + AppItemView *preItemViewSele{nullptr}; ApplistModel *model{nullptr}; KeyInputListener *keyActListenr{nullptr}; }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h b/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h index 441e9832f..f2439d420 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h @@ -9,6 +9,7 @@ #include "components/ui_label.h" #include "components/ui_label_ext.h" #include "components/ui_list.h" +#include "components/ui_custom_hexagons_list.h" #include "window/window.h" #include "ohos_types.h" #include "BaseView.h" @@ -65,31 +66,41 @@ namespace OHOS bool continueDrag{false}; }; - class ApplistPresenter; - class ApplistView : public View, public ListScrollListener, public UIViewGroup - { - public: - ApplistView(); - virtual ~ApplistView(); +class ApplistPresenter; +class ApplistView : public View { +public: + ApplistView(); + virtual ~ApplistView(); - virtual void OnStart() override; - virtual void OnSetUpView() override; - virtual void OnTearDownView() override; - virtual void OnStop() override; - bool InitPage(); - bool SetupViewPage(ApplistView *applistView); - ApplistPresenter *g_ApplistPresenter{nullptr}; - void AddAppItemToList(const AppItem &item); - void ClearAppItemToList(); - void OnItemSelected(int16 index, UIView *view) override; - UIList *GetAppUIList(void); + virtual void OnStart() override; + virtual void OnSetUpView() override; + virtual void OnTearDownView() override; + virtual void OnStop() override; - private: - ApplistAdapter *listAdapter_{nullptr}; - UIList *contentList_{nullptr}; - UIView::OnDragListener *dragListener{nullptr}; - AppItemView *itemViewSele{nullptr}; - AppItemView *preItemViewSele{nullptr}; - }; + void AddAppItemToList(const AppItem &item); + void ClearAppItemToList(); + void RefreshAppList(void); +private: + void HexagonsStyleOnStart(); + void ListStyleOnStart(); + void HexagonsStyleOnSetUpView(); + void ListStyleOnSetUpView(); + void HexagonsStyleOnStop(); + void ListStyleOnStop(); + + /* for list style */ + ApplistAdapter *listAdapter_{nullptr}; + UIList *contentList_{nullptr}; + UIView::OnDragListener *dragListener{nullptr}; + + /* for hexagons style */ + UICustomHexagonsList* hexagonsList_{nullptr}; + std::list listHexagonsView_; + int16_t horMargin_ = 0; + int16_t verMargin_ = 0; + uint16_t imgSize_ = 0; + uint16_t imgDistance_ = 0; + +}; } #endif // APPLIST_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/AppItemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/AppItemView.cpp index e4ff34f9f..cd35ebb0f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/AppItemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/AppItemView.cpp @@ -22,8 +22,7 @@ namespace OHOS { AppItemView::AppItemView() { SetPosition(0, 0, HORIZONTAL_RESOLUTION, APP_ITEM_BUTTON_HEIGHT); - SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); SetTouchable(true); SetUpChild(); Add(&icon_); @@ -40,6 +39,7 @@ namespace OHOS { { icon_.SetPosition(ICON_X, 0); icon_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + icon_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); icon_.Resize(APP_ITEM_BUTTON_WIDTH, APP_ITEM_BUTTON_HEIGHT); icon_.SetResizeMode(UIImageView::CENTER); icon_.SetAutoEnable(false); @@ -50,8 +50,7 @@ namespace OHOS { label_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); label_.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); label_.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); - label_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - label_.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + label_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); } void AppItemView::SetItemInfo(const AppItem &itemInfo) @@ -83,4 +82,25 @@ namespace OHOS { icon_.ResetTransParameter(); } + HexagonsItemView::HexagonsItemView() + { + } + + HexagonsItemView::~HexagonsItemView() + { + } + void HexagonsItemView::SetItemInfo(const AppItem &itemInfo) + { + itemInfo_ = itemInfo; + } + + AppViewId HexagonsItemView::GetViewId() + { + return itemInfo_.id; + } + + const char *HexagonsItemView::GetAppUid() + { + return itemInfo_.uid; + } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistAdapter.cpp index e7f38f325..8e26721c8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistAdapter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistAdapter.cpp @@ -27,14 +27,7 @@ void ApplistAdapter::ClearItem(void) UIView *ApplistAdapter::GetView(UIView *inView, int16 index) { - if (listData_.empty()) { - return nullptr; - } - if (index < 0) { - return nullptr; - } - size_t uindex = index; - if (uindex >= listData_.size()) { + if (index >= (int16)listData_.size() || index < 0) { return nullptr; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistCardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistCardView.cpp index 34d85ff6d..8add32d82 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistCardView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistCardView.cpp @@ -1,5 +1,5 @@ #include "ApplistCardView.h" - +#if 0 namespace OHOS { ApplistCardView::ApplistCardView() @@ -63,6 +63,5 @@ namespace OHOS void ApplistCardView::UnLoad(void) { - } - -} \ No newline at end of file + }} +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp index 5cfe6b578..4b99fe64d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp @@ -16,9 +16,10 @@ #include "UiConfig.h" #include "AppViewIDs.h" #include "components/ui_label_ext.h" -#include"language/font/ui_resource_string.h" +#include "language/font/ui_resource_string.h" #include "ApplistModel.h" #include "ApplistPresenter.h" +#include "SetDesktopModel.h" namespace OHOS { @@ -37,8 +38,8 @@ namespace OHOS {VIEW_CALLER_LOG, PNG_APPLIST_CALLLOG_IMAGE, PNG_APPLIST_CALLLOG_IMAGE, "通话记录", nullptr}, {VIEW_PHONE, PNG_APPLIST_CALLER_IMAGE, PNG_APPLIST_CALLER_IMAGE, "电话", nullptr}, {VIEW_MAIN_STOPWATCH, PNG_APPLIST_STOPWATCH_IMAGE, PNG_APPLIST_STOPWATCH_IMAGE, "秒表", nullptr}, - //{VIEW_CONNECT_PHONE, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "连接手机", nullptr}, - //{VIEW_LANGUAGE_SWITCH, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "语言切换", nullptr}, + //{VIEW_CONNECT_PHONE, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "连接手机", nullptr}, + //{VIEW_LANGUAGE_SWITCH, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "语言切换", nullptr}, #ifdef SUPPORT_ALIPAY_SEC {VIEW_MAIN_ALIPAY, PNG_APPLIST_ALIPAY_IMAGE, PNG_APPLIST_ALIPAY_IMAGE, "支付宝", nullptr}, #endif @@ -67,9 +68,13 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistModel::~ApplistModel()"); } - void ApplistModel::initApplist() + void ApplistModel::Init() { - ResolvingJSAppItems(); + if (!initFlag) + { + ResolvingJSAppItems(); + initFlag = true; + } } void ApplistModel::ResolvingJSAppItems(void) @@ -93,13 +98,11 @@ namespace OHOS #endif bundleLen = 0; appLen = 0; - nativeAppNum = sizeof(g_nativeAppList) / sizeof(AppItem); if (nativeAppNum >= APP_MAX_NUM) { nativeAppNum = APP_MAX_NUM; } - ret = memcpy_s(applist, sizeof(AppItem) * APP_MAX_NUM, g_nativeAppList, sizeof(AppItem) * nativeAppNum); if (ret != EOK) { @@ -132,6 +135,10 @@ namespace OHOS bundleInfos[len].abilityInfo = nullptr; } } + else + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ResolvingJSAppItems GetBundleInfos ret = %d \r", ret); + } #endif } @@ -175,7 +182,7 @@ namespace OHOS { presenter->GetAppListView()->AddAppItemToList(itemInfo[i]); } - presenter->GetAppListView()->GetAppUIList()->RefreshList(); + presenter->GetAppListView()->RefreshAppList(); } } @@ -183,4 +190,9 @@ namespace OHOS { presenter = p; } + + bool ApplistModel::GetIsUseListStyle(void) + { + return (SetDesktopModel::GetInstance().GetDesktopStyle() == APPLIST_STYLE); + } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp index 1f2337b65..cb70db1fd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp @@ -16,13 +16,12 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::ApplistPresenter()"); model = &ApplistModel::GetInstance(); + model->Init(); model->SetPresenter(this); } - ApplistPresenter::~ApplistPresenter() - { - if (keyActListenr != nullptr) - { + ApplistPresenter::~ApplistPresenter() { + if (keyActListenr != nullptr) { delete keyActListenr; keyActListenr = nullptr; } @@ -33,7 +32,6 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnStart()"); Presenter::OnStart(); - model->initApplist(); if (keyActListenr == nullptr) { @@ -62,6 +60,7 @@ namespace OHOS { view_->AddAppItemToList(itemInfo[i]); } + view_->RefreshAppList(); } void ApplistPresenter::OnPause() @@ -78,24 +77,30 @@ namespace OHOS bool ApplistPresenter::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); - AppItemView *itemView = static_cast(&view); - AppViewId viewId = itemView->GetViewId(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); - if (viewId < VIEW_MAX_INTER_APP) - { + AppViewId viewId = VIEW_INVALID; + char *uid = nullptr; + if (GetIsUseListStyle() == true) { + AppItemView *itemView = static_cast(&view); + viewId = itemView->GetViewId(); + uid = (char *)itemView->GetAppUid(); + } else { + HexagonsItemView *itemView = static_cast(&view); + viewId = itemView->GetViewId(); + uid = (char *)itemView->GetAppUid(); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d", viewId); + if (viewId < VIEW_MAX_INTER_APP) { NativeAbility::GetInstance().ChangeSlice(viewId); return true; - } - else if (viewId == VIEW_EXTERN_APP) - { + } else if (viewId == VIEW_EXTERN_APP) { #ifdef JS_ENABLE - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick bundleName = %s", itemView->GetAppUid()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick bundleName = %s", uid); Want *want = new Want(); memset_s(want, sizeof(Want), 0, sizeof(Want)); ElementName startElement = {}; startElement.abilityName = (char *)"default"; - startElement.bundleName = (char *)itemView->GetAppUid(); + startElement.bundleName = uid; startElement.deviceId = nullptr; SetWantElement(want, startElement); @@ -106,7 +111,19 @@ namespace OHOS } return false; } + void ApplistPresenter::OnItemSelected(int16 index, UIView *view) + { + UNUSED(index); + if (view != nullptr) { + itemViewSele = static_cast(view); + itemViewSele->SelectedChange(); + if (preItemViewSele != nullptr && preItemViewSele != itemViewSele) { + preItemViewSele->Reset(); + } + preItemViewSele = itemViewSele; + } + } void ApplistPresenter::SetStartIndex(uint16_t index) { model->SetStartIndex(index); @@ -134,7 +151,12 @@ namespace OHOS return model->GetAppListNum(); } - ApplistView *ApplistPresenter::GetAppListView() + bool ApplistPresenter::GetIsUseListStyle(void) + { + return model->GetIsUseListStyle(); + } + + ApplistView* ApplistPresenter::GetAppListView() { return view_; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp index b42eb6140..07b7ef0e1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp @@ -10,233 +10,226 @@ #include "ApplistPresenter.h" #include "AppItemView.h" -namespace OHOS -{ - static constexpr int16 NUM_2 = 2; - static constexpr int16 MAX_SCROLL_DIS = 1000; +namespace OHOS { +static constexpr int16 NUM_2 = 2; +static constexpr int16 MAX_SCROLL_DIS = 1000; - ApplistView::ApplistView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ApplistView "); - UIViewGroup::SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - } +ApplistView::ApplistView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ApplistView "); +} - ApplistView::~ApplistView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::~ApplistView "); +ApplistView::~ApplistView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::~ApplistView "); + if (listAdapter_ != nullptr) { delete listAdapter_; listAdapter_ = nullptr; + } + if (contentList_ != nullptr) { delete contentList_; contentList_ = nullptr; + } + if (dragListener != nullptr) { delete dragListener; dragListener = nullptr; + } + if (hexagonsList_ != nullptr) { + delete hexagonsList_; + hexagonsList_ = nullptr; } +} - // 初始化页面 - bool ApplistView::InitPage() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " ApplistView::InitPage"); - g_ApplistPresenter = new ApplistPresenter(); - g_ApplistPresenter->GetApplistModelPtr()->initApplist(); - // BaseView::RootView(Color::Black().full); - listAdapter_ = new ApplistAdapter(); - if (listAdapter_ == nullptr) - { - return false; - } - listAdapter_->SetItemClickListener(g_ApplistPresenter); - - contentList_ = new UIList(UIList::VERTICAL); - if (contentList_ == nullptr) - { - return false; - } - contentList_->SetPosition(0, 0); - contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - contentList_->SetScrollBlankSize(VERTICAL_RESOLUTION / NUM_2); - contentList_->SetSelectPosition(VERTICAL_RESOLUTION / NUM_2); // middle position - contentList_->SetDraggable(true); - contentList_->SetThrowDrag(true); - contentList_->EnableAutoAlign(true); - contentList_->SetScrollStateListener(this); - contentList_->SetMaxScrollDistance(MAX_SCROLL_DIS); - contentList_->SetVisible(true); - Add(contentList_); - dragListener = new AppListOnDragListener(); - if (dragListener == nullptr) - { - return false; - } - contentList_->SetOnDragListener(dragListener); - - return true; +void ApplistView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStart "); + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + if (presenter_->GetIsUseListStyle() == true) { + ListStyleOnStart(); + } else { + HexagonsStyleOnStart(); } +} - // 设置页面视图 - bool ApplistView::SetupViewPage(ApplistView *applistView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " ApplistView::SetupViewPage"); - const AppItem *itemInfo = g_ApplistPresenter->GetApplistModelPtr()->GetApplistItems(); - for (uint8 i = 0; i < g_ApplistPresenter->GetApplistModelPtr()->GetAppListNum(); i++) - { - applistView->AddAppItemToList(itemInfo[i]); - } - /* -------------------------------------------------------------------------- */ - if (contentList_ == nullptr || listAdapter_ == nullptr) - { - return false; - } - uint16_t startIndex = 0; - int16_t headY = 0; - if (g_ApplistPresenter->GetStartIndex() >= g_ApplistPresenter->GetListItemNum()) - { - startIndex = g_ApplistPresenter->GetListItemNum() - 1; - headY = VERTICAL_RESOLUTION / NUM_2; - } - else - { - startIndex = g_ApplistPresenter->GetStartIndex(); - headY = g_ApplistPresenter->GetHeadItemY(); - if (headY == 0) - { - headY = VERTICAL_RESOLUTION / NUM_2; - } - } - contentList_->SetStartIndex(startIndex); - contentList_->SetAdapter(listAdapter_); - contentList_->ScrollBy(headY); - return true; +void ApplistView::HexagonsStyleOnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStart "); + if (hexagonsList_ == nullptr) { + hexagonsList_ = new UICustomHexagonsList(); } + container_->Add(hexagonsList_); + hexagonsList_->SetPosition(0, 0, + container_->GetWidth() - 2 * (horMargin_ + 1), container_->GetHeight() - 2 * (verMargin_ + 1)); // 2, two + imgDistance_ = container_->GetWidth() * 0.25991; // 0.25991, empirical coefficient + imgSize_ = container_->GetWidth() * 0.23348; // 0.23348, empirical coefficient + hexagonsList_->SetImageDistance(imgDistance_); + hexagonsList_->SetImageSizeInCenter(imgSize_); + int16_t blankSize = hexagonsList_->GetRelativeRect().GetWidth() > hexagonsList_->GetRelativeRect().GetHeight() ? + hexagonsList_->GetRelativeRect().GetWidth() / 2 : hexagonsList_->GetRelativeRect().GetHeight() / 2; // 2, half + hexagonsList_->SetScrollBlankSize(blankSize); + hexagonsList_->SetReboundSize(blankSize); + hexagonsList_->SetThrowDrag(true); +} - void ApplistView::OnStart() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStart "); - View::OnStart(); - - BaseView::RootView(Color::Black().full); +void ApplistView::ListStyleOnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStart"); + listAdapter_ = new ApplistAdapter(); + if (listAdapter_ == nullptr) { + return; + } + listAdapter_->SetItemClickListener(presenter_); - listAdapter_ = new ApplistAdapter(); - if (listAdapter_ == nullptr) - { - return; - } - listAdapter_->SetItemClickListener(presenter_); + contentList_ = new UIList(UIList::VERTICAL); + if (contentList_ == nullptr) { + return; + } + contentList_->SetPosition(0, 0); + contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + contentList_->SetScrollBlankSize(VERTICAL_RESOLUTION / NUM_2); + contentList_->SetSelectPosition(VERTICAL_RESOLUTION / NUM_2); // middle position + contentList_->SetDraggable(true); + contentList_->SetThrowDrag(true); + contentList_->EnableAutoAlign(true); + contentList_->SetScrollStateListener(presenter_); + contentList_->SetMaxScrollDistance(MAX_SCROLL_DIS); + contentList_->SetYScrollBarVisible(true); + container_->Add(contentList_); + + dragListener = new AppListOnDragListener(); + if (dragListener == nullptr) { + return; + } + contentList_->SetOnDragListener(dragListener); +} - contentList_ = new UIList(UIList::VERTICAL); - if (contentList_ == nullptr) - { - return; - } - contentList_->SetPosition(0, 0); - contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - contentList_->SetScrollBlankSize(VERTICAL_RESOLUTION / NUM_2); - contentList_->SetSelectPosition(VERTICAL_RESOLUTION / NUM_2); // middle position - contentList_->SetDraggable(true); - contentList_->SetThrowDrag(true); - contentList_->EnableAutoAlign(true); - contentList_->SetScrollStateListener(this); - contentList_->SetMaxScrollDistance(MAX_SCROLL_DIS); - contentList_->SetYScrollBarVisible(true); - SetContainerView(contentList_); - - dragListener = new AppListOnDragListener(); - if (dragListener == nullptr) - { - return; - } - contentList_->SetOnDragListener(dragListener); - contentList_->SetRotateFactor(2); - contentList_->RequestFocus(); +void ApplistView::OnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnSetUpView"); + View::OnSetUpView(); + if (presenter_->GetIsUseListStyle() == true) { + ListStyleOnSetUpView(); + } else { + HexagonsStyleOnSetUpView(); } +} - void ApplistView::OnSetUpView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnSetUpView"); - View::OnSetUpView(); +void ApplistView::HexagonsStyleOnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnSetUpView "); +} - if (contentList_ == nullptr || listAdapter_ == nullptr) - { - return; - } +void ApplistView::ListStyleOnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnSetUpView"); - uint16_t startIndex = 0; - int16_t headY = 0; - if (presenter_->GetStartIndex() >= presenter_->GetListItemNum()) - { - startIndex = presenter_->GetListItemNum() - 1; - headY = VERTICAL_RESOLUTION / NUM_2; - } - else - { - startIndex = presenter_->GetStartIndex(); - headY = presenter_->GetHeadItemY(); - if (headY == 0) - { - headY = VERTICAL_RESOLUTION / NUM_2; - } - } - contentList_->SetStartIndex(startIndex); - contentList_->SetAdapter(listAdapter_); - contentList_->ScrollBy(headY); - Draw(); + if (contentList_ == nullptr || listAdapter_ == nullptr) { return; } - void ApplistView::OnTearDownView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnTearDownView"); - View::OnTearDownView(); - return; + uint16_t startIndex = 0; + int16_t headY = 0; + if (presenter_->GetStartIndex() >= presenter_->GetListItemNum()) { + startIndex = presenter_->GetListItemNum() - 1; + headY = VERTICAL_RESOLUTION / NUM_2; + } else { + startIndex = presenter_->GetStartIndex(); + headY = presenter_->GetHeadItemY(); + if (headY == 0) { + headY = VERTICAL_RESOLUTION / NUM_2; + } } + contentList_->SetStartIndex(startIndex); + contentList_->SetAdapter(listAdapter_); + contentList_->ScrollBy(headY); + return; +} - void ApplistView::OnStop() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStop"); - int16_t listHeadY = contentList_->GetChildrenHead()->GetY(); - int16_t listHeadIndex = contentList_->GetChildrenHead()->GetViewIndex(); - - presenter_->SetHeadItemY(listHeadY); - presenter_->SetStartIndex(listHeadIndex); +void ApplistView::OnTearDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnTearDownView"); + View::OnTearDownView(); + return; +} - View::OnStop(); - container_ = nullptr; +void ApplistView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStop"); + if (presenter_->GetIsUseListStyle() == true) { + ListStyleOnStop(); + } else { + HexagonsStyleOnStop(); + } + if (container_ != nullptr) { + container_->RemoveAll(); + } + View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); + return; +} - RootView::GetInstance()->ClearOnKeyActListener(); - RootView::GetInstance()->RemoveAll(); - RootView::GetInstance()->ClearFocus(); - return; +void ApplistView::HexagonsStyleOnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStop"); + if (hexagonsList_ != nullptr) { + hexagonsList_->RemoveAll(); + } + for (auto iter : listHexagonsView_) { + delete iter; } + listHexagonsView_.clear(); +} - void ApplistView::AddAppItemToList(const AppItem &item) - { +void ApplistView::ListStyleOnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStop"); + int16_t listHeadY = contentList_->GetChildrenHead()->GetY(); + int16_t listHeadIndex = contentList_->GetChildrenHead()->GetViewIndex(); + presenter_->SetHeadItemY(listHeadY); + presenter_->SetStartIndex(listHeadIndex); +} + +void ApplistView::AddAppItemToList(const AppItem &item) +{ + if (presenter_->GetIsUseListStyle() == true) { listAdapter_->AddListItem(item); + } else { + HexagonsItemView *itemView = new HexagonsItemView(); + itemView->SetItemInfo(item); + itemView->SetSrc(item.iconSmall); + itemView->SetTouchable(true); + itemView->SetOnClickListener(presenter_); + + hexagonsList_->Add(itemView); + listHexagonsView_.push_back(itemView); } +} - void ApplistView::ClearAppItemToList() - { +void ApplistView::ClearAppItemToList() +{ + if (presenter_->GetIsUseListStyle() == true) { listAdapter_->ClearItem(); - } - - void ApplistView::OnItemSelected(int16 index, UIView *view) - { - UNUSED(index); - if (view != nullptr) - { - itemViewSele = static_cast(view); - itemViewSele->SelectedChange(); - - if (preItemViewSele != nullptr && preItemViewSele != itemViewSele) - { - preItemViewSele->Reset(); - } - preItemViewSele = itemViewSele; + } else { + if (hexagonsList_ != nullptr) { + hexagonsList_->RemoveAll(); } + for (auto iter : listHexagonsView_) { + delete iter; + } + listHexagonsView_.clear(); } +} - UIList *ApplistView::GetAppUIList(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::GetAppUIList"); - return contentList_; +void ApplistView::RefreshAppList(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::RefreshAppList"); + if (presenter_->GetIsUseListStyle() == true) { + contentList_->RefreshList(); + } else { + hexagonsList_->LayoutChildren(true); } +} } diff --git a/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h b/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h index 750a39d67..9f67b8134 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h @@ -12,7 +12,6 @@ #include #include "View.h" #include "components/ui_label.h" -#include "components/ui_label_ext.h" #include "components/root_view.h" #include "components/ui_view_group.h" #include "components/ui_image_view.h" @@ -30,120 +29,8 @@ #include "animator/animator_manager.h" #include "time.h" #include "sys/time.h" -#include "animator/animator.h" -#include "common/image_cache_manager.h" -#include -#include "sys/time.h" -#include "components/ui_box_progress.h" -#include "components/ui_image_view.h" -#include "components/ui_label.h" -#include "components/ui_label_ext.h" -#include "battery_hal.h" - -#include "hal_tick.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif - -extern uint8_t battery_get_voltage(float *voltage); -#ifdef XTS_SUPPORT -extern uint8_t is_xts_test_done(void); -#endif -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif namespace OHOS { -static constexpr int16_t SEC_TO_MILLI = 1000; -static constexpr int16_t USEC_TO_MILLI = 1000; -static constexpr int16_t MIN_TO_HOUR = 60; -static constexpr int16_t HOURLY_SYSTEM = 24; -static constexpr int16_t INTERVAL = 30; - -class ClockAnimatorCallback : public AnimatorCallback { -public: - explicit ClockAnimatorCallback(UISweepClock *clock) : sweepClock(clock) {} - ~ClockAnimatorCallback() {} - virtual void Callback(UIView *view) - { - UNUSED(view); - struct timeval tv; - gettimeofday(&tv, NULL); - uint64_t second = tv.tv_sec; - uint64_t uSecond = tv.tv_usec; - uint64_t minute = second / MIN_TO_HOUR; - uint64_t hour = minute / MIN_TO_HOUR; - uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); - uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); - uint16_t realMilliSecond = static_cast((second % MIN_TO_HOUR) * - SEC_TO_MILLI + uSecond / USEC_TO_MILLI); - sweepClock->SetSweepTime12Hour(realHour, realMinute, realMilliSecond, 1); - } - -private: - UISweepClock *sweepClock{nullptr}; -}; - -class ProgressCallback : public AnimatorCallback { -public: - explicit ProgressCallback(UIBoxProgress *progress, UILabel *batterylabel, UILabel *XTSlabel) : progress(progress), batterylabel(batterylabel),XTSlabel(XTSlabel) {} - ~ProgressCallback() {} - virtual void Callback(UIView *view) - { - float voltage = 0.0F; - uint8_t value = 0; - uint8_t xts_testing = 1; - uint32_t RunTime_ = HALTick::GetInstance().GetTime(); - #ifdef XTS_SUPPORT - xts_testing = is_xts_test_done(); - #endif - - if (!xts_testing) { - // XTS测试进行 - xts_flag = 1; - XTSlabel->SetText("XTS测试进行中"); - XTSlabel->SetTextColor(Color::GetColorFromRGBA(0xe6, 0x04, 0x09, 0xff)); - value = 0; - //printf("bat check stamp %u xts_testing %u,xts_flag %u\r\n", RunTime_, xts_testing,xts_flag); - } else { - // XTS测试结束 - if (xts_flag) { - XTSlabel->SetText("XTS测试结束"); - XTSlabel->SetTextColor(Color::GetColorFromRGBA(0x4e, 0xe6, 0x04, 0xff)); - xts_flag = 0; // 复位 - } - value = battery_get_voltage(&voltage); - //printf("bat check stamp %u xts_testing %u,xts_flag %u\r\n", RunTime_, xts_testing,xts_flag); - } - - const char* progress1ForeImageSrc = nullptr; - const char* progress1BackImageSrc = nullptr; - if (value <= 10) { - progress1ForeImageSrc = "/user/res/Battery/Battery_Limit.bin"; - } else if (value <= 20) { - progress1ForeImageSrc = "/user/res/Battery/Battery_Save.bin"; - } else { - progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin"; - } - - progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc); - progress->SetValue(value); // 更新界面 - batterylabel->SetText((std::to_string(value) + "%").c_str()); // 更新百分比显示 - } - -private: - uint8_t xts_flag = 0; //标志位 - UILabel *batterylabel{nullptr}; - UILabel *XTSlabel{nullptr}; - UIBoxProgress *progress{nullptr}; - //std::thread workerThread; - //std::atomic stopThread; -}; class MainClockView : public UICardPage { public: MainClockView(); @@ -156,6 +43,8 @@ public: void RefreshHeartRate(int value); void ClockAnimatorStart(void); void ClockAnimatorStop(void); + void UpdateTime(void); + private: void InitStepValue(); bool InitLabelView(void); @@ -165,27 +54,19 @@ private: bool InitSweepClock(void); bool LoadClockImage(Image *view, uint32_t resId); bool LoadClockImage(UIImageView *view, uint32_t resId); - - UIBoxProgress* progress = nullptr; - AnimatorCallback* progress1callback_ = nullptr; - Animator *progress1animator_ = nullptr; UIImageView *curFace{nullptr}; UILabelButton *stepLabel{nullptr}; UILabel *batteryLabel{nullptr}; UILabel *weekLabel{nullptr}; UILabel *heartRateLabel{nullptr}; - UILabel *XTSLabel{nullptr}; - ClockAnimatorCallback *callBack{nullptr}; - Animator *clockAnimator{nullptr}; UISweepClock *mainSweepClock{nullptr}; Image *secondHand{nullptr}; Image *minuteHand{nullptr}; - UILabel *dataLabel{nullptr}; Image *hourHand{nullptr}; UIImageView *heartRate{nullptr}; Image *hand24Hour{nullptr}; UIImageView *weekDay{nullptr}; - //UIImageView *progress{nullptr}; + UIImageView *progress{nullptr}; Image *bigCircle{nullptr}; Image *medCircle{nullptr}; Image *smallCircle{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp index 826eeb060..974434b43 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp @@ -8,369 +8,296 @@ #include "MainClockView.h" #include "MainPresenterSample.h" #include "components/ui_label.h" -#include "components/ui_label_ext.h" #include "wearable_log.h" #include "ui_resource_image.h" #include "common/image_cache_manager.h" #include -extern uint8_t battery_get_voltage(float *voltage); - -namespace OHOS { -static MainClockView *g_pMainClockView = nullptr; - - -#if 0 -static constexpr uint16_t FONT_DEFAULT_SIZE = 25; -static constexpr uint16_t FONT_TEXT_SIZE = 24; -static constexpr uint16_t STEP_LABEL_X = 100; -static constexpr uint16_t STEP_LABEL_Y = 230; -static constexpr uint16_t BATTERYP_LABEL_X = 315; -static constexpr uint16_t BATTERYP_LABEL_Y = 230; -static constexpr uint16_t TEXT_WIDTH = 60; -static constexpr uint16_t TEXT_HEIGHT = 35; -static constexpr uint16_t POINT_POSITION_X = 202; -static constexpr uint16_t POINT_POSITION_Y = 16; -static constexpr uint16_t SECOND_POINT_POSITION_Y = 16; -static constexpr uint16_t POINT_CENTER_X = 25; -static constexpr uint16_t POINT_CENTER_Y = 211; -static constexpr uint16_t STEP_CHAR_NUM = 255; -static constexpr int16_t STEP_LABLE_WIDTH = 75; -static constexpr int16_t STEP_LABLE_SIZE = 35; -static constexpr uint16_t WEEKLABEL_POSITION_X = 247; -static constexpr uint16_t WEEKLABEL_POSITION_Y = 122; -static constexpr uint16_t HEARTRATELABEL_POSITION_X = 198; -static constexpr uint16_t HEARTRATELABEL_POSITION_Y = 330; -static constexpr uint16_t HEARTRATE_POSITION_X = 156; -static constexpr uint16_t HEARTRATE_POSITION_Y = 260; -static constexpr uint16_t PROGRESS_POSITION_X = 53; -static constexpr uint16_t PROGRESS_POSITION_Y = 54; -static constexpr uint16_t BIGCIRCLE_POSITION_X = 202; -static constexpr uint16_t BIGCIRCLE_POSITION_Y = 202; -static constexpr uint16_t MEDCIRCLE_POSITION_X = 202; -static constexpr uint16_t MEDCIRCLE_POSITION_Y = 202; -static constexpr uint16_t SMALLCIRCLE_POSITION_X = 202; -static constexpr uint16_t SMALLCIRCLE_POSITION_Y = 202; -static constexpr uint16_t WEEKDAY_POSITION_X = 193; -static constexpr uint16_t WEEKDAY_POSITION_Y = 127; -#endif - -static constexpr uint16_t SECOND_POINT_POSITION_X = 221; -static constexpr uint16_t SECOND_POINT_POSITION_Y = 28; -static constexpr uint16_t MINUTE_POINT_POSITION_X = 221; -static constexpr uint16_t MINUTE_POINT_POSITION_Y = 33; -static constexpr uint16_t HOUR_POINT_POSITION_X = 221; -static constexpr uint16_t HOUR_POINT_POSITION_Y = 87; - -static constexpr uint16_t SECOND_POINT_CENTER_X = 12; -static constexpr uint16_t SECOND_POINT_CENTER_Y = 205; -static constexpr uint16_t MINUTE_POINT_CENTER_X = 12; -static constexpr uint16_t MINUTE_POINT_CENTER_Y = 200; -static constexpr uint16_t HOUR_POINT_CENTER_X = 12; -static constexpr uint16_t HOUR_POINT_CENTER_Y = 146; - - - - -MainClockView::MainClockView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::MainClockView"); - SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - g_pMainClockView = this; -} - -MainClockView::~MainClockView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::~MainClockView"); - if (clockAnimator != nullptr) { - clockAnimator->Stop(); - delete clockAnimator; - clockAnimator = nullptr; - } - if(progress1animator_ != nullptr) { - progress1animator_->Stop(); - delete progress1animator_; - progress1animator_ = nullptr; - } - mainSweepClock->RemoveAll(); - - delete batteryLabel; - batteryLabel = nullptr; - delete weekLabel; - weekLabel = nullptr; - delete dataLabel; - dataLabel = nullptr; - delete mainSweepClock; - mainSweepClock = nullptr; - #if 0 - delete curFace; - curFace = nullptr; - delete stepLabel; - stepLabel = nullptr; - delete batteryLabel; - batteryLabel = nullptr; - delete callBack; - callBack = nullptr; - delete secondHand; - secondHand = nullptr; - delete minuteHand; - minuteHand = nullptr; - delete hourHand; - hourHand = nullptr; - delete weekLabel; - weekLabel = nullptr; - delete heartRateLabel; - heartRateLabel = nullptr; - delete heartRate; - heartRate = nullptr; - delete hand24Hour; - hand24Hour = nullptr; - delete weekDay; - weekDay = nullptr; - delete progress; - progress = nullptr; - delete bigCircle; - bigCircle = nullptr; - delete medCircle; - medCircle = nullptr; - delete smallCircle; - smallCircle = nullptr; - Remove(mainSweepClock); - delete mainSweepClock; - mainSweepClock = nullptr; -#endif - g_pMainClockView = nullptr; -} - -MainClockView *MainClockView::GetInstance(void) -{ - return g_pMainClockView; -} - -void MainClockView::InitStepValue() +namespace OHOS { -#if 0 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue"); - uint32_t stepValue; - int weekToday = ActivityModel::GetInstance()->GetWeekToday(); - ActivityModel::GetInstance()->GetStepData((StepDataDistribute)weekToday, &stepValue); - char stepChar[STEP_CHAR_NUM] = {0}; - if (sprintf_s(stepChar, STEP_CHAR_NUM, "%d", stepValue) == -1) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue error"); - return; - } - if (stepLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue nullptr"); - return; - } - stepLabel->SetText(stepChar); - stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); - stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); - stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); -#endif -} + static MainClockView *g_pMainClockView = nullptr; + + static constexpr uint16_t FONT_DEFAULT_SIZE = 25; + static constexpr uint16_t FONT_TEXT_SIZE = 24; + static constexpr uint16_t STEP_LABEL_X = 100; + static constexpr uint16_t STEP_LABEL_Y = 230; + static constexpr uint16_t BATTERYP_LABEL_X = 315; + static constexpr uint16_t BATTERYP_LABEL_Y = 230; + static constexpr uint16_t TEXT_WIDTH = 60; + static constexpr uint16_t TEXT_HEIGHT = 35; + static constexpr uint16_t POINT_POSITION_X = 202; + static constexpr uint16_t POINT_POSITION_Y = 16; + static constexpr uint16_t SECOND_POINT_POSITION_Y = 16; + static constexpr uint16_t POINT_CENTER_X = 25; + static constexpr uint16_t POINT_CENTER_Y = 211; + static constexpr uint16_t STEP_CHAR_NUM = 255; + static constexpr int16_t STEP_LABLE_WIDTH = 75; + static constexpr int16_t STEP_LABLE_SIZE = 35; + static constexpr uint16_t WEEKLABEL_POSITION_X = 247; + static constexpr uint16_t WEEKLABEL_POSITION_Y = 122; + static constexpr uint16_t HEARTRATELABEL_POSITION_X = 198; + static constexpr uint16_t HEARTRATELABEL_POSITION_Y = 330; + static constexpr uint16_t HEARTRATE_POSITION_X = 156; + static constexpr uint16_t HEARTRATE_POSITION_Y = 260; + static constexpr uint16_t PROGRESS_POSITION_X = 53; + static constexpr uint16_t PROGRESS_POSITION_Y = 54; + static constexpr uint16_t BIGCIRCLE_POSITION_X = 202; + static constexpr uint16_t BIGCIRCLE_POSITION_Y = 202; + static constexpr uint16_t MEDCIRCLE_POSITION_X = 202; + static constexpr uint16_t MEDCIRCLE_POSITION_Y = 202; + static constexpr uint16_t SMALLCIRCLE_POSITION_X = 202; + static constexpr uint16_t SMALLCIRCLE_POSITION_Y = 202; + static constexpr uint16_t WEEKDAY_POSITION_X = 193; + static constexpr uint16_t WEEKDAY_POSITION_Y = 127; + static constexpr int16_t SEC_TO_MILLI = 1000; + static constexpr int16_t USEC_TO_MILLI = 1000; + static constexpr int16_t MIN_TO_HOUR = 60; + static constexpr int16_t HOURLY_SYSTEM = 24; + static constexpr int16_t INTERVAL = 30; + + MainClockView::MainClockView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::MainClockView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + g_pMainClockView = this; + } + + MainClockView::~MainClockView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::~MainClockView"); + mainSweepClock->RemoveAll(); + delete curFace; + curFace = nullptr; + delete stepLabel; + stepLabel = nullptr; + delete batteryLabel; + batteryLabel = nullptr; + delete secondHand; + secondHand = nullptr; + delete minuteHand; + minuteHand = nullptr; + delete hourHand; + hourHand = nullptr; + delete weekLabel; + weekLabel = nullptr; + delete heartRateLabel; + heartRateLabel = nullptr; + delete heartRate; + heartRate = nullptr; + delete hand24Hour; + hand24Hour = nullptr; + delete weekDay; + weekDay = nullptr; + delete progress; + progress = nullptr; + delete bigCircle; + bigCircle = nullptr; + delete medCircle; + medCircle = nullptr; + delete smallCircle; + smallCircle = nullptr; + Remove(mainSweepClock); + delete mainSweepClock; + mainSweepClock = nullptr; + g_pMainClockView = nullptr; + } + + MainClockView *MainClockView::GetInstance(void) + { + return g_pMainClockView; + } + + void MainClockView::InitStepValue() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue"); + uint32_t stepValue; + int weekToday = ActivityModel::GetInstance()->GetWeekToday(); + ActivityModel::GetInstance()->GetStepData((StepDataDistribute)weekToday, &stepValue); + char stepChar[STEP_CHAR_NUM] = {0}; + if (sprintf_s(stepChar, STEP_CHAR_NUM, "%d", stepValue) == -1) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue error"); + return; + } + if (stepLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue nullptr"); + return; + } + stepLabel->SetText(stepChar); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); + } + + bool MainClockView::InitLabelView(void) + { + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + stepLabel = new UILabelButton(); + if (stepLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stepLabel new fail"); + return false; + } + stepLabel->SetPosition(STEP_LABEL_X, STEP_LABEL_Y); + stepLabel->Resize(STEP_LABLE_WIDTH, STEP_LABLE_SIZE); + stepLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + stepLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + stepLabel->SetViewId(MAIN_CLICK_ACTIVITY); + stepLabel->SetTouchable(true); + stepLabel->SetOnClickListener(clickListener); + InitStepValue(); + + batteryLabel = new UILabel(); + if (batteryLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLabel new fail"); + return false; + } + batteryLabel->SetPosition(BATTERYP_LABEL_X, BATTERYP_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + batteryLabel->SetText("90%"); + batteryLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + batteryLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + batteryLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + + heartRateLabel = new UILabel(); + if (heartRateLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRateLabel new fail"); + return false; + } + heartRateLabel->SetPosition(HEARTRATELABEL_POSITION_X, HEARTRATELABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT); + heartRateLabel->SetText("--"); + heartRateLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + heartRateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + heartRateLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); -bool MainClockView::InitLabelView(void) -{ -#if 0 - UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); - stepLabel = new UILabelButton(); - if (stepLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stepLabel new fail"); - return false; - } - stepLabel->SetPosition(STEP_LABEL_X, STEP_LABEL_Y); - stepLabel->Resize(STEP_LABLE_WIDTH, STEP_LABLE_SIZE); - stepLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - stepLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - stepLabel->SetViewId(MAIN_CLICK_ACTIVITY); - stepLabel->SetTouchable(true); - stepLabel->SetOnClickListener(clickListener); - InitStepValue(); - - batteryLabel = new UILabel(); - if (batteryLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLabel new fail"); - return false; - } - batteryLabel->SetPosition(BATTERYP_LABEL_X, BATTERYP_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - batteryLabel->SetText("90%"); - batteryLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - batteryLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - batteryLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - - heartRateLabel = new UILabel(); - if (heartRateLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRateLabel new fail"); - return false; - } - heartRateLabel->SetPosition(HEARTRATELABEL_POSITION_X, HEARTRATELABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT); - heartRateLabel->SetText("--"); - heartRateLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - heartRateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - heartRateLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - - weekLabel = new UILabel(); - if (weekLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekLabel new fail"); - return false; - } - weekLabel->SetPosition(WEEKLABEL_POSITION_X, WEEKLABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT); - weekLabel->SetText("2"); - weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE); - weekLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); -#endif -#if 0 - printf("lable init\n"); - batteryLabel = new UILabel(); - if (batteryLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLabel new fail"); - return false; - } - batteryLabel->SetPosition(228, 52); // widget's left position and top position - batteryLabel->Resize(66, 33); - batteryLabel->SetText("2%"); - batteryLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - batteryLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); - batteryLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - mainSweepClock->Add(batteryLabel); - batteryLabel->SetVisible(true); - - if (dataLabel == nullptr) { - dataLabel = new UILabel(); - } - dataLabel->SetPosition(177, 358); // widget's left position and top position - dataLabel->Resize(200, 60); // widget's width and height - dataLabel->SetViewId("data");// Set style - dataLabel->SetStyle(STYLE_TEXT_FONT, 30); - dataLabel->SetStyle(STYLE_LINE_HEIGHT, 30); - dataLabel->SetText("12月22号"); - dataLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - dataLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - dataLabel->SetRollSpeed(0); - dataLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - mainSweepClock->Add(dataLabel); - dataLabel->SetVisible(true); - - if (weekLabel == nullptr) { weekLabel = new UILabel(); - } - weekLabel->SetPosition(194, 395); // widget's left position and top position - weekLabel->Resize(200, 60); // widget's width and height - weekLabel->SetViewId("weekday");// Set style - weekLabel->SetStyle(STYLE_TEXT_FONT, 26); - weekLabel->SetStyle(STYLE_LINE_HEIGHT, 30); - weekLabel->SetText("星期五"); - weekLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - weekLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - weekLabel->SetRollSpeed(0); - weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); - - mainSweepClock->Add(weekLabel); - weekLabel->SetVisible(true); -#endif - return true; -} - -bool MainClockView::InitCenterCircleView(void) -{ -#if 0 - bigCircle = new Image(); - if (bigCircle == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bigCircle new fail"); - return false; - } - if (LoadClockImage(bigCircle, CLOCK_BIGCIRCLE_IMAGE_PATH) == false) { - return false; - } + if (weekLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekLabel new fail"); + return false; + } + weekLabel->SetPosition(WEEKLABEL_POSITION_X, WEEKLABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT); + weekLabel->SetText("2"); + weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE); + weekLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + return true; + } + + bool MainClockView::InitCenterCircleView(void) + { + bigCircle = new Image(); + if (bigCircle == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bigCircle new fail"); + return false; + } + if (LoadClockImage(bigCircle, CLOCK_CLASSIC_GEOMETRY) == false) + { + return false; + } - medCircle = new Image(); - if (medCircle == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "medCircle new fail"); - return false; - } - if (LoadClockImage(medCircle, CLOCK_MEDCIRCLE_IMAGE_PATH) == false) { - return false; - } + medCircle = new Image(); + if (medCircle == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "medCircle new fail"); + return false; + } + if (LoadClockImage(medCircle, CLOCK_CLASSIC_GEOMETRY) == false) + { + return false; + } - smallCircle = new Image(); - if (smallCircle == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "smallCircle new fail"); - return false; - } - if (LoadClockImage(smallCircle, CLOCK_CIRCLE_IMAGE_PATH) == false) { - return false; + smallCircle = new Image(); + if (smallCircle == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "smallCircle new fail"); + return false; + } + if (LoadClockImage(smallCircle, CLOCK_CLASSIC_GEOMETRY) == false) + { + return false; + } + return true; } -#endif - return true; -} -bool MainClockView::InitHandView(void) -{ - secondHand = new Image(); - if (secondHand == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "secondHand new fail"); - return false; - } - if (LoadClockImage(secondHand, CLOCK_SECOND) == false) { - return false; - } + bool MainClockView::InitHandView(void) + { + secondHand = new Image(); + if (secondHand == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "secondHand new fail"); + return false; + } + if (LoadClockImage(secondHand, CLOCK_CLOCK_SECOND) == false) + { + return false; + } - minuteHand = new Image(); - if (minuteHand == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "minuteHand new fail"); - return false; - } - if (LoadClockImage(minuteHand, CLOCK_MINUTE) == false) { - return false; - } - hourHand = new Image(); - if (hourHand == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hourHand new fail"); - return false; - } - if (LoadClockImage(hourHand, CLOCK_HOUR) == false) { - return false; - } -#if 0 - hand24Hour = new Image(); - if (hand24Hour == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hand24Hour new fail"); - return false; - } - if (LoadClockImage(hand24Hour, CLOCK_HAND24HOUR_IMAGE_PATH) == false) { - return false; - } -#endif - return true; -} + minuteHand = new Image(); + if (minuteHand == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "minuteHand new fail"); + return false; + } + if (LoadClockImage(minuteHand, CLOCK_CLOCK_MINUTE) == false) + { + return false; + } + hourHand = new Image(); + if (hourHand == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hourHand new fail"); + return false; + } + if (LoadClockImage(hourHand, CLOCK_CLOCK_HOUR) == false) + { + return false; + } -bool MainClockView::LoadClockImage(Image *view, uint32_t resId) -{ - std::string file = CLOCK_IAMGES; - ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); - if (image == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadClockImage %x fail", resId); - return false; + hand24Hour = new Image(); + if (hand24Hour == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hand24Hour new fail"); + return false; + } + if (LoadClockImage(hand24Hour, CLOCK_CLASSIC_GEOMETRY) == false) + { + return false; + } + return true; } - view->SetSrc(image); - return true; -} -bool MainClockView::LoadClockImage(UIImageView *view, uint32_t resId) -{ - std::string file = CLOCK_IAMGES; - ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); - if (image == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadClockImage %x fail", resId); - return false; + bool MainClockView::LoadClockImage(Image *view, uint32_t resId) + { + std::string file = CLOCK_IAMGES; + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadClockImage %x fail", resId); + return false; + } + view->SetSrc(image); + return true; + } + + bool MainClockView::LoadClockImage(UIImageView *view, uint32_t resId) + { + std::string file = CLOCK_IAMGES; + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadClockImage %x fail", resId); + return false; + } + view->SetSrc(image); + return true; } - view->SetSrc(image); - return true; -} -bool MainClockView::InitSweepClock(void) -{ + bool MainClockView::InitSweepClock(void) + { +#if 0 curFace = new UIImageView(); if (curFace == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace new fail"); @@ -378,12 +305,11 @@ bool MainClockView::InitSweepClock(void) } curFace->SetPosition(0, 0); - if (LoadClockImage(curFace, CLOCK_CLASSIC_GEOMETRY) == false) { + if (LoadClockImage(curFace, CLOCK_CLOCK0) == false) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace LoadClockImage CLOCK_MAIN_FACE_IMAGE fail"); return false; } - //InitLabelView(); -#if 0 + if (InitLabelView() == false) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelView() fail"); return false; @@ -413,93 +339,8 @@ bool MainClockView::InitSweepClock(void) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "progress LoadClockImage CLOCK_PROGRESS_IMAGE_PATH fail"); return false; } -#endif + InitHandView(); - /**************************************************************/ - //printf("lable init\n"); - batteryLabel = new UILabel(); - if (batteryLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLabel new fail"); - return false; - } - batteryLabel->SetPosition(228, 52); // widget's left position and top position - batteryLabel->Resize(66, 33); - float voltage = 0.0F; - uint8_t value = battery_get_voltage(&voltage); - batteryLabel->SetText((std::to_string(value) + "%").c_str()); // 更新百分比显示 - batteryLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - batteryLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); - batteryLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - //mainSweepClock->Add(batteryLabel); - if (dataLabel == nullptr) { - dataLabel = new UILabel(); - } - dataLabel->SetPosition(177, 358); // widget's left position and top position - dataLabel->Resize(200, 60); // widget's width and height - dataLabel->SetViewId("data");// Set style - dataLabel->SetStyle(STYLE_TEXT_FONT, 30); - dataLabel->SetStyle(STYLE_LINE_HEIGHT, 30); - dataLabel->SetText("12月22号"); - dataLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - dataLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - dataLabel->SetRollSpeed(0); - dataLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - //mainSweepClock->Add(dataLabel); - if (weekLabel == nullptr) { - weekLabel = new UILabel(); - } - weekLabel->SetPosition(194, 395); // widget's left position and top position - //weekLabel->Resize(200, 60); // widget's width and height - weekLabel->SetViewId("weekday");// Set style - weekLabel->SetStyle(STYLE_TEXT_FONT, 30); - weekLabel->SetStyle(STYLE_LINE_HEIGHT, 30); - weekLabel->SetText("星期五"); - weekLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - weekLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - weekLabel->SetRollSpeed(0); - weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); - - // Add Label to App - if (XTSLabel == nullptr) { - XTSLabel = new UILabel(); - } - XTSLabel->SetPosition(130, 273); // widget's left position and top position - XTSLabel->Resize(200, 60); // widget's width and height - XTSLabel->SetViewId("label1");// Set style - XTSLabel->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property - //XTSLabel->SetText("XTS测试进行中"); - XTSLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - //XTSLabel->SetTextColor(Color::GetColorFromRGBA(0xe6, 0x04, 0x09, 0xff)); - XTSLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - XTSLabel->SetRollSpeed(0); - XTSLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add BoxProgress to App - if (progress == nullptr) { - progress = new UIBoxProgress(); - } - progress->SetPosition(180, 58); // widget's left position and top position - progress->Resize(31, 19); // widget's width and height - progress->SetViewId("progress1");// Set style - progress->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - - // Set additional property - progress->SetValue(value); - // Set BackgroundStyle - progress->SetBackgroundStyle(STYLE_TEXT_COLOR, 0xff000000); - // Set ForegroundStyle - progress->SetForegroundStyle(STYLE_TEXT_COLOR, 0xff000000); - progress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff000000); - progress->SetForegroundStyle(STYLE_LINE_WIDTH, 0); - const char* progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin"; - char * progress1BackImageSrc = nullptr; - progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc); - - /**************************************************************/ - //InitLabelView(); -#if 0 weekDay = new UIImageView(); if (weekDay == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekDay new fail"); @@ -511,140 +352,115 @@ bool MainClockView::InitSweepClock(void) return false; } #endif - return true; -} - -void MainClockView::PreLoad(void) -{ - if (!viewiInitStatus) { - InitView(); - viewiInitStatus = true; + return true; } -} -void MainClockView::UnLoad(void) -{ - // Main clock view is commonly used page, so we do not release it's resources inner slice. -} - -bool MainClockView::InitView(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitView"); - - mainSweepClock = new UISweepClock(); - if (mainSweepClock == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSweepClock new fail"); - return false; + void MainClockView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; } - if (InitSweepClock() == false) { - return false; } - mainSweepClock->Add(curFace); - mainSweepClock->Add(weekLabel); - mainSweepClock->Add(dataLabel); - mainSweepClock->Add(batteryLabel); - mainSweepClock->Add(XTSLabel); - mainSweepClock->Add(progress); -#if 0 - mainSweepClock->Add(stepLabel); - mainSweepClock->Add(heartRate); - mainSweepClock->Add(weekLabel); - mainSweepClock->Add(heartRateLabel); - mainSweepClock->Add(weekDay); - mainSweepClock->Add(progress); - mainSweepClock->Add(batteryLabel); -#endif - - Add(mainSweepClock); - - mainSweepClock->SetDragParentInstead(true); - mainSweepClock->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - - // {214, 3}: position x, y {14, 223}: center x, y - mainSweepClock->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand, - { SECOND_POINT_POSITION_X, SECOND_POINT_POSITION_Y }, { SECOND_POINT_CENTER_X, SECOND_POINT_CENTER_Y }); - mainSweepClock->SetHandImage(UISweepClock::HandType::MINUTE_HAND, *minuteHand, - { MINUTE_POINT_POSITION_X, MINUTE_POINT_POSITION_Y }, { MINUTE_POINT_CENTER_X, MINUTE_POINT_CENTER_Y }); - mainSweepClock->SetHandImage(UISweepClock::HandType::HOUR_HAND, *hourHand, { HOUR_POINT_POSITION_X, HOUR_POINT_POSITION_Y }, - { HOUR_POINT_CENTER_X, HOUR_POINT_CENTER_Y }); -#if 0 - mainSweepClock->SetHandCircleImage(UISweepClock::HandType::SECOND_HAND, *smallCircle, - { SMALLCIRCLE_POSITION_X, SMALLCIRCLE_POSITION_Y }); - mainSweepClock->SetHandCircleImage(UISweepClock::HandType::MINUTE_HAND, *medCircle, - { MEDCIRCLE_POSITION_X, MEDCIRCLE_POSITION_Y }); - mainSweepClock->SetHandCircleImage(UISweepClock::HandType::HOUR_HAND, *bigCircle, - { BIGCIRCLE_POSITION_X, BIGCIRCLE_POSITION_Y }); -#endif - mainSweepClock->SetInitTime24Hour(0, 0, 0); - mainSweepClock->SetWorkMode(UISweepClock::WorkMode::NORMAL); - InitDateTime(); - - callBack = new ClockAnimatorCallback(mainSweepClock); - if (callBack == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callBack new fail"); - return false; - } - clockAnimator = new Animator(callBack, mainSweepClock, 50, true); - if (clockAnimator == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clockAnimator new fail"); - return false; + void MainClockView::UnLoad(void) + { + // Main clock view is commonly used page, so we do not release it's resources inner slice. } - progress1callback_ = new ProgressCallback(progress,batteryLabel,XTSLabel); - progress1animator_ = new Animator(progress1callback_,progress,10000,true); - progress1animator_->Start(); - clockAnimator->Start(); - SetCoverable(true); - return true; -} -void MainClockView::RefreshStep(int step) -{ -#if 0 - char stepChar[STEP_CHAR_NUM] = {0}; + bool MainClockView::InitView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitView"); - (void)sprintf_s(stepChar, STEP_CHAR_NUM, "%d", step); - stepLabel->SetText(stepChar); -#endif -} - -void MainClockView::RefreshHeartRate(int value) -{ -#if 0 - if (value == 0) { - heartRateLabel->SetText("--"); - return; - } - char heartRateChar[STEP_CHAR_NUM] = {0}; - - (void)sprintf_s(heartRateChar, STEP_CHAR_NUM, "%d", value); - heartRateLabel->SetText(heartRateChar); -#endif -} - -void MainClockView::InitDateTime(void) -{ - struct tm pTM; - time_t seconds; - time(&seconds); - localtime_r(&seconds, &pTM); - mainSweepClock->SetTime24Hour(pTM.tm_hour, pTM.tm_min, pTM.tm_sec); -} - -void MainClockView::ClockAnimatorStart(void) -{ - if (clockAnimator != nullptr) { - progress1animator_->Start(); - clockAnimator->Start(); - } -} + mainSweepClock = new UISweepClock(); + if (mainSweepClock == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSweepClock new fail"); + return false; + } + if (InitSweepClock() == false) + { + return false; + } -void MainClockView::ClockAnimatorStop(void) -{ - if (clockAnimator != nullptr) { - clockAnimator->Stop(); - progress1animator_->Stop(); + mainSweepClock->Add(curFace); + mainSweepClock->Add(stepLabel); + mainSweepClock->Add(heartRate); + mainSweepClock->Add(weekLabel); + mainSweepClock->Add(heartRateLabel); + mainSweepClock->Add(weekDay); + mainSweepClock->Add(progress); + mainSweepClock->Add(batteryLabel); + Add(mainSweepClock); + + mainSweepClock->SetDragParentInstead(true); + mainSweepClock->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + + // {214, 3}: position x, y {14, 223}: center x, y + mainSweepClock->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand, + {POINT_POSITION_X, SECOND_POINT_POSITION_Y}, {POINT_CENTER_X, POINT_CENTER_Y}); + mainSweepClock->SetHandImage(UISweepClock::HandType::MINUTE_HAND, *minuteHand, + {POINT_POSITION_X, POINT_POSITION_Y}, {POINT_CENTER_X, POINT_CENTER_Y}); + mainSweepClock->SetHandImage(UISweepClock::HandType::HOUR_HAND, *hourHand, {POINT_POSITION_X, POINT_POSITION_Y}, + {POINT_CENTER_X, POINT_CENTER_Y}); + mainSweepClock->SetHandCircleImage(UISweepClock::HandType::SECOND_HAND, *smallCircle, + {SMALLCIRCLE_POSITION_X, SMALLCIRCLE_POSITION_Y}); + mainSweepClock->SetHandCircleImage(UISweepClock::HandType::MINUTE_HAND, *medCircle, + {MEDCIRCLE_POSITION_X, MEDCIRCLE_POSITION_Y}); + mainSweepClock->SetHandCircleImage(UISweepClock::HandType::HOUR_HAND, *bigCircle, + {BIGCIRCLE_POSITION_X, BIGCIRCLE_POSITION_Y}); + + mainSweepClock->SetInitTime24Hour(0, 0, 0); + mainSweepClock->SetWorkMode(UISweepClock::WorkMode::NORMAL); + InitDateTime(); + SetCoverable(true); + return true; + } + + void MainClockView::RefreshStep(int step) + { + char stepChar[STEP_CHAR_NUM] = {0}; + + (void)sprintf_s(stepChar, STEP_CHAR_NUM, "%d", step); + stepLabel->SetText(stepChar); + } + + void MainClockView::RefreshHeartRate(int value) + { + if (value == 0) + { + heartRateLabel->SetText("--"); + return; + } + char heartRateChar[STEP_CHAR_NUM] = {0}; + + (void)sprintf_s(heartRateChar, STEP_CHAR_NUM, "%d", value); + heartRateLabel->SetText(heartRateChar); + } + + void MainClockView::InitDateTime(void) + { + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + mainSweepClock->SetTime24Hour(pTM.tm_hour, pTM.tm_min, pTM.tm_sec); + } + + void MainClockView::UpdateTime(void) + { + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t second = tv.tv_sec; + uint64_t uSecond = tv.tv_usec; + uint64_t minute = second / MIN_TO_HOUR; + uint64_t hour = minute / MIN_TO_HOUR + timezone / (MIN_TO_HOUR * MIN_TO_HOUR); + uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); + uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); + uint16_t realMilliSecond = static_cast((second % MIN_TO_HOUR) * + SEC_TO_MILLI + + uSecond / USEC_TO_MILLI); + mainSweepClock->SetSweepTime12Hour(realHour, realMinute, realMilliSecond, 1); } } - -} diff --git a/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassControlView.h b/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassControlView.h index 7fa5ee943..3867489bb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassControlView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassControlView.h @@ -23,10 +23,12 @@ public: bool InitView(void); void PreLoad(void) override; void UnLoad(void) override; + void SetCalibrationView(bool flag); private: CompassCalibrationView *compassCalibrationView{nullptr}; CompassView *compassView{nullptr}; bool viewiInitStatus{false}; + bool isCalibration{false}; void ClearAll(void); }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassControlView.cpp b/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassControlView.cpp index bd87bff20..be71dc868 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassControlView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassControlView.cpp @@ -36,7 +36,7 @@ void CompassControlView::ClearAll(void) bool CompassControlView::InitView(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassControlView::InitView(void)"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassControlView InitView"); compassCalibrationView = new CompassCalibrationView(); if (compassCalibrationView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::new compassCalibrationView fail"); @@ -64,10 +64,24 @@ bool CompassControlView::InitView(void) compassView->SetVisible(true); compassCalibrationView->SetVisible(false); } - // SetCoverable(true); return true; } +void CompassControlView::SetCalibrationView(bool flag) +{ + if (flag == isCalibration) { + return; + } + + if (flag) { + compassCalibrationView->SetVisible(true); + compassView->SetVisible(false); + } else { + compassCalibrationView->SetVisible(false); + compassView->SetVisible(true); + } +} + void CompassControlView::PreLoad(void) { if (!viewiInitStatus) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp index 3efc336c8..6c1252984 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp @@ -30,6 +30,7 @@ DialInfo dialInfo[MAX_DIALNUM] = { int dial_num; void read_dial(void) { +#if 0 DIR *dirp = opendir(DIAL_DIR); // 遍历文件 dial_num = 0; @@ -84,6 +85,7 @@ void read_dial(void) } // 关闭目录 closedir(dirp); +#endif } void printf_dial(void) diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp index 167ef3878..023b24356 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp @@ -448,7 +448,7 @@ namespace OHOS if (MainViewSample::GetInstance() != nullptr && HeartRateView::GetInstance() != nullptr) { - if (MainViewSample::GetInstance()->GetHorCurrentPage() == HEART_RATE) + if (MainViewSample::GetInstance()->GetHorCurrentCard() == HEART_RATE) { HeartRateView::GetInstance()->SetHeartRateData(rateData, sizeof(Point) * len); HeartRateView::GetInstance()->RefreshElectrocardiogram(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/CustomizationView.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/CustomizationView.h index e94a38e00..557cde567 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/CustomizationView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/CustomizationView.h @@ -10,7 +10,6 @@ #include "View.h" #include "common/screen.h" #include "components/ui_label.h" -#include "components/ui_label_ext.h" #include "components/ui_scroll_view.h" #include "components/ui_radio_button.h" #include "components/ui_label_button.h" diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkEndView.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkEndView.h index 42afc8f20..06fc19dd7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkEndView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkEndView.h @@ -8,7 +8,6 @@ #define INDOORWALK_END_VIEW_H #include "components/ui_label.h" -#include "components/ui_label_ext.h" #include "components/ui_button.h" #include "components/ui_view_group.h" #include "common/screen.h" diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkModel.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkModel.h index 0c132035f..679802aec 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkModel.h @@ -11,7 +11,6 @@ #include "string" #include "gfx_utils/list.h" #include "components/ui_label.h" -#include "components/ui_label_ext.h" #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkMotionView.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkMotionView.h index 4a4ebaa49..303045f66 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkMotionView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkMotionView.h @@ -50,7 +50,6 @@ private: bool pageStatus[MAX_MOTIONPAGE]{false}; UISwipeView::OnSwipeListener* motionclickListener{nullptr}; UIView::OnDragListener* motionDragListener{nullptr}; - AppGroupView *GreatePage(int32_t MotionPageId); }; } // namespace OHOS #endif // INDOORWALK_MOTION_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPreparedView.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPreparedView.h index 26428fb90..8f073adba 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPreparedView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPreparedView.h @@ -9,7 +9,6 @@ #include "View.h" #include "components/ui_label.h" -#include "components/ui_label_ext.h" #include "components/ui_image_view.h" #include "components/ui_label_button.h" #include "components/ui_image_animator.h" diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPresenter.h index 1048f3f7c..b3f4c7df5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/IndoorWalkPresenter.h @@ -9,13 +9,10 @@ #include "Presenter.h" #include "components/ui_label.h" -#include "components/ui_label_ext.h" #include "NativeLauncher.h" #include "NativeAbility.h" #include "components/ui_swipe_view.h" -#include "KeyInputListener.h" -#include "common/key_code.h" namespace OHOS { enum IndoorWalkPresenterNum : uint8_t { @@ -65,7 +62,7 @@ static constexpr const char *STEPS_BUTTON = "stepsView"; // 步数 class IndoorWalkView; class IndoorWalkPresenter : public Presenter, public UISwipeView::OnSwipeListener, - public UIView::OnClickListener, public UIView::OnLongPressListener,public RootView::OnKeyActListener, + public UIView::OnClickListener, public UIView::OnLongPressListener, public UIView::OnDragListener { public: IndoorWalkPresenter(); @@ -77,7 +74,6 @@ public: void OnStop() override; bool OnClick(UIView& view, const ClickEvent& event) override; bool OnDrag(UIView& view, const DragEvent& event) override; - bool OnKeyAct(UIView &view, const KeyEvent &event) override; bool OnLongPress(UIView& view, const LongPressEvent& event) override; virtual void OnSwipe(UISwipeView& view) override; void HidePageImageView(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFifth.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFifth.h index 5b8dcff66..745f0fce0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFifth.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFifth.h @@ -12,7 +12,6 @@ #include "wearable_log.h" #include "ohos_types.h" #include "components/ui_label.h" -#include "components/ui_label_ext.h" #include "components/ui_image_view.h" #include "AppGroupView.h" diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFirst.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFirst.h index c782855f2..8b0c1d188 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFirst.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFirst.h @@ -12,7 +12,6 @@ #include "wearable_log.h" #include "ohos_types.h" #include "components/ui_label.h" -#include "components/ui_label_ext.h" #include "components/ui_image_view.h" #include "AppGroupView.h" diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFourth.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFourth.h index c5671dafc..f141257d1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFourth.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageFourth.h @@ -12,7 +12,6 @@ #include "wearable_log.h" #include "ohos_types.h" #include "components/ui_label.h" -#include "components/ui_label_ext.h" #include "components/ui_image_view.h" #include "AppGroupView.h" diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageSecond.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageSecond.h index 9c27255aa..005178aa7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageSecond.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageSecond.h @@ -12,7 +12,6 @@ #include "wearable_log.h" #include "ohos_types.h" #include "components/ui_label.h" -#include "components/ui_label_ext.h" #include "components/ui_image_view.h" #include "AppGroupView.h" diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageThird.h b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageThird.h index 3b1c816e9..de2e51743 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageThird.h +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/include/MotionPageThird.h @@ -12,7 +12,6 @@ #include "wearable_log.h" #include "ohos_types.h" #include "components/ui_label.h" -#include "components/ui_label_ext.h" #include "components/ui_image_view.h" #include "AppGroupView.h" diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkMotionView.cpp b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkMotionView.cpp index 866e42f86..a3350f28e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkMotionView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkMotionView.cpp @@ -127,7 +127,7 @@ UIViewGroup *IndoorWalkMotionView::WalkMotionViewInit(void) walkMotionList->SetAnimatorTime(50); // 50:animator drag time(ms) for (uint16_t i = 0; i < maxPage; i++) { - recordCard[i] = GreatePage(i); + recordCard[i] = (this->*(g_pageMapper[i].func))(); if (recordCard[i] == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "IndoorWalkMotionView:: recordCard %d error", i); return nullptr; @@ -170,20 +170,4 @@ void IndoorWalkMotionView::InitialStep() IndoorWalkModel::GetInstance()->SetInitialStep(stepValue); } -AppGroupView *IndoorWalkMotionView::GreatePage(int32_t StreamId) -{ - uint16_t i; - AppGroupView *view = nullptr; - int32_t MotionPageId = ScreenModels::GetInstance()->GetCardPage(StreamId); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GreatePage MotionPageId:%d", MotionPageId); - for (i = 0; i < sizeof(g_pageMapper) / sizeof(g_pageMapper[0]); i++) { - if (g_pageMapper[i].id == MotionPageId) { - view = (this->*(g_pageMapper[i].func))(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GreatePage view:%p", view); - return view; - } - } - return nullptr; -} - } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPreparedView.cpp b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPreparedView.cpp index 47eeb84e3..326e8605f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPreparedView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPreparedView.cpp @@ -135,7 +135,7 @@ bool IndoorWalkPreparedView::InitBatteryView() // 加载电量 return false; } battery->SetPosition(BATTERY_X, BATTERY_Y); - //ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, battery, DROPDOWN_DROPDOWN_BATTERY); + // ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, battery, DROPDOWN_DROPDOWN_BATTERY); group->Add(battery); batteryLable = new UILabel(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp index 543b3626c..6e33f8f50 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkPresenter.cpp @@ -165,19 +165,6 @@ void IndoorWalkPresenter::OnSwipe(UISwipeView &view) return; } -bool IndoorWalkPresenter::OnKeyAct(UIView &view, const KeyEvent &event) -{ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "IndoorWalkPresenter::OnKeyAct"); - uint16 keyID = event.GetKeyId(); - // 如果是power键就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) - { - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - } - return true; -} - bool IndoorWalkPresenter::OnClick(UIView& view, const ClickEvent& event) { UNUSED(event); diff --git a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkView.cpp b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkView.cpp index bbb5d69b2..23bd60810 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/indoorwalk/src/IndoorWalkView.cpp @@ -39,9 +39,7 @@ void IndoorWalkView::OnStart() WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "IndoorWalkView::~OnStart"); View::OnStart(); BaseView::RootView(Color::Black().full); - // 增加按键监听 - RootView::OnKeyActListener *keyactListener =(RootView::OnKeyActListener *)OHOS::IndoorWalkPresenter::GetInstance(); - RootView::GetInstance()->SetOnKeyActListener(keyactListener); + ChangeView(INDOORWALK_MAX, INDOORWALKPREPAREDVIEW); RootView::GetInstance()->Invalidate(); return; diff --git a/code/sdk/application/wearable/fd230app/nativeui/key/include/KeyInputListener.h b/code/sdk/application/wearable/fd230app/nativeui/key/include/KeyInputListener.h index a5bd57cc4..3e22e2c69 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/key/include/KeyInputListener.h +++ b/code/sdk/application/wearable/fd230app/nativeui/key/include/KeyInputListener.h @@ -23,17 +23,16 @@ namespace OHOS virtual ~KeyInputListener() {} bool OnKeyAct(UIView &view, const KeyEvent &event) override; - private: - void OnKeyPress(void); - void OnKeyLongPress(const KeyEvent &event); - void OnKeyRelease(const KeyEvent &event); - void CallVolumeDipSwitchControl(uint8_t status); - void PlayerVolumeDipSwitchControl(uint8_t model); - - private: - int32 pressFlag{0}; // 按下标志 - int32 longPressFlag{0}; // 长按标志 - VolumeSliderEventListener *volumeSliderEventListener{nullptr}; - }; +private: + void OnKeyPress(void); + void OnKeyLongPress(const KeyEvent& event); + void OnKeyRelease(const KeyEvent& event); + void CallVolumeDipSwitchControl(VolumeChangeStatus status); + void PlayerVolumeDipSwitchControl(VolumeChangeStatus status); +private: + int32 pressFlag{0}; + int32 longPressFlag{0}; + VolumeSliderEventListener *volumeSliderEventListener{nullptr}; +}; } #endif // KEY_INPUT_LISTENER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp b/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp index 63b086b22..684b0f94e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp @@ -88,43 +88,33 @@ namespace OHOS return; } - void KeyInputListener::CallVolumeDipSwitchControl(uint8_t model) - { - if (MainCallingPresenter::GetInstance() != nullptr && CallerLogModel::GetInstance()->GetCallStatus()) - { - if (CallerLogModel::GetInstance()->GetVolumeScreenStatus() == true) - { - volumeSliderEventListener = VolumeSliderEventListener::GetInstance(); - if (volumeSliderEventListener == nullptr) - { - return; - } - volumeSliderEventListener->ChangeVolume(model); - } - else - { - MainCallingPresenter::GetInstance()->HonrsViewChange(); - CallerLogModel::GetInstance()->SetVolumeScreenStatus(true); +void KeyInputListener::CallVolumeDipSwitchControl(VolumeChangeStatus status) +{ + if (MainCallingPresenter::GetInstance() != nullptr && CallerLogModel::GetInstance()->GetCallStatus()) { + if (CallerLogModel::GetInstance()->GetVolumeScreenStatus() == true) { + volumeSliderEventListener = VolumeSliderEventListener::GetInstance(); + if (volumeSliderEventListener == nullptr) { + return; } + volumeSliderEventListener->ChangeVolume(status); + } else { + MainCallingPresenter::GetInstance()->HonrsViewChange(); + CallerLogModel::GetInstance()->SetVolumeScreenStatus(true); } - if (IsNotifyCallStatus() == true) - { - if (NotificationManager::GetInstance()->GetVolumeScreenStatus() == true) - { - volumeSliderEventListener = VolumeSliderEventListener::GetInstance(); - if (volumeSliderEventListener == nullptr) - { - return; - } - volumeSliderEventListener->ChangeVolume(model); - } - else - { - HonrsViewChange(); - NotificationManager::GetInstance()->SetVolumeScreenStatus(true); + } + if (IsNotifyCallStatus() == true) { + if (NotificationManager::GetInstance()->GetVolumeScreenStatus() == true) { + volumeSliderEventListener = VolumeSliderEventListener::GetInstance(); + if (volumeSliderEventListener == nullptr) { + return; } + volumeSliderEventListener->ChangeVolume(status); + } else { + HonrsViewChange(); + NotificationManager::GetInstance()->SetVolumeScreenStatus(true); } } +} extern "C" { @@ -144,7 +134,7 @@ namespace OHOS // 如果当前页面是音量卡片或正在通话中,则执行音量+操作 if (currentViewId == VIEW_INCOMING_CALL || IsCallingNotify() == true) // 音量卡片 { - CallVolumeDipSwitchControl(1); // 音量+ + CallVolumeDipSwitchControl(VOLUMEUP); // 音量+ } else if (currentViewId != VIEW_MAIN) // 如果当前页面不是主表盘,如果屏幕亮起,则先处理闹钟通知再切换到主表盘页面 { @@ -179,7 +169,7 @@ namespace OHOS // 如果当前页面是音量卡片或正在通话中,则执行音量减操作 if (currentViewId == VIEW_INCOMING_CALL || IsCallingNotify() == true) // 音量卡片 { - CallVolumeDipSwitchControl(0); // 音量- + CallVolumeDipSwitchControl(VOLUMEDOWN); // 音量- } else if (currentViewId != VIEW_MAIN) // 如果当前页面不是主表盘,如果屏幕亮起,则先处理闹钟通知再切换到主表盘页面。 { diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinParser.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/DialBinParser.h similarity index 86% rename from code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinParser.h rename to code/sdk/application/wearable/fd230app/nativeui/main/include/DialBinParser.h index 0a30225cb..dc737236f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinParser.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/DialBinParser.h @@ -22,12 +22,12 @@ #include "components/ui_abstract_progress.h" namespace OHOS { - class DialBinParser { public: static DialBinParser* GetInstance(void); bool UpdateDial(const std::string& file, FILE* fp, DialViewGroup* group); - void* MallocAndReadBuf(FILE* file, uint32_t readSize); + bool GetDialPreviewInfo(FILE* fp, DialPreviewInfo* info); + protected: int32_t ParseDialHeader(FILE* file); int32_t ParserDialStaticImg(FILE* fp); @@ -41,21 +41,21 @@ protected: int32_t ParserDialArcProgress(FILE* fp); int32_t ParserDialVideo(FILE* fp); int32_t ParserDialClick(FILE* fp); - + int32_t ParserDialKaleidoscope(FILE* fp); + private: DialBinParser(); virtual ~DialBinParser(); - + void* MallocAndReadBuf(FILE* file, uint32_t readSize); bool SetProgressType(FILE* fp, UIAbstractProgress* view, DialProgressType data); - static constexpr uint8_t DIAL_BIN_PARSER_FUNC_NUM = 11; + static constexpr uint8_t DIAL_BIN_PARSER_FUNC_NUM = 12; // 12: func max value int32_t (DialBinParser::*funcArray_[DIAL_BIN_PARSER_FUNC_NUM])(FILE*); DialViewGroup* dialGroup_ = nullptr; std::string file_; - uint32_t dirId_ = 0xfef << 20; + uint32_t dirId_ = 0xfef << 20; // 20: offset uint32_t imageOffset_ = 0; - uint32_t pre_ = 0; }; } -#endif \ No newline at end of file +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinTypes.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/DialBinTypes.h similarity index 77% rename from code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinTypes.h rename to code/sdk/application/wearable/fd230app/nativeui/main/include/DialBinTypes.h index aadaf2181..1f8f49375 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinTypes.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/DialBinTypes.h @@ -19,6 +19,18 @@ #include "components/ui_canvas_ext.h" namespace OHOS { +static constexpr uint8_t DIAL_NAME_MAX_LEN = 16; +static constexpr uint8_t DIAL_VERSION_MAX_LEN = 16; +static constexpr uint8_t DIAL_DESCRIPTION_MAX_LEN = 128; +static constexpr uint8_t DIAL_DIGITALIMG_IMG_MAX_NUM = 10; + +struct DialPreviewInfo { + char dialName[DIAL_NAME_MAX_LEN]; + char description[DIAL_DESCRIPTION_MAX_LEN]; + uint32_t imgId; + uint32_t offset; +}; + struct DialRect { int16_t x; int16_t y; @@ -27,12 +39,12 @@ struct DialRect { }; struct DialHeader { - char dialName[16]; + char dialName[DIAL_NAME_MAX_LEN]; int16_t width; int16_t height; - char version[16]; + char version[DIAL_VERSION_MAX_LEN]; uint16_t previewImgId; - char description[128]; + char description[DIAL_DESCRIPTION_MAX_LEN]; uint32_t imageOffset; uint8_t freq; uint8_t dialViewCount; @@ -69,12 +81,11 @@ struct DialOptionImg { uint8_t count; }; -constexpr uint8_t DIGITALIMG_IMG_MAX_NUM = 10; struct DialDigitalImg { uint8_t alignType : 4; uint8_t integerLength : 4; uint8_t decimalPrecision; - uint16_t imgIds[DIGITALIMG_IMG_MAX_NUM]; + uint16_t imgIds[DIAL_DIGITALIMG_IMG_MAX_NUM]; int16_t signImgId; int16_t decimalPointImgId; uint16_t space; @@ -154,5 +165,11 @@ struct DialClick { char bundleName[64]; }; }; + +struct DialKaleidoscope { + uint16_t imgId; + float crownRotateStep; + float animatorRotateStep; +}; } #endif // GRAPHIC_LITE_DIAL_BIN_TYPE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainModel.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainModel.h new file mode 100644 index 000000000..6bc09a099 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainModel.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainModel.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef MAIN_MODEL_H +#define MAIN_MODEL_H + +#include +#include "UiConfig.h" + +namespace OHOS { + typedef struct { + CardId id; + const char *cardImg; + } CardInfo; + + typedef struct { + DialId id; + const char *dialName; + const char *dialImg; + uint8_t freq; + } DialInfo; + + typedef struct { + uint8_t dialFlag; + uint8_t dialId; + std::string dialFullName; + } DialSetting; + + class MainModel { + public: + static MainModel &GetInstance(void); + void InitCardSettings(void); + uint8_t GetCardSettingCount(void); + CardId *GetCardSettings(void); + void DeleteCardSetting(uint8_t index); + void AddCardSetting(uint8_t index); + const CardInfo *GetCardInfo(CardId card) const; + const DialInfo *GetDialInfo(DialId dial) const; + void AddDialSetting(const DialSetting &setting); + void InitDialSettings(void); + DialSetting &GetDialSetting(); + private: + void InitDialSettingDefault(void); + MainModel(); + MainModel(const MainModel &); + MainModel &operator=(const MainModel &); + virtual ~MainModel(); + + CardId cardSettings[CARD_SETTING_COUNT_MAX] = { MAX_CARD }; + uint8_t cardSettingCount{0}; + DialSetting dialSetting; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h index 6d2dc9046..c375d34e8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h @@ -15,6 +15,7 @@ #include "KeyInputListener.h" #include "drag_event.h" #include "MainViewSample.h" +#include "MainModel.h" #include "components/ui_swipe_view.h" #include "components/ui_view.h" #include "CompassView.h" @@ -44,13 +45,14 @@ namespace OHOS constexpr uint16_t VERTICAL_STATUS = 1; constexpr uint16_t HORIZONTAL_STATUS = 0; - class MainViewSample; - class MainPresenterSample : public Presenter, public ModelListenerSample, public UIView::OnClickListener, public UISwipeView::OnSwipeListener, public UISwipeView, public CompassPresenter, public UIView::OnLongPressListener - { - public: - MainPresenterSample(); - virtual ~MainPresenterSample(); - static MainPresenterSample *GetInstance(void); +class MainViewSample; +class MainPresenterSample : public Presenter, public ModelListenerSample, + public UIView::OnClickListener, public UISwipeView::OnSwipeListener, + public UIView::OnLongPressListener, public UISwipeView, public CompassPresenter { +public: + MainPresenterSample(); + virtual ~MainPresenterSample(); + static MainPresenterSample *GetInstance(void); void OnStart() override; void OnPause() override; @@ -61,37 +63,29 @@ namespace OHOS bool OnLongPress(UIView &view, const LongPressEvent &event) override; virtual void OnSwipe(UISwipeView &view) override; void SetPage(int8_t id); - void SetTaskPeroid(int page); + void SetTaskPeroid(CardId cardId); void setCallback(ZoomEffect *callback) { callback_ = callback; } - void SetDialPath(std::string filePath) - { - filePath_ = filePath; - } - - std::string GetDialPath() - { - return filePath_; - } - - private: - void ProcessDataNotify(void); - void SetCircleProgress(void); - void SetCompassRotate(void); - KeyInputListener *keyActListener_{nullptr}; - ZoomEffect *callback_{nullptr}; - uint8_t state = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; - int16_t musicCount{0}; - int64_t playerCurrentTime{0}; - int64_t playerMusicDuration{0}; - int64_t playerProgressVlaue{0}; - int8_t entryTimes{1}; - std::string filePath_; - bool isCompassSensorOpened_{false}; - }; + void InitCardSettings(void); + uint8_t GetCardSettingCount(void); + CardId *GetCardSettings(void); + void InitDialSettings(void); + DialSetting& GetDialSetting(); +private: + void ProcessDataNotify(void); + void SetCircleProgress(void); + void SetCompassRotate(void); + KeyInputListener *keyActListener_{nullptr}; + ZoomEffect* callback_{nullptr}; + uint8_t state_ = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; + int64_t playerCurrentTime_{0}; + int64_t playerMusicDuration_{0}; + int64_t playerProgressValue_{0}; + bool isCompassSensorOpened_{false}; +}; } #endif // MAIN_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainViewSample.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainViewSample.h index c193757f6..de9e751ab 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainViewSample.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainViewSample.h @@ -20,12 +20,9 @@ #include "ModelListenerSample.h" #include "ScreenModels.h" #include "ActivityWeekView.h" -#include "compass/include/CompassControlView.h" -#if USE_OFFLINE_DIAL +#include "CompassControlView.h" #include "DialViewGroup.h" -#else #include "MainClockView.h" -#endif #include "PlayersView.h" #include "MainPresenterSample.h" #include "HeartRateView.h" @@ -33,6 +30,7 @@ #include "PullUpDownView.h" #include "components/ui_cross_view.h" +#include "SetCardModel.h" #include "heart_blood/include/BloodCardView.h" #include "traing/training_card/include/Training_CardView.h" #include "ApplistCardView.h" @@ -51,6 +49,7 @@ namespace OHOS void OnSetUpView() override; void OnTearDownView() override; void OnStop() override; + UICardPage *InitWatchFacePage(void); UICardPage *InitHeartRatePage(void); UICardPage *InitActivityPage(void); @@ -60,12 +59,10 @@ namespace OHOS UICardPage *InitWeatherPage(void); UICardPage *InitTrainingPage(void); UICardPage *InitApplistPage(void); + void AnimatorStart(int pageIndex); void AnimatorStop(void); - uint16_t GetHorCurrentPage() const - { - return mainSwipeGroup->GetCurrentPageId(UISwipeView::HORIZONTAL); // 0: horizontal; 1: vertical - } + CardId GetHorCurrentCard() const; UIView *GetMainViewGroup(void) const { @@ -82,8 +79,6 @@ namespace OHOS if (mainClockView != nullptr) { SetPage(mainClockView->GetViewIndex()); - mainClockView->ComeBack(); - mainClockView->Invalidate(); } } @@ -94,19 +89,9 @@ namespace OHOS private: PullUpDownView *dropDownView{nullptr}; -#if USE_OFFLINE_DIAL - DialViewGroup *mainClockView{nullptr}; -#else - MainClockView *mainClockView{nullptr}; -#endif - - /* -------------------------------------------------------------------------- */ + UICardPage *mainClockView{nullptr}; MessageCardView *messageView{nullptr}; UILabel *MessageLable = nullptr; - // UIList *Messagelist = nullptr; - // IconAdapter *list1adapter_ = nullptr; - // List *Messagelistdate = nullptr; - /* -------------------------------------------------------------------------- */ ActivityWeekView *activityWeekView{nullptr}; PlayersView *playersView{nullptr}; CompassControlView *compassControlView{nullptr}; @@ -126,6 +111,9 @@ namespace OHOS void VerticalViewInit(void); void VertViewLoad(void); void HorViewLoad(void); + + UICardPage *InitWathOffDial(DialSetting &setting); + UICardPage *InitWathDial(DialSetting &setting); }; } // namespace OHOS #endif // MAIN_VIEW_SAMPLE_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingPresenter.h index 7daf8e600..f18dac441 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingPresenter.h @@ -24,11 +24,12 @@ namespace OHOS { typedef enum : uint16_t { VOLUMEPHONE = 1, VOLUMEPLAYERS = 3, + VOLUMEPHONENOTIFY = 4, } VolumeFactor; typedef enum : uint8_t { - VOLUMELOWERS = 0, - VOLUMELEVATED = 1, + VOLUMEDOWN = 0, + VOLUMEUP = 1, VOLUMEDRAG = 2, } VolumeChangeStatus; @@ -41,8 +42,7 @@ public: static VolumeSliderEventListener *GetInstance(); void OnChange(int32_t progress) override; void OnRelease(int32_t progress) override; - void ChangeImage(void); - void ChangeVolume(uint8_t status); + void ChangeVolume(VolumeChangeStatus status); bool OnClick(UIView& view, const ClickEvent& event) override; bool OnDrag(UIView& view, const DragEvent& event) override; void SetPlayerCoefficients(int16_t value); diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingView.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingView.h index 5248864f0..efdb0d883 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingView.h @@ -31,10 +31,13 @@ public: bool SetUpVolume(void); UIButton *GetIncreaseButton(void); UIButton *GetDecreaseButton(void); + int get_progress_vlaue() + { + return progress->GetValue(); + } private: VolumeSliderEventListener *listener{nullptr}; UISlider *progress{nullptr}; - UIImageView* VolumeVetor = nullptr; UIButton *increaseButton{nullptr}; UIButton *decreaseButton{nullptr}; int ShowVolume(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialKaleidoscopeView.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialKaleidoscopeView.h new file mode 100644 index 000000000..f73c2b817 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialKaleidoscopeView.h @@ -0,0 +1,11 @@ +/* + * Copyright (c) @CompanyNameMagicTag. 2024. All rights reserved. + */ + +#ifndef DIAL_KALEIDOSCOPE_VIEW_H +#define DIAL_KALEIDOSCOPE_VIEW_H +#include "components/ui_kaleidoscope_view.h" +namespace OHOS{ +using DialKaleidoscopeView = UIKaleidoscopeView; +} +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp new file mode 100644 index 000000000..53a0dd307 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainModel.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "unistd.h" +#include "MainModel.h" +#include "kv_store.h" +#include "securec.h" +#include "wearable_log.h" + +namespace OHOS { + static const int CARD_SETTING_VALUE_LEN = 32; + static const int DIAL_SETTING_VALUE_LEN = 64; + const CardInfo cardInfoMap[] = { + { HEART_RATE, PNG_SET_CARD_HEART }, + { COMPASS, PNG_SET_CARD_COMPASS }, + { ACTIVITY, PNG_SET_CARD_ACTIVITY }, + { MUSIC_PLAYER, PNG_SET_CARD_PLAYER }, + }; + + const DialInfo dialInfoMap[] = { + { DIAL_CLOCK, "扫秒表盘", PNG_SET_DIAL_CLOCK, DEFAULT_TASK_PERIOD }, + }; + + MainModel::MainModel() {} + + MainModel::~MainModel() {} + + MainModel &MainModel::GetInstance() + { + static MainModel instance; + return instance; + } + + const CardInfo *MainModel::GetCardInfo(CardId card) const + { + for (uint8_t i = 0; i < (sizeof(cardInfoMap) / sizeof(cardInfoMap[0])); i++) { + if (card == cardInfoMap[i].id) { + return &cardInfoMap[i]; + } + } + return nullptr; + } + + const DialInfo *MainModel::GetDialInfo(DialId dialId) const + { + for (uint8_t i = 0; i < (sizeof(dialInfoMap) / sizeof(dialInfoMap[0])); i++) { + if (dialId == dialInfoMap[i].id) { + return &dialInfoMap[i]; + } + } + return nullptr; + } + + void MainModel::InitCardSettings(void) + { + char temp[CARD_SETTING_VALUE_LEN] = { 0 }; + int len; + int index = 0; + + memset_s(cardSettings, CARD_SETTING_COUNT_MAX, 0, CARD_SETTING_COUNT_MAX); + len = UtilsGetValue("card_setting", temp, CARD_SETTING_VALUE_LEN); + if (len >= 0) { + /* 读取用户card配置 */ + char *setBuffer = nullptr; + char *setValue = strtok_s(temp, ",", &setBuffer); + while (setValue != nullptr) { + if (index >= CARD_SETTING_COUNT_MAX) { + break; + } + cardSettings[index++] = (CardId)atoi(setValue); + setValue = strtok_s(nullptr, ",", &setBuffer); + } + cardSettingCount = index; + } else { + /* 使用默认card配置 */ + cardSettings[index++] = WATCH_FACE; + cardSettings[index++] = HEART_RATE; + cardSettings[index++] = COMPASS; + cardSettings[index++] = ACTIVITY; + cardSettings[index++] = MUSIC_PLAYER; + cardSettingCount = index; + } + } + + void MainModel::DeleteCardSetting(uint8_t index) + { + char temp[CARD_SETTING_VALUE_LEN] = { 0 }; + for (uint8_t i = 0; i < cardSettingCount; i++) { + if (i == index + 1) { + uint8_t j = i; + for (; j < cardSettingCount - 1; j++) { + cardSettings[j] = cardSettings[j + 1]; + } + cardSettings[j] = MAX_CARD; + cardSettingCount--; + } + } + + for (uint8_t i = 0; i < cardSettingCount; i++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "cardSettings[%d] = %d", i, cardSettings[i]); + (void)sprintf_s(temp + strlen(temp), CARD_SETTING_VALUE_LEN, "%d,", cardSettings[i]); + } + (void)UtilsSetValue("card_setting", temp); + } + + void MainModel::AddCardSetting(uint8_t index) + { + char temp[CARD_SETTING_VALUE_LEN] = { 0 }; + if (cardSettingCount >= CARD_SETTING_COUNT_MAX) { + return; + } + for (int i = 0; i < cardSettingCount; i++) { + if (cardSettings[i] == cardInfoMap[index].id) { + return; + } + } + cardSettings[cardSettingCount++] = cardInfoMap[index].id; + for (uint8_t i = 0; i < cardSettingCount; i++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "cardSettings[%d] = %d", i, cardSettings[i]); + (void)sprintf_s(temp + strlen(temp), CARD_SETTING_VALUE_LEN, "%d,", cardSettings[i]); + } + (void)UtilsSetValue("card_setting", temp); + } + + uint8_t MainModel::GetCardSettingCount(void) + { + return cardSettingCount; + } + + CardId *MainModel::GetCardSettings(void) + { + return cardSettings; + } + + void MainModel::InitDialSettingDefault(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitDialSettingDefault"); + dialSetting.dialFlag = 0; + dialSetting.dialId = DIAL_CLOCK; + dialSetting.dialFullName = ""; + } + + void MainModel::AddDialSetting(const DialSetting &setting) + { + std::string tmp; + tmp += std::to_string(setting.dialFlag); + tmp += ","; + tmp += std::to_string(setting.dialId); + tmp += ","; + tmp += setting.dialFullName; + tmp += ","; + (void)UtilsSetValue("dial_setting", tmp.c_str()); + } + + void MainModel::InitDialSettings(void) + { + char temp[DIAL_SETTING_VALUE_LEN] = { 0 }; + int len; + len = UtilsGetValue("dial_setting", temp, DIAL_SETTING_VALUE_LEN); + if (len >= 0) { + char *setBuffer = nullptr; + char *setValue = strtok_s(temp, ",", &setBuffer); + if (setValue != nullptr) { + dialSetting.dialFlag = atoi(setValue); + } else { + InitDialSettingDefault(); + return; + } + + setValue = strtok_s(nullptr, ",", &setBuffer); + if (setValue != nullptr) { + dialSetting.dialId = atoi(setValue); + } else { + InitDialSettingDefault(); + return; + } + + setValue = strtok_s(nullptr, ",", &setBuffer); + if (setValue != nullptr) { + dialSetting.dialFullName = setValue; + if (!((dialSetting.dialFullName.length() > 0) && + (access(dialSetting.dialFullName.c_str(), F_OK) == 0))) { + InitDialSettingDefault(); + return; + } + } else { + InitDialSettingDefault(); + return; + } + } else { + InitDialSettingDefault(); + } + } + + DialSetting& MainModel::GetDialSetting() + { + return dialSetting; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp index 7d451916e..c0731e932 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp @@ -84,7 +84,7 @@ namespace OHOS void MainPresenterSample::OnStop(void) { - if (entryTimes == 0) + if (isCompassSensorOpened_) { CompassModel::GetInstance()->CloseCompassSensor(); } @@ -96,20 +96,13 @@ namespace OHOS keyActListener_ = nullptr; } } - // 长按进入切换表盘页面 - bool MainPresenterSample::OnLongPress(UIView &view, const LongPressEvent &event) - { - UNUSED(event); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnLongPress OnLongPress"); - NativeAbility::GetInstance().ChangeSlice(VIEW_DIALUPDATE); - return true; - } + bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StatusButtonClickListener: %s", view.GetViewId()); string curViewId = view.GetViewId(); -#if 0 + UIImageView *imgView = static_cast(&view); if (HealthModel::GetInstance() == nullptr) { @@ -118,35 +111,29 @@ namespace OHOS } if (curViewId == DROPDOWN_CLICK_DONOTDISTURB) { - if (HealthModel::GetInstance()->GetDntDistStatus() == 0) - { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_DN_DISTURB_B); - HealthModel::GetInstance()->UpdateDntDistStatus(1); - } - else - { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_DN_DISTURB); - HealthModel::GetInstance()->UpdateDntDistStatus(0); - } +#if 0 + if (HealthModel::GetInstance()->GetDntDistStatus() == 0) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_DN_DISTURB_B); + HealthModel::GetInstance()->UpdateDntDistStatus(1); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_DN_DISTURB); + HealthModel::GetInstance()->UpdateDntDistStatus(0); } - if (curViewId == DROPDOWN_CLICK_BRIGHTENSCREEN) - { - if (HealthModel::GetInstance()->GetBriScrStatus() == 0) - { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_BRI_SCREEN_B); - HealthModel::GetInstance()->UpdateBriScrStatus(1); - int32_t enable = 0; - SendMsgToUIService(SCREEN_OFF_ENABLE_TO_UI, 0, &enable, sizeof(int32_t)); - } - else - { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_BRI_SCREEN); - HealthModel::GetInstance()->UpdateBriScrStatus(0); - int32_t enable = 1; - SendMsgToUIService(SCREEN_OFF_ENABLE_TO_UI, 0, &enable, sizeof(int32_t)); - } + } + if (curViewId == DROPDOWN_CLICK_BRIGHTENSCREEN) { + if (HealthModel::GetInstance()->GetBriScrStatus() == 0) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_BRI_SCREEN_B); + HealthModel::GetInstance()->UpdateBriScrStatus(1); + int32_t enable = 0; + SendMsgToUIService(SCREEN_OFF_ENABLE_TO_UI, 0, &enable, sizeof(int32_t)); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_BRI_SCREEN); + HealthModel::GetInstance()->UpdateBriScrStatus(0); + int32_t enable = 1; + SendMsgToUIService(SCREEN_OFF_ENABLE_TO_UI, 0, &enable, sizeof(int32_t)); } #endif + } if (g_jumpView.count(curViewId) != 0) { NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId]); @@ -154,6 +141,24 @@ namespace OHOS return true; } + bool MainPresenterSample::OnLongPress(UIView &view, const LongPressEvent &event) + { + UNUSED(event); + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample OnLongPress"); + uint8_t cardId = view_->GetHorCurrentCard(); + if (cardId != WATCH_FACE) + { + SetCardModel::GetInstance().SetSelectedCard(cardId); + NativeAbility::GetInstance().ChangeSlice(VIEW_SET_CARD); + } + else + { + NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL); + } + return true; + } + void MainPresenterSample::SetPage(int8_t id) { if (view_ != nullptr) @@ -162,22 +167,27 @@ namespace OHOS } } - void MainPresenterSample::SetTaskPeroid(int page) + void MainPresenterSample::SetTaskPeroid(CardId cardId) { - if (page == COMPASS) + if (cardId == COMPASS) { PresenterTask::GetInstance()->SetPeriod(DEFAULT_TASK_PERIOD); } - else if (page == WATCH_FACE) + else if (cardId == WATCH_FACE) { -#if USE_OFFLINE_DIAL - uint32_t time = dynamic_cast(view_->GetViewById(WATCH_FACE))->GetPeriod(); -#else - uint32_t time = DEFAULT_TASK_PERIOD; -#endif + uint32_t time; + DialSetting &setting = GetDialSetting(); + if (setting.dialFlag) + { + time = dynamic_cast(view_->GetViewById(WATCH_FACE))->GetPeriod(); + } + else + { + time = DEFAULT_TASK_PERIOD; + } PresenterTask::GetInstance()->SetPeriod(time); } - else if (page == MUSIC_PLAYER) + else if (cardId == MUSIC_PLAYER) { PresenterTask::GetInstance()->SetPeriod(PLAYER_PERIOD); } @@ -189,31 +199,28 @@ namespace OHOS void MainPresenterSample::OnSwipe(UISwipeView &view) { -#if TESTCHECK - MemCheck::GetInstance()->DumpMemInfo(); - printf("total size:%d\n", view_->GetHorCurrentPage()); -#endif UNUSED(view); - int page = view_->GetHorCurrentPage(); + CardId cardId = view_->GetHorCurrentCard(); callback_->OnSwipe(view); - SetTaskPeroid(page); - if (page == COMPASS) + SetTaskPeroid(cardId); + if (cardId == COMPASS) { if (!isCompassSensorOpened_) { CompassModel::GetInstance()->OpenCompassSensor(); isCompassSensorOpened_ = true; } - else if (entryTimes == 0) - { - CompassModel::GetInstance()->CloseCompassSensor(); - entryTimes++; - } - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe"); - return; } + else if (isCompassSensorOpened_) + { + CompassModel::GetInstance()->CloseCompassSensor(); + isCompassSensorOpened_ = false; + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe"); + return; } + void MainPresenterSample::ProcessDataNotify(void) { HealthMsg healthMsg; @@ -243,75 +250,82 @@ namespace OHOS { return; } - state = playersView->GetPlayerButtonState(); - if (state == UICheckBox::UICheckBoxState::SELECTED) + state_ = playersView->GetPlayerButtonState(); + if (state_ == UICheckBox::UICheckBoxState::SELECTED) { - PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime); - PlayersModel::GetInstance()->GetDuration(playerMusicDuration); - if (playerMusicDuration != 0) + int32_t playerState; + PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState); + if (playerState != PLAYER_STARTED) + { + playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); + return; + } + PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_); + PlayersModel::GetInstance()->GetDuration(playerMusicDuration_); + if (playerMusicDuration_ != 0) { - playerProgressVlaue = (playerCurrentTime * PROGRESS_PERCENTAGE) / playerMusicDuration; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressVlaue %lld", playerProgressVlaue); + playerProgressValue_ = (playerCurrentTime_ * PROGRESS_PERCENTAGE) / playerMusicDuration_; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressValue_ %lld", playerProgressValue_); } else { - playerProgressVlaue = 100; // 100: max progress value + playerProgressValue_ = 100; // 100: max progress value } - PlayersModel::GetInstance()->SetCircleProgress(playerProgressVlaue); - PlayersPresenter::GetInstance()->SetPlaybackProgress(playerProgressVlaue); + PlayersModel::GetInstance()->SetCircleProgress(playerProgressValue_); + PlayersPresenter::GetInstance()->SetPlaybackProgress(playerProgressValue_); } } void MainPresenterSample::SetCompassRotate() { - if (CompassCalibrationView::GetInstance() == nullptr) - { - return; - } - if (CompassView::GetInstance() == nullptr) - { - return; - } - - uint8_t status = CompassModel::GetInstance()->GetCalibrationStatus(); - if (status == 1) + bool status = CompassModel::GetInstance()->GetCalibrationStatus(); + dynamic_cast(view_->GetViewById(COMPASS))->SetCalibrationView(status); + if (!status) { - CompassCalibrationView::GetInstance()->SetVisible(true); - CompassView::GetInstance()->SetVisible(false); - } - else - { - CompassCalibrationView::GetInstance()->SetVisible(false); - CompassView::GetInstance()->SetVisible(true); DetermineToRotate(); } } - void MainPresenterSample::Notify(void) - { - if (view_->GetHorCurrentPage() == COMPASS) - { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "COMPASS"); - SetCompassRotate(); - } - else if (view_->GetHorCurrentPage() == MUSIC_PLAYER) - { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MUSIC_PLAYER"); - SetCircleProgress(); - } - else if (view_->GetHorCurrentPage() == WATCH_FACE) - { -#if USE_OFFLINE_DIAL +void MainPresenterSample::Notify(void) +{ + CardId cardId = view_->GetHorCurrentCard(); + if (cardId == COMPASS) { + SetCompassRotate(); + } else if (cardId == MUSIC_PLAYER) { + SetCircleProgress(); + } else if (cardId == WATCH_FACE) { + DialSetting &setting = GetDialSetting(); + if (setting.dialFlag) { DialModelTime::GetInstance()->UpdateTime(); - dynamic_cast(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData(); -#else - dynamic_cast(view_->GetViewById(WATCH_FACE))->UpdateTime(); -#endif - } - else if (view_->GetHorCurrentPage() == BLOODOXGEN) - { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodCardView"); + dynamic_cast(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData(); + } else { + dynamic_cast(view_->GetViewById(WATCH_FACE))->UpdateTime(); } } +} + + void MainPresenterSample::InitCardSettings(void) + { + MainModel::GetInstance().InitCardSettings(); + } + + uint8_t MainPresenterSample::GetCardSettingCount(void) + { + return MainModel::GetInstance().GetCardSettingCount(); + } + + CardId *MainPresenterSample::GetCardSettings(void) + { + return MainModel::GetInstance().GetCardSettings(); + } + + void MainPresenterSample::InitDialSettings(void) + { + return MainModel::GetInstance().InitDialSettings(); + } + DialSetting &MainPresenterSample::GetDialSetting() + { + return MainModel::GetInstance().GetDialSetting(); + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp index 687f8a245..a031c0ac5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp @@ -26,7 +26,7 @@ namespace OHOS UICardPage *(MainViewSample::*func)(void); }; - static const MainViewMapper PageMapper[] = { + static const MainViewMapper CardMapper[] = { {WATCH_FACE, &MainViewSample::InitWatchFacePage}, {HEART_RATE, &MainViewSample::InitHeartRatePage}, {BLOODOXGEN, &MainViewSample::InitBloodOxygenPage}, @@ -35,9 +35,7 @@ namespace OHOS {WEATHER, &MainViewSample::InitWeatherPage}, {MUSIC_PLAYER, &MainViewSample::InitMusicPlayerPage}, {ACTIVITY, &MainViewSample::InitActivityPage}, -#if 0 - {APPLIST,&MainViewSample::InitApplistPage} -#endif + }; MainViewSample::MainViewSample() @@ -145,10 +143,13 @@ namespace OHOS delete mainSwipeGroup; mainSwipeGroup = nullptr; } - - g_pMainView = nullptr; + if (callback != nullptr) + { + delete callback; + callback = nullptr; + g_pMainView = nullptr; + } } - MainViewSample *MainViewSample::GetInstance(void) { return g_pMainView; @@ -178,14 +179,15 @@ namespace OHOS return; } } + HorizontalViewInit(); HorViewLoad(); VerticalViewInit(); VertViewLoad(); mainSwipeGroup->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - mainSwipeGroup->SetAnimatorTime(10); // 50: animator drag time(ms); + mainSwipeGroup->SetAnimatorTime(50); // 50: animator drag time(ms); mainSwipeGroup->SetLoopState(true); - mainSwipeGroup->EnableScreenCap(true); // 屏幕截图展示,取消使用实时绘制 + mainSwipeGroup->EnableScreenCap(true); mainSwipeGroup->RegisterSwipeCallback(callback); SwitchToClockPage(); SetContainerView(mainSwipeGroup); @@ -194,40 +196,56 @@ namespace OHOS bool MainViewSample::HorizontalViewInit(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::HorizontalViewInit"); - UISwipeView::OnSwipeListener *listener = nullptr; - - for (int16_t i = 0; i < MAX_CARD; i++) - { - recordCard[i] = (this->*(PageMapper[i].func))(); - if (recordCard[i] == nullptr) + presenter_->InitDialSettings(); + presenter_->InitCardSettings(); + uint8_t cardSettingNum = presenter_->GetCardSettingCount(); + CardId *cardSettings = presenter_->GetCardSettings(); + uint8_t cardMapNumber = sizeof(CardMapper) / sizeof(CardMapper[0]); + for (int16_t i = 0; i < cardSettingNum; i++) + { + for (uint8_t j = 0; j < cardMapNumber; j++) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainViewSample:: recordCard %d error", i); - return false; + if (cardSettings[i] == CardMapper[j].id) + { + recordCard[j] = (this->*(CardMapper[j].func))(); + if (recordCard[j] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MainViewSample:: recordCard %d error", j); + return false; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "MainViewSample:: recordCard[%d]:%p", j, recordCard[j]); + break; + } } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample:: recordCard[%d]:%p", i, recordCard[i]); } - - listener = static_cast(MainPresenterSample::GetInstance()); - if (listener == nullptr) - { - return false; - } - MainPresenterSample::GetInstance()->setCallback(callback); - mainSwipeGroup->SetOnSwipeListener(listener); + presenter_->setCallback(callback); + mainSwipeGroup->SetOnSwipeListener(presenter_); + mainSwipeGroup->SetOnLongPressListener(presenter_); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitPage over"); return true; } void MainViewSample::HorViewLoad(void) { - for (int16_t i = 0; i < MAX_CARD; i++) + uint8_t cardSettingNum = presenter_->GetCardSettingCount(); + CardId *cardSettings = presenter_->GetCardSettings(); + for (int16_t i = 0; i < cardSettingNum; i++) { - mainSwipeGroup->HorAdd(recordCard[i]); + CardId cardId = cardSettings[i]; + if (recordCard[cardId] != nullptr) + { + mainSwipeGroup->HorAdd(recordCard[cardId]); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample:: HorViewLoad cardid = %d ViewIndex = %d", + cardId, recordCard[cardId]->GetViewIndex()); + } } } void MainViewSample::VerticalViewInit(void) { +#ifdef FD230 dropDownView = new PullUpDownView(); if (dropDownView == nullptr) { @@ -238,7 +256,6 @@ namespace OHOS dropDownView->SetViewId("dropDownView"); dropDownView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); dropDownView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); -#if 1 messageView = new MessageCardView(); if (messageView == nullptr) { @@ -259,43 +276,12 @@ namespace OHOS MessageLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); messageView->Add(MessageLable); /* -------------------------------------------------------------------------- */ - messageView->SetViewId("messageView"); messageView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); messageView->PreLoad(); messageView->SetDraggable(false); messageView->SetIntercept(true); messageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); -#endif -/* -------------------------------------------------------------------------- */ -#if 0 - messageView = new UICardPage(); - if (messageView == nullptr) - { - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageView new fail"); - return; - } - } - messageView->SetPosition(0, 0); - messageView->SetWidth(Screen::GetInstance().GetWidth()); - messageView->SetHeight(Screen::GetInstance().GetHeight()); - messageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - messageView->SetViewId("messageView"); - messageView->SetTouchable(true); - messageView->SetIntercept(true); - MessageLable = new UILabel(); - if (MessageLable == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLable new fail"); - return; - } - MessageLable->SetPosition(MESLABLE_X_TMP, MESLABLE_Y_TMP, MESLABLE_WIDTH_TMP, MESLABLE_HEIGHT_TMP); - MessageLable->SetText("无消息"); - MessageLable->SetAlign(TEXT_ALIGNMENT_CENTER); - MessageLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_SIZE_TMP); - MessageLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - messageView->Add(MessageLable); #endif } @@ -305,23 +291,19 @@ namespace OHOS mainSwipeGroup->VerAdd(messageView, UICrossView::VPage::DOWN_PAGE); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::PullViewLoad::Pull View Load complete"); } - void MainViewSample::OnSetUpView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::OnSetUpView"); View::OnSetUpView(); - // show timerView Draw(); } - void MainViewSample::OnTearDownView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::OnTearDownView"); View::OnTearDownView(); return; } - void MainViewSample::OnStop() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::OnStop"); @@ -333,50 +315,42 @@ namespace OHOS RootView::GetInstance()->RemoveAll(); return; } - + UICardPage *MainViewSample::InitWathOffDial(DialSetting &setting) + { + DialViewGroup *dial = new DialViewGroup(); + dial->SetDial(setting.dialFullName); + return dial; + } + UICardPage *MainViewSample::InitWathDial(DialSetting &setting) + { + switch (setting.dialId) + { + case DIAL_CLOCK: + return new MainClockView(); + default: + return nullptr; + } + } UICardPage *MainViewSample::InitWatchFacePage(void) { -#if USE_OFFLINE_DIAL - mainClockView = new DialViewGroup(); -#if 0 - std::string filePath = dynamic_cast(presenter_)->GetDialPath(); - if (filePath.size() == 0) + DialSetting &setting = presenter_->GetDialSetting(); + if (setting.dialFlag) { - filePath = RES_PATH "/dials/Dynamic_cat.bin"; + mainClockView = InitWathOffDial(setting); + } + else + { + mainClockView = InitWathDial(setting); } -#endif - uint8_t fileid = DialUpdateModel::GetInstance()->GetDialConfigPath(); - std::string filePath = dialInfo_1[fileid].dialPath; - mainClockView->SetDial(filePath); -#else - mainClockView = new MainClockView(); -#endif if (mainClockView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView new fail"); return nullptr; } - - mainClockView->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - mainClockView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - UIView::OnLongPressListener *buttonLongPress = static_cast(MainPresenterSample::GetInstance()); - mainClockView->SetOnLongPressListener(buttonLongPress); - return mainClockView; } - UICardPage *MainViewSample::InitHeartRatePage(void) - { - heartRateView = new HeartRateView(); - if (heartRateView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRateView new fail"); - return nullptr; - } - return heartRateView; - } - // 主界面音乐界面 UICardPage *MainViewSample::InitMusicPlayerPage(void) { @@ -432,21 +406,16 @@ namespace OHOS } return weatherControlView; } - void MainViewSample::SetPage(int16_t page) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetPage is %d", page); - if (mainSwipeGroup != nullptr) - { - mainSwipeGroup->SetHorCurrentPage(page); - // 刷新 - OHOS::UISwipeView swipe; - mainSwipeGroup->OnSwipe(swipe); - } - if (presenter_ != nullptr) + UICardPage *MainViewSample::InitHeartRatePage(void) + { + heartRateView = new HeartRateView(); + if (heartRateView == nullptr) { - presenter_->SetTaskPeroid(page); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRateView new fail"); + return nullptr; } + return heartRateView; } // 运动界面 UICardPage *MainViewSample::InitActivityPage(void) @@ -459,12 +428,27 @@ namespace OHOS } return activityWeekView; } - bool MainViewSample::IsMainClockPage(void) + + void MainViewSample::SetPage(int16_t page) { - // mainSwipeGroup->GetCurrentPageView(1) == dropDownView || mainSwipeGroup->GetCurrentPageView(1) == messageView - if (mainSwipeGroup->GetCurrentPageId(0) == WATCH_FACE && mainSwipeGroup->GetCurrentPageId(1) == 1) + if (mainSwipeGroup != nullptr) { - // 0: horizontal; 1: vertical + mainSwipeGroup->SetHorCurrentPage(page); + } + + if (presenter_ != nullptr) + { + CardId *cardSettings = presenter_->GetCardSettings(); + /* page 与CardId 没有对应关系,需要一次转换 */ + presenter_->SetTaskPeroid(cardSettings[page]); + } + } + + bool MainViewSample::IsMainClockPage(void) + { + if (mainSwipeGroup->GetCurrentPageId(0) == mainClockView->GetViewIndex() && + mainSwipeGroup->GetCurrentPageId(1) == 1) + { // 0: horizontal; 1: vertical return true; } else @@ -472,4 +456,13 @@ namespace OHOS return false; } } + + CardId MainViewSample::GetHorCurrentCard() const + { + CardId *cardSettings = presenter_->GetCardSettings(); + int pageId = mainSwipeGroup->GetCurrentPageId(UISwipeView::HORIZONTAL); // 0: horizontal; 1: vertical + /* pageId 与CardId 没有对应关系,需要一次转换 */ + return cardSettings[pageId]; + } + } diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingPresenter.cpp index c83ba6b3d..88a3091bf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingPresenter.cpp @@ -15,8 +15,16 @@ #include "CallerLogModel.h" #include "bts_avrcp_controller.h" #include "bts_avrcp_target.h" +#include "notification_manager.h" +#include "BluetoothHeadsetEvent.h" +#include "bts_avrcp_controller.h" namespace OHOS { + +#ifdef __cplusplus +extern "C" { +#endif + static VolumeSliderEventListener *g_pVolumeSliderEventListener = nullptr; constexpr int16_t SOUND_CHANGE = 10; @@ -45,51 +53,18 @@ bool VolumeSliderEventListener::OnClick(UIView& view, const ClickEvent& event) WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick OnClick"); if (strcmp(view.GetViewId(), INCREASE_BUTTON) == 0) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetIncreaseButton OnClick"); - ChangeVolume(VOLUMELEVATED); + ChangeVolume(VOLUMEUP); } else if (strcmp(view.GetViewId(), DECREASE_BUTTON) == 0) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetDecreaseButton OnClick"); - ChangeVolume(VOLUMELOWERS); + ChangeVolume(VOLUMEDOWN); } else if (strcmp(view.GetViewId(), VOLUME_PROGRESS) == 0) { - ChangeImage(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetDragButton OnClick"); ChangeVolume(VOLUMEDRAG); } return true; } -void VolumeSliderEventListener::ChangeImage() -{ - ImageInfo *image; - VolumeSettingView *volumeSettingView = VolumeSettingView::GetInstance(); - if (volumeSettingView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChangeImage:volumeSettingView new fail"); - return; - } - UISlider *progress = volumeSettingView->GetProgress(); - if (progress == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChangeImage:progress new fail"); - return; - } - UIButton *decrease = volumeSettingView->GetDecreaseButton(); - if (decrease == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChangeImage:decrease new fail"); - return; - } - - volumeSettingView->sounding = progress->GetValue(); - if (volumeSettingView->sounding == 0) { - image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUTE_BUTTON, PLAYER_IAMGES); - decrease->SetImageSrc(image, image); - // 刷新UI - decrease->Invalidate(); - } else { - image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_DECREASE_BUTTON, PLAYER_IAMGES); - decrease->SetImageSrc(image, image); - // 刷新UI - decrease->Invalidate(); - } -} - -void VolumeSliderEventListener::ChangeVolume(uint8_t status) +void VolumeSliderEventListener::ChangeVolume(VolumeChangeStatus status) { ImageInfo *image; VolumeSettingView *volumeSettingView = VolumeSettingView::GetInstance(); @@ -109,7 +84,7 @@ void VolumeSliderEventListener::ChangeVolume(uint8_t status) } preSound = volumeSettingView->sounding; - if (status == 1) { + if (status == VOLUMEUP) { volumeSettingView->sounding = progress->GetValue() + SOUND_CHANGE; if (volumeSettingView->sounding > VOLUME_MAX) { volumeSettingView->sounding = VOLUME_MAX; @@ -118,39 +93,71 @@ void VolumeSliderEventListener::ChangeVolume(uint8_t status) decrease->SetImageSrc(image, image); // 刷新UI decrease->Invalidate(); - } else if (status == 0) { + progress->SetValue(volumeSettingView->sounding); + } else if (status == VOLUMEDOWN) { volumeSettingView->sounding = progress->GetValue() - SOUND_CHANGE; if (volumeSettingView->sounding < VOLUME_MIN) { volumeSettingView->sounding = VOLUME_MIN; } + if (volumeSettingView->sounding == VOLUME_MIN && + (playerCoefficients == VOLUMEPHONE || playerCoefficients == VOLUMEPHONENOTIFY)) { + // 通话场景音量不能设置为0 + volumeSettingView->sounding = SOUND_CHANGE; + } if ((volumeSettingView->sounding == 0) && (preSound != 0)) { image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUTE_BUTTON, PLAYER_IAMGES); decrease->SetImageSrc(image, image); // 刷新UI decrease->Invalidate(); } + progress->SetValue(volumeSettingView->sounding); + } else if (status == VOLUMEDRAG) { + volumeSettingView->sounding = progress->GetValue(); + if (volumeSettingView->sounding == VOLUME_MIN && + (playerCoefficients == VOLUMEPHONE || playerCoefficients == VOLUMEPHONENOTIFY)) { + // 通话场景音量不能设置为0 + volumeSettingView->sounding = SOUND_CHANGE; + progress->SetValue(volumeSettingView->sounding); + } + if (volumeSettingView->sounding == 0) { + image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUTE_BUTTON, PLAYER_IAMGES); + decrease->SetImageSrc(image, image); + // 刷新UI + decrease->Invalidate(); + } else { + image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_DECREASE_BUTTON, PLAYER_IAMGES); + decrease->SetImageSrc(image, image); + // 刷新UI + decrease->Invalidate(); + } } - progress->SetValue(volumeSettingView->sounding); + if (playerCoefficients == VOLUMEPLAYERS) { BtAndLocalVolumeSet(volumeSettingView->sounding); } - if (playerCoefficients == VOLUMEPHONE) { + if (playerCoefficients == VOLUMEPHONE || playerCoefficients == VOLUMEPHONENOTIFY) { unsigned char volumeValue; volumeValue = (unsigned char) ((double) (volumeSettingView->sounding * CALL_VOLUME_MAX) / (VOLUME_MAX - VOLUME_MIN)); // 音量转换 SetSpeakerVolume(volumeValue); } } +extern BtAvrcpTgInf g_avrcp_srv_inf; void VolumeSliderEventListener::BtAndLocalVolumeSet(int16_t sounding) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtAndLocalVolumeSet %d", sounding); - AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, sounding); // 本地音量设置 + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtAndLocalVolumeSet %d", sounding); + if (g_avrcp_srv_inf.avrcp_srv_conn_stat == PROFILE_STATE_CONNECTED) { + uint8_t volume = sounding * AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100 / 100; // 100:本地音量最大值 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "volume 0x%x", volume); + (void)avrcp_ct_set_absolute_volume(&(g_avrcp_srv_inf.bd_addr), volume); // 手表音量设置同步远端BT音量 + } else { + AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, sounding); // 本地音量设置 + } } void VolumeSliderEventListener::OnRelease(int32_t value) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRelease %d", value); - ChangeImage(); ChangeVolume(VOLUMEDRAG); } @@ -162,7 +169,6 @@ void VolumeSliderEventListener::SetPlayerCoefficients(int16_t value) void VolumeSliderEventListener::OnChange(int32_t value) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnChange %d", value); - ChangeImage(); ChangeVolume(VOLUMEDRAG); } @@ -197,9 +203,16 @@ bool VolumeSliderEventListener::OnDrag(UIView& view, const DragEvent& event) mainCallView->GetCallingGroup()->SetVisible(true); CallerLogModel::GetInstance()->SetVolumeScreenStatus(false); } + if (playerCoefficients == VOLUMEPHONENOTIFY) { + volumeSettingView->SetVisible(false); + NotificationManager::GetInstance()->SetVolumeScreenStatus(false); + } RootView::GetInstance()->Invalidate(); } } return true; } -} \ No newline at end of file +#ifdef __cplusplus +} +#endif +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingView.cpp index 042b9a582..4276373a0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingView.cpp @@ -16,10 +16,10 @@ static constexpr uint16_t BUTTON_Y = 0; static constexpr uint16_t BUTTON_Y2 = 363; static constexpr uint16_t BUTTON_WIDTH = 90; static constexpr uint16_t BUTTON_HEIGHT = 90; -static constexpr uint16_t SLIDER_X = 167; -static constexpr uint16_t SLIDER_Y = 77; -static constexpr uint16_t SLIDER_WIDTH = 130; -static constexpr uint16_t SLIDER_HEIGHT = 310; +static constexpr uint16_t SLIDER_X = 207; +static constexpr uint16_t SLIDER_Y = 90; +static constexpr uint16_t SLIDER_WIDTH = 40; +static constexpr uint16_t SLIDER_HEIGHT = 274; constexpr uint16_t VOLUME_OK = 0; constexpr int16_t VOLUME_ERROR = (-1); @@ -77,23 +77,6 @@ bool VolumeSettingView::SetUpVolume(void) progress->SetViewId(VOLUME_PROGRESS); progress->SetRange(VOLUME_MAX, VOLUME_MIN); - progress->SetStyle(STYLE_BORDER_RADIUS, 100); - progress->SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); - progress->SetForegroundStyle(STYLE_LINE_CAP,CapType::CAP_ROUND); - progress->SetSliderColor(Color::GetColorFromRGBA(0x19, 0x19, 0x19, 0xff), Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); - progress->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff); - - if(VolumeVetor == nullptr) - { - VolumeVetor = new UIImageView(); - if (progress == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VolumeVetor new fail"); - return false; - } - } - VolumeVetor->SetPosition(213, 213,40,40); - VolumeVetor->SetSrc(PNG_VOLUME_CONTROL_VECTOR); - if (listener == nullptr) { listener = new VolumeSliderEventListener(); if (listener == nullptr) { @@ -111,7 +94,6 @@ bool VolumeSettingView::SetUpVolume(void) SetDraggable(true); SetTouchable(true); Add(progress); - Add(VolumeVetor); ShowVolume(); return true; @@ -148,7 +130,6 @@ int VolumeSettingView::ShowVolume(void) image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_INCREASE_BUTTON, PLAYER_IAMGES); increaseButton->SetImageSrc(image, image); increaseButton->SetOnClickListener(clickListener); - increaseButton->SetVisible(false); Add(increaseButton); if (decreaseButton == nullptr) { @@ -163,7 +144,6 @@ int VolumeSettingView::ShowVolume(void) image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_DECREASE_BUTTON, PLAYER_IAMGES); decreaseButton->SetImageSrc(image, image); decreaseButton->SetOnClickListener(clickListener); - decreaseButton->SetVisible(false); Add(decreaseButton); return VOLUME_OK; diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinParser.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinParser.cpp index a027a9818..6e54b0a92 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinParser.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinParser.cpp @@ -29,7 +29,7 @@ #include "DialBoxProgressView.h" #include "DialArcProgressView.h" #include "DialArcLabelView.h" -#include "wearable_log.h" +#include "DialKaleidoscopeView.h" namespace OHOS { DialBinParser::DialBinParser() @@ -45,6 +45,7 @@ DialBinParser::DialBinParser() funcArray_[8] = &DialBinParser::ParserDialArcProgress; // 8: index funcArray_[9] = &DialBinParser::ParserDialVideo; // 9: index funcArray_[10] = &DialBinParser::ParserDialClick; // 10: index + funcArray_[11] = &DialBinParser::ParserDialKaleidoscope; // 11: index } DialBinParser::~DialBinParser() @@ -77,6 +78,39 @@ DialBinParser* DialBinParser::GetInstance(void) return &instance; } +bool DialBinParser::GetDialPreviewInfo(FILE* fp, DialPreviewInfo* info) +{ + if (fp == nullptr || info == nullptr) { + GRAPHIC_LOGE("Get dial preview fail, param error!\n"); + return false; + } + + DialHeader* dialHeader = static_cast(MallocAndReadBuf(fp, sizeof(DialHeader))); + if (dialHeader == nullptr) { + GRAPHIC_LOGE("[%s: %d]malloc or read fail!\n", __FUNCTION__, __LINE__); + return false; + } + + if (memcpy_s(info->dialName, DIAL_NAME_MAX_LEN, dialHeader->dialName, DIAL_NAME_MAX_LEN) != EOK) { + GRAPHIC_LOGE("[%s: %d]memcpy_s dial name fail!\n", __FUNCTION__, __LINE__); + free(dialHeader); + return false; + } + + if (memcpy_s(info->description, DIAL_DESCRIPTION_MAX_LEN, + dialHeader->description, DIAL_DESCRIPTION_MAX_LEN) != EOK) { + GRAPHIC_LOGE("[%s: %d]memcpy_s dial description fail!\n", __FUNCTION__, __LINE__); + free(dialHeader); + return false; + } + + info->imgId = dialHeader->previewImgId | dirId_; + info->offset = dialHeader->imageOffset; + + free(dialHeader); + return true; +} + bool DialBinParser::UpdateDial(const std::string& file, FILE* fp, DialViewGroup* group) { if (fp == nullptr) { @@ -115,6 +149,7 @@ int32_t DialBinParser::ParseDialHeader(FILE* file) dialGroup_->SetHeight(dialHeader->height); dialGroup_->SetPeriod(1000 / dialHeader->freq); // 1000: ms imageOffset_ = dialHeader->imageOffset; + uint8_t* viewType = static_cast(MallocAndReadBuf(file, (sizeof(uint8_t) * dialHeader->dialViewCount))); if (viewType == nullptr) { UIFree(dialHeader); @@ -131,15 +166,7 @@ int32_t DialBinParser::ParseDialHeader(FILE* file) } } } - /* -------------------------------------------------------------------------- */ - #if 1 - uint32_t resId = dialHeader->previewImgId | dirId_; - uint32_t curReadPt = ftell(file); - ImageInfo* info = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file_, file, false, imageOffset_); - fseek(file, curReadPt, SEEK_SET); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "previewImgId %p %s", resId,info); - #endif - /* -------------------------------------------------------------------------- */ + UIFree(viewType); UIFree(dialHeader); return 0; @@ -170,7 +197,6 @@ int32_t DialBinParser::ParserDialStaticImg(FILE* fp) return -1; } fseek(fp, curReadPt, SEEK_SET); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ParserDialStaticImg %s %p", info,resId); view->SetSrc(info); dialGroup_->AddView(view); @@ -349,8 +375,8 @@ int32_t DialBinParser::ParserDialDigitalImg(FILE* fp) fseek(fp, curReadPt, SEEK_SET); } - ImageInfo* numInfoArray[DIGITALIMG_IMG_MAX_NUM] = {}; - for (uint16_t i = 0; i < DIGITALIMG_IMG_MAX_NUM; i++) { + ImageInfo* numInfoArray[DIAL_DIGITALIMG_IMG_MAX_NUM] = {}; + for (uint16_t i = 0; i < DIAL_DIGITALIMG_IMG_MAX_NUM; i++) { resId = data->imgIds[i] | dirId_; curReadPt = ftell(fp); numInfoArray[i] = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, @@ -364,7 +390,7 @@ int32_t DialBinParser::ParserDialDigitalImg(FILE* fp) fseek(fp, curReadPt, SEEK_SET); } view->SetParent(dialGroup_); - view->SetNumRes(const_cast(numInfoArray), DIGITALIMG_IMG_MAX_NUM); + view->SetNumRes(const_cast(numInfoArray), DIAL_DIGITALIMG_IMG_MAX_NUM); dialGroup_->AddView(static_cast(data->bindData), view, data->isPeriod); UIFree(data); @@ -453,7 +479,11 @@ bool DialBinParser::SetProgressType(FILE* fp, UIAbstractProgress* view, DialProg fseek(fp, curReadPt, SEEK_SET); view->SetImage(foregroundInfo, nullptr); } else if (data.type == 1) { - view->SetForegroundStyle(STYLE_BACKGROUND_COLOR, data.color.full); + if (view->GetViewType() == UI_BOX_PROGRESS) { + view->SetForegroundStyle(STYLE_BACKGROUND_COLOR, data.color.full); + } else if (view->GetViewType() == UI_CIRCLE_PROGRESS) { + view->SetForegroundStyle(STYLE_LINE_COLOR, data.color.full); + } } else if (data.type == 2) { // 2: gradient ColorStop* stopArray = static_cast(MallocAndReadBuf(fp, (sizeof(ColorStop) * data.stopCount))); if (stopArray == nullptr) { @@ -576,4 +606,40 @@ int32_t DialBinParser::ParserDialClick(FILE* fp) return 0; } -} \ No newline at end of file + +int32_t DialBinParser::ParserDialKaleidoscope(FILE* fp) +{ + if (fp == nullptr) { + GRAPHIC_LOGE("Parser dial option image fail, file is nullptr!\n"); + return -1; + } + + DialKaleidoscope* data = static_cast(MallocAndReadBuf(fp, sizeof(DialKaleidoscope))); + if (data == nullptr) { + GRAPHIC_LOGE("[%s: %d]malloc or read fail!\n", __FUNCTION__, __LINE__); + return -1; + } + + DialKaleidoscopeView* view = new DialKaleidoscopeView(); + uint32_t resId = data->imgId | dirId_; + uint32_t curReadPt = ftell(fp); + ImageInfo* imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, + file_, fp, false, imageOffset_); + if (imgInfo == nullptr) { + GRAPHIC_LOGE("[%s: %d]load img fail! file: %s resId: %x\n", + __FUNCTION__, __LINE__, file_.c_str(), resId); + return false; + } + fseek(fp, curReadPt, SEEK_SET); + + view->SetSrc(imgInfo); + view->RequestFocus(); + view->SetRotateEventFactor(data->crownRotateStep); // 0.2: rotate event factor + view->SetRotateAnimatorValue(data->animatorRotateStep); // 0.1: rotate animator value + view->StartRotateAnimator(); + dialGroup_->AddView(view); + + UIFree(data); + return 0; +} +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/screensetting/include/ScreenModels.h b/code/sdk/application/wearable/fd230app/nativeui/screensetting/include/ScreenModels.h index a37e746a7..ffa8c36d0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/screensetting/include/ScreenModels.h +++ b/code/sdk/application/wearable/fd230app/nativeui/screensetting/include/ScreenModels.h @@ -1,5 +1,3 @@ - - /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: ScreenModels @@ -13,50 +11,17 @@ #include "gfx_utils/list.h" #include "ui_image_view.h" -namespace OHOS -{ - typedef enum - { - WATCH_FACE = 0, - HEART_RATE, - TRAINING, - BLOODOXGEN, - COMPASS, - WEATHER, - MUSIC_PLAYER, - ACTIVITY, - // APPLIST, - MAX_CARD, - } CardId; - - struct CardInfo - { - int16_t cardId; - }; - - class ScreenModels - { - public: - ScreenModels(); - ~ScreenModels(); - static ScreenModels *GetInstance(void); - // card funtion - bool SetUpListCase(void); - bool SaveCardConfig(void); - bool InitCardConfig(void); - void SetCardConfigDefault(void); - int16_t GetCardPage(uint16_t page); - bool CardInsertFirst(int32_t card); - bool CardDelete(int32_t card); - int16_t GetMaxCard(void); - int16_t GetLastCardPage(void); - bool LoadAppImages(std::string file, UIImageView *view, uint32_t resId); - void PreLoadAppimages(void); - - private: - void LoadAppMultiImages(std::string file, uint32_t startId, uint32_t lastId); - List *listMainView{nullptr}; // record main view pages - int16_t maxPage = MAX_CARD; - }; +namespace OHOS { +class ScreenModels { +public: + ScreenModels(); + ~ScreenModels(); + static ScreenModels *GetInstance(void); + bool LoadAppImages(std::string file, UIImageView *view, uint32_t resId); + void PreLoadAppimages(void); + void InitKvStorage(void); +private: + void LoadAppMultiImages(std::string file, uint32_t startId, uint32_t lastId); +}; } #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/screensetting/src/ScreenModels.cpp b/code/sdk/application/wearable/fd230app/nativeui/screensetting/src/ScreenModels.cpp index 8b593c13c..feb639c4b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/screensetting/src/ScreenModels.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/screensetting/src/ScreenModels.cpp @@ -11,189 +11,61 @@ #include "stdio.h" #include #include +#include "kvstore_env.h" +#include "kv_store.h" #include "ScreenModels.h" #include "common/image_cache_manager.h" #include "UiConfig.h" #include "ui_resource_image.h" -namespace OHOS +namespace OHOS { + +ScreenModels::ScreenModels() { +} - ScreenModels::ScreenModels() - { - } +ScreenModels::~ScreenModels() +{ +} - ScreenModels::~ScreenModels() - { - } +ScreenModels *ScreenModels::GetInstance(void) +{ + static ScreenModels screenModel; + return &screenModel; +} - ScreenModels *ScreenModels::GetInstance(void) - { - static ScreenModels screenModel; - return &screenModel; - } +void ScreenModels::InitKvStorage(void) +{ + int ret = UtilsSetEnv("/user"); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "UtilsSetEnv /user ret = %d", ret); +} - bool ScreenModels::SetUpListCase(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpListCase"); - listMainView = new List(); - if (listMainView == nullptr) - { - return false; +void ScreenModels::LoadAppMultiImages(std::string file, uint32_t startId, uint32_t lastId) +{ + for (uint32_t i = startId; i <= lastId; i++) { + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(i, file); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAppMultiImages %x fail", i); + return; } - listMainView->Clear(); - return true; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAppMultiImages %x", i); } +} - bool ScreenModels::InitCardConfig(void) - { - if (SetUpListCase() == false) - { - return false; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardConfig1"); - int32_t fd = open(CARD_CONFIG_PATH, O_RDWR, S_IRWXU); - ListNode *node; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardConfig2"); - struct CardInfo cardInfoData; - if (fd < 0) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardConfig open fail"); - fd = open(CARD_CONFIG_PATH, O_RDWR | O_CREAT, S_IRWXU); - if (fd < 0) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardConfig open fail 2"); - return false; - } - SetCardConfigDefault(); - node = listMainView->Begin(); - for (int32_t i = 0; i < maxPage; i++) - { - cardInfoData = node->data_; - node = node->next_; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Init write cardInfoData.i:%d ", cardInfoData.cardId); - if (write(fd, &cardInfoData, sizeof(CardInfo)) != sizeof(CardInfo)) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Init SaveGlobalHealthToFile fail"); - } - } - close(fd); - return true; - } - else - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardConfig3"); - for (int32_t i = 0; i < maxPage; i++) - { - if (read(fd, &cardInfoData, sizeof(CardInfo)) != sizeof(CardInfo)) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Init Read GlobalHealthToFile fail"); - } - listMainView->PushBack(cardInfoData); - } - close(fd); - return true; - } +bool ScreenModels::LoadAppImages(std::string file, UIImageView *view, uint32_t resId) +{ + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAppImages %x fail", resId); return false; } + view->SetSrc(image); + return true; +} - bool ScreenModels::SaveCardConfig(void) - { - int32_t fd = open(CARD_CONFIG_PATH, O_RDWR | O_CREAT, S_IRWXU); - if (fd < 0) - { - close(fd); - return false; - } - else - { - if (write(fd, &listMainView, listMainView->Size()) != listMainView->Size()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SaveGlobalHealthToFile fail"); - } - close(fd); - return true; - } - } - - void ScreenModels::SetCardConfigDefault(void) - { - int16_t i; - struct CardInfo cardInfoData; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardConfigDefault"); - for (i = 0; i < MAX_CARD; i++) - { - cardInfoData.cardId = i; - listMainView->PushBack(cardInfoData); - } - } - - int16_t ScreenModels::GetCardPage(uint16_t page) - { - ListNode *node = listMainView->Begin(); - for (uint8_t i = 0; i < page; i++) - { - if (node->next_ != NULL) - { - node = node->next_; - } - else - { - return -1; - } - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetCardPage cardId:%d", node->data_.cardId); - return node->data_.cardId; - } - - int16_t ScreenModels::GetLastCardPage(void) - { - ListNode *node = listMainView->Begin(); - for (uint8_t i = 0; i < MAX_CARD; i++) - { - if (node->next_ == NULL) - { - node = node->next_; - } - } - return node->data_.cardId; - } - - int16_t ScreenModels::GetMaxCard(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetMaxCard maxPage:%d", maxPage); - return maxPage; - } - - void ScreenModels::LoadAppMultiImages(std::string file, uint32_t startId, uint32_t lastId) - { - for (uint32_t i = startId; i <= lastId; i++) - { - ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(i, file); - if (image == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAppMultiImages %x fail", i); - return; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAppMultiImages %x", i); - } - } - - bool ScreenModels::LoadAppImages(std::string file, UIImageView *view, uint32_t resId) - { - ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); - if (image == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAppImages %x fail", resId); - return false; - } - view->SetSrc(image); - return true; - } - - void ScreenModels::PreLoadAppimages(void) - { - LoadAppMultiImages(PLAYER_IAMGES, PLAYER_BACKGROUND, PLAYER_PLAYING); +void ScreenModels::PreLoadAppimages(void) +{ + LoadAppMultiImages(PLAYER_IAMGES, PLAYER_BACKGROUND, PLAYER_PLAYING); LoadAppMultiImages(CLOCK_IAMGES, CLOCK_CLOCK0, CLOCK_SECOND); LoadAppMultiImages(COMPASS_IAMGES, COMPASS_COMPASS0, COMPASS_COMPASS2); LoadAppMultiImages(DROPDOWN_IAMGES, DROPDOWN_BLUETOOTHCONNECTED, DROPDOWN_SETTING); @@ -201,5 +73,6 @@ namespace OHOS LoadAppMultiImages(BLOOD_IAMGES, BLOODOXYGEN_BACKGOUND, BLOODOXYGEN_BACKGOUND); LoadAppMultiImages(TRAINING_IAMGES, TRAINING_BOUTTONGROUND, TRAINING_WALKING_BIG); LoadAppMultiImages(MESSAGE_IAMGES, MESSAGE_MESSAGE, MESSAGE_WECHAT); - } + +} } diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardAdapter.h b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardAdapter.h new file mode 100644 index 000000000..417891c87 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardAdapter.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardAdapter.h + * Author: + * Create: 2021-09-18 + */ + +#ifndef SET_CARD_ADAPTER_H +#define SET_CARD_ADAPTER_H + +#include +#include +#include "components/ui_list.h" +#include "components/ui_label.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/abstract_adapter.h" +#include "UiConfig.h" +#include "wearable_log.h" +#include "SetCardItem.h" + +namespace OHOS { +class SetCardAdapter : public AbstractAdapter { +public: + explicit SetCardAdapter(); + virtual ~SetCardAdapter(); + + virtual uint16 GetCount(void) override; + + virtual UIView *GetView(UIView *inView, int16 index) override; + + virtual void AddListItem(const CardInfo &item); + + void ClearItem(void); + +private: + std::list listData_; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardDeleteView.h b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardDeleteView.h new file mode 100644 index 000000000..99b0c8c2a --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardDeleteView.h @@ -0,0 +1,26 @@ +/** + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: + * Author: + * Create: + */ + +#ifndef SET_CARD_DELETE_VIEW_H +#define SET_CARD_DELETE_VIEW_H + +#include "components/ui_label_button.h" +#include "SetCardPresenter.h" + +namespace OHOS { +class SetCardDeleteView : public UIViewGroup { +public: + SetCardDeleteView(SetCardPresenter *presenter); + virtual ~SetCardDeleteView(); + bool InitView(); +private: + SetCardPresenter *presenter_; + UILabelButton confirmBtn; + UILabelButton cancelBtn; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardItem.h b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardItem.h new file mode 100644 index 000000000..646f24fbf --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardItem.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardItem.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_CARD_ITEM_H +#define SET_CARD_ITEM_H + +#include +#include +#include "components/ui_view.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "MainModel.h" +#include "UiConfig.h" + +namespace OHOS { + +class SetCardItem :public UIViewGroup { +public: + SetCardItem(); + virtual ~SetCardItem(); + void SetItemInfo(const CardInfo &cardInfo); +private: + void SetUpChild(); + UIImageView cardImg_; + CardInfo cardInfo_; +}; + +} + +#endif // SET_CARD_ITEM_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardModel.h b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardModel.h new file mode 100644 index 000000000..43ed70b26 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardModel.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardModel.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_CARD_MODEL_H +#define SET_CARD_MODEL_H + +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "SetCardPresenter.h" +#include "SetCardItem.h" + +namespace OHOS { + class SetCardModel { + public: + static SetCardModel &GetInstance(void); + uint8_t *GetCardShowList(void); + uint8_t GetCardShowCount(void) const; + void InitCardShowList(void); + void SetSelectedCardIndex(uint8_t cardIndex); + uint8_t GetSelectedCardIndex(void) const; + void DeleteCardSetting(void); + void SetSelectedCard(uint8_t cardId); + uint8_t GetSelectedCard(void); + private: + SetCardModel(); + SetCardModel(const SetCardModel &); + SetCardModel &operator=(const SetCardModel &); + virtual ~SetCardModel(); + + uint8_t cardShowList[CARD_SETTING_COUNT_MAX] = { 0 }; + uint8_t cardShowCount{0}; + uint8_t selectedCardIndex{0}; + uint8_t selectedCardId{MAX_CARD}; + }; +} + +#endif // SET_CARD_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardNoCardView.h b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardNoCardView.h new file mode 100644 index 000000000..16264fac7 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardNoCardView.h @@ -0,0 +1,27 @@ +/** + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: + * Author: + * Create: + */ + +#ifndef SET_CARD_NO_CARD_VIEW_H +#define SET_CARD_NO_CARD_VIEW_H + +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "SetCardPresenter.h" + +namespace OHOS { +class SetCardNoCardView : public UIViewGroup { +public: + SetCardNoCardView(SetCardPresenter *presenter); + virtual ~SetCardNoCardView(); + bool InitView(); +private: + SetCardPresenter *presenter_; + UILabelButton addBtn; +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardPresenter.h new file mode 100644 index 000000000..5c9b4e016 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardPresenter.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardPresenter.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_CARD_PRESENTER_H +#define SET_CARD_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_list.h" +#include "components/ui_view.h" +#include "KeyInputListener.h" + +namespace OHOS { + +static const char *SET_CARD_ADD = "setcardadd"; +static const char *SET_CARD_DEL = "setcarddel"; +static const char *SET_CARD_DEL_CONFIRM = "setcarddelconfirm"; +static const char *SET_CARD_DEL_CANCEL = "setcarddelcancel"; + +class SetCardView; +class SetCardModel; +class SetCardPresenter : public Presenter, + public UIView::OnClickListener, + public ListScrollListener { +public: + SetCardPresenter(); + virtual ~SetCardPresenter(); + + virtual void OnStart() override; + virtual void OnResume() override; + virtual void OnStop() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + virtual void OnScrollStart(int16_t index, UIView *view) override; + virtual void OnScrollEnd(int16_t index, UIView *view) override; + virtual void OnItemSelected(int16_t index, UIView* view) override; + void InitCardShowList(void); + uint8_t *GetCardShowList(void); + uint8_t GetCardShowCount(void) const; + void SetSelectedCard(uint8_t cardId); + uint8_t GetSelectedCard(void); +private: + KeyInputListener *keyActListenr{nullptr}; + SetCardModel *model{nullptr}; + +}; +} + +#endif // SET_CARD_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardView.h b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardView.h new file mode 100644 index 000000000..9c18e0d09 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/include/SetCardView.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardView.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_CARD_VIEW_H +#define SET_CARD_VIEW_H + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +#include "window/window.h" +#include "BaseView.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "SetCardAdapter.h" +#include "SetCardModel.h" +#include "SetCardDeleteView.h" +#include "SetCardNoCardView.h" + +namespace OHOS { +class SetCardPresenter; + +class SetCardView : public View { +public: + SetCardView(); + virtual ~SetCardView(); + + static SetCardView *GetInstance() + { + static SetCardView instance; + return &instance; + } + + virtual void OnStart() override; + virtual void OnSetUpView() override; + virtual void OnTearDownView() override; + virtual void OnStop() override; + void ShowDeleteView(bool show); + void ShowAddView(bool show); + void RefreshCardList(void); +private: + void SetUpListInfo(void); + void SetUpListView(void); + void SetUpDeleteView(void); + void SetUpAddView(void); + void ShowCardListView(bool show); + UIImageView addImg_; + UIList contentList_; + UIImageView delImg_; + + SetCardDeleteView *deleteView_{nullptr}; + SetCardNoCardView *noCardView_{nullptr}; + SetCardAdapter *setCardAdapter_{nullptr}; + uint32_t scrollIndex_{0}; +}; +} +#endif // SET_CARD_VIEW_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardAdapter.cpp new file mode 100644 index 000000000..4bce9dbb0 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardAdapter.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardAdapter.cpp + * Author: + * Create: 2021-09-18 + */ + +#include "SetCardAdapter.h" + +namespace OHOS { +SetCardAdapter::SetCardAdapter() {} + +SetCardAdapter::~SetCardAdapter() +{ + listData_.clear(); +} + +uint16 SetCardAdapter::GetCount(void) +{ + return listData_.size(); +} + +void SetCardAdapter::ClearItem(void) +{ + listData_.clear(); +} + +UIView *SetCardAdapter::GetView(UIView *inView, int16 index) +{ + if (index >= (int16)listData_.size() || index < 0) { + return nullptr; + } + + std::list::iterator it = listData_.begin(); + for (int i = 0; i < index; i++) { + it++; + } + + SetCardItem *item = nullptr; + if (inView == nullptr) { + item = new SetCardItem(); + if (item == nullptr) { + return nullptr; + } + } else { + item = static_cast(inView); + } + + item->SetItemInfo(*it); + item->SetViewIndex(index); + return item; +} + +void SetCardAdapter::AddListItem(const CardInfo &item) +{ + listData_.push_back(item); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardDeleteView.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardDeleteView.cpp new file mode 100644 index 000000000..d957515c8 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardDeleteView.cpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description. + * Author: + * Create: + */ + +#include "UiConfig.h" +#include +#include "cmsis_os.h" +#include "SetCardDeleteView.h" + +namespace OHOS { + +SetCardDeleteView::SetCardDeleteView(SetCardPresenter *presenter) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardDeleteView::SetCardDeleteView"); + presenter_ = presenter; + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + InitView(); + Add(&confirmBtn); + Add(&cancelBtn); +} + +SetCardDeleteView::~SetCardDeleteView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardDeleteView::~SetCardDeleteView"); + Remove(&confirmBtn); + Remove(&cancelBtn); +} + +bool SetCardDeleteView::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardDeleteView::InitView"); + confirmBtn.SetPosition(184, 118); + confirmBtn.Resize(86, 50); + confirmBtn.SetViewId(SET_CARD_DEL_CONFIRM); + confirmBtn.SetText("删除"); + confirmBtn.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + confirmBtn.SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + confirmBtn.SetOnClickListener(presenter_); + + cancelBtn.SetPosition(186, 231); + cancelBtn.Resize(82, 50); + cancelBtn.SetViewId(SET_CARD_DEL_CANCEL); + cancelBtn.SetText("取消"); + cancelBtn.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + cancelBtn.SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + cancelBtn.SetOnClickListener(presenter_); + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardItem.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardItem.cpp new file mode 100644 index 000000000..61b9c4989 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardItem.cpp @@ -0,0 +1,32 @@ +#include "SetCardItem.h" +#include "SetCardPresenter.h" +#include "wearable_log.h" + +namespace OHOS { + SetCardItem::SetCardItem() + { + SetPosition(0, 0, 454, 280); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + SetUpChild(); + Add(&cardImg_); + } + + SetCardItem::~SetCardItem() + { + Remove(&cardImg_); + } + + void SetCardItem::SetUpChild() + { + cardImg_.SetPosition(87, 0); + cardImg_.Resize(280, 280); + cardImg_.SetResizeMode(UIImageView::FILL); + cardImg_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + } + + void SetCardItem::SetItemInfo(const CardInfo &cardInfo) + { + cardInfo_ = cardInfo; + cardImg_.SetSrc(cardInfo.cardImg); + } +}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardModel.cpp new file mode 100644 index 000000000..32ca2b547 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardModel.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardModel.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "SetCardModel.h" +#include "MainModel.h" +#include "kv_store.h" +#include "securec.h" + +namespace OHOS { + SetCardModel::SetCardModel() {} + + SetCardModel::~SetCardModel() {} + + SetCardModel &SetCardModel::GetInstance() + { + static SetCardModel instance; + return instance; + } + + void SetCardModel::InitCardShowList(void) + { + MainModel::GetInstance().InitCardSettings(); + uint8_t cardCount = MainModel::GetInstance().GetCardSettingCount(); + CardId *cardSettings = MainModel::GetInstance().GetCardSettings(); + cardShowCount = 0; + for (uint8_t i = 0; i < cardCount; i++) { + if (cardSettings[i] == WATCH_FACE) { + continue; + } + cardShowList[cardShowCount++] = cardSettings[i]; + } + } + + uint8_t *SetCardModel::GetCardShowList(void) + { + return cardShowList; + } + + uint8_t SetCardModel::GetCardShowCount(void) const + { + return cardShowCount; + } + + void SetCardModel::SetSelectedCardIndex(uint8_t cardIndex) + { + selectedCardIndex = cardIndex; + } + + uint8_t SetCardModel::GetSelectedCardIndex(void) const + { + return selectedCardIndex; + } + + void SetCardModel::DeleteCardSetting(void) + { + MainModel::GetInstance().DeleteCardSetting(selectedCardIndex); + } + + void SetCardModel::SetSelectedCard(uint8_t cardId) + { + selectedCardId = cardId; + } + + uint8_t SetCardModel::GetSelectedCard(void) + { + return selectedCardId; + } +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardNoCardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardNoCardView.cpp new file mode 100644 index 000000000..15cb462b6 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardNoCardView.cpp @@ -0,0 +1,43 @@ +/** + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description. + * Author: + * Create: + */ + +#include "UiConfig.h" +#include +#include "cmsis_os.h" +#include "SetCardNoCardView.h" + +namespace OHOS { + +SetCardNoCardView::SetCardNoCardView(SetCardPresenter *presenter) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardNoCardView::SetCardNoCardView"); + presenter_ = presenter; + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + InitView(); + Add(&addBtn); +} + +SetCardNoCardView::~SetCardNoCardView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardNoCardView::~SetCardNoCardView"); + Remove(&addBtn); +} + +bool SetCardNoCardView::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardNoCardView::InitView"); + addBtn.SetPosition(184, 118); + addBtn.Resize(86, 50); + addBtn.SetViewId(SET_CARD_ADD); + addBtn.SetText("添加"); + addBtn.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + addBtn.SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + addBtn.SetOnClickListener(presenter_); + return true; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardPresenter.cpp new file mode 100644 index 000000000..f32df85a9 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardPresenter.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardPresenter.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "SetCardView.h" +#include "SetCardModel.h" +#include "SetCardPresenter.h" + +namespace OHOS { + SetCardPresenter::SetCardPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::SetCardPresenter"); + model = &SetCardModel::GetInstance(); + } + + SetCardPresenter::~SetCardPresenter() { + if (keyActListenr != nullptr) { + delete keyActListenr; + keyActListenr = nullptr; + } + } + + void SetCardPresenter::OnStart() + { + Presenter::OnStart(); + if (keyActListenr == nullptr) { + keyActListenr = new KeyInputListener(); + if (keyActListenr != nullptr) { + RootView::GetInstance()->SetOnKeyActListener(keyActListenr); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnStart: new KeyInputListener fail"); + } + } + } + + void SetCardPresenter::OnResume(void) + { + } + + void SetCardPresenter::OnStop(void) + { + RootView::GetInstance()->ClearOnKeyActListener(); + } + + bool SetCardPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::OnClick"); + if (strcmp(view.GetViewId(), SET_CARD_ADD) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::SET_CARD_ADD"); + NativeAbility::GetInstance().ChangeSlice(VIEW_ADD_CARD); + } else if (strcmp(view.GetViewId(), SET_CARD_DEL) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::SET_CARD_DEL"); + view_->ShowDeleteView(true); + } else if (strcmp(view.GetViewId(), SET_CARD_DEL_CONFIRM) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::SET_CARD_DEL_CONFIRM"); + model->DeleteCardSetting(); + view_->ShowDeleteView(false); + view_->RefreshCardList(); + } else if (strcmp(view.GetViewId(), SET_CARD_DEL_CANCEL) == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::SET_CARD_DEL_CANCEL"); + view_->ShowDeleteView(false); + } + return true; + } + + void SetCardPresenter::OnScrollStart(int16_t index, UIView *view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::OnScrollStart index = %d", index); + return; + } + + void SetCardPresenter::OnScrollEnd(int16_t index, UIView *view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::OnScrollEnd index = %d", index); + if (view == nullptr) { + return; + } + model->SetSelectedCardIndex(index); + } + + void SetCardPresenter::OnItemSelected(int16_t index, UIView* view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardPresenter::OnItemSelected index = %d", index); + if (view == nullptr) { + return; + } + } + void SetCardPresenter::InitCardShowList(void) + { + model->InitCardShowList(); + } + + uint8_t *SetCardPresenter::GetCardShowList(void) + { + return model->GetCardShowList(); + } + + uint8_t SetCardPresenter::GetCardShowCount(void) const + { + return model->GetCardShowCount(); + } + + void SetCardPresenter::SetSelectedCard(uint8_t cardId) + { + model->SetSelectedCard(cardId); + } + + uint8_t SetCardPresenter::GetSelectedCard(void) + { + return model->GetSelectedCard(); + } + +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardView.cpp new file mode 100644 index 000000000..f18a1c8e4 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_card/src/SetCardView.cpp @@ -0,0 +1,208 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetCardView.cpp + * Author: + * Create: 2021-11-23 + */ + +#include +#include "SetCardView.h" +#include "SetCardPresenter.h" + +namespace OHOS { +SetCardView::SetCardView():contentList_(UIList::HORIZONTAL) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::SetCardView"); +} + +SetCardView::~SetCardView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::~SetCardView"); + if (deleteView_ != nullptr) { + delete deleteView_; + deleteView_ = nullptr; + } + + if (noCardView_ != nullptr) { + delete noCardView_; + noCardView_ = nullptr; + } + + if (setCardAdapter_ != nullptr) { + delete setCardAdapter_; + setCardAdapter_ = nullptr; + } +} + +void SetCardView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::OnStart"); + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + setCardAdapter_ = new SetCardAdapter(); + SetUpListInfo(); + SetUpListView(); + SetUpDeleteView(); + SetUpAddView(); +} + +void SetCardView::OnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::OnSetUpView"); + View::OnSetUpView(); + ShowDeleteView(false); + if (setCardAdapter_->GetCount() == 0) { + ShowAddView(true); + } +} + +void SetCardView::OnTearDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::OnTearDownView"); + View::OnTearDownView(); +} + +void SetCardView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::OnStop"); + View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } +} + +void SetCardView::SetUpListInfo(void) +{ + presenter_->InitCardShowList(); + uint8_t num = presenter_->GetCardShowCount(); + uint8_t *cardSettings = presenter_->GetCardShowList(); + uint8_t selectCardId = presenter_->GetSelectedCard(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpListInfo::selectCardId = %u", selectCardId); + setCardAdapter_->ClearItem(); + for (uint8_t i = 0; i < num; i++) { + const CardInfo *info = MainModel::GetInstance().GetCardInfo( + static_cast(cardSettings[i])); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpListInfo::%d %s", info->id, info->cardImg); + if (selectCardId == info->id) { + scrollIndex_ = i; + presenter_->SetSelectedCard(MAX_CARD); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpListInfo::scrollIndex_ = %u", scrollIndex_); + } + setCardAdapter_->AddListItem(*info); + } +} + +void SetCardView::SetUpListView(void) +{ + addImg_.SetPosition(187, 10); + addImg_.Resize(80, 80); + addImg_.SetResizeMode(UIImageView::FILL); + addImg_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + addImg_.SetSrc(PNG_SET_CARD_ADD); + addImg_.SetViewId(SET_CARD_ADD); + addImg_.SetVisible(false); + + contentList_.SetPosition(0, 92); + contentList_.Resize(HORIZONTAL_RESOLUTION, 280); + contentList_.SetScrollBlankSize(HORIZONTAL_RESOLUTION / 2); + contentList_.SetSelectPosition(HORIZONTAL_RESOLUTION / 2); + contentList_.SetDraggable(true); + contentList_.SetThrowDrag(true); + contentList_.EnableAutoAlign(true); + contentList_.SetScrollStateListener(presenter_); + contentList_.SetMaxScrollDistance(1000); + contentList_.SetAdapter(setCardAdapter_); + contentList_.SetVisible(false); + contentList_.ScrollTo(scrollIndex_); + + delImg_.SetPosition(187, 374); + delImg_.Resize(80, 80); + delImg_.SetResizeMode(UIImageView::FILL); + delImg_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + delImg_.SetSrc(PNG_SET_CARD_DEL); + delImg_.SetViewId(SET_CARD_DEL); + delImg_.SetVisible(false); + + addImg_.SetTouchable(true); + addImg_.SetOnClickListener(presenter_); + delImg_.SetTouchable(true); + delImg_.SetOnClickListener(presenter_); + + container_->Add(&addImg_); + container_->Add(&contentList_); + container_->Add(&delImg_); +} + +void SetCardView::SetUpDeleteView(void) +{ + deleteView_ = new SetCardDeleteView(presenter_); + if (deleteView_ == nullptr) { + return; + } + deleteView_->SetVisible(false); + container_->Add(deleteView_); +} + +void SetCardView::SetUpAddView(void) +{ + noCardView_ = new SetCardNoCardView(presenter_); + if (noCardView_ == nullptr) { + return; + } + noCardView_->SetVisible(false); + container_->Add(noCardView_); +} + +void SetCardView::ShowCardListView(bool show) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::ShowCardListView %u", show); + if (show) { + addImg_.SetVisible(true); + contentList_.SetVisible(true); + delImg_.SetVisible(true); + } else { + addImg_.SetVisible(false); + contentList_.SetVisible(false); + delImg_.SetVisible(false); + } +} + +void SetCardView::ShowDeleteView(bool show) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::ShowDeleteView %u", show); + if (show) { + ShowCardListView(false); + deleteView_->SetVisible(true); + } else { + ShowCardListView(true); + deleteView_->SetVisible(false); + } +} + +void SetCardView::ShowAddView(bool show) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetCardView::ShowAddView %u", show); + if (show) { + ShowCardListView(false); + noCardView_->SetVisible(true); + } else { + ShowCardListView(true); + noCardView_->SetVisible(false); + } +} + +void SetCardView::RefreshCardList(void) +{ + contentList_.RemoveAll(); + SetUpListInfo(); + contentList_.RefreshList(); + if (setCardAdapter_->GetCount() == 0) { + ShowAddView(true); + } +} + +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_desktop/include/SetDesktopModel.h b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/include/SetDesktopModel.h new file mode 100644 index 000000000..5c5a9261e --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/include/SetDesktopModel.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDesktopModel.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DESKTOP_MODEL_H +#define SET_DESKTOP_MODEL_H + +#include +#include +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "SetDesktopPresenter.h" + +typedef enum { + APPLIST_STYLE, + HEXAGONS_STYLE, +} DesktopStyle; + +namespace OHOS { + class SetDesktopModel { + public: + static SetDesktopModel &GetInstance(void); + DesktopStyle GetDesktopStyle(void); + void SetDesktopStyle(DesktopStyle style); + private: + SetDesktopModel(); + SetDesktopModel(const SetDesktopModel &); + SetDesktopModel &operator=(const SetDesktopModel &); + virtual ~SetDesktopModel(); + + }; +} + +#endif // SET_DESKTOP_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_desktop/include/SetDesktopPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/include/SetDesktopPresenter.h new file mode 100644 index 000000000..1e8d0c19f --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/include/SetDesktopPresenter.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDesktopPresenter.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DESKTOP_PRESENTER_H +#define SET_DESKTOP_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" + +namespace OHOS { +static const char *SET_DESKTOP_LIST = "setdesktopList"; +static const char *SET_DESKTOP_HEXAGONS = "setdesktopHexagons"; + +class SetDesktopView; +class SetDesktopModel; +class SetDesktopPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + SetDesktopPresenter(); + virtual ~SetDesktopPresenter(); + + virtual void OnStart() override; + virtual void OnResume() override; + virtual void OnStop() override; + + bool OnClick(UIView &view, const ClickEvent &event) override; + virtual bool OnDrag(UIView& view, const DragEvent& event) override; + bool GetHexagonsStyleState(void); +private: + +}; +} + +#endif // SET_DESKTOP_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_desktop/include/SetDesktopView.h b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/include/SetDesktopView.h new file mode 100644 index 000000000..4c992747f --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/include/SetDesktopView.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDesktopView.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DESKTOP_VIEW_H +#define SET_DESKTOP_VIEW_H + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +#include "window/window.h" +#include "BaseView.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" + +namespace OHOS { +class SetDesktopPresenter; + +class SetDesktopView : public View { +public: + SetDesktopView(); + virtual ~SetDesktopView(); + + static SetDesktopView *GetInstance() + { + static SetDesktopView instance; + return &instance; + } + + virtual void OnStart() override; + virtual void OnSetUpView() override; + virtual void OnTearDownView() override; + virtual void OnStop() override; + void UpdateSelectedStyle(bool hexagonsSelected); +private: + UILabel titleText; + UIToggleButton hexagonsBtn; + UIToggleButton listBtn; + UIImageView hexagonsImage; + UIImageView listImage; + UILabel listText; + UILabel hexagonsText; +}; +} +#endif // SET_DESKTOP_VIEW_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_desktop/src/SetDesktopModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/src/SetDesktopModel.cpp new file mode 100644 index 000000000..d5f64f315 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/src/SetDesktopModel.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SettingModel.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "SetDesktopModel.h" +#include "kv_store.h" +#include "securec.h" + +namespace OHOS { + static const int STYLE_VALUE_LEN = 32; + SetDesktopModel::SetDesktopModel() {} + + SetDesktopModel::~SetDesktopModel() {} + + SetDesktopModel &SetDesktopModel::GetInstance() + { + static SetDesktopModel instance; + return instance; + } + + DesktopStyle SetDesktopModel::GetDesktopStyle(void) + { + DesktopStyle style; + char temp[STYLE_VALUE_LEN] = { 0 }; + (void)UtilsGetValue("applist_style", temp, STYLE_VALUE_LEN); + if (strcmp(temp, "hexagons") == 0) { + style = HEXAGONS_STYLE; + } else { + style = APPLIST_STYLE; + } + return style; + } + + void SetDesktopModel::SetDesktopStyle(DesktopStyle style) + { + if (style == APPLIST_STYLE) { + (void)UtilsSetValue("applist_style", "list"); + } else if (style == HEXAGONS_STYLE) { + (void)UtilsSetValue("applist_style", "hexagons"); + } + } + +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_desktop/src/SetDesktopPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/src/SetDesktopPresenter.cpp new file mode 100644 index 000000000..0c361bcb1 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/src/SetDesktopPresenter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SettingPresenter.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "SetDesktopView.h" +#include "SetDesktopModel.h" +#include "SetDesktopPresenter.h" + +namespace OHOS { + SetDesktopPresenter::SetDesktopPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopPresenter::SetDesktopPresenter"); + } + + SetDesktopPresenter::~SetDesktopPresenter() {} + + void SetDesktopPresenter::OnStart() + { + Presenter::OnStart(); + } + + void SetDesktopPresenter::OnResume(void) + { + } + + void SetDesktopPresenter::OnStop(void) + { + } + + bool SetDesktopPresenter::OnDrag(UIView& view, const DragEvent& event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopPresenter::OnDrag"); + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnDrag ChangeSlice"); + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + return false; + } + + bool SetDesktopPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopPresenter::OnClick"); + if (strcmp(view.GetViewId(), SET_DESKTOP_HEXAGONS) == 0) { + SetDesktopModel::GetInstance().SetDesktopStyle(HEXAGONS_STYLE); + } else if (strcmp(view.GetViewId(), SET_DESKTOP_LIST) == 0) { + SetDesktopModel::GetInstance().SetDesktopStyle(APPLIST_STYLE); + } + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + return true; + } + bool SetDesktopPresenter::GetHexagonsStyleState(void) + { + return (SetDesktopModel::GetInstance().GetDesktopStyle() == HEXAGONS_STYLE); + } +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_desktop/src/SetDesktopView.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/src/SetDesktopView.cpp new file mode 100644 index 000000000..c5f2b49df --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_desktop/src/SetDesktopView.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDesktopView.cpp + * Author: + * Create: 2021-11-23 + */ + +#include +#include "SetDesktopView.h" +#include "SetDesktopPresenter.h" + +namespace OHOS { +SetDesktopView::SetDesktopView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::SetDesktopView"); +} + +SetDesktopView::~SetDesktopView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::~SetDesktopView"); +} + +void SetDesktopView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::OnStart"); + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetDraggable(true); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetOnDragListener(presenter_); + container_->SetTouchable(true); +} + +void SetDesktopView::OnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::OnSetUpView"); + View::OnSetUpView(); + + titleText.SetPosition(180, 45, 260, 110); + titleText.SetText("桌面"); + titleText.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + titleText.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); + titleText.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + container_->Add(&titleText); + + listImage.SetPosition(25, 135, 190, 190); + listImage.SetSrc(PNG_SET_DESKTOP_BG_IMAGE); + container_->Add(&listImage); + + listBtn.SetPosition(47, 157, 148, 148); + listBtn.SetImages(PNG_SET_DESKTOP_LIST_IMAGE, PNG_SET_DESKTOP_LIST_IMAGE); + listBtn.SetViewId(SET_DESKTOP_LIST); + container_->Add(&listBtn); + + listText.SetPosition(96, 328, 200, 60); + listText.SetText("列表"); + listText.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + listText.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + listText.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + container_->Add(&listText); + + hexagonsImage.SetPosition(247, 135, 190, 190); + hexagonsImage.SetSrc(PNG_SET_DESKTOP_BG_IMAGE); + container_->Add(&hexagonsImage); + + hexagonsBtn.SetPosition(267, 157, 148, 148); + hexagonsBtn.SetImages(PNG_SET_DESKTOP_HEXAGONS_IMAGE, PNG_SET_DESKTOP_HEXAGONS_IMAGE); + hexagonsBtn.SetViewId(SET_DESKTOP_HEXAGONS); + container_->Add(&hexagonsBtn); + + hexagonsText.SetPosition(305, 328, 200, 60); + hexagonsText.SetText("蜂窝"); + hexagonsText.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + hexagonsText.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + hexagonsText.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + container_->Add(&hexagonsText); + + listBtn.SetOnClickListener(presenter_); + hexagonsBtn.SetOnClickListener(presenter_); + UpdateSelectedStyle(presenter_->GetHexagonsStyleState()); +} + +void SetDesktopView::OnTearDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::OnTearDownView"); + View::OnTearDownView(); +} + +void SetDesktopView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDesktopView::OnStop"); + View::OnStop(); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } +} + +void SetDesktopView::UpdateSelectedStyle(bool hexagonsSelected) +{ + listImage.SetVisible(!hexagonsSelected); + hexagonsImage.SetVisible(hexagonsSelected); + hexagonsBtn.SetState(hexagonsSelected); + listBtn.SetState(!hexagonsSelected); +} +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialInfo.h b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialInfo.h new file mode 100644 index 000000000..7ccb7984d --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialInfo.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialInfo.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DIAL_INFO_H +#define SET_DIAL_INFO_H +#include +#include +#include +#include "common/image_cache_manager.h" +namespace OHOS { + typedef struct { + uint8_t dialFlag; /* 1:离线表盘 0:预制表盘 */ + uint8_t id; /* 仅预制表盘使用 */ + std::string dialFullName; /* 仅离线表盘使用 */ + std::string imageFullName; /* 仅预制表盘使用 */ + std::string dialName; + std::string description; /* 仅离线表盘使用 */ + uint8_t freq; + ImageInfo *preImageInfo; + } SetDialInfo; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h new file mode 100644 index 000000000..695c5beea --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialModel.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DIAL_MODEL_H +#define SET_DIAL_MODEL_H +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "SetDialInfo.h" + +namespace OHOS { + class SetDialModel { + public: + static SetDialModel &GetInstance(void); + void LoadAllDial(void); + size_t GetDialCount(void); + std::vector& GetDialInfo(void); + void SaveDialSetting(uint8_t pageIndex); + uint8_t GetPageIndex(void); + private: + void LoadAllDialFromRam(void); + void LoadAllDialFromFs(void); + SetDialModel(); + SetDialModel(const SetDialModel &); + SetDialModel &operator=(const SetDialModel &); + virtual ~SetDialModel(); + int32_t ParseDialHeader(const std::string &dialFileName, SetDialInfo &dialInfo); + std::vector dialInfoList; + uint8_t pageIndex_{0}; + }; +} + +#endif // SET_DIAL_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialPresenter.h new file mode 100644 index 000000000..65b4a746d --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialPresenter.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialPresenter.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DIAL_PRESENTER_H +#define SET_DIAL_PRESENTER_H +#include "SetDialInfo.h" +#include "SetDialModel.h" +#include "Presenter.h" +#include "components/ui_view.h" +#include "KeyInputListener.h" + +namespace OHOS { + +class SetDialView; +class SetDialModel; +class SetDialPresenter : public Presenter, + public UIView::OnClickListener, + public UICoverflowView::OnCoverflowScrollListener { +public: + SetDialPresenter(); + virtual ~SetDialPresenter(); + size_t GetDialCount(void); + std::vector& GetDialInfo(void); + uint8_t GetPageIndex(void); + virtual void OnStart() override; + virtual void OnResume() override; + virtual void OnStop() override; + bool OnScroll() override; + bool OnClick(UIView &view, const ClickEvent &event) override; +private: + KeyInputListener *keyActListenr{nullptr}; + SetDialModel *model{nullptr}; +}; +} + +#endif // SET_DIAL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialView.h b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialView.h new file mode 100644 index 000000000..85ee938c9 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialView.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialView.h + * Author: + * Create: 2021-11-23 + */ + +#ifndef SET_DIAL_VIEW_H +#define SET_DIAL_VIEW_H + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_coverflow_view.h" +#include "window/window.h" +#include "BaseView.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" + +namespace OHOS { +static constexpr uint8_t DIVISOR_TWO = 2; +class SetDialPresenter; + +class SetDialView : public View { +public: + SetDialView(); + virtual ~SetDialView(); + + static SetDialView *GetInstance() + { + static SetDialView instance; + return &instance; + } + + virtual void OnStart() override; + virtual void OnSetUpView() override; + virtual void OnTearDownView() override; + virtual void OnStop() override; + void CoverflowViewScroll(void); + uint8_t GetCoverflowPage(void); +private: + void SetUpCoverflowView(void); + UICoverflowView coverflow_; + UILabel label_; + uint8_t lastIndex_; +}; +} +#endif // SET_DIAL_VIEW_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp new file mode 100644 index 000000000..122c0adb0 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialModel.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "MainModel.h" +#include "SetDialModel.h" +#include "kv_store.h" +#include "securec.h" +#include "dirent.h" +#include "DialBinTypes.h" +#include "wearable_log.h" + +namespace OHOS { + SetDialModel::SetDialModel() {} + + SetDialModel::~SetDialModel() {} + + SetDialModel &SetDialModel::GetInstance() + { + static SetDialModel instance; + return instance; + } + void SetDialModel::LoadAllDial() + { + dialInfoList.clear(); + LoadAllDialFromRam(); + LoadAllDialFromFs(); + } + + void SetDialModel::LoadAllDialFromRam() + { + for (uint8_t i = DIAL_CLOCK; i < DIAL_MAX; i++) { + const DialInfo *info = MainModel::GetInstance().GetDialInfo((DialId)i); + if (info != nullptr) { + SetDialInfo dialInfo; + dialInfo.dialFlag = 0; + dialInfo.id = i; + dialInfo.dialName = info->dialName; + dialInfo.imageFullName = info->dialImg; + dialInfo.freq = info->freq; + ImageInfo* imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(info->dialImg, false); + if (info == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail", + info->dialImg); + continue; + } + dialInfo.preImageInfo = imageInfo; + dialInfoList.push_back(dialInfo); + } + } + } + + void SetDialModel::LoadAllDialFromFs() + { + int ret; + struct dirent *direntp; + + // 打开目录 + DIR *dirp = opendir(APP_DIAL_PATH); + // 遍历文件 + if (dirp != NULL) { + while ((direntp = readdir(dirp)) != NULL) { + SetDialInfo dialInfo; + int ret = ParseDialHeader(direntp->d_name, dialInfo); + if (ret == 0) { + dialInfoList.push_back(dialInfo); + } + } + } + // 关闭目录 + closedir(dirp); + return; + } + + int32_t SetDialModel::ParseDialHeader(const std::string &dialFileName, SetDialInfo &dialInfo) + { + DialHeader dialHeader{0}; + std::string dialFullName = APP_DIAL_PATH; + dialFullName += "/"; + dialFullName += dialFileName; + FILE *fp = fopen(dialFullName.c_str(), "rb"); + if (fp == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader cannot open file: %s", + dialFullName.c_str()); + return -1; + } + if (fread(&dialHeader, 1, sizeof(dialHeader), fp) != sizeof(dialHeader)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader fread %s fail", + dialFullName.c_str()); + return -1; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader dialFullName: %s", + dialFullName.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader dialName: %s", + dialHeader.dialName); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader description: %s", + dialHeader.description); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader freq: %u", + dialHeader.freq); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader previewImgId: %u", + dialHeader.previewImgId); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader imageOffset: %u", + dialHeader.imageOffset); + ImageInfo *info = ImageCacheManager::GetInstance().LoadOneInMultiRes( + dialHeader.previewImgId | (0xfef << 20), dialFullName, fp, false, dialHeader.imageOffset); + if (info == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader loadimage fail"); + return -1; + } + + dialInfo.dialFlag = 1; + dialInfo.id = 0; + dialInfo.dialFullName = dialFullName; + dialInfo.dialName = dialHeader.dialName; + dialInfo.description = dialHeader.description; + dialInfo.freq = dialHeader.freq; + dialInfo.preImageInfo = info; + + fclose(fp); + return 0; + } + + void SetDialModel::SaveDialSetting(uint8_t pageIndex) + { + if (pageIndex >= dialInfoList.size()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialModel SaveDialSetting [%u %u]", + pageIndex, dialInfoList.size()); + return; + } + DialSetting diagSetting; + SetDialInfo &info = dialInfoList[pageIndex]; + diagSetting.dialFlag = info.dialFlag; + diagSetting.dialId = info.id; + diagSetting.dialFullName = info.dialFullName; + MainModel::GetInstance().AddDialSetting(diagSetting); + pageIndex_ = pageIndex; + } + + size_t SetDialModel::GetDialCount(void) + { + return dialInfoList.size(); + } + + std::vector& SetDialModel::GetDialInfo(void) + { + return dialInfoList; + } + + uint8_t SetDialModel::GetPageIndex(void) + { + if (pageIndex_ >= dialInfoList.size()) { + return 0; + } else { + return pageIndex_; + } + } + +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialPresenter.cpp new file mode 100644 index 000000000..2fbaa9943 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialPresenter.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialPresenter.cpp + * Author: + * Create: 2021-11-23 + */ + +#include "SetDialView.h" +#include "SetDialModel.h" +#include "SetDialPresenter.h" + +namespace OHOS { + SetDialPresenter::SetDialPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialPresenter::SetDialPresenter"); + model = &SetDialModel::GetInstance(); + model->LoadAllDial(); + } + + SetDialPresenter::~SetDialPresenter() + { + if (keyActListenr != nullptr) { + delete keyActListenr; + keyActListenr = nullptr; + } + } + + void SetDialPresenter::OnStart() + { + Presenter::OnStart(); + if (keyActListenr == nullptr) { + keyActListenr = new KeyInputListener(); + if (keyActListenr != nullptr) { + RootView::GetInstance()->SetOnKeyActListener(keyActListenr); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnStart: new KeyInputListener fail"); + } + } + } + + void SetDialPresenter::OnResume(void) + { + } + + void SetDialPresenter::OnStop(void) + { + } + + bool SetDialPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialPresenter::OnClick"); + uint8_t pageIndex = view_->GetCoverflowPage(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialPresenter select pageIndex = %u", pageIndex); + model->SaveDialSetting(pageIndex); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + return true; + } + + bool SetDialPresenter::OnScroll() + { + view_->CoverflowViewScroll(); + return true; + } + + size_t SetDialPresenter::GetDialCount(void) + { + return model->GetDialCount(); + } + + std::vector& SetDialPresenter::GetDialInfo(void) + { + return model->GetDialInfo(); + } + + uint8_t SetDialPresenter::GetPageIndex(void) + { + return model->GetPageIndex(); + } +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp new file mode 100644 index 000000000..b683a860f --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: SetDialView.cpp + * Author: + * Create: 2021-11-23 + */ + +#include +#include "SetDialView.h" +#include "SetDialPresenter.h" + +namespace OHOS { +SetDialView::SetDialView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetDialView"); +} + +SetDialView::~SetDialView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::~SetDialView"); +} + +void SetDialView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnStart"); + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + SetUpCoverflowView(); +} + +void SetDialView::SetUpCoverflowView(void) +{ + coverflow_.SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + coverflow_.SetIntercept(true); + coverflow_.SetOnCoverflowListener(presenter_); + coverflow_.SetOnClickListener(presenter_); + std::vector &dialInfo = presenter_->GetDialInfo(); + for (auto iter : dialInfo) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetUpCoverflowView %s", + iter.dialName.c_str()); + coverflow_.Add(iter.dialName.c_str(), iter.preImageInfo); + } + lastIndex_ = presenter_->GetPageIndex(); + coverflow_.SetCurrentPage(lastIndex_); + + label_.SetPosition(127, 50, 200, 50); + label_.SetTextColor(Color::White()); + label_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label_.SetText(dialInfo[lastIndex_].dialName.c_str()); + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + + container_->Add(&coverflow_); + container_->Add(&label_); +} + +void SetDialView::OnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnSetUpView"); + View::OnSetUpView(); +} + +void SetDialView::OnTearDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnTearDownView"); + View::OnTearDownView(); +} + +void SetDialView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnStop"); + View::OnStop(); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } +} + +void SetDialView::CoverflowViewScroll(void) +{ + int16_t contMidX = static_cast(Screen::GetInstance().GetWidth() / DIVISOR_TWO); + int16_t minOffset = contMidX; + uint8_t newCenterIndex = lastIndex_; + for (uint8_t i = 0; i < coverflow_.GetChildrenNumber(); i++) { + Rect rect = coverflow_.GetViewByIndex(i)->GetOrigRect(); + int16_t x = rect.GetLeft(); + int16_t x1 = rect.GetRight(); + int16_t xMid = static_cast(x + (x1 - x + 1) / DIVISOR_TWO); + int16_t distance = MATH_ABS(xMid - contMidX); + if (distance < minOffset) { + newCenterIndex = i; + minOffset = distance; + } + } + if (newCenterIndex != lastIndex_) { + lastIndex_ = newCenterIndex; + std::vector &dialInfo = presenter_->GetDialInfo(); + label_.SetText(dialInfo[lastIndex_].dialName.c_str()); + } + + Rect curViewRect = coverflow_.GetViewByIndex(lastIndex_)->GetOrigRect(); + int16_t centerMid = curViewRect.GetLeft() + curViewRect.GetWidth() / DIVISOR_TWO; + int16_t offset = MATH_ABS(contMidX - centerMid); + if (offset > curViewRect.GetWidth() / DIVISOR_TWO) { + label_.SetStyle(STYLE_TEXT_OPA, 0); + } else { + uint8_t alpha = (uint8_t)((1.0f - ((float)offset / (curViewRect.GetWidth() / DIVISOR_TWO))) * OPA_OPAQUE); + label_.SetStyle(STYLE_TEXT_OPA, alpha); + } +} + +uint8_t SetDialView::GetCoverflowPage(void) +{ + return lastIndex_; +} + +} diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index 15f8c8f22..38ebe73c7 100755 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -57,8 +57,8 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/innerkits - ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/events - ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits +c + ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits/gfx_utils ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits @@ -111,6 +111,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelHeartRate.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelSteps.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelPower.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bloodoxygen/src/BloodOxygenView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bloodoxygen/src/BloodBandoffView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp index b540ca6e3..e6280653b 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp @@ -320,16 +320,6 @@ UICardPage *MainViewSample::InitCompassPage(void) return compassControlView; } -UICardPage *MainViewSample::InitMusicPlayerPage(void) -{ - playersView = new PlayersView(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersView new fail"); - return nullptr; - } - return playersView; -} - void MainViewSample::SetPage(int16_t page) { if (mainSwipeGroup != nullptr) { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/parser/DialBinParser.h b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/parser/DialBinParser.h deleted file mode 100644 index cb81a18bc..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/parser/DialBinParser.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2023 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 GRAPHIC_LITE_DIAL_BIN_PARSER_H -#define GRAPHIC_LITE_DIAL_BIN_PARSER_H -#include -#include -#include "graphic_types.h" -#include "DialViewGroup.h" -#include "DialBinTypes.h" -#include "components/ui_abstract_progress.h" - -namespace OHOS -{ - - class DialBinParser - { - public: - static DialBinParser *GetInstance(void); - bool UpdateDial(const std::string &file, FILE *fp, DialViewGroup *group); - void *MallocAndReadBuf(FILE *file, uint32_t readSize); - - protected: - int32_t ParseDialHeader(FILE *file); - int32_t ParserDialStaticImg(FILE *fp); - int32_t ParserDialSequenceImg(FILE *fp); - int32_t ParserDialRotateImg(FILE *fp); - int32_t ParserDialOptionImg(FILE *fp); - int32_t ParserDialDigitalImg(FILE *fp); - int32_t ParserDialLabel(FILE *fp); - int32_t ParserDialArcLabel(FILE *fp); - int32_t ParserDialBoxProgress(FILE *fp); - int32_t ParserDialArcProgress(FILE *fp); - int32_t ParserDialVideo(FILE *fp); - int32_t ParserDialClick(FILE *fp); - - private: - DialBinParser(); - virtual ~DialBinParser(); - // void* MallocAndReadBuf(FILE* file, uint32_t readSize); - bool SetProgressType(FILE *fp, UIAbstractProgress *view, DialProgressType data); - - static constexpr uint8_t DIAL_BIN_PARSER_FUNC_NUM = 11; - int32_t (DialBinParser::*funcArray_[DIAL_BIN_PARSER_FUNC_NUM])(FILE *); - - DialViewGroup *dialGroup_ = nullptr; - std::string file_; - uint32_t dirId_ = 0xfef << 20; - uint32_t imageOffset_ = 0; - }; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/parser/DialBinTypes.h b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/parser/DialBinTypes.h deleted file mode 100644 index aadaf2181..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/parser/DialBinTypes.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2023 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 GRAPHIC_LITE_DIAL_BIN_TYPE_H -#define GRAPHIC_LITE_DIAL_BIN_TYPE_H -#include "color.h" -#include "graphic_types.h" -#include "components/ui_canvas_ext.h" - -namespace OHOS { -struct DialRect { - int16_t x; - int16_t y; - int16_t w; - int16_t h; -}; - -struct DialHeader { - char dialName[16]; - int16_t width; - int16_t height; - char version[16]; - uint16_t previewImgId; - char description[128]; - uint32_t imageOffset; - uint8_t freq; - uint8_t dialViewCount; -}; - -struct DialStaticImg { - Point pos; - Point center; - float rotate; - uint16_t imgId; -}; - -struct DialSequenceImg { - Point pos; - uint16_t interval; - bool repeat; - uint8_t imgNum; -}; - -struct DialRotateImg { - Point pos; - Point center; - int16_t rotateStart; - int16_t rotateEnd; - uint16_t imgId; - int16_t bindData; - bool isPeriod; -}; - -struct DialOptionImg { - Point pos; - int16_t bindData; - bool isPeriod; - uint8_t count; -}; - -constexpr uint8_t DIGITALIMG_IMG_MAX_NUM = 10; -struct DialDigitalImg { - uint8_t alignType : 4; - uint8_t integerLength : 4; - uint8_t decimalPrecision; - uint16_t imgIds[DIGITALIMG_IMG_MAX_NUM]; - int16_t signImgId; - int16_t decimalPointImgId; - uint16_t space; - Point alignPosition; - int16_t bindData; - bool isPeriod; -}; - -struct DialLabel { - uint8_t breakMode; - uint8_t align; - uint8_t fontSize; - bool isPeriod; - DialRect rect; - uint32_t color; - char fontName[64]; - char text[64]; - int16_t bindData; -}; - -struct DialArcLabel { - uint8_t align; - uint8_t fontSize; - Point center; - int16_t radius; - int16_t rotateStart; - int16_t rotateEnd; - uint32_t color; - char fontName[64]; - char text[64]; - int16_t bindData; - bool isPeriod; -}; - -struct DialProgressType { - uint8_t type; // image | color | gradient_color - DialRect rect; - union { - uint8_t stopCount; - uint16_t imgId; - Color32 color; - }; -}; - -struct DialBoxProgress { - uint8_t cap; - uint8_t direction; - bool isPeriod; - int16_t bindData; - uint32_t bgColor; - DialProgressType typeData; -}; - -struct DialArcProgress { - uint8_t cap; - bool isPeriod; - uint16_t radius; - uint16_t startAngle; - uint16_t endAngle; - uint16_t lineWidth; - int16_t bindData; - uint32_t bgColor; - DialProgressType typeData; -}; - -struct DialVideo { - DialRect rect; - uint32_t offset; - Color32 colorKey; -}; - -struct DialClick { - uint8_t type; - DialRect rect; - union { - uint32_t sliceId; - char bundleName[64]; - }; -}; -} -#endif // GRAPHIC_LITE_DIAL_BIN_TYPE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/include/PhoneService.h b/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/include/PhoneService.h index 36eeaa6e7..8ac11c662 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/include/PhoneService.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/include/PhoneService.h @@ -14,246 +14,253 @@ #include "PhoneAudio.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #define MULTI_CALL_MAX_NUME 5 // 最大多路通话路数 -#define CALL_LOG_MAX_NUM 30 // 最多记录30条通话记录,超出后删除最老的记录 +#define CALL_LOG_MAX_NUM 30 // 最多记录30条通话记录,超出后删除最老的记录 #define NAME_SIZE 20 #define MAX_PHONE_NUM 20 #define CALL_VOLUME_MAX 15 -typedef struct { - int operate; - int lastStatus; - char name[NAME_SIZE]; - unsigned char nameLen; - unsigned char tel[MAX_PHONE_NUM]; - unsigned char telLen; - uint64 activeTime; // 首次电话接通时间点 - uint64 creationTime; // 通话创建时间(不是接通时间) - hfp_hf_calls_info_t unitCalls; -} PhoneCallInfo; - -enum OperateType { - OPERATE_NO_OPE = 0, // 无操作 - OPERATE_DIALING, // 呼出,正在拨号中 - OPERATE_ALERTING, // 呼出,对方响铃 - OPERATE_INCOMING, // 来电呼入 - OPERATE_WAITING, // 来电呼入(等待) - OPERATE_WATCH_ACTIVE, // 对方呼入,手表接听 - OPERATE_PHONE_ACTIVE, // 对方呼入,手机接听 (手表接收到此操作,调用DisconnectSco接口断开SCO连接) - OPERATE_PEER_ACTIVE, // 呼出,对方接听 - OPERATE_PHONE_HOLD, // 手机挂起通话 - OPERATE_WATCH_REJECT, // 手表拒接来电 - OPERATE_WATCH_FINISH, // 手表发起通话结束(挂断通话) - OPERATE_NON_WATCH_FINISH, // 非手表发起通话结束(手机挂断+拒接来电) -}; - -// 通话失败类型 -typedef enum { - ERROR_BT = 0, // 蓝牙 - ERROR_DIAL, // 拨号 -} PhoneServiceErrorType; - -// 通话结束类型 -typedef enum { - CALL_OUTGOING = 0, // 呼出电话 - CALL_INCOMING, // 呼入电话 - CALL_MISSED, // 未接来电 -} CallFinishStatus; - -typedef struct { - char name[NAME_SIZE]; - unsigned char nameLen; - unsigned char tel[MAX_PHONE_NUM]; - unsigned char telLen; - CallFinishStatus status; - uint64 creationTime; // 通话创建时间(不是接通时间) - uint64 callDurTime; // 通话持续时间 -} CallLogInfo; - -// 通话状态改变回调函数 -typedef void (*PhoneServiceCallChangedCb)(const PhoneCallInfo *phoneCall); -// 电话服务失败回调函数 -typedef void (*PhoneServiceErrorCb)(PhoneServiceErrorType type, int volume); -// sco连接回调函数(状态只有断开和连接两种状态) 通话转移会导致sco连接和断连 -typedef void (*PhoneServiceScoStatusCb)(hfp_sco_connect_state_t state); - -typedef struct { - PhoneServiceCallChangedCb callChanged; - PhoneServiceErrorCb phoneServiceErrorCb; - PhoneServiceScoStatusCb scoStatusCb; -} PhoneServiceCb; - -void AddToCallLog(CallLogInfo *info); -/** - * @brief 注册电话服务回调函数 - * - * @param phoneServiceFun 注册函数 - * @return 返回值 成功返回0,失败返回错误码 - */ -int RegisterCallChangedCb(PhoneServiceCb *phoneServiceFun); - -/** - * @brief 电话服务初始化 - */ -void PhoneServiceInit(void); - -/** - * @brief 手表呼出电话 - * - * @param number 呼出号码 - * @param len 号码长度,只包括号码数字部分,不包括结尾'\0' - * @return 返回值 成功返回0,失败返回错误码 - */ -int DialCall(unsigned char *number, unsigned char len); - -/** - * @brief 手表接听呼入来电 - * - * @return 返回值 成功返回0,失败返回错误码 - */ -int AcceptIncomingCall(void); - -/** - * @brief 手表拒接呼入来电 - * - * @return 返回值 成功返回0,失败返回错误码 - */ -int RejectIncomingCall(void); - -/** - * @brief 手表结束通话 - * - * @return 返回值 成功返回0,失败返回错误码 - */ -int FinishCall(void); - -/** - * @brief 获取当前通话的最新变化状态 - * - * @return 返回值 通话变化状态 - */ -int GetCurrCallState(void); - -/** - * @brief 判断此次通话是否是完整通话流程 - * - * @return 返回值 true:是;false:不是 - */ -bool IsCompleteCallFlow(void); - -/** - * @brief 获取当前正在通话路数 - * - * @return 返回值 返回当前正在通话路数 - */ -int GetCurrCallNum(void); - -/** - * @brief 获取当前通话路数和对应的通话信息 - * - * @param callList 用来接收通话信息,需调用者分配空间,大小为MULTI_CALL_MAX_NUME * sizeof(PhoneCallInfo) - * @param listNum callList中PhoneCallInfo个数,大小为MULTI_CALL_MAX_NUME - * @param retNum 接收当前正在进行的通话路数 - * @return 返回值 成功返回0,失败返回错误码 - */ -int GetCallInfoInCallList(PhoneCallInfo callList[], int listNum, int *retNum); - -/** - * @brief 获取当前通话音量大小(0 -15) - * - * @param volume - * - * @return 返回值 当前通话音量大小 - */ -unsigned char GetCallCurrVolume(void); - -/** - * @brief 设置手表通话Speaker音量 - * - * @param volume - * - * @return 返回值 void - */ -void SetSpeakerVolume(unsigned char volume); - -/** - * @brief 设置通话Speaker静音/取消静音 - * - * @param isMute true:设置通话Speaker静音;false:设置通话Speaker取消静音 - * @return 返回值 成功返回ture,失败返回false - */ -bool SetSpeakerMute(bool isMute); - -/** - * @brief 设置通话mic静音/取消静音 - * - * @param isMute true:设置通话mic静音;false:设置通话mic取消静音 - * @return 返回值 成功返回ture,失败返回false - */ -bool SetMicMute(bool isMute); - -/** - * @brief 获取SCO的连接状态 - * - * @return 返回值 返回SCO的连接状态 - */ -int GetScoConnectState(void); - -/** - * @brief 通话转移到手表 - * - * @return 返回值 成功返回0,失败返回错误码 - */ -int TransCallToWatch(void); - -/** - * @brief 通话转移到手机 - * - * @return 返回值 成功返回0,失败返回错误码 - */ -int TransCallToMobilePhone(void); - -/** - * @brief 获取通话记录 - * - * @param info 接收获取的通话记录,由调用者释放free - * @param num 接收通话记录条数 - * @return 返回值 成功返回0,失败返回错误码 - */ -int GetCallLog(CallLogInfo **info, int *num); - -/** - * @brief 删除第一条通话记录 - * - * @return 返回值 成功返回0,失败返回错误码 - */ -int RemoveFirstCallLog(void); - -/** - * @brief 清空通话记录 - * - * @return 返回值 成功返回0,失败返回错误码 - */ -int ClearCallLogFile(void); - -/** - * @brief 获取蓝牙状态 - * - * @return 返回值 蓝牙连接状态 - */ -uint32 GetBtConnectStatus(void); - -/** - * @brief 释放蓝牙通话媒体资源 - * - * @return 返回值 无 - */ -void AudioRelease(void); - -uint32 GetCallCodec(void); + typedef struct + { + int operate; + int lastStatus; + char name[NAME_SIZE]; + unsigned char nameLen; + unsigned char tel[MAX_PHONE_NUM]; + unsigned char telLen; + uint64 activeTime; // 首次电话接通时间点 + uint64 creationTime; // 通话创建时间(不是接通时间) + hfp_hf_calls_info_t unitCalls; + } PhoneCallInfo; + + enum OperateType + { + OPERATE_NO_OPE = 0, // 无操作 + OPERATE_DIALING, // 呼出,正在拨号中 + OPERATE_ALERTING, // 呼出,对方响铃 + OPERATE_INCOMING, // 来电呼入 + OPERATE_WAITING, // 来电呼入(等待) + OPERATE_WATCH_ACTIVE, // 对方呼入,手表接听 + OPERATE_PHONE_ACTIVE, // 对方呼入,手机接听 (手表接收到此操作,调用DisconnectSco接口断开SCO连接) + OPERATE_PEER_ACTIVE, // 呼出,对方接听 + OPERATE_PHONE_HOLD, // 手机挂起通话 + OPERATE_WATCH_REJECT, // 手表拒接来电 + OPERATE_WATCH_FINISH, // 手表发起通话结束(挂断通话) + OPERATE_NON_WATCH_FINISH, // 非手表发起通话结束(手机挂断+拒接来电) + }; + + // 通话失败类型 + typedef enum + { + ERROR_BT = 0, // 蓝牙 + ERROR_DIAL, // 拨号 + } PhoneServiceErrorType; + + // 通话结束类型 + typedef enum + { + CALL_OUTGOING = 0, // 呼出电话 + CALL_INCOMING, // 呼入电话 + CALL_MISSED, // 未接来电 + } CallFinishStatus; + + typedef struct + { + char name[NAME_SIZE]; + unsigned char nameLen; + unsigned char tel[MAX_PHONE_NUM]; + unsigned char telLen; + CallFinishStatus status; + uint64 creationTime; // 通话创建时间(不是接通时间) + uint64 callDurTime; // 通话持续时间 + } CallLogInfo; + + // 通话状态改变回调函数 + typedef void (*PhoneServiceCallChangedCb)(const PhoneCallInfo *phoneCall); + // 电话服务失败回调函数 + typedef void (*PhoneServiceErrorCb)(PhoneServiceErrorType type, int volume); + // sco连接回调函数(状态只有断开和连接两种状态) 通话转移会导致sco连接和断连 + typedef void (*PhoneServiceScoStatusCb)(hfp_sco_connect_state_t state); + + typedef struct + { + PhoneServiceCallChangedCb callChanged; + PhoneServiceErrorCb phoneServiceErrorCb; + PhoneServiceScoStatusCb scoStatusCb; + } PhoneServiceCb; + + void AddToCallLog(CallLogInfo *info); + /** + * @brief 注册电话服务回调函数 + * + * @param phoneServiceFun 注册函数 + * @return 返回值 成功返回0,失败返回错误码 + */ + int RegisterCallChangedCb(PhoneServiceCb *phoneServiceFun); + + /** + * @brief 电话服务初始化 + */ + void PhoneServiceInit(void); + + /** + * @brief 手表呼出电话 + * + * @param number 呼出号码 + * @param len 号码长度,只包括号码数字部分,不包括结尾'\0' + * @return 返回值 成功返回0,失败返回错误码 + */ + int DialCall(unsigned char *number, unsigned char len); + + /** + * @brief 手表接听呼入来电 + * + * @return 返回值 成功返回0,失败返回错误码 + */ + int AcceptIncomingCall(void); + + /** + * @brief 手表拒接呼入来电 + * + * @return 返回值 成功返回0,失败返回错误码 + */ + int RejectIncomingCall(void); + + /** + * @brief 手表结束通话 + * + * @return 返回值 成功返回0,失败返回错误码 + */ + int FinishCall(void); + + /** + * @brief 获取当前通话的最新变化状态 + * + * @return 返回值 通话变化状态 + */ + int GetCurrCallState(void); + + /** + * @brief 判断此次通话是否是完整通话流程 + * + * @return 返回值 true:是;false:不是 + */ + bool IsCompleteCallFlow(void); + + /** + * @brief 获取当前正在通话路数 + * + * @return 返回值 返回当前正在通话路数 + */ + int GetCurrCallNum(void); + + /** + * @brief 获取当前通话路数和对应的通话信息 + * + * @param callList 用来接收通话信息,需调用者分配空间,大小为MULTI_CALL_MAX_NUME * sizeof(PhoneCallInfo) + * @param listNum callList中PhoneCallInfo个数,大小为MULTI_CALL_MAX_NUME + * @param retNum 接收当前正在进行的通话路数 + * @return 返回值 成功返回0,失败返回错误码 + */ + int GetCallInfoInCallList(PhoneCallInfo callList[], int listNum, int *retNum); + + /** + * @brief 获取当前通话音量大小(0 -15) + * + * @param volume + * + * @return 返回值 当前通话音量大小 + */ + unsigned char GetCallCurrVolume(void); + + /** + * @brief 设置手表通话Speaker音量 + * + * @param volume + * + * @return 返回值 void + */ + void SetSpeakerVolume(unsigned char volume); + + /** + * @brief 设置通话Speaker静音/取消静音 + * + * @param isMute true:设置通话Speaker静音;false:设置通话Speaker取消静音 + * @return 返回值 成功返回ture,失败返回false + */ + bool SetSpeakerMute(bool isMute); + + /** + * @brief 设置通话mic静音/取消静音 + * + * @param isMute true:设置通话mic静音;false:设置通话mic取消静音 + * @return 返回值 成功返回ture,失败返回false + */ + bool SetMicMute(bool isMute); + + /** + * @brief 获取SCO的连接状态 + * + * @return 返回值 返回SCO的连接状态 + */ + int GetScoConnectState(void); + + /** + * @brief 通话转移到手表 + * + * @return 返回值 成功返回0,失败返回错误码 + */ + int TransCallToWatch(void); + + /** + * @brief 通话转移到手机 + * + * @return 返回值 成功返回0,失败返回错误码 + */ + int TransCallToMobilePhone(void); + + /** + * @brief 获取通话记录 + * + * @param info 接收获取的通话记录,由调用者释放free + * @param num 接收通话记录条数 + * @return 返回值 成功返回0,失败返回错误码 + */ + int GetCallLog(CallLogInfo **info, int *num); + + /** + * @brief 删除第一条通话记录 + * + * @return 返回值 成功返回0,失败返回错误码 + */ + int RemoveFirstCallLog(void); + + /** + * @brief 清空通话记录 + * + * @return 返回值 成功返回0,失败返回错误码 + */ + int ClearCallLogFile(void); + + /** + * @brief 获取蓝牙状态 + * + * @return 返回值 蓝牙连接状态 + */ + uint32 GetBtConnectStatus(void); + + /** + * @brief 释放蓝牙通话媒体资源 + * + * @return 返回值 无 + */ + void AudioRelease(void); + + uint32 GetCallCodec(void); #ifdef __cplusplus } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp b/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp index a15639445..bd9effd0b 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp @@ -25,7 +25,8 @@ #include "samgr_lite.h" #include "ui_service.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #define CALL_LOG_PATH "/user/data/calllog.bin" @@ -38,561 +39,637 @@ extern "C" { #define INVALID_PHONE_SERVICE_VALUE (-1) -typedef enum { - AUDIO_UNKNOW = 0, - AUDIO_ACT_INTERRUPT_WATCH_RING, // 手表铃声焦点 - AUDIO_ACT_INTERRUPT_BT_SCO, // 蓝牙通话焦点 - AUDIO_CONN_IN_BT_SCO, - AUDIO_CONN_OUT_BT_SCO, - AUDIO_STREAM_INIT, - AUDIO_STREAM_START_SCO, - AUDIO_STREAM_START_DN, - AUDIO_STREAM_START_UP, -} AudioState; - -static PhoneCallInfo g_callList[MULTI_CALL_MAX_NUME]; -static uint32 g_currCallNum = 0; -static uint32 g_finishOperate = OPERATE_NON_WATCH_FINISH; -static uint32 g_scoFlag = HFP_SCO_STATE_DISCONNECTED; // sco连接状态,同时也表示通话在手表还是在手机 -static uint32 g_btConnState = PROFILE_STATE_DISCONNECTED; // 蓝牙连接状态 -static bd_addr_t g_bdAddr; // 设备的蓝牙地址 -static uint32 g_currCallState = HFP_HF_CALL_STATE_FINISHED; -static bool g_completeCallFlag = false; // 完整通话流程:从incoming、dialing或alerting开始才算完整 -static uint32 g_audioState = AUDIO_UNKNOW; -static MutexId g_audioMutex; -static uint32 g_call_codec = mSBC; - -static int g_hdlUpMic = INVALID_PHONE_SERVICE_VALUE; -static int g_hdlUpSco = INVALID_PHONE_SERVICE_VALUE; -static int g_hdlDnSpk = INVALID_PHONE_SERVICE_VALUE; -static int g_hdlDnSco = INVALID_PHONE_SERVICE_VALUE; - -PhoneServiceCb g_callChanged; -void HfpIncomingEventPublish(uint16 topic, hfp_hf_calls_info_t callsInfo); - -static void PhoneServiceScreenCtr(bool turnOnFlag) -{ - if (turnOnFlag) { - int32_t timeout = -1; - SendMsgToUIService(SCREEN_TURN_ON_TO_UI, 0, &timeout, sizeof(int32_t)); - } else { - SendMsgToUIService(SCREEN_TURN_OFF_TO_UI, 0, NULL, 0); + typedef enum + { + AUDIO_UNKNOW = 0, + AUDIO_ACT_INTERRUPT_WATCH_RING, // 手表铃声焦点 + AUDIO_ACT_INTERRUPT_BT_SCO, // 蓝牙通话焦点 + AUDIO_CONN_IN_BT_SCO, + AUDIO_CONN_OUT_BT_SCO, + AUDIO_STREAM_INIT, + AUDIO_STREAM_START_SCO, + AUDIO_STREAM_START_DN, + AUDIO_STREAM_START_UP, + } AudioState; + + static PhoneCallInfo g_callList[MULTI_CALL_MAX_NUME]; + static uint32 g_currCallNum = 0; + static uint32 g_finishOperate = OPERATE_NON_WATCH_FINISH; + static uint32 g_scoFlag = HFP_SCO_STATE_DISCONNECTED; // sco连接状态,同时也表示通话在手表还是在手机 + static uint32 g_btConnState = PROFILE_STATE_DISCONNECTED; // 蓝牙连接状态 + static bd_addr_t g_bdAddr; // 设备的蓝牙地址 + static uint32 g_currCallState = HFP_HF_CALL_STATE_FINISHED; + static bool g_completeCallFlag = false; // 完整通话流程:从incoming、dialing或alerting开始才算完整 + static uint32 g_audioState = AUDIO_UNKNOW; + static MutexId g_audioMutex; + static uint32 g_call_codec = mSBC; + + static int g_hdlUpMic = INVALID_PHONE_SERVICE_VALUE; + static int g_hdlUpSco = INVALID_PHONE_SERVICE_VALUE; + static int g_hdlDnSpk = INVALID_PHONE_SERVICE_VALUE; + static int g_hdlDnSco = INVALID_PHONE_SERVICE_VALUE; + + PhoneServiceCb g_callChanged; + void HfpIncomingEventPublish(uint16 topic, hfp_hf_calls_info_t callsInfo); + + static void PhoneServiceScreenCtr(bool turnOnFlag) + { + if (turnOnFlag) + { + int32_t timeout = -1; + SendMsgToUIService(SCREEN_TURN_ON_TO_UI, 0, &timeout, sizeof(int32_t)); + } + else + { + SendMsgToUIService(SCREEN_TURN_OFF_TO_UI, 0, NULL, 0); + } } -} - -static void InitMutex(void) -{ - g_audioMutex = MUTEX_InitValue(); -} -uint32 GetCallCodec(void) -{ - return g_call_codec; -} - -int RegisterCallChangedCb(PhoneServiceCb *phoneServiceFun) -{ - if (phoneServiceFun == NULL) { - return OHOS_FAILURE; + static void InitMutex(void) + { + g_audioMutex = MUTEX_InitValue(); } - (void)memcpy_s(&g_callChanged, sizeof(g_callChanged), phoneServiceFun, sizeof(g_callChanged)); - - return OHOS_SUCCESS; -} - -static void CallChangedCb(const PhoneCallInfo *phoneCall) -{ - g_callChanged.callChanged(phoneCall); -} - -static void PhoneServiceErrorCallback(PhoneServiceErrorType type, int volume) -{ - g_callChanged.phoneServiceErrorCb(type, volume); -} + uint32 GetCallCodec(void) + { + return g_call_codec; + } -static void ScoStatusCb(hfp_sco_connect_state_t state) -{ - g_callChanged.scoStatusCb(state); -} + int RegisterCallChangedCb(PhoneServiceCb *phoneServiceFun) + { + if (phoneServiceFun == NULL) + { + return OHOS_FAILURE; + } -int GetCurrCallState(void) -{ - return g_currCallState; -} + (void)memcpy_s(&g_callChanged, sizeof(g_callChanged), phoneServiceFun, sizeof(g_callChanged)); -// 初始化媒体 -static void AudioInit(void) -{ - int ret; - ret = PhoneAudioManagerInit(); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioInit] [PhoneAudioManagerInit] failed!"); + return OHOS_SUCCESS; } -} - -// 释放音频焦点 -static void AudioDeactInterrupt(AudioStreamType type) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioDeactInterrupt] start type: 0x%x, g_audioState: 0x%x", - type, g_audioState); - if ((type == AUDIO_STREAM_VOICE_CALL_BT_SCO && g_audioState >= AUDIO_ACT_INTERRUPT_BT_SCO) || - (type == AUDIO_STREAM_RING && g_audioState == AUDIO_ACT_INTERRUPT_WATCH_RING)) { - (void)PhoneAudioManagerDeactInterrupt(); + static void CallChangedCb(const PhoneCallInfo *phoneCall) + { + g_callChanged.callChanged(phoneCall); } -} -// 申请音频焦点 -static void AudioActInterrupt(AudioStreamType type) -{ - int ret = OHOS_SUCCESS; + static void PhoneServiceErrorCallback(PhoneServiceErrorType type, int volume) + { + g_callChanged.phoneServiceErrorCb(type, volume); + } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioActInterrupt] start type: 0x%x, g_audioState: 0x%x", - type, g_audioState); + static void ScoStatusCb(hfp_sco_connect_state_t state) + { + g_callChanged.scoStatusCb(state); + } - if (type != AUDIO_STREAM_VOICE_CALL_BT_SCO && type != AUDIO_STREAM_RING) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioActInterrupt] failed! type: 0x%x, g_audioState: 0x%x", - type, g_audioState); - return; + int GetCurrCallState(void) + { + return g_currCallState; } - MUTEX_Lock(g_audioMutex); - // 申请蓝牙通话焦点 - if (type == AUDIO_STREAM_VOICE_CALL_BT_SCO && g_audioState < AUDIO_ACT_INTERRUPT_BT_SCO) { - if (g_audioState == AUDIO_ACT_INTERRUPT_WATCH_RING) { - AudioDeactInterrupt(AUDIO_STREAM_RING); + // 初始化媒体 + static void AudioInit(void) + { + int ret; + ret = PhoneAudioManagerInit(); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioInit] [PhoneAudioManagerInit] failed!"); } + } - ret = PhoneAudioManagerActInterrupt(type); - if (ret == OHOS_SUCCESS) { - g_audioState = AUDIO_ACT_INTERRUPT_BT_SCO; - } - } else if (type == AUDIO_STREAM_RING && g_audioState < AUDIO_ACT_INTERRUPT_WATCH_RING) { - ret = PhoneAudioManagerActInterrupt(type); - if (ret == OHOS_SUCCESS) { - g_audioState = AUDIO_ACT_INTERRUPT_WATCH_RING; + // 释放音频焦点 + static void AudioDeactInterrupt(AudioStreamType type) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioDeactInterrupt] start type: 0x%x, g_audioState: 0x%x", + type, g_audioState); + + if ((type == AUDIO_STREAM_VOICE_CALL_BT_SCO && g_audioState >= AUDIO_ACT_INTERRUPT_BT_SCO) || + (type == AUDIO_STREAM_RING && g_audioState == AUDIO_ACT_INTERRUPT_WATCH_RING)) + { + (void)PhoneAudioManagerDeactInterrupt(); } } - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioActInterrupt] failed! type: 0x%x, g_audioState: 0x%x", - type, g_audioState); - } + // 申请音频焦点 + static void AudioActInterrupt(AudioStreamType type) + { + int ret = OHOS_SUCCESS; - MUTEX_Unlock(g_audioMutex); -} + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioActInterrupt] start type: 0x%x, g_audioState: 0x%x", + type, g_audioState); -// 媒体连接SCO设备 -static void AudioConnectScoDevInit(void) -{ - int ret; + if (type != AUDIO_STREAM_VOICE_CALL_BT_SCO && type != AUDIO_STREAM_RING) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioActInterrupt] failed! type: 0x%x, g_audioState: 0x%x", + type, g_audioState); + return; + } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioConnectScoDevInit] start g_scoFlag: 0x%x, g_audioState: 0x%x", - g_scoFlag, g_audioState); - if (g_scoFlag != HFP_SCO_STATE_CONNECTED || g_audioState < AUDIO_ACT_INTERRUPT_BT_SCO) { - return; - } + MUTEX_Lock(g_audioMutex); + // 申请蓝牙通话焦点 + if (type == AUDIO_STREAM_VOICE_CALL_BT_SCO && g_audioState < AUDIO_ACT_INTERRUPT_BT_SCO) + { + if (g_audioState == AUDIO_ACT_INTERRUPT_WATCH_RING) + { + AudioDeactInterrupt(AUDIO_STREAM_RING); + } - MUTEX_Lock(g_audioMutex); - if (g_audioState < AUDIO_STREAM_INIT) { - if (g_audioState < AUDIO_CONN_IN_BT_SCO) { - // 配置媒体连接SCO设配状态(下行),只有在SCO连接后才能设置 - ret = PhoneAudioManagerSetDeviceConnState(IN_BLUETOOTH_SCO, AUDIO_DEVICE_CONNECTED); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioConnectScoDevInit] [PhoneAudioManagerSetDeviceConnState] \ - IN_BLUETOOTH_SCO failed! ret = %d", ret); - MUTEX_Unlock(g_audioMutex); - return; - } else { - g_audioState = AUDIO_CONN_IN_BT_SCO; + ret = PhoneAudioManagerActInterrupt(type); + if (ret == OHOS_SUCCESS) + { + g_audioState = AUDIO_ACT_INTERRUPT_BT_SCO; } } - - if (g_audioState < AUDIO_CONN_OUT_BT_SCO) { - // 配置媒体连接SCO设配状态(上行),只有在SCO连接后才能设置 - ret = PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_SCO, AUDIO_DEVICE_CONNECTED); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioConnectScoDevInit] [PhoneAudioManagerSetDeviceConnState] \ - OUT_BLUETOOTH_SCO failed! ret = %d", ret); - MUTEX_Unlock(g_audioMutex); - return; - } else { - g_audioState = AUDIO_CONN_OUT_BT_SCO; + else if (type == AUDIO_STREAM_RING && g_audioState < AUDIO_ACT_INTERRUPT_WATCH_RING) + { + ret = PhoneAudioManagerActInterrupt(type); + if (ret == OHOS_SUCCESS) + { + g_audioState = AUDIO_ACT_INTERRUPT_WATCH_RING; } } - if (g_hdlUpSco == INVALID_PHONE_SERVICE_VALUE) { - g_hdlUpSco = PhoneAudioStreamOutInit(AUDIO_UP_LINK); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioActInterrupt] failed! type: 0x%x, g_audioState: 0x%x", + type, g_audioState); } - if (g_hdlDnSco == INVALID_PHONE_SERVICE_VALUE) { - g_hdlDnSco = PhoneAudioStreamInInit(AUDIO_DOWN_LINK); - } + MUTEX_Unlock(g_audioMutex); + } - if (g_hdlUpSco != INVALID_PHONE_SERVICE_VALUE && g_hdlDnSco != INVALID_PHONE_SERVICE_VALUE) { - g_audioState = AUDIO_STREAM_INIT; + // 媒体连接SCO设备 + static void AudioConnectScoDevInit(void) + { + int ret; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioConnectScoDevInit] start g_scoFlag: 0x%x, g_audioState: 0x%x", + g_scoFlag, g_audioState); + if (g_scoFlag != HFP_SCO_STATE_CONNECTED || g_audioState < AUDIO_ACT_INTERRUPT_BT_SCO) + { + return; } - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioConnectScoDevInit] end g_audioState: %d, g_hdlUpSco: %d, g_hdlDnSco: %d", - g_audioState, g_hdlUpSco, g_hdlDnSco); - MUTEX_Unlock(g_audioMutex); - return; -} + MUTEX_Lock(g_audioMutex); + if (g_audioState < AUDIO_STREAM_INIT) + { + if (g_audioState < AUDIO_CONN_IN_BT_SCO) + { + // 配置媒体连接SCO设配状态(下行),只有在SCO连接后才能设置 + ret = PhoneAudioManagerSetDeviceConnState(IN_BLUETOOTH_SCO, AUDIO_DEVICE_CONNECTED); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioConnectScoDevInit] [PhoneAudioManagerSetDeviceConnState] \ + IN_BLUETOOTH_SCO failed! ret = %d", + ret); + MUTEX_Unlock(g_audioMutex); + return; + } + else + { + g_audioState = AUDIO_CONN_IN_BT_SCO; + } + } -// 建立上行通路 -static void AudioUpStart(void) -{ - int ret = OHOS_SUCCESS; - uint32 micShmId = 0; + if (g_audioState < AUDIO_CONN_OUT_BT_SCO) + { + // 配置媒体连接SCO设配状态(上行),只有在SCO连接后才能设置 + ret = PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_SCO, AUDIO_DEVICE_CONNECTED); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioConnectScoDevInit] [PhoneAudioManagerSetDeviceConnState] \ + OUT_BLUETOOTH_SCO failed! ret = %d", + ret); + MUTEX_Unlock(g_audioMutex); + return; + } + else + { + g_audioState = AUDIO_CONN_OUT_BT_SCO; + } + } + + if (g_hdlUpSco == INVALID_PHONE_SERVICE_VALUE) + { + g_hdlUpSco = PhoneAudioStreamOutInit(AUDIO_UP_LINK); + } + + if (g_hdlDnSco == INVALID_PHONE_SERVICE_VALUE) + { + g_hdlDnSco = PhoneAudioStreamInInit(AUDIO_DOWN_LINK); + } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] start g_scoFlag: %d, g_audioState: %d", g_scoFlag, g_audioState); + if (g_hdlUpSco != INVALID_PHONE_SERVICE_VALUE && g_hdlDnSco != INVALID_PHONE_SERVICE_VALUE) + { + g_audioState = AUDIO_STREAM_INIT; + } + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioConnectScoDevInit] end g_audioState: %d, g_hdlUpSco: %d, g_hdlDnSco: %d", + g_audioState, g_hdlUpSco, g_hdlDnSco); + MUTEX_Unlock(g_audioMutex); - if (g_scoFlag != HFP_SCO_STATE_CONNECTED || g_audioState < AUDIO_STREAM_INIT) { return; } - MUTEX_Lock(g_audioMutex); - if (g_audioState < AUDIO_STREAM_START_UP) { - if (g_hdlUpMic == INVALID_PHONE_SERVICE_VALUE) { - g_hdlUpMic = PhoneAudioStreamInInit(AUDIO_UP_LINK); + // 建立上行通路 + static void AudioUpStart(void) + { + int ret = OHOS_SUCCESS; + uint32 micShmId = 0; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] start g_scoFlag: %d, g_audioState: %d", g_scoFlag, g_audioState); + + if (g_scoFlag != HFP_SCO_STATE_CONNECTED || g_audioState < AUDIO_STREAM_INIT) + { + return; } - if (g_audioState < AUDIO_STREAM_START_SCO) { - ret = PhoneAudioStreamInStart(g_hdlDnSco); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] [AudioStreamInStart] [dn_sco] error! ret: %d", ret); + MUTEX_Lock(g_audioMutex); + if (g_audioState < AUDIO_STREAM_START_UP) + { + if (g_hdlUpMic == INVALID_PHONE_SERVICE_VALUE) + { + g_hdlUpMic = PhoneAudioStreamInInit(AUDIO_UP_LINK); } - ret |= PhoneAudioStreamOutStart(g_hdlUpSco); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] [AudioStreamOutStart] [up_sco] error ret: %d", ret); + if (g_audioState < AUDIO_STREAM_START_SCO) + { + ret = PhoneAudioStreamInStart(g_hdlDnSco); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] [AudioStreamInStart] [dn_sco] error! ret: %d", ret); + } + + ret |= PhoneAudioStreamOutStart(g_hdlUpSco); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] [AudioStreamOutStart] [up_sco] error ret: %d", ret); + } + if (ret == OHOS_SUCCESS) + { + g_audioState = AUDIO_STREAM_START_SCO; + } } - if (ret == OHOS_SUCCESS) { - g_audioState = AUDIO_STREAM_START_SCO; - } - } - ret |= PhoneAudioStreamInStart(g_hdlUpMic); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] [PhoneAudioStreamInStart] [up_mic] error! ret = %d", ret); - } + ret |= PhoneAudioStreamInStart(g_hdlUpMic); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] [PhoneAudioStreamInStart] [up_mic] error! ret = %d", ret); + } - ret |= PhoneAudioStreamInGetChannelId(g_hdlUpMic, &micShmId); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] [AudioStreamInGetChannelId] [up_mic] error ret: %d", ret); - } + ret |= PhoneAudioStreamInGetChannelId(g_hdlUpMic, &micShmId); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] [AudioStreamInGetChannelId] [up_mic] error ret: %d", ret); + } - ret |= PhoneAudioStreamOutAttachFrontend(g_hdlUpSco, micShmId); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] [AudioStreamOutAttachFrontend] [up_sco] error ret:%d", ret); - } + ret |= PhoneAudioStreamOutAttachFrontend(g_hdlUpSco, micShmId); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] [AudioStreamOutAttachFrontend] [up_sco] error ret:%d", ret); + } - if (ret == OHOS_SUCCESS) { - g_audioState = AUDIO_STREAM_START_UP; + if (ret == OHOS_SUCCESS) + { + g_audioState = AUDIO_STREAM_START_UP; + } } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] end g_audioState:%d, g_hdlUpMic:%d, g_hdlUpSco:%d, micShmId:0x%x", + g_audioState, g_hdlUpMic, g_hdlUpSco, micShmId); + MUTEX_Unlock(g_audioMutex); + return; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioUpStart] end g_audioState:%d, g_hdlUpMic:%d, g_hdlUpSco:%d, micShmId:0x%x", - g_audioState, g_hdlUpMic, g_hdlUpSco, micShmId); - MUTEX_Unlock(g_audioMutex); - return; -} - -// 建立下行通路 -static void AudioDnStart(void) -{ - int ret = OHOS_SUCCESS; - uint32 spkShmId = 0; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] start g_scoFlag: %d, g_audioState: %d", g_scoFlag, g_audioState); + // 建立下行通路 + static void AudioDnStart(void) + { + int ret = OHOS_SUCCESS; + uint32 spkShmId = 0; - if (g_scoFlag != HFP_SCO_STATE_CONNECTED || g_audioState < AUDIO_STREAM_INIT) { - return; - } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] start g_scoFlag: %d, g_audioState: %d", g_scoFlag, g_audioState); - MUTEX_Lock(g_audioMutex); - if (g_audioState < AUDIO_STREAM_START_DN) { - if (g_hdlDnSpk == INVALID_PHONE_SERVICE_VALUE) { - g_hdlDnSpk = PhoneAudioStreamOutInit(AUDIO_DOWN_LINK); + if (g_scoFlag != HFP_SCO_STATE_CONNECTED || g_audioState < AUDIO_STREAM_INIT) + { + return; } - if (g_audioState < AUDIO_STREAM_START_SCO) { - ret = PhoneAudioStreamOutStart(g_hdlUpSco); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] [AudioStreamOutStart] [up_sco] error! ret = %d", ret); + MUTEX_Lock(g_audioMutex); + if (g_audioState < AUDIO_STREAM_START_DN) + { + if (g_hdlDnSpk == INVALID_PHONE_SERVICE_VALUE) + { + g_hdlDnSpk = PhoneAudioStreamOutInit(AUDIO_DOWN_LINK); } - ret |= PhoneAudioStreamInStart(g_hdlDnSco); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] [AudioStreamInStart] [dn_sco] error! ret = %d", ret); + if (g_audioState < AUDIO_STREAM_START_SCO) + { + ret = PhoneAudioStreamOutStart(g_hdlUpSco); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] [AudioStreamOutStart] [up_sco] error! ret = %d", ret); + } + + ret |= PhoneAudioStreamInStart(g_hdlDnSco); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] [AudioStreamInStart] [dn_sco] error! ret = %d", ret); + } + + if (ret == OHOS_SUCCESS) + { + g_audioState = AUDIO_STREAM_START_SCO; + } } - if (ret == OHOS_SUCCESS) { - g_audioState = AUDIO_STREAM_START_SCO; + ret |= PhoneAudioStreamOutStart(g_hdlDnSpk); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] [PhoneAudioStreamOutStart] [dn_spk] error! ret = %d", ret); } - } - ret |= PhoneAudioStreamOutStart(g_hdlDnSpk); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] [PhoneAudioStreamOutStart] [dn_spk] error! ret = %d", ret); - } + ret |= PhoneAudioStreamOutGetChannelId(g_hdlDnSpk, &spkShmId); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] [AudioStreamOutGetChannelId] [dn_spk] error ret: %d", ret); + } - ret |= PhoneAudioStreamOutGetChannelId(g_hdlDnSpk, &spkShmId); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] [AudioStreamOutGetChannelId] [dn_spk] error ret: %d", ret); - } + ret |= PhoneAudioStreamInAttachBackend(g_hdlDnSco, spkShmId); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] [AudioStreamInAttachBackend] [dn_sco] error ret: %d", ret); + } - ret |= PhoneAudioStreamInAttachBackend(g_hdlDnSco, spkShmId); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] [AudioStreamInAttachBackend] [dn_sco] error ret: %d", ret); + if (ret == OHOS_SUCCESS) + { + g_audioState = AUDIO_STREAM_START_DN; + } } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] end g_audioState:%d, g_hdlDnSpk:%d, g_hdlDnSco:%d, spkShmId: 0x%x", + g_audioState, g_hdlDnSpk, g_hdlDnSco, spkShmId); + MUTEX_Unlock(g_audioMutex); - if (ret == OHOS_SUCCESS) { - g_audioState = AUDIO_STREAM_START_DN; - } + return; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioDnStart] end g_audioState:%d, g_hdlDnSpk:%d, g_hdlDnSco:%d, spkShmId: 0x%x", - g_audioState, g_hdlDnSpk, g_hdlDnSco, spkShmId); - MUTEX_Unlock(g_audioMutex); - return; -} - -// 同步音量 -static void SyncVolume(void) -{ - unsigned char volume; + // 同步音量 + static void SyncVolume(void) + { + unsigned char volume; - volume = GetCallCurrVolume(); - SetSpeakerVolume(volume); -} + volume = GetCallCurrVolume(); + SetSpeakerVolume(volume); + } #ifdef __cplusplus -extern "C" { + extern "C" + { #endif -static void PostGraphicEvent(void (*fun)(void)) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PostGraphicEvent] start"); - GraphicService::GetInstance()->PostGraphicEvent(*fun); -} + static void PostGraphicEvent(void (*fun)(void)) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PostGraphicEvent] start"); + GraphicService::GetInstance()->PostGraphicEvent(*fun); + } #ifdef __cplusplus -} + } #endif -// 蓝牙通话下行 -static void AudioDn(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioDn] start g_audioState: %d", g_audioState); + // 蓝牙通话下行 + static void AudioDn(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioDn] start g_audioState: %d", g_audioState); - // 申请蓝牙通话音频焦点 - AudioActInterrupt(AUDIO_STREAM_VOICE_CALL_BT_SCO); + // 申请蓝牙通话音频焦点 + AudioActInterrupt(AUDIO_STREAM_VOICE_CALL_BT_SCO); - // 媒体连接SCO设备 - AudioConnectScoDevInit(); + // 媒体连接SCO设备 + AudioConnectScoDevInit(); - // 建立音频下行通路 - AudioDnStart(); - if (g_audioState == AUDIO_STREAM_START_DN) { - // 同步音量 - PostGraphicEvent(SyncVolume); + // 建立音频下行通路 + AudioDnStart(); + if (g_audioState == AUDIO_STREAM_START_DN) + { + // 同步音量 + PostGraphicEvent(SyncVolume); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioDn] end g_audioState: %d", g_audioState); } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioDn] end g_audioState: %d", g_audioState); -} - -// 蓝牙通话上行 -static void AudioUp(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioUp] start g_audioState: %d", g_audioState); - // 申请蓝牙通话音频焦点 - AudioActInterrupt(AUDIO_STREAM_VOICE_CALL_BT_SCO); + // 蓝牙通话上行 + static void AudioUp(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioUp] start g_audioState: %d", g_audioState); - // 媒体连接SCO设备 - AudioConnectScoDevInit(); + // 申请蓝牙通话音频焦点 + AudioActInterrupt(AUDIO_STREAM_VOICE_CALL_BT_SCO); - // 建立音频上行通路 - AudioUpStart(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioUp] end g_audioState: %d", g_audioState); + // 媒体连接SCO设备 + AudioConnectScoDevInit(); -} + // 建立音频上行通路 + AudioUpStart(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioUp] end g_audioState: %d", g_audioState); + } -static void AudioUpRelease(void) -{ - int ret; + static void AudioUpRelease(void) + { + int ret; - if (g_hdlUpSco != INVALID_PHONE_SERVICE_VALUE) { - ret = PhoneAudioStreamOutStop(g_hdlUpSco); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpRelease] [OutStop] g_hdlUpSco error! ret = %d", ret); - } - ret = PhoneAudioStreamOutDeinit(g_hdlUpSco); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpRelease] [OutDeinit] g_hdlUpSco error! ret = %d", ret); + if (g_hdlUpSco != INVALID_PHONE_SERVICE_VALUE) + { + ret = PhoneAudioStreamOutStop(g_hdlUpSco); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpRelease] [OutStop] g_hdlUpSco error! ret = %d", ret); + } + ret = PhoneAudioStreamOutDeinit(g_hdlUpSco); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpRelease] [OutDeinit] g_hdlUpSco error! ret = %d", ret); + } } - } - if (g_hdlUpMic != INVALID_PHONE_SERVICE_VALUE) { - ret = PhoneAudioStreamInStop(g_hdlUpMic); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] [InStop] g_hdlUpMic error! ret = %d", ret); - } - ret = PhoneAudioStreamInDeinit(g_hdlUpMic); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] [InDeinit] g_hdlUpMic error! ret = %d", ret); + if (g_hdlUpMic != INVALID_PHONE_SERVICE_VALUE) + { + ret = PhoneAudioStreamInStop(g_hdlUpMic); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] [InStop] g_hdlUpMic error! ret = %d", ret); + } + ret = PhoneAudioStreamInDeinit(g_hdlUpMic); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] [InDeinit] g_hdlUpMic error! ret = %d", ret); + } } - } - if (g_audioState >= AUDIO_CONN_OUT_BT_SCO) { - ret = PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_SCO, AUDIO_DEVICE_DISCONNECTED); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] OUT_BLUETOOTH_SCO error! ret = %d", ret); + if (g_audioState >= AUDIO_CONN_OUT_BT_SCO) + { + ret = PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_SCO, AUDIO_DEVICE_DISCONNECTED); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] OUT_BLUETOOTH_SCO error! ret = %d", ret); + } } - } - g_hdlUpSco = INVALID_PHONE_SERVICE_VALUE; - g_hdlUpMic = INVALID_PHONE_SERVICE_VALUE; - -} + g_hdlUpSco = INVALID_PHONE_SERVICE_VALUE; + g_hdlUpMic = INVALID_PHONE_SERVICE_VALUE; + } -static void AudioDnRelease(void) -{ - int ret; + static void AudioDnRelease(void) + { + int ret; - if (g_hdlDnSco != INVALID_PHONE_SERVICE_VALUE) { - ret = PhoneAudioStreamInStop(g_hdlDnSco); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpRelease] [InStop] g_hdlDnSco error! ret = %d", ret); - } - ret = PhoneAudioStreamInDeinit(g_hdlDnSco); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpRelease] [InDeinit] g_hdlDnSco error! ret = %d", ret); + if (g_hdlDnSco != INVALID_PHONE_SERVICE_VALUE) + { + ret = PhoneAudioStreamInStop(g_hdlDnSco); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpRelease] [InStop] g_hdlDnSco error! ret = %d", ret); + } + ret = PhoneAudioStreamInDeinit(g_hdlDnSco); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioUpRelease] [InDeinit] g_hdlDnSco error! ret = %d", ret); + } } - } - if (g_hdlDnSpk != INVALID_PHONE_SERVICE_VALUE) { - ret = PhoneAudioStreamOutStop(g_hdlDnSpk); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] [OutStop] g_hdlDnSpk error! ret = %d", ret); + if (g_hdlDnSpk != INVALID_PHONE_SERVICE_VALUE) + { + ret = PhoneAudioStreamOutStop(g_hdlDnSpk); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] [OutStop] g_hdlDnSpk error! ret = %d", ret); + } + ret = PhoneAudioStreamOutDeinit(g_hdlDnSpk); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] [OutDeinit] g_hdlDnSpk error! ret = %d", ret); + } } - ret = PhoneAudioStreamOutDeinit(g_hdlDnSpk); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] [OutDeinit] g_hdlDnSpk error! ret = %d", ret); + + if (g_audioState >= AUDIO_CONN_IN_BT_SCO) + { + ret = PhoneAudioManagerSetDeviceConnState(IN_BLUETOOTH_SCO, AUDIO_DEVICE_DISCONNECTED); + if (ret != OHOS_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] IN_BLUETOOTH_SCO error! ret = %d", ret); + } } + + g_hdlDnSco = INVALID_PHONE_SERVICE_VALUE; + g_hdlDnSpk = INVALID_PHONE_SERVICE_VALUE; } - if (g_audioState >= AUDIO_CONN_IN_BT_SCO) { - ret = PhoneAudioManagerSetDeviceConnState(IN_BLUETOOTH_SCO, AUDIO_DEVICE_DISCONNECTED); - if (ret != OHOS_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AudioDnRelease] IN_BLUETOOTH_SCO error! ret = %d", ret); + /* 销毁上下行通路 释放音频焦点 */ + void AudioRelease(void) + { + if (g_audioState == AUDIO_UNKNOW) + { + return; } - } - g_hdlDnSco = INVALID_PHONE_SERVICE_VALUE; - g_hdlDnSpk = INVALID_PHONE_SERVICE_VALUE; -} + MUTEX_Lock(g_audioMutex); + AudioUpRelease(); + AudioDnRelease(); + /* 释放音频焦点 */ + AudioDeactInterrupt(AUDIO_STREAM_VOICE_CALL_BT_SCO); + AudioDeactInterrupt(AUDIO_STREAM_RING); // 适配某些机型不触发SCO + g_audioState = AUDIO_UNKNOW; -/* 销毁上下行通路 释放音频焦点 */ -void AudioRelease(void) -{ - if (g_audioState == AUDIO_UNKNOW) { - return; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioRelease] end g_audioState: %d,", g_audioState); + MUTEX_Unlock(g_audioMutex); } - MUTEX_Lock(g_audioMutex); - AudioUpRelease(); - AudioDnRelease(); - - /* 释放音频焦点 */ - AudioDeactInterrupt(AUDIO_STREAM_VOICE_CALL_BT_SCO); - AudioDeactInterrupt(AUDIO_STREAM_RING); // 适配某些机型不触发SCO - g_audioState = AUDIO_UNKNOW; - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AudioRelease] end g_audioState: %d,", g_audioState); - MUTEX_Unlock(g_audioMutex); -} - -static void CallListInit(void) -{ - int i; + static void CallListInit(void) + { + int i; - g_currCallNum = 0; + g_currCallNum = 0; - (void)memset_s(g_callList, sizeof(g_callList), 0, sizeof(g_callList)); - for (i = 0; i < MULTI_CALL_MAX_NUME; i++) { - (void)memset_s(g_callList[i].name, NAME_SIZE, '\0', NAME_SIZE); - (void)memset_s(g_callList[i].tel, MAX_PHONE_NUM, '\0', MAX_PHONE_NUM); - g_callList[i].lastStatus = HFP_HF_CALL_STATE_FINISHED; + (void)memset_s(g_callList, sizeof(g_callList), 0, sizeof(g_callList)); + for (i = 0; i < MULTI_CALL_MAX_NUME; i++) + { + (void)memset_s(g_callList[i].name, NAME_SIZE, '\0', NAME_SIZE); + (void)memset_s(g_callList[i].tel, MAX_PHONE_NUM, '\0', MAX_PHONE_NUM); + g_callList[i].lastStatus = HFP_HF_CALL_STATE_FINISHED; + } } -} -static void CopyBdAddr(const bd_addr_t *bdAddr) -{ - unsigned char addr[BD_ADDR_LEN] = {0}; - if (strncmp((const char*)g_bdAddr.addr, (const char*)addr, BD_ADDR_LEN) == 0) { - (void)memcpy_s(g_bdAddr.addr, BD_ADDR_LEN, bdAddr->addr, BD_ADDR_LEN); + static void CopyBdAddr(const bd_addr_t *bdAddr) + { + unsigned char addr[BD_ADDR_LEN] = {0}; + if (strncmp((const char *)g_bdAddr.addr, (const char *)addr, BD_ADDR_LEN) == 0) + { + (void)memcpy_s(g_bdAddr.addr, BD_ADDR_LEN, bdAddr->addr, BD_ADDR_LEN); + } } -} -static void CatBdAddr(const bd_addr_t *bdAddr) -{ + static void CatBdAddr(const bd_addr_t *bdAddr) + { #if WEARABLEOG_DEBUG_ENABLE - for (unsigned char i = 0; i < BD_ADDR_LEN; i++) { - printf("%X", bdAddr->addr[i]); - } - printf(""); + for (unsigned char i = 0; i < BD_ADDR_LEN; i++) + { + printf("%X", bdAddr->addr[i]); + } + printf(""); #else UNUSED(bdAddr); #endif -} + } -static void BtConnectedPro(const bd_addr_t *bdAddr) -{ - g_btConnState = PROFILE_STATE_CONNECTED; - CopyBdAddr(bdAddr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BtConnectedPro] g_bdAddr: "); - CatBdAddr(&g_bdAddr); -} + static void BtConnectedPro(const bd_addr_t *bdAddr) + { + g_btConnState = PROFILE_STATE_CONNECTED; + CopyBdAddr(bdAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BtConnectedPro] g_bdAddr: "); + CatBdAddr(&g_bdAddr); + } -static void BtDisconnectedPro(void) -{ - g_btConnState = PROFILE_STATE_DISCONNECTED; - (void)memset_s(g_bdAddr.addr, BD_ADDR_LEN, 0, BD_ADDR_LEN); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BtDisconnectedPro] g_bdAddr: "); - CatBdAddr(&g_bdAddr); + static void BtDisconnectedPro(void) + { + g_btConnState = PROFILE_STATE_DISCONNECTED; + (void)memset_s(g_bdAddr.addr, BD_ADDR_LEN, 0, BD_ADDR_LEN); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BtDisconnectedPro] g_bdAddr: "); + CatBdAddr(&g_bdAddr); - // 通知APP蓝牙断开连接 - PhoneServiceErrorCallback(ERROR_BT, PROFILE_STATE_DISCONNECTED); - CallListInit(); + // 通知APP蓝牙断开连接 + PhoneServiceErrorCallback(ERROR_BT, PROFILE_STATE_DISCONNECTED); + CallListInit(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtDisconnectedPro callState: %d", g_currCallState); - if (g_currCallState == HFP_HF_CALL_STATE_INCOMING) { - /* 处理呼入阶段,取消手表配对 */ - hfp_hf_calls_info_t call = {0}; - HfpIncomingEventPublish(TOPIC_EVENT_HFP_FINISHED, call); - } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtDisconnectedPro callState: %d", g_currCallState); + if (g_currCallState == HFP_HF_CALL_STATE_INCOMING) + { + /* 处理呼入阶段,取消手表配对 */ + hfp_hf_calls_info_t call = {0}; + HfpIncomingEventPublish(TOPIC_EVENT_HFP_FINISHED, call); + } - g_currCallState = HFP_HF_CALL_STATE_FINISHED; - g_scoFlag = HFP_SCO_STATE_DISCONNECTED; - g_completeCallFlag = false; -} + g_currCallState = HFP_HF_CALL_STATE_FINISHED; + g_scoFlag = HFP_SCO_STATE_DISCONNECTED; + g_completeCallFlag = false; + } -// 蓝牙状态连接 -static void ConnStateChanged(const bd_addr_t *bdAddr, profile_connect_state_t state) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ConnStateChanged] state = 0x%X bdAddr: ", state); - CatBdAddr(bdAddr); + // 蓝牙状态连接 + static void ConnStateChanged(const bd_addr_t *bdAddr, profile_connect_state_t state) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ConnStateChanged] state = 0x%X bdAddr: ", state); + CatBdAddr(bdAddr); - if (state == PROFILE_STATE_CONNECTED) { - SendMsgToUIService(BT_CONNECTED_TO_UI, 0, NULL, 0); - } else if (state == PROFILE_STATE_DISCONNECTED) { - SendMsgToUIService(BT_DISCONNECTED_TO_UI, 0, NULL, 0); - } + if (state == PROFILE_STATE_CONNECTED) + { + SendMsgToUIService(BT_CONNECTED_TO_UI, 0, NULL, 0); + } + else if (state == PROFILE_STATE_DISCONNECTED) + { + SendMsgToUIService(BT_DISCONNECTED_TO_UI, 0, NULL, 0); + } - switch (state) { + switch (state) + { case PROFILE_STATE_CONNECTING: // 蓝牙正在连接 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ConnStateChanged] BT connecting"); break; @@ -609,67 +686,72 @@ static void ConnStateChanged(const bd_addr_t *bdAddr, profile_connect_state_t st break; default: break; + } } -} - -// 获取蓝牙状态 -uint32 GetBtConnectStatus(void) -{ - g_btConnState = (uint32)hfp_hf_get_device_connect_state(&g_bdAddr); - return g_btConnState; -} -// SCO连接处理 -static void ScoConnectPro(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectPro] g_currCallNum = %d, g_scoFlag = %d", g_currCallNum, g_scoFlag); - // 通知sco建立连接(或通话转移:手机 -> 手表) - ScoStatusCb(HFP_SCO_STATE_CONNECTED); - if (g_currCallState == HFP_HF_CALL_STATE_ACTIVE && g_scoFlag == HFP_SCO_STATE_CONNECTED) { - // The call is transferred from the phone to the watch. Need to show the call notification view. - hfp_hf_calls_info_t call = {0}; - HfpIncomingEventPublish(TOPIC_EVENT_HFP_PHONE_TO_WATCH, call); - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectPro] g_audioState: %d ", g_audioState); + // 获取蓝牙状态 + uint32 GetBtConnectStatus(void) + { + g_btConnState = (uint32)hfp_hf_get_device_connect_state(&g_bdAddr); + return g_btConnState; + } + + // SCO连接处理 + static void ScoConnectPro(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectPro] g_currCallNum = %d, g_scoFlag = %d", g_currCallNum, g_scoFlag); + // 通知sco建立连接(或通话转移:手机 -> 手表) + ScoStatusCb(HFP_SCO_STATE_CONNECTED); + if (g_currCallState == HFP_HF_CALL_STATE_ACTIVE && g_scoFlag == HFP_SCO_STATE_CONNECTED) + { + // The call is transferred from the phone to the watch. Need to show the call notification view. + hfp_hf_calls_info_t call = {0}; + HfpIncomingEventPublish(TOPIC_EVENT_HFP_PHONE_TO_WATCH, call); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectPro] g_audioState: %d ", g_audioState); - if (g_audioState < AUDIO_STREAM_START_DN) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectPro] post AudioDn"); - PostGraphicEvent(AudioDn); - } + if (g_audioState < AUDIO_STREAM_START_DN) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectPro] post AudioDn"); + PostGraphicEvent(AudioDn); + } - if (g_audioState != AUDIO_STREAM_START_UP) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectPro] post AudioUp"); - PostGraphicEvent(AudioUp); + if (g_audioState != AUDIO_STREAM_START_UP) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoConnectPro] post AudioUp"); + PostGraphicEvent(AudioUp); + } } -} - -// SCO断连处理 -static void ScoDisconnectPro(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoDisconnectPro] start g_currCallState = %d", g_currCallState); + // SCO断连处理 + static void ScoDisconnectPro(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoDisconnectPro] start g_currCallState = %d", g_currCallState); - ScoStatusCb(HFP_SCO_STATE_DISCONNECTED); - if (g_currCallState == HFP_HF_CALL_STATE_ACTIVE && g_scoFlag == HFP_SCO_STATE_DISCONNECTED) { - // The call is transferred from the watch to the phone. Need to close the call notification view. - hfp_hf_calls_info_t call = {0}; - HfpIncomingEventPublish(TOPIC_EVENT_HFP_WATCH_TO_PHONE, call); + ScoStatusCb(HFP_SCO_STATE_DISCONNECTED); + if (g_currCallState == HFP_HF_CALL_STATE_ACTIVE && g_scoFlag == HFP_SCO_STATE_DISCONNECTED) + { + // The call is transferred from the watch to the phone. Need to close the call notification view. + hfp_hf_calls_info_t call = {0}; + HfpIncomingEventPublish(TOPIC_EVENT_HFP_WATCH_TO_PHONE, call); + } + AudioRelease(); // 为了保持时序,此处采取同步调用 + usleep(5000); // 增加延时确保SCO断开AUDIO通路释放成功 } - AudioRelease(); // 为了保持时序,此处采取同步调用 - usleep(5000); // 增加延时确保SCO断开AUDIO通路释放成功 -} -// Sco连接状态变化回调函数,音频连接状态 -static void ScoStateChanged(const bd_addr_t *bdAddr, hfp_sco_connect_state_t state) -{ - g_scoFlag = state; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoStateChanged] state = %d, g_scoFlag = %d, g_currCallNum = %d", state, - g_scoFlag, g_currCallNum); + // Sco连接状态变化回调函数,音频连接状态 + static void ScoStateChanged(const bd_addr_t *bdAddr, hfp_sco_connect_state_t state) + { + g_scoFlag = state; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoStateChanged] state = %d, g_scoFlag = %d, g_currCallNum = %d", state, + g_scoFlag, g_currCallNum); - switch (state) { + switch (state) + { case HFP_SCO_STATE_CONNECTING: PhoneServiceScreenCtr(1); - if (g_scoFlag != HFP_SCO_STATE_CONNECTED) { + if (g_scoFlag != HFP_SCO_STATE_CONNECTED) + { g_scoFlag = HFP_SCO_STATE_CONNECTED; CopyBdAddr(bdAddr); ScoConnectPro(); @@ -694,722 +776,837 @@ static void ScoStateChanged(const bd_addr_t *bdAddr, hfp_sco_connect_state_t sta default: break; + } } -} - -static void CallLogCreatDir(void) -{ - DIR *dir = NULL; - dir = opendir(CALL_LOG_DIR); - if (dir == NULL) { - mkdir(CALL_LOG_DIR, S_IREAD | S_IWRITE); - } else { - closedir(dir); - } - return; -} - -// 获取通话记录文件长度 -static int GetCallLogFileSize(void) -{ - int len = 0; - FILE *fp = fopen(CALL_LOG_PATH, "rb"); - if (fp == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[GetCallLogFileSize] fopen CALL_LOG_PATH error"); - return OHOS_FAILURE; - } - - fseek(fp, 0, SEEK_END); - len = ftell(fp); - fseek(fp, 0, SEEK_SET); - fclose(fp); - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[GetCallLogFileSize] len = %d", len); - return len; -} - -// 添加通话进通话记录文件 -static void AddToCallLog(CallLogInfo *info) -{ - FILE *fp = NULL; - size_t ret; - fp = fopen(CALL_LOG_PATH, "ab"); - if (fp == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddToCallLog] fopen failed!"); + static void CallLogCreatDir(void) + { + DIR *dir = NULL; + dir = opendir(CALL_LOG_DIR); + if (dir == NULL) + { + mkdir(CALL_LOG_DIR, S_IREAD | S_IWRITE); + } + else + { + closedir(dir); + } return; } - ret = fwrite(info, sizeof(CallLogInfo), 1, fp); - if (ret != 1) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddToCallLog] fwrite failed! ret = %d", ret); - } + // 获取通话记录文件长度 + static int GetCallLogFileSize(void) + { + int len = 0; + FILE *fp = fopen(CALL_LOG_PATH, "rb"); + if (fp == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[GetCallLogFileSize] fopen CALL_LOG_PATH error"); + return OHOS_FAILURE; + } - fclose(fp); - return; -} + fseek(fp, 0, SEEK_END); + len = ftell(fp); + fseek(fp, 0, SEEK_SET); + fclose(fp); -static int CopyPhoneLogToTmpLog(void) -{ - FILE *fp = NULL; - FILE *ftp = NULL; - CallLogInfo *info = NULL; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[GetCallLogFileSize] len = %d", len); + return len; + } - int retLen; - int fileSize = GetCallLogFileSize(); + // 添加通话进通话记录文件 + void AddToCallLog(CallLogInfo *info) + { + FILE *fp = NULL; + size_t ret; - if (fileSize == OHOS_FAILURE || fileSize == 0) { - return fileSize; - } + fp = fopen(CALL_LOG_PATH, "ab"); + if (fp == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddToCallLog] fopen failed!"); + return; + } - retLen = fileSize - sizeof(CallLogInfo); - if (retLen == 0) { - return ClearCallLogFile(); // 只有一条记录,清空通话记录 - } + ret = fwrite(info, sizeof(CallLogInfo), 1, fp); + if (ret != 1) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddToCallLog] fwrite failed! ret = %d", ret); + } - fp = fopen(CALL_LOG_PATH,"rb"); - if (fp == NULL) { - return OHOS_FAILURE; - } - ftp = fopen(CALL_TMP_LOG_PATH, "wb+"); - if (ftp == NULL) { fclose(fp); - return OHOS_FAILURE; + return; } - info = (CallLogInfo *)malloc(fileSize); - if (info == NULL) { - fclose(fp); - fclose(ftp); - return OHOS_FAILURE; - } + static int CopyPhoneLogToTmpLog(void) + { + FILE *fp = NULL; + FILE *ftp = NULL; + CallLogInfo *info = NULL; - (void)memset_s(info, fileSize, 0, fileSize); - if(fread(info, fileSize, 1, fp) != 1) { - retLen = OHOS_FAILURE; - goto END; - } + int retLen; + int fileSize = GetCallLogFileSize(); - if(fwrite((info + 1), retLen, 1, ftp) != 1) { - retLen = OHOS_FAILURE; - goto END; - } + if (fileSize == OHOS_FAILURE || fileSize == 0) + { + return fileSize; + } -END: - fclose(fp); - fclose(ftp); - free(info); - info = NULL; - return retLen; -} + retLen = fileSize - sizeof(CallLogInfo); + if (retLen == 0) + { + return ClearCallLogFile(); // 只有一条记录,清空通话记录 + } -// 删除第一条通话记录 -int RemoveFirstCallLog(void) -{ - FILE *fp = NULL; - FILE *ftp = NULL; - CallLogInfo *info = NULL; + fp = fopen(CALL_LOG_PATH, "rb"); + if (fp == NULL) + { + return OHOS_FAILURE; + } + ftp = fopen(CALL_TMP_LOG_PATH, "wb+"); + if (ftp == NULL) + { + fclose(fp); + return OHOS_FAILURE; + } - int ret = OHOS_SUCCESS; - int fileSize = CopyPhoneLogToTmpLog(); - if (fileSize == OHOS_FAILURE || fileSize == 0) { - return fileSize; - } + info = (CallLogInfo *)malloc(fileSize); + if (info == NULL) + { + fclose(fp); + fclose(ftp); + return OHOS_FAILURE; + } - fp = fopen(CALL_LOG_PATH,"wb+"); - if (fp == NULL) { - return OHOS_FAILURE; - } - ftp = fopen(CALL_TMP_LOG_PATH, "rb"); - if (ftp == NULL) { - fclose(fp); - return OHOS_FAILURE; - } + (void)memset_s(info, fileSize, 0, fileSize); + if (fread(info, fileSize, 1, fp) != 1) + { + retLen = OHOS_FAILURE; + goto END; + } - info = (CallLogInfo *)malloc(fileSize); - if (info == NULL) { + if (fwrite((info + 1), retLen, 1, ftp) != 1) + { + retLen = OHOS_FAILURE; + goto END; + } + + END: fclose(fp); fclose(ftp); - return OHOS_FAILURE; - } - (void)memset_s(info, fileSize, 0, fileSize); - if(fread(info, fileSize, 1, ftp) != 1) { - ret = OHOS_FAILURE; - goto END; - } + free(info); + info = NULL; + return retLen; + } + + // 删除第一条通话记录 + int RemoveFirstCallLog(void) + { + FILE *fp = NULL; + FILE *ftp = NULL; + CallLogInfo *info = NULL; + + int ret = OHOS_SUCCESS; + int fileSize = CopyPhoneLogToTmpLog(); + if (fileSize == OHOS_FAILURE || fileSize == 0) + { + return fileSize; + } - if(fwrite(info, fileSize, 1, fp) != 1) { - ret = OHOS_FAILURE; - goto END; - } + fp = fopen(CALL_LOG_PATH, "wb+"); + if (fp == NULL) + { + return OHOS_FAILURE; + } + ftp = fopen(CALL_TMP_LOG_PATH, "rb"); + if (ftp == NULL) + { + fclose(fp); + return OHOS_FAILURE; + } -END: - fclose(fp); - fclose(ftp); - free(info); - info = NULL; - return ret; -} + info = (CallLogInfo *)malloc(fileSize); + if (info == NULL) + { + fclose(fp); + fclose(ftp); + return OHOS_FAILURE; + } + (void)memset_s(info, fileSize, 0, fileSize); + if (fread(info, fileSize, 1, ftp) != 1) + { + ret = OHOS_FAILURE; + goto END; + } -// 添加通话记录 -static void AddToCallLogPro(PhoneCallInfo *callInfo) -{ - int ret, num, fileSize; - CallLogInfo info; + if (fwrite(info, fileSize, 1, fp) != 1) + { + ret = OHOS_FAILURE; + goto END; + } - if (callInfo == NULL) { - return; + END: + fclose(fp); + fclose(ftp); + free(info); + info = NULL; + return ret; } - fileSize = GetCallLogFileSize(); - num = fileSize / sizeof(CallLogInfo); - if (num >= CALL_LOG_MAX_NUM) { - ret = RemoveFirstCallLog(); - if (ret == OHOS_FAILURE) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddToCallLogPro] RemoveFirstCallLog error"); + // 添加通话记录 + static void AddToCallLogPro(PhoneCallInfo *callInfo) + { + int ret, num, fileSize; + CallLogInfo info; + + if (callInfo == NULL) + { return; } - } - (void)memset_s(info.name, NAME_SIZE, '\0', NAME_SIZE); - (void)memset_s(info.tel, MAX_PHONE_NUM, '\0', MAX_PHONE_NUM); - ret = memcpy_s(info.name, NAME_SIZE, callInfo->name, callInfo->nameLen); - if (ret != EOK) { - info.nameLen = 0; - } else { - info.nameLen = callInfo->nameLen; - } + fileSize = GetCallLogFileSize(); + num = fileSize / sizeof(CallLogInfo); + if (num >= CALL_LOG_MAX_NUM) + { + ret = RemoveFirstCallLog(); + if (ret == OHOS_FAILURE) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddToCallLogPro] RemoveFirstCallLog error"); + return; + } + } - ret = memcpy_s(info.tel, MAX_PHONE_NUM, callInfo->unitCalls.number, callInfo->unitCalls.number_len); - if (ret != EOK) { - info.telLen = 0; - } else { - info.telLen = callInfo->unitCalls.number_len; - } + (void)memset_s(info.name, NAME_SIZE, '\0', NAME_SIZE); + (void)memset_s(info.tel, MAX_PHONE_NUM, '\0', MAX_PHONE_NUM); + ret = memcpy_s(info.name, NAME_SIZE, callInfo->name, callInfo->nameLen); + if (ret != EOK) + { + info.nameLen = 0; + } + else + { + info.nameLen = callInfo->nameLen; + } - info.creationTime = callInfo->creationTime; - if (callInfo->lastStatus == HFP_HF_CALL_STATE_ACTIVE || callInfo->lastStatus == HFP_HF_CALL_STATE_HELD || - callInfo->lastStatus == HFP_HF_CALL_STATE_RESPONSE_HELD) { - info.callDurTime = time(NULL) - callInfo->activeTime; - } else { - info.callDurTime = 0; - } + ret = memcpy_s(info.tel, MAX_PHONE_NUM, callInfo->unitCalls.number, callInfo->unitCalls.number_len); + if (ret != EOK) + { + info.telLen = 0; + } + else + { + info.telLen = callInfo->unitCalls.number_len; + } + + info.creationTime = callInfo->creationTime; + if (callInfo->lastStatus == HFP_HF_CALL_STATE_ACTIVE || callInfo->lastStatus == HFP_HF_CALL_STATE_HELD || + callInfo->lastStatus == HFP_HF_CALL_STATE_RESPONSE_HELD) + { + info.callDurTime = time(NULL) - callInfo->activeTime; + } + else + { + info.callDurTime = 0; + } + + if (callInfo->lastStatus == HFP_HF_CALL_STATE_INCOMING || callInfo->lastStatus == HFP_HF_CALL_STATE_WAITING) + { + info.status = CALL_MISSED; + } + else if (callInfo->unitCalls.outgoing == 1) + { + info.status = CALL_OUTGOING; + } + else + { + info.status = CALL_INCOMING; + } - if (callInfo->lastStatus == HFP_HF_CALL_STATE_INCOMING || callInfo->lastStatus == HFP_HF_CALL_STATE_WAITING) { - info.status = CALL_MISSED; - } else if (callInfo->unitCalls.outgoing == 1) { - info.status = CALL_OUTGOING; - } else { - info.status = CALL_INCOMING; + AddToCallLog(&info); } - AddToCallLog(&info); -} + // 获取通话记录 + int GetCallLog(CallLogInfo **info, int *num) + { + FILE *fp = NULL; + int ret, fileSize, number; + CallLogInfo *callInfo = NULL; -// 获取通话记录 -int GetCallLog(CallLogInfo **info, int *num) -{ - FILE *fp = NULL; - int ret, fileSize, number; - CallLogInfo *callInfo = NULL; + fp = fopen(CALL_LOG_PATH, "rb"); + if (fp == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddToCallLog] fopen CALL_LOG_PATH failed!"); + return OHOS_FAILURE; + } - fp = fopen(CALL_LOG_PATH, "rb"); - if (fp == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddToCallLog] fopen CALL_LOG_PATH failed!"); - return OHOS_FAILURE; - } + fileSize = GetCallLogFileSize(); + if (fileSize == 0) + { + *info = NULL; + *num = 0; + fclose(fp); + return OHOS_SUCCESS; + } - fileSize = GetCallLogFileSize(); - if (fileSize == 0) { - *info = NULL; - *num = 0; + number = fileSize / sizeof(CallLogInfo); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[GetCallLog] fileSize = %d, number = %d", fileSize, number); + callInfo = (CallLogInfo *)malloc(fileSize); + if (callInfo == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[GetCallLog] malloc callInfo fail!"); + *info = NULL; + *num = 0; + fclose(fp); + return OHOS_FAILURE; + } + (void)memset_s(callInfo, fileSize, 0, fileSize); + + ret = fread(callInfo, sizeof(CallLogInfo), number, fp); + if (ret != number) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[GetCallLog] fread fp fail ret = %d", ret); + *info = NULL; + *num = 0; + fclose(fp); + return OHOS_FAILURE; + } + + *info = callInfo; + *num = number; fclose(fp); return OHOS_SUCCESS; } - number = fileSize / sizeof(CallLogInfo); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[GetCallLog] fileSize = %d, number = %d", fileSize, number); - callInfo = (CallLogInfo *)malloc(fileSize); - if (callInfo == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[GetCallLog] malloc callInfo fail!"); - *info = NULL; - *num = 0; - fclose(fp); - return OHOS_FAILURE; - } - (void)memset_s(callInfo, fileSize, 0, fileSize); + // 清空通话记录 + int ClearCallLogFile(void) + { + FILE *fp = fopen(CALL_LOG_PATH, "wb"); + if (fp == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[ClearCallLogFile] fopen CALL_LOG_PATH failed!"); + return OHOS_FAILURE; + } - ret = fread(callInfo, sizeof(CallLogInfo), number, fp); - if (ret != number) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[GetCallLog] fread fp fail ret = %d", ret); - *info = NULL; - *num = 0; fclose(fp); - return OHOS_FAILURE; - } - - *info = callInfo; - *num = number; - fclose(fp); - return OHOS_SUCCESS; -} - -// 清空通话记录 -int ClearCallLogFile(void) -{ - FILE *fp = fopen(CALL_LOG_PATH, "wb"); - if (fp == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[ClearCallLogFile] fopen CALL_LOG_PATH failed!"); - return OHOS_FAILURE; + return OHOS_SUCCESS; } - fclose(fp); - return OHOS_SUCCESS; -} - -// 查找号码对应的电话信息在list中的位置 -static PhoneCallInfo *FindCallInfoInCallList(const unsigned char *number, unsigned char numberLen) -{ - int i; - const char *str1 = NULL; - const char *str2 = NULL; - - if (g_currCallNum == 0) { - return NULL; - } + // 查找号码对应的电话信息在list中的位置 + static PhoneCallInfo *FindCallInfoInCallList(const unsigned char *number, unsigned char numberLen) + { + int i; + const char *str1 = NULL; + const char *str2 = NULL; - for (i = 0; i < MULTI_CALL_MAX_NUME; i++) { - if (numberLen != g_callList[i].telLen) { - continue; - } else { - str1 = (const char*)number; - str2 = (const char*)g_callList[i].tel; + if (g_currCallNum == 0) + { + return NULL; + } - if (strncmp(str1, str2, numberLen) == 0) { - return &g_callList[i]; + for (i = 0; i < MULTI_CALL_MAX_NUME; i++) + { + if (numberLen != g_callList[i].telLen) + { + continue; + } + else + { + str1 = (const char *)number; + str2 = (const char *)g_callList[i].tel; + + if (strncmp(str1, str2, numberLen) == 0) + { + return &g_callList[i]; + } } } - } - return NULL; -} + return NULL; + } -static void CatPhoneNumber(char *number, unsigned char len) -{ + static void CatPhoneNumber(char *number, unsigned char len) + { #if WEARABLEOG_DEBUG_ENABLE - for (unsigned char i = 0; i < len; i++) { - printf("%c", *(number + i)); - } - printf(""); + for (unsigned char i = 0; i < len; i++) + { + printf("%c", *(number + i)); + } + printf(""); #else UNUSED(number); UNUSED(len); #endif -} + } -static void AddCurrCallToCallList(const hfp_hf_calls_info_t *call) -{ - PhoneCallInfo *phoneCall = NULL; - int tmp, ret; + static void AddCurrCallToCallList(const hfp_hf_calls_info_t *call) + { + PhoneCallInfo *phoneCall = NULL; + int tmp, ret; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AddCurrCallToCallList] start, call->state = %d", call->state); - if (call == NULL || g_currCallNum >= MULTI_CALL_MAX_NUME || - (call->state != HFP_HF_CALL_STATE_ACTIVE && call->state != HFP_HF_CALL_STATE_HELD && - call->state != HFP_HF_CALL_STATE_ALERTING)) { - return; - } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AddCurrCallToCallList] start, call->state = %d", call->state); + if (call == NULL || g_currCallNum >= MULTI_CALL_MAX_NUME || + (call->state != HFP_HF_CALL_STATE_ACTIVE && call->state != HFP_HF_CALL_STATE_HELD && + call->state != HFP_HF_CALL_STATE_ALERTING)) + { + return; + } - g_currCallNum++; - tmp = g_currCallNum - 1; - phoneCall = &g_callList[tmp]; + g_currCallNum++; + tmp = g_currCallNum - 1; + phoneCall = &g_callList[tmp]; - if (call->state == HFP_HF_CALL_STATE_ACTIVE) { // 正在通话 - phoneCall->operate = OPERATE_PHONE_ACTIVE; - phoneCall->activeTime = time(NULL); - } else if (call->state == HFP_HF_CALL_STATE_HELD) { // 挂起 - phoneCall->operate = OPERATE_PHONE_HOLD; - phoneCall->activeTime = time(NULL); - } else if (call->state == HFP_HF_CALL_STATE_ALERTING) { // 呼出,对方响铃 - phoneCall->operate = OPERATE_ALERTING; - } + if (call->state == HFP_HF_CALL_STATE_ACTIVE) + { // 正在通话 + phoneCall->operate = OPERATE_PHONE_ACTIVE; + phoneCall->activeTime = time(NULL); + } + else if (call->state == HFP_HF_CALL_STATE_HELD) + { // 挂起 + phoneCall->operate = OPERATE_PHONE_HOLD; + phoneCall->activeTime = time(NULL); + } + else if (call->state == HFP_HF_CALL_STATE_ALERTING) + { // 呼出,对方响铃 + phoneCall->operate = OPERATE_ALERTING; + } - // 使用通讯录接口获取当前电话对应的备注人名(通讯录待开发) + // 使用通讯录接口获取当前电话对应的备注人名(通讯录待开发) - phoneCall->lastStatus = call->state; - phoneCall->creationTime = time(NULL); + phoneCall->lastStatus = call->state; + phoneCall->creationTime = time(NULL); - ret = memcpy_s(phoneCall->tel, MAX_PHONE_NUM, call->number, call->number_len); - if (ret != EOK) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddCurrCallToCallList] memcpy_s tel fail, ret = %d", ret); - CatPhoneNumber(call->number, call->number_len); + ret = memcpy_s(phoneCall->tel, MAX_PHONE_NUM, call->number, call->number_len); + if (ret != EOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AddCurrCallToCallList] memcpy_s tel fail, ret = %d", ret); + CatPhoneNumber(call->number, call->number_len); + } + phoneCall->telLen = call->number_len; + (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AddCurrCallToCallList] end"); + + // 通知手表电话呼入 + CallChangedCb(phoneCall); } - phoneCall->telLen = call->number_len; - (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AddCurrCallToCallList] end"); - // 通知手表电话呼入 - CallChangedCb(phoneCall); -} + // 通话状态变化--呼出,正在拨号处理 + static void CallChangeDialPro(const hfp_hf_calls_info_t *call) + { + PhoneCallInfo *phoneCall = NULL; + int tmp, ret; -// 通话状态变化--呼出,正在拨号处理 -static void CallChangeDialPro(const hfp_hf_calls_info_t *call) -{ - PhoneCallInfo *phoneCall = NULL; - int tmp, ret; + if (call == NULL) + { + return; + } + g_currCallNum++; + tmp = g_currCallNum - 1; - if (call == NULL) { - return; - } - g_currCallNum++; - tmp = g_currCallNum - 1; + phoneCall = &g_callList[tmp]; - phoneCall = &g_callList[tmp]; + // 使用通讯录接口获取当前电话对应的备注人名(通讯录待开发) - // 使用通讯录接口获取当前电话对应的备注人名(通讯录待开发) + phoneCall->operate = OPERATE_DIALING; + phoneCall->lastStatus = call->state; + phoneCall->creationTime = time(NULL); - phoneCall->operate = OPERATE_DIALING; - phoneCall->lastStatus = call->state; - phoneCall->creationTime = time(NULL); + ret = memcpy_s(phoneCall->tel, MAX_PHONE_NUM, call->number, call->number_len); + if (ret != EOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CallChangeDialPro] memcpy_s tel fail, ret = %d", ret); + CatPhoneNumber(call->number, call->number_len); + } + phoneCall->telLen = call->number_len; - ret = memcpy_s(phoneCall->tel, MAX_PHONE_NUM, call->number, call->number_len); - if (ret != EOK) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CallChangeDialPro] memcpy_s tel fail, ret = %d", ret); - CatPhoneNumber(call->number, call->number_len); + (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); + + // 通知手表正在拨号 + CallChangedCb(phoneCall); } - phoneCall->telLen = call->number_len; - (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); + // 通话状态变化--呼出,对方响铃 + static void CallChangeAlertPro(const hfp_hf_calls_info_t *call) + { + PhoneCallInfo *phoneCall = NULL; - // 通知手表正在拨号 - CallChangedCb(phoneCall); -} + if (call == NULL) + { + return; + } -// 通话状态变化--呼出,对方响铃 -static void CallChangeAlertPro(const hfp_hf_calls_info_t *call) -{ - PhoneCallInfo *phoneCall = NULL; + phoneCall = FindCallInfoInCallList((const unsigned char *)call->number, call->number_len); + if (phoneCall == NULL) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeAlertPro] FindCallInfoInCallList Alert no this call"); + AddCurrCallToCallList(call); + return; + } + phoneCall->operate = OPERATE_ALERTING; + phoneCall->lastStatus = call->state; - if (call == NULL) { - return; - } + (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); - phoneCall = FindCallInfoInCallList((const unsigned char*)call->number, call->number_len); - if (phoneCall == NULL) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeAlertPro] FindCallInfoInCallList Alert no this call"); - AddCurrCallToCallList(call); - return; + // 通知手表正对方响铃 + CallChangedCb(phoneCall); } - phoneCall->operate = OPERATE_ALERTING; - phoneCall->lastStatus = call->state; - (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); + void HfpIncomingEventPublish(uint16 topic, hfp_hf_calls_info_t callsInfo) + { + int32 ret; + uint32 size = sizeof(hfp_hf_calls_info_t); + Request *request = NULL; + BroadcastApi *broadcastApi = NULL; + IUnknown *api = NULL; - // 通知手表正对方响铃 - CallChangedCb(phoneCall); -} + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HfpIncomingEventPublish topic=%u!!", topic); -void HfpIncomingEventPublish(uint16 topic, hfp_hf_calls_info_t callsInfo) -{ - int32 ret; - uint32 size = sizeof(hfp_hf_calls_info_t); - Request *request = NULL; - BroadcastApi *broadcastApi = NULL; - IUnknown *api = NULL; - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HfpIncomingEventPublish topic=%u!!", topic); - - /* alloc request */ - request = SAMGR_AllocRequestMsg(0, PLATFORM_CORE, BROADCAST_SVR_ID, size); - if (request == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SAMGR_AllocRequestMsg failed"); - return; - } - request->msgId = topic; - ret = memcpy_s(request->data, size, (const void *)&callsInfo, size); - if (ret != EOK) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HfpIncomingEventPublish memcpy_s rateDataTmp fail! ret = %d", ret); - return; - } - request->len = size; - request->msgValue = 0; + /* alloc request */ + request = SAMGR_AllocRequestMsg(0, PLATFORM_CORE, BROADCAST_SVR_ID, size); + if (request == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SAMGR_AllocRequestMsg failed"); + return; + } + request->msgId = topic; + ret = memcpy_s(request->data, size, (const void *)&callsInfo, size); + if (ret != EOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HfpIncomingEventPublish memcpy_s rateDataTmp fail! ret = %d", ret); + return; + } + request->len = size; + request->msgValue = 0; + + /* public request */ + api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME); + if (api == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetFeatureApi failed"); + SAMGR_FreeRequestMsg(request); + return; + } + ret = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi); + if (ret != 0 || broadcastApi == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "QueryInterface failed"); + SAMGR_FreeRequestMsg(request); + return; + } + broadcastApi->PublishTopic((IUnknown *)broadcastApi, request); + broadcastApi->Release((IUnknown *)broadcastApi); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HfpIncomingEventPublish end!!"); - /* public request */ - api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME); - if (api == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetFeatureApi failed"); - SAMGR_FreeRequestMsg(request); - return; - } - ret = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi); - if (ret != 0 || broadcastApi == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "QueryInterface failed"); - SAMGR_FreeRequestMsg(request); return; } - broadcastApi->PublishTopic((IUnknown *)broadcastApi, request); - broadcastApi->Release((IUnknown *)broadcastApi); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HfpIncomingEventPublish end!!"); - return; -} + // 通话状态变化--呼入处理 + static void CallChangeIncomePro(const hfp_hf_calls_info_t *call) + { + PhoneCallInfo *phoneCall = NULL; + int tmp, ret; -// 通话状态变化--呼入处理 -static void CallChangeIncomePro(const hfp_hf_calls_info_t *call) -{ - PhoneCallInfo *phoneCall = NULL; - int tmp, ret; + if (call == NULL || g_currCallNum >= MULTI_CALL_MAX_NUME || + (call->state != HFP_HF_CALL_STATE_INCOMING && call->state != HFP_HF_CALL_STATE_WAITING)) + { + return; + } - if (call == NULL || g_currCallNum >= MULTI_CALL_MAX_NUME || - (call->state != HFP_HF_CALL_STATE_INCOMING && call->state != HFP_HF_CALL_STATE_WAITING)) { - return; - } + phoneCall = FindCallInfoInCallList((const unsigned char *)call->number, call->number_len); + if (phoneCall != NULL) + { + // 通话状态由呼入等待转换成呼入情况 + } + else + { + g_currCallNum++; + tmp = g_currCallNum - 1; + phoneCall = &g_callList[tmp]; + } - phoneCall = FindCallInfoInCallList((const unsigned char*)call->number, call->number_len); - if (phoneCall != NULL) { - // 通话状态由呼入等待转换成呼入情况 - } else { - g_currCallNum++; - tmp = g_currCallNum - 1; - phoneCall = &g_callList[tmp]; - } + // 使用通讯录接口获取当前电话对应的备注人名(通讯录待开发) - // 使用通讯录接口获取当前电话对应的备注人名(通讯录待开发) + if (call->state == HFP_HF_CALL_STATE_INCOMING) + { + phoneCall->operate = OPERATE_INCOMING; + } + else + { + phoneCall->operate = OPERATE_WAITING; + } + phoneCall->lastStatus = call->state; + phoneCall->creationTime = time(NULL); + + ret = memcpy_s(phoneCall->tel, MAX_PHONE_NUM, call->number, call->number_len); + if (ret != EOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CallChangeIncomePro] memcpy_s tel fail, ret = %d", ret); + CatPhoneNumber(call->number, call->number_len); + } + phoneCall->telLen = call->number_len; - if (call->state == HFP_HF_CALL_STATE_INCOMING) { - phoneCall->operate = OPERATE_INCOMING; - } else { - phoneCall->operate = OPERATE_WAITING; - } - phoneCall->lastStatus = call->state; - phoneCall->creationTime = time(NULL); + (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); - ret = memcpy_s(phoneCall->tel, MAX_PHONE_NUM, call->number, call->number_len); - if (ret != EOK) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CallChangeIncomePro] memcpy_s tel fail, ret = %d", ret); - CatPhoneNumber(call->number, call->number_len); + // 发布电话呼入事件 + HfpIncomingEventPublish(TOPIC_EVENT_HFP_INCOMMING, phoneCall->unitCalls); + // 通知手表电话呼入 + CallChangedCb(phoneCall); } - phoneCall->telLen = call->number_len; - (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); + // 通话状态变化--接听流程处理 + static void CallChangeActivePro(const hfp_hf_calls_info_t *call) + { + PhoneCallInfo *phoneCall = NULL; - // 发布电话呼入事件 - HfpIncomingEventPublish(TOPIC_EVENT_HFP_INCOMMING, phoneCall->unitCalls); - // 通知手表电话呼入 - CallChangedCb(phoneCall); -} + if (call == NULL) + { + return; + } -// 通话状态变化--接听流程处理 -static void CallChangeActivePro(const hfp_hf_calls_info_t *call) -{ - PhoneCallInfo *phoneCall = NULL; + phoneCall = FindCallInfoInCallList((const unsigned char *)call->number, call->number_len); + if (phoneCall == NULL) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeActivePro] FindCallInfoInCallList Active no this call"); + AddCurrCallToCallList(call); + return; + } - if (call == NULL) { - return; - } + if (phoneCall->lastStatus == HFP_HF_CALL_STATE_HELD && IsCompleteCallFlow() == true) + { // 挂起状态切换到接听状态 + phoneCall->operate = OPERATE_WATCH_ACTIVE; + } + else if (phoneCall->lastStatus == HFP_HF_CALL_STATE_HELD && IsCompleteCallFlow() == false) + { + phoneCall->operate = OPERATE_PHONE_ACTIVE; + } + else if (phoneCall->operate == OPERATE_WATCH_ACTIVE) + { // 手表接听 + // 不做操作 + } + else + { + if (phoneCall->unitCalls.outgoing == 1 && + (phoneCall->lastStatus == HFP_HF_CALL_STATE_DIALING || phoneCall->lastStatus == HFP_HF_CALL_STATE_ALERTING)) + { + phoneCall->operate = OPERATE_PEER_ACTIVE; // 对方接听 + } + else + { + // 手机接听 + phoneCall->operate = OPERATE_PHONE_ACTIVE; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeActivePro] phone active!"); + } + } - phoneCall = FindCallInfoInCallList((const unsigned char*)call->number, call->number_len); - if (phoneCall == NULL) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeActivePro] FindCallInfoInCallList Active no this call"); - AddCurrCallToCallList(call); - return; - } + if (phoneCall->activeTime == 0 && + (phoneCall->lastStatus == HFP_HF_CALL_STATE_DIALING || phoneCall->lastStatus == HFP_HF_CALL_STATE_ALERTING || + phoneCall->lastStatus == HFP_HF_CALL_STATE_INCOMING || phoneCall->lastStatus == HFP_HF_CALL_STATE_WAITING)) + { + phoneCall->activeTime = time(NULL); + } - if (phoneCall->lastStatus == HFP_HF_CALL_STATE_HELD && IsCompleteCallFlow() == true) { // 挂起状态切换到接听状态 - phoneCall->operate = OPERATE_WATCH_ACTIVE; - } else if (phoneCall->lastStatus == HFP_HF_CALL_STATE_HELD && IsCompleteCallFlow() == false) { - phoneCall->operate = OPERATE_PHONE_ACTIVE; - } else if (phoneCall->operate == OPERATE_WATCH_ACTIVE) { // 手表接听 - // 不做操作 - } else { - if (phoneCall->unitCalls.outgoing == 1 && - (phoneCall->lastStatus == HFP_HF_CALL_STATE_DIALING || phoneCall->lastStatus == HFP_HF_CALL_STATE_ALERTING)) { - phoneCall->operate = OPERATE_PEER_ACTIVE; // 对方接听 - } else { - // 手机接听 - phoneCall->operate = OPERATE_PHONE_ACTIVE; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeActivePro] phone active!"); + phoneCall->lastStatus = call->state; + (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); + if (phoneCall->operate == OPERATE_PHONE_ACTIVE) + { + // 发布电话接听事件,手表关闭来电通知 + HfpIncomingEventPublish(TOPIC_EVENT_HFP_PHONE_ACTIVE, phoneCall->unitCalls); + } + else if (phoneCall->operate == OPERATE_WATCH_ACTIVE && g_scoFlag == HFP_SCO_STATE_CONNECTED) + { + // 发布手表接听事件,通知切换接听界面 + HfpIncomingEventPublish(TOPIC_EVENT_HFP_WATCH_ACTIVE, phoneCall->unitCalls); } + // 通知手表触发接听 + CallChangedCb(phoneCall); } - if (phoneCall->activeTime == 0 && - (phoneCall->lastStatus == HFP_HF_CALL_STATE_DIALING || phoneCall->lastStatus == HFP_HF_CALL_STATE_ALERTING || - phoneCall->lastStatus == HFP_HF_CALL_STATE_INCOMING || phoneCall->lastStatus == HFP_HF_CALL_STATE_WAITING)) { - phoneCall->activeTime = time(NULL); - } + // 通话状态变化--拒接/结束流程处理 + static void CallChangeFinishPro(const hfp_hf_calls_info_t *call) + { + PhoneCallInfo *phoneCall = NULL; + PhoneCallInfo tmp; - phoneCall->lastStatus = call->state; - (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); - if (phoneCall->operate == OPERATE_PHONE_ACTIVE) { - // 发布电话接听事件,手表关闭来电通知 - HfpIncomingEventPublish(TOPIC_EVENT_HFP_PHONE_ACTIVE, phoneCall->unitCalls); - } else if (phoneCall->operate == OPERATE_WATCH_ACTIVE && g_scoFlag == HFP_SCO_STATE_CONNECTED) { - // 发布手表接听事件,通知切换接听界面 - HfpIncomingEventPublish(TOPIC_EVENT_HFP_WATCH_ACTIVE, phoneCall->unitCalls); - } - // 通知手表触发接听 - CallChangedCb(phoneCall); -} + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeFinishPro] start g_scoFlag = %d, g_currCallNum = %d", + g_scoFlag, g_currCallNum); + if (call == NULL || g_currCallNum == 0) + { + return; + } -// 通话状态变化--拒接/结束流程处理 -static void CallChangeFinishPro(const hfp_hf_calls_info_t *call) -{ - PhoneCallInfo *phoneCall = NULL; - PhoneCallInfo tmp; + phoneCall = FindCallInfoInCallList((const unsigned char *)call->number, call->number_len); + if (phoneCall == NULL) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeFinishPro] FindCallInfoInCallList Finish no this call"); + return; + } + if (g_finishOperate == OPERATE_WATCH_FINISH) + { + phoneCall->operate = OPERATE_WATCH_FINISH; + } + else if (g_finishOperate == OPERATE_WATCH_REJECT) + { + phoneCall->operate = OPERATE_WATCH_REJECT; + } + else + { + phoneCall->operate = OPERATE_NON_WATCH_FINISH; + } + g_finishOperate = OPERATE_NON_WATCH_FINISH; + g_currCallNum--; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeFinishPro] start g_scoFlag = %d, g_currCallNum = %d", - g_scoFlag, g_currCallNum); - if (call == NULL || g_currCallNum == 0) { - return; - } + (void)memcpy_s(&tmp, sizeof(PhoneCallInfo), phoneCall, sizeof(PhoneCallInfo)); + (void)memcpy_s(&tmp.unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); + (void)memset_s(phoneCall, sizeof(PhoneCallInfo), 0, sizeof(PhoneCallInfo)); + (void)memset_s(phoneCall->name, NAME_SIZE, '\0', NAME_SIZE); + (void)memset_s(phoneCall->tel, MAX_PHONE_NUM, '\0', MAX_PHONE_NUM); + phoneCall->lastStatus = HFP_HF_CALL_STATE_FINISHED; - phoneCall = FindCallInfoInCallList((const unsigned char*)call->number, call->number_len); - if (phoneCall == NULL) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeFinishPro] FindCallInfoInCallList Finish no this call"); - return; - } - if (g_finishOperate == OPERATE_WATCH_FINISH) { - phoneCall->operate = OPERATE_WATCH_FINISH; - } else if (g_finishOperate == OPERATE_WATCH_REJECT) { - phoneCall->operate = OPERATE_WATCH_REJECT; - } else { - phoneCall->operate = OPERATE_NON_WATCH_FINISH; - } - g_finishOperate = OPERATE_NON_WATCH_FINISH; - g_currCallNum--; + // 添加通话记录 + AddToCallLogPro(&tmp); - (void)memcpy_s(&tmp, sizeof(PhoneCallInfo), phoneCall, sizeof(PhoneCallInfo)); - (void)memcpy_s(&tmp.unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); - (void)memset_s(phoneCall, sizeof(PhoneCallInfo), 0, sizeof(PhoneCallInfo)); - (void)memset_s(phoneCall->name, NAME_SIZE, '\0', NAME_SIZE); - (void)memset_s(phoneCall->tel, MAX_PHONE_NUM, '\0', MAX_PHONE_NUM); - phoneCall->lastStatus = HFP_HF_CALL_STATE_FINISHED; + // 发布电话结束事件 + HfpIncomingEventPublish(TOPIC_EVENT_HFP_FINISHED, phoneCall->unitCalls); + // 通知手表通话结束 + CallChangedCb(&tmp); - // 添加通话记录 - AddToCallLogPro(&tmp); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeFinishPro] end g_scoFlag = %d, g_currCallNum = %d", + g_scoFlag, g_currCallNum); + } - // 发布电话结束事件 - HfpIncomingEventPublish(TOPIC_EVENT_HFP_FINISHED, phoneCall->unitCalls); - // 通知手表通话结束 - CallChangedCb(&tmp); + // 通话状态变化--挂起通话(当前只有手机挂起触发(并且手表不需感知),手表不支持挂起触发,对方挂起不感知) + static void CallChangeHeldPro(const hfp_hf_calls_info_t *call) + { + PhoneCallInfo *phoneCall = NULL; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeFinishPro] end g_scoFlag = %d, g_currCallNum = %d", - g_scoFlag, g_currCallNum); -} + if (call == NULL) + { + return; + } -// 通话状态变化--挂起通话(当前只有手机挂起触发(并且手表不需感知),手表不支持挂起触发,对方挂起不感知) -static void CallChangeHeldPro(const hfp_hf_calls_info_t *call) -{ - PhoneCallInfo *phoneCall = NULL; + phoneCall = FindCallInfoInCallList((const unsigned char *)call->number, call->number_len); + if (phoneCall == NULL) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeHeldPro] FindCallInfoInCallList Held no this call"); + AddCurrCallToCallList(call); + return; + } - if (call == NULL) { - return; - } + // 手机挂起通话 + phoneCall->operate = OPERATE_PHONE_HOLD; + if (phoneCall->lastStatus == HFP_HF_CALL_STATE_INCOMING || phoneCall->lastStatus == HFP_HF_CALL_STATE_WAITING) + { + phoneCall->activeTime = time(NULL); + } + phoneCall->lastStatus = call->state; + (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); - phoneCall = FindCallInfoInCallList((const unsigned char*)call->number, call->number_len); - if (phoneCall == NULL) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallChangeHeldPro] FindCallInfoInCallList Held no this call"); - AddCurrCallToCallList(call); - return; + // 通知手表触发挂起 + CallChangedCb(phoneCall); } - // 手机挂起通话 - phoneCall->operate = OPERATE_PHONE_HOLD; - if (phoneCall->lastStatus == HFP_HF_CALL_STATE_INCOMING || phoneCall->lastStatus == HFP_HF_CALL_STATE_WAITING) { - phoneCall->activeTime = time(NULL); + static void PlayWatchRing(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayWatchRing] start"); + // 申请手表铃声焦点 + // AudioActInterrupt(AUDIO_STREAM_RING); + // 播放手表铃声(播放方案待定) } - phoneCall->lastStatus = call->state; - (void)memcpy_s(&phoneCall->unitCalls, sizeof(hfp_hf_calls_info_t), call, sizeof(hfp_hf_calls_info_t)); - - // 通知手表触发挂起 - CallChangedCb(phoneCall); -} - -static void PlayWatchRing(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PlayWatchRing] start"); - // 申请手表铃声焦点 - // AudioActInterrupt(AUDIO_STREAM_RING); - // 播放手表铃声(播放方案待定) -} -static void CallAudioHandle(const hfp_hf_calls_info_t *call) -{ - int state = call->state; + static void CallAudioHandle(const hfp_hf_calls_info_t *call) + { + int state = call->state; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallAudioHandle] start g_audioState: %d", g_audioState); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallAudioHandle] start g_audioState: %d", g_audioState); - if (state == HFP_HF_CALL_STATE_INCOMING || state == HFP_HF_CALL_STATE_DIALING || - state == HFP_HF_CALL_STATE_ALERTING) { // 电话呼入,支持播放手机铃声 - if (call->in_band_ring == true) { - // 播放手机端铃声 - PostGraphicEvent(AudioDn); - } else { - if (g_scoFlag != HFP_SCO_STATE_CONNECTED) { - // 播放手表铃声 - PostGraphicEvent(PlayWatchRing); + if (state == HFP_HF_CALL_STATE_INCOMING || state == HFP_HF_CALL_STATE_DIALING || + state == HFP_HF_CALL_STATE_ALERTING) + { // 电话呼入,支持播放手机铃声 + if (call->in_band_ring == true) + { + // 播放手机端铃声 + PostGraphicEvent(AudioDn); + } + else + { + if (g_scoFlag != HFP_SCO_STATE_CONNECTED) + { + // 播放手表铃声 + PostGraphicEvent(PlayWatchRing); + } } } - } else if (state == HFP_HF_CALL_STATE_FINISHED) { - return; - } else if (g_scoFlag == HFP_SCO_STATE_CONNECTED) { - if (g_audioState < AUDIO_STREAM_START_DN) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallAudioHandle] post AudioDn"); - PostGraphicEvent(AudioDn); + else if (state == HFP_HF_CALL_STATE_FINISHED) + { + return; } - if (g_audioState != AUDIO_STREAM_START_UP) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallAudioHandle] post AudioUp"); - PostGraphicEvent(AudioUp); + else if (g_scoFlag == HFP_SCO_STATE_CONNECTED) + { + if (g_audioState < AUDIO_STREAM_START_DN) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallAudioHandle] post AudioDn"); + PostGraphicEvent(AudioDn); + } + if (g_audioState != AUDIO_STREAM_START_UP) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallAudioHandle] post AudioUp"); + PostGraphicEvent(AudioUp); + } } - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallAudioHandle] end g_audioState: %d", g_audioState); -} - -static void CatCallStateChangedInfo(const bd_addr_t *bdAddr, const hfp_hf_calls_info_t *call) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "***************************CallStateChanged***************************"); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "g_scoFlag = %d, g_currCallNum = %d, bdAddr: ", g_scoFlag, g_currCallNum); - CatBdAddr(bdAddr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "id = %d, state = %d", call->id, call->state); - CatPhoneNumber(call->number, call->number_len); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "multi_party = %d, outgoing = %d, in_band_ring = %d, creation_time = %ld", - call->multi_party, call->outgoing, call->in_band_ring, call->creation_time); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "***********************************************************************"); -} + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CallAudioHandle] end g_audioState: %d", g_audioState); + } -// 设置完整通话标志 -static void SetCompleteCallFlag(const hfp_hf_calls_info_t *call) -{ - if (call->state == HFP_HF_CALL_STATE_INCOMING) { - g_completeCallFlag = true; - } else if ((call->state == HFP_HF_CALL_STATE_DIALING || call->state == HFP_HF_CALL_STATE_ALERTING) && - (g_currCallNum == 1 || g_currCallNum == 0)) { - g_completeCallFlag = true; - } else if (call->state == HFP_HF_CALL_STATE_ACTIVE) { - g_completeCallFlag = true; + static void CatCallStateChangedInfo(const bd_addr_t *bdAddr, const hfp_hf_calls_info_t *call) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "***************************CallStateChanged***************************"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "g_scoFlag = %d, g_currCallNum = %d, bdAddr: ", g_scoFlag, g_currCallNum); + CatBdAddr(bdAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "id = %d, state = %d", call->id, call->state); + CatPhoneNumber(call->number, call->number_len); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "multi_party = %d, outgoing = %d, in_band_ring = %d, creation_time = %ld", + call->multi_party, call->outgoing, call->in_band_ring, call->creation_time); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "***********************************************************************"); } -} -bool IsCompleteCallFlow(void) -{ - return g_completeCallFlag; -} + // 设置完整通话标志 + static void SetCompleteCallFlag(const hfp_hf_calls_info_t *call) + { + if (call->state == HFP_HF_CALL_STATE_INCOMING) + { + g_completeCallFlag = true; + } + else if ((call->state == HFP_HF_CALL_STATE_DIALING || call->state == HFP_HF_CALL_STATE_ALERTING) && + (g_currCallNum == 1 || g_currCallNum == 0)) + { + g_completeCallFlag = true; + } + else if (call->state == HFP_HF_CALL_STATE_ACTIVE) + { + g_completeCallFlag = true; + } + } -// 通话状态变化上报回调 -static void CallStateChanged(const bd_addr_t *bdAddr, const hfp_hf_calls_info_t *call) -{ - CopyBdAddr(bdAddr); - if (call == NULL || g_btConnState != PROFILE_STATE_CONNECTED) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "call is null or BT disconnected connStatus: 0x%X", g_btConnState); - return; + bool IsCompleteCallFlow(void) + { + return g_completeCallFlag; } - SetCompleteCallFlag(call); - CatCallStateChangedInfo(bdAddr, call); - CallAudioHandle(call); + // 通话状态变化上报回调 + static void CallStateChanged(const bd_addr_t *bdAddr, const hfp_hf_calls_info_t *call) + { + CopyBdAddr(bdAddr); + if (call == NULL || g_btConnState != PROFILE_STATE_CONNECTED) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "call is null or BT disconnected connStatus: 0x%X", g_btConnState); + return; + } + + SetCompleteCallFlag(call); + CatCallStateChangedInfo(bdAddr, call); + CallAudioHandle(call); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "CallStateChanged state = %d", call->state); - switch (call->state) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "CallStateChanged state = %d", call->state); + switch (call->state) + { case HFP_HF_CALL_STATE_ACTIVE: // 正在通话 CallChangeActivePro(call); break; @@ -1438,467 +1635,517 @@ static void CallStateChanged(const bd_addr_t *bdAddr, const hfp_hf_calls_info_t break; default: break; - } + } - // 规避某些型号手机在电话呼入时重复断开和连接SCO - if (call->state == HFP_HF_CALL_STATE_FINISHED) { - if (g_currCallNum == 0) { - g_currCallState = HFP_HF_CALL_STATE_FINISHED; + // 规避某些型号手机在电话呼入时重复断开和连接SCO + if (call->state == HFP_HF_CALL_STATE_FINISHED) + { + if (g_currCallNum == 0) + { + g_currCallState = HFP_HF_CALL_STATE_FINISHED; + } + } + else + { + g_currCallState = call->state; } - } else { - g_currCallState = call->state; - } - if (g_currCallNum == 0) { - g_completeCallFlag = false; + if (g_currCallNum == 0) + { + g_completeCallFlag = false; + } } -} -static void BtHfpVolumeChanged(int volumeType, unsigned char hfpVolume) -{ - int maxVolume, minVolume, volume; - bool ret; + static void BtHfpVolumeChanged(int volumeType, unsigned char hfpVolume) + { + int maxVolume, minVolume, volume; + bool ret; - // mic - if (volumeType == HFP_VOLUME_MIC) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VolumeChanged Type = %d, hfpVolume = %d", - volumeType, hfpVolume); - } + // mic + if (volumeType == HFP_VOLUME_MIC) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VolumeChanged Type = %d, hfpVolume = %d", + volumeType, hfpVolume); + } - // speak - if (volumeType == HFP_VOLUME_SPEAKER) { - minVolume = PhoneAudioGetMinVolume(); - maxVolume = PhoneAudioGetMaxVolume(); - volume = hfpVolume * (maxVolume - minVolume) / CALL_VOLUME_MAX; // 转换 - volume = (volume == 0) ? ((maxVolume - minVolume) / CALL_VOLUME_MAX) : volume; - ret = PhoneAudioSetVolume(volume); - if (ret != true) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VolumeChanged Type: %d, ret: %d", - volumeType, ret); + // speak + if (volumeType == HFP_VOLUME_SPEAKER) + { + minVolume = PhoneAudioGetMinVolume(); + maxVolume = PhoneAudioGetMaxVolume(); + volume = hfpVolume * (maxVolume - minVolume) / CALL_VOLUME_MAX; // 转换 + volume = (volume == 0) ? ((maxVolume - minVolume) / CALL_VOLUME_MAX) : volume; + ret = PhoneAudioSetVolume(volume); + if (ret != true) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VolumeChanged Type: %d, ret: %d", + volumeType, ret); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VolumeChanged Type: %d, min: %d, max: %d volume: %d ret: %d", + volumeType, minVolume, maxVolume, volume, ret); } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VolumeChanged Type: %d, min: %d, max: %d volume: %d ret: %d", - volumeType, minVolume, maxVolume, volume, ret); } -} -// 音量调节回调 -static void VolumeChanged(const bd_addr_t *bdAddr, hfp_volume_type_t type, unsigned char volume) -{ - UNUSED(bdAddr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[VolumeChanged] type = %d volume = %d", type, volume); - GraphicService::GetInstance()->PostGraphicEvent(std::bind(BtHfpVolumeChanged, type, volume)); -} - -// 拨号失败回调 -static void DialErrorCode(const bd_addr_t *bdAddr, int code) -{ - UNUSED(bdAddr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[DialErrorCode] code = %d", code); - PhoneServiceErrorCallback(ERROR_DIAL, code); -} - -static void HfpBatteryChanged(const bd_addr_t *bdAddr, int batteryLevel) -{ - UNUSED(bdAddr); - UNUSED(batteryLevel); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpBatteryChanged] batteryLevel: %d", batteryLevel); -} + // 音量调节回调 + static void VolumeChanged(const bd_addr_t *bdAddr, hfp_volume_type_t type, unsigned char volume) + { + UNUSED(bdAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[VolumeChanged] type = %d volume = %d", type, volume); + GraphicService::GetInstance()->PostGraphicEvent(std::bind(BtHfpVolumeChanged, type, volume)); + } -static void HfpSignalStrengthChanged(const bd_addr_t *bdAddr, int signalStrength) -{ - UNUSED(bdAddr); - UNUSED(signalStrength); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpSignalStrengthChanged] signalStrength: %d", signalStrength); -} + // 拨号失败回调 + static void DialErrorCode(const bd_addr_t *bdAddr, int code) + { + UNUSED(bdAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[DialErrorCode] code = %d", code); + PhoneServiceErrorCallback(ERROR_DIAL, code); + } -static void HfpRegistStatusChanged(const bd_addr_t *bdAddr, int status) -{ - UNUSED(bdAddr); - UNUSED(status); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpRegistStatusChanged] status: %d", status); -} + static void HfpBatteryChanged(const bd_addr_t *bdAddr, int batteryLevel) + { + UNUSED(bdAddr); + UNUSED(batteryLevel); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpBatteryChanged] batteryLevel: %d", batteryLevel); + } -static void HfpRoamingStatusChanged(const bd_addr_t *bdAddr, int status) -{ - UNUSED(bdAddr); - UNUSED(status); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpRoamingStatusChanged] status: %d", status); -} + static void HfpSignalStrengthChanged(const bd_addr_t *bdAddr, int signalStrength) + { + UNUSED(bdAddr); + UNUSED(signalStrength); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpSignalStrengthChanged] signalStrength: %d", signalStrength); + } -static void HfpOperatorSelection(const bd_addr_t *bdAddr, unsigned char *name, unsigned int len) -{ - UNUSED(bdAddr); - UNUSED(name); - UNUSED(len); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpOperatorSelection] name: %s, len: %d", name, len); -} + static void HfpRegistStatusChanged(const bd_addr_t *bdAddr, int status) + { + UNUSED(bdAddr); + UNUSED(status); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpRegistStatusChanged] status: %d", status); + } -static void HfpSubscriberNumber(const bd_addr_t *bdAddr, unsigned char *number, unsigned int len) -{ - UNUSED(bdAddr); - UNUSED(number); - UNUSED(len); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpSubscriberNumber] number: %s, len: %d", number, len); -} + static void HfpRoamingStatusChanged(const bd_addr_t *bdAddr, int status) + { + UNUSED(bdAddr); + UNUSED(status); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpRoamingStatusChanged] status: %d", status); + } -static void VoiceRecogStatusChanged(const bd_addr_t *bdAddr, int status) -{ - UNUSED(bdAddr); - UNUSED(status); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[VoiceRecogStatusChanged] status: %d", status); -} + static void HfpOperatorSelection(const bd_addr_t *bdAddr, unsigned char *name, unsigned int len) + { + UNUSED(bdAddr); + UNUSED(name); + UNUSED(len); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpOperatorSelection] name: %s, len: %d", name, len); + } -static void InbandRingtoneChanged(const bd_addr_t *bdAddr, int status) -{ - UNUSED(bdAddr); - UNUSED(status); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[InbandRingtoneChanged] status: %d", status); -} + static void HfpSubscriberNumber(const bd_addr_t *bdAddr, unsigned char *number, unsigned int len) + { + UNUSED(bdAddr); + UNUSED(number); + UNUSED(len); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[HfpSubscriberNumber] number: %s, len: %d", number, len); + } -static void CodecChanged(const bd_addr_t *bdAddr, int codec) -{ - UNUSED(bdAddr); - if (codec == HFP_HF_CODEC_ID_CVSD) { - g_call_codec = PCM; - } else if (codec == HFP_HF_CODEC_ID_MSBC) { - g_call_codec = mSBC; + static void VoiceRecogStatusChanged(const bd_addr_t *bdAddr, int status) + { + UNUSED(bdAddr); + UNUSED(status); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[VoiceRecogStatusChanged] status: %d", status); } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CodecChanged] codec: %d, call_codec: %d", codec, g_call_codec); -} + static void InbandRingtoneChanged(const bd_addr_t *bdAddr, int status) + { + UNUSED(bdAddr); + UNUSED(status); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[InbandRingtoneChanged] status: %d", status); + } -static void RegisterHfpHfCallbacks(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RegisterHfpHfCallbacks] start"); - int ret; - hfp_hf_callbacks_t callbacks = { - ConnStateChanged, - ScoStateChanged, - HfpBatteryChanged, - HfpSignalStrengthChanged, - HfpRegistStatusChanged, - HfpRoamingStatusChanged, - HfpOperatorSelection, - HfpSubscriberNumber, - VoiceRecogStatusChanged, - InbandRingtoneChanged, - VolumeChanged, - CallStateChanged, - DialErrorCode, - CodecChanged, - }; - - ret = hfp_hf_register_callbacks(&callbacks); - if (ret != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RegisterHfpHfCallbacks] ret = %d", ret); + static void CodecChanged(const bd_addr_t *bdAddr, int codec) + { + UNUSED(bdAddr); + if (codec == HFP_HF_CODEC_ID_CVSD) + { + g_call_codec = PCM; + } + else if (codec == HFP_HF_CODEC_ID_MSBC) + { + g_call_codec = mSBC; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CodecChanged] codec: %d, call_codec: %d", codec, g_call_codec); + } + + static void RegisterHfpHfCallbacks(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RegisterHfpHfCallbacks] start"); + int ret; + hfp_hf_callbacks_t callbacks = { + ConnStateChanged, + ScoStateChanged, + HfpBatteryChanged, + HfpSignalStrengthChanged, + HfpRegistStatusChanged, + HfpRoamingStatusChanged, + HfpOperatorSelection, + HfpSubscriberNumber, + VoiceRecogStatusChanged, + InbandRingtoneChanged, + VolumeChanged, + CallStateChanged, + DialErrorCode, + CodecChanged, + }; + + ret = hfp_hf_register_callbacks(&callbacks); + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RegisterHfpHfCallbacks] ret = %d", ret); + } } -} -void PhoneServiceInit(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PhoneServiceInit] start"); - g_scoFlag = HFP_SCO_STATE_DISCONNECTED; - AudioInit(); - InitMutex(); - CallLogCreatDir(); - if (GetCallLogFileSize() == OHOS_FAILURE) { // 如果不存在文件,创建新文件 - (void)ClearCallLogFile(); - } - (void)memset_s(g_bdAddr.addr, BD_ADDR_LEN, 0, BD_ADDR_LEN); - CallListInit(); - RegisterHfpHfCallbacks(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PhoneServiceInit] end"); -} + void PhoneServiceInit(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PhoneServiceInit] start"); + g_scoFlag = HFP_SCO_STATE_DISCONNECTED; + AudioInit(); + InitMutex(); + CallLogCreatDir(); + if (GetCallLogFileSize() == OHOS_FAILURE) + { // 如果不存在文件,创建新文件 + (void)ClearCallLogFile(); + } + (void)memset_s(g_bdAddr.addr, BD_ADDR_LEN, 0, BD_ADDR_LEN); + CallListInit(); + RegisterHfpHfCallbacks(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[PhoneServiceInit] end"); + } + + // 手表主动拨打电话 + int DialCall(unsigned char *number, unsigned char len) + { + int ret; + unsigned char *tel = NULL; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[DialCall] start"); + if (g_btConnState != PROFILE_STATE_CONNECTED) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DialCall] BT connStatus: 0x%X", g_btConnState); + return OHOS_FAILURE; + } -// 手表主动拨打电话 -int DialCall(unsigned char *number, unsigned char len) -{ - int ret; - unsigned char *tel = NULL; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[DialCall] start"); - if (g_btConnState != PROFILE_STATE_CONNECTED) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DialCall] BT connStatus: 0x%X", g_btConnState); - return OHOS_FAILURE; - } - - // 有通话时,不允许拨出电话 - if (g_currCallNum > 0 || len > MAX_PHONE_NUM || number == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DialCall] g_currCallNum = %d", g_currCallNum); - return OHOS_FAILURE; - } - - tel = (unsigned char *)malloc(len + 1); - if (tel == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DialCall] malloc tel error"); - return OHOS_FAILURE; - } - (void)memcpy_s(tel, len, number, len); - *(tel + len) = '\0'; - ret = hfp_hf_start_dial(&g_bdAddr, tel, len); - if (ret != ERRCODE_BT_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DialCall] hfp_hf_start_dial error ret %d", ret); + // 有通话时,不允许拨出电话 + if (g_currCallNum > 0 || len > MAX_PHONE_NUM || number == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DialCall] g_currCallNum = %d", g_currCallNum); + return OHOS_FAILURE; + } + + tel = (unsigned char *)malloc(len + 1); + if (tel == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DialCall] malloc tel error"); + return OHOS_FAILURE; + } + (void)memcpy_s(tel, len, number, len); + *(tel + len) = '\0'; + ret = hfp_hf_start_dial(&g_bdAddr, tel, len); + if (ret != ERRCODE_BT_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DialCall] hfp_hf_start_dial error ret %d", ret); + free(tel); + return OHOS_FAILURE; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[DialCall] success!"); free(tel); - return OHOS_FAILURE; + return OHOS_SUCCESS; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[DialCall] success!"); - free(tel); - return OHOS_SUCCESS; -} -// 手表主动接听 -int AcceptIncomingCall(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] start"); - int ret, i; - PhoneCallInfo *phoneCall = NULL; - PhoneCallInfo *tmp = g_callList; + // 手表主动接听 + int AcceptIncomingCall(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] start"); + int ret, i; + PhoneCallInfo *phoneCall = NULL; + PhoneCallInfo *tmp = g_callList; - if (g_btConnState != PROFILE_STATE_CONNECTED) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] BT connStatus: 0x%X", g_btConnState); - return OHOS_FAILURE; - } + if (g_btConnState != PROFILE_STATE_CONNECTED) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] BT connStatus: 0x%X", g_btConnState); + return OHOS_FAILURE; + } - for (i = 0; i < MULTI_CALL_MAX_NUME; i++) { - if (tmp->lastStatus == HFP_HF_CALL_STATE_INCOMING || tmp->lastStatus == HFP_HF_CALL_STATE_WAITING) { - phoneCall = tmp; - break; + for (i = 0; i < MULTI_CALL_MAX_NUME; i++) + { + if (tmp->lastStatus == HFP_HF_CALL_STATE_INCOMING || tmp->lastStatus == HFP_HF_CALL_STATE_WAITING) + { + phoneCall = tmp; + break; + } + tmp++; } - tmp++; - } - if (phoneCall == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] no incoming"); - return OHOS_FAILURE; - } + if (phoneCall == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] no incoming"); + return OHOS_FAILURE; + } - phoneCall->operate = OPERATE_WATCH_ACTIVE; + phoneCall->operate = OPERATE_WATCH_ACTIVE; - if (g_currCallNum > 1) { - ret = hfp_hf_accept_incoming_call(&g_bdAddr, HFP_HF_ACCEPT_CALL_ACTION_HOLD); // 正在通话,有人呼入,接听呼入电话,挂起当前通话 - } else { - ret = hfp_hf_accept_incoming_call(&g_bdAddr, HFP_HF_ACCEPT_CALL_ACTION_NONE); // 无人通话,有人呼入,接听呼入电话 - } - if (ret != ERRCODE_BT_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] hfp_hf_accept_incoming_call error ret = %d", ret); - phoneCall->operate = OPERATE_NO_OPE; - return OHOS_FAILURE; + if (g_currCallNum > 1) + { + ret = hfp_hf_accept_incoming_call(&g_bdAddr, HFP_HF_ACCEPT_CALL_ACTION_HOLD); // 正在通话,有人呼入,接听呼入电话,挂起当前通话 + } + else + { + ret = hfp_hf_accept_incoming_call(&g_bdAddr, HFP_HF_ACCEPT_CALL_ACTION_NONE); // 无人通话,有人呼入,接听呼入电话 + } + if (ret != ERRCODE_BT_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] hfp_hf_accept_incoming_call error ret = %d", ret); + phoneCall->operate = OPERATE_NO_OPE; + return OHOS_FAILURE; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] success!"); + return OHOS_SUCCESS; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] success!"); - return OHOS_SUCCESS; -} -// 手表拒接呼入来电,成功:0,失败:错误码 -int RejectIncomingCall(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RejectIncomingCall] start"); - int ret, i; - PhoneCallInfo *phoneCall = NULL; - PhoneCallInfo *tmp = g_callList; + // 手表拒接呼入来电,成功:0,失败:错误码 + int RejectIncomingCall(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RejectIncomingCall] start"); + int ret, i; + PhoneCallInfo *phoneCall = NULL; + PhoneCallInfo *tmp = g_callList; - if (g_btConnState != PROFILE_STATE_CONNECTED) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RejectIncomingCall] BT connStatus: 0x%X", g_btConnState); - return OHOS_FAILURE; - } + if (g_btConnState != PROFILE_STATE_CONNECTED) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RejectIncomingCall] BT connStatus: 0x%X", g_btConnState); + return OHOS_FAILURE; + } - for (i = 0; i < MULTI_CALL_MAX_NUME; i++) { - if (tmp->lastStatus == HFP_HF_CALL_STATE_INCOMING || tmp->lastStatus == HFP_HF_CALL_STATE_WAITING) { - phoneCall = tmp; + for (i = 0; i < MULTI_CALL_MAX_NUME; i++) + { + if (tmp->lastStatus == HFP_HF_CALL_STATE_INCOMING || tmp->lastStatus == HFP_HF_CALL_STATE_WAITING) + { + phoneCall = tmp; + } + tmp++; } - tmp++; - } - if (phoneCall == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] no incoming"); - return OHOS_SUCCESS; - } + if (phoneCall == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AcceptIncomingCall] no incoming"); + return OHOS_SUCCESS; + } - ret = hfp_hf_reject_incoming_call(&g_bdAddr); - if (ret != ERRCODE_BT_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RejectIncomingCall] hfp_hf_reject_incoming_call error ret = %d", ret); - return OHOS_FAILURE; + ret = hfp_hf_reject_incoming_call(&g_bdAddr); + if (ret != ERRCODE_BT_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[RejectIncomingCall] hfp_hf_reject_incoming_call error ret = %d", ret); + return OHOS_FAILURE; + } + g_finishOperate = OPERATE_WATCH_REJECT; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RejectIncomingCall] success!"); + return OHOS_SUCCESS; } - g_finishOperate = OPERATE_WATCH_REJECT; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[RejectIncomingCall] success!"); - return OHOS_SUCCESS; -} -// 手表结束通话 -int FinishCall(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FinishCall] start"); + // 手表结束通话 + int FinishCall(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FinishCall] start"); - if (g_btConnState != PROFILE_STATE_CONNECTED) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FinishCall] BT connStatus: 0x%X", g_btConnState); - return OHOS_FAILURE; - } - int ret = hfp_hf_finish_call(&g_bdAddr); - if (ret != ERRCODE_BT_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FinishCall] hfp_hf_finish_call error ret = %d", ret); - return OHOS_FAILURE; + if (g_btConnState != PROFILE_STATE_CONNECTED) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FinishCall] BT connStatus: 0x%X", g_btConnState); + return OHOS_FAILURE; + } + int ret = hfp_hf_finish_call(&g_bdAddr); + if (ret != ERRCODE_BT_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FinishCall] hfp_hf_finish_call error ret = %d", ret); + return OHOS_FAILURE; + } + g_finishOperate = OPERATE_WATCH_FINISH; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FinishCall] success!"); + return OHOS_SUCCESS; } - g_finishOperate = OPERATE_WATCH_FINISH; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FinishCall] success!"); - return OHOS_SUCCESS; -} -// 获取当前正在通话路数 -int GetCurrCallNum(void) -{ - return g_currCallNum; -} + // 获取当前正在通话路数 + int GetCurrCallNum(void) + { + return g_currCallNum; + } + + /** + * @brief 获取当前通话路数和对应的通话信息 + * + * @param callList 用来接收通话信息,需调用者分配空间,大小为MULTI_CALL_MAX_NUME * sizeof(PhoneCallInfo) + * @param listNum callList中PhoneCallInfo个数,大小为MULTI_CALL_MAX_NUME + * @param retNum 接收当前正在进行的通话路数 + * @return 返回值 成功返回0,失败返回错误码 + */ + int GetCallInfoInCallList(PhoneCallInfo callList[], int listNum, int *retNum) + { + int i, len; + PhoneCallInfo *tmp = g_callList; + PhoneCallInfo *tmp2 = callList; + + if (callList == NULL || listNum < MULTI_CALL_MAX_NUME) + { + *retNum = 0; + return OHOS_FAILURE; + } -/** - * @brief 获取当前通话路数和对应的通话信息 - * - * @param callList 用来接收通话信息,需调用者分配空间,大小为MULTI_CALL_MAX_NUME * sizeof(PhoneCallInfo) - * @param listNum callList中PhoneCallInfo个数,大小为MULTI_CALL_MAX_NUME - * @param retNum 接收当前正在进行的通话路数 - * @return 返回值 成功返回0,失败返回错误码 - */ -int GetCallInfoInCallList(PhoneCallInfo callList[], int listNum, int *retNum) -{ - int i, len; - PhoneCallInfo *tmp = g_callList; - PhoneCallInfo *tmp2 = callList; + if (g_currCallNum == 0) + { + *retNum = 0; + return OHOS_SUCCESS; + } - if (callList == NULL || listNum < MULTI_CALL_MAX_NUME) { - *retNum = 0; - return OHOS_FAILURE; - } + len = sizeof(PhoneCallInfo); + for (i = 0; i < MULTI_CALL_MAX_NUME; i++) + { + if (tmp->lastStatus == HFP_HF_CALL_STATE_FINISHED) + { + tmp++; + } + else + { + (void)memcpy_s(tmp2, len, tmp, len); + tmp++; + tmp2++; + } + } - if (g_currCallNum == 0) { - *retNum = 0; + *retNum = g_currCallNum; return OHOS_SUCCESS; } - len = sizeof(PhoneCallInfo); - for (i = 0; i < MULTI_CALL_MAX_NUME; i++) { - if (tmp->lastStatus == HFP_HF_CALL_STATE_FINISHED) { - tmp++; - } else { - (void)memcpy_s(tmp2, len, tmp, len); - tmp++; - tmp2++; + // 获取当前通话音量大小 (0 - 15) + // hfp音量范围 0-15, media 音量范围 0-100 + unsigned char GetCallCurrVolume(void) + { + int volume; + int minVolume; + int maxVolume; + unsigned char hfpVolume; + + volume = PhoneAudioGetVolume(); + minVolume = PhoneAudioGetMinVolume(); + maxVolume = PhoneAudioGetMaxVolume(); + hfpVolume = (unsigned char)((volume * CALL_VOLUME_MAX) / (maxVolume - minVolume)); // 转换 + + if (volume != 0 && hfpVolume == 0) + { + hfpVolume = 1; } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[GetCallCurrVolume] volume = %d, minVolume = %d, maxVolume = %d, hfpVolume = %d", + volume, minVolume, maxVolume, hfpVolume); + return hfpVolume; } - *retNum = g_currCallNum; - return OHOS_SUCCESS; -} + void SetSpeakerVolume(unsigned char hfpVolume) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] start, hfpVolume = %d", hfpVolume); + int ret, minVolume, maxVolume, volume; -// 获取当前通话音量大小 (0 - 15) -// hfp音量范围 0-15, media 音量范围 0-100 -unsigned char GetCallCurrVolume(void) -{ - int volume; - int minVolume; - int maxVolume; - unsigned char hfpVolume; - - volume = PhoneAudioGetVolume(); - minVolume = PhoneAudioGetMinVolume(); - maxVolume = PhoneAudioGetMaxVolume(); - hfpVolume = (unsigned char)((volume * CALL_VOLUME_MAX) / (maxVolume - minVolume)); // 转换 - - if (volume != 0 && hfpVolume == 0) { - hfpVolume = 1; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[GetCallCurrVolume] volume = %d, minVolume = %d, maxVolume = %d, hfpVolume = %d", - volume, minVolume, maxVolume, hfpVolume); - return hfpVolume; -} + minVolume = PhoneAudioGetMinVolume(); + maxVolume = PhoneAudioGetMaxVolume(); + volume = hfpVolume * (maxVolume - minVolume) / CALL_VOLUME_MAX; // 转换 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] minVolume = %d, maxVolume = %d, volume = %d", + minVolume, maxVolume, volume); -void SetSpeakerVolume(unsigned char hfpVolume) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] start, hfpVolume = %d", hfpVolume); - int ret, minVolume, maxVolume, volume; - - minVolume = PhoneAudioGetMinVolume(); - maxVolume = PhoneAudioGetMaxVolume(); - volume = hfpVolume * (maxVolume - minVolume) / CALL_VOLUME_MAX; // 转换 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] minVolume = %d, maxVolume = %d, volume = %d", - minVolume, maxVolume, volume); - - ret = PhoneAudioSetVolume(volume); - if (ret != true) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] PhoneAudioSetVolume ret = %d", ret); - return; - } + ret = PhoneAudioSetVolume(volume); + if (ret != true) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] PhoneAudioSetVolume ret = %d", ret); + return; + } + + ret = hfp_hf_set_volume(&g_bdAddr, HFP_VOLUME_SPEAKER, hfpVolume); + if (ret != ERRCODE_BT_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] set_volume fail ret = %d, hfpVolume = %d", + ret, hfpVolume); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] success!"); - ret = hfp_hf_set_volume(&g_bdAddr, HFP_VOLUME_SPEAKER, hfpVolume); - if (ret != ERRCODE_BT_SUCCESS) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] set_volume fail ret = %d, hfpVolume = %d", - ret, hfpVolume); return; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SetSpeakerVolume] success!"); - - return; -} -// 设置通话speaker静音 -bool SetSpeakerMute(bool isMute) -{ - return PhoneAudioSetSpeakerMute(isMute); -} + // 设置通话speaker静音 + bool SetSpeakerMute(bool isMute) + { + return PhoneAudioSetSpeakerMute(isMute); + } -// 设置通话mic静音/取消静音 -bool SetMicMute(bool isMute) -{ - return PhoneAudioSetMicMute(isMute); -} + // 设置通话mic静音/取消静音 + bool SetMicMute(bool isMute) + { + return PhoneAudioSetMicMute(isMute); + } -// 获取SCO的连接状态 -int GetScoConnectState(void) -{ - return g_scoFlag; -} + // 获取SCO的连接状态 + int GetScoConnectState(void) + { + return g_scoFlag; + } -// 通话转移到手表 -int TransCallToWatch(void) -{ - int ret; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[TransCallToWatch] start"); + // 通话转移到手表 + int TransCallToWatch(void) + { + int ret; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[TransCallToWatch] start"); - if (g_btConnState != PROFILE_STATE_CONNECTED) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[TransCallToWatch] BT connStatus: 0x%X", g_btConnState); - return OHOS_FAILURE; - } + if (g_btConnState != PROFILE_STATE_CONNECTED) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[TransCallToWatch] BT connStatus: 0x%X", g_btConnState); + return OHOS_FAILURE; + } - ret = GetScoConnectState(); - if (ret == HFP_SCO_STATE_CONNECTED || ret == HFP_SCO_STATE_CONNECTING) { - return OHOS_SUCCESS; - } else { - ret = hfp_hf_connect_sco(&g_bdAddr); - if (ret != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[TransCallToWatch] ret = %d", ret); + ret = GetScoConnectState(); + if (ret == HFP_SCO_STATE_CONNECTED || ret == HFP_SCO_STATE_CONNECTING) + { + return OHOS_SUCCESS; + } + else + { + ret = hfp_hf_connect_sco(&g_bdAddr); + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[TransCallToWatch] ret = %d", ret); + } + return ret; } - return ret; } -} -// 通话转移到手机 -int TransCallToMobilePhone(void) -{ - int ret; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[TransCallToMobilePhone] start"); + // 通话转移到手机 + int TransCallToMobilePhone(void) + { + int ret; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[TransCallToMobilePhone] start"); - if (g_btConnState != PROFILE_STATE_CONNECTED) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[TransCallToMobilePhone] BT connStatus: 0x%X", g_btConnState); - return OHOS_FAILURE; - } + if (g_btConnState != PROFILE_STATE_CONNECTED) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[TransCallToMobilePhone] BT connStatus: 0x%X", g_btConnState); + return OHOS_FAILURE; + } - ret = GetScoConnectState(); - if (ret == HFP_SCO_STATE_DISCONNECTED || ret == HFP_SCO_STATE_DISCONNECTING) { - return OHOS_SUCCESS; - } else { - ret = hfp_hf_disconnect_sco(&g_bdAddr); - if (ret != 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[TransCallToMobilePhone] ret = %d", ret); + ret = GetScoConnectState(); + if (ret == HFP_SCO_STATE_DISCONNECTED || ret == HFP_SCO_STATE_DISCONNECTING) + { + return OHOS_SUCCESS; + } + else + { + ret = hfp_hf_disconnect_sco(&g_bdAddr); + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[TransCallToMobilePhone] ret = %d", ret); + } + return ret; } - return ret; } -} #ifdef __cplusplus } diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index 5c6311f0f..e72074298 100755 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -216,6 +216,7 @@ void MsgCenterNotifyAlarmProc(const Topic topic, Request* req) AlarmPopUpPresenter::GetInstance()->DelayAlarmRing(); } } +#ifdef FD230 #ifdef SUPPORT_CHARGER_PLUG_DETECTION_NOTIFICATION void MsgCenterNotifyChargePlugProc(const Topic topic, Request* req) { @@ -305,6 +306,7 @@ void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req) // } } +#endif #endif void MsgCenterNotifyNextDayProc(const Topic topic, Request* req) { @@ -763,6 +765,7 @@ static msg_center_notify_table_t g_msg_center_notify_table[] = { {TOPIC_EVENT_HFP_WATCH_TO_PHONE, MsgCenterNotifyHfpPhoneProc}, {TOPIC_EVENT_HFP_WATCH_ACTIVE, MsgCenterNotifyHfpWatchProc}, {TOPIC_EVENT_HFP_PHONE_TO_WATCH, MsgCenterNotifyHfpWatchProc}, +#ifdef FD230 #ifdef SUPPORT_CHARGER_PLUG_DETECTION_NOTIFICATION {TOPIC_EVENT_CHARGE_PLUG, MsgCenterNotifyChargePlugProc}, {TOPIC_EVENT_CHARGE_UNPLUG, MsgCenterNotifyChargeUnPlugProc}, @@ -795,6 +798,7 @@ static msg_center_notify_table_t g_msg_center_notify_table[] = { #endif {TOPIC_EVENT_FIND_WATCH,MsgCenterNotifyFindWatchProc}, {TOPIC_EVENT_CANCEL_FIND_WATCH,MsgCenterNotifyCanCelFindWatchProc}, +#endif }; static msg_center_notify_table_t *MsgCenterGetNotifyTblCb(uint8_t idx) diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp index 21ea0dd73..d51939af0 100755 --- a/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp @@ -250,6 +250,7 @@ void DisableCallTimer(CallTimerType type) osStatus_t ret; switch (type) { case NOTIFY_PHONE_CALLING_DISPLAY: + #ifdef FD230 if (g_callDuration != NULL) { info.callDurTime=get_g_callTimes(); g_callTimesclean(); @@ -262,6 +263,7 @@ void DisableCallTimer(CallTimerType type) g_callDuration = NULL; } break; + #endif case NOTIFY_PHONE_CURTIME_DISPLAY: if (g_callCurrentTime != NULL) { ret = osTimerDelete(g_callCurrentTime); diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index c19324cc9..cbfc288f6 100755 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -136,6 +136,7 @@ target = { 'SUPPORT_AT_CUSTOMUTILS', 'SUPPORT_ALIPAY_SEC', 'SUPPORT_BLE_SERVICE', + 'FD230', 'SUPPORT_HID_SERVICE' ], 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", @@ -176,7 +177,7 @@ target = { 'dsp_version': 'max', 'packet': True, 'image_analysis': False, - # 'fs_image_path':'evb4', + #'fs_image_path':'evb4', 'fs_image_path':'fd230', 'fs_image': True }, diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_ALARM.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_ALARM.bin index 61b893e48..00a75bf0c 100644 Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_ALARM.bin and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_ALARM.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_CALLER_IMAGE.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_CALLER_IMAGE.bin index c711f6658..fe389b546 100644 Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_CALLER_IMAGE.bin and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_CALLER_IMAGE.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_COMPASS_IMAGE.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_COMPASS_IMAGE.bin index 381dbe9d6..d1fa4b53c 100644 Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_COMPASS_IMAGE.bin and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_COMPASS_IMAGE.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_SETTING.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_SETTING.bin index bf4e8395a..c96716ae4 100644 Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_SETTING.bin and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_SETTING.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_SPO2.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_SPO2.bin index cc9c66482..8177b458e 100644 Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_SPO2.bin and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/APPLIST_SPO2.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_ACTIVITY.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_ACTIVITY.bin new file mode 100644 index 000000000..45a459dac Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_ACTIVITY.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_ADD.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_ADD.bin new file mode 100644 index 000000000..f308fc020 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_ADD.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_COMPASS.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_COMPASS.bin new file mode 100644 index 000000000..e253bbe46 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_COMPASS.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_DEL.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_DEL.bin new file mode 100644 index 000000000..0c0adcbd8 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_DEL.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_HEART.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_HEART.bin new file mode 100644 index 000000000..a19125d62 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_HEART.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_PLAYER.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_PLAYER.bin new file mode 100644 index 000000000..6b0985224 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/CARD_PLAYER.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/DIAL_CLOCK.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/DIAL_CLOCK.bin new file mode 100644 index 000000000..744141270 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/DIAL_CLOCK.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/NEW_DEVICE.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/NEW_DEVICE.bin index b3180e934..437402ac4 100644 Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/NEW_DEVICE.bin and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/NEW_DEVICE.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SETTING_NEXT.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SETTING_NEXT.bin index 1a68bf4f1..fccee00b9 100644 Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SETTING_NEXT.bin and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SETTING_NEXT.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SETTTING_DESKTOP.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SETTTING_DESKTOP.bin new file mode 100644 index 000000000..332ebc054 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SETTTING_DESKTOP.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SET_DESKTOP_BG.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SET_DESKTOP_BG.bin new file mode 100644 index 000000000..fafbd1b50 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SET_DESKTOP_BG.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SET_DESKTOP_HEXAGONS.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SET_DESKTOP_HEXAGONS.bin new file mode 100644 index 000000000..6c9477666 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SET_DESKTOP_HEXAGONS.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SET_DESKTOP_LIST.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SET_DESKTOP_LIST.bin new file mode 100644 index 000000000..14547a23b Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/SET_DESKTOP_LIST.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/backGround.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/backGround.bin new file mode 100644 index 000000000..d17f2ab13 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/backGround.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/hexagons.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/hexagons.bin new file mode 100644 index 000000000..f3dc2e88b Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/hexagons.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/kaleidoscope.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/kaleidoscope.bin new file mode 100644 index 000000000..eac0b9066 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/kaleidoscope.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/planet.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/planet.bin new file mode 100644 index 000000000..9a6e5ba36 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/planet.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/rabbit454.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/rabbit454.bin new file mode 100644 index 000000000..f98a0c1bf Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/rabbit454.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/rainbow.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/rainbow.bin new file mode 100644 index 000000000..3419bad22 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/rainbow.bin differ