org.symbian.tools.wrttools.doc.WebDeveloper/html/GUID-B12990B6-979C-4BBA-B030-FB7CEC04CB3A.html
author Eugene Ostroukhov <eugeneo@symbian.org>
Tue, 30 Mar 2010 15:20:42 -0700
changeset 292 d1d1c556b0d1
parent 229 716254ccbcc0
permissions -rw-r--r--
Bug 2431 - Import gives incorrect warning


<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="copyright" content="(C) Copyright 2009"/><meta name="DC.rights.owner" content="(C) Copyright 2009"/><meta name="DC.Type" content="concept"/><meta name="DC.Title" content="STEW: supporting screen rotation"/><meta name="abstract" content="This example illustrates how to design a widget that supports the changes in screen orientation."/><meta name="description" content="This example illustrates how to design a widget that supports the changes in screen orientation."/><meta name="DC.Relation" scheme="URI" content="GUID-9F3218D9-2BEA-417C-8017-E05AC749BF84"/><meta name="DC.Relation" scheme="URI" content="GUID-0FCBC574-2328-4986-99D3-7DC4BDE9C3A4"/><meta name="DC.Relation" scheme="URI" content="GUID-775005BC-2FF8-45A9-BBA6-6CED6B5780A2"/><meta name="DC.Relation" scheme="URI" content="GUID-EB2043BB-E557-429B-BA0A-E350A6D06597"/><meta name="DC.Format" content="XHTML"/><meta name="DC.Identifier" content="GUID-B12990B6-979C-4BBA-B030-FB7CEC04CB3A"/><meta name="DC.Language" content="en"/><title>STEW: supporting screen rotation </title><script type="text/javascript">
      function initPage() {}
    </script><link href="../PRODUCT_PLUGIN/book.css" rel="stylesheet" type="text/css"/><link href="css/s60/style.css" rel="stylesheet" type="text/css" media="all"/></head><body onload="initPage();"><div class="body"><div class="contentLeft prTxt"><h1 class="pageHeading" id="GUID-B12990B6-979C-4BBA-B030-FB7CEC04CB3A">STEW: supporting screen rotation</h1><div><p>This example illustrates how to design a widget that supports the changes in screen orientation.</p>
<div><h3>Laying out pages in portrait and landscape orientation</h3><p>STEW is designed for the 240 x 320 (QVGA) and the 360 x 640 (nHD) screen size in both portrait and landscape orientation. To accommodate for the changes in the width and height ratio when moving between portrait and landscape orientation, the position and size of all elements in the HTML and CSS files in the STEW example are specified relatively.</p><pre class="codeblock">.input_container input {
	width: 100%;
	...
}

.top_bar {
	width: 100%;
	...
}

