Advertisement
loonerz

ApplicationWindow Backup 18-Junio-2014

Jun 18th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var imagesPath;
  2. var fontName;
  3. var osname = Ti.Platform.osname;
  4. imagesPath = Titanium.Filesystem.resourcesDirectory + "images/";
  5. fontName = 'ArialRoundedBold';
  6.  
  7. var dpi = 'dp';
  8.  
  9. function ApplicationWindow(usuario)
  10. {
  11.     //load component dependencies
  12.     var MenuView = require('ui/common/Menu');
  13.     var MainView = require('ui/common/MainView');
  14.     var BabyProfile = require('ui/android/BabyProfile');
  15.     var Friends = require('ui/common/Friends');
  16.     var Moments = require('ui/common/Moments');
  17.     var Activity = require('ui/android/Activity');
  18.     var Favorites = require('ui/android/Favorites');
  19.     var Today = require('ui/android/Today');
  20.     var Badges = require('ui/common/Badges');
  21.     var MomentDetails = require('ui/android/MomentDetails');
  22.     var CareGiverProfile = require('ui/common/CareGiverProfile');
  23.     var TidBitView = require('ui/common/TidBitViewer');
  24.     var NoBabies = require('ui/common/NoBabies');
  25.    
  26.     // Variable for current displayed app on MainView
  27.     var currentApp;
  28.     // var runningApps = [];
  29.  
  30.     //create component instance
  31.     var self = Ti.UI.createWindow(
  32.     {
  33.         backgroundColor : '#0e76bc',
  34.         navBarHidden : true,
  35.         exitOnClose : true
  36.     });
  37.    
  38.     var selfLoadingView = Ti.UI.createView({
  39.         width:Ti.UI.FILL,
  40.         height:Ti.UI.SIZE,
  41.         layout:"vertical"
  42.     });
  43.    
  44.     var selfBackground = Ti.UI.createImageView({
  45.         image:imagesPath + "img_avion.png",
  46.         left:"0dp",
  47.         width:"250dp"
  48.     });
  49.    
  50.     var selfExplaination = Ti.UI.createLabel({
  51.         text : L("Loading_string"),
  52.         font:{
  53.             fontSize:"38dp",
  54.             fontFamily: 'HelveticaNeue-Light'
  55.         },
  56.         color : "#ffffff",
  57.         width : Ti.UI.SIZE,
  58.         height : Ti.UI.SIZE,
  59.         textAlign : "left",
  60.         left : "10dp",
  61.         right:"60dp",
  62.         top:"25dp"
  63.     });
  64.    
  65.     // back button event listener
  66.     self.addEventListener('android:back', function(e)
  67.     {
  68.         Ti.API.info('androidbackandroidnback');
  69.        
  70.         var upperViewPresent = Ti.App.Properties.getBool('activityMomentViewPresent');
  71.         Ti.API.info('upperViewPresent ' + upperViewPresent);
  72.        
  73.         if(upperViewPresent)
  74.         {              
  75.             Ti.App.fireEvent('closeUpperView');        
  76.             hideTidBitView();              
  77.             Ti.App.Properties.setBool('activityMomentViewPresent', false);         
  78.         }
  79.         else
  80.         {
  81.             self.close({
  82.                 top : Ti.Platform.displayCaps.platformHeight,
  83.                 duration : 700
  84.             });
  85.         }
  86.     });
  87.    
  88.     function disappearLoading()
  89.     {
  90.         indicator.hide();
  91.         selfExplaination.setText(L("everything_loaded"));
  92.         selfBackground.animate({opacity:"0", duration:1000}, function(e){
  93.             selfExplaination.animate({opacity:"0", duration:700});
  94.         });
  95.     }
  96.    
  97.     var indicator = Ti.UI.createActivityIndicator({
  98.         height : Ti.UI.SIZE,
  99.         width : Ti.UI.SIZE
  100.     });
  101.    
  102.     indicator.show();
  103.    
  104.     selfLoadingView.add(selfBackground);
  105.     selfLoadingView.add(selfExplaination);
  106.     selfLoadingView.add(indicator);
  107.     self.add(selfLoadingView);
  108.  
  109.     Ti.UI.setBackgroundColor('#0e76bc');
  110.  
  111.     function removeListeners()
  112.     {
  113.         Ti.App.removeEventListener('switchApp', switchApp);
  114.         //Ti.App.removeEventListener('switchMenuVisibility', switchMenuVisibility);
  115.         Ti.App.removeEventListener('closeMainWindow', closeMainWindow);
  116.         Ti.App.removeEventListener('reloadUserInfo', reloadUserInfo);
  117.     }
  118.  
  119.     function closeMainWindow(e)
  120.     {
  121.         Ti.App.Properties.setBool('windowOpened', false);
  122.         removeListeners();
  123.         self.close();      
  124.     }
  125.    
  126.     Ti.App.addEventListener("closeMainWindow", closeMainWindow);
  127.  
  128.     function reloadUserInfo()
  129.     {
  130.         Ti.API.info('inside reloadUserInfo');
  131.         var userId = usuario.user.id;
  132.         var url = 'http://api.kinedu.com/api/v1/users/' + userId + '?locale=' + Ti.App.getUserDefinedLanguage();
  133.         var token = Ti.App.Properties.getString('token');
  134.         var client = Ti.Network.createHTTPClient(
  135.         {
  136.             onload : function(data)
  137.             {
  138.                 Ti.API.info('Info del user ' + this.responseText);
  139.                 var response = JSON.parse(this.responseText);
  140.                 usuario.user = response;
  141.                 Ti.App.Properties.setString('user', JSON.stringify(usuario));
  142.                 Ti.App.fetchFamilyRequest;
  143.                 closeMainWindowForRestart();
  144.             },
  145.             onerror : function(data)
  146.             {
  147.                 Ti.API.info('Error loading user info ' + this.responseText);
  148.                 Ti.API.info(JSON.stringify(data));
  149.             },
  150.             timeout : 35000
  151.         });
  152.         client.open('GET', url);
  153.         client.setRequestHeader('Authorization', 'Token token=' + token);
  154.         client.send();
  155.     }
  156.  
  157.     function closeMainWindowForRestart(e)
  158.     {
  159.         removeListeners();
  160.         // var babiesString = JSON.parse(Ti.App.Properties.getString('babies'));
  161.  
  162.         var babies = JSON.parse(Ti.App.Properties.getString('babies'));
  163.         // var babies = Ti.App.Properties.getString('babies');
  164.         for (var i = 0; i < babies.length; i++)
  165.         {
  166.             Ti.API.info('cache Kinedugram ' + Ti.App.Properties.getString('Activities_Cache_App_' + babies[i].id));
  167.             Ti.API.info('cache Moments ' + Ti.App.Properties.getString('Moments_Cache_App_' + babies[i].id));
  168.             Ti.API.info('cache Favorites ' + Ti.App.Properties.getString('Favorites_Cache_App_' + babies[i].id));
  169.             Ti.App.Properties.removeProperty('Activities_Cache_App_' + babies[i].id);
  170.             Ti.App.Properties.removeProperty('Favorites_Cache_App_' + babies[i].id);
  171.             Ti.App.Properties.removeProperty('Moments_Cache_App_' + babies[i].id);
  172.             Ti.API.info('after cache Kinedugram ' + Ti.App.Properties.getString('Activities_Cache_App_' + babies[i].id));
  173.             Ti.API.info('after cache Moments ' + Ti.App.Properties.getString('Moments_Cache_App_' + babies[i].id));
  174.             Ti.API.info('after cache Favorites ' + Ti.App.Properties.getString('Favorites_Cache_App_' + babies[i].id));
  175.         }
  176.         for (var i = 0; i < babies.length; i++)
  177.         {
  178.             Ti.API.info('another for cache Kinedugram ' + Ti.App.Properties.getString('Activities_Cache_App_' + babies[i].id));
  179.             Ti.API.info('another for cache Moments ' + Ti.App.Properties.getString('Moments_Cache_App_' + babies[i].id));
  180.             Ti.API.info('another for cache Favorites ' + Ti.App.Properties.getString('Favorites_Cache_App_' + babies[i].id));
  181.         }
  182.        
  183.         //self.close();
  184.         Ti.App.fireEvent('openWindow');
  185.     }
  186.  
  187.  
  188.     Ti.App.addEventListener("reloadUserInfo", reloadUserInfo);
  189.  
  190.     var currentBaby;
  191.  
  192.     //*************
  193.     // fast app switching
  194.     // Array that holds every app instace opened so far to enable a faster loading
  195.     var appHolder = [];
  196.  
  197.     //*************
  198.  
  199.     self.setCurrentBaby = function(babyObj)
  200.     {
  201.         // currentBaby = id;
  202.         // manageBabiesView = ManageBabies();
  203.         // self.add(manageBabiesView);
  204.         Ti.App.Properties.setBool('windowOpened', true);
  205.         Ti.App.fireEvent('refreshManagement');
  206.         currentBaby = babyObj.id;
  207.         currentBabyName = babyObj.name;
  208.  
  209.         Ti.API.info('function current baby ' + currentBaby);
  210.         Ti.App.Properties.setString('currentBaby', currentBaby);
  211.         Ti.App.Properties.setString('currentBabyName', currentBabyName);
  212.         if ( typeof babyObj.active_programme !== 'undefined')
  213.         {
  214.             Ti.App.Properties.setInt('currentProgramme', babyObj.active_programme.id);
  215.         }
  216.  
  217.         currentApp = findApp("Today", currentBaby);
  218.         if (currentApp == null)
  219.         {
  220.             currentApp = new Today(currentBaby);
  221.             appHolder.push(
  222.             {
  223.                 name : "Today",
  224.                 babyId : currentBaby,
  225.                 app : currentApp
  226.             });
  227.         }
  228.  
  229.         // Ti.API.info('function current baby ' + currentBaby);
  230.         // Ti.App.Properties.setString('currentBaby', currentBaby);
  231.         Ti.App.Properties.setString('current_app', 'Today');
  232.         currentApp.setParentWindow(self);
  233.         Ti.API.info('current app ' + Ti.App.Properties.getString('current_app'));
  234.         mainView.swapView(currentApp, false);
  235.  
  236.     };
  237.    
  238.     var platformWidth = Ti.Platform.displayCaps.platformWidth;
  239.     var platformHeight = Ti.Platform.displayCaps.platformHeight;
  240.     Ti.API.info('platform width ' + platformWidth);
  241.     Ti.API.info('platform height ' + platformHeight);
  242.     if(platformWidth > platformHeight)
  243.     {
  244.         platformWidth = Ti.Platform.displayCaps.platformHeight;
  245.         platformHeight = Ti.Platform.displayCaps.platformWidth;
  246.     }
  247.     Ti.API.info('adjusted platform width ' + platformWidth);
  248.     Ti.API.info('adjusted platform height ' + platformHeight);
  249.    
  250.     var touchBlockView = Ti.UI.createView(
  251.     {
  252.         // width : Ti.Platform.displayCaps.platformWidth,
  253.         // height : Ti.Platform.displayCaps.platformHeight,
  254.         width : platformWidth,
  255.         height : platformHeight,
  256.         top : 0,
  257.         // left : Ti.Platform.displayCaps.platformWidth,
  258.         left : platformWidth,
  259.         //backgroundColor : 'pink',
  260.         //opacity : 0.6,
  261.         zIndex : 999
  262.     });
  263.  
  264.     var tidbitViewer = TidBitView();
  265.    
  266.     function showTidBitView(e)
  267.     {
  268.         Ti.App.Properties.setBool('activityMomentViewPresent', true);
  269.         tidbitViewer.setDescription(e.description);
  270.         tidbitViewer.setLeft(0);
  271.         tidbitViewer.animate(
  272.         {
  273.             opacity : 1,
  274.             duration : 200
  275.         });
  276.     }
  277.  
  278.  
  279.     Ti.App.addEventListener('showTidBitView', showTidBitView);
  280.  
  281.     function hideTidBitView(e)
  282.     {
  283.         tidbitViewer.animate(
  284.         {
  285.             opacity : 0,
  286.             duration : 200
  287.         });
  288.     }
  289.  
  290.  
  291.     Ti.App.addEventListener('hideTidBitView', hideTidBitView);
  292.  
  293.     var mainView = new MainView();
  294.     var menuView;// = new MenuView(usuario, self.setCurrentBaby);
  295.     //self.add(menuView);
  296.     var curX;
  297.     var deltaX;
  298.     var currentPositionX;
  299.  
  300.     var menuDisplayed = false;
  301.     var menuFriendsDisplayed = false;
  302.  
  303.     // var touchingShowMenuViewInitialLeft = Ti.Platform.displayCaps.platformWidth;
  304.     var touchingShowMenuViewInitialLeft = platformWidth;
  305.     var touchingShowMenuView = Ti.UI.createView(
  306.     {
  307.         // width : Ti.Platform.displayCaps.platformWidth,
  308.         // height : Ti.Platform.displayCaps.platformHeight,
  309.         width : platformWidth,
  310.         height : platformHeight,
  311.         left : 245 + dpi,
  312.         top : "0dp",
  313.         backgroundColor : "red",
  314.         zIndex : 4,
  315.         opacity : ".5"
  316.  
  317.     });
  318.  
  319.     var titleMenuButtonHolderMain = Ti.UI.createView(
  320.     {
  321.         // width : Ti.Platform.displayCaps.platformWidth,
  322.         width : platformWidth,
  323.         height : Ti.UI.SIZE,
  324.         left : 0,
  325.         top : 0
  326.     });
  327.  
  328.     // var titleMenuButtonHolderDraggableWidth = Ti.Platform.displayCaps.platformWidth / 2;
  329.     var titleMenuButtonHolderDraggableWidth = platformWidth / 2;
  330.     var titleMenuButtonHolderDraggable = Ti.UI.createView(
  331.     {
  332.         height : "44dp",
  333.         width : titleMenuButtonHolderDraggableWidth,
  334.         left : 0,
  335.         top : 0,
  336.         zIndex : 1000,
  337.         backgroundColor : "transparent"
  338.     });
  339.  
  340.     var titleMenuButtonHolderDraggableRight = Ti.UI.createView(
  341.     {
  342.         height : "44dp",
  343.         width : titleMenuButtonHolderDraggableWidth,
  344.         right : 0,
  345.         top : 0,
  346.         zIndex : 1001,
  347.         backgroundColor : "transparent"
  348.     });
  349.    
  350.     // var animateDisplayMenu = Ti.UI.createAnimation(
  351.     // {
  352.         // left : 245 + dpi,
  353.         // duration : 350,
  354.         // //curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
  355.     // });
  356.     // var animateHideMenu = Ti.UI.createAnimation(
  357.     // {
  358.         // left : 0,
  359.         // duration : 350,
  360.         // //curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
  361.     // });
  362. //  
  363.     // var friendsLeft = "-245dp";
  364. //
  365.     // var animateDisplayFriends = Ti.UI.createAnimation(
  366.     // {
  367.         // left : friendsLeft,
  368.         // duration : 350,
  369.         // //curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
  370.     // });
  371. //
  372.     // var animateHideFriendsMenu = Ti.UI.createAnimation(
  373.     // {
  374.         // left : 0,
  375.         // duration : 350,
  376.         // //curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
  377.     // });
  378. //
  379.     // animateHideMenu.addEventListener("complete", function(e)
  380.     // {
  381. //
  382.         // //If the menu is hidden, then we need to show the moments button again.
  383.         // Ti.App.fireEvent("showMomentsButton");
  384. //
  385.         // Ti.API.info("animateHideMenu hideMenu");
  386.         // titleMenuButtonHolderMain.left = 0;
  387. //
  388.         // mainView.view.left = 0;
  389. //
  390.         // // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
  391.         // touchBlockView.setLeft(platformWidth);
  392.         // touchBlockView.setZIndex(999);
  393. //
  394.         // Ti.UI.setBackgroundColor('#0e76bc');
  395. //
  396.         // menuDisplayed = false;
  397.         // if (singletapLaunch == true)
  398.         // {
  399.             // singletapLaunch = false;
  400.         // }
  401.     // });
  402. //
  403.     // animateHideFriendsMenu.addEventListener("complete", function(e)
  404.     // {
  405. //
  406.         // //If the menu is hidden, then we need to show the moments button again.
  407.         // Ti.App.fireEvent("showMomentsButton");
  408. //
  409.         // Ti.API.info("animateHideFriendsMenu hideMenu");
  410.         // titleMenuButtonHolderMain.left = 0;
  411. //
  412.         // mainView.view.left = 0;
  413. //
  414.         // // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
  415.         // touchBlockView.setLeft(platformWidth);
  416.         // touchBlockView.setZIndex(999);
  417.         // //menuDisplayed = false;
  418. //
  419.         // Ti.UI.setBackgroundColor('#0e76bc');
  420. //
  421.         // menuFriendsDisplayed = false;
  422. //
  423.         // if (singletapLaunch == true)
  424.         // {
  425.             // singletapLaunch = false;
  426.         // }
  427. //
  428.     // });
  429. //
  430.     // animateDisplayFriends.addEventListener("complete", function(e)
  431.     // {
  432. //
  433.         // //If the menu is showing, then we need to hide the moments button again.
  434. //
  435.         // Ti.API.info("animateDisplayFriends showMenu");
  436.         // titleMenuButtonHolderMain.left = "-245" + dpi;
  437.         // mainView.view.left = "-245" + dpi;
  438.         // touchBlockView.setLeft("-245" + dpi);
  439.         // touchBlockView.setZIndex(999);
  440. //
  441.         // Ti.UI.setBackgroundColor('#000000');
  442. //
  443.         // menuFriendsDisplayed = true;
  444. //
  445.         // if (singletapLaunch == true)
  446.         // {
  447.             // singletapLaunch = false;
  448.         // }
  449.     // });
  450. //
  451.     // animateDisplayMenu.addEventListener("complete", function(e)
  452.     // {
  453. //
  454.         // //If the menu is hidden, then we need to show the moments button again.
  455.         // //Ti.App.fireEvent("showMomentsButton");
  456. //
  457.         // Ti.API.info("animateDisplayMenu showMenu");
  458.         // titleMenuButtonHolderMain.left = "245dp";
  459.         // mainView.view.left = "245dp";
  460.         // touchBlockView.setLeft(245 + dpi);
  461.         // touchBlockView.setZIndex(999);
  462.         // menuDisplayed = true;
  463.         // if (singletapLaunch == true)
  464.         // {
  465.             // singletapLaunch = false;
  466.         // }
  467.     // });
  468. //
  469.     // animateDisplayFriends.addEventListener("complete", function(e)
  470.     // {
  471. //
  472.         // //If the menu is showing, then we need to hide the moments button again.
  473.         // Ti.App.fireEvent("hideMomentsButton");
  474. //
  475.         // Ti.API.info("animateDisplayFriends showMenu");
  476.         // titleMenuButtonHolderMain.right = 245;
  477.         // mainView.view.right = 245;
  478.         // touchBlockView.setRight(245 + dpi);
  479.         // touchBlockView.setZIndex(999);
  480. //
  481.         // Ti.UI.setBackgroundColor('#000000');
  482. //
  483.         // menuFriendsDisplayed = true;
  484. //
  485.         // if (singletapLaunch == true)
  486.         // {
  487.             // singletapLaunch = false;
  488.         // }
  489.     // });
  490.     // function switchMenuVisibility(e)
  491.     // {
  492.         // if (menuDisplayed == true)
  493.         // {
  494.             // mainView.view.setLeft(245 + dpi);
  495.             // touchBlockView.setLeft(245 + dpi);
  496.             // touchBlockView.setZIndex(999);
  497.             // mainView.view.animate(animateHideMenu, function(e){
  498. //             
  499.                 // if(Ti.App.Properties.getString('current_app')=="Moments") // moments needs a little delay.
  500.                 // {
  501.                     // Ti.App.fireEvent("initialLoadMoments");
  502.                 // }
  503. //             
  504.             // });
  505.             // touchingShowMenuView.visible = false;
  506.             // menuDisplayed = false;
  507.             // return;
  508. //
  509.         // }
  510.         // else
  511.         // {
  512.             // mainView.view.setLeft(0);
  513.             // // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
  514.             // touchBlockView.setLeft(platformWidth);
  515.             // touchBlockView.setZIndex(999);
  516.             // mainView.view.animate(animateDisplayMenu);
  517.             // touchingShowMenuView.visible = true;
  518. //
  519.             // Ti.UI.setBackgroundColor('#000000');
  520. //
  521.             // menuDisplayed = true;
  522.             // return;
  523.         // }
  524.     // }
  525.     // Ti.App.addEventListener("switchMenuVisibility", switchMenuVisibility);
  526.     var singletapLaunch = false;
  527.     // titleMenuButtonHolderDraggable.addEventListener("singletap", function(e)
  528.     // {
  529.         // // show menu
  530.         // Ti.API.info("titleMenuButtonHolderDraggable singletap on title menu");
  531.         // Ti.API.info(singletapLaunch);
  532.         // singletapLaunch = true;
  533. //
  534.         // if (menuDisplayed == true)
  535.         // {
  536.             // Ti.API.info('single tap to display menu');
  537.             // mainView.view.setLeft(245 + dpi);
  538.             // touchBlockView.setLeft(245 + dpi);
  539.             // mainView.view.animate(animateHideMenu);
  540.             // touchingShowMenuView.visible = false;
  541.             // // menuDisplayed = false;
  542.             // return;
  543. //
  544.         // }
  545.         // else
  546.         // {
  547.             // Ti.API.info('titleMenuButtonHolderDraggable single tap to hide menu');
  548.             // mainView.view.setLeft(0);
  549.             // // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
  550.             // touchBlockView.setLeft(platformWidth);
  551. //
  552.             // Ti.App.fireEvent("hideMomentsButton");
  553.             // mainView.view.animate(animateDisplayMenu);
  554. //
  555.             // touchingShowMenuView.visible = false;
  556. //
  557.             // return;
  558.         // }
  559.     // });
  560.     // touchBlockView.addEventListener('singletap', function(e)
  561.     // {
  562.         // Ti.API.info("singletap on touchBlockView");
  563.         // Ti.API.info(singletapLaunch);
  564. //
  565.         // if (menuDisplayed == true)
  566.         // {
  567.             // Ti.API.info('single tap touchBlockView to display menu');
  568.             // mainView.view.setLeft(245 + dpi);
  569.             // touchBlockView.setLeft(245 + dpi);
  570. //
  571.             // mainView.view.animate(animateHideMenu, function(e)
  572.             // {
  573.                 // menuView.animate(
  574.                 // {
  575.                     // left : 0,
  576.                     // duration : 1
  577.                 // });
  578.             // });
  579. //
  580.             // touchingShowMenuView.visible = false;
  581.             // // menuDisplayed = false;
  582.             // return;
  583. //
  584.         // }
  585. //
  586.         // if (menuFriendsDisplayed == true)
  587.         // {
  588.             // Ti.API.info('single tap to display menu');
  589.             // //mainView.view.setLeft((-1)*245 + dpi);
  590.             // //touchBlockView.setLeft((-1)*245 + dpi);
  591.             // Ti.API.info('mainView.view left ' + mainView.view.left);
  592.             // mainView.view.animate(animateHideFriendsMenu, function(e)
  593.             // {
  594.                 // menuView.animate(
  595.                 // {
  596.                     // left : 0,
  597.                     // duration : 1
  598.                 // });
  599.             // });
  600.             // touchingShowMenuView.visible = false;
  601.             // // menuDisplayed = false;
  602.         // }
  603. //
  604.         // else
  605.         // {
  606.             // Ti.API.info('single tap to hide menu');
  607.             // Ti.API.info('mainView.view left ' + mainView.view.left);
  608. //
  609.             // // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
  610.             // touchBlockView.setLeft(platformWidth);
  611.             // mainView.view.animate(animateDisplayMenu, function(e)
  612.             // {
  613.                 // mainView.view.setLeft(0);
  614.             // });
  615.             // touchingShowMenuView.visible = false;
  616.             // // menuDisplayed = true;
  617.             // return;
  618.         // }
  619.     // });
  620.     // titleMenuButtonHolderDraggable.addEventListener('touchstart', function(e)
  621.     // {
  622.         // curX = e.x;
  623.         // initialViewX = parseInt(mainView.view.getLeft());
  624.         // Ti.API.info("curX: " + curX);
  625.         // Ti.API.info("initialViewX: " + initialViewX);
  626.     // });
  627. //
  628.     // titleMenuButtonHolderDraggable.addEventListener('touchmove', function(e)
  629.     // {
  630.         // deltaX = e.x - curX;
  631.         // // Ti.API.info("deltaX: " + deltaX);
  632.         // currentPositionX = initialViewX + deltaX;
  633.         // if (currentPositionX > 0)
  634.         // {
  635.             // // Ti.API.info("currentPositionX: " + currentPositionX);
  636.             // mainView.view.setLeft(currentPositionX);
  637.         // }
  638.     // });
  639. //
  640.     // titleMenuButtonHolderDraggable.addEventListener('touchend', function(e)
  641.     // {
  642. //
  643.         // Ti.API.info("touch end");
  644.         // Ti.API.info(singletapLaunch);
  645.         // if (singletapLaunch == false)
  646.         // {
  647.             // Ti.API.info('touch end after a drag');
  648.             // if (mainView.view.getLeft() < 150)
  649.             // {
  650.                 // Ti.API.info('titleMenuButtonHolderDraggable hiding menu');
  651.                 // mainView.view.animate(animateHideMenu);
  652.                 // touchingShowMenuView.visible = false;
  653.                 // // menuDisplayed = false;
  654. //
  655.             // }
  656.             // else
  657.             // if (mainView.view.getLeft() > 150)
  658.             // {
  659.                 // Ti.API.info('titleMenuButtonHolderDraggable showing menu');
  660.                 // mainView.view.animate(animateDisplayMenu);
  661.                 // touchingShowMenuView.visible = true;
  662.                 // // menuDisplayed = true;
  663.             // }
  664. //
  665.         // }
  666.     // });
  667.  
  668.  
  669.     // dragging SecondLevel view code
  670.     function draggableFunctions()
  671.     {
  672.         var curX;
  673.         var deltaX;
  674.         var currentPositionX;
  675.         var initialViewX = mainView.view.getLeft();
  676.    
  677.         var menuDisplayed = false;
  678.         var menuFriendsDisplayed = false;
  679.    
  680.         var animateDisplayMenu = Ti.UI.createAnimation(
  681.         {
  682.             left : 245 + dpi,
  683.             duration : 350,
  684.             curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
  685.         });
  686.         var animateHideMenu = Ti.UI.createAnimation(
  687.         {
  688.             left : 0,
  689.             duration : 350,
  690.             curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
  691.         });
  692.    
  693.         var animateDisplayFriends = Ti.UI.createAnimation(
  694.         {
  695.             left : -245 + dpi,
  696.             duration : 350,
  697.             curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
  698.         });
  699.    
  700.         var animateHideFriendsMenu = Ti.UI.createAnimation(
  701.         {
  702.             left : 0,
  703.             duration : 350,
  704.             curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
  705.         });
  706.    
  707.         animateHideMenu.addEventListener("complete", function(e)
  708.         {
  709.    
  710.             //If the menu is hidden, then we need to show the moments button again.
  711.             Ti.App.fireEvent("showMomentsButton");
  712.    
  713.             Ti.API.info("draggableFunctions animateHideMenu hideMenu");
  714.             titleMenuButtonHolderMain.left = 0;
  715.    
  716.             mainView.view.left = 0;
  717.    
  718.             // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
  719.             touchBlockView.setLeft(platformWidth);
  720.             touchBlockView.setZIndex(999);
  721.    
  722.             Ti.UI.setBackgroundColor('#0e76bc');
  723.    
  724.             menuDisplayed = false;
  725.             if (singletapLaunch == true)
  726.             {
  727.                 singletapLaunch = false;
  728.             }
  729.         });
  730.    
  731.         animateHideFriendsMenu.addEventListener("complete", function(e)
  732.         {
  733.    
  734.             //If the menu is hidden, then we need to show the moments button again.
  735.             Ti.App.fireEvent("showMomentsButton");
  736.    
  737.             Ti.API.info("draggableFunctions animateHideFriendsMenu hideMenu");
  738.             titleMenuButtonHolderMain.left = 0;
  739.    
  740.             mainView.view.left = 0;
  741.    
  742.             // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
  743.             touchBlockView.setLeft(platformWidth);
  744.             touchBlockView.setZIndex(999);
  745.             //menuDisplayed = false;
  746.    
  747.             Ti.UI.setBackgroundColor('#0e76bc');
  748.    
  749.             menuFriendsDisplayed = false;
  750.    
  751.             if (singletapLaunch == true)
  752.             {
  753.                 singletapLaunch = false;
  754.             }
  755.    
  756.         });
  757.    
  758.         animateDisplayFriends.addEventListener("complete", function(e)
  759.         {
  760.    
  761.             //If the menu is showing, then we need to hide the moments button again.
  762.    
  763.             Ti.API.info("draggableFunctions animateDisplayFriends showMenu");
  764.             titleMenuButtonHolderMain.left = -245 + dpi;
  765.             mainView.view.left = -245 + dpi;
  766.             touchBlockView.setLeft(-245 + dpi);
  767.             touchBlockView.setZIndex(999);
  768.    
  769.             Ti.UI.setBackgroundColor('#000000');
  770.    
  771.             menuFriendsDisplayed = true;
  772.    
  773.             if (singletapLaunch == true)
  774.             {
  775.                 singletapLaunch = false;
  776.             }
  777.         });
  778.    
  779.         animateDisplayMenu.addEventListener("complete", function(e)
  780.         {
  781.    
  782.             //If the menu is hidden, then we need to show the moments button again.
  783.             //Ti.App.fireEvent("showMomentsButton");
  784.    
  785.             Ti.API.info("draggableFunctions animateDisplayMenu showMenu");
  786.             titleMenuButtonHolderMain.left = "245dp";
  787.             mainView.view.left = "245dp";
  788.             touchBlockView.setLeft(245 + dpi);
  789.             touchBlockView.setZIndex(999);
  790.             menuDisplayed = true;
  791.             if (singletapLaunch == true)
  792.             {
  793.                 singletapLaunch = false;
  794.             }
  795.         });
  796.    
  797.         animateDisplayFriends.addEventListener("complete", function(e)
  798.         {
  799.    
  800.             //If the menu is showing, then we need to hide the moments button again.
  801.             Ti.App.fireEvent("hideMomentsButton");
  802.    
  803.             Ti.API.info("draggableFunctions animateDisplayFriendsshowMenu");
  804.             titleMenuButtonHolderMain.right = 245;
  805.             mainView.view.right = 245;
  806.             touchBlockView.setRight(245 + dpi);
  807.             touchBlockView.setZIndex(999);
  808.    
  809.             Ti.UI.setBackgroundColor('#000000');
  810.    
  811.             menuFriendsDisplayed = true;
  812.    
  813.             if (singletapLaunch == true)
  814.             {
  815.                 singletapLaunch = false;
  816.             }
  817.         });
  818.    
  819.         function switchMenuVisibility(e)
  820.         {
  821.             if (menuDisplayed == true)
  822.             {
  823.                 mainView.view.setLeft(245 + dpi);
  824.                 touchBlockView.setLeft(245 + dpi);
  825.                 touchBlockView.setZIndex(999);
  826.                 mainView.view.animate(animateHideMenu, function(e){
  827.                    
  828.                     if(Ti.App.Properties.getString('current_app')=="Moments") // moments needs a little delay.
  829.                     {
  830.                         Ti.App.fireEvent("initialLoadMoments");
  831.                     }
  832.                    
  833.                 });
  834.                 touchingShowMenuView.visible = false;
  835.                 menuDisplayed = false;
  836.                 return;
  837.    
  838.             }
  839.             else
  840.             {
  841.                 mainView.view.setLeft(0);
  842.                 // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
  843.                 touchBlockView.setLeft(platformWidth);
  844.                 touchBlockView.setZIndex(999);
  845.                 mainView.view.animate(animateDisplayMenu);
  846.                 touchingShowMenuView.visible = true;
  847.    
  848.                 Ti.UI.setBackgroundColor('#000000');
  849.    
  850.                 menuDisplayed = true;
  851.                 return;
  852.             }
  853.         }
  854.    
  855.    
  856.         Ti.App.addEventListener("switchMenuVisibility", switchMenuVisibility);
  857.    
  858.         // var singletapLaunch = false;
  859.    
  860.         titleMenuButtonHolderDraggableRight.addEventListener("singletap", function(e)
  861.         {
  862.             // show friends
  863.             Ti.API.info("draggableFunctions titleMenuButtonHolderDraggableRight singletap on title menu");
  864.             Ti.API.info(singletapLaunch);
  865.             singletapLaunch = true;
  866.    
  867.             if (menuFriendsDisplayed == true)
  868.             {
  869.                 Ti.API.info('draggableFunctions titleMenuButtonHolderDraggableRight single tap to hide menu');
  870.                 Ti.API.info('mainView.view left ' + mainView.view.left);
  871.    
  872.                 // mainView.view.setLeft("-245dp");
  873.                 // touchBlockView.setLeft("-245dp");
  874.                 //mainView.view.animate(animateHideFriendsMenu);
  875.                 menuView.setLeft(0);
  876.                 touchingShowMenuView.visible = false;
  877.                 //menuFriendsDisplayed = false;
  878.                 return;
  879.    
  880.             }
  881.             else
  882.             {
  883.                 Ti.API.info('draggableFunctions titleMenuButtonHolderDraggableRight single tap to hide menu');
  884.                 Ti.API.info('mainView.view left ' + mainView.view.left);
  885.                 mainView.view.setLeft(0);
  886.                 // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
  887.                 touchBlockView.setLeft(platformWidth);
  888.    
  889.                 Ti.App.fireEvent("hideMomentsButton");
  890.                 mainView.view.animate(animateDisplayFriends);
  891.    
  892.                 try
  893.                 {
  894.                     var usuarioReport = JSON.parse(Ti.App.Properties.getString('user'));
  895.                     //usuario.user.name
  896.    
  897.                     var eventProperties = {"distinct_id" : usuarioReport.user.id};
  898.                     Ti.App.fireEvent("reportToMixPanel",{
  899.                         eventName : "[IA:Deed] Open friends menu",
  900.                         eventProperties : eventProperties
  901.                     });
  902.                 }
  903.                 catch(e)
  904.                 {
  905.                     //alert(e);
  906.                 }
  907.    
  908.                 menuView.setLeft("-245dp");
  909.                 menuView.animate(
  910.                 {
  911.                     left : ("-245dp"),
  912.                     duration : 1
  913.                 });
  914.                 touchingShowMenuView.visible = false;
  915.                 //menuFriendsDisplayed = true;
  916.                 return;
  917.             }
  918.         });
  919.    
  920.         titleMenuButtonHolderDraggable.addEventListener("singletap", function(e)
  921.         {
  922.             // show menu
  923.             Ti.API.info("draggableFunctions titleMenuButtonHolderDraggable singletap on title menu");
  924.             Ti.API.info(singletapLaunch);
  925.             singletapLaunch = true;
  926.    
  927.             if (menuDisplayed == true)
  928.             {
  929.                 Ti.API.info('draggableFunctions titleMenuButtonHolderDraggable single tap to display menu');
  930.                 Ti.API.info('mainView.view left ' + mainView.view.left);
  931.                 mainView.view.setLeft(245 + dpi);
  932.                 touchBlockView.setLeft(245 + dpi);
  933.                 mainView.view.animate(animateHideMenu);
  934.                 touchingShowMenuView.visible = false;
  935.                 // menuDisplayed = false;
  936.                 return;
  937.    
  938.             }
  939.             else
  940.             {
  941.                 Ti.API.info('draggableFunctions titleMenuButtonHolderDraggable single tap to hide menu');
  942.                 Ti.API.info('mainView.view left ' + mainView.view.left);
  943.                 mainView.view.setLeft(0);
  944.                 // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
  945.                 touchBlockView.setLeft(platformWidth);
  946.    
  947.                 Ti.App.fireEvent("hideMomentsButton");
  948.                 mainView.view.animate(animateDisplayMenu);
  949.    
  950.                 touchingShowMenuView.visible = false;
  951.    
  952.                 return;
  953.             }
  954.         });
  955.    
  956.         touchBlockView.addEventListener('singletap', function(e)
  957.         {
  958.             Ti.API.info("draggableFunctions touchBlockView singletap on touchBlockView");
  959.             Ti.API.info(singletapLaunch);
  960.    
  961.             if (menuDisplayed == true)
  962.             {
  963.                 Ti.API.info('draggableFunctions menuDisplayed touchBlockView single tap to display menu');
  964.                 Ti.API.info('mainView.view left ' + mainView.view.left);
  965.                 mainView.view.setLeft("245" + dpi);
  966.                 touchBlockView.setLeft("245" + dpi);
  967.    
  968.                 mainView.view.animate(animateHideMenu, function(e)
  969.                 {
  970.                     menuView.animate(
  971.                     {
  972.                         left : 0,
  973.                         duration : 1
  974.                     });
  975.                 });
  976.    
  977.                 touchingShowMenuView.visible = false;
  978.                 // menuDisplayed = false;
  979.                 return;
  980.    
  981.             }
  982.    
  983.             if (menuFriendsDisplayed == true)
  984.             {
  985.                 Ti.API.info('draggableFunctions menuFriendsDisplayed touchBlockView single tap to display menu');
  986.                 Ti.API.info('mainView.view left ' + mainView.view.left);
  987.                 //mainView.view.setLeft((-1)*245 + dpi);
  988.                 //touchBlockView.setLeft((-1)*245 + dpi);
  989.    
  990.                 mainView.view.animate(animateHideFriendsMenu, function(e)
  991.                 {
  992.                     menuView.animate(
  993.                     {
  994.                         left : 0,
  995.                         duration : 1
  996.                     });
  997.                 });
  998.                 touchingShowMenuView.visible = false;
  999.                 // menuDisplayed = false;
  1000.             }
  1001.    
  1002.             else
  1003.             {
  1004.                 Ti.API.info('draggableFunctions menuFriendsDisplayed touchBlockView single tap to hide menu');
  1005.                 Ti.API.info('mainView.view left ' + mainView.view.left);
  1006.    
  1007.                 // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
  1008.                 // touchBlockView.setLeft(platformWidth);
  1009.                 touchBlockView.setLeft("-245" + dpi);
  1010.                 mainView.view.animate(animateDisplayMenu, function(e)
  1011.                 {
  1012.                     mainView.view.setLeft(0);
  1013.                 });
  1014.                 touchingShowMenuView.visible = false;
  1015.                 // menuDisplayed = true;
  1016.                 return;
  1017.             }
  1018.         });
  1019.    
  1020.         titleMenuButtonHolderDraggable.addEventListener('touchstart', function(e)
  1021.         {
  1022.             curX = e.x;
  1023.             initialViewX = parseInt(mainView.view.getLeft());
  1024.             Ti.API.info("curX: " + curX);
  1025.             Ti.API.info("initialViewX: " + initialViewX);
  1026.         });
  1027.    
  1028.         titleMenuButtonHolderDraggable.addEventListener('touchmove', function(e)
  1029.         {
  1030.             deltaX = e.x - curX;
  1031.             // Ti.API.info("deltaX: " + deltaX);
  1032.             currentPositionX = initialViewX + deltaX;
  1033.             if (currentPositionX > 0)
  1034.             {
  1035.                 // Ti.API.info("currentPositionX: " + currentPositionX);
  1036.                 mainView.view.setLeft(currentPositionX);
  1037.             }
  1038.         });
  1039.    
  1040.         titleMenuButtonHolderDraggable.addEventListener('touchend', function(e)
  1041.         {
  1042.    
  1043.             Ti.API.info("draggableFunctions titleMenuButtonHolderDraggable touch end");
  1044.             Ti.API.info(singletapLaunch);
  1045.             if (singletapLaunch == false)
  1046.             {
  1047.                 Ti.API.info('draggableFunctions titleMenuButtonHolderDraggable touch end after a drag');
  1048.                 if (mainView.view.getLeft() < 150)
  1049.                 {
  1050.                     Ti.API.info('draggableFunctions titleMenuButtonHolderDraggable hiding menu');
  1051.                     mainView.view.animate(animateHideMenu);
  1052.                     touchingShowMenuView.visible = false;
  1053.                     // menuDisplayed = false;
  1054.    
  1055.                 }
  1056.                 else
  1057.                 if (mainView.view.getLeft() > 150)
  1058.                 {
  1059.                     Ti.API.info('draggableFunctions titleMenuButtonHolderDraggable showing menu');
  1060.                     mainView.view.animate(animateDisplayMenu);
  1061.                     touchingShowMenuView.visible = true;
  1062.                     // menuDisplayed = true;
  1063.                 }
  1064.    
  1065.             }
  1066.         });
  1067.     }
  1068.     //*************
  1069.     // chathead drag button
  1070.  
  1071.     // var screenWidth = Ti.Platform.displayCaps.platformWidth;
  1072.     // var screenHeight = Ti.Platform.displayCaps.platformHeight;
  1073.     var screenWidth = platformWidth;
  1074.     var screenHeight = platformHeight;
  1075.     var circleWidth = 88 * (Ti.Platform.displayCaps.dpi / 160);
  1076.     Ti.API.info('screen width ' + screenWidth + ' dpi ' + Ti.Platform.displayCaps.dpi);
  1077.     var originLeft = screenWidth - circleWidth + 20;
  1078.     Ti.API.info('original left ' + originLeft);
  1079.     originLeft = originLeft * (160 / Ti.Platform.displayCaps.dpi);
  1080.     Ti.API.info('left en dp ' + originLeft);
  1081.     var originTop = 88;
  1082.  
  1083.     var KineduMomentsButton = Ti.UI.createImageView(
  1084.     {
  1085.         bottom : "10dp",
  1086.         zIndex : 4,
  1087.         image : imagesPath + "KineduMoments.png",
  1088.         width : "77dp",
  1089.         height : "77dp"
  1090.  
  1091.     });
  1092.  
  1093.     Ti.App.addEventListener("showMomentsButton", function(e)
  1094.     {
  1095.         KineduMomentsButton.animate(
  1096.         {
  1097.             opacity : 1,
  1098.             duration : 150
  1099.         });
  1100.     });
  1101.     Ti.App.addEventListener("hideMomentsButton", function(e)
  1102.     {
  1103.         KineduMomentsButton.animate(
  1104.         {
  1105.             opacity : 0,
  1106.             duration : 150
  1107.         });
  1108.     });
  1109.  
  1110.     /*
  1111.     var dragView = Titanium.UI.createView({
  1112.     backgroundColor:'transparent',
  1113.     // backgroundColor:'black',
  1114.     // opacity : 0.7,
  1115.     width:88 + dpi,
  1116.     height:88 + dpi,
  1117.     zIndex : 5,
  1118.     left:originLeft + dpi,
  1119.     top:88 + dpi,
  1120.     });
  1121.  
  1122.     self.add(dragView);
  1123.  
  1124.     var curX, curY;
  1125.     var deltaX, deltaY;
  1126.     var initialViewX = parseFloat(KineduMomentsButton.getLeft()) * (Ti.Platform.displayCaps.dpi / 160);
  1127.     var initialViewY = parseFloat(KineduMomentsButton.getTop()) * (Ti.Platform.displayCaps.dpi / 160);
  1128.     var currentPositionX = initialViewX;
  1129.     var currentPositionY = initialViewY;
  1130.     //dragView.addEventListener('touchstart', function(e) {
  1131.     // Ti.API.info('initial x ' + initialViewX);
  1132.     // Ti.API.info('initial y ' + initialViewY);
  1133.     // Ti.API.info('drag left ' + dragView.getLeft());
  1134.     // Ti.API.info('drag top ' + dragView.getTop());
  1135.     //});
  1136.  
  1137.     dragView.addEventListener('touchmove', function(e) {
  1138.     curX = e.x;
  1139.     curY = e.y;
  1140.  
  1141.     deltaX = e.x - curX;
  1142.     deltaY = e.y - curY;
  1143.     currentPositionX = initialViewX + deltaX;
  1144.     currentPositionY = initialViewY + deltaY;
  1145.     // Ti.API.info('delta x ' + deltaX + ' delta  y ' + deltaY);
  1146.     // Ti.API.info('current position x ' + currentPositionX + ' current position y ' + currentPositionY);
  1147.     // Ti.API.info('');
  1148.     KineduMomentsButton.setLeft(currentPositionX);
  1149.     KineduMomentsButton.setTop(currentPositionY);
  1150.     });
  1151.  
  1152.     function recallControl()
  1153.     {
  1154.     var animateControlToOrigin = Ti.UI.createAnimation({
  1155.     left:initialViewX + dpi,
  1156.     top:initialViewY + dpi,
  1157.     duration:300,
  1158.     });
  1159.     animateControlToOrigin.addEventListener("complete", function(e){
  1160.     // Ti.API.info('animacion completada en kinedu moment button');
  1161.     KineduMomentsButton.setLeft(initialViewX + dpi);
  1162.     KineduMomentsButton.setTop(initialViewY + dpi);
  1163.     initialViewX = initialViewX * ( Ti.Platform.displayCaps.dpi / 160);
  1164.     initialViewY = initialViewY * ( Ti.Platform.displayCaps.dpi / 160);
  1165.     });
  1166.  
  1167.     KineduMomentsButton.animate(animateControlToOrigin);
  1168.     }
  1169.  
  1170.     dragView.addEventListener("touchend", function(e) {
  1171.     deltaX = 0;
  1172.     deltaY = 0;
  1173.     var factor = 160 * (Ti.Platform.displayCaps.dpi / 160);
  1174.  
  1175.     if (currentPositionX < (screenWidth / 2) - (circleWidth / 2)) {
  1176.     initialViewX = -20;
  1177.     if (currentPositionY < (screenHeight / 2) - (circleWidth / 2)) {
  1178.     initialViewY = originTop;
  1179.     } else {
  1180.     initialViewY = currentPositionY * (160 / Ti.Platform.displayCaps.dpi);
  1181.     }
  1182.     } else// to the right
  1183.     {
  1184.     initialViewX = originLeft;
  1185.     initialViewY = currentPositionY * (160 / Ti.Platform.displayCaps.dpi);
  1186.     }
  1187.     // Ti.API.info('current x ' + currentPositionX + ' current y ' + currentPositionY);
  1188.     // Ti.API.info('initial x ' + initialViewX + ' initial y ' + initialViewY);
  1189.     dragView.setLeft(initialViewX + dpi);
  1190.     dragView.setTop(initialViewY + dpi);
  1191.     recallControl();
  1192.  
  1193.     });
  1194.     */
  1195.  
  1196.     //*************
  1197.  
  1198.     var createMomentWindowOpen = false;
  1199.  
  1200.     KineduMomentsButton.addEventListener("singletap", function(e)
  1201.     {
  1202.  
  1203.         // Ti.API.info('current x ' + currentPositionX + ' current y ' + currentPositionY);
  1204.         // currentPositionX = initialViewX;
  1205.         // currentPositionY = initialViewY;
  1206.         if (!createMomentWindowOpen)
  1207.         {
  1208.             createMomentWindowOpen = true;
  1209.             var GenericWindow = require('ui/android/GenericWindow');
  1210.             var windowType = 'normal';
  1211.             if (Ti.App.Properties.getObject('currentActivity') !== null)
  1212.             {
  1213.                 windowType = 'activity';
  1214.             }
  1215.             var momentWindow = new GenericWindow(
  1216.             {
  1217.                 title : 'new moment',
  1218.                 type : windowType
  1219.             });
  1220.             momentWindow.setActivity(self.activity);
  1221.  
  1222.             momentWindow.applyProperties(
  1223.             {
  1224.                 // width : Ti.Platform.displayCaps.platformWidth,
  1225.                 // height : Ti.Platform.displayCaps.platformHeight,
  1226.                 // top : Ti.Platform.displayCaps.platformHeight,
  1227.                 width : platformWidth,
  1228.                 height : platformHeight,
  1229.                 top : platformHeight,
  1230.                 left : 0,
  1231.             });
  1232.             var CreateMoment = require('ui/common/CreateMoment');
  1233.            
  1234.             try
  1235.             {
  1236.                 var createMomentView = new CreateMoment();
  1237.                 // momentWindow.add(createMomentView);
  1238.                 momentWindow.addView(createMomentView);
  1239.                 // createMomentView.setParent(momentWindow);
  1240.                 createMomentView.fireEvent('setParent',
  1241.                 {
  1242.                     win : momentWindow
  1243.                 });
  1244.  
  1245.                 self.fireEvent('addWindow',
  1246.                 {
  1247.                     windowToAdd : momentWindow
  1248.                 });
  1249.                 createMomentView.openCamera();
  1250.             }
  1251.             catch(err)
  1252.             {
  1253.                 Ti.API.info('No babies to create moment');
  1254.             }
  1255.  
  1256.         }
  1257.     });
  1258.  
  1259.     //*************
  1260.  
  1261.     //self.add(mainView.view);
  1262.     //self.add(touchBlockView);
  1263.  
  1264.     titleMenuButtonHolderMain.add(titleMenuButtonHolderDraggable);
  1265.     titleMenuButtonHolderMain.add(titleMenuButtonHolderDraggableRight);
  1266.  
  1267.     //self.add(titleMenuButtonHolderMain);
  1268.  
  1269.     //self.add(KineduMomentsButton);
  1270.  
  1271.     //self.add(tidbitViewer);
  1272.  
  1273.     function findApp(appName, babyId)
  1274.     {
  1275.         for (var i = 0; i < appHolder.length; i++)
  1276.         {
  1277.             if (appHolder[i].name == appName && appHolder[i].babyId == babyId)
  1278.             {
  1279.                 if (Ti.App.Properties.getString('todayAppIsNull') === 'true')
  1280.                 {
  1281.                     appHolder.splice(i, 1);
  1282.                     Ti.API.info('it exists but it was an empty view');
  1283.                     return null;
  1284.                 }
  1285.                 else
  1286.                 {
  1287.                     Ti.API.info('it exists');
  1288.                     return appHolder[i].app;
  1289.                 }
  1290.             }
  1291.         }
  1292.         Ti.API.info('it does not exist');
  1293.         return null;
  1294.     }
  1295.  
  1296.     function switchApp(e)
  1297.     {
  1298.         var current_app = Ti.App.Properties.getString('current_app');
  1299.  
  1300.         //Ti.API.info('current ' + current_app + ' e.app ' + e.app + ' e.id ' + e.id + ' currentBaby ' + Ti.App.Properties.getString('currentBaby'));
  1301.         if (e.app !== current_app || e.id !== parseInt(Ti.App.Properties.getString('currentBaby')))
  1302.         {
  1303.             mainView.removeApp();
  1304.             Ti.App.Properties.setString('currentBaby', e.id);
  1305.            
  1306.             try
  1307.             {
  1308.                 var usuarioReport = JSON.parse(Ti.App.Properties.getString('user'));
  1309.                 var eventProperties = {"distinct_id":usuarioReport.user.id, "switchedTo":e.app};
  1310.                 Ti.App.fireEvent("reportToMixPanel", {eventName:"[IA:Deed] SwtitchApp", eventProperties:eventProperties});
  1311.             }
  1312.             catch(e)
  1313.                         {
  1314.                 //alert(e);
  1315.             }
  1316.            
  1317.             Ti.API.info("SwitchingApps=>"+JSON.stringify(e.app));
  1318.  
  1319.             switch(e.app)
  1320.             {
  1321.                 case "NoBabies":
  1322.                     //currentApp = findApp("NoBabies",-1);
  1323.                     Ti.API.info("NoBabiesAppSwitchedTo");
  1324.                     currentApp = new NoBabies();
  1325.                     appHolder.push({name:"NoBabies",babyId:-1, app:currentApp});           
  1326.                
  1327.                 break;
  1328.                
  1329.                 case "Progress":
  1330.                
  1331.                     try
  1332.                     {
  1333.                         var reportActiveUser = JSON.parse(Ti.App.Properties.getString('user'));
  1334.                         var mp_babyId = Ti.App.Properties.getString('currentBaby');
  1335.                         var eventProperties = { "user": reportActiveUser, "baby": mp_babyId} ;
  1336.                         Ti.App.fireEvent("reportToMixPanel", {eventName:"[IA:View] Baby stats", eventProperties:eventProperties});
  1337.                     }
  1338.                     catch(e)
  1339.                     {
  1340.                         Ti.API.info("Reporting To MixPanel=>" +e);
  1341.                     }
  1342.  
  1343.                     var babyProfile = findApp("Progress", e.id);
  1344.  
  1345.                     if (babyProfile == null)
  1346.                     {
  1347.                         var babyProfile = new BabyProfile(e.id);
  1348.                         currentApp = babyProfile.view;
  1349.                         appHolder.push(
  1350.                         {
  1351.                             name : "Progress",
  1352.                             babyId : e.id,
  1353.                             app : babyProfile
  1354.                         });
  1355.                     }
  1356.                     else
  1357.                     {
  1358.                         currentApp = babyProfile.view;
  1359.                         babyProfile.refresh();
  1360.                     }
  1361.                    
  1362.                     //expand this baby.
  1363.                     Ti.App.fireEvent("babyOptionsToggle", {babyId:e.id});
  1364.  
  1365.                     break;
  1366.                 case "Moments":
  1367.  
  1368.                     try
  1369.                     {
  1370.                         currentApp = findApp("Moments", e.id);
  1371.                        
  1372.                         try
  1373.                         {
  1374.                             var reportActiveUser = JSON.parse(Ti.App.Properties.getString('user'));
  1375.                             var mp_babyId = Ti.App.Properties.getString('currentBaby');
  1376.                             var eventProperties = { "user": reportActiveUser, "baby": mp_babyId} ;
  1377.                             Ti.App.fireEvent("reportToMixPanel", {eventName:"[IA:View] Baby stats", eventProperties:eventProperties});
  1378.                         }
  1379.                         catch(e)
  1380.                         {
  1381.                             Ti.API.info("Reporting To MixPanel=>" +e);
  1382.                         }
  1383.                        
  1384.                         if (currentApp == null)
  1385.                         {
  1386.                             currentApp = new Moments(e.id);
  1387.                             appHolder.push(
  1388.                             {
  1389.                                 name : "Moments",
  1390.                                 babyId : e.id,
  1391.                                 app : currentApp
  1392.                             });
  1393.                         }
  1394.                     }
  1395.                     catch(err)
  1396.                     {
  1397.                         Ti.API.info("err " + err + "e.id " + e.id);
  1398.                     }
  1399.  
  1400.                     break;
  1401.                 case "Today":
  1402.                    
  1403.  
  1404.                     if (Ti.App.Properties.getBool('canReadKinedugram'))
  1405.                     {
  1406.                         try
  1407.                         {
  1408.                             var reportActiveUser = JSON.parse(Ti.App.Properties.getString('user'));
  1409.                             var eventProperties =
  1410.                             {
  1411.                                 "user" : reportActiveUser,
  1412.                                 "baby" : e.id
  1413.                             };
  1414.                             Ti.App.fireEvent("reportToMixPanel",
  1415.                             {
  1416.                                 eventName : "[IA:View] Kinedugram",
  1417.                                 eventProperties : eventProperties
  1418.                             });
  1419.                         }
  1420.                         catch(e)
  1421.                         {
  1422.                             //alert(e);
  1423.                         }
  1424.  
  1425.                         currentApp = findApp("Today", e.id);
  1426.                         if (currentApp == null)
  1427.                         {
  1428.                             currentApp = new Today(e.id);
  1429.                             appHolder.push(
  1430.                             {
  1431.                                 name : "Today",
  1432.                                 babyId : e.id,
  1433.                                 app : currentApp
  1434.                             });
  1435.                         }
  1436.                     }
  1437.                     else {
  1438.                         var dialog = Ti.UI.createAlertDialog(
  1439.                         {
  1440.                             cancel : 1,
  1441.                             buttonNames : ['222', '22'],
  1442.                             message : "4444",
  1443.                             title : "444"
  1444.                         });
  1445.                        
  1446.                         dialog.show();
  1447.                     }
  1448.                    
  1449.                     //currentApp = new Today(e.id);
  1450.                     break;
  1451.                 case "Favorites":
  1452.  
  1453.                     currentApp = findApp("Favorites", e.id);
  1454.                     if (currentApp == null)
  1455.                     {
  1456.                         currentApp = new Favorites(e.id);
  1457.                         appHolder.push(
  1458.                         {
  1459.                             name : "Favorites",
  1460.                             babyId : e.id,
  1461.                             app : currentApp
  1462.                         });
  1463.                     }
  1464.  
  1465.                     break;
  1466.                 case "Friends":
  1467.  
  1468.                     currentApp = findApp("Friends", e.id);
  1469.                     if (currentApp == null)
  1470.                     {
  1471.                         currentApp = new Friends(e.id);
  1472.                         appHolder.push(
  1473.                         {
  1474.                             name : "Friends",
  1475.                             babyId : e.id,
  1476.                             app : currentApp
  1477.                         });
  1478.                     }
  1479.  
  1480.                     break;
  1481.                 case "Achievements":
  1482.  
  1483.                     currentApp = findApp("Achievements", e.id);
  1484.                     if (currentApp == null)
  1485.                     {
  1486.                         currentApp = new Badges(e.id);
  1487.                         appHolder.push(
  1488.                         {
  1489.                             name : "Achievements",
  1490.                             babyId : e.id,
  1491.                             app : currentApp
  1492.                         });
  1493.                     }
  1494.  
  1495.                     break;
  1496.                 case "CareGiver":
  1497.  
  1498.                     currentApp = findApp("CareGiver", e.id);
  1499.                     if (currentApp == null)
  1500.                     {
  1501.                         currentApp = new CareGiverProfile(e.id);
  1502.                         appHolder.push(
  1503.                         {
  1504.                             name : "CareGiver",
  1505.                             babyId : e.id,
  1506.                             app : currentApp
  1507.                         });
  1508.                     }
  1509.  
  1510.                     //currentApp = new CareGiverProfile(usuario);
  1511.                     break;
  1512.             }
  1513.             if ( typeof currentApp.setParentWindow !== 'undefined')
  1514.             {
  1515.                 currentApp.setParentWindow(self);
  1516.             }
  1517.             Ti.App.Properties.setString('current_app', e.app);
  1518.             mainView.swapView(currentApp, e.showMenu);
  1519.         }
  1520.         else
  1521.         {
  1522.             // mainView.view.setLeft(0 + dpi);
  1523.             mainView.view.animate(animateHideMenu);
  1524.             Ti.UI.setBackgroundColor('#0e76bc');
  1525.             menuDisplayed = false;
  1526.         }
  1527.        
  1528.         mainView.removeWaiting();
  1529.  
  1530.     }
  1531.  
  1532.  
  1533.     Ti.App.addEventListener("switchApp", switchApp);
  1534.  
  1535.     self.addEventListener('addWindow', function(e)
  1536.     {
  1537.         Ti.API.info('addWindow');
  1538.         // Ti.API.info('parameters sent ' + JSON.stringify(e));
  1539.         // Ti.API.info('window to be added ' + e.windowToAdd);
  1540.         var win = e.windowToAdd;
  1541.         self.add(win);
  1542.         win.animate(
  1543.         {
  1544.             top : 0,
  1545.             left : 0,
  1546.             duration : 600
  1547.         });
  1548.     });
  1549.  
  1550.     self.addEventListener('removeWindow', function(e)
  1551.     {
  1552.         Ti.API.info('removeWindow');
  1553.         // Ti.API.info('parameters sent ' + JSON.stringify(e));
  1554.         // Ti.API.info('window to be removed ' + e.windowToRemove);
  1555.         var win = e.windowToRemove;
  1556.         self.remove(win);
  1557.         createMomentWindowOpen = false;
  1558.     });
  1559.  
  1560.     var androidActivity = Ti.Android.currentActivity;
  1561.  
  1562.     androidActivity.addEventListener('destroy', function(e)
  1563.     {
  1564.         Ti.API.info('Android Activity Destroyed');
  1565.  
  1566.         Ti.App.Properties.setString('currentBaby', null);
  1567.         Ti.App.Properties.setString('current_app', 'Today');
  1568.         Ti.App.Properties.setObject('currentActivity', null);
  1569.  
  1570.         Ti.App.Properties.setObject('currentArea', null);
  1571.  
  1572.         var tmpImage = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, ('baby_temp.png'));
  1573.         if (tmpImage.exists())
  1574.         {
  1575.             tmpImage.deleteFile();
  1576.         }
  1577.         var tmpVideo = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, ('baby_temp.mp4'));
  1578.         if (tmpVideo.exists())
  1579.         {
  1580.             tmpVideo.deleteFile();
  1581.         }
  1582.     });
  1583.    
  1584.  
  1585.     //AccelerateOpenSpeed
  1586.     self.addEventListener("open", function(e)
  1587.     {
  1588.        
  1589.         //mainView = new MainView();
  1590.         menuView = new MenuView(usuario, self.setCurrentBaby);
  1591.  
  1592.         disappearLoading();
  1593.  
  1594.         selfLoadingView.animate(
  1595.         {
  1596.             opacity : "0",
  1597.             duration : 800
  1598.         }, function(e)
  1599.         {
  1600.  
  1601.             menuView.setOpacity("0");
  1602.             self.add(menuView);
  1603.             draggableFunctions();
  1604.  
  1605.             mainView.view.setOpacity("0");
  1606.  
  1607.             self.add(mainView.view);
  1608.  
  1609.             mainView.view.animate(
  1610.             {
  1611.                 opacity : "1",
  1612.                 duration : 300
  1613.             }, function(e)
  1614.             {
  1615.                 self.add(touchBlockView);
  1616.                 self.add(titleMenuButtonHolderMain);
  1617.                 self.add(KineduMomentsButton);
  1618.                 self.add(tidbitViewer);
  1619.                 menuView.setOpacity("1");
  1620.             });
  1621.  
  1622.         });
  1623.  
  1624.     });
  1625.  
  1626.  
  1627.     return self;
  1628. }
  1629.  
  1630. //make constructor function the public component interface
  1631. module.exports = ApplicationWindow;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement