testActivity.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /***********************************************
  2. /gen auto by zuitools
  3. ***********************************************/
  4. #include "testActivity.h"
  5. /*TAG:GlobalVariable全局变量*/
  6. static ZKButton* mButton8Ptr;
  7. static ZKButton* mButton7Ptr;
  8. static ZKButton* mButton6Ptr;
  9. static ZKButton* mButton4Ptr;
  10. static ZKButton* mButton3Ptr;
  11. static ZKButton* mButton2Ptr;
  12. static ZKButton* mButton1Ptr;
  13. static testActivity* mActivityPtr;
  14. /*register activity*/
  15. REGISTER_ACTIVITY(testActivity);
  16. typedef struct {
  17. int id; // 定时器ID , 不能重复
  18. int time; // 定时器 时间间隔 单位 毫秒
  19. }S_ACTIVITY_TIMEER;
  20. #include "../logic/testLogic.cc"
  21. /***********/
  22. typedef struct {
  23. int id;
  24. const char *pApp;
  25. } SAppInfo;
  26. /**
  27. *点击跳转window
  28. */
  29. static SAppInfo sAppInfoTab[] = {
  30. // { ID_TEST_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_TEST_Button8, onButtonClick_Button8,
  44. ID_TEST_Button7, onButtonClick_Button7,
  45. ID_TEST_Button6, onButtonClick_Button6,
  46. ID_TEST_Button4, onButtonClick_Button4,
  47. ID_TEST_Button3, onButtonClick_Button3,
  48. ID_TEST_Button2, onButtonClick_Button2,
  49. ID_TEST_Button1, onButtonClick_Button1,
  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. testActivity::testActivity() {
  99. //todo add init code here
  100. mVideoLoopIndex = -1;
  101. mVideoLoopErrorCount = 0;
  102. }
  103. testActivity::~testActivity() {
  104. //todo add init file here
  105. // 退出应用时需要反注册
  106. EASYUICONTEXT->unregisterGlobalTouchListener(this);
  107. onUI_quit();
  108. unregisterProtocolDataUpdateListener(onProtocolDataUpdate);
  109. mButton8Ptr = NULL;
  110. mButton7Ptr = NULL;
  111. mButton6Ptr = NULL;
  112. mButton4Ptr = NULL;
  113. mButton3Ptr = NULL;
  114. mButton2Ptr = NULL;
  115. mButton1Ptr = NULL;
  116. mActivityPtr = NULL;
  117. }
  118. const char* testActivity::getAppName() const{
  119. return "test.ftu";
  120. }
  121. //TAG:onCreate
  122. void testActivity::onCreate() {
  123. Activity::onCreate();
  124. mButton8Ptr = (ZKButton*)findControlByID(ID_TEST_Button8);
  125. mButton7Ptr = (ZKButton*)findControlByID(ID_TEST_Button7);
  126. mButton6Ptr = (ZKButton*)findControlByID(ID_TEST_Button6);
  127. mButton4Ptr = (ZKButton*)findControlByID(ID_TEST_Button4);
  128. mButton3Ptr = (ZKButton*)findControlByID(ID_TEST_Button3);
  129. mButton2Ptr = (ZKButton*)findControlByID(ID_TEST_Button2);
  130. mButton1Ptr = (ZKButton*)findControlByID(ID_TEST_Button1);
  131. mActivityPtr = this;
  132. onUI_init();
  133. registerProtocolDataUpdateListener(onProtocolDataUpdate);
  134. rigesterActivityTimer();
  135. }
  136. void testActivity::onClick(ZKBase *pBase) {
  137. //TODO: add widget onClik code
  138. int buttonTablen = sizeof(sButtonCallbackTab) / sizeof(S_ButtonCallback);
  139. for (int i = 0; i < buttonTablen; ++i) {
  140. if (sButtonCallbackTab[i].id == pBase->getID()) {
  141. if (sButtonCallbackTab[i].callback((ZKButton*)pBase)) {
  142. return;
  143. }
  144. break;
  145. }
  146. }
  147. int len = sizeof(sAppInfoTab) / sizeof(sAppInfoTab[0]);
  148. for (int i = 0; i < len; ++i) {
  149. if (sAppInfoTab[i].id == pBase->getID()) {
  150. EASYUICONTEXT->openActivity(sAppInfoTab[i].pApp);
  151. return;
  152. }
  153. }
  154. Activity::onClick(pBase);
  155. }
  156. void testActivity::onResume() {
  157. Activity::onResume();
  158. EASYUICONTEXT->registerGlobalTouchListener(this);
  159. startVideoLoopPlayback();
  160. onUI_show();
  161. }
  162. void testActivity::onPause() {
  163. Activity::onPause();
  164. EASYUICONTEXT->unregisterGlobalTouchListener(this);
  165. stopVideoLoopPlayback();
  166. onUI_hide();
  167. }
  168. void testActivity::onIntent(const Intent *intentPtr) {
  169. Activity::onIntent(intentPtr);
  170. onUI_intent(intentPtr);
  171. }
  172. bool testActivity::onTimer(int id) {
  173. return onUI_Timer(id);
  174. }
  175. void testActivity::onProgressChanged(ZKSeekBar *pSeekBar, int progress){
  176. int seekBarTablen = sizeof(SZKSeekBarCallbackTab) / sizeof(S_ZKSeekBarCallback);
  177. for (int i = 0; i < seekBarTablen; ++i) {
  178. if (SZKSeekBarCallbackTab[i].id == pSeekBar->getID()) {
  179. SZKSeekBarCallbackTab[i].callback(pSeekBar, progress);
  180. break;
  181. }
  182. }
  183. }
  184. int testActivity::getListItemCount(const ZKListView *pListView) const{
  185. int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
  186. for (int i = 0; i < tablen; ++i) {
  187. if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
  188. return SListViewFunctionsCallbackTab[i].getListItemCountCallback(pListView);
  189. break;
  190. }
  191. }
  192. return 0;
  193. }
  194. void testActivity::obtainListItemData(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index){
  195. int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
  196. for (int i = 0; i < tablen; ++i) {
  197. if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
  198. SListViewFunctionsCallbackTab[i].obtainListItemDataCallback(pListView, pListItem, index);
  199. break;
  200. }
  201. }
  202. }
  203. void testActivity::onItemClick(ZKListView *pListView, int index, int id){
  204. int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
  205. for (int i = 0; i < tablen; ++i) {
  206. if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
  207. SListViewFunctionsCallbackTab[i].onItemClickCallback(pListView, index, id);
  208. break;
  209. }
  210. }
  211. }
  212. void testActivity::onSlideItemClick(ZKSlideWindow *pSlideWindow, int index) {
  213. int tablen = sizeof(SSlideWindowItemClickCallbackTab) / sizeof(S_SlideWindowItemClickCallback);
  214. for (int i = 0; i < tablen; ++i) {
  215. if (SSlideWindowItemClickCallbackTab[i].id == pSlideWindow->getID()) {
  216. SSlideWindowItemClickCallbackTab[i].onSlideItemClickCallback(pSlideWindow, index);
  217. break;
  218. }
  219. }
  220. }
  221. bool testActivity::onTouchEvent(const MotionEvent &ev) {
  222. return ontestActivityTouchEvent(ev);
  223. }
  224. void testActivity::onTextChanged(ZKTextView *pTextView, const std::string &text) {
  225. int tablen = sizeof(SEditTextInputCallbackTab) / sizeof(S_EditTextInputCallback);
  226. for (int i = 0; i < tablen; ++i) {
  227. if (SEditTextInputCallbackTab[i].id == pTextView->getID()) {
  228. SEditTextInputCallbackTab[i].onEditTextChangedCallback(text);
  229. break;
  230. }
  231. }
  232. }
  233. void testActivity::rigesterActivityTimer() {
  234. int tablen = sizeof(REGISTER_ACTIVITY_TIMER_TAB) / sizeof(S_ACTIVITY_TIMEER);
  235. for (int i = 0; i < tablen; ++i) {
  236. S_ACTIVITY_TIMEER temp = REGISTER_ACTIVITY_TIMER_TAB[i];
  237. registerTimer(temp.id, temp.time);
  238. }
  239. }
  240. void testActivity::onVideoPlayerMessage(ZKVideoView *pVideoView, int msg) {
  241. int tablen = sizeof(SVideoViewCallbackTab) / sizeof(S_VideoViewCallback);
  242. for (int i = 0; i < tablen; ++i) {
  243. if (SVideoViewCallbackTab[i].id == pVideoView->getID()) {
  244. if (SVideoViewCallbackTab[i].loop) {
  245. //循环播放
  246. videoLoopPlayback(pVideoView, msg, i);
  247. } else if (SVideoViewCallbackTab[i].onVideoViewCallback != NULL){
  248. SVideoViewCallbackTab[i].onVideoViewCallback(pVideoView, msg);
  249. }
  250. break;
  251. }
  252. }
  253. }
  254. void testActivity::videoLoopPlayback(ZKVideoView *pVideoView, int msg, size_t callbackTabIndex) {
  255. switch (msg) {
  256. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_STARTED:
  257. LOGD("ZKVideoView::E_MSGTYPE_VIDEO_PLAY_STARTED\n");
  258. if (callbackTabIndex >= (sizeof(SVideoViewCallbackTab)/sizeof(S_VideoViewCallback))) {
  259. break;
  260. }
  261. pVideoView->setVolume(SVideoViewCallbackTab[callbackTabIndex].defaultvolume / 10.0);
  262. mVideoLoopErrorCount = 0;
  263. break;
  264. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_ERROR:
  265. /**错误处理 */
  266. ++mVideoLoopErrorCount;
  267. if (mVideoLoopErrorCount > 100) {
  268. LOGD("video loop error counts > 100, quit loop playback !");
  269. break;
  270. } //不用break, 继续尝试播放下一个
  271. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED:
  272. LOGD("ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED\n");
  273. std::vector<std::string> videolist;
  274. std::string fileName(getAppName());
  275. if (fileName.size() < 4) {
  276. LOGD("getAppName size < 4, ignore!");
  277. break;
  278. }
  279. fileName = fileName.substr(0, fileName.length() - 4) + "_video_list.txt";
  280. fileName = "/mnt/extsd/" + fileName;
  281. if (!parseVideoFileList(fileName.c_str(), videolist)) {
  282. LOGD("parseVideoFileList failed !");
  283. break;
  284. }
  285. if (pVideoView && !videolist.empty()) {
  286. mVideoLoopIndex = (mVideoLoopIndex + 1) % videolist.size();
  287. pVideoView->play(videolist[mVideoLoopIndex].c_str());
  288. }
  289. break;
  290. }
  291. }
  292. void testActivity::startVideoLoopPlayback() {
  293. int tablen = sizeof(SVideoViewCallbackTab) / sizeof(S_VideoViewCallback);
  294. for (int i = 0; i < tablen; ++i) {
  295. if (SVideoViewCallbackTab[i].loop) {
  296. ZKVideoView* videoView = (ZKVideoView*)findControlByID(SVideoViewCallbackTab[i].id);
  297. if (!videoView) {
  298. return;
  299. }
  300. //循环播放
  301. videoLoopPlayback(videoView, ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED, i);
  302. return;
  303. }
  304. }
  305. }
  306. void testActivity::stopVideoLoopPlayback() {
  307. int tablen = sizeof(SVideoViewCallbackTab) / sizeof(S_VideoViewCallback);
  308. for (int i = 0; i < tablen; ++i) {
  309. if (SVideoViewCallbackTab[i].loop) {
  310. ZKVideoView* videoView = (ZKVideoView*)findControlByID(SVideoViewCallbackTab[i].id);
  311. if (!videoView) {
  312. return;
  313. }
  314. if (videoView->isPlaying()) {
  315. videoView->stop();
  316. }
  317. return;
  318. }
  319. }
  320. }
  321. bool testActivity::parseVideoFileList(const char *pFileListPath, std::vector<string>& mediaFileList) {
  322. mediaFileList.clear();
  323. if (NULL == pFileListPath || 0 == strlen(pFileListPath)) {
  324. LOGD("video file list is null!");
  325. return false;
  326. }
  327. ifstream is(pFileListPath, ios_base::in);
  328. if (!is.is_open()) {
  329. LOGD("cann't open file %s \n", pFileListPath);
  330. return false;
  331. }
  332. char tmp[1024] = {0};
  333. while (is.getline(tmp, sizeof(tmp))) {
  334. string str = tmp;
  335. removeCharFromString(str, '\"');
  336. removeCharFromString(str, '\r');
  337. removeCharFromString(str, '\n');
  338. if (str.size() > 1) {
  339. mediaFileList.push_back(str.c_str());
  340. }
  341. }
  342. LOGD("(f:%s, l:%d) parse fileList[%s], get [%d]files", __FUNCTION__,
  343. __LINE__, pFileListPath, int(mediaFileList.size()));
  344. for (std::vector<string>::size_type i = 0; i < mediaFileList.size(); i++) {
  345. LOGD("file[%u]:[%s]", ::size_t(i), mediaFileList[i].c_str());
  346. }
  347. is.close();
  348. return true;
  349. }
  350. int testActivity::removeCharFromString(string& nString, char c) {
  351. string::size_type pos;
  352. while(1) {
  353. pos = nString.find(c);
  354. if(pos != string::npos) {
  355. nString.erase(pos, 1);
  356. } else {
  357. break;
  358. }
  359. }
  360. return (int)nString.size();
  361. }
  362. void testActivity::registerUserTimer(int id, int time) {
  363. registerTimer(id, time);
  364. }
  365. void testActivity::unregisterUserTimer(int id) {
  366. unregisterTimer(id);
  367. }
  368. void testActivity::resetUserTimer(int id, int time) {
  369. resetTimer(id, time);
  370. }