Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10809] Android: lightweight window might not allow heavy weight window to focus

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-09-07T15:43:12.000+0000
Affected Version/sRelease 2.0.2, Release 2.1.2, Release 3.0.0
Fix Version/sRelease 2.1.3, Release 3.0.0, Sprint 2012-18 API
ComponentsAndroid
LabelsSupportTeam, api, module_window, qe-testadded
ReporterFederico Casali
AssigneeVishal Duggal
Created2012-09-06T20:47:34.000+0000
Updated2013-06-10T23:25:36.000+0000

Description

Problem description

Creating a lightweight windows between two heavyweight windows might prevent heavyweight focus event to be fired

Steps to reproduce and sample code

Run the sample code (also on https://gist.github.com/61044bd87f85742e3b19):
/**
 * Creates a simple black light weight window
 */
function LightWeightWindow(){
	var win = Ti.UI.createWindow({
		backgroundColor: 'black',
	});

	return win;
}

/**
 * Creates a heavy weight window
 * @param {Number} num	the window number
 */
function HeavyWeightWindow(num){
	num ++;
	// create the window
	var win = Ti.UI.createWindow({
		fullscreen: false, // make it heavy weight
		backgroundColor: '#ccc',
		title: 'win '+num
	});

	// let's do some processing
	for(var i = 0; i < 200; i++) {
		win.add(Ti.UI.createView({width:0,height:0,left:0,top:0}));
	}

	// open next window
	var btn = Ti.UI.createButton({
		title: 'open win ' + (num + 1)
	});

	btn.addEventListener('click', function(){
		// open light weight window
		var lightWeight = LightWeightWindow();
		lightWeight.open();
		// create the next heavy weight window
		var next = 	HeavyWeightWindow(num);
		// open the heavy weight window
		next.open();
		// lastly, close the light weight window
		lightWeight.close();
	});

	// on focus, show the toast notification
	win.addEventListener('focus', function(){
		Ti.UI.createNotification({
			message:'focus on win '+ num,
			duration: Ti.UI.NOTIFICATION_DURATION_SHORT
		}).show();

		Ti.API.info('focus on win '+ num)
	});

	win.add(btn);

	return win;
}

HeavyWeightWindow(0).open();

Steps to reproduce

- Click on the button to open a lightweight window, create next heavyweight window, open it and then close the lightweight window previously opened. - On window focus, we show a toast notification - Open a few windows, then press the back button. Result: 'focus' event listener is no longer triggered when pressing the back button

Comments

  1. Hieu Pham 2012-09-07

    Here's another test case, similar to the one above, but has "blur" eventListener added as well.
       /**
        * Creates a simple black light weight window
        */
       function LightWeightWindow(){
           var win = Ti.UI.createWindow({
               backgroundColor: 'black',
           });
        
           return win;
       }
        
       /**
        * Creates a heavy weight window
        * @param {Number} num  the window number
        */
       function HeavyWeightWindow(num){
           num ++;
           // create the window
           var win = Ti.UI.createWindow({
               fullscreen: false, // make it heavy weight
               backgroundColor: '#ccc',
               title: 'win '+num
           });
        
           // let's do some processing
           for(var i = 0; i < 200; i++) {
               win.add(Ti.UI.createView({width:0,height:0,left:0,top:0}));
           }
        
           // open next window
           var btn = Ti.UI.createButton({
               title: 'open win ' + (num + 1)
           });
        
           btn.addEventListener('click', function(){
               // open light weight window
               var lightWeight = LightWeightWindow();
               lightWeight.open();
               // create the next heavy weight window
               var next =  HeavyWeightWindow(num);
               // open the heavy weight window
               next.open();
               // lastly, close the light weight window
               lightWeight.close();
           });
        
           // on focus, show the toast notification
           win.addEventListener('focus', function(){
               Ti.UI.createNotification({
                   message:'focus on win '+ num,
                   duration: Ti.UI.NOTIFICATION_DURATION_SHORT
               }).show();
        
               Ti.API.info('focus on win '+ num)
           });
           
           win.addEventListener('blur', function(){
        
               Ti.API.info('blur on win '+ num)
           });
        
           win.add(btn);
        
           return win;
       }
        
       HeavyWeightWindow(0).open();
       
  2. Vishal Duggal 2012-09-07

    PR for master https://github.com/appcelerator/titanium_mobile/pull/2888
  3. Vishal Duggal 2012-09-07

    PR for 2_1_X https://github.com/appcelerator/titanium_mobile/pull/2890
  4. Shyam Bhadauria 2012-09-10

    Environment used for verification - Titanium SDK: 2.2.0.v20120907162025 Titanium  Studio: 2.1.3.201209071738 Device:Samsung GALAXY Note (2.3.6) Machine OS - MAC 10.8

JSON Source