Tabbar, composer ,setActivityIndicator

I’ve four tabs - dashboard,activity,settings and reload

dashboard - if valid login details found in a saved json file then connect to a remote server and download data otherwise redirect to account page.

activity - it uses saved json data  and populate table 

settings/account - login form, if login details are correct it save a json file which dashbord uses

reload - it forces dashboard to reload and connect to the remote server and download data again

Issues 

1> When I fresh install the app. Dashboard redirect to account page which is good. After successfully logged in it gives blank page. If I terminate the app and relaunce it works fine

2> After successfully logged in when it redirect to dashboard, the selected tab should be Dashboard at the moment Account tab is still selected

3> In Android network actvity indicator never stops/terminate. After successfully logged in it takes you to the Dashboard but spinning wheel never get stopped and you can’t click on other tab.

4> When you press the reload button it forces dashboard to fetch content and reload it but the tab doesn’t chage. It still set reload button active. You can’t click again unless you go to other tabs.

–*********************************************************************************************

– ====================================================================

– Corona SDK “Widget” Sample Code

– ====================================================================

– File: main.lua

– Version 2.0

– Copyright © 2013 Corona Labs Inc. All Rights Reserved.

– Permission is hereby granted, free of charge, to any person obtaining a copy of 

– this software and associated documentation files (the “Software”), to deal in the 

– Software without restriction, including without limitation the rights to use, copy, 

– modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 

– and to permit persons to whom the Software is furnished to do so, subject to the 

– following conditions:

– 

– The above copyright notice and this permission notice shall be included in all copies 

– or substantial portions of the Software.

– 

– THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 

– INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 

– PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 

– FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 

– OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 

– DEALINGS IN THE SOFTWARE.

– Published changes made to this software and associated documentation and module files (the

– “Software”) may be used and distributed by Corona Labs, Inc. without notification. Modifications

– made to this software and associated documentation and module files may or may not become

– part of an official software release. All modifications made to the software will be

– licensed under these same terms and conditions.

– Support Graphics 2.0

–*********************************************************************************************

– Hide the status bar

display.setStatusBar( display.HiddenStatusBar )

– Set the background to white

display.setDefault( “background”, 0 ) – white

– Require the widget & composer libraries

local widget = require( “widget” )

widget.setTheme( “widget_theme_ios7” )

local composer = require( “composer” )

local json = require( “json” )

require( “function” )

– The device will auto-select the theme or you can set it here

– widget.setTheme( “widget_theme_ios” ) – iOS5/6 theme

– widget.setTheme( “widget_theme_ios7” ) – iOS7 theme

– widget.setTheme( “widget_theme_android” )  – android theme

local halfW = display.contentCenterX

local halfH = display.contentCenterY

– local titleGradient = {

– type = ‘gradient’,

– color1 = { 189/255, 203/255, 220/255, 255/255 }, 

– color2 = { 89/255, 116/255, 152/255, 255/255 },

– direction = “down”

– }

– -- Create toolbar to go at the top of the screen

– local titleBar = display.newRect( halfW, 0, display.contentWidth, 32 )

– titleBar:setFillColor( titleGradient ) 

– titleBar.y = titleBar.contentHeight * 0.5

– local titleText = display.newText( “Widget Demo”, halfW, titleBar.y, native.systemFontBold, 16 )

– Create buttons table for the tab bar

local tabButtons = 

{

{

width = 32, 

height = 32,

defaultFile = “assets/home.png”,

overFile = “assets/home.png”,

label = “Dashboard”,

onPress = function() composer.gotoScene( “dashboard”,{ effect=“slideDown”} ); end,

selected = true

},

{

width = 32, 

height = 32,

defaultFile = “assets/activity.png”,

overFile = “assets/activity.png”,

label = “Activity”,

onPress = function() composer.gotoScene( “activity”,{ effect=“slideUp” } ); end,

},

{

width = 32, 

height = 32,

defaultFile = “assets/account.png”,

overFile = “assets/account.png”,

label = “Account”,

onPress = function() 

composer.gotoScene( “settings”,{ effect=“slideRight” } );

end,

},

{

width = 32, 

height = 32,

defaultFile = “assets/reload.png”,

overFile = “assets/reload.png”,

label = “Reload”,

onPress = function() 

composer.removeScene(‘dashboard’,true);

composer.gotoScene( “dashboard”,{ effect=“fade” } );

end,

}

}

– Create a tab-bar and place it at the bottom of the screen

 tabBar = widget.newTabBar

{

top = display.contentHeight - 50,

width = display.contentWidth,

buttons = tabButtons,

height=50

}

composer.tabBar = tabBar

– If email and password saved before go to dashaboard else go to setting

local data=json.decode(loadValue(‘settings’))

if data then 

if data.email~=’’ and data.password~=’’ and data.loggedin==true then

composer.gotoScene( “dashboard” )

else 

composer.removeScene(“settings”)

composer.gotoScene( “settings” )

end

else

composer.gotoScene( “settings” )

end

settings/account

