moreLogic.cc 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #pragma once
  2. #include "uart/ProtocolSender.h"
  3. #include "service/BusinessConfig.h"
  4. #include "restclient-cpp/restclient.h"
  5. #include <string>
  6. #include "base/strings.hpp"
  7. /*
  8. *此文件由GUI工具生成
  9. *文件功能:用于处理用户的逻辑相应代码
  10. *功能说明:
  11. *========================onButtonClick_XXXX
  12. 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称,
  13. 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK.
  14. *========================onSlideWindowItemClick_XXXX(int index)
  15. 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  16. 如slideWindow1;index 代表按下图标的偏移值
  17. *========================onSeekBarChange_XXXX(int progress)
  18. 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  19. 如SeekBar1;progress 代表当前的进度值
  20. *========================ogetListItemCount_XXXX()
  21. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称,
  22. 如List1;返回值为当前列表的总条数
  23. *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index)
  24. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称,
  25. 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明
  26. *========================常用接口===============
  27. *LOGD(...) 打印调试信息的接口
  28. *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字****
  29. *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色
  30. *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12
  31. *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用
  32. *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度
  33. *
  34. * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示
  35. */
  36. Json::Value deviceMenus;
  37. static std::string deviceInfoPic = "/more/shebi.png";
  38. void setDeviceMenuTheme() {
  39. int deviceMenuThemeInt = StoragePreferences::getInt(STORE_THEME, defaultThemeInt);
  40. if (deviceMenuThemeInt == 1) {
  41. deviceInfoPic = "/more/shebi.png";
  42. }
  43. else if (deviceMenuThemeInt == 2) {
  44. deviceInfoPic = "/more/shebi-pink.png";
  45. }
  46. deviceMenus[0]["icon_src"] = deviceInfoPic;
  47. mDeviceMenuListViewPtr->refreshListView();
  48. }
  49. void getDeviceMenu() {
  50. std::string url = getHttpGateway() + "/deviceBed/get_device_menu_list/" + StoragePreferences::getString(STORE_PARTID, "") + "/4";
  51. LOGD("请求设备菜单列表. url = %s", url.c_str());
  52. //发起HTTP POST请求
  53. RestClient::Response r = RestClient::get(url);
  54. if (r.code != 200) {
  55. LOGD("请求设备菜单列表-> 错误代码: %d", r.code);
  56. return;
  57. }
  58. LOGD("请求设备菜单列表. result = %s", r.body.c_str());
  59. //解析json
  60. Json::Reader reader;
  61. Json::Value root;
  62. if(reader.parse(r.body, root, false)) {
  63. if (root.size() > 0) {
  64. int count = 0;
  65. deviceMenus.clear();
  66. for (int i = 0; i < root.size(); i++) {
  67. if (root[i]["act_name"].asString() == "deviceInfoActivity") {
  68. count += 1;
  69. root[i]["icon_src"] = deviceInfoPic;
  70. deviceMenus.append(root[i]);
  71. }
  72. // else if (root[i]["act_name"].asString() == "callBedActivity") {
  73. // count += 1;
  74. // root[i]["icon_src"] = deviceInfoPic;
  75. // deviceMenus.append(root[i]);
  76. // }
  77. else if (root[i]["act_name"].asString() == "deviceAddActivity") {
  78. count += 1;
  79. root[i]["icon_src"] = deviceInfoPic;
  80. deviceMenus.append(root[i]);
  81. }
  82. }
  83. if (count == 0) {
  84. Json::Value deviceInfo;
  85. deviceInfo["icon_src"] = deviceInfoPic;
  86. deviceInfo["name"] = "设备信息";
  87. deviceInfo["introduction"] = "查看信息和设置";
  88. deviceInfo["act_name"] = "deviceInfoActivity";
  89. deviceMenus.append(deviceInfo);
  90. }
  91. }
  92. }
  93. }
  94. /**
  95. * 注册定时器
  96. * 填充数组用于注册定时器
  97. * 注意:id不能重复
  98. */
  99. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  100. //{0, 6000}, //定时器id=0, 时间间隔6秒
  101. //{1, 1000},
  102. };
  103. /**
  104. * 当界面构造时触发
  105. */
  106. static void onUI_init(){
  107. //Tips :添加 UI初始化的显示代码到这里,如:mText1Ptr->setText("123");
  108. deviceMenus[0]["icon_src"] = deviceInfoPic;
  109. deviceMenus[0]["name"] = LANGUAGEMANAGER->getValue("DeviceInfo");
  110. deviceMenus[0]["introduction"] = "查看信息和设置";
  111. deviceMenus[0]["act_name"] = "deviceInfoActivity";
  112. deviceMenus[1]["icon_src"] ="/more/keshi.png";
  113. deviceMenus[1]["name"] = LANGUAGEMANAGER->getValue("DeviceAdd");
  114. deviceMenus[1]["introduction"] = "注册设备";
  115. deviceMenus[1]["act_name"] = "deviceAddActivity";
  116. // deviceMenus[1]["icon_src"] ="/more/keshi.png";
  117. // deviceMenus[1]["name"] = "呼叫床位";
  118. // deviceMenus[1]["introduction"] = "呼叫床位分机";
  119. // deviceMenus[0]["act_name"] = "callBedActivity";
  120. //
  121. // deviceMenus[2]["icon_src"] ="/more/yiyuan.png";
  122. // deviceMenus[2]["name"] = "医院简介";
  123. // deviceMenus[2]["introduction"] = "医院详细介绍";
  124. //
  125. // deviceMenus[3]["icon_src"] ="/more/yiyuan.png";
  126. // deviceMenus[3]["name"] = "医院简介";
  127. // deviceMenus[3]["introduction"] = "医院详细介绍";
  128. mDeviceMenuListViewPtr->refreshListView();
  129. }
  130. /**
  131. * 当切换到该界面时触发
  132. */
  133. static void onUI_intent(const Intent *intentPtr) {
  134. if (intentPtr != NULL) {
  135. //TODO
  136. }
  137. }
  138. /*
  139. * 当界面显示时触发
  140. */
  141. static void onUI_show() {
  142. EASYUICONTEXT->showStatusBar();
  143. EASYUICONTEXT->showNaviBar();
  144. setDeviceMenuTheme();
  145. }
  146. /*
  147. * 当界面隐藏时触发
  148. */
  149. static void onUI_hide() {
  150. }
  151. /*
  152. * 当界面完全退出时触发
  153. */
  154. static void onUI_quit() {
  155. }
  156. /**
  157. * 串口数据回调接口
  158. */
  159. static void onProtocolDataUpdate(const SProtocolData &data) {
  160. }
  161. /**
  162. * 定时器触发函数
  163. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  164. * 参数: id
  165. * 当前所触发定时器的id,与注册时的id相同
  166. * 返回值: true
  167. * 继续运行当前定时器
  168. * false
  169. * 停止运行当前定时器
  170. */
  171. static bool onUI_Timer(int id){
  172. switch (id) {
  173. default:
  174. break;
  175. }
  176. return true;
  177. }
  178. /**
  179. * 有新的触摸事件时触发
  180. * 参数:ev
  181. * 新的触摸事件
  182. * 返回值:true
  183. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  184. * false
  185. * 触摸事件将继续传递到控件上
  186. */
  187. static bool onmoreActivityTouchEvent(const MotionEvent &ev) {
  188. switch (ev.mActionStatus) {
  189. case MotionEvent::E_ACTION_DOWN://触摸按下
  190. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  191. break;
  192. case MotionEvent::E_ACTION_MOVE://触摸滑动
  193. break;
  194. case MotionEvent::E_ACTION_UP: //触摸抬起
  195. break;
  196. default:
  197. break;
  198. }
  199. return false;
  200. }
  201. static int getListItemCount_DeviceMenuListView(const ZKListView *pListView) {
  202. //LOGD("getListItemCount_DeviceMenuListView !\n");
  203. return deviceMenus.size();
  204. }
  205. static void obtainListItemData_DeviceMenuListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  206. //LOGD(" obtainListItemData_ DeviceMenuListView !!!\n");
  207. string name = deviceMenus[index]["name"].asString();
  208. if (name.size() > 12) {
  209. name = name.substr(0, 12) + " \n" + name.substr(12);
  210. }
  211. pListItem->setText(name);
  212. // pListItem->findSubItemByID(ID_MORE_IntroductionSubItem)->setText(deviceMenus[index]["introduction"].asCString());
  213. pListItem->findSubItemByID(ID_MORE_DeviceMenuPicSubItem)->setBackgroundPic(deviceMenus[index]["icon_src"].asCString());
  214. }
  215. static void onListItemClick_DeviceMenuListView(ZKListView *pListView, int index, int id) {
  216. //LOGD(" onListItemClick_ DeviceMenuListView !!!\n");
  217. string actName = deviceMenus[index]["act_name"].asString();
  218. if (actName == "deviceInfoActivity") {
  219. // EASYUICONTEXT->openActivity("deviceInfoActivity");
  220. Intent* intent = new Intent();
  221. intent->putExtra(functionWindows, "deviceInfo");
  222. EASYUICONTEXT->openActivity("functionActivity", intent);
  223. }
  224. else if (actName == "callBedActivity") {
  225. Intent* intent = new Intent();
  226. intent->putExtra(functionWindows, "callBed");
  227. EASYUICONTEXT->openActivity("functionActivity", intent);
  228. // // 发送tcp, tcp_type = VOICE, tcp_action = CANCEL_BY_DOOR
  229. // TcpModel tcpModel;
  230. // tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  231. // tcpModel.type = TcpType::VOICE;
  232. // tcpModel.action = VoiceAction::CANCEL_BY_DOOR;
  233. // tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  234. // std::string req = getTcpModelString(tcpModel);
  235. // LOGD("TCP VOICE : %s",req.c_str());
  236. //
  237. // std::string cencalByDoorTid = tcpModel.tid;
  238. //
  239. // //回调注册
  240. // TcpCallback callback;
  241. // callback.tid = tcpModel.tid;
  242. // callback.jsonStr = req;
  243. // callback.onSuccess = [](Json::Value json){
  244. // LOGD("side callback success");
  245. // return 0;
  246. // };
  247. // callback.onFalied = [](Json::Value json){
  248. // LOGD("side callback failed");
  249. // return 0;
  250. // };
  251. // TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  252. }
  253. else if (actName == "deviceAddActivity") {
  254. Intent* intent = new Intent();
  255. intent->putExtra(functionWindows, "deviceAdd");
  256. EASYUICONTEXT->openActivity("functionActivity", intent);
  257. }
  258. }