interactionActivity.cpp 14 KB

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