#勿扰
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dnotdisturb/src/DnotDisturbPresenter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dnotdisturb/src/DnotDisturbView.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dnotdisturb/src/DnotDisturbModel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/language/LanguageInit.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/config/src/ConfigModel.cpp
VIEW_MAIN_STOPWATCH, // 秒表
VIEW_MAIN_COUNTDOWN, // 计时器
VIEW_DNOTDISTURB, // 勿扰模式
+ VIEW_FLASHLIGH, // 手电筒
/* ----------------------------------- 录音 ----------------------------------- */
VIEW_RECORD,
/* ---------------------------------- 界面 ---------------------------------- */
--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-10 16:38:44
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-04-10 16:44:52
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/include/DnotDisturbModel.h
+ */
+#ifndef DNOTDISTURB_MODEL_H
+#define DNOTDISTURB_MODEL_H
+
+namespace OHOS
+{
+ class DnotDisturbModel
+ {
+ public:
+ static DnotDisturbModel &GetInstance(void);
+ void SetDoNotDisturbModeEnabled(bool enabled);
+ bool GetDoNotDisturbModeEnabled() const;
+
+ private:
+ DnotDisturbModel();
+ DnotDisturbModel(const DnotDisturbModel &) = delete;
+ DnotDisturbModel &operator=(const DnotDisturbModel &) = delete;
+ virtual ~DnotDisturbModel();
+
+ bool isDoNotDisturbModeEnabled = false; // 默认勿扰模式未开启
+ };
+}
+
+#endif
\ No newline at end of file
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-04-10 11:58:32
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-10 15:22:51
+ * @LastEditTime: 2024-04-10 16:26:47
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/include/DnotDisturbPresenter.h
*/
class DnotDisturbPresenter : public Presenter<DnotDisturbView>,
public UIView::OnClickListener,
public RootView::OnKeyActListener,
+ public ModelListenerSample,
public UIView::OnDragListener
{
public:
void OnStop() override;
static DnotDisturbPresenter *GetInstance();
+ virtual void Notify() override;
private:
bool OnClick(UIView &view, const ClickEvent &event) override;
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-04-10 11:58:15
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-10 15:06:49
+ * @LastEditTime: 2024-04-10 16:30:58
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/include/DnotDisturbView.h
*/
#ifndef DNOTDISTURB_VIEW_H
#include "components/ui_label_ext.h"
#include "components/ui_image_view.h"
#include "components/ui_label_button_ext.h"
+#include "ModelListenerSample.h"
+#include "iostream"
namespace OHOS
{
class DnotDisturbPresenter;
static DnotDisturbView *GetInstance(void);
UILabelButtonExt *GetButtonOn(void);
UILabelButtonExt *GetButtonOff(void);
-
+ void UpdataTime();
+
void OnStart() override;
void OnSetUpView() override;
void OnTearDownView() override;
void ClearAll(void);
UIScrollView *scrollView = nullptr;
UILabelExt *showTimeLabel{nullptr}; // 显示系统时间的标签
+ UIImageView *background{nullptr};
UIImageView *DnotDisturbImage{nullptr};
UILabelExt *AttentionLabel{nullptr};
- UILabelButtonExt *ButtonOn;
+ UILabelButtonExt *ButtonOn;
UILabelButtonExt *ButtonOff;
};
}
--- /dev/null
+#include "dnotdisturb/include/DnotDisturbModel.h"
+
+namespace OHOS
+{
+
+ DnotDisturbModel::DnotDisturbModel() {}
+
+ DnotDisturbModel::~DnotDisturbModel() {}
+
+ DnotDisturbModel &DnotDisturbModel::GetInstance()
+ {
+ static DnotDisturbModel instance;
+ return instance;
+ }
+
+ void DnotDisturbModel::SetDoNotDisturbModeEnabled(bool enabled)
+ {
+ isDoNotDisturbModeEnabled = enabled;
+ }
+
+ bool DnotDisturbModel::GetDoNotDisturbModeEnabled() const
+ {
+ return isDoNotDisturbModeEnabled;
+ }
+}
\ No newline at end of file
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-04-10 11:58:37
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-10 15:29:22
+ * @LastEditTime: 2024-04-10 16:45:23
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbPresenter.cpp
*/
#include "AppViewIDs.h"
#include "NativeAbility.h"
#include "dnotdisturb/include/DnotDisturbView.h"
#include "dnotdisturb/include/DnotDisturbPresenter.h"
+#include "dnotdisturb/include/DnotDisturbModel.h"
#include "common/key_code.h"
#include <custom_utils.h>
namespace OHOS
}
if (&view == p_DnotDisturbView->GetButtonOn())
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " DnotDisturb enable!!");
+ DnotDisturbModel::GetInstance().SetDoNotDisturbModeEnabled(true);
+ uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
+ NativeAbility::GetInstance().ChangeSlice(preSlice);
}
else if (&view == p_DnotDisturbView->GetButtonOff())
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " DnotDisturb disable!!");
+ DnotDisturbModel::GetInstance().SetDoNotDisturbModeEnabled(false);
+ uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
+ NativeAbility::GetInstance().ChangeSlice(preSlice);
}
return true;
}
}
return true;
}
+
+ void DnotDisturbPresenter::Notify()
+ {
+ DnotDisturbView::GetInstance()->UpdataTime();
+ }
}
\ No newline at end of file
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-04-10 11:58:21
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-10 15:21:47
+ * @LastEditTime: 2024-04-10 17:16:44
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbView.cpp
*/
#include "dnotdisturb/include/DnotDisturbView.h"
if (scrollView != nullptr)
{
scrollView->RemoveAll();
+
if (showTimeLabel != nullptr)
{
delete showTimeLabel;
showTimeLabel = nullptr;
}
+ if (background != nullptr)
+ {
+ delete background;
+ background = nullptr;
+ }
+
if (DnotDisturbImage != nullptr)
{
delete DnotDisturbImage;
if (scrollView == nullptr)
{
scrollView = new UIScrollView();
- if (scrollView != nullptr)
+ if (scrollView == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::scrollView new fail!!");
return;
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::showTimeLabel new fail!!");
return;
}
- showTimeLabel->SetPosition(83, 52, 300, 40);
- showTimeLabel->SetStyle(STYLE_TEXT_FONT, 30);
- showTimeLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
- showTimeLabel->SetText("23:00");
+ showTimeLabel->SetPosition(83, 52, 300, 46);
+ showTimeLabel->SetStyle(STYLE_TEXT_FONT, 40);
+ showTimeLabel->SetStyle(STYLE_LINE_HEIGHT, 46);
showTimeLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
showTimeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
showTimeLabel->SetRollSpeed(40);
- showTimeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ showTimeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40);
+ /* -------------------------------------------------------------------------- */
+ background = new UIImageView();
+ if (background == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::background new fail!!");
+ return;
+ }
+ background->SetPosition(186, 116);
+ ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, background, DROPDOWN_ICONELLIPSEPURPLE);
/* -------------------------------------------------------------------------- */
DnotDisturbImage = new UIImageView();
if (DnotDisturbImage == nullptr)
DnotDisturbImage->SetPosition(186, 116, 94, 94);
DnotDisturbImage->SetAutoEnable(false);
DnotDisturbImage->SetResizeMode(UIImageView::CENTER);
- DnotDisturbImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xff8e20e2);
ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, DnotDisturbImage, DROPDOWN_DNOTDISTURB);
/* -------------------------------------------------------------------------- */
AttentionLabel = new UILabelExt();
AttentionLabel->SetStyle(STYLE_TEXT_FONT, 30);
AttentionLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
AttentionLabel->SetText("开启勿扰模式,手表将不会发出震动与铃声,是否开启");
- AttentionLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ AttentionLabel->SetLineBreakMode(UILabelExt::LINE_BREAK_WRAP);
AttentionLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));
AttentionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
AttentionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::ButtonOn new fail!!");
return;
}
- ButtonOn->SetPosition(111, 320, 120, 120);
+ ButtonOn->SetPosition(256, 320, 120, 120);
ButtonOn->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
ButtonOn->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
- const char *ButtonOnImgSrc = "/user/res/SYSTEM_CheckOff.bin";
+ const char *ButtonOnImgSrc = "/user/res/SYSTEM_CheckOn.bin";
ButtonOn->SetImageSrc(ButtonOnImgSrc, ButtonOnImgSrc);
ButtonOn->SetImagePosition(10, 10);
ButtonOn->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED);
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::ButtonOff new fail!!");
return;
}
- ButtonOff->SetPosition(256, 320, 120, 120);
+ ButtonOff->SetPosition(111, 320, 120, 120);
ButtonOff->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
ButtonOff->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
- const char *ButtonOffImgSrc = "/user/res/SYSTEM_CheckOn.bin";
+ const char *ButtonOffImgSrc = "/user/res/SYSTEM_CheckOff.bin";
ButtonOff->SetImageSrc(ButtonOffImgSrc, ButtonOffImgSrc);
ButtonOff->SetImagePosition(10, 10);
ButtonOff->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED);
}
}
+ /*更新当前时间*/
+ void DnotDisturbView::UpdataTime()
+ {
+ // 获取当前时间
+ struct tm pTM;
+ time_t seconds;
+ time(&seconds);
+ localtime_r(&seconds, &pTM);
+
+ // 解析时间
+ int hour = pTM.tm_hour;
+ int minute = pTM.tm_min;
+
+ // 将时间和日期转换为字符串
+ std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute);
+ showTimeLabel->SetText(stringtime.c_str());
+ }
+
UILabelButtonExt *DnotDisturbView::GetButtonOn(void)
{
return ButtonOn;
{
View<DnotDisturbPresenter>::OnStart();
DnotDisturbViewInit();
+
+ // 增加按键监听
+ RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::DnotDisturbPresenter::GetInstance();
+ RootView::GetInstance()->SetOnKeyActListener(keyactListener);
}
void DnotDisturbView::OnSetUpView()
{
View<DnotDisturbPresenter>::OnSetUpView();
scrollView->Add(showTimeLabel);
+ scrollView->Add(background);
scrollView->Add(DnotDisturbImage);
scrollView->Add(AttentionLabel);
scrollView->Add(ButtonOn);
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-03-01 15:10:34
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-03-27 10:40:38
+ * @LastEditTime: 2024-04-10 15:48:47
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h
*/
static constexpr const char *DROPDOWN_CLICK_BRIGHTENSCREEN = "dropdownclickbrightscreen";
static constexpr const char *DROPDOWN_CLICK_SETTING = "dropdownclicksetting"; // 设置
- static constexpr const char *DROPDOWN_CLICK_LIGHTING = "dropdownclicklighting"; // 亮屏
+ static constexpr const char *DROPDOWN_CLICK_LIGHTING = "dropdownclicklighting"; // 手电筒
static constexpr const char *DROPDOWN_CLICK_DNOTDISTURB = "dropdownclickdnotdisturb"; // 勿扰
static constexpr const char *DROPDOWN_CLICK_SAVEELE = "dropdownclicksaveele"; // 省电
static constexpr const char *DROPDOWN_CLICK_FINDMYPHONE = "dropdownclickfindmyphone"; // 找手机
map<string, AppViewId> g_jumpView = {
{DROPDOWN_CLICK_SETTING, VIEW_SETTING}, // 设置
- //{DROPDOWN_CLICK_DNOTDISTURB, VIEW_FIND_PHONE}, // 勿扰
- {DROPDOWN_CLICK_SAVEELE, VIEW_SAVEELE}, // 省电模式
- {DROPDOWN_CLICK_FINDMYPHONE, VIEW_FIND_PHONE},
+ //{DROPDOWN_CLICK_LIGHTING, VIEW_FLASHLIGH}, // 手电筒
+ {DROPDOWN_CLICK_DNOTDISTURB, VIEW_DNOTDISTURB}, // 勿扰
+ {DROPDOWN_CLICK_SAVEELE, VIEW_SAVEELE}, // 省电模式
+ {DROPDOWN_CLICK_FINDMYPHONE, VIEW_FIND_PHONE}, // 查找手机
};
static MainPresenterSample *g_pMainPresenterSample = nullptr;
#include "ScreenModels.h"
#include "SettingModel.h"
#include "ui_resource_image.h"
-
+#include "dnotdisturb/include/DnotDisturbModel.h"
namespace OHOS
{
+
+ static constexpr int16_t SETTING_INDEX = 0;
+ static constexpr int16_t LIGHTING_INDEX = 1;
+ static constexpr int16_t DNOTDISTURB_INDEX = 2;
+ static constexpr int16_t SAVEPOWER_INDEX = 3;
+ static constexpr int16_t FINDPHONE_INDEX = 4;
+ static constexpr int16_t MAX_INDEX = 5;
+
/* ---------------------------------- 坐标位置 ---------------------------------- */
// 设置
constexpr int16_t SETTING_IMG_X = 30;
constexpr int16_t SETTING_IMG_Y = 186;
- // 亮屏
+ // 手电筒
constexpr int16_t LIGHTING_IMG_X = 76;
constexpr int16_t LIGHTING_IMG_Y = 76;
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::~PullUpDownView");
RemoveAll();
- for (int i = 0; i < 5; i++)
+ for (int i = 0; i < MAX_INDEX; i++)
{
delete dropIconBackground[i];
dropIconBackground[i] = nullptr;
/// @param void
void PullUpDownView::InitViewImgBackGround(void)
{
- for (int i = 0; i < 5; i++)
+ for (int i = 0; i < MAX_INDEX; i++)
{
dropIconBackground[i] = new UIImageView();
if (dropIconBackground[i] == nullptr)
return;
}
}
- dropIconBackground[0]->SetPosition(SETTING_IMG_X, SETTING_IMG_Y);
- dropIconBackground[1]->SetPosition(LIGHTING_IMG_X, LIGHTING_IMG_Y);
- dropIconBackground[2]->SetPosition(DNOTDISTURB_IMG_X, DNOTDISTURB_IMG_Y);
- dropIconBackground[3]->SetPosition(SAVEPOWER_IMG_X, SAVEPOWER_IMG_Y);
- dropIconBackground[4]->SetPosition(FINDPHONE_IMG_X, FINDPHONE_IMG_Y);
- for (int i = 0; i < 5; i++)
+ dropIconBackground[SETTING_INDEX]->SetPosition(SETTING_IMG_X, SETTING_IMG_Y);
+ dropIconBackground[LIGHTING_INDEX]->SetPosition(LIGHTING_IMG_X, LIGHTING_IMG_Y);
+ dropIconBackground[DNOTDISTURB_INDEX]->SetPosition(DNOTDISTURB_IMG_X, DNOTDISTURB_IMG_Y);
+ dropIconBackground[SAVEPOWER_INDEX]->SetPosition(SAVEPOWER_IMG_X, SAVEPOWER_IMG_Y);
+ dropIconBackground[FINDPHONE_INDEX]->SetPosition(FINDPHONE_IMG_X, FINDPHONE_IMG_Y);
+ for (int i = 0; i < MAX_INDEX; i++)
{
- ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dropIconBackground[i], DROPDOWN_ICONELLIPSEBLACK);
+ if (i == DNOTDISTURB_INDEX && DnotDisturbModel::GetInstance().GetDoNotDisturbModeEnabled() == true)
+ {
+ ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dropIconBackground[i], DROPDOWN_ICONELLIPSEPURPLE);
+ }
+ else
+ {
+ ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dropIconBackground[i], DROPDOWN_ICONELLIPSEBLACK);
+ }
Add(dropIconBackground[i]);
}
}