244 lines
7.0 KiB
C++
244 lines
7.0 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description:
|
|
*
|
|
* Author: wuchangxin
|
|
*
|
|
* Create: 2024-8-24
|
|
*--------------------------------------------------------------------------*/
|
|
#ifndef TJD_UI_APP_TIMER_VIEW_H
|
|
#define TJD_UI_APP_TIMER_VIEW_H
|
|
|
|
#include "TjdUiAppTimerPresenter.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "View.h"
|
|
#include "components/ui_button.h"
|
|
#include "components/ui_checkbox.h"
|
|
#include "components/ui_circle_progress.h"
|
|
#include "components/ui_edit_text.h"
|
|
#include "components/ui_image_animator.h"
|
|
#include "components/ui_image_view.h"
|
|
#include "components/ui_label.h"
|
|
#include "components/ui_label_ext.h"
|
|
#include "components/ui_list.h"
|
|
#include "components/ui_picker.h"
|
|
#include "components/ui_scroll_view.h"
|
|
#include "components/ui_scroll_view_nested.h"
|
|
#include "components/ui_slider.h"
|
|
#include "components/ui_swipe_view.h"
|
|
#include "components/ui_view_group.h"
|
|
#include <iostream>
|
|
#include <list>
|
|
namespace TJD {
|
|
|
|
#define MAX_TIMER 8
|
|
|
|
struct TimerPickerInfo
|
|
{
|
|
char *time;
|
|
uint16_t textId;
|
|
};
|
|
|
|
struct TimerInfo
|
|
{
|
|
int hours;
|
|
int minutes;
|
|
int seconds;
|
|
};
|
|
|
|
enum TimerViewIndex
|
|
{
|
|
TIMER_MAIN_VIEW = 0,
|
|
TIMER_RUNNING_VIEW,
|
|
TIMER_CUSTOM_SETTING_VIEW,
|
|
TIMER_VIEW_MAX
|
|
};
|
|
|
|
extern bool GetTimerStatus();
|
|
|
|
class TimerViewBase : public OHOS::UIScrollViewNested
|
|
{
|
|
public:
|
|
TimerViewBase() { SetHorizontalScrollState(false); }
|
|
virtual ~TimerViewBase() {}
|
|
virtual void ShowView() { SetVisible(true); };
|
|
virtual void HideView() { SetVisible(false); };
|
|
};
|
|
|
|
class TimerUIScrollView : public OHOS::UIScrollViewNested
|
|
{
|
|
public:
|
|
TimerUIScrollView() {}
|
|
~TimerUIScrollView() {}
|
|
bool OnDragStartEvent(const OHOS::DragEvent &event) override;
|
|
bool OnDragEvent(const OHOS::DragEvent &event) override;
|
|
bool OnDragEndEvent(const OHOS::DragEvent &event) override;
|
|
|
|
private:
|
|
bool isOnStart_{false};
|
|
};
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// 类名: TimerViewOnListener
|
|
// 描述: 监听计时器界面按钮点击事件
|
|
// ----------------------------------------------------------------------------
|
|
static OHOS::GraphicTimer *timerIsRunningTimer_ = nullptr;
|
|
class TimerViewOnListener : public OHOS::UIView::OnClickListener
|
|
{ // 主监听器
|
|
public:
|
|
~TimerViewOnListener()
|
|
{
|
|
if (timerIsRunningTimer_ != nullptr) {
|
|
timerIsRunningTimer_->Stop();
|
|
delete timerIsRunningTimer_;
|
|
timerIsRunningTimer_ = nullptr;
|
|
}
|
|
}
|
|
virtual bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event);
|
|
|
|
private:
|
|
};
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// 类名: TimerMainView
|
|
// 描述: 计时器主界面
|
|
// ----------------------------------------------------------------------------
|
|
class TimerPickerOnListener : public OHOS::UIView::OnClickListener
|
|
{
|
|
public:
|
|
virtual bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event);
|
|
};
|
|
|
|
class TimerPicker : public OHOS::UIViewGroup
|
|
{
|
|
public:
|
|
TimerPicker(TimerPickerInfo &info);
|
|
~TimerPicker() { RemoveAll(); };
|
|
|
|
private:
|
|
TimerPickerOnListener timerPickerOnListener;
|
|
OHOS::UIImageView timerPickerBg_;
|
|
OHOS::UILabel time_;
|
|
OHOS::UILabelExt unit_;
|
|
};
|
|
|
|
class TimerMainView : public TimerViewBase
|
|
{
|
|
public:
|
|
TimerMainView();
|
|
~TimerMainView();
|
|
void ShowView();
|
|
|
|
private:
|
|
OHOS::UILabelExt mainViewTitle_;
|
|
TimerPicker *timerPicker_[MAX_TIMER];
|
|
OHOS::UIView customBg_;
|
|
OHOS::UILabelExt customLabel_;
|
|
OHOS::UIView mainViewBg_;
|
|
TimerViewOnListener timerMainViewListener;
|
|
};
|
|
|
|
static void TimerCallBack(void *arg);
|
|
static void TimerIsRunningTimerCallBack(void *arg);
|
|
// ----------------------------------------------------------------------------
|
|
// 类名: TimerRunningView
|
|
// 描述: 计时中界面
|
|
// ----------------------------------------------------------------------------
|
|
class TimerRunningView : public TimerViewBase
|
|
{
|
|
public:
|
|
TimerRunningView();
|
|
~TimerRunningView();
|
|
void InitView();
|
|
void InitView(TimerInfo &curTime);
|
|
static TimerRunningView *GetInstance();
|
|
void UpdateInfo(uint64_t Value);
|
|
void ShowView();
|
|
void HideView();
|
|
TimerInfo ExtractTime(const std::string &timeStr);
|
|
|
|
OHOS::UILabel *GetCountDownLabel() { return &countDownLabel_; }
|
|
OHOS::UILabel *GetRemindLabel() { return &remindLabel_; }
|
|
void CreateRunningTimer();
|
|
|
|
uint64_t lastTime; // 保存上一次时间
|
|
uint8_t touchTimerIndex_ = MAX_TIMER; // 当前选择的定时器下标
|
|
private:
|
|
OHOS::UILabelExt targetLabel_; // 目标时间
|
|
OHOS::UILabel countDownLabel_; // 倒计时
|
|
OHOS::UILabelExt remindLabel_; // 提醒
|
|
OHOS::UILabelExt endingLabel_; // 提醒
|
|
OHOS::UICircleProgress countDownProgress_; // 倒计时进度条
|
|
OHOS::UIImageView imgCancel_;
|
|
OHOS::UICheckBox PauseOrContinueBox_;
|
|
OHOS::UIImageView imgRefresh_;
|
|
TimerViewOnListener timerRunningViewOnListener;
|
|
};
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// 类名: TimerCustomSettingiew
|
|
// 描述: 自定义计时设置
|
|
// ----------------------------------------------------------------------------
|
|
class TimerCustomSettingiew : public TimerViewBase
|
|
{
|
|
public:
|
|
TimerCustomSettingiew();
|
|
~TimerCustomSettingiew();
|
|
static TimerCustomSettingiew *GetInstance(void);
|
|
void ShowView();
|
|
void HideView();
|
|
void SelectPicker(OHOS::UIPicker *selectPicker);
|
|
TimerInfo GetPickerSelectedTime()
|
|
{
|
|
TimerInfo info;
|
|
info.hours = hourPicker_.GetSelected();
|
|
info.minutes = minutePicker_.GetSelected();
|
|
info.seconds = secPicker_.GetSelected();
|
|
return info;
|
|
}
|
|
|
|
private:
|
|
class PickerSelectListener : public UIView::OnTouchListener
|
|
{
|
|
public:
|
|
bool OnPress(UIView &view, const OHOS::PressEvent &event) override;
|
|
bool OnCancel(UIView &view, const OHOS::CancelEvent &event) override;
|
|
};
|
|
PickerSelectListener pickerSelectListener_;
|
|
OHOS::UIImageView imgConfirm_;
|
|
OHOS::UIImageView imgCancel_;
|
|
OHOS::UIImageView imgTimeGap_[2]; // 时间间隔符:
|
|
OHOS::UILabelExt hourUnit_;
|
|
OHOS::UILabelExt minuteUnit_;
|
|
OHOS::UILabelExt secUnit_;
|
|
OHOS::UIPicker hourPicker_;
|
|
OHOS::UIPicker minutePicker_;
|
|
OHOS::UIPicker secPicker_;
|
|
OHOS::UIPicker *lastPicker_{nullptr};
|
|
TimerViewOnListener CustomSettingViewOnListener;
|
|
};
|
|
|
|
class TjdUiAppTimerPresenter;
|
|
class TjdUiAppTimerView : public OHOS::View<TjdUiAppTimerPresenter>
|
|
{
|
|
public:
|
|
TjdUiAppTimerView();
|
|
~TjdUiAppTimerView();
|
|
static TjdUiAppTimerView *GetInstance(void);
|
|
void OnStart() override;
|
|
void OnStop() override;
|
|
|
|
void ShowView(TimerViewIndex showIndex);
|
|
static TimerViewIndex currentViewIndex_;
|
|
|
|
private:
|
|
void InitTargetView(TimerViewIndex index);
|
|
|
|
TimerUIScrollView *mainView_{nullptr};
|
|
TimerViewBase *viewManager_[TIMER_VIEW_MAX]{nullptr};
|
|
};
|
|
|
|
} // namespace TJD
|
|
|
|
#endif |