提交 36736e4a 编写于 作者: L liqiang

fix ui_time_picker reset value bug.

Change-Id: I3ad09f4078ede999953edc2378ca781883c12e3f
Signed-off-by: Nliqiang <liqiang121@huawei.com>
上级 9f9f18e8
......@@ -29,7 +29,6 @@ UITimePicker::UITimePicker()
selectedSecond_{0},
secVisible_(false),
loopState_{false},
setSelectedTime_(nullptr),
pickerWidth_(0),
itemsHeight_(0),
xPos_(0),
......@@ -104,12 +103,7 @@ void UITimePicker::InitTimePicker()
minutePicker_->SetLoopState(loopState_[PICKER_MIN]);
}
if (setSelectedTime_ == nullptr) {
const char* curTime = secVisible_ ? "00:00:00" : "00:00";
RefreshSelected(curTime);
} else {
RefreshSelected(setSelectedTime_);
}
RefreshSelected(selectedValue_);
}
void UITimePicker::DeInitTimePicker()
......@@ -207,7 +201,20 @@ void UITimePicker::GetValueByIndex(char* value, uint8_t len, uint16_t index, int
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);
}
......
......@@ -340,7 +340,6 @@ private:
char selectedSecond_[BUF_SIZE];
bool secVisible_;
bool loopState_[PICKER_MAX];
const char* setSelectedTime_;
uint16_t pickerWidth_;
uint16_t itemsHeight_;
int16_t xPos_;
......
......@@ -47,6 +47,7 @@ void UITestUIPicker::TearDown()
container_->Remove(setSelectBtn_);
container_->Remove(setLeftToRightBtn_);
container_->Remove(setRightToLeftBtn_);
container_->Remove(setMarginBtn_);
container_->Remove(selectIndex_);
container_->Remove(selectTime_);
container_->Remove(picker1_);
......@@ -58,6 +59,7 @@ void UITestUIPicker::TearDown()
setSelectBtn_ = nullptr;
setLeftToRightBtn_ = nullptr;
setRightToLeftBtn_ = nullptr;
setMarginBtn_ = nullptr;
selectIndex_ = nullptr;
selectTime_ = nullptr;
container_ = nullptr;
......@@ -148,6 +150,9 @@ void UITestUIPicker::CreatButtons()
if (setRightToLeftBtn_ == nullptr) {
setRightToLeftBtn_ = new UILabelButton();
}
if (setMarginBtn_ == nullptr) {
setMarginBtn_ = new UILabelButton();
}
}
void UITestUIPicker::UIKit_Picker_Test_Base_002()
......@@ -184,13 +189,21 @@ void UITestUIPicker::UIKit_Picker_Test_Time_Picker_001()
container_->Add(label);
label->SetPosition(672, 0); // 672: x-coordinate
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) {
picker2_ = new UITimePicker();
}
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_->RegisterSelectedListener(this);
picker2_->SetSelected("12:20:30");
positionX_ = picker2_->GetWidth();
positionY_ = picker2_->GetY();
......@@ -217,6 +230,14 @@ bool UITestUIPicker::OnClick(UIView& view, const ClickEvent& event)
picker1_->SetDirect(UITextLanguageDirect::TEXT_DIRECT_LTR);
} else if (&view == setRightToLeftBtn_) {
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;
}
......
......@@ -49,6 +49,7 @@ private:
UILabelButton* setSelectBtn_ = nullptr;
UILabelButton* setLeftToRightBtn_ = nullptr;
UILabelButton* setRightToLeftBtn_ = nullptr;
UILabelButton* setMarginBtn_ = nullptr;
UILabel* selectIndex_ = nullptr;
UILabel* selectTime_ = nullptr;
UIScrollView* container_ = nullptr;
......@@ -57,6 +58,7 @@ private:
UITimePicker* picker2_ = nullptr;
int16_t lastX_ = 0;
int16_t lastY_ = 0;
int16_t margin_ = 0;
};
} // namespace OHOS
#endif // UI_TEST_UI_PICKER_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册