Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var imagesPath;
- var fontName;
- var osname = Ti.Platform.osname;
- imagesPath = Titanium.Filesystem.resourcesDirectory + "images/";
- fontName = 'ArialRoundedBold';
- var dpi = 'dp';
- function ApplicationWindow(usuario)
- {
- //load component dependencies
- var MenuView = require('ui/common/Menu');
- var MainView = require('ui/common/MainView');
- var BabyProfile = require('ui/android/BabyProfile');
- var Friends = require('ui/common/Friends');
- var Moments = require('ui/common/Moments');
- var Activity = require('ui/android/Activity');
- var Favorites = require('ui/android/Favorites');
- var Today = require('ui/android/Today');
- var Badges = require('ui/common/Badges');
- var MomentDetails = require('ui/android/MomentDetails');
- var CareGiverProfile = require('ui/common/CareGiverProfile');
- var TidBitView = require('ui/common/TidBitViewer');
- var NoBabies = require('ui/common/NoBabies');
- // Variable for current displayed app on MainView
- var currentApp;
- // var runningApps = [];
- //create component instance
- var self = Ti.UI.createWindow(
- {
- backgroundColor : '#0e76bc',
- navBarHidden : true,
- exitOnClose : true
- });
- var selfLoadingView = Ti.UI.createView({
- width:Ti.UI.FILL,
- height:Ti.UI.SIZE,
- layout:"vertical"
- });
- var selfBackground = Ti.UI.createImageView({
- image:imagesPath + "img_avion.png",
- left:"0dp",
- width:"250dp"
- });
- var selfExplaination = Ti.UI.createLabel({
- text : L("Loading_string"),
- font:{
- fontSize:"38dp",
- fontFamily: 'HelveticaNeue-Light'
- },
- color : "#ffffff",
- width : Ti.UI.SIZE,
- height : Ti.UI.SIZE,
- textAlign : "left",
- left : "10dp",
- right:"60dp",
- top:"25dp"
- });
- // back button event listener
- self.addEventListener('android:back', function(e)
- {
- Ti.API.info('androidbackandroidnback');
- var upperViewPresent = Ti.App.Properties.getBool('activityMomentViewPresent');
- Ti.API.info('upperViewPresent ' + upperViewPresent);
- if(upperViewPresent)
- {
- Ti.App.fireEvent('closeUpperView');
- hideTidBitView();
- Ti.App.Properties.setBool('activityMomentViewPresent', false);
- }
- else
- {
- self.close({
- top : Ti.Platform.displayCaps.platformHeight,
- duration : 700
- });
- }
- });
- function disappearLoading()
- {
- indicator.hide();
- selfExplaination.setText(L("everything_loaded"));
- selfBackground.animate({opacity:"0", duration:1000}, function(e){
- selfExplaination.animate({opacity:"0", duration:700});
- });
- }
- var indicator = Ti.UI.createActivityIndicator({
- height : Ti.UI.SIZE,
- width : Ti.UI.SIZE
- });
- indicator.show();
- selfLoadingView.add(selfBackground);
- selfLoadingView.add(selfExplaination);
- selfLoadingView.add(indicator);
- self.add(selfLoadingView);
- Ti.UI.setBackgroundColor('#0e76bc');
- function removeListeners()
- {
- Ti.App.removeEventListener('switchApp', switchApp);
- //Ti.App.removeEventListener('switchMenuVisibility', switchMenuVisibility);
- Ti.App.removeEventListener('closeMainWindow', closeMainWindow);
- Ti.App.removeEventListener('reloadUserInfo', reloadUserInfo);
- }
- function closeMainWindow(e)
- {
- Ti.App.Properties.setBool('windowOpened', false);
- removeListeners();
- self.close();
- }
- Ti.App.addEventListener("closeMainWindow", closeMainWindow);
- function reloadUserInfo()
- {
- Ti.API.info('inside reloadUserInfo');
- var userId = usuario.user.id;
- var url = 'http://api.kinedu.com/api/v1/users/' + userId + '?locale=' + Ti.App.getUserDefinedLanguage();
- var token = Ti.App.Properties.getString('token');
- var client = Ti.Network.createHTTPClient(
- {
- onload : function(data)
- {
- Ti.API.info('Info del user ' + this.responseText);
- var response = JSON.parse(this.responseText);
- usuario.user = response;
- Ti.App.Properties.setString('user', JSON.stringify(usuario));
- Ti.App.fetchFamilyRequest;
- closeMainWindowForRestart();
- },
- onerror : function(data)
- {
- Ti.API.info('Error loading user info ' + this.responseText);
- Ti.API.info(JSON.stringify(data));
- },
- timeout : 35000
- });
- client.open('GET', url);
- client.setRequestHeader('Authorization', 'Token token=' + token);
- client.send();
- }
- function closeMainWindowForRestart(e)
- {
- removeListeners();
- // var babiesString = JSON.parse(Ti.App.Properties.getString('babies'));
- var babies = JSON.parse(Ti.App.Properties.getString('babies'));
- // var babies = Ti.App.Properties.getString('babies');
- for (var i = 0; i < babies.length; i++)
- {
- Ti.API.info('cache Kinedugram ' + Ti.App.Properties.getString('Activities_Cache_App_' + babies[i].id));
- Ti.API.info('cache Moments ' + Ti.App.Properties.getString('Moments_Cache_App_' + babies[i].id));
- Ti.API.info('cache Favorites ' + Ti.App.Properties.getString('Favorites_Cache_App_' + babies[i].id));
- Ti.App.Properties.removeProperty('Activities_Cache_App_' + babies[i].id);
- Ti.App.Properties.removeProperty('Favorites_Cache_App_' + babies[i].id);
- Ti.App.Properties.removeProperty('Moments_Cache_App_' + babies[i].id);
- Ti.API.info('after cache Kinedugram ' + Ti.App.Properties.getString('Activities_Cache_App_' + babies[i].id));
- Ti.API.info('after cache Moments ' + Ti.App.Properties.getString('Moments_Cache_App_' + babies[i].id));
- Ti.API.info('after cache Favorites ' + Ti.App.Properties.getString('Favorites_Cache_App_' + babies[i].id));
- }
- for (var i = 0; i < babies.length; i++)
- {
- Ti.API.info('another for cache Kinedugram ' + Ti.App.Properties.getString('Activities_Cache_App_' + babies[i].id));
- Ti.API.info('another for cache Moments ' + Ti.App.Properties.getString('Moments_Cache_App_' + babies[i].id));
- Ti.API.info('another for cache Favorites ' + Ti.App.Properties.getString('Favorites_Cache_App_' + babies[i].id));
- }
- //self.close();
- Ti.App.fireEvent('openWindow');
- }
- Ti.App.addEventListener("reloadUserInfo", reloadUserInfo);
- var currentBaby;
- //*************
- // fast app switching
- // Array that holds every app instace opened so far to enable a faster loading
- var appHolder = [];
- //*************
- self.setCurrentBaby = function(babyObj)
- {
- // currentBaby = id;
- // manageBabiesView = ManageBabies();
- // self.add(manageBabiesView);
- Ti.App.Properties.setBool('windowOpened', true);
- Ti.App.fireEvent('refreshManagement');
- currentBaby = babyObj.id;
- currentBabyName = babyObj.name;
- Ti.API.info('function current baby ' + currentBaby);
- Ti.App.Properties.setString('currentBaby', currentBaby);
- Ti.App.Properties.setString('currentBabyName', currentBabyName);
- if ( typeof babyObj.active_programme !== 'undefined')
- {
- Ti.App.Properties.setInt('currentProgramme', babyObj.active_programme.id);
- }
- currentApp = findApp("Today", currentBaby);
- if (currentApp == null)
- {
- currentApp = new Today(currentBaby);
- appHolder.push(
- {
- name : "Today",
- babyId : currentBaby,
- app : currentApp
- });
- }
- // Ti.API.info('function current baby ' + currentBaby);
- // Ti.App.Properties.setString('currentBaby', currentBaby);
- Ti.App.Properties.setString('current_app', 'Today');
- currentApp.setParentWindow(self);
- Ti.API.info('current app ' + Ti.App.Properties.getString('current_app'));
- mainView.swapView(currentApp, false);
- };
- var platformWidth = Ti.Platform.displayCaps.platformWidth;
- var platformHeight = Ti.Platform.displayCaps.platformHeight;
- Ti.API.info('platform width ' + platformWidth);
- Ti.API.info('platform height ' + platformHeight);
- if(platformWidth > platformHeight)
- {
- platformWidth = Ti.Platform.displayCaps.platformHeight;
- platformHeight = Ti.Platform.displayCaps.platformWidth;
- }
- Ti.API.info('adjusted platform width ' + platformWidth);
- Ti.API.info('adjusted platform height ' + platformHeight);
- var touchBlockView = Ti.UI.createView(
- {
- // width : Ti.Platform.displayCaps.platformWidth,
- // height : Ti.Platform.displayCaps.platformHeight,
- width : platformWidth,
- height : platformHeight,
- top : 0,
- // left : Ti.Platform.displayCaps.platformWidth,
- left : platformWidth,
- //backgroundColor : 'pink',
- //opacity : 0.6,
- zIndex : 999
- });
- var tidbitViewer = TidBitView();
- function showTidBitView(e)
- {
- Ti.App.Properties.setBool('activityMomentViewPresent', true);
- tidbitViewer.setDescription(e.description);
- tidbitViewer.setLeft(0);
- tidbitViewer.animate(
- {
- opacity : 1,
- duration : 200
- });
- }
- Ti.App.addEventListener('showTidBitView', showTidBitView);
- function hideTidBitView(e)
- {
- tidbitViewer.animate(
- {
- opacity : 0,
- duration : 200
- });
- }
- Ti.App.addEventListener('hideTidBitView', hideTidBitView);
- var mainView = new MainView();
- var menuView;// = new MenuView(usuario, self.setCurrentBaby);
- //self.add(menuView);
- var curX;
- var deltaX;
- var currentPositionX;
- var menuDisplayed = false;
- var menuFriendsDisplayed = false;
- // var touchingShowMenuViewInitialLeft = Ti.Platform.displayCaps.platformWidth;
- var touchingShowMenuViewInitialLeft = platformWidth;
- var touchingShowMenuView = Ti.UI.createView(
- {
- // width : Ti.Platform.displayCaps.platformWidth,
- // height : Ti.Platform.displayCaps.platformHeight,
- width : platformWidth,
- height : platformHeight,
- left : 245 + dpi,
- top : "0dp",
- backgroundColor : "red",
- zIndex : 4,
- opacity : ".5"
- });
- var titleMenuButtonHolderMain = Ti.UI.createView(
- {
- // width : Ti.Platform.displayCaps.platformWidth,
- width : platformWidth,
- height : Ti.UI.SIZE,
- left : 0,
- top : 0
- });
- // var titleMenuButtonHolderDraggableWidth = Ti.Platform.displayCaps.platformWidth / 2;
- var titleMenuButtonHolderDraggableWidth = platformWidth / 2;
- var titleMenuButtonHolderDraggable = Ti.UI.createView(
- {
- height : "44dp",
- width : titleMenuButtonHolderDraggableWidth,
- left : 0,
- top : 0,
- zIndex : 1000,
- backgroundColor : "transparent"
- });
- var titleMenuButtonHolderDraggableRight = Ti.UI.createView(
- {
- height : "44dp",
- width : titleMenuButtonHolderDraggableWidth,
- right : 0,
- top : 0,
- zIndex : 1001,
- backgroundColor : "transparent"
- });
- // var animateDisplayMenu = Ti.UI.createAnimation(
- // {
- // left : 245 + dpi,
- // duration : 350,
- // //curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
- // });
- // var animateHideMenu = Ti.UI.createAnimation(
- // {
- // left : 0,
- // duration : 350,
- // //curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
- // });
- //
- // var friendsLeft = "-245dp";
- //
- // var animateDisplayFriends = Ti.UI.createAnimation(
- // {
- // left : friendsLeft,
- // duration : 350,
- // //curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
- // });
- //
- // var animateHideFriendsMenu = Ti.UI.createAnimation(
- // {
- // left : 0,
- // duration : 350,
- // //curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
- // });
- //
- // animateHideMenu.addEventListener("complete", function(e)
- // {
- //
- // //If the menu is hidden, then we need to show the moments button again.
- // Ti.App.fireEvent("showMomentsButton");
- //
- // Ti.API.info("animateHideMenu hideMenu");
- // titleMenuButtonHolderMain.left = 0;
- //
- // mainView.view.left = 0;
- //
- // // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
- // touchBlockView.setLeft(platformWidth);
- // touchBlockView.setZIndex(999);
- //
- // Ti.UI.setBackgroundColor('#0e76bc');
- //
- // menuDisplayed = false;
- // if (singletapLaunch == true)
- // {
- // singletapLaunch = false;
- // }
- // });
- //
- // animateHideFriendsMenu.addEventListener("complete", function(e)
- // {
- //
- // //If the menu is hidden, then we need to show the moments button again.
- // Ti.App.fireEvent("showMomentsButton");
- //
- // Ti.API.info("animateHideFriendsMenu hideMenu");
- // titleMenuButtonHolderMain.left = 0;
- //
- // mainView.view.left = 0;
- //
- // // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
- // touchBlockView.setLeft(platformWidth);
- // touchBlockView.setZIndex(999);
- // //menuDisplayed = false;
- //
- // Ti.UI.setBackgroundColor('#0e76bc');
- //
- // menuFriendsDisplayed = false;
- //
- // if (singletapLaunch == true)
- // {
- // singletapLaunch = false;
- // }
- //
- // });
- //
- // animateDisplayFriends.addEventListener("complete", function(e)
- // {
- //
- // //If the menu is showing, then we need to hide the moments button again.
- //
- // Ti.API.info("animateDisplayFriends showMenu");
- // titleMenuButtonHolderMain.left = "-245" + dpi;
- // mainView.view.left = "-245" + dpi;
- // touchBlockView.setLeft("-245" + dpi);
- // touchBlockView.setZIndex(999);
- //
- // Ti.UI.setBackgroundColor('#000000');
- //
- // menuFriendsDisplayed = true;
- //
- // if (singletapLaunch == true)
- // {
- // singletapLaunch = false;
- // }
- // });
- //
- // animateDisplayMenu.addEventListener("complete", function(e)
- // {
- //
- // //If the menu is hidden, then we need to show the moments button again.
- // //Ti.App.fireEvent("showMomentsButton");
- //
- // Ti.API.info("animateDisplayMenu showMenu");
- // titleMenuButtonHolderMain.left = "245dp";
- // mainView.view.left = "245dp";
- // touchBlockView.setLeft(245 + dpi);
- // touchBlockView.setZIndex(999);
- // menuDisplayed = true;
- // if (singletapLaunch == true)
- // {
- // singletapLaunch = false;
- // }
- // });
- //
- // animateDisplayFriends.addEventListener("complete", function(e)
- // {
- //
- // //If the menu is showing, then we need to hide the moments button again.
- // Ti.App.fireEvent("hideMomentsButton");
- //
- // Ti.API.info("animateDisplayFriends showMenu");
- // titleMenuButtonHolderMain.right = 245;
- // mainView.view.right = 245;
- // touchBlockView.setRight(245 + dpi);
- // touchBlockView.setZIndex(999);
- //
- // Ti.UI.setBackgroundColor('#000000');
- //
- // menuFriendsDisplayed = true;
- //
- // if (singletapLaunch == true)
- // {
- // singletapLaunch = false;
- // }
- // });
- // function switchMenuVisibility(e)
- // {
- // if (menuDisplayed == true)
- // {
- // mainView.view.setLeft(245 + dpi);
- // touchBlockView.setLeft(245 + dpi);
- // touchBlockView.setZIndex(999);
- // mainView.view.animate(animateHideMenu, function(e){
- //
- // if(Ti.App.Properties.getString('current_app')=="Moments") // moments needs a little delay.
- // {
- // Ti.App.fireEvent("initialLoadMoments");
- // }
- //
- // });
- // touchingShowMenuView.visible = false;
- // menuDisplayed = false;
- // return;
- //
- // }
- // else
- // {
- // mainView.view.setLeft(0);
- // // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
- // touchBlockView.setLeft(platformWidth);
- // touchBlockView.setZIndex(999);
- // mainView.view.animate(animateDisplayMenu);
- // touchingShowMenuView.visible = true;
- //
- // Ti.UI.setBackgroundColor('#000000');
- //
- // menuDisplayed = true;
- // return;
- // }
- // }
- // Ti.App.addEventListener("switchMenuVisibility", switchMenuVisibility);
- var singletapLaunch = false;
- // titleMenuButtonHolderDraggable.addEventListener("singletap", function(e)
- // {
- // // show menu
- // Ti.API.info("titleMenuButtonHolderDraggable singletap on title menu");
- // Ti.API.info(singletapLaunch);
- // singletapLaunch = true;
- //
- // if (menuDisplayed == true)
- // {
- // Ti.API.info('single tap to display menu');
- // mainView.view.setLeft(245 + dpi);
- // touchBlockView.setLeft(245 + dpi);
- // mainView.view.animate(animateHideMenu);
- // touchingShowMenuView.visible = false;
- // // menuDisplayed = false;
- // return;
- //
- // }
- // else
- // {
- // Ti.API.info('titleMenuButtonHolderDraggable single tap to hide menu');
- // mainView.view.setLeft(0);
- // // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
- // touchBlockView.setLeft(platformWidth);
- //
- // Ti.App.fireEvent("hideMomentsButton");
- // mainView.view.animate(animateDisplayMenu);
- //
- // touchingShowMenuView.visible = false;
- //
- // return;
- // }
- // });
- // touchBlockView.addEventListener('singletap', function(e)
- // {
- // Ti.API.info("singletap on touchBlockView");
- // Ti.API.info(singletapLaunch);
- //
- // if (menuDisplayed == true)
- // {
- // Ti.API.info('single tap touchBlockView to display menu');
- // mainView.view.setLeft(245 + dpi);
- // touchBlockView.setLeft(245 + dpi);
- //
- // mainView.view.animate(animateHideMenu, function(e)
- // {
- // menuView.animate(
- // {
- // left : 0,
- // duration : 1
- // });
- // });
- //
- // touchingShowMenuView.visible = false;
- // // menuDisplayed = false;
- // return;
- //
- // }
- //
- // if (menuFriendsDisplayed == true)
- // {
- // Ti.API.info('single tap to display menu');
- // //mainView.view.setLeft((-1)*245 + dpi);
- // //touchBlockView.setLeft((-1)*245 + dpi);
- // Ti.API.info('mainView.view left ' + mainView.view.left);
- // mainView.view.animate(animateHideFriendsMenu, function(e)
- // {
- // menuView.animate(
- // {
- // left : 0,
- // duration : 1
- // });
- // });
- // touchingShowMenuView.visible = false;
- // // menuDisplayed = false;
- // }
- //
- // else
- // {
- // Ti.API.info('single tap to hide menu');
- // Ti.API.info('mainView.view left ' + mainView.view.left);
- //
- // // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
- // touchBlockView.setLeft(platformWidth);
- // mainView.view.animate(animateDisplayMenu, function(e)
- // {
- // mainView.view.setLeft(0);
- // });
- // touchingShowMenuView.visible = false;
- // // menuDisplayed = true;
- // return;
- // }
- // });
- // titleMenuButtonHolderDraggable.addEventListener('touchstart', function(e)
- // {
- // curX = e.x;
- // initialViewX = parseInt(mainView.view.getLeft());
- // Ti.API.info("curX: " + curX);
- // Ti.API.info("initialViewX: " + initialViewX);
- // });
- //
- // titleMenuButtonHolderDraggable.addEventListener('touchmove', function(e)
- // {
- // deltaX = e.x - curX;
- // // Ti.API.info("deltaX: " + deltaX);
- // currentPositionX = initialViewX + deltaX;
- // if (currentPositionX > 0)
- // {
- // // Ti.API.info("currentPositionX: " + currentPositionX);
- // mainView.view.setLeft(currentPositionX);
- // }
- // });
- //
- // titleMenuButtonHolderDraggable.addEventListener('touchend', function(e)
- // {
- //
- // Ti.API.info("touch end");
- // Ti.API.info(singletapLaunch);
- // if (singletapLaunch == false)
- // {
- // Ti.API.info('touch end after a drag');
- // if (mainView.view.getLeft() < 150)
- // {
- // Ti.API.info('titleMenuButtonHolderDraggable hiding menu');
- // mainView.view.animate(animateHideMenu);
- // touchingShowMenuView.visible = false;
- // // menuDisplayed = false;
- //
- // }
- // else
- // if (mainView.view.getLeft() > 150)
- // {
- // Ti.API.info('titleMenuButtonHolderDraggable showing menu');
- // mainView.view.animate(animateDisplayMenu);
- // touchingShowMenuView.visible = true;
- // // menuDisplayed = true;
- // }
- //
- // }
- // });
- // dragging SecondLevel view code
- function draggableFunctions()
- {
- var curX;
- var deltaX;
- var currentPositionX;
- var initialViewX = mainView.view.getLeft();
- var menuDisplayed = false;
- var menuFriendsDisplayed = false;
- var animateDisplayMenu = Ti.UI.createAnimation(
- {
- left : 245 + dpi,
- duration : 350,
- curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
- });
- var animateHideMenu = Ti.UI.createAnimation(
- {
- left : 0,
- duration : 350,
- curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
- });
- var animateDisplayFriends = Ti.UI.createAnimation(
- {
- left : -245 + dpi,
- duration : 350,
- curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
- });
- var animateHideFriendsMenu = Ti.UI.createAnimation(
- {
- left : 0,
- duration : 350,
- curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
- });
- animateHideMenu.addEventListener("complete", function(e)
- {
- //If the menu is hidden, then we need to show the moments button again.
- Ti.App.fireEvent("showMomentsButton");
- Ti.API.info("draggableFunctions animateHideMenu hideMenu");
- titleMenuButtonHolderMain.left = 0;
- mainView.view.left = 0;
- // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
- touchBlockView.setLeft(platformWidth);
- touchBlockView.setZIndex(999);
- Ti.UI.setBackgroundColor('#0e76bc');
- menuDisplayed = false;
- if (singletapLaunch == true)
- {
- singletapLaunch = false;
- }
- });
- animateHideFriendsMenu.addEventListener("complete", function(e)
- {
- //If the menu is hidden, then we need to show the moments button again.
- Ti.App.fireEvent("showMomentsButton");
- Ti.API.info("draggableFunctions animateHideFriendsMenu hideMenu");
- titleMenuButtonHolderMain.left = 0;
- mainView.view.left = 0;
- // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
- touchBlockView.setLeft(platformWidth);
- touchBlockView.setZIndex(999);
- //menuDisplayed = false;
- Ti.UI.setBackgroundColor('#0e76bc');
- menuFriendsDisplayed = false;
- if (singletapLaunch == true)
- {
- singletapLaunch = false;
- }
- });
- animateDisplayFriends.addEventListener("complete", function(e)
- {
- //If the menu is showing, then we need to hide the moments button again.
- Ti.API.info("draggableFunctions animateDisplayFriends showMenu");
- titleMenuButtonHolderMain.left = -245 + dpi;
- mainView.view.left = -245 + dpi;
- touchBlockView.setLeft(-245 + dpi);
- touchBlockView.setZIndex(999);
- Ti.UI.setBackgroundColor('#000000');
- menuFriendsDisplayed = true;
- if (singletapLaunch == true)
- {
- singletapLaunch = false;
- }
- });
- animateDisplayMenu.addEventListener("complete", function(e)
- {
- //If the menu is hidden, then we need to show the moments button again.
- //Ti.App.fireEvent("showMomentsButton");
- Ti.API.info("draggableFunctions animateDisplayMenu showMenu");
- titleMenuButtonHolderMain.left = "245dp";
- mainView.view.left = "245dp";
- touchBlockView.setLeft(245 + dpi);
- touchBlockView.setZIndex(999);
- menuDisplayed = true;
- if (singletapLaunch == true)
- {
- singletapLaunch = false;
- }
- });
- animateDisplayFriends.addEventListener("complete", function(e)
- {
- //If the menu is showing, then we need to hide the moments button again.
- Ti.App.fireEvent("hideMomentsButton");
- Ti.API.info("draggableFunctions animateDisplayFriendsshowMenu");
- titleMenuButtonHolderMain.right = 245;
- mainView.view.right = 245;
- touchBlockView.setRight(245 + dpi);
- touchBlockView.setZIndex(999);
- Ti.UI.setBackgroundColor('#000000');
- menuFriendsDisplayed = true;
- if (singletapLaunch == true)
- {
- singletapLaunch = false;
- }
- });
- function switchMenuVisibility(e)
- {
- if (menuDisplayed == true)
- {
- mainView.view.setLeft(245 + dpi);
- touchBlockView.setLeft(245 + dpi);
- touchBlockView.setZIndex(999);
- mainView.view.animate(animateHideMenu, function(e){
- if(Ti.App.Properties.getString('current_app')=="Moments") // moments needs a little delay.
- {
- Ti.App.fireEvent("initialLoadMoments");
- }
- });
- touchingShowMenuView.visible = false;
- menuDisplayed = false;
- return;
- }
- else
- {
- mainView.view.setLeft(0);
- // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
- touchBlockView.setLeft(platformWidth);
- touchBlockView.setZIndex(999);
- mainView.view.animate(animateDisplayMenu);
- touchingShowMenuView.visible = true;
- Ti.UI.setBackgroundColor('#000000');
- menuDisplayed = true;
- return;
- }
- }
- Ti.App.addEventListener("switchMenuVisibility", switchMenuVisibility);
- // var singletapLaunch = false;
- titleMenuButtonHolderDraggableRight.addEventListener("singletap", function(e)
- {
- // show friends
- Ti.API.info("draggableFunctions titleMenuButtonHolderDraggableRight singletap on title menu");
- Ti.API.info(singletapLaunch);
- singletapLaunch = true;
- if (menuFriendsDisplayed == true)
- {
- Ti.API.info('draggableFunctions titleMenuButtonHolderDraggableRight single tap to hide menu');
- Ti.API.info('mainView.view left ' + mainView.view.left);
- // mainView.view.setLeft("-245dp");
- // touchBlockView.setLeft("-245dp");
- //mainView.view.animate(animateHideFriendsMenu);
- menuView.setLeft(0);
- touchingShowMenuView.visible = false;
- //menuFriendsDisplayed = false;
- return;
- }
- else
- {
- Ti.API.info('draggableFunctions titleMenuButtonHolderDraggableRight single tap to hide menu');
- Ti.API.info('mainView.view left ' + mainView.view.left);
- mainView.view.setLeft(0);
- // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
- touchBlockView.setLeft(platformWidth);
- Ti.App.fireEvent("hideMomentsButton");
- mainView.view.animate(animateDisplayFriends);
- try
- {
- var usuarioReport = JSON.parse(Ti.App.Properties.getString('user'));
- //usuario.user.name
- var eventProperties = {"distinct_id" : usuarioReport.user.id};
- Ti.App.fireEvent("reportToMixPanel",{
- eventName : "[IA:Deed] Open friends menu",
- eventProperties : eventProperties
- });
- }
- catch(e)
- {
- //alert(e);
- }
- menuView.setLeft("-245dp");
- menuView.animate(
- {
- left : ("-245dp"),
- duration : 1
- });
- touchingShowMenuView.visible = false;
- //menuFriendsDisplayed = true;
- return;
- }
- });
- titleMenuButtonHolderDraggable.addEventListener("singletap", function(e)
- {
- // show menu
- Ti.API.info("draggableFunctions titleMenuButtonHolderDraggable singletap on title menu");
- Ti.API.info(singletapLaunch);
- singletapLaunch = true;
- if (menuDisplayed == true)
- {
- Ti.API.info('draggableFunctions titleMenuButtonHolderDraggable single tap to display menu');
- Ti.API.info('mainView.view left ' + mainView.view.left);
- mainView.view.setLeft(245 + dpi);
- touchBlockView.setLeft(245 + dpi);
- mainView.view.animate(animateHideMenu);
- touchingShowMenuView.visible = false;
- // menuDisplayed = false;
- return;
- }
- else
- {
- Ti.API.info('draggableFunctions titleMenuButtonHolderDraggable single tap to hide menu');
- Ti.API.info('mainView.view left ' + mainView.view.left);
- mainView.view.setLeft(0);
- // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
- touchBlockView.setLeft(platformWidth);
- Ti.App.fireEvent("hideMomentsButton");
- mainView.view.animate(animateDisplayMenu);
- touchingShowMenuView.visible = false;
- return;
- }
- });
- touchBlockView.addEventListener('singletap', function(e)
- {
- Ti.API.info("draggableFunctions touchBlockView singletap on touchBlockView");
- Ti.API.info(singletapLaunch);
- if (menuDisplayed == true)
- {
- Ti.API.info('draggableFunctions menuDisplayed touchBlockView single tap to display menu');
- Ti.API.info('mainView.view left ' + mainView.view.left);
- mainView.view.setLeft("245" + dpi);
- touchBlockView.setLeft("245" + dpi);
- mainView.view.animate(animateHideMenu, function(e)
- {
- menuView.animate(
- {
- left : 0,
- duration : 1
- });
- });
- touchingShowMenuView.visible = false;
- // menuDisplayed = false;
- return;
- }
- if (menuFriendsDisplayed == true)
- {
- Ti.API.info('draggableFunctions menuFriendsDisplayed touchBlockView single tap to display menu');
- Ti.API.info('mainView.view left ' + mainView.view.left);
- //mainView.view.setLeft((-1)*245 + dpi);
- //touchBlockView.setLeft((-1)*245 + dpi);
- mainView.view.animate(animateHideFriendsMenu, function(e)
- {
- menuView.animate(
- {
- left : 0,
- duration : 1
- });
- });
- touchingShowMenuView.visible = false;
- // menuDisplayed = false;
- }
- else
- {
- Ti.API.info('draggableFunctions menuFriendsDisplayed touchBlockView single tap to hide menu');
- Ti.API.info('mainView.view left ' + mainView.view.left);
- // touchBlockView.setLeft(Ti.Platform.displayCaps.platformWidth);
- // touchBlockView.setLeft(platformWidth);
- touchBlockView.setLeft("-245" + dpi);
- mainView.view.animate(animateDisplayMenu, function(e)
- {
- mainView.view.setLeft(0);
- });
- touchingShowMenuView.visible = false;
- // menuDisplayed = true;
- return;
- }
- });
- titleMenuButtonHolderDraggable.addEventListener('touchstart', function(e)
- {
- curX = e.x;
- initialViewX = parseInt(mainView.view.getLeft());
- Ti.API.info("curX: " + curX);
- Ti.API.info("initialViewX: " + initialViewX);
- });
- titleMenuButtonHolderDraggable.addEventListener('touchmove', function(e)
- {
- deltaX = e.x - curX;
- // Ti.API.info("deltaX: " + deltaX);
- currentPositionX = initialViewX + deltaX;
- if (currentPositionX > 0)
- {
- // Ti.API.info("currentPositionX: " + currentPositionX);
- mainView.view.setLeft(currentPositionX);
- }
- });
- titleMenuButtonHolderDraggable.addEventListener('touchend', function(e)
- {
- Ti.API.info("draggableFunctions titleMenuButtonHolderDraggable touch end");
- Ti.API.info(singletapLaunch);
- if (singletapLaunch == false)
- {
- Ti.API.info('draggableFunctions titleMenuButtonHolderDraggable touch end after a drag');
- if (mainView.view.getLeft() < 150)
- {
- Ti.API.info('draggableFunctions titleMenuButtonHolderDraggable hiding menu');
- mainView.view.animate(animateHideMenu);
- touchingShowMenuView.visible = false;
- // menuDisplayed = false;
- }
- else
- if (mainView.view.getLeft() > 150)
- {
- Ti.API.info('draggableFunctions titleMenuButtonHolderDraggable showing menu');
- mainView.view.animate(animateDisplayMenu);
- touchingShowMenuView.visible = true;
- // menuDisplayed = true;
- }
- }
- });
- }
- //*************
- // chathead drag button
- // var screenWidth = Ti.Platform.displayCaps.platformWidth;
- // var screenHeight = Ti.Platform.displayCaps.platformHeight;
- var screenWidth = platformWidth;
- var screenHeight = platformHeight;
- var circleWidth = 88 * (Ti.Platform.displayCaps.dpi / 160);
- Ti.API.info('screen width ' + screenWidth + ' dpi ' + Ti.Platform.displayCaps.dpi);
- var originLeft = screenWidth - circleWidth + 20;
- Ti.API.info('original left ' + originLeft);
- originLeft = originLeft * (160 / Ti.Platform.displayCaps.dpi);
- Ti.API.info('left en dp ' + originLeft);
- var originTop = 88;
- var KineduMomentsButton = Ti.UI.createImageView(
- {
- bottom : "10dp",
- zIndex : 4,
- image : imagesPath + "KineduMoments.png",
- width : "77dp",
- height : "77dp"
- });
- Ti.App.addEventListener("showMomentsButton", function(e)
- {
- KineduMomentsButton.animate(
- {
- opacity : 1,
- duration : 150
- });
- });
- Ti.App.addEventListener("hideMomentsButton", function(e)
- {
- KineduMomentsButton.animate(
- {
- opacity : 0,
- duration : 150
- });
- });
- /*
- var dragView = Titanium.UI.createView({
- backgroundColor:'transparent',
- // backgroundColor:'black',
- // opacity : 0.7,
- width:88 + dpi,
- height:88 + dpi,
- zIndex : 5,
- left:originLeft + dpi,
- top:88 + dpi,
- });
- self.add(dragView);
- var curX, curY;
- var deltaX, deltaY;
- var initialViewX = parseFloat(KineduMomentsButton.getLeft()) * (Ti.Platform.displayCaps.dpi / 160);
- var initialViewY = parseFloat(KineduMomentsButton.getTop()) * (Ti.Platform.displayCaps.dpi / 160);
- var currentPositionX = initialViewX;
- var currentPositionY = initialViewY;
- //dragView.addEventListener('touchstart', function(e) {
- // Ti.API.info('initial x ' + initialViewX);
- // Ti.API.info('initial y ' + initialViewY);
- // Ti.API.info('drag left ' + dragView.getLeft());
- // Ti.API.info('drag top ' + dragView.getTop());
- //});
- dragView.addEventListener('touchmove', function(e) {
- curX = e.x;
- curY = e.y;
- deltaX = e.x - curX;
- deltaY = e.y - curY;
- currentPositionX = initialViewX + deltaX;
- currentPositionY = initialViewY + deltaY;
- // Ti.API.info('delta x ' + deltaX + ' delta y ' + deltaY);
- // Ti.API.info('current position x ' + currentPositionX + ' current position y ' + currentPositionY);
- // Ti.API.info('');
- KineduMomentsButton.setLeft(currentPositionX);
- KineduMomentsButton.setTop(currentPositionY);
- });
- function recallControl()
- {
- var animateControlToOrigin = Ti.UI.createAnimation({
- left:initialViewX + dpi,
- top:initialViewY + dpi,
- duration:300,
- });
- animateControlToOrigin.addEventListener("complete", function(e){
- // Ti.API.info('animacion completada en kinedu moment button');
- KineduMomentsButton.setLeft(initialViewX + dpi);
- KineduMomentsButton.setTop(initialViewY + dpi);
- initialViewX = initialViewX * ( Ti.Platform.displayCaps.dpi / 160);
- initialViewY = initialViewY * ( Ti.Platform.displayCaps.dpi / 160);
- });
- KineduMomentsButton.animate(animateControlToOrigin);
- }
- dragView.addEventListener("touchend", function(e) {
- deltaX = 0;
- deltaY = 0;
- var factor = 160 * (Ti.Platform.displayCaps.dpi / 160);
- if (currentPositionX < (screenWidth / 2) - (circleWidth / 2)) {
- initialViewX = -20;
- if (currentPositionY < (screenHeight / 2) - (circleWidth / 2)) {
- initialViewY = originTop;
- } else {
- initialViewY = currentPositionY * (160 / Ti.Platform.displayCaps.dpi);
- }
- } else// to the right
- {
- initialViewX = originLeft;
- initialViewY = currentPositionY * (160 / Ti.Platform.displayCaps.dpi);
- }
- // Ti.API.info('current x ' + currentPositionX + ' current y ' + currentPositionY);
- // Ti.API.info('initial x ' + initialViewX + ' initial y ' + initialViewY);
- dragView.setLeft(initialViewX + dpi);
- dragView.setTop(initialViewY + dpi);
- recallControl();
- });
- */
- //*************
- var createMomentWindowOpen = false;
- KineduMomentsButton.addEventListener("singletap", function(e)
- {
- // Ti.API.info('current x ' + currentPositionX + ' current y ' + currentPositionY);
- // currentPositionX = initialViewX;
- // currentPositionY = initialViewY;
- if (!createMomentWindowOpen)
- {
- createMomentWindowOpen = true;
- var GenericWindow = require('ui/android/GenericWindow');
- var windowType = 'normal';
- if (Ti.App.Properties.getObject('currentActivity') !== null)
- {
- windowType = 'activity';
- }
- var momentWindow = new GenericWindow(
- {
- title : 'new moment',
- type : windowType
- });
- momentWindow.setActivity(self.activity);
- momentWindow.applyProperties(
- {
- // width : Ti.Platform.displayCaps.platformWidth,
- // height : Ti.Platform.displayCaps.platformHeight,
- // top : Ti.Platform.displayCaps.platformHeight,
- width : platformWidth,
- height : platformHeight,
- top : platformHeight,
- left : 0,
- });
- var CreateMoment = require('ui/common/CreateMoment');
- try
- {
- var createMomentView = new CreateMoment();
- // momentWindow.add(createMomentView);
- momentWindow.addView(createMomentView);
- // createMomentView.setParent(momentWindow);
- createMomentView.fireEvent('setParent',
- {
- win : momentWindow
- });
- self.fireEvent('addWindow',
- {
- windowToAdd : momentWindow
- });
- createMomentView.openCamera();
- }
- catch(err)
- {
- Ti.API.info('No babies to create moment');
- }
- }
- });
- //*************
- //self.add(mainView.view);
- //self.add(touchBlockView);
- titleMenuButtonHolderMain.add(titleMenuButtonHolderDraggable);
- titleMenuButtonHolderMain.add(titleMenuButtonHolderDraggableRight);
- //self.add(titleMenuButtonHolderMain);
- //self.add(KineduMomentsButton);
- //self.add(tidbitViewer);
- function findApp(appName, babyId)
- {
- for (var i = 0; i < appHolder.length; i++)
- {
- if (appHolder[i].name == appName && appHolder[i].babyId == babyId)
- {
- if (Ti.App.Properties.getString('todayAppIsNull') === 'true')
- {
- appHolder.splice(i, 1);
- Ti.API.info('it exists but it was an empty view');
- return null;
- }
- else
- {
- Ti.API.info('it exists');
- return appHolder[i].app;
- }
- }
- }
- Ti.API.info('it does not exist');
- return null;
- }
- function switchApp(e)
- {
- var current_app = Ti.App.Properties.getString('current_app');
- //Ti.API.info('current ' + current_app + ' e.app ' + e.app + ' e.id ' + e.id + ' currentBaby ' + Ti.App.Properties.getString('currentBaby'));
- if (e.app !== current_app || e.id !== parseInt(Ti.App.Properties.getString('currentBaby')))
- {
- mainView.removeApp();
- Ti.App.Properties.setString('currentBaby', e.id);
- try
- {
- var usuarioReport = JSON.parse(Ti.App.Properties.getString('user'));
- var eventProperties = {"distinct_id":usuarioReport.user.id, "switchedTo":e.app};
- Ti.App.fireEvent("reportToMixPanel", {eventName:"[IA:Deed] SwtitchApp", eventProperties:eventProperties});
- }
- catch(e)
- {
- //alert(e);
- }
- Ti.API.info("SwitchingApps=>"+JSON.stringify(e.app));
- switch(e.app)
- {
- case "NoBabies":
- //currentApp = findApp("NoBabies",-1);
- Ti.API.info("NoBabiesAppSwitchedTo");
- currentApp = new NoBabies();
- appHolder.push({name:"NoBabies",babyId:-1, app:currentApp});
- break;
- case "Progress":
- try
- {
- var reportActiveUser = JSON.parse(Ti.App.Properties.getString('user'));
- var mp_babyId = Ti.App.Properties.getString('currentBaby');
- var eventProperties = { "user": reportActiveUser, "baby": mp_babyId} ;
- Ti.App.fireEvent("reportToMixPanel", {eventName:"[IA:View] Baby stats", eventProperties:eventProperties});
- }
- catch(e)
- {
- Ti.API.info("Reporting To MixPanel=>" +e);
- }
- var babyProfile = findApp("Progress", e.id);
- if (babyProfile == null)
- {
- var babyProfile = new BabyProfile(e.id);
- currentApp = babyProfile.view;
- appHolder.push(
- {
- name : "Progress",
- babyId : e.id,
- app : babyProfile
- });
- }
- else
- {
- currentApp = babyProfile.view;
- babyProfile.refresh();
- }
- //expand this baby.
- Ti.App.fireEvent("babyOptionsToggle", {babyId:e.id});
- break;
- case "Moments":
- try
- {
- currentApp = findApp("Moments", e.id);
- try
- {
- var reportActiveUser = JSON.parse(Ti.App.Properties.getString('user'));
- var mp_babyId = Ti.App.Properties.getString('currentBaby');
- var eventProperties = { "user": reportActiveUser, "baby": mp_babyId} ;
- Ti.App.fireEvent("reportToMixPanel", {eventName:"[IA:View] Baby stats", eventProperties:eventProperties});
- }
- catch(e)
- {
- Ti.API.info("Reporting To MixPanel=>" +e);
- }
- if (currentApp == null)
- {
- currentApp = new Moments(e.id);
- appHolder.push(
- {
- name : "Moments",
- babyId : e.id,
- app : currentApp
- });
- }
- }
- catch(err)
- {
- Ti.API.info("err " + err + "e.id " + e.id);
- }
- break;
- case "Today":
- if (Ti.App.Properties.getBool('canReadKinedugram'))
- {
- try
- {
- var reportActiveUser = JSON.parse(Ti.App.Properties.getString('user'));
- var eventProperties =
- {
- "user" : reportActiveUser,
- "baby" : e.id
- };
- Ti.App.fireEvent("reportToMixPanel",
- {
- eventName : "[IA:View] Kinedugram",
- eventProperties : eventProperties
- });
- }
- catch(e)
- {
- //alert(e);
- }
- currentApp = findApp("Today", e.id);
- if (currentApp == null)
- {
- currentApp = new Today(e.id);
- appHolder.push(
- {
- name : "Today",
- babyId : e.id,
- app : currentApp
- });
- }
- }
- else {
- var dialog = Ti.UI.createAlertDialog(
- {
- cancel : 1,
- buttonNames : ['222', '22'],
- message : "4444",
- title : "444"
- });
- dialog.show();
- }
- //currentApp = new Today(e.id);
- break;
- case "Favorites":
- currentApp = findApp("Favorites", e.id);
- if (currentApp == null)
- {
- currentApp = new Favorites(e.id);
- appHolder.push(
- {
- name : "Favorites",
- babyId : e.id,
- app : currentApp
- });
- }
- break;
- case "Friends":
- currentApp = findApp("Friends", e.id);
- if (currentApp == null)
- {
- currentApp = new Friends(e.id);
- appHolder.push(
- {
- name : "Friends",
- babyId : e.id,
- app : currentApp
- });
- }
- break;
- case "Achievements":
- currentApp = findApp("Achievements", e.id);
- if (currentApp == null)
- {
- currentApp = new Badges(e.id);
- appHolder.push(
- {
- name : "Achievements",
- babyId : e.id,
- app : currentApp
- });
- }
- break;
- case "CareGiver":
- currentApp = findApp("CareGiver", e.id);
- if (currentApp == null)
- {
- currentApp = new CareGiverProfile(e.id);
- appHolder.push(
- {
- name : "CareGiver",
- babyId : e.id,
- app : currentApp
- });
- }
- //currentApp = new CareGiverProfile(usuario);
- break;
- }
- if ( typeof currentApp.setParentWindow !== 'undefined')
- {
- currentApp.setParentWindow(self);
- }
- Ti.App.Properties.setString('current_app', e.app);
- mainView.swapView(currentApp, e.showMenu);
- }
- else
- {
- // mainView.view.setLeft(0 + dpi);
- mainView.view.animate(animateHideMenu);
- Ti.UI.setBackgroundColor('#0e76bc');
- menuDisplayed = false;
- }
- mainView.removeWaiting();
- }
- Ti.App.addEventListener("switchApp", switchApp);
- self.addEventListener('addWindow', function(e)
- {
- Ti.API.info('addWindow');
- // Ti.API.info('parameters sent ' + JSON.stringify(e));
- // Ti.API.info('window to be added ' + e.windowToAdd);
- var win = e.windowToAdd;
- self.add(win);
- win.animate(
- {
- top : 0,
- left : 0,
- duration : 600
- });
- });
- self.addEventListener('removeWindow', function(e)
- {
- Ti.API.info('removeWindow');
- // Ti.API.info('parameters sent ' + JSON.stringify(e));
- // Ti.API.info('window to be removed ' + e.windowToRemove);
- var win = e.windowToRemove;
- self.remove(win);
- createMomentWindowOpen = false;
- });
- var androidActivity = Ti.Android.currentActivity;
- androidActivity.addEventListener('destroy', function(e)
- {
- Ti.API.info('Android Activity Destroyed');
- Ti.App.Properties.setString('currentBaby', null);
- Ti.App.Properties.setString('current_app', 'Today');
- Ti.App.Properties.setObject('currentActivity', null);
- Ti.App.Properties.setObject('currentArea', null);
- var tmpImage = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, ('baby_temp.png'));
- if (tmpImage.exists())
- {
- tmpImage.deleteFile();
- }
- var tmpVideo = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, ('baby_temp.mp4'));
- if (tmpVideo.exists())
- {
- tmpVideo.deleteFile();
- }
- });
- //AccelerateOpenSpeed
- self.addEventListener("open", function(e)
- {
- //mainView = new MainView();
- menuView = new MenuView(usuario, self.setCurrentBaby);
- disappearLoading();
- selfLoadingView.animate(
- {
- opacity : "0",
- duration : 800
- }, function(e)
- {
- menuView.setOpacity("0");
- self.add(menuView);
- draggableFunctions();
- mainView.view.setOpacity("0");
- self.add(mainView.view);
- mainView.view.animate(
- {
- opacity : "1",
- duration : 300
- }, function(e)
- {
- self.add(touchBlockView);
- self.add(titleMenuButtonHolderMain);
- self.add(KineduMomentsButton);
- self.add(tidbitViewer);
- menuView.setOpacity("1");
- });
- });
- });
- return self;
- }
- //make constructor function the public component interface
- module.exports = ApplicationWindow;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement