settingActivity.cpp 15 KB

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