Created
November 13, 2010 19:36
-
-
Save vinceyoumans/675571 to your computer and use it in GitHub Desktop.
FOCUS event not firing when returning to win from another win.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//========= this .ls will download the json file of access numbers | |
// it will parse them into a table view | |
// and allow users to select an access number people. | |
var win = Titanium.UI.currentWindow; | |
var data = [ | |
{ph: "213-455-0203", state: "CALIFORNIA", city: "Anaheim/LA", title: "CALIFORNIA - Anaheim/LA - 213-455-0203"}, | |
{ph: "310-437-8924", state: "CALIFORNIA", city: "Anaheim/LA", title: "CALIFORNIA - Anaheim/LA - 310-437-8924"}, | |
{ph: "310-584-8932", state: "CALIFORNIA", city: "Anaheim/LA", title: "CALIFORNIA - Anaheim/LA - 310-584-8932"}, | |
{ph: "323-212-9942", state: "CALIFORNIA", city: "Anaheim/LA", title: "CALIFORNIA - Anaheim/LA - 323-212-9942"}, | |
{ph: "562-391-0055", state: "CALIFORNIA", city: "Anaheim/LA", title: "CALIFORNIA - Anaheim/LA - 562-391-0055"}, | |
{ph: "714-249-9929", state: "CALIFORNIA", city: "Anaheim/LA", title: "CALIFORNIA - Anaheim/LA - 714-249-9929"}, | |
{ph: "714-463-9939", state: "CALIFORNIA", city: "Anaheim/LA", title: "CALIFORNIA - Anaheim/LA - 714-463-9939"}, | |
{ph: "760-561-0033", state: "CALIFORNIA", city: "Anaheim/LA", title: "CALIFORNIA - Anaheim/LA - 818-230-0054"}, | |
{ph: "818-230-0054", state: "CALIFORNIA", city: "Anaheim/LA", title: "CALIFORNIA - Anaheim/LA - 818-230-0054"}, | |
{ph: "858-384-9926", state: "CALIFORNIA", city: "Anaheim/LA", title: "CALIFORNIA - Anaheim/LA - 858-384-9926"}, | |
{ph: "303-214-0702", state: "COLORADO", city: "COLORADO", title: "CALIFORNIA - Anaheim/LA - 303-214-0702"}, | |
{ph: "303-209-5547", state: "COLORADO", city: "COLORADO", title: "CALIFORNIA - Anaheim/LA - 303-209-5547"}, | |
{ph: "305-357-7424", state: "FLORIDA", city: "Dade", title: "CALIFORNIA - Anaheim/LA - 305-357-7424"}, | |
{ph: "786-275-3050", state: "FLORIDA", city: "Dade", title: "CALIFORNIA - Anaheim/LA - 786-275-3050"}, | |
{ph: "786-217-6868", state: "FLORIDA", city: "Homestead", title: "CALIFORNIA - Anaheim/LA - 786-217-6868"} | |
]; | |
// create table view | |
var tableview = Titanium.UI.createTableView({ | |
data:data | |
}); | |
Ti.API.info('===============STEP 4 =========================='); | |
Ti.API.info('========= ADD CLICK EVENT - ==========='); | |
// create table view event listener | |
tableview.addEventListener('click', function(e) | |
{ | |
// event data | |
var index = e.index; | |
var row = e.row; | |
var rowData = e.rowData; | |
//=== custom properties | |
var phonenum = e.rowData.ph; | |
//var phonenum = e.data.PH; | |
//var phonenum = data[index].PH; | |
var zzstate = e.rowData.state; | |
var zzcity = e.rowData.city; | |
var zztitle = e.rowData.title; | |
Ti.API.info('============= -----------click event'); | |
Ti.API.info('---index = ' + index); //worked | |
Ti.API.info('phonenum = ' + phonenum ); | |
Ti.API.info('zzstate = ' + zzstate ); | |
Ti.API.info('zzcity = ' + zzcity ); | |
Ti.API.info('========= --------------end click event'); | |
var alertdialog = Titanium.UI.createAlertDialog( | |
{ | |
title:'Table View', | |
buttonNames:['set number','Cancel'], | |
message:'Would you like to make ' + zztitle +' your default access number?', | |
phone: phonenum, | |
location: zzcity | |
}); // alert dialog | |
var zresult = 0; | |
alertdialog.addEventListener('click',function(e){ | |
// why am I not able to pass parameters from create alert dialog to the alert dialog? | |
zresult = e.index; | |
zphone = e.phone; | |
zlocation = e.title; | |
Ti.API.info('====================================================='); | |
Ti.API.info('========in the dialog event listener === start ===='); | |
Ti.API.info('====e.index ===alert dialog ' + zresult ); | |
Ti.API.info('====phone number = ' + phonenum ); | |
Ti.API.info('====zzstate ====== ' + zzstate ); | |
Ti.API.info('====zzcity ====== ' + zzcity ); | |
Ti.API.info('====zlocation === ' + zlocation ); | |
Ti.API.info('========in the dialog event listener === stop ===='); | |
Ti.API.info('====================================================='); | |
switch(zresult) | |
{ | |
case 0: | |
//execute code block 1 | |
Ti.API.info('========== set changes = true ===================='); | |
Titanium.App.Properties.setString("mycity",zzcity); | |
Titanium.App.Properties.setString("mystate",zzstate); | |
Titanium.App.Properties.setString("myAccNum",phonenum); | |
break; | |
case 1: | |
//execute code block 2 | |
Ti.API.info('========== set changes = false ===================='); | |
break; | |
default: | |
//code to be executed if n is different from case 1 and 2 | |
Ti.API.info('========== set changes = not working ===================='); | |
} //switch | |
}); // alertdialog click event | |
alertdialog.show(); | |
}); | |
win.add(tableview); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Titanium.UI.currentWindow; | |
var newAC = false; | |
var l1 = Titanium.UI.createLabel({ | |
//text:'You will have to select a local access number to use this service.', | |
text:'The code is in b1.addEventListener("click", function()', | |
width:300, | |
height:250, | |
top:35, | |
color:'#336699', | |
textAlign:'center' | |
}); | |
win.add(l1); | |
var l2 = Titanium.UI.createLabel({ | |
text:'SELECT ACCESS NUMBER', | |
height:50, | |
width:'auto', | |
shadowColor:'#aaa', | |
shadowOffset:{x:5,y:5}, | |
color:'#900', | |
font:{fontSize:20, fontStyle:'italic'}, | |
top:10, | |
textAlign:'center' | |
}); | |
win.add(l2); | |
// --- todo... determine if an access number is already setup. | |
var lcity = Titanium.UI.createLabel({ | |
text:'city', | |
width:200, | |
height:20, | |
top:80, | |
color:'#336699', | |
textAlign:'center' | |
}); | |
win.add(lcity); | |
var lstate = Titanium.UI.createLabel({ | |
text:'state', | |
width:200, | |
height:20, | |
top:100, | |
color:'#336699', | |
textAlign:'center' | |
}); | |
//win.add(lstate); | |
var lphone = Titanium.UI.createLabel({ | |
//text:'phone ' + valuemymyAccNum, | |
text:'phone', | |
width:200, | |
height:20, | |
top:120, | |
color:'#336699', | |
textAlign:'center' | |
}); | |
win.add(lphone); | |
//================== BUTTONS ========================================== | |
var b1 = Titanium.UI.createButton({ | |
title:'choose number', | |
height:40, | |
width:200, | |
top:230 | |
}); | |
var visible=true; | |
var b2 = Titanium.UI.createButton({ | |
title:'clear Access num', | |
height:40, | |
width:200, | |
top:280 | |
}); | |
var visible=true; | |
//================== functions ========================================== | |
b1.addEventListener('click', function() | |
{ | |
var tab = Titanium.UI.currentTab; | |
Ti.API.info("------mmmmmmmmmmmm In Window for setup steps mmmmmmmmmmmmmm----"); | |
var wsetup = Titanium.UI.createWindow({ | |
url:"../TAB02/STEP03-A.js", | |
tabBarHidden:false, | |
navBarHidden: false, | |
backgroundColor:'#336699' | |
}); | |
tab.open(wsetup,{animated:true}); | |
}); | |
win.add(b1); | |
b2.addEventListener('click', function() | |
{ | |
Ti.API.info("------ In Window for setup steps ----"); | |
var wsetup = Titanium.UI.createWindow({ | |
backgroundColor:'#336699' | |
}); | |
Titanium.App.Properties.setString("mycity",null); | |
Titanium.App.Properties.setString("mystate",null); | |
Titanium.App.Properties.setString("myAccNum",null); | |
resetwindow(); | |
}); | |
win.add(b2); | |
//================================================================= | |
//win.addEventListener("focus",function(E){ | |
win.addEventListener("focus",function(E){ | |
Ti.API.info("------ in the window focus event ----"); | |
Ti.API.info("--------------------------------------"); | |
refreshwindow(); | |
}); | |
function resetwindow(){ | |
Ti.API.info("------ currnet window gets focus ----"); | |
Ti.API.info("---------------zzzzzzz----------------------"); | |
var valuemycity = Titanium.App.Properties.getString("mycity"); | |
var valuemystate = Titanium.App.Properties.getString("mystate"); | |
var valuemyAccNum = Titanium.App.Properties.getString("myAccNum"); | |
//================= adding the default labels | |
if (!valuemyAccNum){ | |
Ti.API.info('------ there is no access number'); | |
var newAC = true; | |
} | |
else | |
{ | |
Ti.API.info('------ there is an access number'); | |
newAC = false; | |
} | |
Ti.API.info('the city is: '+ valuemycity ); | |
Ti.API.info('the state is: '+ valuemystate ); | |
Ti.API.info('the phone is: '+ valuemyAccNum ); | |
switch(newAC) | |
{ | |
case true : | |
//execute code block 1 | |
Ti.API.info('==== there is no default Access number=============='); | |
l1.text = 'You will have to select a local access number to use this service.'; | |
lcity.text = ''; | |
lstate.text = ''; | |
lphone.text = ''; | |
break; | |
case false: | |
//execute code block 2 | |
Ti.API.info('=====the AccNum is set=========='); | |
l1.text = 'If you change your local city or state, you can change your local access number as well'; | |
lcity.text = 'city: ' + valuemycity; | |
lstate.text = 'state ' + valuemystate; | |
lphone.text = 'phone: ' + valuemyAccNum; | |
break; | |
default: | |
//code to be executed if n is different from case 1 and 2 | |
Ti.API.info('========== set changes = not working ===================='); | |
} //switch | |
}; | |
function refreshwindow(){ | |
var valuemycity = Titanium.App.Properties.getString("mycity"); | |
var valuemystate = Titanium.App.Properties.getString("mystate"); | |
var valuemyAccNum = Titanium.App.Properties.getString("myAccNum"); | |
lcity.text = 'city: ' + valuemycity; | |
lstate.text = 'state ' + valuemystate; | |
lphone.text = 'phone: ' + valuemyAccNum; | |
}; | |
resetwindow(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
the issue is with android. I have not tested with iPHONE. FOCUS event does not fire when returning to a win from a second win. | |
I put together a demonstrating program that outlines a problem that I think I found. | |
This is just two tabs. The second tab updates itself automatically when first opened. However, the second tab also has a button called "CLICK ME FIRST - SELECT ACCESS NUMBER" | |
this will take you to another tableview in a window. Select a row, an alert box will show. | |
Accept or decline the update. | |
When hitting the return button, the initial window should fire the FOCUS event again, but it does not. | |
can you look at this and figure out what is going wrong? | |
Second QUESTION. Iss there a way to autoamtically return to the previous window when "ACCEPTING" the message display? | |
// create table view data object | |
var data = [ | |
{title:'STEP 3', hasChild:true, test:'../TAB02/step03.js'}, | |
{title:'CREDITS', hasChild:false} | |
]; | |
// create table view | |
var tableview = Titanium.UI.createTableView({ | |
data:data | |
}); | |
// create table view event listener | |
tableview.addEventListener('click', function(e) | |
{ | |
Ti.API.info('------ in the tab4a.js listener ----------'); | |
if (e.rowData.test) | |
{ | |
var win = null; | |
if (Ti.Platform.name == "android") { | |
win = Titanium.UI.createWindow({ | |
url:e.rowData.test, | |
title:e.rowData.title, | |
top:100 | |
}); | |
} else { | |
win = Titanium.UI.createWindow({ | |
url:e.rowData.test, | |
title:e.rowData.title, | |
backgroundColor:'#fff', | |
barColor:'#111' | |
}); | |
} | |
Titanium.UI.currentTab.open(win,{animated:true}); | |
} | |
}); | |
// add table view to the window | |
Titanium.UI.currentWindow.add(tableview); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment