navibar.cc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. #pragma once
  2. #include "uart/ProtocolSender.h"
  3. #include <sys/reboot.h>
  4. #include "app/Activity.h"
  5. #include "service/BusinessConfig.h"
  6. #include "net/NetManager.h"
  7. #include "core/sip_config.h"
  8. #include "core/utilities.h"
  9. /*
  10. *此文件由GUI工具生成
  11. *文件功能:用于处理用户的逻辑相应代码
  12. *功能说明:
  13. *========================onButtonClick_XXXX
  14. 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[标识]名称,
  15. 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK.
  16. *========================onSlideWindowItemClick_XXXX(int index)
  17. 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[标识]名称,
  18. 如slideWindow1;index 代表按下图标的偏移值
  19. *========================onSeekBarChange_XXXX(int progress)
  20. 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[标识]名称,
  21. 如SeekBar1;progress 代表当前的进度值
  22. *========================ogetListItemCount_XXXX()
  23. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[标识]名称,
  24. 如List1;返回值为当前列表的总条数
  25. *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index)
  26. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[标识]名称,
  27. 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明
  28. *========================常用接口===============
  29. *LOGD(...) 打印调试信息的接口
  30. *mTextXXX->setText("****") 在控件TextXXX上显示文字****
  31. *mButton1->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色
  32. *mSeekBar->setProgress(12) 在控件mSeekBar上将进度调整到12
  33. *mListView1->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用
  34. *mDashbroadView1->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度
  35. */
  36. static uint32_t navibarButtonColor = buleDeepColour;
  37. static bool isNursing2 = false;
  38. static int blueCodeId = 0;
  39. static string blueCodeTid = "";
  40. void setNavibarTheme() {
  41. int themeInt = StoragePreferences::getInt(STORE_THEME, defaultThemeInt);
  42. if (themeInt == 1) {
  43. mBgPainterPtr->setBackgroundPic("/navibar/bg.png");
  44. mHelpButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "/button/square_bule.png");
  45. navibarButtonColor = buleDeepColour;
  46. mHomeButtonPtr->setTextColor(navibarButtonColor);
  47. }
  48. else if (themeInt == 2) {
  49. mBgPainterPtr->setBackgroundPic("/navibar/bg-pink.png");
  50. mHelpButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "/button/square_pink.png");
  51. navibarButtonColor = redDeepColour;
  52. mHomeButtonPtr->setTextColor(navibarButtonColor);
  53. }
  54. }
  55. void goHome() {
  56. mHomeButtonPtr->setBackgroundPic("button/elliptic_white.png");
  57. mHomeButtonPtr->setTextColor(navibarButtonColor);
  58. mHealthCareButtonPtr->setBackgroundPic("");
  59. mHealthCareButtonPtr->setTextColor(whiteColour);
  60. mMoreButtonPtr->setBackgroundPic("");
  61. mMoreButtonPtr->setTextColor(whiteColour);
  62. EASYUICONTEXT->openActivity("mainActivity");
  63. EASYUICONTEXT->closeActivity("moreActivity");
  64. EASYUICONTEXT->closeActivity("medicalCareActivity");
  65. }
  66. void goMore() {
  67. mHomeButtonPtr->setBackgroundPic("");
  68. mHomeButtonPtr->setTextColor(whiteColour);
  69. mHealthCareButtonPtr->setBackgroundPic("");
  70. mHealthCareButtonPtr->setTextColor(whiteColour);
  71. mMoreButtonPtr->setBackgroundPic("button/elliptic_white.png");
  72. mMoreButtonPtr->setTextColor(navibarButtonColor);
  73. EASYUICONTEXT->openActivity("moreActivity");
  74. // EASYUICONTEXT->closeActivity("mainActivity");
  75. EASYUICONTEXT->closeActivity("medicalCareActivity");
  76. }
  77. void goCare() {
  78. mHomeButtonPtr->setBackgroundPic("");
  79. mHomeButtonPtr->setTextColor(whiteColour);
  80. mHealthCareButtonPtr->setBackgroundPic("button/elliptic_white.png");
  81. mHealthCareButtonPtr->setTextColor(navibarButtonColor);
  82. mMoreButtonPtr->setBackgroundPic("");
  83. mMoreButtonPtr->setTextColor(whiteColour);
  84. EASYUICONTEXT->openActivity("medicalCareActivity");
  85. // EASYUICONTEXT->closeActivity("mainActivity");
  86. EASYUICONTEXT->closeActivity("moreActivity");
  87. }
  88. void setNursingBg(bool setNursing) {
  89. isNursing2 = setNursing;
  90. if (mnavibarPtr == NULL) {
  91. return;
  92. }
  93. if (setNursing) {
  94. mBgPainterPtr->setBackgroundPic("navibar/bg-pink.png");
  95. mNursingButtonPtr->setText(LANGUAGEMANAGER->getValue("NursingEnd"));
  96. mBlueCodeButtonPtr->setInvalid(false);
  97. }
  98. else {
  99. mBgPainterPtr->setBackgroundPic("navibar/bg.png");
  100. mNursingButtonPtr->setText(LANGUAGEMANAGER->getValue("Nursing"));
  101. mBlueCodeButtonPtr->setInvalid(true);
  102. }
  103. }
  104. void setNursing2(bool setNursing) {
  105. if (setNursing) {
  106. setNursingBg(setNursing);
  107. // 门灯控制
  108. std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  109. if (color != "" && color.size() == 3) {
  110. color = color + "F";
  111. } else {
  112. color = "010F";
  113. }
  114. lightControl("DOORLED", color);
  115. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING
  116. TcpModel tcpModel;
  117. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  118. tcpModel.type = TcpType::SIDE;
  119. tcpModel.action = SideAction::NURSING;
  120. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  121. tcpModel.to_id = 0;
  122. sendTcpModel(tcpModel);
  123. // 把护理状态缓存起来
  124. StoragePreferences::putBool(STORE_NURSING_TYPE, true);
  125. }
  126. else {
  127. setNursingBg(setNursing);
  128. lightControl("DOORLED", "000F");
  129. setNursingEnd();
  130. if (blueCodeId != 0) {
  131. TcpModel tcpModel;
  132. tcpModel.tid = blueCodeTid;
  133. tcpModel.type = TcpType::BLUE_CODE;
  134. tcpModel.action = BlueCodeAction::RESPONSE;
  135. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  136. tcpModel.data = to_string(blueCodeId);
  137. std::string req = getTcpModelString(tcpModel);
  138. LOGD("TCP BLUE CODE : %s",req.c_str());
  139. //回调注册
  140. TcpCallback callback;
  141. callback.tid = tcpModel.tid;
  142. callback.jsonStr = req;
  143. callback.onSuccess = [](Json::Value json){
  144. LOGD("side callback success");
  145. return 0;
  146. };
  147. callback.onFalied = [](Json::Value json){
  148. LOGD("side callback failed");
  149. return 0;
  150. };
  151. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  152. blueCodeId = 0;
  153. blueCodeTid = "";
  154. }
  155. }
  156. }
  157. //void callBedButtonSetVisible() {
  158. // if (mnavibarPtr == NULL) {
  159. // return;
  160. // }
  161. //
  162. // int roomCallBed = StoragePreferences::getInt(STORE_ROOM_CALL_BED, 1);
  163. // if (!roomCallBed) {
  164. // // 如果roomCallBed是0的话,那就隐藏
  165. // mCallBedButtonPtr->setVisible(roomCallBed);
  166. // mCallBedPicPainterPtr->setVisible(roomCallBed);
  167. //
  168. // mHelpButtonPtr->setPosition(LayoutPosition(11, 374, 96, 96));
  169. // mHelpPicPainterPtr->setPosition(LayoutPosition(46, 396, 27, 27));
  170. // mCallNurseButtonPtr->setPosition(LayoutPosition(11, 482, 96, 96));
  171. // mCallNursePicPainterPtr->setPosition(LayoutPosition(45, 504, 29, 27));
  172. //
  173. // }
  174. // else {
  175. // // 如果roomCallBed是1的话,那就显示
  176. // mCallBedButtonPtr->setVisible(roomCallBed);
  177. // mCallBedPicPainterPtr->setVisible(roomCallBed);
  178. //
  179. // mHelpButtonPtr->setPosition(LayoutPosition(11, 265, 96, 96));
  180. // mHelpPicPainterPtr->setPosition(LayoutPosition(43, 287, 32, 26));
  181. // mCallNurseButtonPtr->setPosition(LayoutPosition(11, 374, 96, 96));
  182. // mCallNursePicPainterPtr->setPosition(LayoutPosition(46, 396, 27, 27));
  183. // }
  184. //}
  185. void setBlueCodeId(int id, string tid) {
  186. blueCodeId = id;
  187. blueCodeTid = tid;
  188. }
  189. /**
  190. * 注册定时器
  191. * 填充数组用于注册定时器
  192. * 注意:id不能重复
  193. */
  194. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  195. //{0, 6000}, //定时器id=0, 时间间隔6秒
  196. //{1, 1000},
  197. };
  198. /**
  199. * 当界面构造时触发
  200. */
  201. static void onUI_init(){
  202. //Tips :添加 UI初始化的显示代码到这里,如:mText1->setText("123");
  203. // callBedButtonSetVisible();
  204. setNavibarTheme();
  205. setNursingBg(isNursing2);
  206. }
  207. /*
  208. * 当界面完全退出时触发
  209. */
  210. static void onUI_quit() {
  211. }
  212. /**
  213. * 串口数据回调接口
  214. */
  215. static void onProtocolDataUpdate(const SProtocolData &data) {
  216. //串口数据回调接口
  217. }
  218. /**
  219. * 定时器触发函数
  220. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  221. * 参数: id
  222. * 当前所触发定时器的id,与注册时的id相同
  223. * 返回值: true
  224. * 继续运行当前定时器
  225. * false
  226. * 停止运行当前定时器
  227. */
  228. static bool onUI_Timer(int id){
  229. switch (id) {
  230. default:
  231. break;
  232. }
  233. return true;
  234. }
  235. /**
  236. * 有新的触摸事件时触发
  237. * 参数:ev
  238. * 新的触摸事件
  239. * 返回值:true
  240. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  241. * false
  242. * 触摸事件将继续传递到控件上
  243. */
  244. static bool onnavibarActivityTouchEvent(const MotionEvent &ev) {
  245. switch (ev.mActionStatus) {
  246. case MotionEvent::E_ACTION_DOWN://触摸按下
  247. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  248. break;
  249. case MotionEvent::E_ACTION_MOVE://触摸滑动
  250. break;
  251. case MotionEvent::E_ACTION_UP: //触摸抬起
  252. break;
  253. default:
  254. break;
  255. }
  256. return false;
  257. }
  258. static bool onButtonClick_HomeButton(ZKButton *pButton) {
  259. LOGD(" ButtonClick HomeButton !!!\n");
  260. if (getAuthItId() != 0) {
  261. Intent* intent = new Intent();
  262. intent->putExtra(functionWindows, "logoutMedicalCare");
  263. intent->putExtra(goActivity, "home");
  264. EASYUICONTEXT->openActivity("functionActivity", intent);
  265. } else {
  266. goHome();
  267. }
  268. return false;
  269. }
  270. static bool onButtonClick_HealthCareButton(ZKButton *pButton) {
  271. LOGD(" ButtonClick HealthCareButton !!!\n");
  272. goCare();
  273. return false;
  274. }
  275. static bool onButtonClick_MoreButton(ZKButton *pButton) {
  276. LOGD(" ButtonClick MoreButton !!!\n");
  277. if (getAuthItId() != 0) {
  278. Intent* intent = new Intent();
  279. intent->putExtra(functionWindows, "logoutMedicalCare");
  280. intent->putExtra(goActivity, "more");
  281. EASYUICONTEXT->openActivity("functionActivity", intent);
  282. } else {
  283. goMore();
  284. }
  285. return false;
  286. }
  287. static bool onButtonClick_HelpButton(ZKButton *pButton) {
  288. LOGD(" ButtonClick HelpButton !!!\n");
  289. TcpModel tcpModel;
  290. tcpModel.type = TcpType::REINFORCE;
  291. tcpModel.action = ReinforceAction::CALL;
  292. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  293. tcpModel.to_id = 0;
  294. sendTcpModel(tcpModel);
  295. Intent* intent = new Intent();
  296. intent->putExtra(functionWindows, "help");
  297. EASYUICONTEXT->openActivity("functionActivity", intent);
  298. return false;
  299. }
  300. static bool onButtonClick_CallNurseButton(ZKButton *pButton) {
  301. LOGD(" ButtonClick CallNurseButton !!!\n");
  302. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  303. int port = StoragePreferences::getInt(SIP_REG_PORT, SIP_REG_PORT_DEFAULT);
  304. std::string domain = StoragePreferences::getString(SIP_REG_DOMAIN, SIP_REG_DOMAIN_DEFAULT);
  305. std::string od_number = StoragePreferences::getString(SIP_REG_DOOR_ACCOUNT, SIP_REG_DOOR_ACCOUNT_DEFAULT);
  306. std::string od_number_uri = URI(od_number, domain, port);
  307. LOGD("od_number_uri: %s", od_number_uri.c_str());
  308. GetTelephone()->MakeCall(od_number_uri);
  309. } else {
  310. Intent* intent = new Intent();
  311. intent->putExtra(isOutgoing, "true");
  312. intent->putExtra(audioOnly, "true");
  313. EASYUICONTEXT->openActivity("callActivity", intent);
  314. }
  315. return false;
  316. }
  317. static bool onButtonClick_CallCancelButton(ZKButton *pButton) {
  318. LOGD(" ButtonClick CallCancelButton !!!\n");
  319. // 发送tcp, tcp_type = VOICE, tcp_action = CANCEL_BY_DOOR
  320. TcpModel tcpModel;
  321. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  322. tcpModel.type = TcpType::VOICE;
  323. tcpModel.action = VoiceAction::CANCEL_BY_DOOR;
  324. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  325. std::string req = getTcpModelString(tcpModel);
  326. LOGD("TCP VOICE : %s",req.c_str());
  327. //回调注册
  328. TcpCallback callback;
  329. callback.tid = tcpModel.tid;
  330. callback.jsonStr = req;
  331. callback.onSuccess = [](Json::Value json){
  332. LOGD("side callback success");
  333. return 0;
  334. };
  335. callback.onFalied = [](Json::Value json){
  336. LOGD("side callback failed");
  337. return 0;
  338. };
  339. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  340. return false;
  341. }
  342. static bool onButtonClick_NursingButton(ZKButton *pButton) {
  343. LOGD(" ButtonClick NursingButton !!!\n");
  344. if (!isNursing2) {
  345. Intent* intent = new Intent();
  346. intent->putExtra(functionWindows, "nursing2");
  347. EASYUICONTEXT->openActivity("functionActivity", intent);
  348. }
  349. else {
  350. Intent* intent = new Intent();
  351. intent->putExtra(functionWindows, "nursingEnd2");
  352. EASYUICONTEXT->openActivity("functionActivity", intent);
  353. }
  354. return false;
  355. }
  356. static bool onButtonClick_BlueCodeButton(ZKButton *pButton) {
  357. LOGD(" ButtonClick BlueCodeButton !!!\n");
  358. TcpModel tcpModel;
  359. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  360. tcpModel.type = TcpType::BLUE_CODE;
  361. tcpModel.action = BlueCodeAction::CALL;
  362. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  363. std::string req = getTcpModelString(tcpModel);
  364. LOGD("TCP BLUE CODE : %s",req.c_str());
  365. //回调注册
  366. TcpCallback callback;
  367. callback.tid = tcpModel.tid;
  368. callback.jsonStr = req;
  369. callback.onSuccess = [](Json::Value json){
  370. LOGD("side callback success");
  371. return 0;
  372. };
  373. callback.onFalied = [](Json::Value json){
  374. LOGD("side callback failed");
  375. return 0;
  376. };
  377. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  378. lightControl("DOORLED", "001F");
  379. Intent* intent = new Intent();
  380. intent->putExtra(functionWindows, "blueCode");
  381. EASYUICONTEXT->openActivity("functionActivity", intent);
  382. return false;
  383. }