navibar.cpp 13 KB

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