settingActivity.cpp 14 KB

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