.status_container table{
	width: 100%;
}
</pre><div class="figure" id="GUID-E7646C17-A84F-4729-BB60-EE13A608EBA7"><img src="GUID-440F39F5-9529-4422-A1A2-E5C309CA8750_d0e11769_href.png"/><p class="figure-title"><strong>Figure: </strong>STEW Search view in portrait orientation</p></div><p>In most cases, this ensures good user interface display in both portrait and landscape screen orientation on QVGA screens. On nHD screens, additional logic is needed to reposition the navigation menu. In the figure below, the menu is located at the bottom of the screen in portrait orientation, where it takes up a large portion of the screen and reduces the amount of the screen estate available. To fit more content in the view, display the navigation menu at the right side of the screen in landscape orientation.</p><div class="figure" id="GUID-5BB68204-A994-4F4E-8857-4F2F08A91077"><img src="GUID-B4CB1D93-7418-493A-8ED8-812775ECF341_d0e11778_href.png"/><p class="figure-title"><strong>Figure: </strong>STEW Search view in landscape orientation</p></div><p>Use CSS to change the style of the navigation menu when screen orientation changes between portrait and landscape. The following CSS styles are used for portrait orientation:</p><pre class="codeblock">.buttons_bottom {
	position: absolute;
	bottom: 0;
	left: 0;
	width: 100%;
	height: 84px;
	background: url(images/top_bg.png) bottom repeat-x #b7ecef;
	text-align: center;
	padding-top: 2px;
	border-top: 2px solid #7dcbe5;
}
</pre><p>The following CSS styles are used for landscape orientation:</p><pre class="codeblock">.buttons_bottom_landscape {
    position: absolute;
    top: 0;
    right: 0;
    width: 84px;
    height: 100%;
    padding-top: 50px;
    background: url(images/top_bg_landscape.png) right repeat-y #b7ecef;
    text-align: center;
    border-left: 2px solid #7dcbe5;
}
</pre></div>
<div><h3>Detecting screen orientation changes</h3><p>The following function that is assigned to the <code>onResize</code> event handler in the <code>body</code> element in the HTML file detects screen orientation changes:</p><pre class="codeblock">&lt;body onload="javascript:init();" onresize="javascript:onResize();"&gt;
</pre><p>The <code>onResize</code> function is located in the <code>main.js</code> file.  In addition, the size of the container must be decreased by the menu height or width to position the button menu and title bar correctly on the screen. First, references to all the DOM elements for the menu, container and content are retrieved. Then the size of the content is calculated by subtracting the menu size from the screen size.</p><pre class="codeblock">function onResize() {
	// Get the screen height or width.
	var screenSize = Helper.getScreenSize();	
	
	// On large screens, when rotating, update the
	// bottom menu layout (bottom with portrait, right with
	// landscape). Also update the screen container to be smaller
	// for the amount of the menu to avoid overlapping.
	var menuStrip = document.getElementById( "menu_strip" );
	var topBar = document.getElementById( "top_bar" );
	var container = document.getElementById( "container" );
	var content = document.getElementById( "content" );

	container.style.width = screenSize.width + "px";
	container.style.height = screenSize.height + "px";
	
	var largeScreen = Helper.isLargeScreen(); 
	if ( largeScreen ) {
		// Hide softkeys.
		menu.hideSoftkeys();
				
		// Show menu and resize content.
		var hidden = (menuStrip.className.indexOf( "hidden" ) != -1);		
		if ( Helper.isLandscape() ) {
			menuStrip.className = "buttons_bottom_landscape";

			var width = (screenSize.width - menuStrip.offsetWidth) + "px";
			if ( widgetMenu.activeScreen == Menu.LOGIN_SCREEN ) {
				// If we're on login screen the menu isn't shown so update the width.
				width = screenSize.width + "px";
			}
			topBar.style.width = width;
			content.style.width = width;
			content.style.height = (screenSize.height - topBar.offsetHeight) + "px";
		} else {
			menuStrip.className = "buttons_bottom";

			var width = screenSize.width + "px";
			topBar.style.width = width;
			content.style.width = width;
			content.style.height = (screenSize.height - menuStrip.offsetHeight - topBar.offsetHeight) + "px";
		}
		// If the menu was not visible, hide it.
		if ( hidden ) {
			menuStrip.className += " hidden";
		}
	} else {	
		// Hide menu strip and resize content.
		menuStrip.className = "hidden";
		content.style.width = screenSize.width + "px";
		content.style.height = screenSize.height + "px";
	}
</pre><p>The code above uses two functions from the <code>Helper</code> class: <code>getScreenSize</code> and <code>isLandscape</code>. The <code>getScreenSize</code> function returns the width and height in a <code>size</code> object. The <code>isLandscape</code> function checks the screen orientation. The screen orientation is assumed to be landscape if the width of the screen is greater than its height.</p><pre class="codeblock">isLandscape: function() {
	var size = this.getScreenSize();
	return ( size.width &gt; size.height );	
}
</pre></div>
<div><h3>Polling for screen orientation changes</h3><p>Some devices, such as the first product release of the Nokia 5800, do not support the <code>onResize</code> function. As a workaround for this known issue, a timer is started that polls for screen size changes. The timer is implemented by calling the <code>startResizePoller</code> function of the <code>WrtHelper</code> object.</p><pre class="codeblock">startResizePoller: function() {
	if ( Helper.isLargeScreen() ) {		
		setInterval(WrtHelper._poolResize, 1000);
	}
}
</pre><p>The <code>_poolResize</code> function checks the current and previous screen size.  If the size changed, the function triggers the <code>resize</code> event manually to achieve the same effect as if WRT triggered the event.</p><pre class="codeblock">_poolResize: function() {
	var screenSize = Helper.getScreenSize();
	var height = screenSize.height;
	var width = screenSize.width;
			
	if ( width != WrtHelper._screenWidth || height != WrtHelper._screenHeight ) {
		WrtHelper._screenWidth = width;
		WrtHelper._screenHeight = height;
		
		// Trigger event.
		var fireOnThis = document.body;
		var evObj = document.createEvent("HTMLEvents");
		evObj.initEvent("resize", true, true);
		fireOnThis.dispatchEvent(evObj);
	}
}
</pre></div>
</div></div></div><div class="footer"><hr/><div class="copy">© Nokia 2009.</div></div></body></html>