startActivity.cpp 12 KB

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