提交 efe76dca 编写于 作者: O openharmony_ci 提交者: Gitee

!387 修复ui_time_picker组件在修改样式属性后显示的选中值重置问题

Merge pull request !387 from JayLeeHW/master-temp
...@@ -29,7 +29,6 @@ UITimePicker::UITimePicker() ...@@ -29,7 +29,6 @@ UITimePicker::UITimePicker()
selectedSecond_{0}, selectedSecond_{0},
secVisible_(false), secVisible_(false),
loopState_{false}, loopState_{false},
setSelectedTime_(nullptr),
pickerWidth_(0), pickerWidth_(0),
itemsHeight_(0), itemsHeight_(0),
xPos_(0), xPos_(0),
...@@ -104,12 +103,7 @@ void UITimePicker::InitTimePicker() ...@@ -104,12 +103,7 @@ void UITimePicker::InitTimePicker()
minutePicker_->SetLoopState(loopState_[PICKER_MIN]); minutePicker_->SetLoopState(loopState_[PICKER_MIN]);
} }
if (setSelectedTime_ == nullptr) { RefreshSelected(selectedValue_);
const char* curTime = secVisible_ ? "00:00:00" : "00:00";
RefreshSelected(curTime);
} else {
RefreshSelected(setSelectedTime_);
}
} }
void UITimePicker::DeInitTimePicker() void UITimePicker::DeInitTimePicker()
...@@ -207,7 +201,20 @@ void UITimePicker::GetValueByIndex(char* value, uint8_t len, uint16_t index, int ...@@ -207,7 +201,20 @@ void UITimePicker::GetValueByIndex(char* value, uint8_t len, uint16_t index, int
bool UITimePicker::SetSelected(const char* value) bool UITimePicker::SetSelected(const char* value)
{ {
setSelectedTime_ = value; if (strcpy_s(selectedValue_, SELECTED_VALUE_SIZE, value) != EOK) {
return false;
}
if (secVisible_) {
if (sscanf_s(value, "%[^:]%*c%[^:]%*c%[^\n]", selectedHour_, BUF_SIZE,
selectedMinute_, BUF_SIZE, selectedSecond_, BUF_SIZE) < 3) { // 3: three variables
return false;
}
} else {
if (sscanf_s(value, "[^:]%*c%[^\n]", selectedHour_, BUF_SIZE,
selectedMinute_, BUF_SIZE) < 2) { // 2: two variables
return false;
}
}
return RefreshSelected(value); return RefreshSelected(value);
} }
......
...@@ -340,7 +340,6 @@ private: ...@@ -340,7 +340,6 @@ private:
char selectedSecond_[BUF_SIZE]; char selectedSecond_[BUF_SIZE];
bool secVisible_; bool secVisible_;
bool loopState_[PICKER_MAX]; bool loopState_[PICKER_MAX];
const char* setSelectedTime_;
uint16_t pickerWidth_; uint16_t pickerWidth_;
uint16_t itemsHeight_; uint16_t itemsHeight_;
int16_t xPos_; int16_t xPos_;
......
...@@ -47,6 +47,7 @@ void UITestUIPicker::TearDown() ...@@ -47,6 +47,7 @@ void UITestUIPicker::TearDown()
container_->Remove(setSelectBtn_); container_->Remove(setSelectBtn_);
container_->Remove(setLeftToRightBtn_); container_->Remove(setLeftToRightBtn_);
container_->Remove(setRightToLeftBtn_); container_->Remove(setRightToLeftBtn_);
container_->Remove(setMarginBtn_);
container_->Remove(selectIndex_); container_->Remove(selectIndex_);
container_->Remove(selectTime_); container_->Remove(selectTime_);
container_->Remove(picker1_); container_->Remove(picker1_);
...@@ -58,6 +59,7 @@ void UITestUIPicker::TearDown() ...@@ -58,6 +59,7 @@ void UITestUIPicker::TearDown()
setSelectBtn_ = nullptr; setSelectBtn_ = nullptr;
setLeftToRightBtn_ = nullptr; setLeftToRightBtn_ = nullptr;
setRightToLeftBtn_ = nullptr; setRightToLeftBtn_ = nullptr;
setMarginBtn_ = nullptr;
selectIndex_ = nullptr; selectIndex_ = nullptr;
selectTime_ = nullptr; selectTime_ = nullptr;
container_ = nullptr; container_ = nullptr;
...@@ -148,6 +150,9 @@ void UITestUIPicker::CreatButtons() ...@@ -148,6 +150,9 @@ void UITestUIPicker::CreatButtons()
if (setRightToLeftBtn_ == nullptr) { if (setRightToLeftBtn_ == nullptr) {
setRightToLeftBtn_ = new UILabelButton(); setRightToLeftBtn_ = new UILabelButton();
} }
if (setMarginBtn_ == nullptr) {
setMarginBtn_ = new UILabelButton();
}
} }
void UITestUIPicker::UIKit_Picker_Test_Base_002() void UITestUIPicker::UIKit_Picker_Test_Base_002()
...@@ -184,13 +189,21 @@ void UITestUIPicker::UIKit_Picker_Test_Time_Picker_001() ...@@ -184,13 +189,21 @@ void UITestUIPicker::UIKit_Picker_Test_Time_Picker_001()
container_->Add(label); container_->Add(label);
label->SetPosition(672, 0); // 672: x-coordinate label->SetPosition(672, 0); // 672: x-coordinate
label->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); label->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
container_->Add(setMarginBtn_);
setMarginBtn_->SetPosition(672, 30, 120, 30); // 672: x-coordinate, 30 : y-coordinate, 120 : width, 30 : height
setMarginBtn_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
setMarginBtn_->SetOnClickListener(this);
setMarginBtn_->SetText("增加margin");
if (picker2_ == nullptr) { if (picker2_ == nullptr) {
picker2_ = new UITimePicker(); picker2_ = new UITimePicker();
} }
picker2_->EnableSecond(true); picker2_->EnableSecond(true);
picker2_->SetPosition(652, label->GetY() + g_blank, g_ListW, g_ListH); // 652: x-coordinate picker2_->SetPosition(652, setMarginBtn_->GetY() + 40, g_ListW, g_ListH); // 652: x-coordinate, 40: offset
picker2_->SetItemHeight(50); // 50 height picker2_->SetItemHeight(50); // 50 height
picker2_->RegisterSelectedListener(this); picker2_->RegisterSelectedListener(this);
picker2_->SetSelected("12:20:30");
positionX_ = picker2_->GetWidth(); positionX_ = picker2_->GetWidth();
positionY_ = picker2_->GetY(); positionY_ = picker2_->GetY();
...@@ -217,6 +230,14 @@ bool UITestUIPicker::OnClick(UIView& view, const ClickEvent& event) ...@@ -217,6 +230,14 @@ bool UITestUIPicker::OnClick(UIView& view, const ClickEvent& event)
picker1_->SetDirect(UITextLanguageDirect::TEXT_DIRECT_LTR); picker1_->SetDirect(UITextLanguageDirect::TEXT_DIRECT_LTR);
} else if (&view == setRightToLeftBtn_) { } else if (&view == setRightToLeftBtn_) {
picker1_->SetDirect(UITextLanguageDirect::TEXT_DIRECT_RTL); picker1_->SetDirect(UITextLanguageDirect::TEXT_DIRECT_RTL);
} else if (&view == setMarginBtn_) {
picker2_->Invalidate();
picker2_->SetStyle(STYLE_MARGIN_LEFT, ++margin_);
picker2_->SetStyle(STYLE_MARGIN_RIGHT, margin_);
picker2_->SetStyle(STYLE_MARGIN_TOP, margin_);
picker2_->SetStyle(STYLE_MARGIN_BOTTOM, margin_);
picker2_->SetWidth(++g_ListW);
picker2_->Invalidate();
} }
return true; return true;
} }
......
...@@ -49,6 +49,7 @@ private: ...@@ -49,6 +49,7 @@ private:
UILabelButton* setSelectBtn_ = nullptr; UILabelButton* setSelectBtn_ = nullptr;
UILabelButton* setLeftToRightBtn_ = nullptr; UILabelButton* setLeftToRightBtn_ = nullptr;
UILabelButton* setRightToLeftBtn_ = nullptr; UILabelButton* setRightToLeftBtn_ = nullptr;
UILabelButton* setMarginBtn_ = nullptr;
UILabel* selectIndex_ = nullptr; UILabel* selectIndex_ = nullptr;
UILabel* selectTime_ = nullptr; UILabel* selectTime_ = nullptr;
UIScrollView* container_ = nullptr; UIScrollView* container_ = nullptr;
...@@ -57,6 +58,7 @@ private: ...@@ -57,6 +58,7 @@ private:
UITimePicker* picker2_ = nullptr; UITimePicker* picker2_ = nullptr;
int16_t lastX_ = 0; int16_t lastX_ = 0;
int16_t lastY_ = 0; int16_t lastY_ = 0;
int16_t margin_ = 0;
}; };
} // namespace OHOS } // namespace OHOS
#endif // UI_TEST_UI_PICKER_H #endif // UI_TEST_UI_PICKER_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册