settingActivity.cpp 15 KB

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