moreActivity.cpp 12 KB

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