--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* -- -- ==================================================================== -- Corona SDK "Widget" Sample Code -- ==================================================================== -- -- File: main.lua -- -- Version 2.0 -- -- Copyright (C) 2013 Corona Labs Inc. All Rights Reserved. -- -- Permission is hereby granted, free of charge, to any person obtaining a copy of -- this software and associated documentation files (the "Software"), to deal in the -- Software without restriction, including without limitation the rights to use, copy, -- modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, -- and to permit persons to whom the Software is furnished to do so, subject to the -- following conditions: -- -- The above copyright notice and this permission notice shall be included in all copies -- or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -- INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -- PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -- DEALINGS IN THE SOFTWARE. -- -- Published changes made to this software and associated documentation and module files (the -- "Software") may be used and distributed by Corona Labs, Inc. without notification. Modifications -- made to this software and associated documentation and module files may or may not become -- part of an official software release. All modifications made to the software will be -- licensed under these same terms and conditions. -- -- Supports Graphics 2.0 --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* local widget = require( "widget" ) local composer = require( "composer" ) local mime = require("mime") local json = require("json") local scene = composer.newScene() local txtEmail,txtPassword,lblStatus,lblEmail,lblPassword --Forward reference local settings={} -- saving settings as json format local globalData = require( "globaldata" ) --loading global configuration local widget = require("widget") widget.setTheme( "widget\_theme\_ios7" ) settings=json.decode(loadValue('settings')) local function fieldHandler( textField ) return function( event ) if ( "began" == event.phase ) then -- This is the "keyboard has appeared" event -- In some cases you may want to adjust the interface when the keyboard appears. elseif ( "ended" == event.phase ) then -- This event is called when the user stops editing a field: for example, when they touch a different field elseif ( "editing" == event.phase ) then elseif ( "submitted" == event.phase ) then -- Hide keyboard native.setKeyboardFocus( nil ) end end end -- Our scene function scene:create( event ) local sceneGroup = self.view local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight ) bkgd:setFillColor( 0, 0, 0, 0 ) local listener = function( event ) -- Hide keyboard print("tap pressed") native.setKeyboardFocus( nil ) return true end -- Add listener to background for user "tap" bkgd:addEventListener( "tap", listener ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then lblHeading = display.newText(sceneGroup, "Account", 0, 0, font, 30) lblHeading.anchorX=0.0 lblHeading.anchorY=0.0 lblHeading.x = 10 lblHeading.y = 10 sceneGroup:insert(lblHeading) lblEmail = display.newText(sceneGroup, "Email", 0, 0, font, 15) lblEmail.anchorX=0.0 lblEmail.anchorY=0.0 lblEmail.x = 10 lblEmail.y = 90 sceneGroup:insert(lblEmail) lblStatus = display.newText(sceneGroup, "", 0, 0, font, 13) lblStatus.anchorX=0.0 lblStatus.anchorY=0.0 lblStatus.x = 15 lblStatus.y = 310 sceneGroup:insert(lblStatus) lblPassword = display.newText(sceneGroup, "Password", 0, 0, font, 15) lblPassword.anchorX=0.0 lblPassword.anchorY=0.0 lblPassword.x = 10 lblPassword.y = 180 sceneGroup:insert(lblPassword) local function loginCallback(event) native.setActivityIndicator( true ) if ( event.isError ) then native.setActivityIndicator(false) lblWait.text="Network error, try again!" --lblWait.isVisible=false else --print ( "RESPONSE: " .. event.response ) local data = json.decode(event.response) -- do with data what you want... if data.result==200 then settings = { email=txtEmail.text,password=txtPassword.text,loggedin=true } native.setActivityIndicator(false) saveValue('settings',json.encode(settings)) lblStatus.text=data.msg composer.gotoScene( "dashboard",{ effect="slideUp" } ); else -- prompt them to login again --print("Please try again"..data.msg) --labelReturnStatus.text = "Please try again" native.setActivityIndicator(false) lblStatus.text=data.msg end end return true; end local function handleButtonEvent(event) if "ended" == event.phase or event.phase == "submitted" then if txtEmail.text== "" then -- --msg="First name missing! Please enter first name" lblStatus.text="Please enter valid email address" -- --return false elseif txtPassword.text=="" then -- --msg="Last name missing! Please enter last name" lblStatus.text="Please enter password" -- --return false else lblStatus.text='' native.setActivityIndicator( true ) local params = {} params.timeout = 10 network.request(globalData.loginURL.."?email="..mime.b64(txtEmail.text) .. "&password=" .. mime.b64(txtPassword.text), "GET", loginCallback,params) end end return true end txtEmail = native.newTextField(0,0, 220, 36) txtEmail.anchorX=0 txtEmail.anchorY=0 txtEmail.x = 10 txtEmail.y = 120 txtEmail:addEventListener( "userInput", fieldHandler( function() return txtEmail end ) ) sceneGroup:insert(txtEmail) txtPassword = native.newTextField(0,0, 220, 36) txtPassword.anchorX=0 txtPassword.anchorY=0 txtPassword.x = 10 txtPassword.y = 210 txtPassword.isSecure = true txtPassword:addEventListener( "userInput", fieldHandler( function() return txtPassword end ) ) sceneGroup:insert(txtPassword) local btnLogin = widget.newButton { left = -50, top = 260, id = "login", label = "Sign in", onEvent = handleButtonEvent } sceneGroup:insert(btnLogin) if settings then if settings.email then txtEmail.text=settings.email end if settings.password then txtPassword.text=settings.password end end -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- -- Create, Position and instantiate Input Textfield -- username = native.newTextField(0,0, \_W \* 0.8, 100) -- local font = "HelveticaNeue" or system.nativeFont -- local hintText = "Enter an item to capture" -- username.inputType = "default" -- username.font = native.newFont(font,24) -- username.text = hintText -- username.align = "center" -- username.x = \_W \* 0.5 -- username.y = \_H \* 0.2 end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then lblHeading.text='' lblEmail.text='' lblStatus.text='' lblPassword.text='' txtEmail.isVisible=false txtPassword.isVisible=false end end -- "scene:destroy()" function scene:destroy( event ) print('destory') local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end scene:addEventListener( "create" ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

Are you getting any errors in your terminal/command window?

http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Thank you Rob for the reply with the link. There are no errors in the terminal but I will try the xcode organiser which I’ve not tried before.

Are you getting any errors in your terminal/command window?

http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Thank you Rob for the reply with the link. There are no errors in the terminal but I will try the xcode organiser which I’ve not tried before.