Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8976] Android: window focus event it's not triggered when going back to the parent window

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-07-11T02:57:30.000+0000
Affected Version/sRelease 1.7.6, Release 2.1.0, Release 1.8.2, Release 2.0.1
Fix Version/sRelease 2.1.0, Sprint 2012-10 API
ComponentsAndroid
LabelsSupportTeam, api, module_window, parity, qe-testadded
ReporterFederico Casali
AssigneeHieu Pham
Created2012-05-03T12:06:55.000+0000
Updated2014-11-24T08:19:47.000+0000

Description

Problem description

Focus eventListener is set in the parent window and it's correctly triggered when opening the window. Moving back from a child window to the parent window does not trigger the Focus event. This happens both for heavyweight and lightweight children window from 1.8.2 SDK. On 1.7.6 it is correctly triggered only if the child window is a heavyweight.

Customer engagement notes

With the same code on iOS, Focus event it's always triggered. ING will be using Lightweight windows inside a tabGroup and need to have the same behavior, using same code, between iOS and Android. This is blocking issue for the customer.

Code to reproduce

Using the sample code below, button in win1 opens a Lightweight child window (win3). When win3 it's closed, focus event it's not triggered using all SDK versions. Uncomment line 36 (fullscreen:false) in order to make 'win3' heavyweight. When win3 it's closed, focus event it's triggered only using SDK 1.7.6. With any other higher version it's not.
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

// create tab group
var tabGroup = Titanium.UI.createTabGroup();


//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({  
    icon:'KS_nav_views.png',
    title:'Tab 1',
    window:win1
});

win1.addEventListener('focus', function(){
	alert('focused!')
});



var button = Ti.UI.createButton({
	title:'open win3',
	width:200,
	height:100
});
button.addEventListener('click', function(){
	var win3 = Ti.UI.createWindow({
		title:'foobar',
		backgroundColor:'blue',
		// fullscreen:false
	});
	var button2 = Ti.UI.createButton({
		title:'back to win1',
		width:200,
		height:100,
		backgroundColor:'white'
	});
	button2.addEventListener('click', function(){
		win3.close()
	});
	win3.add(button2);
	

	win3.open();
});

win1.add(button);


var win2 = Titanium.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff'
});
var tab2 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 2',
    window:win2
});

var label2 = Titanium.UI.createLabel({
	color:'#999',
	text:'I am Window 2',
	font:{fontSize:20,fontFamily:'Helvetica Neue'},
	textAlign:'center',
	width:'auto'
});

win2.add(label2);


tabGroup.addTab(tab1);  
tabGroup.addTab(tab2);  

tabGroup.open();

Comments

  1. Vishal Duggal 2012-05-15

    Still not working correctly. Run the test case below On app start - win1 focus (passed) Switch to Tab2 - win1 blur, win2 focus (passed) Switch to Tab1 - win2 blur, win1 focus (passed) Press button to open win3 - win1 blur, win3 focus (fail. blur not fired for win1) Press button to close win3 - win3 blur, win1 focus (pass) Press button to open win3 - win1 blur, win3 focus (fail. blur not fired for win1) Switch to Tab2 - win3 blur, win2 focus (fail blur fired on win1) Switch to Tab1 - win2 blur, win3 focus (fail focus fired on win1) Press button to close win3 - win3 blur, win1 focus (fail. Neither focus nor blur fired)
       // this sets the background color of the master UIView (when there are no windows/tab groups on it)
       Titanium.UI.setBackgroundColor('#000');
        
       var win1 = Titanium.UI.createWindow({  
           title:'Tab 1',
           backgroundColor:'#fff'
       });
       
       var button = Ti.UI.createButton({
           title:'open win3',
           width:200,
           height:100
       });
       
       win1.add(button);
        
       
       win1.addEventListener('focus', function(){
           Ti.API.info('win1 focused!')
       });
       win1.addEventListener('blur', function(){
           Ti.API.info('win1 blurred!')
       }); 
       
       var win2 = Titanium.UI.createWindow({  
           title:'Tab 2',
           backgroundColor:'#fff'
       }); 
        
       var label2 = Titanium.UI.createLabel({
           color:'#999',
           text:'I am Window 2',
           font:{fontSize:20,fontFamily:'Helvetica Neue'},
           textAlign:'center',
           width:'auto'
       });
        
       win2.add(label2);
        
       win2.addEventListener('focus', function(){
           Ti.API.info('win2 focused!')
       });
       win2.addEventListener('blur', function(){
           Ti.API.info('win2 blurred!')
       }); 
       
       var win3 = Ti.UI.createWindow({
       	title:'foobar',
       	backgroundColor:'blue',
       });
       var button2 = Ti.UI.createButton({
       	title:'back to win1',
       	width:200,
       	height:100,
       	backgroundColor:'white'
       });
       
       win3.add(button2);
       
       win3.addEventListener('focus', function(){
           Ti.API.info('win3 focused!')
       });
       win3.addEventListener('blur', function(){
           Ti.API.info('win3 blurred!')
       }); 
       
       button.addEventListener('click', function(){
           win3.open();
       });
       
       button2.addEventListener('click', function(){
       	win3.close()
       });
            
        
       // create tab group
       var tabGroup = Titanium.UI.createTabGroup();
        
       var tab1 = Titanium.UI.createTab({  
           icon:'KS_nav_views.png',
           title:'Tab 1',
           window:win1
       });
        
       
       var tab2 = Titanium.UI.createTab({  
           icon:'KS_nav_ui.png',
           title:'Tab 2',
           window:win2
       });
        
       tabGroup.addTab(tab1);  
       tabGroup.addTab(tab2);  
        
       tabGroup.open();
       
  2. Hieu Pham 2012-05-17

    Complex Test Case:
       Titanium.UI.setBackgroundColor('#000');
        
       // create tab group
       var tabGroup = Titanium.UI.createTabGroup();
        
        
       //
       // create base UI tab and root window
       //
       var win1 = Titanium.UI.createWindow({  
           title:'Tab 1',
           backgroundColor:'#fff'
       });
       var tab1 = Titanium.UI.createTab({  
           icon:'KS_nav_views.png',
           title:'Tab 1',
           window:win1
       });
        
       win1.addEventListener('focus', function(){
           Ti.API.info("win1 focused");
       });
       
       win1.addEventListener('blur', function(){
           Ti.API.info("win1 blur");
       });
        
        
       var button = Ti.UI.createButton({
           title:'open win3',
           width:200,
           height:100
       });
       button.addEventListener('click', function(){
           var win3 = Ti.UI.createWindow({
               title:'foobar',
               backgroundColor:'blue',
               //fullscreen:false
           });
           var button2 = Ti.UI.createButton({
               title:'back to win1',
               top: 100,
               width:200,
               height:100,
               backgroundColor:'white'
           });
           
           var button5 = Ti.UI.createButton({
               title:'open win5',
               width:200,
               height:100,
               backgroundColor:'white'
           });
           button5.addEventListener('click', function() {
               var win5 = Ti.UI.createWindow({
               title:'foobar',
               backgroundColor:'green',
                //fullscreen:false
               });
               var button6 = Ti.UI.createButton({
                   title:'back to win3',
                   width:200,
                   height:100,
                   backgroundColor:'white'
               });
               button6.addEventListener('click', function(){
                   win5.close()
               });
               win5.add(button6);
                win5.addEventListener('blur', function() {
                   Ti.API.info("win5 blurred");
               });
               win5.addEventListener('focus', function() {
                   Ti.API.info("win5 focus");
               });
               win5.open();
           
           });
           button2.addEventListener('click', function(){
               win3.close()
           });
           win3.add(button2);
           win3.addEventListener('blur', function() {
               Ti.API.info("win3 blurred");
           });
           win3.addEventListener('focus', function() {
               Ti.API.info("win3 focus");
           });
           win3.add(button5);
           win3.open();
       });
        
       win1.add(button);
        
        
       var win2 = Titanium.UI.createWindow({  
           title:'Tab 2',
           backgroundColor:'#fff'
       });
       var tab2 = Titanium.UI.createTab({  
           icon:'KS_nav_ui.png',
           title:'Tab 2',
           window:win2
       });
       
       win2.addEventListener('focus', function(){
           Ti.API.info("win2 focused");
       });
       
       win2.addEventListener('blur', function(){
           Ti.API.info("win2 blur");
       });
        
       var button10 = Ti.UI.createButton({
           title:'open win4',
           width:200,
           height:100
       });
       button10.addEventListener('click', function(){
           var win4 = Ti.UI.createWindow({
               title:'foobar',
               backgroundColor:'red',
                //fullscreen:false
           });
           var button12 = Ti.UI.createButton({
               title:'back to win2',
               width:200,
               height:100,
               backgroundColor:'white'
           });
           button12.addEventListener('click', function(){
               win4.close()
           });
           win4.add(button12);
           win4.addEventListener('blur', function() {
               Ti.API.info("win4 blurred");
           });
           win4.addEventListener('focus', function() {
               Ti.API.info("win4 focus");
           });
        
           win4.open();
       });
       
        
       win2.add(button10);
        
        
       tabGroup.addTab(tab1);  
       tabGroup.addTab(tab2);  
        
       tabGroup.open();
       
       
  3. Hieu Pham 2012-05-21

    Another test case:
       var win1 = Ti.UI.createWindow({fullscreen: false});
       var button1 = Ti.UI.createButton();
       button1.addEventListener('click', function() {
           var win2 = Ti.UI.createWindow({fullscreen: false});
           win2.addEventListener('focus', function() {
               Ti.API.info("win2 focused");
           });
           win2.addEventListener('blur', function() {
               Ti.API.info("win2 blur");
           });
           win2.open();
       });
       
       win1.add(button1);
       win1.addEventListener('focus', function() {
           Ti.API.info("win1 focused");
       });
       win1.addEventListener('blur', function() {
           Ti.API.info("win1 blur");
       });
       win1.open();
       
  4. Mauro Parra-Miranda 2012-05-23

    This is still happening to the customer
  5. Mauro Parra-Miranda 2012-05-23

    Fixed, tested on latest CIBuild, provided testcase to the customer.
  6. Neeraj Gupta 2012-05-23

    QE team needs to add a test case so leave the fixed tickets in resolved state.
  7. Michael Pettiford 2012-06-18

    Closing issue Tested with Ti Studio build 2.1.0.201206172244 Ti Mobile SDK2.1.0.v20120618134156 hash r00905cd0 OSX Lion 10.7.3 Nexus S OS 4.0.4 The expected behavior is shown
  8. Anshu Mittal 2012-07-11

    Reopening to update labels.
  9. Shameer Jan 2013-12-10

    Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/4967

JSON Source