navibar.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. #include "navibar.h"
  2. #include "entry/EasyUIContext.h"
  3. /*TAG:GlobalVariable全局变量*/
  4. static ZKButton* mHomeButtonPtr;
  5. static ZKPainter* mCallBedPicPainterPtr;
  6. static ZKPainter* mCallNursePicPainterPtr;
  7. static ZKPainter* mHelpPicPainterPtr;
  8. static ZKButton* mHealthCareButtonPtr;
  9. static ZKButton* mCallBedButtonPtr;
  10. static ZKButton* mCallNurseButtonPtr;
  11. static ZKButton* mHelpButtonPtr;
  12. static ZKButton* mMoreButtonPtr;
  13. static navibar* mnavibarPtr;
  14. /* register sysapp */
  15. REGISTER_SYSAPP(APP_TYPE_SYS_NAVIBAR, navibar);
  16. typedef struct {
  17. int id; // 定时器ID , 不能重复
  18. int time; // 定时器 时间间隔 单位 毫秒
  19. }S_ACTIVITY_TIMEER;
  20. #include "logic/navibar.cc"
  21. /***********/
  22. typedef struct {
  23. int id;
  24. const char *pApp;
  25. } SAppInfo;
  26. /**
  27. *点击跳转window
  28. */
  29. static SAppInfo sAppInfoTab[] = {
  30. // { ID_MAIN_TEXT, "TextViewActivity" },
  31. };
  32. /***************/
  33. typedef bool (*ButtonCallback)(ZKButton *pButton);
  34. /**
  35. * button onclick表
  36. */
  37. typedef struct {
  38. int id;
  39. ButtonCallback callback;
  40. }S_ButtonCallback;
  41. /*TAG:ButtonCallbackTab按键映射表*/
  42. static S_ButtonCallback sButtonCallbackTab[] = {
  43. ID_NAVIBAR_HomeButton, onButtonClick_HomeButton,
  44. ID_NAVIBAR_HealthCareButton, onButtonClick_HealthCareButton,
  45. ID_NAVIBAR_CallBedButton, onButtonClick_CallBedButton,
  46. ID_NAVIBAR_CallNurseButton, onButtonClick_CallNurseButton,
  47. ID_NAVIBAR_HelpButton, onButtonClick_HelpButton,
  48. ID_NAVIBAR_MoreButton, onButtonClick_MoreButton,
  49. };
  50. /***************/
  51. typedef void (*SeekBarCallback)(ZKSeekBar *pSeekBar, int progress);
  52. typedef struct {
  53. int id;
  54. SeekBarCallback callback;
  55. }S_ZKSeekBarCallback;
  56. /*TAG:SeekBarCallbackTab*/
  57. static S_ZKSeekBarCallback SZKSeekBarCallbackTab[] = {
  58. };
  59. typedef int (*ListViewGetItemCountCallback)(const ZKListView *pListView);
  60. typedef void (*ListViewobtainListItemDataCallback)(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index);
  61. typedef void (*ListViewonItemClickCallback)(ZKListView *pListView, int index, int id);
  62. typedef struct {
  63. int id;
  64. ListViewGetItemCountCallback getListItemCountCallback;
  65. ListViewobtainListItemDataCallback obtainListItemDataCallback;
  66. ListViewonItemClickCallback onItemClickCallback;
  67. }S_ListViewFunctionsCallback;
  68. /*TAG:ListViewFunctionsCallback*/
  69. static S_ListViewFunctionsCallback SListViewFunctionsCallbackTab[] = {
  70. };
  71. typedef void (*SlideWindowItemClickCallback)(ZKSlideWindow *pSlideWindow, int index);
  72. typedef struct {
  73. int id;
  74. SlideWindowItemClickCallback onSlideItemClickCallback;
  75. }S_SlideWindowItemClickCallback;
  76. /*TAG:SlideWindowFunctionsCallbackTab*/
  77. static S_SlideWindowItemClickCallback SSlideWindowItemClickCallbackTab[] = {
  78. };
  79. typedef void (*EditTextInputCallback)(const std::string &text);
  80. typedef struct {
  81. int id;
  82. EditTextInputCallback onEditTextChangedCallback;
  83. }S_EditTextInputCallback;
  84. /*TAG:EditTextInputCallback*/
  85. static S_EditTextInputCallback SEditTextInputCallbackTab[] = {
  86. };
  87. typedef void (*VideoViewCallback)(ZKVideoView *pVideoView, int msg);
  88. typedef struct {
  89. int id; //VideoView ID
  90. bool loop; // 是否是轮播类型
  91. int defaultvolume;//轮播类型时,默认视频音量
  92. VideoViewCallback onVideoViewCallback;
  93. }S_VideoViewCallback;
  94. /*TAG:VideoViewCallback*/
  95. static S_VideoViewCallback SVideoViewCallbackTab[] = {
  96. };
  97. typedef void (*RadioGroupCallback)(ZKRadioGroup*, int);
  98. typedef struct {
  99. int id;
  100. RadioGroupCallback onCheckedChanged;
  101. }S_RadioGroupCallback;
  102. /*TAG:RadioGroupCallbackTab*/
  103. static S_RadioGroupCallback SRadioGroupCallbackTab[] = {
  104. };
  105. navibar::navibar() {
  106. mVideoLoopIndex = -1;
  107. mVideoLoopErrorCount = 0;
  108. }
  109. navibar::~navibar() {
  110. // 退出应用时需要反注册
  111. EASYUICONTEXT->unregisterGlobalTouchListener(this);
  112. unregisterProtocolDataUpdateListener(onProtocolDataUpdate);
  113. onUI_quit();
  114. mnavibarPtr = NULL;
  115. mHomeButtonPtr = NULL;
  116. mCallBedPicPainterPtr = NULL;
  117. mCallNursePicPainterPtr = NULL;
  118. mHelpPicPainterPtr = NULL;
  119. mHealthCareButtonPtr = NULL;
  120. mCallBedButtonPtr = NULL;
  121. mCallNurseButtonPtr = NULL;
  122. mHelpButtonPtr = NULL;
  123. mMoreButtonPtr = NULL;
  124. }
  125. const char* navibar::getAppName() const{
  126. return "navibar.ftu";
  127. }
  128. //TAG:onCreate
  129. void navibar::onCreate() {
  130. BaseApp::onCreate();
  131. mHomeButtonPtr = (ZKButton*)findControlByID(ID_NAVIBAR_HomeButton);
  132. mCallBedPicPainterPtr = (ZKPainter*)findControlByID(ID_NAVIBAR_CallBedPicPainter);
  133. mCallNursePicPainterPtr = (ZKPainter*)findControlByID(ID_NAVIBAR_CallNursePicPainter);
  134. mHelpPicPainterPtr = (ZKPainter*)findControlByID(ID_NAVIBAR_HelpPicPainter);
  135. mHealthCareButtonPtr = (ZKButton*)findControlByID(ID_NAVIBAR_HealthCareButton);
  136. mCallBedButtonPtr = (ZKButton*)findControlByID(ID_NAVIBAR_CallBedButton);
  137. mCallNurseButtonPtr = (ZKButton*)findControlByID(ID_NAVIBAR_CallNurseButton);
  138. mHelpButtonPtr = (ZKButton*)findControlByID(ID_NAVIBAR_HelpButton);
  139. mMoreButtonPtr = (ZKButton*)findControlByID(ID_NAVIBAR_MoreButton);
  140. mnavibarPtr = this;
  141. onUI_init();
  142. // 注册监听全局触摸
  143. EASYUICONTEXT->registerGlobalTouchListener(this);
  144. registerProtocolDataUpdateListener(onProtocolDataUpdate);
  145. rigesterActivityTimer();
  146. startVideoLoopPlayback();
  147. }
  148. void navibar::onClick(ZKBase *pBase) {
  149. int buttonTablen = sizeof(sButtonCallbackTab) / sizeof(S_ButtonCallback);
  150. for (int i = 0; i < buttonTablen; ++i) {
  151. if (sButtonCallbackTab[i].id == pBase->getID()) {
  152. if (sButtonCallbackTab[i].callback((ZKButton*)pBase)) {
  153. return;
  154. }
  155. break;
  156. }
  157. }
  158. int len = sizeof(sAppInfoTab) / sizeof(sAppInfoTab[0]);
  159. for (int i = 0; i < len; ++i) {
  160. if (sAppInfoTab[i].id == pBase->getID()) {
  161. EASYUICONTEXT->openActivity(sAppInfoTab[i].pApp);
  162. return;
  163. }
  164. }
  165. BaseApp::onClick(pBase);
  166. }
  167. bool navibar::onTimer(int id) {
  168. return onUI_Timer(id);
  169. }
  170. void navibar::onProgressChanged(ZKSeekBar *pSeekBar, int progress){
  171. int seekBarTablen = sizeof(SZKSeekBarCallbackTab) / sizeof(S_ZKSeekBarCallback);
  172. for (int i = 0; i < seekBarTablen; ++i) {
  173. if (SZKSeekBarCallbackTab[i].id == pSeekBar->getID()) {
  174. SZKSeekBarCallbackTab[i].callback(pSeekBar, progress);
  175. break;
  176. }
  177. }
  178. }
  179. int navibar::getListItemCount(const ZKListView *pListView) const{
  180. int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
  181. for (int i = 0; i < tablen; ++i) {
  182. if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
  183. return SListViewFunctionsCallbackTab[i].getListItemCountCallback(pListView);
  184. break;
  185. }
  186. }
  187. return 0;
  188. }
  189. void navibar::obtainListItemData(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index){
  190. int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
  191. for (int i = 0; i < tablen; ++i) {
  192. if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
  193. SListViewFunctionsCallbackTab[i].obtainListItemDataCallback(pListView, pListItem, index);
  194. break;
  195. }
  196. }
  197. }
  198. void navibar::onItemClick(ZKListView *pListView, int index, int id){
  199. int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
  200. for (int i = 0; i < tablen; ++i) {
  201. if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
  202. SListViewFunctionsCallbackTab[i].onItemClickCallback(pListView, index, id);
  203. break;
  204. }
  205. }
  206. }
  207. void navibar::onSlideItemClick(ZKSlideWindow *pSlideWindow, int index) {
  208. int tablen = sizeof(SSlideWindowItemClickCallbackTab) / sizeof(S_SlideWindowItemClickCallback);
  209. for (int i = 0; i < tablen; ++i) {
  210. if (SSlideWindowItemClickCallbackTab[i].id == pSlideWindow->getID()) {
  211. SSlideWindowItemClickCallbackTab[i].onSlideItemClickCallback(pSlideWindow, index);
  212. break;
  213. }
  214. }
  215. }
  216. bool navibar::onTouchEvent(const MotionEvent &ev) {
  217. return onnavibarActivityTouchEvent(ev);
  218. }
  219. void navibar::onTextChanged(ZKTextView *pTextView, const std::string &text) {
  220. int tablen = sizeof(SEditTextInputCallbackTab) / sizeof(S_EditTextInputCallback);
  221. for (int i = 0; i < tablen; ++i) {
  222. if (SEditTextInputCallbackTab[i].id == pTextView->getID()) {
  223. SEditTextInputCallbackTab[i].onEditTextChangedCallback(text);
  224. break;
  225. }
  226. }
  227. }
  228. void navibar::rigesterActivityTimer() {
  229. int tablen = sizeof(REGISTER_ACTIVITY_TIMER_TAB) / sizeof(S_ACTIVITY_TIMEER);
  230. for (int i = 0; i < tablen; ++i) {
  231. S_ACTIVITY_TIMEER temp = REGISTER_ACTIVITY_TIMER_TAB[i];
  232. registerTimer(temp.id, temp.time);
  233. }
  234. }
  235. void navibar::onVideoPlayerMessage(ZKVideoView *pVideoView, int msg) {
  236. int tablen = sizeof(SVideoViewCallbackTab) / sizeof(S_VideoViewCallback);
  237. for (int i = 0; i < tablen; ++i) {
  238. if (SVideoViewCallbackTab[i].id == pVideoView->getID()) {
  239. if (SVideoViewCallbackTab[i].loop) {
  240. //循环播放
  241. videoLoopPlayback(pVideoView, msg, i);
  242. } else if (SVideoViewCallbackTab[i].onVideoViewCallback != NULL){
  243. SVideoViewCallbackTab[i].onVideoViewCallback(pVideoView, msg);
  244. }
  245. break;
  246. }
  247. }
  248. }
  249. void navibar::videoLoopPlayback(ZKVideoView *pVideoView, int msg, size_t callbackTabIndex) {
  250. switch (msg) {
  251. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_STARTED:
  252. LOGD("ZKVideoView::E_MSGTYPE_VIDEO_PLAY_STARTED\n");
  253. if (callbackTabIndex >= (sizeof(SVideoViewCallbackTab)/sizeof(S_VideoViewCallback))) {
  254. break;
  255. }
  256. pVideoView->setVolume(SVideoViewCallbackTab[callbackTabIndex].defaultvolume / 10.0);
  257. mVideoLoopErrorCount = 0;
  258. break;
  259. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_ERROR:
  260. /**错误处理 */
  261. ++mVideoLoopErrorCount;
  262. if (mVideoLoopErrorCount > 100) {
  263. LOGD("video loop error counts > 100, quit loop playback !");
  264. break;
  265. } //不用break, 继续尝试播放下一个
  266. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED:
  267. LOGD("ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED\n");
  268. std::vector<std::string> videolist;
  269. std::string fileName(getAppName());
  270. if (fileName.size() < 4) {
  271. LOGD("getAppName size < 4, ignore!");
  272. break;
  273. }
  274. fileName = fileName.substr(0, fileName.length() - 4) + "_video_list.txt";
  275. fileName = "/mnt/extsd/" + fileName;
  276. if (!parseVideoFileList(fileName.c_str(), videolist)) {
  277. LOGD("parseVideoFileList failed !");
  278. break;
  279. }
  280. if (pVideoView && !videolist.empty()) {
  281. mVideoLoopIndex = (mVideoLoopIndex + 1) % videolist.size();
  282. pVideoView->play(videolist[mVideoLoopIndex].c_str());
  283. }
  284. break;
  285. }
  286. }
  287. void navibar::startVideoLoopPlayback() {
  288. int tablen = sizeof(SVideoViewCallbackTab) / sizeof(S_VideoViewCallback);
  289. for (int i = 0; i < tablen; ++i) {
  290. if (SVideoViewCallbackTab[i].loop) {
  291. ZKVideoView* videoView = (ZKVideoView*)findControlByID(SVideoViewCallbackTab[i].id);
  292. if (!videoView) {
  293. return;
  294. }
  295. //循环播放
  296. videoLoopPlayback(videoView, ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED, i);
  297. return;
  298. }
  299. }
  300. }
  301. void navibar::stopVideoLoopPlayback() {
  302. int tablen = sizeof(SVideoViewCallbackTab) / sizeof(S_VideoViewCallback);
  303. for (int i = 0; i < tablen; ++i) {
  304. if (SVideoViewCallbackTab[i].loop) {
  305. ZKVideoView* videoView = (ZKVideoView*)findControlByID(SVideoViewCallbackTab[i].id);
  306. if (!videoView) {
  307. return;
  308. }
  309. if (videoView->isPlaying()) {
  310. videoView->stop();
  311. }
  312. return;
  313. }
  314. }
  315. }
  316. bool navibar::parseVideoFileList(const char *pFileListPath, std::vector<string>& mediaFileList) {
  317. mediaFileList.clear();
  318. if (NULL == pFileListPath || 0 == strlen(pFileListPath)) {
  319. LOGD("video file list is null!");
  320. return false;
  321. }
  322. ifstream is(pFileListPath, ios_base::in);
  323. if (!is.is_open()) {
  324. LOGD("cann't open file %s \n", pFileListPath);
  325. return false;
  326. }
  327. char tmp[1024] = {0};
  328. while (is.getline(tmp, sizeof(tmp))) {
  329. string str = tmp;
  330. removeCharFromString(str, '\"');
  331. removeCharFromString(str, '\r');
  332. removeCharFromString(str, '\n');
  333. if (str.size() > 1) {
  334. mediaFileList.push_back(str.c_str());
  335. }
  336. }
  337. LOGD("(f:%s, l:%d) parse fileList[%s], get [%d]files\n", __FUNCTION__,
  338. __LINE__, pFileListPath, mediaFileList.size());
  339. for (size_t i = 0; i < mediaFileList.size(); i++) {
  340. LOGD("file[%d]:[%s]\n", i, mediaFileList[i].c_str());
  341. }
  342. is.close();
  343. return true;
  344. }
  345. int navibar::removeCharFromString(string& nString, char c)
  346. {
  347. string::size_type pos;
  348. while(1) {
  349. pos = nString.find(c);
  350. if(pos != string::npos) {
  351. nString.erase(pos, 1);
  352. } else {
  353. break;
  354. }
  355. }
  356. return (int)nString.size();
  357. }
  358. void navibar::registerUserTimer(int id, int time) {
  359. registerTimer(id, time);
  360. }
  361. void navibar::unregisterUserTimer(int id) {
  362. unregisterTimer(id);
  363. }
  364. void navibar::resetUserTimer(int id, int time) {
  365. resetTimer(id, time);
  366. }
  367. void navibar::onCheckedChanged(ZKRadioGroup* pRadioGroup, int checkedID) {
  368. int tablen = sizeof(SRadioGroupCallbackTab) / sizeof(S_RadioGroupCallback);
  369. for (int i = 0; i < tablen; ++i) {
  370. if (SRadioGroupCallbackTab[i].id == pRadioGroup->getID()) {
  371. SRadioGroupCallbackTab[i].onCheckedChanged(pRadioGroup, checkedID);
  372. break;
  373. }
  374. }
  375. }