colorActivity.cpp 13 KB

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