namespace OHOS
{
-
// 当前Presenter属性实例化的内存指针
static DialUpdatePresenter *g_pDialUpdatePresenter = nullptr;
{
g_pdialupdatemodel = DialUpdateModel::GetInstance();
g_pDialUpdatePresenter = this;
+ // showid = DialUpdateModel::GetInstance()->GetDialConfigPath();
}
DialUpdatePresenter::~DialUpdatePresenter()
bool DialUpdatePresenter::OnDragEnd(UIView &view, const DragEvent &event)
{
- if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP)
- {
- NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
- }
- // 右滑
- if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
- {
- if (showid == MAX_DIALNUM - 1)
- {
- showid = 0;
- }
- else
- {
- showid++;
- }
- DialUpdateView::GetInstance()->SetView();
- RootView::GetInstance()->Invalidate(); // 刷新界面
- }
- // 左滑
- if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT)
- {
- if (showid == 0)
- {
- showid = MAX_DIALNUM - 1;
- }
- else
- {
- showid--;
- }
- DialUpdateView::GetInstance()->SetView();
- RootView::GetInstance()->Invalidate(); // 刷新界面
- }
- UNUSED(view);
return true;
}
bool DialUpdatePresenter::OnClick(UIView &view, const ClickEvent &event)
{
- // 切换表盘按键
- // if (strcmp(view.GetViewId(), "button_choose") == 0)
- // {
- // // 检查是否需要更新表盘路径
- // uint8_t currentid = g_pdialupdatemodel->GetDialConfigPath();
- // if (showid != currentid)
- // {
- // g_pdialupdatemodel->UpdateDialConfigPath(showid);
- // }
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filepath:%d || currentPath:%d ", showid, currentid);
- // NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TRANSITION_ZOOM);
- // }
// 检查点击的按钮并展示相应的表盘
- for(int i=0;i<dial_num;i++)
- {
- if (strcmp(view.GetViewId(),dialInfo_1[i].title) == 0)
- {
- g_pdialupdatemodel->UpdateDialConfigPath(i);
- NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TRANSITION_ZOOM);
- break;
- }
-
- // {
- }
- if (strcmp(view.GetViewId(), "button_right") == 0)
- {
- if (showid == MAX_DIALNUM - 1)
- {
- showid = 0;
- }
- else
- {
- showid++;
- }
- DialUpdateView::GetInstance()->SetView();
- RootView::GetInstance()->Invalidate(); // 刷新界面
- }
- else if (strcmp(view.GetViewId(), "button_left") == 0)
+ uint8_t showid = DialUpdateView::GetInstance()->GetCurrentPageId();
+ const char *viewid = view.GetViewId();
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showid %s -- viewid %s", dialInfo_1[showid].title, viewid);
+ if (strcmp(viewid, dialInfo_1[showid].title) == 0)
{
- if (showid == 0)
- {
- showid = MAX_DIALNUM - 1;
- }
- else
- {
- showid--;
- }
- DialUpdateView::GetInstance()->SetView();
- RootView::GetInstance()->Invalidate(); // 刷新界面
+ g_pdialupdatemodel->UpdateDialConfigPath(showid);
+ NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TRANSITION_ZOOM);
}
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showid:%d ", showid, showid);
+ // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showid %s -- viewid %s", dialInfo_1[showid].title, viewid);
return true;
}
void DialUpdateView::TestPicker()
{
- // /* -------------------------------- 加载展示表盘信息 -------------------------------- */
- // labelStr = dialInfo[dialId].title;
- // dialpath = dialInfo[dialId].thumbnailPath;
- // if (labelStr.empty() || dialpath.empty())
- // {
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DialInfo is error!");
- // return;
- // }
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TestPicker");
- // if (container_ == nullptr)
- // {
- // container_ = new UICardPage();
- // container_->SetPosition(0, 0, 466, 466);
- // container_->SetStyle(STYLE_BACKGROUND_OPA, 0);
- // }
- // /* -------------------------------------------------------------------------- */
- // // Add Label to App
- // if (label1_ == nullptr)
- // {
- // label1_ = new UILabel();
- // }
- // label1_->SetPosition(181, 50); // widget's left position and top position
- // label1_->Resize(200, 60); // widget's width and height
- // label1_->SetViewId("label_title"); // Set style
- // label1_->SetStyle(STYLE_TEXT_FONT, 26);
- // // Set additional property
- // label1_->SetText(labelStr.c_str());
- // label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
- // label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
- // label1_->SetRollSpeed(0);
- // label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26);
-
- // // Add to rootView
- // container_->Add(label1_);
- // label1_->SetVisible(true);
- // // Add ImageView to App
- // if (image1_ == nullptr)
- // {
- // image1_ = new UIImageView();
- // }
- // image1_->SetPosition(103, 103); // widget's left position and top position
- // image1_->Resize(100, 100); // widget's width and height
- // image1_->SetViewId("image1"); // Set style
- // // Set additional property
- // image1_->SetSrc(dialpath.c_str());
- // // Add to rootView
- // container_->Add(image1_);
- // image1_->SetVisible(true);
-
- // // Add Button to App
- // if (button3_ == nullptr)
- // {
- // button3_ = new UIButton();
- // }
- // button3_->SetPosition(103, 103); // widget's left position and top position
- // button3_->Resize(260, 260); // widget's width and height
- // button3_->SetViewId("button_choose"); // Set style
- // button3_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
- // button3_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
-
- // // Set additional property
- // button3_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED);
- // button3_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED);
- // button3_->SetStyleForState(STYLE_BORDER_COLOR, 0xfffafafa, UIButton::PRESSED);
- // button3_->SetStyleForState(STYLE_BORDER_OPA, 0x00, UIButton::PRESSED);
-
- // // Add the CallBack about events
- // UIView::OnClickListener *button3Click = static_cast<UIView::OnClickListener *>(DialUpdatePresenter::GetInstance());
- // button3_->SetOnClickListener(button3Click);
- // // Add to rootView
- // container_->Add(button3_);
- // button3_->SetVisible(true);
-
- // // Add Button to App
- // if (button1_ == nullptr)
- // {
- // button1_ = new UIButton();
- // }
- // button1_->SetPosition(402, 208); // widget's left position and top position
- // button1_->Resize(23, 50); // widget's width and height
- // button1_->SetViewId("button_right"); // Set style
- // button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
- // button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
-
- // // Set additional property
- // char *button1defaultImgSrc = "/user/res/dialupdate/right_boutton.bin";
-
- // char *button1triggeredImgSrc = nullptr;
- // button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc);
- // button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
-
- // // Add the CallBack about events
- // UIView::OnClickListener *button1Click = static_cast<UIView::OnClickListener *>(DialUpdatePresenter::GetInstance());
- // button1_->SetOnClickListener(button1Click);
- // // Add to rootView
- // container_->Add(button1_);
- // button1_->SetVisible(true);
-
- // // Add Button to App
- // if (button2_ == nullptr)
- // {
- // button2_ = new UIButton();
- // }
- // button2_->SetPosition(40, 208); // widget's left position and top position
- // button2_->Resize(23, 50); // widget's width and height
- // button2_->SetViewId("button_left"); // Set style
- // button2_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
- // button2_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
-
- // // Set additional property
- // char *button2defaultImgSrc = "/user/res/dialupdate/left_boutton.bin";
-
- // char *button2triggeredImgSrc = nullptr;
- // button2_->SetImageSrc(button2defaultImgSrc, button2triggeredImgSrc);
- // button2_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
-
- // // Add the CallBack about events
- // UIView::OnClickListener *button2Click = static_cast<UIView::OnClickListener *>(DialUpdatePresenter::GetInstance());
- // button2_->SetOnClickListener(button2Click);
- // // Add to rootView
- // container_->Add(button2_);
- // button2_->SetVisible(true);
}
-
+ int DialUpdateView::GetCurrentPageId()
+ {
+ return container_->GetCurrentPage();
+ }
void DialUpdateView::init_button()
{
- // read_dial();
- // printf_dial(); // dial_num
- uint8_t fileid = DialUpdateModel::GetInstance()->GetDialConfigPath();
- for (int i = fileid; i < dial_num + fileid; i++)
+ for (int i = 0; i < dial_num; i++)
{
- Button[i % dial_num] = new UILabelButtonExt();
+ Button[i] = new UILabelButtonExt();
if (Button == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::SystemUpgradeButtonExt new fail!");
}
- Button[i % dial_num]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetWidth());
- Button[i % dial_num]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
- Button[i % dial_num]->SetImagePosition(103, 103);
- Button[i % dial_num]->SetViewId(dialInfo_1[i % dial_num].title);
- // uint32_t resId=5|( 0xfef << 20);
- // //uint32_t resId=1|( 0xfef << 20);
- // //ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes((uint8_t*)dialInfo_1[i].dialPath,resId);
- // // std::string str="user/res/dials/KUMI.bin";
- // // FILE * fp = fopen(dialInfo_1[i].dialPath, "rb");
- // // if (fp == nullptr)
- // // {
- // // return;
- // // }
- // // ImageInfo* LoadOneInMultiRes(uint32_t resId, const std::string& file, FILE* userFP = nullptr,
- // // bool isLongTerm = false, int offset = 0);
- // ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId,dialInfo_1[i].thumbnailPath);//,fp,false,dialInfo_1[i].imageOffset);//dialInfo_1[i].dialPath);
- // if (image == nullptr) {
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAppImages %x %s fail", resId,dialInfo_1[1].thumbnailPath);
- // // return ;
- // }
- // view->SetSrc(image);
-
- // Button[i]->SetImageSrc(dialInfo_1[i].dialPath,dialInfo_1[i].dialPath);
- Button[i % dial_num]->SetImageSrc(dialInfo_1[i % dial_num].thumbnailPath, dialInfo_1[i % dial_num].thumbnailPath);
- Button[i % dial_num]->SetText(dialInfo_1[i % dial_num].title);
- Button[i % dial_num]->SetAlign(TEXT_ALIGNMENT_CENTER);
- Button[i % dial_num]->SetLabelPosition(0, -380);
- Button[i % dial_num]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
- Button[i % dial_num]->SetStyleForState(STYLE_BORDER_COLOR, Color::Black().full, UIButton::PRESSED);
- Button[i % dial_num]->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED);
+ Button[i]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetWidth());
+ Button[i]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+ Button[i]->SetImagePosition(103, 103);
+ Button[i]->SetViewId(dialInfo_1[i].title);
+
+ Button[i]->SetImageSrc(dialInfo_1[i].thumbnailPath, dialInfo_1[i].thumbnailPath);
+ Button[i]->SetText(dialInfo_1[i].title);
+ Button[i]->SetAlign(TEXT_ALIGNMENT_CENTER);
+ Button[i]->SetLabelPosition(0, -380);
+ Button[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ Button[i]->SetStyleForState(STYLE_BORDER_COLOR, Color::Black().full, UIButton::PRESSED);
+ Button[i]->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED);
UIView::OnClickListener *buttonClick = static_cast<UIView::OnClickListener *>(DialUpdatePresenter::GetInstance());
- Button[i % dial_num]->SetOnClickListener(buttonClick);
- // button2_->SetOnClickListener(button2Click);
- container_->Add(Button[i % dial_num]);
+ UIView::OnDragListener *buttondarg = static_cast<UIView::OnDragListener *>(DialUpdatePresenter::GetInstance());
+ Button[i]->SetOnClickListener(buttonClick);
+ Button[i]->SetOnDragListener(buttondarg);
+ container_->Add(Button[i]);
}
}
UICardPage *cade[10] = {nullptr};
container_->SetReboundSize(200); // 200: rebound size
container_->SetElastic(true);
}
-
init_button();
-
RootView::GetInstance()->Add(container_);
-
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSwipeGroup new fail");
-
- // container_->RegisterSwipeCallback(callback);
+ /* --------------------------------- 设置为当前表盘 -------------------------------- */
+ uint8_t fileid = DialUpdateModel::GetInstance()->GetDialConfigPath();
+ container_->SetCurrentPage(fileid);
+ container_->SetLoopState(true);
}
void DialUpdateView::OnSetUpView()
{