settingActivity.cpp 16 KB

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