#include "DialBinParser.h"
#include "ModelDialDataFactory.h"
#include "common/low_power_manager.h"
-#include "wearable_log.h"
-namespace OHOS
+namespace OHOS {
+DialViewGroup::DialViewGroup(void)
{
- DialViewGroup::DialViewGroup(void)
- {
- SetTouchable(true);
- SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
- SetCoverable(true);
- }
-
- DialViewGroup::~DialViewGroup(void)
- {
- ClearDial();
- }
-
- void DialViewGroup::ClearDial()
- {
- ListNode<DialDataType> *passiveNode = passiveUpdateTypes_.Head();
- while (passiveNode != passiveUpdateTypes_.End())
- {
- DialDataType type = passiveNode->data_;
- ModelDialDataFactory::GetInstance().UnRegisterDialDataListener(type);
- passiveNode = passiveNode->next_;
- }
- passiveUpdateTypes_.Clear();
-
- ListNode<DialClick> *clickNode = dialClicks_.Head();
- while (clickNode != dialClicks_.End())
- {
- DialClick click = clickNode->data_;
- if (!click.isSliceType)
- {
- UIFree(click.bundleName);
- }
- clickNode = clickNode->next_;
- }
- dialClicks_.Clear();
+ SetTouchable(true);
+ SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+ SetCoverable(true);
+}
- periodicUpdateTypes_.Clear();
+DialViewGroup::~DialViewGroup(void)
+{
+ if (kaleidoscope_ != nullptr) {
+ kaleidoscope_->ClearFocus();
+ kaleidoscope_ = nullptr;
+ }
+ ClearDial();
+}
- dataTypeMap_.clear();
+void DialViewGroup::ClearDial()
+{
+ ListNode<DialDataType>* passiveNode = passiveUpdateTypes_.Head();
+ while (passiveNode != passiveUpdateTypes_.End()) {
+ DialDataType type = passiveNode->data_;
+ ModelDialDataFactory::GetInstance().UnRegisterDialDataListener(type);
+ passiveNode = passiveNode->next_;
+ }
+ passiveUpdateTypes_.Clear();
- ListNode<UIView *> *viewNode = dialViews_.Head();
- while (viewNode != dialViews_.End())
- {
- UIViewGroup::Remove(viewNode->data_);
- delete (viewNode->data_);
- viewNode = viewNode->next_;
+ ListNode<DialClick>* clickNode = dialClicks_.Head();
+ while (clickNode != dialClicks_.End()) {
+ DialClick click = clickNode->data_;
+ if (!click.isSliceType) {
+ UIFree(click.bundleName);
}
- dialViews_.Clear();
-
- period_ = DEFAULT_TASK_PERIOD;
+ clickNode = clickNode->next_;
+ }
+ dialClicks_.Clear();
- video_ = nullptr;
+ periodicUpdateTypes_.Clear();
- sequence_ = nullptr;
+ dataTypeMap_.clear();
- if (fp_ != nullptr)
- {
- fclose(fp_);
- fp_ = nullptr;
- }
+ ListNode<UIView*>* viewNode = dialViews_.Head();
+ while (viewNode != dialViews_.End()) {
+ UIViewGroup::Remove(viewNode->data_);
+ delete(viewNode->data_);
+ viewNode = viewNode->next_;
}
+ dialViews_.Clear();
- void DialViewGroup::SetDial(std::string filePath)
- {
- ClearDial();
- resPreloaded_ = false;
- filePath_ = filePath;
- }
+ period_ = DEFAULT_TASK_PERIOD;
- void DialViewGroup::PreLoad(void)
- {
- if (!resPreloaded_)
- {
- fp_ = fopen(filePath_.c_str(), "rb");
- if (fp_ == nullptr)
- {
- GRAPHIC_LOGE("cannot open file: %s\n", filePath_.c_str());
- return;
- }
- DialBinParser::GetInstance()->UpdateDial(filePath_, fp_, this);
- if (video_ != nullptr)
- {
- video_->StartPlay();
- }
- resPreloaded_ = true;
- }
+ video_ = nullptr;
+
+ if (fp_ != nullptr) {
+ fclose(fp_);
+ fp_ = nullptr;
}
+}
+
+void DialViewGroup::SetDial(std::string filePath)
+{
+ ClearDial();
+ resPreloaded_ = false;
+ filePath_ = filePath;
+}
- void DialViewGroup::ProcessData(DialDataType type, DialView *view)
- {
- int16_t value = static_cast<int16_t>(type) >> 13; // 13: bit shift
- if (value == 0)
- { // 0: float
- float floatData = 0;
- ModelDialDataFactory::GetInstance().GetDialFloatData(type, floatData);
- view->HandleFloatData(floatData);
+void DialViewGroup::PreLoad(void)
+{
+ if (!resPreloaded_) {
+ fp_ = fopen(filePath_.c_str(), "rb");
+ if (fp_ == nullptr) {
+ GRAPHIC_LOGE("cannot open file: %s\n", filePath_.c_str());
+ return;
}
- else if (value == 1)
- { // 1: text
- std::string *textData = nullptr;
- int16_t num = 0;
- ModelDialDataFactory::GetInstance().GetDialTextData(type, textData, num);
- view->HandleTextData(textData, num);
+ DialBinParser::GetInstance()->UpdateDial(filePath_, fp_, this);
+ if (video_ != nullptr) {
+ video_->StartPlay();
}
- else if (value == 2)
- { // 2: multifloat
- float *floatsData = nullptr;
- int16_t num = 0;
- ModelDialDataFactory::GetInstance().GetDialFloatData(type, floatsData, num);
- view->HandleFloatData(floatsData, num);
+
+ if (kaleidoscope_ != nullptr) {
+ kaleidoscope_->RequestFocus();
+ kaleidoscope_->StartRotateAnimator();
}
+ resPreloaded_ = true;
}
+}
- void DialViewGroup::AddView(UIView *view, bool isDialVideoView)
- {
- if (view == nullptr)
- {
- GRAPHIC_LOGE("Parameter is nullptr.\n");
- return;
- }
- dialViews_.PushBack(view);
- Add(view);
-
- if (isDialVideoView)
- {
- if (video_ != nullptr)
- {
- GRAPHIC_LOGE("Already added a video view.\n");
- return;
- }
- video_ = reinterpret_cast<DialVideoView *>(view);
- }
+void DialViewGroup::ProcessData(DialDataType type, DialView* view)
+{
+ int16_t value = static_cast<int16_t>(type) >> 13; // 13: bit shift
+ if (value == 0) { // 0: float
+ float floatData = 0;
+ ModelDialDataFactory::GetInstance().GetDialFloatData(type, floatData);
+ view->HandleFloatData(floatData);
+ } else if (value == 1) { // 1: text
+ std::string* textData = nullptr;
+ int16_t num = 0;
+ ModelDialDataFactory::GetInstance().GetDialTextData(type, textData, num);
+ view->HandleTextData(textData, num);
+ } else if (value == 2) { // 2: multifloat
+ float* floatsData = nullptr;
+ int16_t num = 0;
+ ModelDialDataFactory::GetInstance().GetDialFloatData(type, floatsData, num);
+ view->HandleFloatData(floatsData, num);
}
+}
- void DialViewGroup::AddView(DialDataType type, DialView *view, bool isPeriodic)
- {
- if (view == nullptr)
- {
- GRAPHIC_LOGE("Parameter is nullptr.\n");
- return;
- }
+void DialViewGroup::AddView(UIView* view, bool isDialVideoView)
+{
+ if (view == nullptr) {
+ GRAPHIC_LOGE("Parameter is nullptr.\n");
+ return;
+ }
+ dialViews_.PushBack(view);
+ Add(view);
- dataTypeMap_.insert(std::make_pair(static_cast<int16_t>(type), view));
- if (isPeriodic)
- {
- periodicUpdateTypes_.PushBack(type);
- }
- else
- {
- ModelDialDataFactory::GetInstance().RegisterDialDataListener(type, this);
- passiveUpdateTypes_.PushBack(type);
- }
- dialViews_.PushBack(dynamic_cast<UIView *>(view));
- ProcessData(type, view);
- Add(dynamic_cast<UIView *>(view));
+ if (view->GetViewType() == UI_KALEIDOSCOPE_VIEW) {
+ kaleidoscope_ = dynamic_cast<UIKaleidoscopeView*>(view);
}
- void DialViewGroup::SetPeriod(uint32_t period)
- {
- if (period_ < DEFAULT_TASK_PERIOD)
- {
- period_ = DEFAULT_TASK_PERIOD;
- }
- else
- {
- period_ = period;
+ if (isDialVideoView) {
+ if (video_ != nullptr) {
+ GRAPHIC_LOGE("Already added a video view.\n");
+ return;
}
+ video_ = reinterpret_cast<DialVideoView*>(view);
}
+}
- uint32_t DialViewGroup::GetPeriod()
- {
- return period_;
+void DialViewGroup::AddView(DialDataType type, DialView* view, bool isPeriodic)
+{
+ if (view == nullptr) {
+ GRAPHIC_LOGE("Parameter is nullptr.\n");
+ return;
}
- void DialViewGroup::UpdateViewsByPeriodicUpdateData()
- {
- ListNode<DialDataType> *node = periodicUpdateTypes_.Head();
- while (node != periodicUpdateTypes_.End())
- {
- DialDataType type = node->data_;
- auto iter = dataTypeMap_.find(static_cast<int16_t>(type));
- if (iter != dataTypeMap_.end())
- {
- ProcessData(type, iter->second);
- }
- node = node->next_;
- }
- if (LowPowerManager::GetInstance()->IsLiteSurfaceInRootView())
- {
- Invalidate();
- }
+ dataTypeMap_.insert(std::make_pair(static_cast<int16_t>(type), view));
+ if (isPeriodic) {
+ periodicUpdateTypes_.PushBack(type);
+ } else {
+ ModelDialDataFactory::GetInstance().RegisterDialDataListener(type, this);
+ passiveUpdateTypes_.PushBack(type);
}
+ dialViews_.PushBack(dynamic_cast<UIView*>(view));
+ ProcessData(type, view);
+ Add(dynamic_cast<UIView*>(view));
+}
- void DialViewGroup::OnDialFloatDataUpdate(DialDataType type, float data)
- {
- auto iter = dataTypeMap_.find(static_cast<int16_t>(type));
- if (iter != dataTypeMap_.end())
- {
- DialView *view = iter->second;
- view->HandleFloatData(data);
- }
+void DialViewGroup::SetPeriod(uint32_t period)
+{
+ if (period_ < DEFAULT_TASK_PERIOD) {
+ period_ = DEFAULT_TASK_PERIOD;
+ } else {
+ period_ = period;
}
+}
+
+uint32_t DialViewGroup::GetPeriod()
+{
+ return period_;
+}
- void DialViewGroup::OnDialFloatDataUpdate(DialDataType type, const float *data, uint16_t num)
- {
+void DialViewGroup::UpdateViewsByPeriodicUpdateData()
+{
+ ListNode<DialDataType>* node = periodicUpdateTypes_.Head();
+ while (node != periodicUpdateTypes_.End()) {
+ DialDataType type = node->data_;
auto iter = dataTypeMap_.find(static_cast<int16_t>(type));
- if (iter != dataTypeMap_.end())
- {
- DialView *view = iter->second;
- view->HandleFloatData(data, num);
+ if (iter != dataTypeMap_.end()) {
+ ProcessData(type, iter->second);
}
+ node = node->next_;
+ }
+ if (LowPowerManager::GetInstance()->IsLiteSurfaceInRootView()) {
+ Invalidate();
}
+}
- void DialViewGroup::OnDialTextDataUpdate(DialDataType type, const std::string *data, uint16_t num)
- {
- auto iter = dataTypeMap_.find(static_cast<int16_t>(type));
- if (iter != dataTypeMap_.end())
- {
- DialView *view = iter->second;
- view->HandleTextData(data, num);
- }
+void DialViewGroup::OnDialFloatDataUpdate(DialDataType type, float data)
+{
+ auto iter = dataTypeMap_.find(static_cast<int16_t>(type));
+ if (iter != dataTypeMap_.end()) {
+ DialView* view = iter->second;
+ view->HandleFloatData(data);
+ }
+}
+
+void DialViewGroup::OnDialFloatDataUpdate(DialDataType type, const float* data, uint16_t num)
+{
+ auto iter = dataTypeMap_.find(static_cast<int16_t>(type));
+ if (iter != dataTypeMap_.end()) {
+ DialView* view = iter->second;
+ view->HandleFloatData(data, num);
}
+}
- void DialViewGroup::AddDialClick(Rect &rect, const char *bundleName)
- {
- if (bundleName == nullptr)
- {
- return;
- }
- uint32_t len = static_cast<uint32_t>(strlen(bundleName));
- char *name = static_cast<char *>(UIMalloc(++len));
- if (name == nullptr)
- {
- return;
- }
- if (memcpy_s(name, len, bundleName, len) != EOK)
- {
- UIFree(name);
- name = nullptr;
- return;
- }
- name[len] = '\0';
- DialClick click = {rect, false, {.bundleName = name}};
- dialClicks_.PushBack(click);
+void DialViewGroup::OnDialTextDataUpdate(DialDataType type, const std::string* data, uint16_t num)
+{
+ auto iter = dataTypeMap_.find(static_cast<int16_t>(type));
+ if (iter != dataTypeMap_.end()) {
+ DialView* view = iter->second;
+ view->HandleTextData(data, num);
}
+}
- void DialViewGroup::AddDialClick(Rect &rect, uint32_t sliceId)
- {
- if (sliceId == 0)
- {
- return;
- }
+void DialViewGroup::AddDialClick(Rect& rect, const char* bundleName)
+{
+ if (bundleName == nullptr) {
+ return;
+ }
+ uint32_t len = static_cast<uint32_t>(strlen(bundleName));
+ char* name = static_cast<char*>(UIMalloc(++len));
+ if (name == nullptr) {
+ return;
+ }
+ if (memcpy_s(name, len, bundleName, len) != EOK) {
+ UIFree(name);
+ name = nullptr;
+ return;
+ }
+ name[len] = '\0';
+ DialClick click = {rect, false, {.bundleName = name}};
+ dialClicks_.PushBack(click);
+}
+
+void DialViewGroup::AddDialClick(Rect& rect, uint32_t sliceId)
+{
+ if (sliceId == 0) {
+ return;
+ }
+
+ DialClick click = {rect, true, {.sliceId = sliceId}};
+ dialClicks_.PushBack(click);
+}
- DialClick click = {rect, true, {.sliceId = sliceId}};
- dialClicks_.PushBack(click);
- }
-
- bool DialViewGroup::OnClickEvent(const ClickEvent &event)
- {
- Point point = event.GetCurrentPos();
- ListNode<DialClick> *node = dialClicks_.Head();
- while (node != dialClicks_.End())
- {
- DialClick dialClick = node->data_;
- if (dialClick.area.IsContains(point))
- {
- if (dialClick.isSliceType)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClickEvent %d", dialClick.sliceId);
- NativeAbility::GetInstance().ChangeSlice(dialClick.sliceId);
- }
- else
- {
+bool DialViewGroup::OnClickEvent(const ClickEvent& event)
+{
+ Point point = event.GetCurrentPos();
+ ListNode<DialClick>* node = dialClicks_.Head();
+ while (node != dialClicks_.End()) {
+ DialClick dialClick = node->data_;
+ if (dialClick.area.IsContains(point)) {
+ if (dialClick.isSliceType) {
+ NativeAbility::GetInstance().ChangeSlice(dialClick.sliceId);
+ } else {
#ifdef JS_ENABLE
- StartJsApp(dialClick.bundleName);
+ StartJsApp(dialClick.bundleName);
#endif
- }
- return true;
}
- node = node->next_;
+ return true;
}
- return false;
+ node = node->next_;
}
+ return false;
+}
- void DialViewGroup::ScrollBegin(bool isActive)
- {
- if (video_ == nullptr)
- {
- return;
- }
- if (video_->IsPlayed())
- {
- video_->PausePlay();
+void DialViewGroup::ScrollBegin(bool isActive)
+{
+ if (kaleidoscope_ != nullptr) {
+ if (isActive) {
+ kaleidoscope_->ClearFocus();
+ kaleidoscope_->StopRotateAnimator();
}
+ return;
}
- void DialViewGroup::ScrollEnd(bool isActive)
- {
- if (video_ == nullptr)
- {
- return;
- }
+ if (video_ == nullptr) {
+ return;
+ }
+ if (video_->IsPlayed()) {
+ video_->PausePlay();
+ }
+}
- if (isActive)
- {
- if (video_->IsPaused())
- {
- video_->ResumePlay();
- }
- else if (video_->IsStopped())
- {
- video_->StartPlay();
- }
+void DialViewGroup::ScrollEnd(bool isActive)
+{
+ if (kaleidoscope_ != nullptr) {
+ if (isActive) {
+ kaleidoscope_->StartRotateAnimator();
+ kaleidoscope_->RequestFocus();
}
+ return;
}
- void DialViewGroup::CoverBegin(bool isCovered)
- {
- if (video_ == nullptr)
- {
- return;
- }
+ if (video_ == nullptr) {
+ return;
+ }
- if (video_->IsPlayed())
- {
- video_->PausePlay();
+ if (isActive) {
+ if (video_->IsPaused()) {
+ video_->ResumePlay();
+ } else if (video_->IsStopped()) {
+ video_->StartPlay();
+ }
+ } else {
+ if (video_->IsPaused() || video_->IsPlayed()) {
+ video_->StopPlay();
}
+ ClearCache();
}
+}
- void DialViewGroup::CoverEnd(bool isCovered)
- {
- if (video_ == nullptr)
- {
- return;
+void DialViewGroup::CoverBegin(bool isCovered)
+{
+ if (kaleidoscope_ != nullptr) {
+ if (!isCovered) {
+ kaleidoscope_->StopRotateAnimator();
+ kaleidoscope_->ClearFocus();
}
- if (!isCovered)
- {
- if (video_->IsPaused())
- {
- video_->ResumePlay();
- }
- else if (video_->IsStopped())
- {
+ return;
+ }
- video_->StartPlay();
- }
+ if (video_ == nullptr) {
+ return;
+ }
+
+ if (video_->IsPlayed()) {
+ video_->PausePlay();
+ }
+}
+
+void DialViewGroup::CoverEnd(bool isCovered)
+{
+ if (kaleidoscope_ != nullptr) {
+ if (!isCovered) {
+ kaleidoscope_->RequestFocus();
+ kaleidoscope_->StartRotateAnimator();
}
+ return;
}
- void DialViewGroup::ComeBack()
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ComeBack");
- if (video_ != nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "video_");
- if (video_->IsPaused())
- {
- video_->ResumePlay();
- }
- else if (video_->IsStopped())
- {
- video_->StartPlay();
- }
+ if (video_ == nullptr) {
+ return;
+ }
+ if (!isCovered) {
+ if (video_->IsPaused()) {
+ video_->ResumePlay();
+ } else if (video_->IsStopped()) {
+ video_->StartPlay();
}
}
}
+
+void DialViewGroup::OnActive(void)
+{
+ if (video_ != nullptr) {
+ if (video_->IsPaused()) {
+ video_->ResumePlay();
+ } else if (video_->IsStopped()) {
+ video_->StartPlay();
+ }
+ } else if (kaleidoscope_ != nullptr) {
+ kaleidoscope_->RequestFocus();
+ kaleidoscope_->StartRotateAnimator();
+ }
+}
+}