346 lines
12 KiB
C++
346 lines
12 KiB
C++
#include "TjdUiAppLockScreenView.h"
|
|
#include "TjdUiAppLockScreenPresenter.h"
|
|
#include "TjdUiImageIds.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "TjdUiScreenEvent.h"
|
|
#include "common/image_cache_manager.h"
|
|
#include "gfx_utils/mem_check.h"
|
|
#include "graphic_service.h"
|
|
#include "hal_tick.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
|
|
|
|
namespace TJD {
|
|
|
|
using namespace OHOS;
|
|
|
|
#define LOCKSCREEN_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_lockscreen.bin"
|
|
static int16_t lastTime_{0};
|
|
static TjdUiAppLockScreenView *g_TjdUiAppLockScreenView = nullptr;
|
|
static LockScreenView *g_LockScreenView = nullptr;
|
|
static UnlockScreenView *g_UnlockScreenView = nullptr;
|
|
LockScreenViewIndex TjdUiAppLockScreenView::currentViewIndex_ = LockScreen_VIEW_COUNT;
|
|
static OHOS::ImageInfo *g_pv_lockscreenimageInfo[LockScreenViewIndex::LockScreen_VIEW_COUNT]{nullptr};
|
|
static uint8_t value = 0;
|
|
static void TimerStartCallback_(void *param)
|
|
{
|
|
value += 1;
|
|
GraphicService::GetInstance()->PostGraphicEvent(std::bind(
|
|
[](void *param) {
|
|
if (value < 100)
|
|
LockScreenView::GetInstance()->Drawcircle(value);
|
|
else {
|
|
TjdUiAppLockScreenView *lockScreenView = TjdUiAppLockScreenView::GetInstance();
|
|
lockScreenView->timerStart_->Stop();
|
|
lockScreenView->ShowView(UnlockDone_VIEW);
|
|
lockScreenView->StartJumpTimer();
|
|
}
|
|
},
|
|
param));
|
|
}
|
|
|
|
TjdUiAppLockScreenView::TjdUiAppLockScreenView()
|
|
{
|
|
g_TjdUiAppLockScreenView = this;
|
|
SetPosition(0, 0, 466, 466);
|
|
SetViewId("LockScreenView");
|
|
InitLockScreenImage();
|
|
if (mainView_ == nullptr) {
|
|
mainView_ = new UIViewGroup();
|
|
}
|
|
|
|
mainView_->SetPosition(0, 0, 466, 466);
|
|
|
|
lockscreenView[LockScreen_Start_VIEW] = new LockScreenView();
|
|
mainView_->Add(lockscreenView[LockScreen_Start_VIEW]);
|
|
Add(mainView_);
|
|
ShowView(LockScreen_Start_VIEW);
|
|
}
|
|
|
|
void TjdUiAppLockScreenView::TimerStart()
|
|
{
|
|
if (timerStart_ == nullptr) {
|
|
timerStart_ = new OHOS::GraphicTimer(30, TimerStartCallback_, nullptr, true);
|
|
}
|
|
value = 0;
|
|
timerStart_->Start();
|
|
}
|
|
|
|
void TjdUiAppLockScreenView::TimerStop()
|
|
{
|
|
value = 0;
|
|
LockScreenView::GetInstance()->circleProgress1_.SetValue(value);
|
|
// timerStart_->Stop();
|
|
}
|
|
|
|
void TjdUiAppLockScreenView::InitTargetView(LockScreenViewIndex viewIndex)
|
|
{
|
|
if (lockscreenView[viewIndex] != nullptr)
|
|
return;
|
|
|
|
switch (viewIndex) {
|
|
case LockScreen_Start_VIEW:
|
|
lockscreenView[viewIndex] = new LockScreenView();
|
|
break;
|
|
case UnlockDone_VIEW:
|
|
lockscreenView[viewIndex] = new UnlockScreenView();
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (lockscreenView[viewIndex] == nullptr)
|
|
return;
|
|
|
|
lockscreenView[viewIndex]->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
mainView_->Add(lockscreenView[viewIndex]);
|
|
}
|
|
|
|
void TjdUiAppLockScreenView::ShowView(LockScreenViewIndex showView)
|
|
{
|
|
if (showView < 0 || showView >= LockScreen_VIEW_COUNT) {
|
|
return;
|
|
}
|
|
|
|
InitTargetView(showView);
|
|
|
|
if (currentViewIndex_ >= 0 && currentViewIndex_ < LockScreen_VIEW_COUNT &&
|
|
lockscreenView[currentViewIndex_] != nullptr) {
|
|
lockscreenView[currentViewIndex_]->HideView();
|
|
}
|
|
|
|
if (lockscreenView[showView] != nullptr) {
|
|
lockscreenView[showView]->ShowView();
|
|
}
|
|
|
|
currentViewIndex_ = showView;
|
|
}
|
|
|
|
TjdUiAppLockScreenView *TjdUiAppLockScreenView::GetInstance(void) { return g_TjdUiAppLockScreenView; }
|
|
|
|
TjdUiAppLockScreenView::~TjdUiAppLockScreenView()
|
|
{
|
|
ImageCacheManager::GetInstance().UnloadAllInMultiRes(LOCKSCREEN_IMAGE_BIN_PATH);
|
|
|
|
mainView_->RemoveAll();
|
|
for (int i = 0; i < LockScreen_VIEW_COUNT; i++) {
|
|
if (lockscreenView[i] != nullptr) {
|
|
delete lockscreenView[i];
|
|
lockscreenView[i] = nullptr;
|
|
}
|
|
}
|
|
|
|
RemoveAll();
|
|
if (mainView_ != nullptr) {
|
|
delete mainView_;
|
|
mainView_ = nullptr;
|
|
}
|
|
// RootView::GetInstance()->RemoveSystemView(this);
|
|
}
|
|
|
|
void TjdUiAppLockScreenView::InitLockScreenImage()
|
|
{
|
|
g_pv_lockscreenimageInfo[LockScreenViewIndex::LockScreen_Start_VIEW] =
|
|
OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_LOCKSCREEN_LOCK_01, LOCKSCREEN_IMAGE_BIN_PATH);
|
|
g_pv_lockscreenimageInfo[LockScreenViewIndex::UnlockDone_VIEW] =
|
|
OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_LOCKSCREEN_LOCK_02, LOCKSCREEN_IMAGE_BIN_PATH);
|
|
g_pv_lockscreenimageInfo[LockScreenViewIndex::LockScreen_Crown_VIEW] =
|
|
OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_LOCKSCREEN_LOCK_03, LOCKSCREEN_IMAGE_BIN_PATH);
|
|
}
|
|
|
|
void TjdUiAppLockScreenView::StartJumpTimer()
|
|
{
|
|
if (jumpTimerId_ == nullptr) {
|
|
jumpTimerId_ = osTimerNew(
|
|
[](void *arg) {
|
|
// TjdUiAppLockScreenView *view = TjdUiAppLockScreenView::GetInstance();
|
|
// if (view == nullptr) {
|
|
// return;
|
|
// }
|
|
// OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN);//会重新回到快捷栏
|
|
SetLockScreenEnable(false);
|
|
TjdUiScreenEventSuccessEvent();
|
|
},
|
|
osTimerOnce, nullptr, nullptr);
|
|
if (jumpTimerId_ == nullptr) {
|
|
sys_ui_log_e("TjdUiAppLockScreenView::jumpTimerId_ Create timer fail.");
|
|
return;
|
|
}
|
|
}
|
|
int ret = osTimerStart(jumpTimerId_, 1500);
|
|
|
|
if (ret != 0) {
|
|
sys_ui_log_e("TjdUiAppLockScreenView::AlipayStartBind Start timer fail");
|
|
return;
|
|
}
|
|
}
|
|
|
|
void LockScreenAnimatorCallback::Callback(OHOS::UIView *view)
|
|
{
|
|
LockScreenView *lockScreenView = static_cast<LockScreenView *>(view);
|
|
if (HALTick::GetInstance().GetTime() - lastTime_ >= 30) {
|
|
lastTime_ = HALTick::GetInstance().GetTime();
|
|
value += 1;
|
|
|
|
if (value < 100)
|
|
LockScreenView::GetInstance()->Drawcircle(value);
|
|
else {
|
|
TjdUiAppLockScreenView *lockScreenMainView = TjdUiAppLockScreenView::GetInstance();
|
|
lockScreenView->lockScreenAnimator_->Stop();
|
|
lockScreenMainView->ShowView(UnlockDone_VIEW);
|
|
lockScreenMainView->StartJumpTimer();
|
|
}
|
|
}
|
|
}
|
|
|
|
void LockScreenAnimatorCallback::OnStop(OHOS::UIView &view)
|
|
{
|
|
value = 0;
|
|
LockScreenView::GetInstance()->circleProgress1_.SetValue(value);
|
|
}
|
|
|
|
LockScreenView::LockScreenView()
|
|
{
|
|
g_LockScreenView = this;
|
|
SetPosition(0, 0, 466, 466);
|
|
SetTouchable(true);
|
|
SetDraggable(true);
|
|
|
|
lockscreenstart_.SetPosition(150, 118, 166, 166);
|
|
lockscreenstart_.SetViewId(LOCKSCREEN_ID);
|
|
if (g_pv_lockscreenimageInfo[LockScreenViewIndex::LockScreen_Start_VIEW] != nullptr) {
|
|
lockscreenstart_.SetSrc(g_pv_lockscreenimageInfo[LockScreenViewIndex::LockScreen_Start_VIEW]);
|
|
}
|
|
|
|
lockcrown_.SetPosition(391, 93, 43, 60);
|
|
if (g_pv_lockscreenimageInfo[LockScreenViewIndex::LockScreen_Crown_VIEW] != nullptr) {
|
|
lockcrown_.SetSrc(g_pv_lockscreenimageInfo[LockScreenViewIndex::LockScreen_Crown_VIEW]);
|
|
}
|
|
|
|
lblLockScr_.SetFont(TJD_VECTOR_FONT_FILENAME, 30);
|
|
lblLockScr_.SetTextId(STR_ID_77);
|
|
// lblLockScr_.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
lblLockScr_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
lblLockScr_.SetPosition(0, 311,466,42);
|
|
|
|
lblLockTip_.SetFont(TJD_VECTOR_FONT_FILENAME, 30);
|
|
lblLockTip_.SetTextId(STR_ID_79);
|
|
lblLockTip_.SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
|
|
lblLockTip_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
lblLockTip_.SetPosition(66, 353,334,42);
|
|
|
|
circleProgress1_.SetPosition(150, 118);
|
|
circleProgress1_.Resize(166, 166);
|
|
circleProgress1_.SetViewId("circleProgress1");
|
|
circleProgress1_.SetStyle(STYLE_BACKGROUND_OPA, 0x00);
|
|
circleProgress1_.SetBackgroundStyle(STYLE_LINE_WIDTH, 6);
|
|
circleProgress1_.SetBackgroundStyle(STYLE_LINE_HEIGHT, 6);
|
|
circleProgress1_.SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff968b8b);
|
|
circleProgress1_.SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6);
|
|
circleProgress1_.SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000);
|
|
circleProgress1_.SetForegroundStyle(STYLE_LINE_COLOR, 0xffffffff);
|
|
circleProgress1_.SetForegroundStyle(STYLE_LINE_WIDTH, 6);
|
|
circleProgress1_.SetCenterPosition(83, 83);
|
|
circleProgress1_.SetRadius(83);
|
|
circleProgress1_.SetEndAngle(359);
|
|
circleProgress1_.SetValue(0);
|
|
|
|
lockScreenCallback_ = new LockScreenAnimatorCallback();
|
|
lockScreenAnimator_ = new Animator(lockScreenCallback_, this, 0, true);
|
|
|
|
Add(&lockscreenstart_);
|
|
Add(&lockcrown_);
|
|
Add(&lblLockScr_);
|
|
Add(&lblLockTip_);
|
|
Add(&circleProgress1_);
|
|
}
|
|
|
|
LockScreenView *LockScreenView::GetInstance(void) { return g_LockScreenView; }
|
|
|
|
void LockScreenView::Drawcircle(uint8_t val) { circleProgress1_.SetValue(val); }
|
|
|
|
void LockScreenView::ShowView()
|
|
{
|
|
value = 0;
|
|
lastTime_ = HALTick::GetInstance().GetTime();
|
|
SetVisible(true);
|
|
}
|
|
|
|
void LockScreenView::HideView() { SetVisible(false); }
|
|
|
|
LockScreenView::~LockScreenView()
|
|
{
|
|
if (lockScreenCallback_ != nullptr) {
|
|
delete lockScreenCallback_;
|
|
lockScreenCallback_ = nullptr;
|
|
}
|
|
|
|
if (lockScreenAnimator_ != nullptr) {
|
|
delete lockScreenAnimator_;
|
|
lockScreenAnimator_ = nullptr;
|
|
}
|
|
g_LockScreenView = nullptr;
|
|
RemoveAll();
|
|
}
|
|
|
|
UnlockScreenView::UnlockScreenView()
|
|
{
|
|
g_UnlockScreenView = this;
|
|
SetPosition(0, 0, 466, 466);
|
|
|
|
unlockscreendone_.SetPosition(150, 118, 166, 166);
|
|
unlockscreendone_.SetViewId(UNLOCKDONE_ID);
|
|
if (g_pv_lockscreenimageInfo[LockScreenViewIndex::UnlockDone_VIEW] != nullptr) {
|
|
unlockscreendone_.SetSrc(g_pv_lockscreenimageInfo[LockScreenViewIndex::UnlockDone_VIEW]);
|
|
}
|
|
|
|
lblUnlockDone_.SetFont(TJD_VECTOR_FONT_FILENAME, 30);
|
|
// lblUnlockDone_.SetText("已解锁");
|
|
lblUnlockDone_.SetTextId(STR_ID_78);
|
|
lblUnlockDone_.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
lblUnlockDone_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
lblUnlockDone_.SetPosition(((466 - lblUnlockDone_.GetWidth()) / 2), 311);
|
|
|
|
circleProgress2_.SetPosition(150, 118);
|
|
circleProgress2_.Resize(166, 166);
|
|
circleProgress2_.SetViewId("circleProgress2");
|
|
circleProgress2_.SetStyle(STYLE_BACKGROUND_OPA, 0x00);
|
|
circleProgress2_.SetBackgroundStyle(STYLE_LINE_WIDTH, 6);
|
|
circleProgress2_.SetBackgroundStyle(STYLE_LINE_HEIGHT, 6);
|
|
circleProgress2_.SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff968b8b);
|
|
circleProgress2_.SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6);
|
|
circleProgress2_.SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000);
|
|
circleProgress2_.SetForegroundStyle(STYLE_LINE_COLOR, 0xffffffff);
|
|
circleProgress2_.SetForegroundStyle(STYLE_LINE_WIDTH, 6);
|
|
circleProgress2_.SetCenterPosition(83, 83);
|
|
circleProgress2_.SetRadius(83);
|
|
circleProgress2_.SetEndAngle(359);
|
|
circleProgress2_.SetValue(100);
|
|
|
|
Add(&unlockscreendone_);
|
|
Add(&lblUnlockDone_);
|
|
Add(&circleProgress2_);
|
|
}
|
|
|
|
UnlockScreenView *UnlockScreenView::GetInstance(void) { return g_UnlockScreenView; }
|
|
|
|
UnlockScreenView::~UnlockScreenView()
|
|
{
|
|
g_UnlockScreenView = nullptr;
|
|
RemoveAll();
|
|
}
|
|
|
|
} // namespace TJD
|