public:
static FlashlightModel &GetInstance(void);
+ void SaveSettingInfo(void);
uint8_t GetColorIndex(void);
void SetColorIndex(uint8_t value);
int64_t GetColorValue(void);
void FlashlightStartTimer(void);
void FlashlightStopTimer(void);
- void FlashlightPauseTimer(void);
- void FlashlightResumeTimer(uint32_t interval);
private:
FlashlightModel();
#define Flashlight_ViewId_GroupColorCustom_ "Flashlight_ViewId_GroupColorCustom_"
#define Flashlight_ViewId_ScrollFlashingSetting_ "Flashlight_ViewId_ScrollFlashingSetting_"
+ #define Flashlight_ViewId_ImageColorCustomBackground_ "Flashlight_ViewId_ImageColorCustomBackground_"
+
#define FLASHING_SETTING_ITEM_COUNT (3)
constexpr char * Flashlight_ViewId_FlashingSettingItem_[FLASHING_SETTING_ITEM_COUNT] =
{
void DisplayColorCustomScreen();
void DisplayFlashingSettingScreen();
+ void GetValueByColorCustomSelectedImage(int16_t x, int16_t y, int64_t * value);
+ void GetPointByColorCustomSelectedImage(int16_t * x, int16_t * y, int64_t value);
void UpdateViewMainScreenFlashing(bool flag);
typedef enum
void DeinitColorCustomData();
// UIViewGroup * InitColorCustomData();
+ // void UpdateColorCustomSelectedImage(int16_t x, int16_t y);
UIViewGroup * GroupColorCustom_{nullptr};
- UIImageView * ImageColorCustom_{nullptr};
+ UIImageView * ImageColorCustomBackground_{nullptr};
+ UIImageView * ImageColorCustomSelected_{nullptr};
void DeinitFlashingSettingData();
// UIScrollView * InitFlashingSettingData();
"/user/res/flashlight/color_4.bin",
"/user/res/flashlight/color_5.bin",
};
+
+ #define COLOR_CUSTOM_BACKGROUND_IMAGE "/user/res/flashlight/color_custom_bg.bin"
+ #define COLOR_CUSTOM_SELECTED_IMAGE "/user/res/flashlight/color_custom_selected.bin"
};
}
#endif
\ No newline at end of file
#include "wearable_log.h"
#include "flashlight/include/FlashlightModel.h"
#include "flashlight/include/FlashlightPresenter.h"
+#include "ConfigModel.h"
namespace OHOS
{
static bool switch_flag = false;
- FlashlightModel::FlashlightModel() {}
+ FlashlightModel::FlashlightModel()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:", __LINE__);
+ OHOS::ConfigModel::GetInstance()->GetFlashLightConfigData(&ColorIndex_, &ColorValue_, &FlashingLevel_);
+ }
FlashlightModel::~FlashlightModel() {}
return instance;
}
+ void FlashlightModel::SaveSettingInfo(void)
+ {
+ OHOS::ConfigModel::GetInstance()->SetFlashLightConfigData(ColorIndex_, ColorValue_, FlashingLevel_);
+ }
+
uint8_t FlashlightModel::GetColorIndex(void)
{
return ColorIndex_;
*/
void FlashlightModel::FlashlightStopTimer(void)
{
- // 检查定时器是否存在
- if (g_timer != NULL)
- {
- // 删除定时器并置为 NULL
- osStatus_t ret = osTimerDelete(g_timer);
- if (ret != osOK)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret);
- }
- g_timer = NULL;
- }
- }
- /*
- * @brief 暂停定时器
- */
- void FlashlightModel::FlashlightPauseTimer(void)
- {
- // 检查定时器是否存在
if (g_timer != NULL)
{
- // 暂停定时器,但不删除它
- osStatus_t ret = osTimerStop(g_timer);
+ osStatus_t ret = osOK;
+ ret = osTimerStop(g_timer);
if (ret != osOK)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightPauseTimer osTimerStop failed, ret = %lx!!", ret);
+ return;
}
- }
- }
-
- /*
- * @brief 恢复定时器
- */
- void FlashlightModel::FlashlightResumeTimer(uint32_t interval)
- {
- // 检查定时器是否存在
- if (g_timer != NULL)
- {
- int tick = osMs2Tick(interval);
- // 恢复定时器
- osStatus_t ret = osTimerStart(g_timer, tick);
+ // 删除定时器并置为 NULL
+ ret = osTimerDelete(g_timer);
if (ret != osOK)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightResumeTimer osTimerStart failed, ret = %lx!!", ret);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret);
+ return;
}
+ g_timer = NULL;
}
}
-
}
\ No newline at end of file
ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
FlashlightModel::GetInstance().FlashlightStopTimer();
+ FlashlightModel::GetInstance().SaveSettingInfo();
}
bool FlashlightPresenter::OnDrag(UIView &view, const DragEvent &event)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnDrag");
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnDrag");
UNUSED(view);
if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动
{
bool FlashlightPresenter::OnDragEnd(UIView &view, const DragEvent &event)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnDragEnd");
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnDragEnd");
UNUSED(view);
if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && FlashlightPresenter::X_DRAG_FLAG)
{
bool FlashlightPresenter::OnClick(UIView &view, const ClickEvent &event)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnClick");
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnClick");
UNUSED(event);
if(0 == strcmp(Flashlight_ViewId_ImageColorSetting_, view.GetViewId()))
if(0 == strcmp(Flashlight_ViewId_FlashingSettingItem_[i], view.GetViewId()))
{
FlashlightModel::GetInstance().SetFlashingLevel(i);
- // view_->UpdateFlashingSettingItem();
- // view_->DisplayFlashingSettingScreen();
view_->DisplayViewMainScreen();
return true;
}
{
if(0 == strcmp(Flashlight_ViewId_ImageColorSettingItem_[COLOR_SETTING_ITEM_COUNT - 1], view.GetViewId()))
{
- FlashlightModel::GetInstance().SetColorIndex(i);
+ FlashlightModel::GetInstance().SetColorIndex(COLOR_SETTING_ITEM_COUNT - 1);
view_->DisplayColorCustomScreen();
return true;
}
}
}
+ if(0 == strcmp(Flashlight_ViewId_ImageColorCustomBackground_, view.GetViewId()))
+ {
+ Point point = event.GetCurrentPos();
+ int64_t value = -1;
+ view_->GetValueByColorCustomSelectedImage(point.x, point.y, &value);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnClick.value=%d", value);
+ if(0 > value)
+ return false;
+
+ FlashlightModel::GetInstance().SetColorValue(value);
+ view_->DisplayViewMainScreen();
+ return true;
+ }
+
return true;
}
// 增加按键事件
bool FlashlightPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnKeyAct");
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnKeyAct");
uint16_t keyID = event.GetKeyId();
uint16_t keyState = event.GetState();
// 如果是power键就返回上一级
#include "ui_resource_string.h"
#include "UiConfig.h"
#include "custom_utils.h"
+#include "common/image_cache_manager.h"
namespace OHOS
{
delete GroupColorCustom_;
GroupColorCustom_ = nullptr;
- if(nullptr != ImageColorCustom_)
+ if(nullptr != ImageColorCustomBackground_)
{
- delete ImageColorCustom_;
- ImageColorCustom_ = nullptr;
+ ImageCacheManager::GetInstance().UnloadSingleRes(COLOR_CUSTOM_BACKGROUND_IMAGE);
+
+ delete ImageColorCustomBackground_;
+ ImageColorCustomBackground_ = nullptr;
+ }
+ if(nullptr != ImageColorCustomSelected_)
+ {
+ delete ImageColorCustomSelected_;
+ ImageColorCustomSelected_ = nullptr;
}
}
}
GroupColorCustom_->SetDraggable(true);
GroupColorCustom_->SetOnDragListener(presenter_);
- if(nullptr == ImageColorCustom_)
+ if(nullptr == ImageColorCustomBackground_)
{
- ImageColorCustom_ = new UIImageView;
- if(nullptr == ImageColorCustom_)
+ ImageColorCustomBackground_ = new UIImageView;
+ if(nullptr == ImageColorCustomBackground_)
return nullptr;
- ImageColorCustom_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+ ImageColorCustomBackground_->SetViewId(Flashlight_ViewId_ImageColorCustomBackground_);
+ ImageColorCustomBackground_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+ ImageInfo* info = ImageCacheManager::GetInstance().LoadSingleRes(COLOR_CUSTOM_BACKGROUND_IMAGE);
+ ImageColorCustomBackground_->SetSrc(info);
+ ImageColorCustomBackground_->SetTouchable(true);
+ ImageColorCustomBackground_->SetOnClickListener(presenter_);
+
+ GroupColorCustom_->Add(ImageColorCustomBackground_);
+ }
+ if(nullptr == ImageColorCustomSelected_)
+ {
+ ImageColorCustomSelected_ = new UIImageView();
+ if(nullptr == ImageColorCustomSelected_)
+ return nullptr;
+
+ int16_t x = -1;
+ int16_t y = -1;
+ int64_t value = presenter_->GetColorValue();
+ GetPointByColorCustomSelectedImage(&x, &y, value);
+ ImageColorCustomSelected_->SetPosition(x, y, 70, 70);
+ ImageColorCustomSelected_->SetSrc(COLOR_CUSTOM_SELECTED_IMAGE);
+
+ GroupColorCustom_->Add(ImageColorCustomSelected_);
}
container_->Add(GroupColorCustom_);
return GroupColorCustom_;
}
+ void FlashlightView::GetValueByColorCustomSelectedImage(int16_t x, int16_t y, int64_t * value)
+ {
+ * value = -1;
+
+ if(nullptr == ImageColorCustomSelected_)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+ return ;
+ }
+ if(nullptr == ImageColorCustomBackground_)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+ return ;
+ }
+ const ImageInfo * info = ImageColorCustomBackground_->GetImageInfo();
+ if(nullptr == info)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+ return ;
+ }
+//
+//
+//
+// 待实现功能
+// 获得 (x,y) 处的颜色值
+// 赋值给 value
+//
+//
+//
+ }
+
+ void FlashlightView::GetPointByColorCustomSelectedImage(int16_t * x, int16_t * y, int64_t value)
+ {
+ * x = -1;
+ * y = -1;
+
+ if(nullptr == ImageColorCustomSelected_)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+ return ;
+ }
+ if(nullptr == ImageColorCustomBackground_)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+ return ;
+ }
+ const ImageInfo * info = ImageColorCustomBackground_->GetImageInfo();
+ if(nullptr == info)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+ return ;
+ }
+//
+//
+//
+// 待实现功能
+// 根据给定的颜色值
+// 获得对应的 (x,y)值
+//
+//
+//
+ }
+
void FlashlightView::DeinitFlashingSettingData()
{
if(nullptr != ScrollFlashingSetting_)
--- /dev/null
+version https://git-lfs.github.com/spec/v1
+oid sha256:50e7503c027d75d76a2e75b6cc072d99c905fe85aeb41181ae711b5aa9183599
+size 146040
--- /dev/null
+version https://git-lfs.github.com/spec/v1
+oid sha256:a7afdeb79c87a94eb6f14864cfccff79b9473435206577eb4218c7cb5106ba4f
+size 3480
CONFIGMODEL_ITEM_APPLIST_STYLE,//applist的显示样式
CONFIGMODEL_ITEM_BLE_IOS_OR_ANDROID,//绑定设备为安卓或者ios 0:安卓 1:苹果
CONFIGMODEL_ITEM_BR_PAIR,//br第一次绑定
+
+ // flashlight
+ CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_INDEX, // color index
+ CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_VALUE, // color value
+ CONFIGMODEL_ITEM_FLASHLIGHT_FLASHING_LEVEL, // flashing level
+
CONFIGMODEL_ITEM_MAX,
/* ---------------------------- 设置OpenAI APIKeys ---------------------------- */
void SetOpenAIAPIKeys(const char * value);
std::string GetOpenAIAPIKeys(void);
+
+ // flash light config data
+ void GetFlashLightConfigData(uint8_t * ColorIndex, int64_t * ColorValue, uint8_t * FlashingLevel);
+ void SetFlashLightConfigData(uint8_t ColorIndex, int64_t ColorValue, uint8_t FlashingLevel);
+
/* --------------------------------- 用户配置信息 --------------------------------- */
void SetUserAge(int age);
int GetUserAge();
{ConfigDataType::DATATYPE_STRING, "applist_style", "list" }, //CONFIGMODEL_ITEM_APPLIST_STYLE
{ConfigDataType::DATATYPE_INT, "android_or_ios", "0" },//CONFIGMODEL_ITEM_BLE_IOS_OR_ANDROID
{ConfigDataType::DATATYPE_INT, "br_pari" , "0"},
+ {ConfigDataType::DATATYPE_INT, "color_index", "0" }, // CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_INDEX, // color index
+ {ConfigDataType::DATATYPE_INT, "color_value", "0" }, // CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_VALUE, // color value
+ {ConfigDataType::DATATYPE_INT, "flashing_level", "0" }, // CONFIGMODEL_ITEM_FLASHLIGHT_FLASHING_LEVEL, // flashing level
+
};
ConfigModel(); // 私有构造函数,确保无法在外部实例化
ConfigModel(const ConfigModel &) = delete; // 禁止拷贝构造
{
return get_configData_string(CONFIGMODEL_ITEM_OPEN_AI_API_KEYS);
}
+
+ // flash light config data
+ void ConfigModel::GetFlashLightConfigData(uint8_t * ColorIndex, int64_t * ColorValue, uint8_t * FlashingLevel)
+ {
+ * ColorIndex = get_configData_int(CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_INDEX);
+ * ColorValue = get_configData_int(CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_VALUE);
+ * FlashingLevel = get_configData_int(CONFIGMODEL_ITEM_FLASHLIGHT_FLASHING_LEVEL);
+ }
+
+ void ConfigModel::SetFlashLightConfigData(uint8_t ColorIndex, int64_t ColorValue, uint8_t FlashingLevel)
+ {
+ set_condigData_Int(CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_INDEX, ColorIndex);
+ set_condigData_Int(CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_VALUE, ColorValue);
+ set_condigData_Int(CONFIGMODEL_ITEM_FLASHLIGHT_FLASHING_LEVEL, FlashingLevel);
+ }
+
/* -------------------------------------------------------------------------- */
/*设置用户年龄[后续使用结构体统一配置]*/
void ConfigModel::SetUserAge(int age)