sipTestActivity.cpp 12 KB

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