warnActivity.cpp 12 KB

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