#include "TjdUiAppCameraView.h" #include "NativeAbility.h" #include "TjdUiAppCameraModel.h" #include "TjdUiImageIds.h" #include "TjdUiMultiLanguageExt.h" #include "common/image_cache_manager.h" #include "dock/input_device.h" #include "notification_manager.h" #include "root_view.h" #include "sys_config.h" // #include "ble_api.h" // #include "ble_port_protocol.h" #ifdef __cplusplus extern "C" { #endif #include "ble_api.h" #include "ble_port_protocol.h" static uint8_t g_camera_server_id; static uint16_t g_camera_server_conn_id; static uint16_t g_camera_server_handle; #ifdef __cplusplus } #endif using namespace OHOS; #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 { // extern g_server_id; // extern g_server_conn_id; // extern g_server_handle; #define IMAGE_BIN_PATH TJD_IMAGE_PATH "img_camera.bin" #define IMAGE_NO_CONNECT_BIN_PATH TJD_IMAGE_PATH "img_no_connect.bin" static TjdUiAppCameraView *g_pv_AppCameraView = nullptr; static int16_t HorizontalCenter(int16_t width) { return (OHOS::HORIZONTAL_RESOLUTION - width) / 2; } static void InitLabel(OHOS::UILabel &label, uint8_t size, int16_t y, 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()), y); } // class CameraOnClickedListener : public UIView::OnClickListener // { // public: // CameraOnClickedListener() {} // virtual ~CameraOnClickedListener() {} // virtual bool OnClick(UIView &view, const ClickEvent &event) // { // if (view.GetViewId() == "take_photo") { // // OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MENU_LIST); // // OHOS::NativeAbility::GetInstance().ChangePreSlice(OHOS::TransitionType::TRANSITION_ZOOM); // const Vector2 &scale = {0.8, 0.8}; // Vector2 pivot = {100, 100}; // view.Scale(scale, pivot); // view.Invalidate(); // if (timerToClick_ == nullptr) { // timerToClick_ = new OHOS::GraphicTimer(150, TimerCallbackToClick_, &view, false); // } // timerToClick_->Start(); // static_print_info("TjdUiAppCameraView::CameraOnClickedListener::OnClick take_photo"); // // tjd_get_gatt_server_conn_handle_id(&g_camera_server_id, &g_camera_server_conn_id, // &g_camera_server_handle); // // gatts_ntf_ind_t param = {0}; // // param.attr_handle = g_camera_server_handle; // // uint8_t send_data[4] = {0x5a, 0x04, 0x0e, 0x35}; // // param.value = send_data; // // param.value_len = sizeof(send_data); // // errcode_t ret = gatts_notify_indicate(g_camera_server_id, g_camera_server_conn_id, ¶m); // // if(ret != ERRCODE_SUCC){ // // static_print_error("gatts_notify_indicate faile ret(errcode_t): %x", ret); // // } // // static_print_debug("gatts_notify_indicate success ret(errcode_t): %x", ret); // uint8 pack_head = PROTOCOL_RES_FRAME_HEAD; // tjd_ble_protocol_send_lefun_data(&pack_head,nullptr, 0 , 0x0e); // } // return true; // } // private: // }; TjdUiAppCameraView::TjdUiAppCameraView() { g_pv_AppCameraView = this; } TjdUiAppCameraView::~TjdUiAppCameraView() { g_pv_AppCameraView = nullptr; } TjdUiAppCameraView *TjdUiAppCameraView::GetInstance(void) { return g_pv_AppCameraView; } static void TimerCallback_(void *param) { TjdUiAppCameraView::GetInstance()->TimerToReturn(); } void TjdUiAppCameraView::OnStart() { static_print_debug("TjdUiAppCameraView::OnStart()"); if (container_ == nullptr) { container_ = new UIScrollView(); } groupList_[CameraView::CAMERA_TIPVIEW] = InitTipView(); groupList_[CameraView::CAMERA_LINKVIEW] = InitLinkBleView(); groupList_[CameraView::CAMERA_PHOTOVIEW] = InitCameraView(); container_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); container_->SetStyle(STYLE_BACKGROUND_OPA, 0); // container_->SetOnDragListener(&TjdUiAppCameraPresenter::GetInstance()); container_->Add(groupList_[CameraView::CAMERA_TIPVIEW]); container_->Add(groupList_[CameraView::CAMERA_LINKVIEW]); container_->Add(groupList_[CameraView::CAMERA_PHOTOVIEW]); // RootView::GetInstance()->Add(container_); AddViewToRootContainer(container_); if (tjd_get_ble_into_camera_flag()) { ShowCameraView(CameraView::CAMERA_TIPVIEW); } else if (tjd_get_ble_is_connect()) { // ShowTipView(CameraView::CAMERA_LINKVIEW); uint8_t data = 0x02; uint8_t pack_head = 0x5A; tjd_ble_protocol_send_lefun_data(&pack_head, &data, sizeof(data), ENTER_PHOTO_MODE); tjd_ble_protocol_send_lefun_data(&pack_head, &data, sizeof(data), ENTER_PHOTO_MODE); ShowCameraView(CameraView::CAMERA_TIPVIEW); } else { ShowLinkBleView(CameraView::CAMERA_TIPVIEW); if (timerToReturn_ == nullptr) { timerToReturn_ = new OHOS::GraphicTimer(2000, TimerCallback_, nullptr, false); } timerToReturn_->Start(); } } void TjdUiAppCameraView::OnStop() { printf("TjdUiAppCameraView::OnStop()\n"); TjdUiAppCameraModel::GetInstance().OpenAutoScreenOff(); // RootView::GetInstance()->Remove(container_); if (container_ != nullptr) { container_->RemoveAll(); delete container_; container_ = nullptr; } for (int i = 0; i < CAMERA_MAXTHVIEW; i++) { if (groupList_[i] == nullptr) { continue; } groupList_[i]->RemoveAll(); delete groupList_[i]; groupList_[i] = nullptr; } // if (onClickListener_ != nullptr) { // delete onClickListener_; // onClickListener_ = nullptr; // } // if (OnDragListener_ != nullptr) { // delete OnDragListener_; // OnDragListener_ = nullptr; // } if (tipView_ != nullptr) { delete tipView_; tipView_ = nullptr; } if (linkBleView_ != nullptr) { delete linkBleView_; linkBleView_ = nullptr; } if (cameraView_ != nullptr) { delete cameraView_; cameraView_ = nullptr; } if (imgCamera_cameraView != nullptr) { delete imgCamera_cameraView; imgCamera_cameraView = nullptr; } if (imgCamera_linkBleView != nullptr) { delete imgCamera_linkBleView; imgCamera_linkBleView = nullptr; } if (imgCamera_tipView != nullptr) { delete imgCamera_tipView; imgCamera_tipView = nullptr; } if (lblTip_tipView != nullptr) { delete lblTip_tipView; lblTip_tipView = nullptr; } if (lblTip_linkBleView != nullptr) { delete lblTip_linkBleView; lblTip_linkBleView = nullptr; } if (lblTitle_cameraView != nullptr) { delete lblTitle_cameraView; lblTitle_cameraView = nullptr; } if (lblTitle_tipView != nullptr) { delete lblTitle_tipView; lblTitle_tipView = nullptr; } if (timerToReturn_ != nullptr) { delete timerToReturn_; timerToReturn_ = nullptr; } // if(timerToClick_ != nullptr){ // delete timerToClick_; // timerToClick_ = nullptr; // } } void TjdUiAppCameraView::ChangedView(CameraView view, CameraView hideView) { static_print_debug("TjdUiAppCameraView::ChangedView..."); if (view >= CAMERA_MAXTHVIEW) { return; } if (viewMapper_[view] == nullptr) { return; } (GetInstance()->*viewMapper_[view])(hideView); } void TjdUiAppCameraView::TimerToReturn() { timerToReturn_->Stop(); delete timerToReturn_; timerToReturn_ = nullptr; OHOS::NativeAbility::GetInstance().ChangePreSlice(); } OHOS::UIImageView *TjdUiAppCameraView::GetImgCamera(void) { return imgCamera_cameraView; } OHOS::UIScrollView *TjdUiAppCameraView::InitTipView() { static_print_info("TjdUiAppCameraView::InitTipView()"); if (tipView_ == nullptr) { tipView_ = new UIScrollView(); } tipView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); tipView_->SetStyle(STYLE_BACKGROUND_OPA, 0); if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { tipView_->SetOnDragListener(&TjdUiAppCameraPresenter::GetInstance()); } tipView_->SetVisible(false); if (lblTitle_tipView == nullptr) { lblTitle_tipView = new UILabelExt(); } // InitLabel(*lblTitle_tipView, 28, 17, "相机"); lblTitle_tipView->SetFont(TJD_VECTOR_FONT_FILENAME, 28); lblTitle_tipView->SetTextId(STR_ID_19); lblTitle_tipView->SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); lblTitle_tipView->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); lblTitle_tipView->SetPosition(HorizontalCenter(lblTitle_tipView->GetWidth()), 17); tipView_->Add(lblTitle_tipView); if (lblTip_tipView == nullptr) { lblTip_tipView = new UILabelExt(); } // InitLabel(*lblTip_tipView, 34, 320, "请确认APP已经打开\n遥控拍照"); lblTip_tipView->SetFont(TJD_VECTOR_FONT_FILENAME, 34); lblTip_tipView->SetTextId(STR_ID_563); lblTip_tipView->SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP); lblTip_tipView->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); lblTip_tipView->SetPosition(74, 320, 319, 82); tipView_->Add(lblTip_tipView); if (imgCamera_tipView == nullptr) { imgCamera_tipView = new UIImageView(); } imgCamera_tipView->SetPosition(154, 127); imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_CAMERA_CAMERA, IMAGE_BIN_PATH); if (imgInfo != nullptr) { imgCamera_tipView->SetSrc(imgInfo); } tipView_->Add(imgCamera_tipView); return tipView_; } OHOS::UIScrollView *TjdUiAppCameraView::InitLinkBleView() { static_print_info("TjdUiAppCameraView::InitLinkBleView()"); if (linkBleView_ == nullptr) { linkBleView_ = new UIScrollView(); } linkBleView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); linkBleView_->SetStyle(STYLE_BACKGROUND_OPA, 0); linkBleView_->SetVisible(false); if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { linkBleView_->SetOnDragListener(&TjdUiAppCameraPresenter::GetInstance()); } if (lblTip_linkBleView == nullptr) { lblTip_linkBleView = new UILabelExt(); } // InitLabel(*lblTip_linkBleView, 28, 305, "请连接APP"); lblTip_linkBleView->SetFont(TJD_VECTOR_FONT_FILENAME, 28); lblTip_linkBleView->SetTextId(STR_ID_557); // lblTip_linkBleView->SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); lblTip_linkBleView->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); lblTip_linkBleView->SetPosition(0, 305, 466, 37); linkBleView_->Add(lblTip_linkBleView); if (imgCamera_linkBleView == nullptr) { imgCamera_linkBleView = new UIImageView(); } imgCamera_linkBleView->SetPosition(80, 145); imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_NO_CONNECT_NO_CONNECT, IMAGE_NO_CONNECT_BIN_PATH); if (imgInfo != nullptr) { imgCamera_linkBleView->SetSrc(imgInfo); } linkBleView_->Add(imgCamera_linkBleView); return linkBleView_; } OHOS::UIScrollView *TjdUiAppCameraView::InitCameraView() { static_print_info("TjdUiAppCameraView::InitCameraView()"); if (cameraView_ == nullptr) { cameraView_ = new UIScrollView(); } cameraView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); cameraView_->SetStyle(STYLE_BACKGROUND_OPA, 0); // cameraView_->SetOnDragListener(TjdUiAppCameraPresenter::GetInstance()); cameraView_->SetVisible(false); if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { cameraView_->SetOnDragListener(&TjdUiAppCameraPresenter::GetInstance()); } if (lblTitle_cameraView == nullptr) { lblTitle_cameraView = new UILabelExt(); } // InitLabel(*lblTitle_cameraView, 28, 17, "相机"); lblTitle_cameraView->SetFont(TJD_VECTOR_FONT_FILENAME, 28); lblTitle_cameraView->SetTextId(STR_ID_19); lblTitle_cameraView->SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); lblTitle_cameraView->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); lblTitle_cameraView->SetPosition(HorizontalCenter(lblTitle_cameraView->GetWidth()), 17); cameraView_->Add(lblTitle_cameraView); if (imgCamera_cameraView == nullptr) { imgCamera_cameraView = new UIImageView(); } imgCamera_cameraView->SetPosition(133, 133); imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_CAMERA_CAMERA_DEFAULT, IMAGE_BIN_PATH); if (imgInfo != nullptr) { imgCamera_cameraView->SetSrc(imgInfo); } imgCamera_cameraView->SetTouchable(true); imgCamera_cameraView->SetViewId("take_photo"); imgCamera_cameraView->SetOnClickListener(&TjdUiAppCameraPresenter::GetInstance()); cameraView_->Add(imgCamera_cameraView); return cameraView_; } bool TjdUiAppCameraView::ShowTipView(CameraView hideView) { static_print_info("TjdUiAppCameraView::ShowTipView()"); if (groupList_[hideView] == nullptr) { static_print_info("groupList_ is nullptr"); return false; } groupList_[hideView]->SetVisible(false); if (groupList_[CameraView::CAMERA_TIPVIEW] == nullptr) { static_print_info("groupList_ is nullptr"); return false; } groupList_[CameraView::CAMERA_TIPVIEW]->SetVisible(true); groupList_[CameraView::CAMERA_TIPVIEW]->Invalidate(); return true; } bool TjdUiAppCameraView::ShowLinkBleView(CameraView hideView) { static_print_info("TjdUiAppCameraView::ShowLinkBleView()"); if (groupList_[hideView] == nullptr) { static_print_info("groupList_ is nullptr"); return false; } groupList_[hideView]->SetVisible(false); if (groupList_[CameraView::CAMERA_LINKVIEW] == nullptr) { static_print_info("groupList_ is nullptr"); return false; } groupList_[CameraView::CAMERA_LINKVIEW]->SetVisible(true); groupList_[CameraView::CAMERA_LINKVIEW]->Invalidate(); return true; } bool TjdUiAppCameraView::ShowCameraView(CameraView hideView) { static_print_info("TjdUiAppCameraView::ShowCameraView()"); TjdUiAppCameraModel::GetInstance().CloseAutoScreenOff(); if (groupList_[hideView] == nullptr) { static_print_info("groupList_ is nullptr"); return false; } groupList_[hideView]->SetVisible(false); if (groupList_[CameraView::CAMERA_PHOTOVIEW] == nullptr) { static_print_info("groupList_ is nullptr"); return false; } groupList_[CameraView::CAMERA_PHOTOVIEW]->SetVisible(true); groupList_[CameraView::CAMERA_PHOTOVIEW]->Invalidate(); return true; } #pragma 相机弹窗 CameraPopupWindow::CameraPopupWindow() { static_print_info("CameraPopupWindow\n"); SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); SetStyle(STYLE_BACKGROUND_OPA, 255); // SetOnDragListener(TjdUiAppCameraPresenter::GetInstance()); SetTouchable(true); SetDraggable(true); SetOnDragListener(this); InitLabel(lblTitle_, 28, 17, "相机"); Add(&lblTitle_); imgCamera_.SetPosition(133, 133); auto imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_CAMERA_CAMERA_DEFAULT, IMAGE_BIN_PATH); if (imgInfo != nullptr) { imgCamera_.SetSrc(imgInfo); } imgCamera_.SetTouchable(true); imgCamera_.SetViewId("take_photo"); imgCamera_.SetOnClickListener(&TjdUiAppCameraPresenter::GetInstance()); Add(&imgCamera_); } CameraPopupWindow::~CameraPopupWindow() { RemoveAll(); } bool CameraPopupWindow::OnKeyAct(UIView &view, const KeyEvent &event) { static_print_info("cxin CameraPopupWindow::OnKeyAct\n"); if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) { return true; } if (event.GetState() == OHOS::InputDevice::STATE_RELEASE) { CameraViewExitEvent(); return true; } return false; } void CameraPopupWindow::ScreenDragEventCallback(OHOS::UIView &view, const OHOS::DragEvent &event) { static_print_info("cxin ScreenDragEventCallback\n"); CameraViewExitEvent(); } void CameraViewExitEvent() { extern OHOS::GraphicTimer *timerToClick_; if (timerToClick_ != nullptr) { timerToClick_->Stop(); delete timerToClick_; timerToClick_ = nullptr; } gatts_send_to_app(); NotificationManager::GetInstance()->StopNotify(); TjdUiAppCameraModel::GetInstance().OpenAutoScreenOff(); } } // namespace TJD // void tjd_into_photo(void) // { // OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_CAMERA); // }