moreLogic.cc 7.4 KB

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