From: luozheng <1732036298@qq.com> Date: Wed, 10 Apr 2024 13:33:59 +0000 (+0800) Subject: 添加手电筒功能 X-Git-Tag: release_V1.2.70_20241020_135402~1189^2~22 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=57a0188aabdc46501c715742c309e9e8f331e1a3;p=mirrors%2FFD230.git 添加手电筒功能 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 40c61eec2..8dabb94d7 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -310,6 +310,11 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dnotdisturb/src/DnotDisturbView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dnotdisturb/src/DnotDisturbModel.cpp + #手电筒 + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/flashlight/src/FlashlightPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/flashlight/src/FlashlightView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/flashlight/src/FlashlightModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/language/LanguageInit.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/config/src/ConfigModel.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 814158348..0d44df718 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -59,7 +59,7 @@ typedef enum : uint16_t VIEW_MAIN_STOPWATCH, // 秒表 VIEW_MAIN_COUNTDOWN, // 计时器 VIEW_DNOTDISTURB, // 勿扰模式 - VIEW_FLASHLIGH, // 手电筒 + VIEW_FLASHLIGHT, // 手电筒 /* ----------------------------------- 录音 ----------------------------------- */ VIEW_RECORD, /* ---------------------------------- 界面 ---------------------------------- */ diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index f1affadaa..b429f9a0e 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -54,6 +54,7 @@ namespace OHOS void InitMainStopWatchSlice(void); void InitMainCountDownSlice(void); void InitDnotDisturbSlice(void); + void InitFlashlightSlice(void); /* --------------------------------界面------------------------------------ */ void InitRotateSlice(void); void InitBloodSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index cb78aa0cf..3cbaefdcf 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -154,6 +154,9 @@ #include "dnotdisturb/include/DnotDisturbPresenter.h" #include "dnotdisturb/include/DnotDisturbView.h" + +#include "flashlight/include/FlashlightPresenter.h" +#include "flashlight/include/FlashlightView.h" /* -------------------------------------------------------------------------- */ #include "traing/include/TraingView.h" #include "traing/include/TraingPresenter.h" @@ -287,6 +290,8 @@ namespace OHOS {VIEW_MAIN_STOPWATCH, &NativeLauncher::InitMainStopWatchSlice}, {VIEW_MAIN_COUNTDOWN, &NativeLauncher::InitMainCountDownSlice}, {VIEW_DNOTDISTURB, &NativeLauncher::InitDnotDisturbSlice}, + {VIEW_FLASHLIGHT, &NativeLauncher::InitFlashlightSlice}, + {VIEW_MESSAGE, &NativeLauncher::InitMessageSlice}, {VIEW_ROTATE, &NativeLauncher::InitRotateSlice}, @@ -1169,6 +1174,18 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_DNOTDISTURB, dnotdisturb); } + /*手电筒*/ + void NativeLauncher::InitFlashlightSlice(void) + { + SliceProxy *flashlight = new AbilitySliceProxy; + if (flashlight == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "flashlight"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_FLASHLIGHT, flashlight); + } + /* -------------------------------------------------------------------------- */ void NativeLauncher::InitSetDesktopSlice(void) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightModel.h b/code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightModel.h new file mode 100644 index 000000000..d96c72e3a --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightModel.h @@ -0,0 +1,39 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-10 18:13:01 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-10 20:03:08 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightModel.h + */ + +#include +#ifndef FLASHLIGH_MODEL_H +#define FLASHLIGH_MODEL_H + +namespace OHOS +{ + class FlashlightModel + { + public: + static FlashlightModel &GetInstance(void); + void ToggleBrightness(); + void UpdateScreenColor(); + int64_t GetCurrentBrightness(void); + + private: + FlashlightModel(); + FlashlightModel(const FlashlightModel &) = delete; + FlashlightModel &operator=(const FlashlightModel &) = delete; + virtual ~FlashlightModel(); + + enum Brightness : int64_t + { + Low = 0xff808080, + Medium = 0xffbfbfbf, + High = 0xffffffff, + }; + int64_t currentBrightness = Brightness::Low; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightPresenter.h new file mode 100644 index 000000000..440250ddd --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightPresenter.h @@ -0,0 +1,44 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-10 17:32:31 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-10 19:36:50 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/flashligh/include/FlashlightPresenter.h + */ + +#ifndef FLASHLIGHT_PRESENTER_H +#define FLASHLIGHT_PRESENTER_H + +#include "Presenter.h" +#include "View.h" +#include "flashlight/include/FlashlightView.h" +namespace OHOS +{ + + class FlashlightView; + class FlashlightPresenter : public Presenter, + public UIView::OnClickListener, + public RootView::OnKeyActListener, + public UIView::OnDragListener + { + public: + FlashlightPresenter(); + virtual ~FlashlightPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static FlashlightPresenter *GetInstance(); + + + private: + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightView.h b/code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightView.h new file mode 100644 index 000000000..29d62fb12 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightView.h @@ -0,0 +1,41 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-10 17:32:02 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-10 21:17:05 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/flashligh/include/FlashlightView.h + */ + +#ifndef FLASHLIGH_VIEW_H +#define FLASHLIGH_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_scroll_view.h" +#include "components/ui_image_view.h" +namespace OHOS +{ + class FlashlightPresenter; + class FlashlightView : public View + { + + public: + FlashlightView(); + virtual ~FlashlightView(); + static FlashlightView *GetInstance(void); + void SetTheGroupViewColor(int64_t colorValue); + UIScrollView *GetGroupView(); + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void FlashlightViewInit(void); + void ClearAll(void); + UIScrollView *group{nullptr}; + UIImageView *FlashlightVector{nullptr}; + UIImageView *LineImage{nullptr}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightModel.cpp new file mode 100644 index 000000000..797d7bb5a --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightModel.cpp @@ -0,0 +1,53 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-10 18:13:11 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-10 19:34:54 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightModel.cpp + */ +#include "flashlight/include/FlashlightModel.h" +#include "flashlight/include/FlashlightView.h" + +namespace OHOS +{ + FlashlightModel::FlashlightModel() {} + + FlashlightModel::~FlashlightModel() {} + + FlashlightModel &FlashlightModel::GetInstance() + { + static FlashlightModel instance; + return instance; + } + + /*切换屏幕亮度*/ + void FlashlightModel::ToggleBrightness() + { + switch (currentBrightness) + { + case Brightness::Low: + currentBrightness = Brightness::Medium; // 更新屏幕颜色为中亮度 + + break; + case Brightness::Medium: + currentBrightness = Brightness::High; // 更新屏幕颜色为高亮度 + + break; + case Brightness::High: + currentBrightness = Brightness::Low; // 关闭手电筒(屏幕恢复正常显示) + break; + } + UpdateScreenColor(); + } + + // 基于当前亮度状态currentBrightness,更新屏幕颜色 + void FlashlightModel::UpdateScreenColor() + { + FlashlightView::GetInstance()->SetTheGroupViewColor(currentBrightness); + } + + int64_t FlashlightModel::GetCurrentBrightness(void) + { + return currentBrightness; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightPresenter.cpp new file mode 100644 index 000000000..b52a73444 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightPresenter.cpp @@ -0,0 +1,100 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-10 17:32:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-10 21:30:01 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/flashligh/src/FlashlightPresenter.cpp + */ + +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "flashlight/include/FlashlightPresenter.h" +#include "flashlight/include/FlashlightModel.h" +#include "common/key_code.h" +#include + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static FlashlightPresenter *g_pFlashlightPresenter = nullptr; + + FlashlightPresenter::FlashlightPresenter() + { + g_pFlashlightPresenter = this; + } + + FlashlightPresenter::~FlashlightPresenter() + { + g_pFlashlightPresenter = nullptr; + } + + FlashlightPresenter *FlashlightPresenter::GetInstance() + { + return g_pFlashlightPresenter; + } + + void FlashlightPresenter::OnStart() + { + Presenter::OnStart(); + } + + void FlashlightPresenter::OnPause(void) + { + Presenter::OnPause(); + } + + void FlashlightPresenter::OnResume(void) + { + Presenter::OnResume(); + } + + void FlashlightPresenter::OnStop(void) + { + Presenter::OnStop(); + } + + bool FlashlightPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } + + bool FlashlightPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + return true; + } + + bool FlashlightPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + if (&view == FlashlightView::GetInstance()->GetGroupView()) + { + FlashlightModel::GetInstance().ToggleBrightness(); + } + return true; + } + + // 增加按键事件 + bool FlashlightPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnKeyAct"); + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + return true; + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightView.cpp b/code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightView.cpp new file mode 100644 index 000000000..11eccc4e7 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightView.cpp @@ -0,0 +1,153 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-10 17:32:08 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-10 21:22:43 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/flashligh/src/FlashlightView.cpp + */ +#include "flashlight/include/FlashlightView.h" +#include "flashlight/include/FlashlightPresenter.h" +#include "flashlight/include/FlashlightModel.h" +#include "wearable_log.h" + +namespace OHOS +{ + + static FlashlightView *g_pFlashlightView{nullptr}; + + FlashlightView::FlashlightView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightView::FlashlightView"); + g_pFlashlightView = this; + } + + FlashlightView::~FlashlightView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightView::~FlashlightView"); + ClearAll(); + g_pFlashlightView = nullptr; + } + + FlashlightView *FlashlightView::GetInstance() + { + return g_pFlashlightView; + } + + void FlashlightView::ClearAll(void) + { + group->RemoveAll(); + if (group != nullptr) + { + delete FlashlightVector; + FlashlightVector = nullptr; + + delete LineImage; + LineImage = nullptr; + + delete group; + group = nullptr; + } + } + + void FlashlightView::FlashlightViewInit(void) + { + if (group == nullptr) + { + group = new UIScrollView(); + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightView::group is nullptr"); + return; + } + group->SetPosition(0, 0, 466, 466); + group->SetStyle(STYLE_BACKGROUND_COLOR, FlashlightModel::GetInstance().GetCurrentBrightness()); + group->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + UIView::OnClickListener *listener1 = static_cast(FlashlightPresenter::GetInstance()); + group->SetOnClickListener(listener1); + UIView::OnDragListener *listener2 = static_cast(FlashlightPresenter::GetInstance()); + group->SetOnDragListener(listener2); + /* -------------------------------------------------------------------------- */ + FlashlightVector = new UIImageView(); + if (FlashlightVector == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightView::FlashlightVector is nullptr"); + return; + } + FlashlightVector->SetPosition(212, 191, 100, 100); + const char *imagesPath = "/user/res/flashlight/Flashlight.bin"; + FlashlightVector->SetSrc(imagesPath); + /* -------------------------------------------------------------------------- */ + LineImage = new UIImageView(); + if (LineImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightView::LineImage is nullptr"); + return; + } + LineImage->SetPosition(193, 430, 80, 8); + LineImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xffdddddd); + LineImage->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + } + } + + UIScrollView *FlashlightView::GetGroupView() + { + if (group != nullptr) + { + return group; + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightView::group is new fail!!"); + return nullptr; + } + } + + void FlashlightView::SetTheGroupViewColor(int64_t colorValue) + { + if (group != nullptr) + { + group->SetStyle(STYLE_BACKGROUND_COLOR, colorValue); + group->Invalidate(); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightView::group is new fail!!"); + return; + } + } + + void FlashlightView::OnStart() + { + View::OnStart(); + FlashlightViewInit(); + + // 增加按键监听 + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::FlashlightPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + } + + void FlashlightView::OnSetUpView() + { + + View::OnSetUpView(); + group->Add(FlashlightVector); + group->Add(LineImage); + RootView::GetInstance()->Add(group); + Draw(); + } + + void FlashlightView::OnTearDownView() + { + View::OnTearDownView(); + return; + } + + void FlashlightView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + RootView::GetInstance()->ClearOnKeyActListener(); + return; + } +} \ 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 8fd7d41c1..b2574e17d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp @@ -36,7 +36,7 @@ namespace OHOS map g_jumpView = { {DROPDOWN_CLICK_SETTING, VIEW_SETTING}, // 设置 - //{DROPDOWN_CLICK_LIGHTING, VIEW_FLASHLIGH}, // 手电筒 + {DROPDOWN_CLICK_LIGHTING, VIEW_FLASHLIGHT}, // 手电筒 {DROPDOWN_CLICK_DNOTDISTURB, VIEW_DNOTDISTURB}, // 勿扰 {DROPDOWN_CLICK_SAVEELE, VIEW_SAVEELE}, // 省电模式 {DROPDOWN_CLICK_FINDMYPHONE, VIEW_FIND_PHONE}, // 查找手机 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/flashlight/Flashlight.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/flashlight/Flashlight.bin new file mode 100644 index 000000000..92982c34a Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/flashlight/Flashlight.bin differ