thewarpedcoder

Titanium User Case Close

Jun 13th, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.84 KB | None | 0 0
  1. // All source code open Source Copyright 2011
  2. // Code submitted by thewarpedcoder .... [email protected]
  3.  
  4. /* The purpose of the user cases is to define instances of issues / bugs
  5. * with the applications I code.
  6. *
  7. * This user case uses nameSpaces as this is how the main application works,
  8. * and also opens and closes windows as required. It does not have a window
  9. * stack.
  10. */
  11.  
  12. Ti.UI.setBackgroundColor('#ffffff');
  13.  
  14. // Define the NameSpaces
  15. var mainNS = {};
  16. mainNS.event = {};
  17. mainNS.view = {};
  18. mainNS.tool = {};
  19. mainNS.model = {};
  20.  
  21. (function()
  22. {
  23. var mobWidth = Ti.Platform.displayCaps.platformWidth;
  24. var mobHeight = Ti.Platform.displayCaps.platformHeight;
  25. var mobDiv = 1;
  26.  
  27. if (mobWidth < 480)
  28. {
  29. mobDiv = 2;
  30. }
  31. else if (mobWidth < 640)
  32. {
  33. mobDiv = 1.5;
  34. };
  35. if (Ti.Platform.osname == 'android')
  36. {
  37. androidPlatform = true;
  38. }
  39. // Global variable definitions.
  40.  
  41. var globalCurrScreen = null;
  42. var globalPreviousScreen = null;
  43. var globalBackButt = [];
  44.  
  45. var initiateFlag = true;
  46. var iPos = 0;
  47.  
  48. // Functions
  49. function addBackScreen(inFunction)
  50. {
  51. var tmpBackIn = ({INFUNC: inFunction});
  52.  
  53. globalBackButt.push(tmpBackIn);
  54. };
  55. function popGlobalBackButt()
  56. {
  57. globalBackButt.pop();
  58. };
  59. // Events ....
  60.  
  61. mainNS.event.closeTheApp = function(evt)
  62. {
  63. if (Ti.Platform.osname == 'android')
  64. {
  65. var activity = Ti.Android.currentActivity;
  66. activity.stop();
  67. }
  68. };
  69. mainNS.event.loadBackScreenHandler = function(evt)
  70. {
  71. iPos = ((globalBackButt.length - 2) < 0) ? 0 : (globalBackButt.length - 2);
  72.  
  73. if (globalBackButt.length <= 1)
  74. {
  75. mainNS.event.closeTheApp({});
  76. }
  77. else
  78. {
  79. if (iPos >= 0)
  80. {
  81. var tmp1 = globalBackButt[iPos].INFUNC;
  82.  
  83. if (tmp1)
  84. {
  85. if(globalBackButt.length > 1)
  86. {
  87. popGlobalBackButt();
  88. };
  89. eval(tmp1 + '({BACK: ' + "true" + '});');
  90. }
  91. };
  92. };
  93. };
  94. mainNS.event.loadHomeScreen = function(evt)
  95. {
  96. globalPreviousScreen = globalCurrScreen;
  97.  
  98. if (!evt.BACK)
  99. {
  100. addBackScreen("mainNS.event.loadHomeScreen");
  101. }
  102. mainNS.view.loadHomeScreenWindow().open();
  103.  
  104. if (!initiateFlag)
  105. {
  106. globalPreviousScreen.close();
  107. initiateFlag = false;
  108. }
  109. };
  110. mainNS.event.loadCameraScreen = function(evt)
  111. {
  112. globalPreviousScreen = globalCurrScreen;
  113.  
  114. if (!evt.BACK)
  115. {
  116. addBackScreen("mainNS.event.loadCameraScreen");
  117. }
  118. mainNS.view.loadCameraScreenWindow().open();
  119.  
  120. globalPreviousScreen.close();
  121.  
  122. initiateFlag = false;
  123. };
  124. // Screen Tools
  125.  
  126. mainNS.tool.appNavigationBar = function(evt)
  127. {
  128. var navigationBar = Ti.UI.createView
  129. ({
  130. bottom: 0,
  131. height: 70 / mobDiv,
  132. right: 0,
  133. backgroundColor: "#000000",
  134. opacity: 0.75
  135. });
  136. var tmpHColor = (evt.SCREEN == 'HOME') ? "#FF0000" : "#FFFFFF";
  137. var tmpCColor = (evt.SCREEN == 'CAMERA') ? "#FF0000" : "#FFFFFF";
  138. var tmpBColor = (globalBackButt.length > 1) ? "#FFFFFF" : "#444444";
  139.  
  140. var navBarHomeBtn = Ti.UI.createView
  141. ({
  142. left: 5,
  143. width: 90 / mobDiv,
  144. height: 70 / mobDiv,
  145. top: 0,
  146. backgroundColor: "#000000",
  147. borderColor: "#FFFFFF",
  148. borderWidth: 2
  149. });
  150. var navBarHomeBtnText = Ti.UI.createLabel
  151. ({
  152. width: 90 / mobDiv,
  153. text: "HOME",
  154. color: tmpHColor,
  155. textAlign: 'center',
  156. font: {fontSize: 10}
  157. });
  158. navBarHomeBtn.add(navBarHomeBtnText);
  159. navigationBar.add(navBarHomeBtn);
  160.  
  161. var navBarCameraBtn = Ti.UI.createView
  162. ({
  163. left: 100 / mobDiv,
  164. width: 90 / mobDiv,
  165. height: 70 / mobDiv,
  166. top: 0,
  167. backgroundColor: "#000000",
  168. borderColor: "#FFFFFF",
  169. borderWidth: 2
  170. });
  171. var navBarCameraBtnText = Ti.UI.createLabel
  172. ({
  173. width: 90 / mobDiv,
  174. text: "CAMERA",
  175. color: tmpCColor,
  176. textAlign: 'center',
  177. font: {fontSize: 10}
  178. });
  179. navBarCameraBtn.add(navBarCameraBtnText);
  180. navigationBar.add(navBarCameraBtn);
  181.  
  182. var navBarBackBtn = Ti.UI.createView
  183. ({
  184. left: 200 / mobDiv,
  185. width: 90 / mobDiv,
  186. height: 70 / mobDiv,
  187. top: 0,
  188. backgroundColor: "#000000",
  189. borderColor: "#FFFFFF",
  190. borderWidth: 2
  191. });
  192. var navBarBackBtnText = Ti.UI.createLabel
  193. ({
  194. width: 90 / mobDiv,
  195. text: "BACK",
  196. color: tmpBColor,
  197. textAlign: 'center',
  198. font: {fontSize: 10}
  199. });
  200. navBarBackBtn.add(navBarBackBtnText);
  201. navigationBar.add(navBarBackBtn);
  202.  
  203. var navBarCloseBtn = Ti.UI.createView
  204. ({
  205. right: 10 / mobDiv,
  206. width: 90 / mobDiv,
  207. height: 70 / mobDiv,
  208. top: 0,
  209. backgroundColor: "#000000",
  210. borderColor: "#FFFFFF",
  211. borderWidth: 2
  212. });
  213. var navBarCloseBtnText = Ti.UI.createLabel
  214. ({
  215. width: 90 / mobDiv,
  216. text: "CLOSE",
  217. color: "#FFFFFF",
  218. textAlign: 'center',
  219. font: {fontSize: 10}
  220. });
  221. navBarCloseBtn.add(navBarCloseBtnText);
  222. navigationBar.add(navBarCloseBtn);
  223.  
  224. if (evt.SCREEN != 'HOME') {navBarHomeBtn.addEventListener('click', function() {mainNS.event.loadHomeScreen({})} ); };
  225. if (evt.SCREEN != 'CAMERA') {navBarCameraBtn.addEventListener('click', function() {mainNS.event.loadCameraScreen({})} ); };
  226. if (globalBackButt.length > 1) {navBarBackBtn.addEventListener('click', function() {mainNS.event.loadBackScreenHandler({})} ); };
  227.  
  228. navBarCloseBtn.addEventListener('click', function() {mainNS.event.closeTheApp({})} );
  229.  
  230. return navigationBar;
  231. };
  232. // Screens ....
  233.  
  234. mainNS.view.loadHomeScreenWindow = function()
  235. {
  236. var mainMenuWin = Ti.UI.createWindow
  237. ({
  238. navBarHidden: true,
  239. backgroundColor: "#FFFFFF"
  240. });
  241. var mainMenuWinLabel = Ti.UI.createLabel
  242. ({
  243. width: 200,
  244. text: "HOME SCREEN",
  245. color: "#000000",
  246. textAlign: 'center',
  247. font: {fontSize: 30}
  248. });
  249. mainMenuWin.add(mainMenuWinLabel);
  250.  
  251. globalCurrScreen = mainMenuWin;
  252.  
  253. var navBarData = {SCREEN: "HOME"};
  254.  
  255. var navBar = mainNS.tool.appNavigationBar(navBarData);
  256.  
  257. mainMenuWin.add(navBar);
  258.  
  259. if (Ti.Platform.osname == 'android')
  260. {
  261. mainMenuWin.addEventListener('android:back', function() {mainNS.event.loadBackScreenHandler({})} );
  262. };
  263. return mainMenuWin;
  264. };
  265. mainNS.view.loadCameraScreenWindow = function()
  266. {
  267. var cameraScreenWin = Ti.UI.createWindow
  268. ({
  269. navBarHidden: true,
  270. backgroundColor: "#FFFFFF"
  271. });
  272. var cameraScreenWinLabel = Ti.UI.createLabel
  273. ({
  274. width: 200,
  275. text: "CAMERA SCREEN",
  276. color: "#000000",
  277. textAlign: 'center',
  278. font: {fontSize: 30}
  279. });
  280. cameraScreenWin.add(cameraScreenWinLabel);
  281.  
  282. globalCurrScreen = cameraScreenWin;
  283.  
  284. var navBarData = {SCREEN: "CAMERA"};
  285.  
  286. var navBar = mainNS.tool.appNavigationBar(navBarData);
  287.  
  288. cameraScreenWin.add(navBar);
  289.  
  290. if (Ti.Platform.osname == 'android')
  291. {
  292. cameraScreenWin.addEventListener('android:back', function() {mainNS.event.loadBackScreenHandler({})} );
  293. };
  294. return cameraScreenWin;
  295. };
  296. // Initial Launch
  297. mainNS.event.loadHomeScreen({});
  298.  
  299. })();
Advertisement
Add Comment
Please, Sign In to add comment