#include "TjdUiAppStopwatchAdapter.h" #include "NativeAbility.h" #include "TjdUiAppStopwatchView.h" #include "TjdUiMultiLanguageExt.h" #include "style.h" #include "ui_checkbox.h" #include "ui_view.h" #include "sys_config.h" #define ENABLE_PRINT_INFO 1 #if ENABLE_PRINT_INFO #define static_print_info(...) sys_ui_log_i(__VA_ARGS__) //一般信息打印宏控制 #define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) //警告信息打印一般常开 #define static_print_error(...) sys_ui_log_e(__VA_ARGS__) //错误信息打印一般常开 #define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) //调试信息打印 #else #define static_print_info(...) #define static_print_warn(...) #define static_print_error(...) #define static_print_debug(...) #endif using namespace OHOS; static int16_t HorizontalCenter(int16_t width) { return (OHOS::HORIZONTAL_RESOLUTION - width) / 2; } static inline int16_t HorizontalCenter(int16_t width, int16_t parentWidth) { return (parentWidth - width) / 2; } static inline void InitLabelHorCenter(OHOS::UILabel &label, uint8_t size, int16_t y, int16_t target, const char *text) { label.SetFont(TJD_VECTOR_FONT_FILENAME, size); label.SetText(text); label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); label.SetPosition(HorizontalCenter(label.GetWidth(), target), y); } namespace TJD { class testOnClickListener : public OHOS::UIView::OnClickListener { public: testOnClickListener() {} ~testOnClickListener() {} bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { // printf("testOnClickListener::OnClick======%s======\n", view.GetViewId()); return true; }; private: int16_t index_{0}; }; // UIPicker *uiPicker1_ = nullptr; StopwatchCaseItemView::StopwatchCaseItemView(StopwatchCaseInfo &info) { SetPosition(0, 0, 400, 64); // SetStyle(OHOS::STYLE_MARGIN_TOP, 4); // SetStyle(OHOS::STYLE_MARGIN_BOTTOM, 4); SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff); SetTouchable(true); highBgView.SetPosition(0,0,400,2); highBgView.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626); lowBgView.SetPosition(0,62,400,2); lowBgView.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626); // InitLabelHorCenter(text_, 40, 15, 400, info.timeNum); text_.SetFont(TJD_VECTOR_FONT_FILENAME, 40); text_.SetText(info.timeNum.c_str()); text_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); text_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); text_.SetPosition((400-text_.GetWidth())/2, (58-text_.GetHeight())/2); Add(&text_); Add(&highBgView); Add(&lowBgView); } StopwatchCaseItemView::~StopwatchCaseItemView() { RemoveAll(); } void StopwatchCaseItemView::UpdateView(StopwatchCaseInfo &info) { SetVisible(true); // SetViewIndex(info.index); text_.SetText(info.timeNum.c_str()); text_.SetPosition((400-text_.GetWidth())/2, (58-text_.GetHeight())/2); } bool StopwatchCaseItemView::OnClickEvent(const OHOS::ClickEvent &event){ return UIView::OnClickEvent(event); } // TjdUiAppStopwatchAdapter::TjdUiAppStopwatchAdapter() {} TjdUiAppStopwatchAdapter::~TjdUiAppStopwatchAdapter() {} OHOS::UIView *TjdUiAppStopwatchAdapter::GetView(OHOS::UIView *inView, int16_t index) { OHOS::List &stopwatchList_ = TjdUiAppStopwatchView::GetInstance()->GetStopwatchItemList(); if (stopwatchList_.IsEmpty() || index > stopwatchList_.Size() - 1 || index < 0) { return nullptr; } OHOS::ListNode *node = stopwatchList_.Begin(); for (uint16_t i = 0; i < index; i++) { node = node->next_; } if (inView == nullptr) { itemView_ = new StopwatchCaseItemView(node->data_); } else { itemView_ = static_cast(inView); itemView_->UpdateView(node->data_); } itemView_->SetViewId(node->data_.timeNum.c_str()); return itemView_; } uint16_t TjdUiAppStopwatchAdapter::GetCount() { return TjdUiAppStopwatchView::GetInstance()->GetStopwatchItemList().Size(); } } // namespace TJD