<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cssgallery.info &#187; iPhone</title>
	<atom:link href="http://cssgallery.info/category/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://cssgallery.info</link>
	<description>Resources for web and mobile developers</description>
	<lastBuildDate>Mon, 09 Jan 2012 18:54:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>QR Generator module for Titanium Appcelerator</title>
		<link>http://cssgallery.info/qr-generator-module-for-titanium-appcelerator/</link>
		<comments>http://cssgallery.info/qr-generator-module-for-titanium-appcelerator/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 08:34:02 +0000</pubDate>
		<dc:creator>Dan Tamas</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Titanium Appcelerator]]></category>
		<category><![CDATA[generate QR codes]]></category>
		<category><![CDATA[QR codes]]></category>
		<category><![CDATA[titanium appcelerator]]></category>

		<guid isPermaLink="false">http://cssgallery.info/?p=2113</guid>
		<description><![CDATA[After Appcelerator launched the Marketplace I managed to create and post an iOs only module that is able to <strong>create QR codes directly on the  device</strong> without using an online service.

It can generate <strong>all types of codes</strong> (from 1 to 40) and with <strong>any level of correction</strong> (L, M, Q, H). You can also <strong>customize the size of the resulting QR code</strong> and it will try to adapt itself to this size to remain perfectly sharp and fully visible.]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin: 10px !important;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcssgallery.info%2Fqr-generator-module-for-titanium-appcelerator%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcssgallery.info%2Fqr-generator-module-for-titanium-appcelerator%2F&amp;source=dan_tamas&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>After Appcelerator launched the Marketplace I managed to create and post an iOs only module that is able to <strong>create QR codes directly on the device</strong> without using an online service.</p>
<p>It can generate <strong>all types of codes</strong> (from 1 to 40) and with <strong>any level of correction</strong> (L, M, Q, H). You can also <strong>customize the size of the resulting QR code</strong> and it will try to adapt itself to this size to remain perfectly sharp and fully visible.</p>
<p>For now it&#8217;s able to generate these types of content:</p>
<ul>
<li>pure text</li>
<li>SMS (phone number, message)</li>
<li>phonecall (phone number)</li>
<li>email ( to, subject, message)</li>
<li>geo (lat, lon)</li>
<li>url</li>
</ul>
<p>You can buy it from the Marketplace: <a href="https://marketplace.appcelerator.com/apps/873" title="QR Generator module for Titanium Appcelerator" target="_blank">QR Generator module</a>.</p>
<div style="clear:both;">&nbsp;</div><div class="shr-publisher-2113"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fcssgallery.info%2Fqr-generator-module-for-titanium-appcelerator%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fcssgallery.info%2Fqr-generator-module-for-titanium-appcelerator%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fcssgallery.info%2Fqr-generator-module-for-titanium-appcelerator%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->

<h3>Related posts:</h3><ol><li><a href='http://cssgallery.info/custom-row-for-tableview-in-appcelerator-titanium/' rel='bookmark' title='Custom row for TableView in Appcelerator Titanium'>Custom row for TableView in Appcelerator Titanium</a></li>
<li><a href='http://cssgallery.info/making-a-combo-box-in-titanium-appcelerator-code-and-video/' rel='bookmark' title='Making a combo-box in Titanium Appcelerator &#8211; code and video'>Making a combo-box in Titanium Appcelerator &#8211; code and video</a></li>
<li><a href='http://cssgallery.info/create-a-countdown-timer-with-titanium-appcelerator/' rel='bookmark' title='Create a countdown timer with Titanium Appcelerator'>Create a countdown timer with Titanium Appcelerator</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://cssgallery.info/qr-generator-module-for-titanium-appcelerator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Seven days with Titanium &#8211; day 7 &#8211; orientation and accelerometer</title>
		<link>http://cssgallery.info/seven-days-with-titanium-day-7-orientation-and-accelerometer/</link>
		<comments>http://cssgallery.info/seven-days-with-titanium-day-7-orientation-and-accelerometer/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 20:29:22 +0000</pubDate>
		<dc:creator>Dan Tamas</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Titanium Appcelerator]]></category>
		<category><![CDATA[accelerometer]]></category>
		<category><![CDATA[orientation]]></category>
		<category><![CDATA[Ti.Accelerometer]]></category>
		<category><![CDATA[Ti.Gesture]]></category>
		<category><![CDATA[Ti.UI.FACE_DOWN]]></category>
		<category><![CDATA[Ti.UI.FACE_UP]]></category>
		<category><![CDATA[Ti.UI.LANDSCAPE_LEFT]]></category>
		<category><![CDATA[Ti.UI.LANDSCAPE_RIGHT]]></category>
		<category><![CDATA[Ti.UI.PORTRAIT]]></category>
		<category><![CDATA[Ti.UI.UNKNOWN]]></category>
		<category><![CDATA[Ti.UI.UPSIDE_PORTRAIT]]></category>
		<category><![CDATA[titanium appcelerator]]></category>

		<guid isPermaLink="false">http://cssgallery.info/?p=2117</guid>
		<description><![CDATA[Most of the devices nowadays are equipped with an accelerometer that detect the orientation of the device or the movements the user is doing with it. 

Titanium exposes this functionality through its APIs so let's take advantage of that :)]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin: 10px !important;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-7-orientation-and-accelerometer%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-7-orientation-and-accelerometer%2F&amp;source=dan_tamas&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Most of the devices nowadays are equipped with an accelerometer that detect the orientation of the device or the movements the user is doing with it. </p>
<p>Titanium exposes this functionality through its APIs so let&#8217;s take advantage of that <img src='http://cssgallery.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>The orientation</h2>
<p>The device can report <strong>7 states of the orientation</strong>  and they are defined in Titanium as follows:</p>
<ul>
<li>Ti.UI.UNKNOWN &#8211; the app cannot detect the position</li>
<li>Ti.UI.PORTRAIT</li>
<li>Ti.UI.UPSIDE_PORTRAIT</li>
<li>Ti.UI.LANDSCAPE_LEFT</li>
<li>Ti.UI.LANDSCAPE_RIGHT</li>
<li>Ti.UI.FACE_DOWN &#8211; like resting on a table with the screen downward</li>
<li>Ti.UI.FACE_UP &#8211; like resting on a table but with the screen upward</li>
</ul>
<p>While we have all this constants defined there are situations where <strong>they might not be available</strong>: in iOs when the user locks the orientation <strong>the device will report <u>that</u> orientation</strong> no matter how the device is held. On Android <strong>many devices can detect only the PORTRAIT and LANDSCAPE_LEFT orientations</strong>.</p>
<p>Since version 1.7.2 of the SDK the orientation API changed and is set per window (or activity). You can do this using the property <strong>orientationModes</strong> that accepts an array with the allowed orientation for that window. <a href="http://developer.appcelerator.com/blog/2011/07/android-window-orientation-behavior-change-for-1-7-2.html" title="Appcelerator orientation" target="_blank">See this post on Appcelerator&#8217;s blog</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">win.<span style="color: #660066;">orientationModes</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>Ti.<span style="color: #660066;">UI</span>.<span style="color: #660066;">PORTRAIT</span><span style="color: #339933;">,</span> Ti.<span style="color: #660066;">UI</span>.<span style="color: #660066;">LANDSCAPE_RIGHT</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There is also an event that triggers when the orientation changes allowing you to make the changes you might need (adapt the UI to the new orientation for example.)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ti.<span style="color: #660066;">Gesture</span>.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'orientationchange'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">orientation</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The alert <strong>will show a number from 1 to 7</strong> because the constants defined above are type INT. A good practice is to compare the orientation reported by the event with the constant and not directly with the number. In case something will change in the future this will assure you that the code will keep working.</p>
<p>You can find more about it in the docs page for <a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Gesture-module" title="Titanium Gesture APIs" target="_blank">Titanium.Gesture</a></p>
<h2>The accelerometer</h2>
<p>The accelerometer is a piece of hardware that <strong>is giving you the current position of the device in a 3D coordinates</strong> (x, y and z) vector. This can allow you for example to control the movements of an element on the screen.</p>
<p>To get this vector all you have to do is to <strong>catch the update event</strong> of the <a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Accelerometer-module" title="Titanium Accelerometer" target="_blank">Titanium.Accelerometer APIs</a>. It will return the vector we were talking about.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ti.<span style="color: #660066;">Accelerometer</span>.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'update'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    lbl.<span style="color: #660066;">text</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'x: '</span> <span style="color: #339933;">+</span> e.<span style="color: #660066;">x</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'y:'</span> <span style="color: #339933;">+</span> e.<span style="color: #660066;">y</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'z:'</span> <span style="color: #339933;">+</span> e.<span style="color: #660066;">z</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Again, <strong>it&#8217;s a good practice to remove the event when we don&#8217;t need it anymore</strong> to save some CPU cycles <img src='http://cssgallery.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Well, that&#8217;s it for Day 7. Code strong!</p>
<div style="clear:both;">&nbsp;</div><div class="shr-publisher-2117"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-7-orientation-and-accelerometer%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-7-orientation-and-accelerometer%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-7-orientation-and-accelerometer%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->

<h3>Related posts:</h3><ol><li><a href='http://cssgallery.info/seven-days-with-titanium-day-0-introduction/' rel='bookmark' title='Seven days with Titanium &#8211; day 0 &#8211; introduction'>Seven days with Titanium &#8211; day 0 &#8211; introduction</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-5-gps-and-maps/' rel='bookmark' title='Seven days with Titanium – day 5 – GPS and Maps'>Seven days with Titanium – day 5 – GPS and Maps</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-4-media-images-movies-and-sounds/' rel='bookmark' title='Seven days with Titanium – day 4 – Media – images, movies and sounds'>Seven days with Titanium – day 4 – Media – images, movies and sounds</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://cssgallery.info/seven-days-with-titanium-day-7-orientation-and-accelerometer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advanced Titanium Tutorial &#8211; Bonjour Networking</title>
		<link>http://cssgallery.info/advanced-titanium-tutorial-bonjour-networking/</link>
		<comments>http://cssgallery.info/advanced-titanium-tutorial-bonjour-networking/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 10:33:51 +0000</pubDate>
		<dc:creator>Dan Tamas</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Titanium Appcelerator]]></category>
		<category><![CDATA[Bonjour]]></category>
		<category><![CDATA[Bonjour Networking]]></category>
		<category><![CDATA[connection.start()]]></category>
		<category><![CDATA[serviceBrowser]]></category>
		<category><![CDATA[titanium appcelerator]]></category>
		<category><![CDATA[Titanium Networking]]></category>
		<category><![CDATA[updatedServices event]]></category>
		<category><![CDATA[ZeroConf]]></category>

		<guid isPermaLink="false">http://cssgallery.info/?p=2017</guid>
		<description><![CDATA[Titanium Appcelerator Mobile has implemented for iOs the Bonjour (or ZeroConf if you want) network protocol that <strong>allows you to connect to another device</strong> found in the same network.

Before starting with the boring part - I mean the code - let's watch a video with a small demo showing 3 devices playing together :)

<h2>Networking with Titanium Mobile on iOs</h2>
<iframe title="YouTube video player" width="640" height="480" src="http://www.youtube.com/embed/CajPO9sBfU4?rel=0" frameborder="0" allowfullscreen></iframe>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin: 10px !important;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcssgallery.info%2Fadvanced-titanium-tutorial-bonjour-networking%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcssgallery.info%2Fadvanced-titanium-tutorial-bonjour-networking%2F&amp;source=dan_tamas&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Titanium Appcelerator Mobile has implemented for iOs the Bonjour (or ZeroConf if you want) network protocol that <strong>allows you to connect to another device</strong> found in the same network.</p>
<p>Before starting with the boring part &#8211; I mean the code &#8211; let&#8217;s watch a video with a small demo showing 3 devices playing together <img src='http://cssgallery.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Networking with Titanium Mobile on iOs</h2>
<p><iframe title="YouTube video player" width="640" height="480" src="http://www.youtube.com/embed/CajPO9sBfU4?rel=0" frameborder="0" allowfullscreen></iframe></p>
<p>I would like to mention that the iPod is a second generation one &#8211;  so less capable (the delays are visible in the video) and somehow, sometimes, even seems to loose packets. I tested the same app with an iPad instead of the iPod and everything works just fine.<br />
 <img src="http://cssgallery.info/wp-content/uploads/2011/02/bonjour-experiment1.png" alt="bubbles" title="bonjour experiment" width="158" height="372" class="alignright size-full wp-image-2041" style="margin:0px;border:none;box-shadow:none;-moz-box-shadow:none;-webkit-box-shadow:none;"/></p>
<h2>Bonjour</h2>
<p>Based on the code found in <a href="https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/bonjour.js">KitchenSink</a> I created a small function that creates the connection for us and returns an object to allow you to start it, close it and write to the socket.</p>
<p>Bonjour is a little weird to understand for those with less experience but shortly, things are like this:</p>
<ul>
<li><strong>We need a socket</strong> in read-write mode that will be used by a  localService  to publish its presence.</li>
<li>Each localService have to have <strong>its own unique name</strong> to be able to identify it in the network.</li>
</ul>
<p>Besides this, we need a <strong>serviceBrowser</strong> to find other devices around (that published their presence, of course).</p>
<p>Since everything is asynchronous we&#8217;ll have to rely on events to capture the data sent by somebody or the changes in the number of devices connected.</p>
<p>The serviceBrowser has the <strong>updatedServices event</strong> where we can capture the published services. Here in this function <strong>we&#8217;ll try to catch the read event</strong> for each service that is the one who tells us what data is sent over the network.</p>
<p><strong>Warning:</strong> Close the network connection the moment you don&#8217;t need it anymore.</p>
<h2>The Network Connection Function</h2>
<p>The function I created takes care of this so you will just have to use it as in the example below:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Titanium.<span style="color: #660066;">include</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'bj.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> connection <span style="color: #339933;">=</span> bjnet<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'my_unique_name'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> json_data <span style="color: #339933;">=</span> JSON.<span style="color: #660066;">parse</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">//do something with this data;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
connection.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In other point of your app, where you want to send over a message, just do:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	connection.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'my_message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As I said before, don&#8217;t forget to clean everything:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">win.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'close'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	connection.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>What is going on in the demo?</h2>
<p>The example in the video is pretty simple. Depending on what blob you touch (red, green or blue)  you create a new connection with this name and start it. At this moment any message coming from the network is JSON parsed and a small blob is created with the specified coordinates and color.</p>
<p>On your turn, when you touch the screen you send over the network your coordinates and color so the other devices know what to draw. <strong>Every message is a JSON stringified object</strong> like the one below:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	<span style="color: #009900;">&#123;</span>coords<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>x<span style="color: #339933;">:</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span>y<span style="color: #339933;">:</span><span style="color: #CC0000;">200</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>player<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'red'</span><span style="color: #339933;">,</span> color<span style="color: #339933;">:</span><span style="color: #3366CC;">'#f00'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>As an aside <strong>the demo uses zero images</strong>. None. Everything is native and I plan a future tutorial on how to do this <img src='http://cssgallery.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>The code</h2>
<p>The code is hosted on <a href="https://github.com/rborn/Advanced-Titanium-Tutorial---Bonjour-Networking">Github</a> and you can <a href="https://github.com/rborn/Advanced-Titanium-Tutorial---Bonjour-Networking">download it from here</a>. <strong>Everything is MIT licensed</strong> but I&#8217;d like to hear what you come up with.</p>
<p>Code strong! </p>
<p><strong>PS.</strong> I&#8217;m allowed to say this cause I&#8217;m a titan <img src='http://cssgallery.info/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><strong class="spanish">Check the Spanish version of this post:<br />
 <a href="http://nosoloweb.es/tutorial-avanzado-de-titanium-bonjour-networking/" rel="me">Tutorial Avanzado de Titanium – Bonjour Networking</a></strong></p>
<div style="clear:both;">&nbsp;</div><div class="shr-publisher-2017"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fcssgallery.info%2Fadvanced-titanium-tutorial-bonjour-networking%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fcssgallery.info%2Fadvanced-titanium-tutorial-bonjour-networking%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fcssgallery.info%2Fadvanced-titanium-tutorial-bonjour-networking%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->

<h3>Related posts:</h3><ol><li><a href='http://cssgallery.info/seven-days-with-titanium-day-0-introduction/' rel='bookmark' title='Seven days with Titanium &#8211; day 0 &#8211; introduction'>Seven days with Titanium &#8211; day 0 &#8211; introduction</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-5-gps-and-maps/' rel='bookmark' title='Seven days with Titanium – day 5 – GPS and Maps'>Seven days with Titanium – day 5 – GPS and Maps</a></li>
<li><a href='http://cssgallery.info/making-a-combo-box-in-titanium-appcelerator-code-and-video/' rel='bookmark' title='Making a combo-box in Titanium Appcelerator &#8211; code and video'>Making a combo-box in Titanium Appcelerator &#8211; code and video</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://cssgallery.info/advanced-titanium-tutorial-bonjour-networking/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Seven days with Titanium – day 6 – animations and transforms</title>
		<link>http://cssgallery.info/seven-days-with-titanium-day-6%e2%80%93animations-and-transforms/</link>
		<comments>http://cssgallery.info/seven-days-with-titanium-day-6%e2%80%93animations-and-transforms/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 18:05:11 +0000</pubDate>
		<dc:creator>Dan Tamas</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Titanium Appcelerator]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[animation events]]></category>
		<category><![CDATA[autoreverse]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[titanium appcelerator]]></category>
		<category><![CDATA[transforms]]></category>

		<guid isPermaLink="false">http://cssgallery.info/?p=1977</guid>
		<description><![CDATA[Almost any UI element can be animated and transformed, allowing you to add to your application some eye candy or simply take advantage of predefined elements to give them a new role. For those familiar with <strong>CSS3 animations</strong> this will come very easy as the concept it's pretty the same.

<h2>Animations</h2>
Pointless to say, an animation will change one or more properties of an element form the current stage to another (set by us) in a period of time.]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin: 10px !important;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-6%25e2%2580%2593animations-and-transforms%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-6%25e2%2580%2593animations-and-transforms%2F&amp;source=dan_tamas&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Almost any UI element can be animated and transformed, allowing you to add to your application some eye candy or simply take advantage of predefined elements to give them a new role. For those familiar with <strong>CSS3 animations</strong> this will come very easy as the concept it&#8217;s pretty the same.</p>
<h2>Animations</h2>
<p>Pointless to say, an animation will change one or more properties of an element form the current stage to another (set by us) in a period of time.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> my_view <span style="color: #339933;">=</span>  Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#f00'</span><span style="color: #339933;">,</span>
    height<span style="color: #339933;">:</span><span style="color: #CC0000;">20</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
my_view.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The simple code above will <strong>animate the height of my_view from 20 to 100</strong>.</p>
<p>You can complicate the things more <strong>adding more properties to animate</strong> (like the background color, opacity, etc), <strong>a duration</strong> (that needs to be in ms) and <strong>a curve </strong>(like ease-out or liniar, etc)</p>
<h3>Some examples</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> view <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	width<span style="color: #339933;">:</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span>
	height<span style="color: #339933;">:</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span>
	backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#f00'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
win.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
view.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	height<span style="color: #339933;">:</span><span style="color: #CC0000;">300</span><span style="color: #339933;">,</span> 
	backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#00f'</span><span style="color: #339933;">,</span> 
	duration<span style="color: #339933;">:</span><span style="color: #CC0000;">3000</span><span style="color: #339933;">,</span> 
	curve<span style="color: #339933;">:</span>Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">ANIMATION_CURVE_EASE_IN_OUT</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you need to make an animation to come back to the element&#8217;s original state and repeat it several times, there are 2 properties that might interest you :<strong>repeat</strong> and <strong>autoreverse</strong></p>
<p>The below code will make <strong>the view &#8220;pulse&#8221; 3 times</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> view <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	width<span style="color: #339933;">:</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span>
	height<span style="color: #339933;">:</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span>
	backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#f00'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
win.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
view.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	height<span style="color: #339933;">:</span><span style="color: #CC0000;">130</span><span style="color: #339933;">,</span>
	width<span style="color: #339933;">:</span><span style="color: #CC0000;">130</span><span style="color: #339933;">,</span>
	repeat<span style="color: #339933;">:</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>
	autoreverse<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	curve<span style="color: #339933;">:</span>Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">ANIMATION_CURVE_EASE_IN_OUT</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The animations have 2 events: <strong>start</strong> and <strong>complete</strong>.The <strong>complete event</strong> is very useful because we can chain more animations one after another or start some other actions when the current one stops. </p>
<h2>Transforms</h2>
<p>Similar to CSS3 transforms, in Titanium you can use 2D or 3D transforms.</p>
<p>Basically you create a 2D or a 3D matrix for the transform  or use the predefined &#8220;shortcuts&#8221; &#8211;  (like <strong>scale</strong> or <strong>rotate</strong>) and pass this transform to the object you are creating or to the animation.</p>
<h3>An example with transforms</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> tr_start <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">create2DMatrix</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
tr_start <span style="color: #339933;">=</span> tr_start.<span style="color: #660066;">rotate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> tr_end <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">create2DMatrix</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
tr_end <span style="color: #339933;">=</span> tr_end.<span style="color: #660066;">rotate</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
tr_end <span style="color: #339933;">=</span> tr_end.<span style="color: #660066;">scale</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> view <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	width<span style="color: #339933;">:</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span>
	height<span style="color: #339933;">:</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span>
	transform<span style="color: #339933;">:</span>tr_start<span style="color: #339933;">,</span>
	backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#f00'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
win.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
view.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	transform<span style="color: #339933;">:</span>tr_end<span style="color: #339933;">,</span>
	repeat<span style="color: #339933;">:</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>
	autoreverse<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	duration<span style="color: #339933;">:</span><span style="color: #CC0000;">500</span><span style="color: #339933;">,</span>
	curve<span style="color: #339933;">:</span>Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">ANIMATION_CURVE_EASE_IN_OUT</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The best <strong>resources</strong> to see how everything works are the examples provided by the Appcelerator team in the KitchenSink, the entry point being here:<a href="http://bit.ly/eiow0B">http://bit.ly/eiow0B</a></p>
<p>These animations and transforms are not suited to a very intensive usage (like games) but they can be used with success to improve the apps&#8217; look and feel &#8211; and with this, the user experience.</p>
<p>As always, I wait for your questions, suggestions and what are you come up with <img src='http://cssgallery.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<strong class="spanish">Check the Spanish version of this post:<br />
 <a href="http://nosoloweb.es/siete-dias-con-titanium-dia-6-animaciones-y-transformaciones/" rel="me">Siete días con Titanium – día 6 – animaciones y transformaciones</a></strong></p>
<div style="clear:both;">&nbsp;</div><div class="shr-publisher-1977"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-6%25e2%2580%2593animations-and-transforms%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-6%25e2%2580%2593animations-and-transforms%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-6%25e2%2580%2593animations-and-transforms%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://cssgallery.info/seven-days-with-titanium-day-6%e2%80%93animations-and-transforms/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Seven days with Titanium – day 5 – GPS and Maps</title>
		<link>http://cssgallery.info/seven-days-with-titanium-day-5-gps-and-maps/</link>
		<comments>http://cssgallery.info/seven-days-with-titanium-day-5-gps-and-maps/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 18:13:53 +0000</pubDate>
		<dc:creator>Dan Tamas</dc:creator>
				<category><![CDATA[Development tools]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Titanium Appcelerator]]></category>
		<category><![CDATA[add a route]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[forwardGeocoder]]></category>
		<category><![CDATA[Geolocation]]></category>
		<category><![CDATA[getCurrentHeading]]></category>
		<category><![CDATA[getCurrentPosition]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[Maproute]]></category>
		<category><![CDATA[mapview.addAnnotation]]></category>
		<category><![CDATA[reverseGeocoder]]></category>
		<category><![CDATA[titanium appcelerator]]></category>
		<category><![CDATA[Titanium.Geolocation]]></category>
		<category><![CDATA[Titanium.Map]]></category>

		<guid isPermaLink="false">http://cssgallery.info/?p=1660</guid>
		<description><![CDATA[This doesn't need any kind of introduction. You can use the location on the devices to find the user's place and act accordingly. One thing good to know is that this needs the approval of the user, and for iOs &#62; 3.2 you need to set a <strong>purpose</strong> property to let Apple know what you need it for.

<pre lang="javascript">Titanium.Geolocation.purpose = "GPS user coordinates";</pre>

<h2>How geolocation works?</h2>

]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin: 10px !important;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-5-gps-and-maps%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-5-gps-and-maps%2F&amp;source=dan_tamas&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This doesn&#8217;t need any kind of introduction. You can use the location on the devices to find the user&#8217;s place and act accordingly. One thing good to know is that this needs the approval of the user, and for iOs &gt; 3.2 you need to set a <strong>purpose</strong> property to let Apple know what you need it for.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Titanium.<span style="color: #660066;">Geolocation</span>.<span style="color: #660066;">purpose</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;GPS user coordinates&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>How geolocation works</h2>
<p>When you start the app <strong>the coordinates are the ones cached on the device</strong>, in other words the ones detected at the last time you used the geolocation on your device. Detecting the current position takes time so if you have an app based on geolocation you might want to take this in account to improve the user experience and avoid to get false results.</p>
<p><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Geolocation-module">Titanium.Geolocation</a> provides the needed methods to manage geolocation.</p>
<p>In general the most used method is <strong>getCurrentPosition</strong> that gives you the current position and fires once and the <strong>location</strong> event that triggers repeatedly on the location change. To be more clear think you want to log a route the user follow: when the app starts you get its start position then while walking you can get the points of the route with a adjustable granularity.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
Titanium.<span style="color: #660066;">Geolocation</span>.<span style="color: #660066;">distanceFilter</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// set the granularity of the location event</span>
&nbsp;
	Titanium.<span style="color: #660066;">Geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">// manage the error</span>
                <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> longitude <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> latitude <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> altitude <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">altitude</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> heading <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">heading</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> accuracy <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">accuracy</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> speed <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">speed</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> timestamp <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">timestamp</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> altitudeAccuracy <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">altitudeAccuracy</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">// we use the above data the way we need it</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	Titanium.<span style="color: #660066;">Geolocation</span>.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'location'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">// manage the error</span>
		<span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> longitude <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> latitude <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> altitude <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">altitude</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> heading <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">heading</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> accuracy <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">accuracy</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> speed <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">speed</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> timestamp <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">timestamp</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> altitudeAccuracy <span style="color: #339933;">=</span> e.<span style="color: #660066;">coords</span>.<span style="color: #660066;">altitudeAccuracy</span><span style="color: #339933;">;</span>
&nbsp;
               <span style="color: #006600; font-style: italic;">// again we use the gathered data</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There are some other methods that can be used like <strong>reverseGeocoder</strong>, <strong>forwardGeocoder</strong>, and <strong>getCurrentHeading</strong> &#8211;  for compass. Because not all the devices have the GPS location (like iPod) or the compass and because the user can have the location services disabled you have to check if it exists, if it&#8217;s enabled and then let the user know about this.</p>
<p>As the documentation page is not complete yet, I suggest you to <strong>take a look</strong> at the <a href="http://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/geolocation.js">geolocation example</a> that shows very well how to use this.</p>
<h2>Maps</h2>
<p>The maps are created using the <a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Map-module">Titanium.Map</a> methods. The maps are a little bit complicated but allows you to do some real nice interfaces. You can use a <strong>Mapview</strong> and add a route to it, or pins(markers) and to the pins to attach popups with images, titles, even &#8220;links&#8221; o another windows for a more detailed view of the specified place or whatever you may need.</p>
<h3>Create a map</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> mapview <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">Map</span>.<span style="color: #660066;">createView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	top<span style="color: #339933;">:</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span>
	height<span style="color: #339933;">:</span><span style="color: #CC0000;">300</span><span style="color: #339933;">,</span>
	mapType<span style="color: #339933;">:</span> Titanium.<span style="color: #660066;">Map</span>.<span style="color: #660066;">STANDARD_TYPE</span><span style="color: #339933;">,</span>
	region<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>latitude<span style="color: #339933;">:</span><span style="color: #CC0000;">33.74511</span><span style="color: #339933;">,</span> longitude<span style="color: #339933;">:-</span><span style="color: #CC0000;">84.38993</span><span style="color: #339933;">,</span> latitudeDelta<span style="color: #339933;">:</span><span style="color: #CC0000;">0.5</span><span style="color: #339933;">,</span> longitudeDelta<span style="color: #339933;">:</span><span style="color: #CC0000;">0.5</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	animate<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	regionFit<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	userLocation<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Nothing complicated: the constructor can receive different arguments including the <strong>annotations</strong> (pins), but of course you will have to declare it first.</p>
<p>And this is done like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> apple <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">Map</span>.<span style="color: #660066;">createAnnotation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	latitude<span style="color: #339933;">:</span><span style="color: #CC0000;">37.33168900</span><span style="color: #339933;">,</span>
	longitude<span style="color: #339933;">:-</span><span style="color: #CC0000;">122.03073100</span><span style="color: #339933;">,</span>
	title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Steve Jobs&quot;</span><span style="color: #339933;">,</span>
	subtitle<span style="color: #339933;">:</span><span style="color: #3366CC;">'Cupertino, CA'</span><span style="color: #339933;">,</span>
	pincolor<span style="color: #339933;">:</span>Titanium.<span style="color: #660066;">Map</span>.<span style="color: #660066;">ANNOTATION_GREEN</span><span style="color: #339933;">,</span>
	animate<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	rightButton<span style="color: #339933;">:</span> <span style="color: #3366CC;">'apple_logo.jpg'</span><span style="color: #339933;">,</span>
	myid<span style="color: #339933;">:</span><span style="color: #CC0000;">2</span> <span style="color: #006600; font-style: italic;">// CUSTOM ATTRIBUTE THAT IS PASSED INTO EVENT OBJECTS</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> atlanta <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">Map</span>.<span style="color: #660066;">createAnnotation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		latitude<span style="color: #339933;">:</span><span style="color: #CC0000;">33.74511</span><span style="color: #339933;">,</span>
		longitude<span style="color: #339933;">:-</span><span style="color: #CC0000;">84.38993</span><span style="color: #339933;">,</span>
		title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Atlanta, GA&quot;</span><span style="color: #339933;">,</span>
		subtitle<span style="color: #339933;">:</span><span style="color: #3366CC;">'Atlanta Braves Stadium<span style="color: #000099; font-weight: bold;">\n</span>foo'</span><span style="color: #339933;">,</span>
		animate<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		leftButton<span style="color: #339933;">:</span><span style="color: #3366CC;">'atlanta.jpg'</span><span style="color: #339933;">,</span>
		rightButton<span style="color: #339933;">:</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">iPhone</span>.<span style="color: #660066;">SystemButton</span>.<span style="color: #660066;">DISCLOSURE</span><span style="color: #339933;">,</span>
		myid<span style="color: #339933;">:</span><span style="color: #CC0000;">3</span> <span style="color: #006600; font-style: italic;">// CUSTOM ATTRIBUTE THAT IS PASSED INTO EVENT OBJECTS</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>and the map constructor gets</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	annotations<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>atlanta<span style="color: #339933;">,</span>apple<span style="color: #009900;">&#93;</span></pre></div></div>

<p>or later you can add this annotation using</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	mapview.<span style="color: #660066;">addAnnotation</span><span style="color: #009900;">&#40;</span>atlanta<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Map events</h3>
<p>One thing you need to know is that <strong>the events are registered at the map level</strong>. So you cannot get a click event on a pin. You will have to get the click event of the mapview ad use the <strong>clicksource</strong> and <strong>the custom property (myId) </strong> properties to detect the annotation and what has been clicked (pin, leftbutton, rightbutton, title, subtitle)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">source</span>.<span style="color: #660066;">myid</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">3</span> <span style="color: #339933;">&amp;&amp;</span> evt.<span style="color: #660066;">clicksource</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'rightButton'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// do your stuff</span>
        <span style="color: #009900;">&#125;</span></pre></div></div>

<h3>MapRoute</h3>
<p>Another thing you can do with a map is to <strong>add a route</strong> (iOs only for now). Basically you can draw a line on the map specifying the points (gpd point) it needs to pass through.</p>
<p>A route can look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> route <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;some name&quot;</span><span style="color: #339933;">,</span>
	points<span style="color: #339933;">:</span>points<span style="color: #339933;">,</span>
	color<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;red&quot;</span><span style="color: #339933;">,</span>
	width<span style="color: #339933;">:</span><span style="color: #CC0000;">2</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Where  <strong>points</strong> it&#8217;s an array of objects containing latitude and longitude coordinates.</p>
<p><img src="http://cssgallery.info/wp-content/uploads/2011/02/gmap-capture-on-iphone.jpg" alt="screen capture showing a google map on an iphone screen" title="Maproute with Titanium" width="320" height="460" class="alignright size-full wp-image-1947" /></p>
<h3>Example &#8211; add a route to a Mapview</h3>
<p>Below is an example that adds a route to a mapview using some readymade coordinates. It will generate something similar to the screenshot in the right.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> center <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>latitude<span style="color: #339933;">:</span><span style="color: #CC0000;">42.30</span><span style="color: #339933;">,</span>longitude<span style="color: #339933;">:-</span><span style="color: #CC0000;">71.18</span><span style="color: #339933;">,</span>latitudeDelta<span style="color: #339933;">:</span><span style="color: #CC0000;">0.03</span><span style="color: #339933;">,</span> longitudeDelta<span style="color: #339933;">:</span><span style="color: #CC0000;">0.1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> mapview <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">Map</span>.<span style="color: #660066;">createView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	mapType<span style="color: #339933;">:</span> Titanium.<span style="color: #660066;">Map</span>.<span style="color: #660066;">STANDARD_TYPE</span><span style="color: #339933;">,</span>
	region<span style="color: #339933;">:</span> center<span style="color: #339933;">,</span>
	animate<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	regionFit<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
points <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
	<span style="color: #009900;">&#123;</span>latitude<span style="color: #339933;">:</span><span style="color: #CC0000;">42.31</span><span style="color: #339933;">,</span>longitude<span style="color: #339933;">:-</span><span style="color: #CC0000;">71.11</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#123;</span>latitude<span style="color: #339933;">:</span><span style="color: #CC0000;">42.32</span><span style="color: #339933;">,</span>longitude<span style="color: #339933;">:-</span><span style="color: #CC0000;">71.13</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#123;</span>latitude<span style="color: #339933;">:</span><span style="color: #CC0000;">42.31</span><span style="color: #339933;">,</span>longitude<span style="color: #339933;">:-</span><span style="color: #CC0000;">71.22</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#123;</span>latitude<span style="color: #339933;">:</span><span style="color: #CC0000;">42.28</span><span style="color: #339933;">,</span>longitude<span style="color: #339933;">:-</span><span style="color: #CC0000;">71.26</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// route object</span>
<span style="color: #003366; font-weight: bold;">var</span> route <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;some name&quot;</span><span style="color: #339933;">,</span>
	points<span style="color: #339933;">:</span>points<span style="color: #339933;">,</span>
	color<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#00f&quot;</span><span style="color: #339933;">,</span>
	width<span style="color: #339933;">:</span><span style="color: #CC0000;">2</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// add a route</span>
mapview.<span style="color: #660066;">addRoute</span><span style="color: #009900;">&#40;</span>route<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>What next?</h2>
<p>A good exercise would be maybe to create an application that it&#8217;s watching your position while you are driving or walking and display it on a map. All you would have to do is to use the <strong>location</strong> event and use the returned value to append a new item to the <strong>points</strong> array.</p>
<p>Anybody wanna try ? <img src='http://cssgallery.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong class="spanish">Check the Spanish version of this post:<br />
 <a href="http://nosoloweb.es/siete-dias-con-titanium-dia-5-gps-y-mapas/" rel="me">Siete días con Titanium – día 5 – GPS y Mapas</a></strong></p>
<div style="clear:both;">&nbsp;</div><div class="shr-publisher-1660"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-5-gps-and-maps%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-5-gps-and-maps%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-5-gps-and-maps%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->

<h3>Related posts:</h3><ol><li><a href='http://cssgallery.info/seven-days-with-titanium-day-7-orientation-and-accelerometer/' rel='bookmark' title='Seven days with Titanium &#8211; day 7 &#8211; orientation and accelerometer'>Seven days with Titanium &#8211; day 7 &#8211; orientation and accelerometer</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-4-media-images-movies-and-sounds/' rel='bookmark' title='Seven days with Titanium – day 4 – Media – images, movies and sounds'>Seven days with Titanium – day 4 – Media – images, movies and sounds</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-6%e2%80%93animations-and-transforms/' rel='bookmark' title='Seven days with Titanium – day 6 – animations and transforms'>Seven days with Titanium – day 6 – animations and transforms</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://cssgallery.info/seven-days-with-titanium-day-5-gps-and-maps/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Seven days with Titanium – day 4 – Media – images, movies and sounds</title>
		<link>http://cssgallery.info/seven-days-with-titanium-day-4-media-images-movies-and-sounds/</link>
		<comments>http://cssgallery.info/seven-days-with-titanium-day-4-media-images-movies-and-sounds/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 14:52:15 +0000</pubDate>
		<dc:creator>Dan Tamas</dc:creator>
				<category><![CDATA[Development tools]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Titanium Appcelerator]]></category>
		<category><![CDATA[ImageView]]></category>
		<category><![CDATA[titanium appcelerator]]></category>
		<category><![CDATA[Titanium Appcelerator media]]></category>
		<category><![CDATA[Titanium Appcelerator movies]]></category>
		<category><![CDATA[Titanium Appcelerator sounds]]></category>
		<category><![CDATA[Titanium Appcelerator videos]]></category>
		<category><![CDATA[Titanium.Media.createSound]]></category>
		<category><![CDATA[Titanium.Media.createVideoPlayer]]></category>
		<category><![CDATA[Titanium.Media.showCamera]]></category>
		<category><![CDATA[Titanium.UI.createImage]]></category>

		<guid isPermaLink="false">http://cssgallery.info/?p=1654</guid>
		<description><![CDATA[The day 4 comes very late because it was a very busy period so I had no time to continue the tutorials. 
Ok, so we should treat in this tutorial the media part of Appcelerator. This includes images - display and capture them with the camera and how to play movie and sounds.

<h2>Display images with Appcelerator</h2>

To display an image we use the ImageView. The image view has some simple arguments, like any view in the Titanium framework. I won't repeat them except for the important one. Obviously the source if the image is the one we are interested in set by the <strong>image</strong> argument, and accepts local or remote files.]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin: 10px !important;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-4-media-images-movies-and-sounds%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-4-media-images-movies-and-sounds%2F&amp;source=dan_tamas&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>The day 4 comes very late because it was a very busy period so I had no time to continue the tutorials.<br />
Ok, so we should treat in this tutorial the media part of Appcelerator. This includes images &#8211; display and capture them with the camera &#8211; and how to play movie and sounds.</p>
<h2>Display images with Appcelerator</h2>
<p>To display an image we use the ImageView. The image view has some simple arguments, like any view in the Titanium framework. I won&#8217;t repeat them except for the important one. Obviously the source if the image is the one we are interested in set by the <strong>image</strong> argument, and accepts local or remote files.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> the_img <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createImageView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> 
image<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;test.jpg&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>How does Titanium treat the path for local images? The path of the files are simply relative to the <strong>Resources</strong> folder. So you can use any folder/subfolder under the Resources one to locate the images of your application.</p>
<p>For the remote images a simple url to the image it&#8217;s enough.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> the_img <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createImageView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> 
image<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;http://example.com/test.png&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Titanium accepts all the formats the targeted OS supports.</p>
<h2>How to take pictures using the camera?</h2>
<p>The method you have to use is <a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Media.showCamera-method.html"><strong>Titanium.Media.showCamera</strong></a> that will display the OS interface for taking photos and expose the <strong>3 possible events</strong> (success, cancel, error) to us, so we can decide what to do next.</p>
<p>The function triggered by the success event receives as argument an object containing the media (the image itself) and the width and height of it. Using this data you can create a ImageView and add it to your window for example.</p>
<p>Below is a simple example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> win <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">currentWindow</span><span style="color: #339933;">;</span>
Titanium.<span style="color: #660066;">Media</span>.<span style="color: #660066;">showCamera</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	success<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> image <span style="color: #339933;">=</span> event.<span style="color: #660066;">media</span><span style="color: #339933;">;</span>
&nbsp;
		Ti.<span style="color: #660066;">API</span>.<span style="color: #660066;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Our type was: '</span><span style="color: #339933;">+</span>event.<span style="color: #660066;">mediaType</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">mediaType</span> <span style="color: #339933;">==</span> Ti.<span style="color: #660066;">Media</span>.<span style="color: #660066;">MEDIA_TYPE_PHOTO</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> imageView <span style="color: #339933;">=</span> Ti.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createImageView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>width<span style="color: #339933;">:</span>win.<span style="color: #660066;">width</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span>win.<span style="color: #660066;">height</span><span style="color: #339933;">,</span>image<span style="color: #339933;">:</span>event.<span style="color: #660066;">media</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			win.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>imageView<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;got the wrong type back =&quot;</span><span style="color: #339933;">+</span>event.<span style="color: #660066;">mediaType</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	cancel<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
               <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'You canceled the action.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	error<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// create alert</span>
		<span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createAlertDialog</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Camera'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// set message</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>error.<span style="color: #660066;">code</span> <span style="color: #339933;">==</span> Titanium.<span style="color: #660066;">Media</span>.<span style="color: #660066;">NO_CAMERA</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			a.<span style="color: #660066;">setMessage</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Please run this test on device'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #009900;">&#123;</span>
			a.<span style="color: #660066;">setMessage</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Unexpected error: '</span> <span style="color: #339933;">+</span> error.<span style="color: #660066;">code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// show alert</span>
		a.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	saveToPhotoGallery<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	allowEditing<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	mediaTypes<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>Ti.<span style="color: #660066;">Media</span>.<span style="color: #660066;">MEDIA_TYPE_VIDEO</span><span style="color: #339933;">,</span>Ti.<span style="color: #660066;">Media</span>.<span style="color: #660066;">MEDIA_TYPE_PHOTO</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Like the previous examples this one is found in the <a href="http://github.com/appcelerator/titanium_mobile/downloads">Kitchensink</a> provided by Titanium.</p>
<h2>Basic sounds with Appcelerator</h2>
<p>I will talk only about the basic sounds that are located on the device and can be used as games sounds or as sounds in your application.</p>
<p>The sounds are loaded by the method</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> sound <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">Media</span>.<span style="color: #660066;">createSound</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	url<span style="color: #339933;">:</span><span style="color: #3366CC;">'cricket.wav'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>From here you can <strong>play</strong>, <strong>stop</strong>, <strong>pause</strong>, <strong>reset</strong>, and <strong>set the volume</strong> of the sound with the methods presented in the documentation page of <a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Media.Sound-object">Titanium.Media.Sound</a>.</p>
<p>Each sound has its events, the most notable being the <strong>complete</strong> one that triggers when the sound finished to play.</p>
<p>If the sound file is big you should use the <strong>preload</strong> set to <strong>true</strong> when you build the sound. If you don&#8217;t do this the sound won&#8217;t start instantly when you call the <strong>play</strong> method.</p>
<p>One thing that you need to pay attention to is to <strong>release</strong> the sound if you don&#8217;t need it anymore. For example you play an intro sound only when the user starts the app, then after the sounds completes, you have to release it to free some memory on the device.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> intro_sound <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">Media</span>.<span style="color: #660066;">createSound</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	url<span style="color: #339933;">:</span><span style="color: #3366CC;">'cricket.wav'</span><span style="color: #339933;">,</span>
	preload<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
intro_sound.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'complete'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> intro_sound.<span style="color: #660066;">release</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
intro_sound.<span style="color: #660066;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//... more code here</span></pre></div></div>

<p>The above code will play the sound and autorelease it when it ends.</p>
<h2>Play Videos</h2>
<p>Using videos is similar with using sounds.  You will have to create a  player using the <a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Media.createVideoPlayer-method.html"><strong>Titanium.Media.createVideoPlayer</strong></a> method.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> videoURL <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://movies.apple.com/media/us/ipad/2010/tours/apple-ipad-video-us-20100127_r848-9cie.mov'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> activeMovie <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">Media</span>.<span style="color: #660066;">createVideoPlayer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	url<span style="color: #339933;">:</span> videoURL<span style="color: #339933;">,</span>
	width<span style="color: #339933;">:</span><span style="color: #CC0000;">300</span><span style="color: #339933;">,</span>
	height<span style="color: #339933;">:</span><span style="color: #CC0000;">200</span><span style="color: #339933;">,</span>
	top<span style="color: #339933;">:</span><span style="color: #CC0000;">50</span><span style="color: #339933;">,</span>
	left<span style="color: #339933;">:</span><span style="color: #CC0000;">50</span><span style="color: #339933;">,</span>
	backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#0f0'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
view.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>activeMovie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
activeMovie.<span style="color: #660066;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The url of the videoplayer can be a remote or a local file but you have to take care to be supported by the OS.</p>
<p>On the <a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Media.VideoPlayer-object.html">videoplayer documentation page</a> you will find more about the properties, methods and events supported by this control.</p>
<p>A notable thing is that in the SDK > 3.2 you can embed the videoplayer in any view and play it here without the need of making it fullscreen as in the next screenshot: </p>
<p><img src="http://cssgallery.info/wp-content/uploads/2010/11/embeded_titanium_videoplayer.png" alt="embeded_titanium_videoplayer" title="embeded titanium videoplayer" width="357" height="361" class="alignnone size-full wp-image-1678" /></p>
<p>That&#8217;s it for today, see you on Day 5.</p>
<p><strong class="spanish">Check the Spanish version of this post:<br />
 <a href="http://nosoloweb.es/siete-dias-con-titanium-dia-4-media-imagenes-peliculas-y-sonidos/" rel="me">Siete días con Titanium – día 4 – Media – Imágenes, películas y sonidos</a></strong></p>
<div style="clear:both;">&nbsp;</div><div class="shr-publisher-1654"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-4-media-images-movies-and-sounds%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-4-media-images-movies-and-sounds%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-4-media-images-movies-and-sounds%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->

<h3>Related posts:</h3><ol><li><a href='http://cssgallery.info/seven-days-with-titanium-day-0-introduction/' rel='bookmark' title='Seven days with Titanium &#8211; day 0 &#8211; introduction'>Seven days with Titanium &#8211; day 0 &#8211; introduction</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-5-gps-and-maps/' rel='bookmark' title='Seven days with Titanium – day 5 – GPS and Maps'>Seven days with Titanium – day 5 – GPS and Maps</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-1-windows-views-navigation-and-tabs/' rel='bookmark' title='Seven days with Titanium – day 1 – windows, views, navigation and tabs'>Seven days with Titanium – day 1 – windows, views, navigation and tabs</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://cssgallery.info/seven-days-with-titanium-day-4-media-images-movies-and-sounds/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
<enclosure url="http://movies.apple.com/media/us/ipad/2010/tours/apple-ipad-video-us-20100127_r848-9cie.mov" length="322" type="video/quicktime" />
		</item>
		<item>
		<title>Seven days with Titanium – day 3 &#8211; ajax(xhr) and webviews</title>
		<link>http://cssgallery.info/seven-days-with-titanium-day-3-ajaxxhr-and-webviews/</link>
		<comments>http://cssgallery.info/seven-days-with-titanium-day-3-ajaxxhr-and-webviews/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 14:58:59 +0000</pubDate>
		<dc:creator>Dan Tamas</dc:creator>
				<category><![CDATA[Development tools]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Titanium Appcelerator]]></category>
		<category><![CDATA[httpclient]]></category>
		<category><![CDATA[iphone titanium httpclient]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[JSON.parse]]></category>
		<category><![CDATA[JSON.stringify]]></category>
		<category><![CDATA[titanium ajax]]></category>
		<category><![CDATA[titanium webview]]></category>
		<category><![CDATA[Titanium.Network.online]]></category>
		<category><![CDATA[Titanium.UI.createWebView]]></category>
		<category><![CDATA[Titanium.XML]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://cssgallery.info/?p=1626</guid>
		<description><![CDATA[In "day 3" we will learn <strong>how to make our application communicate with a webserver</strong>. There are 2 ways we can do this: one is to use a <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.WebView-object">webview</a></strong> and point it to a real web page or using the <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Network.HTTPClient-object">HttpClient</a></strong> that Appcelerator provides us.

<h2>The WebView</h2>
What is <strong>WebView</strong>? A WebView is nothing more than a chromeless browser or, if you want, a "naked" browser (it misses the interface we're used to) that allows us to open remote or local webpages and display it in our apps.

You can use the webview for many purposes starting from displaying some nice html/css formatted text to building your own in-app browser. One thing you must NOT forget is that the webview it's very expensive for the device (in terms of CPU load and memory usage) so try to use it only when it's really really needed.

The webview is created using the function <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.createWebView-method.html">Titanium.UI.createWebView</a></strong>. Some things to specify about it would be that you have to choose between managing the touch events as a Titanium entity, or let the webpage do this. You cannot have both in the same time.

Two <strong>events</strong> that deserve more attention are <strong>beforeLoad</strong> and <strong>load</strong> that can be used to show and hide a <em>"loading..."</em> screen from the moment you try to load a remote page until the webpage is fully loaded.]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin: 10px !important;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-3-ajaxxhr-and-webviews%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-3-ajaxxhr-and-webviews%2F&amp;source=dan_tamas&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In &#8220;day 3&#8243; we will learn <strong>how to make our application communicate with a webserver</strong>. There are 2 ways we can do this: one is to use a <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.WebView-object">webview</a></strong> and point it to a real web page or using the <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Network.HTTPClient-object">HttpClient</a></strong> that Appcelerator provides us.</p>
<h2>The WebView</h2>
<p>What is <strong>WebView</strong>?  A WebView is nothing more than a chromeless browser or, if you want, a &#8220;naked&#8221; browser (it misses the interface we&#8217;re used to) that allows us to open remote or local webpages and display it in our apps.</p>
<p>You can use the webview for many purposes starting from displaying some nice html/css formatted text to building your own in-app browser. One thing you must NOT forget is that the webview it&#8217;s very expensive for the device (in terms of CPU load and memory usage) so try to use it only when it&#8217;s really really needed.</p>
<p>The webview is created using the function <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.createWebView-method.html">Titanium.UI.createWebView</a></strong>. Some things to specify about it would be that you have to choose between managing the touch events as a Titanium entity, or let the webpage do this. You cannot have both in the same time.</p>
<p>Two <strong>events</strong> that deserve more attention are <strong>beforeLoad</strong> and <strong>load</strong> that can be used to show and hide a <em>&#8220;loading&#8230;&#8221;</em> screen from the moment you try to load a remote page until the webpage is fully loaded.</p>
<h2>The HttpClient</h2>
<p>If you need to communicate with a server on a lower level (REST APIs, your own server implementation, etc) you can use the <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Network.HTTPClient-object.html">HttpClient</a></strong> that is equivalent of XHR (or ajax) in web.</p>
<p>When you use <strong>HttpClient</strong> you need to take in account two things:</p>
<ol>
<li>that the call is made asynchronous so your app logic needs to work this way </li>
<li>that you need to make it in a certain sequence: <strong>create</strong>, <strong>set events</strong>, <strong>open</strong>, <strong>send</strong>.</li>
</ol>
<p>So you need to create the <strong>HttpClient</strong>, set its onload and onerror events (that triggers when the call reply is received or an error occurs), open the channel and send the request &#8211;  with or without parameters.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> xhr <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">Network</span>.<span style="color: #660066;">createHTTPClient</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
xhr.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	Titanium.<span style="color: #660066;">API</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loaded'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
xhr.<span style="color: #000066;">onerror</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	Titanium.<span style="color: #660066;">API</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
xhr.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;http://google.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
xhr.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Within the function used with onload event you can use the <strong>responseText</strong> (normal or json reply), <strong>responseXML</strong>(XML reply) or <strong>responseData</strong> (binary reply) for further proccessing.</p>
<h2>Things to mention when you use networking with your apps</h2>
<p>Always let the user know that something is processing in the background &#8211; on a slow internet connection the users will believe the app crashed and will probably kill it. </p>
<p>For iPhone: if there is no network you need to alert the user about it &#8211; this is an Apple request and failing to do so might lead them to reject your app. This can be verified with the boolean <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Network-module">Titanium.Network.online</a></strong>.</p>
<h2>JSON , XML</h2>
<p>When it&#8217;s about sending structured data over httpthe server can reply in a JSON or XML format. I prefer JSON for two reasons:</p>
<ol>
<li>The JSON format is Javascript native</li>
<li>the overall size of the information received from the server is smaller, so the reply comes faster.</li>
</ol>
<p><strong>Titanium can use both formats</strong>: <strong>JSON</strong> with <strong>JSON.parse(string) </strong>and <strong>JSON.stringify(object)</strong> to manipulate the data and <strong>XML</strong> with the <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.XML-module">Titanium.XML</a></strong>. The XML string needs to be parsed and the result, an DOM2 object, needs further processing with the DOM2 own methods.</p>
<p>So as you see XML can get ugly( or at least for me). Because of this I use when possible <strong>YQL</strong>.</p>
<h2>YQL</h2>
<p><strong>YQL</strong> is the SQL for the web (a SQL like implementation for HTML build by the guys from Yahoo) that allows you to use a syntax similar to SQL for the <strong>DOM</strong> elements in a webpage. I won&#8217;t go further into details, you can do it by yourself on <strong><a href="http://developer.yahoo.com/yql/">the YQL page</a></strong>.</p>
<p>What I will show you is how to convert an XML reply into JSON using the  <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Yahoo.yql-method.html">Titanium.Yahoo.yql</a></strong> module. </p>
<p>First of all you need to go to the <strong>YQL Console</strong> page and try to transform an <strong>rss feed</strong> &#8211; that is pure <strong>XML</strong> into JSON. Go to <strong><a href="http://developer.yahoo.com/yql/console/?q=select%20*%20from%20xml%20where%20url%20%3D%20%22http%3A%2F2Fdeveloper.appcelerator.com%2Ffeed%2Fquestions%2Fcreated%22">this</a></strong> link, select JSON as format, empty the callback function input, un-check the Diagnostics checkbox and run the test. You will get the <strong>XML</strong> file converted in JSON.</p>
<p>We can do the same using the YQL module that Titanium provides us:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
Titanium.<span style="color: #660066;">Yahoo</span>.<span style="color: #660066;">yql</span><span style="color: #009900;">&#40;</span>
   <span style="color: #3366CC;">'select * from xml where url=&quot;http://developer.appcelerator.com/feed/questions/created&quot;'</span><span style="color: #339933;">,</span>
   <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// e.data holds the reply in json format</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We covered a little the basic networking in Titanium but there are unlimited ways on how you can use it.</p>
<h2>More resources</h2>
<p>As always <strong><a href="http://github.com/appcelerator/titanium_mobile/tree/master/demos/KitchenSink/Resources/examples/">KitchenSink</a></strong> scroll at the end and take a look at all <strong>xhr*,xml*, yql*</strong> files.</p>
<p>A full <a href="http://mobile.tutsplus.com/tutorials/appcelerator/appcelerator-using-json-to-build-a-twitter-client/">Twitter APIs/Titanium XHR tutorial</a> &#8211;  a must read.</p>
<p>And of course the official documentation:</p>
<ul>
<li><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.WebView-object"><strong>WebView</strong></a></li>
<li><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Network.HTTPClient-object"><strong>HttpClient</strong></a></li>
<li><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Yahoo.yql-method.html"><strong>YQL</strong></a></li>
</ul>
<p>If you have any questions or suggestions don&#8217;t hesitate to post them here. </p>
<p><strong class="spanish">Check the Spanish version of this post:<br />
 <a href="http://nosoloweb.es/siete-dias-con-titanium-dia-3-ajaxxhr-y-webviews/" rel="me">Siete días con Titanium – día 3 – ajax(xhr) y webviews</a></strong></p>
<div style="clear:both;">&nbsp;</div><div class="shr-publisher-1626"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-3-ajaxxhr-and-webviews%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-3-ajaxxhr-and-webviews%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-3-ajaxxhr-and-webviews%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://cssgallery.info/seven-days-with-titanium-day-3-ajaxxhr-and-webviews/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Seven days with Titanium – day 2 &#8211; tables and pickers</title>
		<link>http://cssgallery.info/seven-days-with-titanium-day-2-tables-and-pickers/</link>
		<comments>http://cssgallery.info/seven-days-with-titanium-day-2-tables-and-pickers/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 19:05:53 +0000</pubDate>
		<dc:creator>Dan Tamas</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Development tools]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Titanium Appcelerator]]></category>
		<category><![CDATA[android titanium tables]]></category>
		<category><![CDATA[Appcelerator Titanium tutorial]]></category>
		<category><![CDATA[iphone tables titanium]]></category>
		<category><![CDATA[iphone titanium picker]]></category>
		<category><![CDATA[PickerViews]]></category>
		<category><![CDATA[The Data property]]></category>
		<category><![CDATA[The Table element]]></category>
		<category><![CDATA[titanium appcelerator]]></category>
		<category><![CDATA[titanium tables]]></category>

		<guid isPermaLink="false">http://cssgallery.info/?p=1586</guid>
		<description><![CDATA[Welcome to <strong>day 2 with Titanium - Tables and pickers.</strong> A short reminder of what we've done till now:
<ul>
	<li><strong><a href="http://cssgallery.info/seven-days-with-titanium-day-0-introduction/">Introduction</a></strong></li>
	<li><strong><a href="http://cssgallery.info/seven-days-with-titanium-–-day-1-–-windowsviewsnavigation-and-tabs/">Day 1 - Windows, Views, navigation and Tabs</a></strong>.</li>
</ul>
<br/>
Believe it or not, the <strong>table</strong> is the most used UI element in the iPhone SDK. If you play a little with the applications that come with your "iDevice" you will see that almost all the native apps have tables. Sometimes they are so well designed and the appearance so changed that you don't even think of them as tables. But in time, while you will learn more, you will be able to spot it and a lot of ideas will come to you :). Also I think that that the <strong>pickers</strong> are some sort of "undercover tables" so that's why I'll present both in the same tutorial. ]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin: 10px !important;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-2-tables-and-pickers%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-2-tables-and-pickers%2F&amp;source=dan_tamas&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Welcome to <strong>day 2 with Titanium &#8211; Tables and pickers.</strong> A short reminder of what we&#8217;ve done till now:</p>
<ul>
<li><strong><a href="http://cssgallery.info/seven-days-with-titanium-day-0-introduction/">Introduction</a></strong></li>
<li><strong><a href="http://cssgallery.info/seven-days-with-titanium-–-day-1-–-windowsviewsnavigation-and-tabs/">Day 1 &#8211; Windows, Views, navigation and Tabs</a></strong>.</li>
</ul>
<p>Believe it or not, the <strong>table</strong> is the most used UI element in the iPhone SDK. If you play a little with the applications that come with your &#8220;iDevice&#8221; you will see that almost all the native apps have tables. Sometimes they are so well designed and the appearance so changed that you don&#8217;t even think of them as tables. But in time, while you will learn more, you will be able to spot it and a lot of ideas will come to you <img src='http://cssgallery.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Also I think that that the <strong>pickers</strong> are some sort of &#8220;undercover tables&#8221; so that&#8217;s why I&#8217;ll present both in the same tutorial. </p>
<h2>The Table element</h2>
<p>The table element is created using  <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.createTableView-method.html">Titanium.UI.createTableView</a></strong> function. This function accepts an object as argument like we are used to &#8211; with the different settings we might want to give to the table. Besides the usual properties ( like <strong>top</strong>, <strong>left</strong>, etc) we have a very important one named <strong>data</strong>. </p>
<h2>The Data property</h2>
<p>The <strong>data</strong> property will hold the rows of the table as an array. The below code will show you what I&#8217;m talking about:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> win1 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#fff&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> table1 <span style="color: #339933;">=</span>  Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTableView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	data<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
		<span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Row 1 - simple row&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Row 2 -  with child&quot;</span><span style="color: #339933;">,</span> hasChild<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Row 3 -  with detail&quot;</span><span style="color: #339933;">,</span> hasDetail<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Row 4 -  with check&quot;</span><span style="color: #339933;">,</span> hasCheck<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Row 5 -  red background&quot;</span><span style="color: #339933;">,</span> backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#f00&quot;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#93;</span>	
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
win1.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>table1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
win1.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>So, what are we doing here? </h3>
<p>We create a <strong>window</strong>. As we said in <strong><a href="http://cssgallery.info/seven-days-with-titanium-–-day-1-–-windowsviewsnavigation-and-tabs/">day 1</a></strong>, the application needs to have at least one window. Into this window we add <strong>table1</strong> with the <strong>rows</strong> set as above.</p>
<p>This is the simplest way to do it, with the properties of the rows set as the <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.TableViewRow-object">Titanium.UI.TableViewRows</a></strong> documentation page specifies.</p>
<p>If you develop cross-platform you&#8217;ll need to take in account that each platform will show the data in it&#8217;s way (and some specific things may be missing). Below are 2 screenshots on how the above code looks on iPhone and Android.</p>
<p><img src="http://cssgallery.info/wp-content/uploads/2010/08/capture-1.png" alt="Simple table with Titanium on iPhone" title="Simple table with Titanium on iPhone" width="295" height="444" class="alignleft size-full wp-image-1591" /><img src="http://cssgallery.info/wp-content/uploads/2010/08/capture-21.png" alt="Simple table with Titanium on Android" title="Simple table with Titanium on Android" width="295" height="444" class="alignleft size-full wp-image-1592" /></p>
<h2>A very important thing to know about tables</h2>
<p>The rows into tables are rendered &#8220;on request&#8221;, so let&#8217;s say you have 20 rows &#8211;  it&#8217;s clear that visible will be only a few (10 on a standard height). To save memory and to speed up the application  the other rows will be rendered when the user scrolls the table. To do this faster the OS of the device creates some sort of template for each layout of the rows and reuse it changing only what&#8217;s different. To take advantage of this you <strong>MUST</strong> set a <strong>className</strong> attribute for the rows that share the same layout ( I didn&#8217;t do it above to simplify the code).</p>
<p><strong>It is important</strong> mainly because for a few rows the memory usage is not too high, but for many rows &#8211; depending on how many and what&#8217;s inside the row &#8211; the app will move slow or even crash. The <strong>className</strong> can be any string you like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Row 1 - simple row&quot;</span><span style="color: #339933;">,</span> className<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;layout_one&quot;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<h2>More about tables</h2>
<p>Each table has at least one section  and each table can be plain (as above) or grouped. Let&#8217;s create a grouped table:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> table1 <span style="color: #339933;">=</span>  Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTableView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	style<span style="color: #339933;">:</span>Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">iPhone</span>.<span style="color: #660066;">TableViewStyle</span>.<span style="color: #660066;">GROUPED</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> section1 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTableViewSection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
section1.<span style="color: #660066;">headerTitle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Hello&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> row1 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTableViewRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Hello 1&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> row2 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTableViewRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Hello 2&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
section1.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>row1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
section1.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>row2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> section2 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTableViewSection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
section2.<span style="color: #660066;">headerTitle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Hello2&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> row3 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTableViewRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Hello 3&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> row4 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTableViewRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Hello 4&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
section2.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>row3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
section2.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>row4<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
table1.<span style="color: #660066;">setData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>section1<span style="color: #339933;">,</span>section2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>And the result</h3>
<p><img src="http://cssgallery.info/wp-content/uploads/2010/08/capture-31.png" alt="Grouped table with Titanium on Iphone" title="Grouped table with Titanium on Iphone" width="295" height="444" class="alignleft size-full wp-image-1595" /><img src="http://cssgallery.info/wp-content/uploads/2010/08/capture-4.png" alt="Grouped table with Titanium on Android" title="Grouped table with Titanium on Android" width="295" height="444" class="alignleft size-full wp-image-1598" /></p>
<p>As you see I used the method <strong>setData()</strong> to set the content of the table after it is created. </p>
<p>This method accepts any array of <strong>sections</strong> created with <strong><a href="http://developer.appcelerator.com/apidoc/mobile/1.3/Titanium.UI.createTableViewSection-method.html">Titanium.UI.createTableViewSection</a></strong> , <strong>rows</strong> created with <strong><a href="http://developer.appcelerator.com/apidoc/mobile/1.3/Titanium.UI.createTableViewRow-method.html">Titanium.UI.createTableViewRow</a></strong>  or <strong>objects</strong> that describe the <strong>rows</strong> as in the first example.</p>
<h2>Custom tables</h2>
<p>All the above examples show you how to create simple tables. If you want to create a more complicated layout you will need to create custom rows for this and <strong><a href="http://cssgallery.info/custom-row-for-tableview-in-appcelerator-titanium/">The Custom Rows tutorial</a></strong> explains how to do it..</p>
<h2>The Pickers or PickerViews</h2>
<p>The pickers are the equivalent of the <strong>select</strong> tag in html. The only difference is that you can create a multicolumn picker (which in HTML it&#8217;s not possible without using some tricks). The function that creates a picker is <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.createPicker-method">Titanium.UI.createPicker</a></strong></p>
<p>A simple picker it&#8217;s created with the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> picker <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createPicker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
data.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createPickerRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Bananas'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
data.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createPickerRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Strawberries'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
data.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createPickerRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Mangos'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
data.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createPickerRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Grapes'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
picker.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Sadly for now it is implemented only on the Apple platform (please correct me if I&#8217;m wrong)  so here it is how it should look like:<br />
<img src="http://cssgallery.info/wp-content/uploads/2010/08/capture-5.png" alt="Picker with Titanium" title="Picker with Titanium" width="320" height="480" class="alignnone size-full wp-image-1600" /></p>
<p>The type property of the picker lets you chose form the next predefined types but you always can create your own multicolumn picker.</p>
<p><strong>Titanium.UI.PICKER_TYPE_PLAIN (default)</strong>,<br />
<strong>Titanium.UI.PICKER_TYPE_DATE_AND_TIME</strong>,<br />
<strong>Titanium.UI.PICKER_TYPE_DATE</strong>,<br />
<strong>Titanium.UI.PICKER_TYPE_TIME</strong> or<br />
<strong>Titanium.UI.PICKER_TYPE_COUNT_DOWN_TIMER</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> picker <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createPicker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
type<span style="color: #339933;">:</span>Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">PICKER_TYPE_DATE_AND_TIME</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><img src="http://cssgallery.info/wp-content/uploads/2010/08/capture-6.png" alt="Date and time picker" title="Date and time picker" width="320" height="480" class="alignnone size-full wp-image-1601" /></p>
<p>Since the tables and the rows are similar  you will be able to create your custom rows in the same way as for the tables using of course the specific functions for the picker (linked at the end of the tutorial).</p>
<p>I won&#8217;t go further as the post is big enough already  but I&#8217;ll try in the future to create a set of posts that will be specific to an UI element and where I&#8217;ll try to &#8220;dissect&#8221; it as much as possible.</p>
<h2>More resources</h2>
<p>Here are some links to follow for more information:</p>
<ul>
<li><strong><a href="http://cssgallery.info/custom-row-for-tableview-in-appcelerator-titanium/">Custom table rows with Titanium</a></strong></li>
<li>A more advanced tutorial on <strong><a href="http://cssgallery.info/making-a-combo-box-in-titanium-appcelerator-code-and-video/">how to create a picker that behaves like the keyboard</a></strong> on iPhone</li>
<li>Titanium documentation for <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Picker-object">pickers</a></strong>, <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.PickerColumn-object">picker columns</a></strong>, <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.PickerRow-object">picker rows</a></strong> and <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.TableView-object">tables</a></strong>, <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.TableViewSection-object">table sections</a></strong>, <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.TableViewRow-object">table rows</a></strong>.</li>
</ul>
<p>As always, thank you for reading this and I&#8217;m waiting for your questions and suggestions. If you have your own tutorials or links I&#8217;ll be glad to add them here to improve the quality of the posts.</p>
<p>See you on <a href="http://cssgallery.info/seven-days-with-titanium-%E2%80%93-day-3-ajaxxhr-and-webviews/">day 3</a>.</p>
<p><strong class="spanish">Check the Spanish version of this post:<br />
 <a href="http://nosoloweb.es/siete-dias-con-titanium-dia-2-tablas-y-selectores/" rel="me">Siete días con Titanium – día 2 – tablas y selectores</a></strong></p>
<div style="clear:both;">&nbsp;</div><div class="shr-publisher-1586"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-2-tables-and-pickers%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-2-tables-and-pickers%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-2-tables-and-pickers%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->

<h3>Related posts:</h3><ol><li><a href='http://cssgallery.info/custom-row-for-tableview-in-appcelerator-titanium/' rel='bookmark' title='Custom row for TableView in Appcelerator Titanium'>Custom row for TableView in Appcelerator Titanium</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-0-introduction/' rel='bookmark' title='Seven days with Titanium &#8211; day 0 &#8211; introduction'>Seven days with Titanium &#8211; day 0 &#8211; introduction</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-5-gps-and-maps/' rel='bookmark' title='Seven days with Titanium – day 5 – GPS and Maps'>Seven days with Titanium – day 5 – GPS and Maps</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://cssgallery.info/seven-days-with-titanium-day-2-tables-and-pickers/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Seven days with Titanium – day 1 – windows, views, navigation and tabs</title>
		<link>http://cssgallery.info/seven-days-with-titanium-day-1-windows-views-navigation-and-tabs/</link>
		<comments>http://cssgallery.info/seven-days-with-titanium-day-1-windows-views-navigation-and-tabs/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 22:38:07 +0000</pubDate>
		<dc:creator>Dan Tamas</dc:creator>
				<category><![CDATA[Development tools]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Titanium Appcelerator]]></category>
		<category><![CDATA[basics of the interface]]></category>
		<category><![CDATA[createWindow]]></category>
		<category><![CDATA[download code]]></category>
		<category><![CDATA[download project]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[NavigationGroup]]></category>
		<category><![CDATA[TabGroup]]></category>
		<category><![CDATA[tableGroup]]></category>
		<category><![CDATA[tabs]]></category>
		<category><![CDATA[titanium appcelerator]]></category>
		<category><![CDATA[titanium tabs]]></category>
		<category><![CDATA[titanium views]]></category>
		<category><![CDATA[titanium windows]]></category>
		<category><![CDATA[views]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://cssgallery.info/?p=1543</guid>
		<description><![CDATA[Today is going to be the first day of the Titanium tutorial for beginners  and a pretty long post.
Before we begin here is the recap of what we have written until now (and updated what will come): <strong><a href="http://cssgallery.info/seven-days-with-titanium-day-0-introduction/">Seven days with Titanium – day 0 – introduction</a></strong>

As specified in the <strong><a href="http://cssgallery.info/seven-days-with-titanium-day-0-introduction/">Introduction</a></strong> post I will try in this lesson to say some things about <strong>navigation</strong>, <strong>windows</strong>, <strong>views</strong> and <strong>tabs</strong> – the basics of the interface.
]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin: 10px !important;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-1-windows-views-navigation-and-tabs%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-1-windows-views-navigation-and-tabs%2F&amp;source=dan_tamas&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Today is going to be the first day of the Titanium tutorial for beginners  and a pretty long post.<br />
Before we begin here is the recap of what we have written until now (and updated what will come): <strong><a href="http://cssgallery.info/seven-days-with-titanium-day-0-introduction/">Seven days with Titanium – day 0 – introduction</a></strong></p>
<p>As specified in the <strong><a href="http://cssgallery.info/seven-days-with-titanium-day-0-introduction/">Introduction</a></strong> post I will try in this lesson to say some things about <strong>navigation</strong>, <strong>windows</strong>, <strong>views</strong> and <strong>tabs</strong> – the basics of the interface.</p>
<p>I will try to first to enumerate each of these elements and then explain what they do and how to use them. Also each interface element has a link to it&#8217;s documentation page on Appcelerator site.</p>
<p>Everything that is related to the interface you will find it into the <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI-module" target="_blank">Titanium.UI</a></strong> module. There are also some platform specific modules that cover elements of interface present only on the specific platform: <strong>Titanium.UI.Android,Titanium.UI.iPhone,Titanium.UI.iPad</strong> but for now we won&#8217;t talk about them.</p>
<h2>The Window element</h2>
<p>The basic element in a Titanium application is a <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Window-object" target="_blank">Window</a></strong>. There is nothing complicated here, it&#8217;s a &#8220;container&#8221; for all the other elements if you wish. An application can have one or more windows but it must to have at least one window. A Window it&#8217;s one of the few elements that can exist by itself without the need to be a child of something.</p>
<h2>The View element</h2>
<p>Another  basic element  it&#8217;s a <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.View-object" target="_blank">View</a></strong>. The <strong>View</strong> can be the analog of a <strong>div</strong> tag in HTML so basically it&#8217;s just a rectangle that can hold other elements for an easy and convenient control of the application&#8217;s layout. A <strong>View</strong> cannot exists by itself  it will have to be a child of a <strong>Window</strong> or other element that accepts <strong>Views</strong> as child (a <strong>TableRowView</strong> or another <strong>View</strong> for example).</p>
<h2>The TabGroup and the Tabs</h2>
<p>The main navigational elements (and common to all platforms) is the <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.TabGroup-object" target="_blank">TabGroup</a></strong> and the <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Tab-object" target="_blank">Tabs</a></strong>. Exactly what the names says &#8211; analog with a browser with tabs capabilities , a <strong>TabGroup</strong> will hold more <strong>Tabs</strong>. Each <strong>Tab</strong> will control (open) a window. If you decide that you application will have a <strong>TabGroup</strong> this will be the &#8220;root&#8221; of the application. What does it mean? That any window opened by the <strong>Tabs</strong> in <strong>TabGroup</strong> will be controlled by this  and the <strong>TabGroup</strong> has one instance only  and it cannot be closed or removed, but only hidden.</p>
<p>There is also an iPhone specific navigation element, named <strong><a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.iPhone.NavigationGroup-object" target="_blank">NavigationGroup</a></strong> that allows to navigate through windows without the need to create the navigation toolbar/buttons by ourselves.</p>
<h2>Example</h2>
<p>This is how an application with<strong> a TabGroup, 2 Windows, 2 Tabs and a View </strong>looks loke on the Android and the iPhone platforms.</p>
<p><img class="alignleft size-full wp-image-1555" title="Seven days with Titanium- day 1 - android" src="http://cssgallery.info/wp-content/uploads/2010/08/capture-3.png" alt="Seven days with Titanium- day 1 - android" width="295" height="444" /><img class="alignleft size-full wp-image-1556" title="Seven days with Titanium- day 1 - iPhone" src="http://cssgallery.info/wp-content/uploads/2010/08/capture-2.png" alt="Seven days with Titanium- day 1 - iPhone" width="295" height="444" /></p>
<h2>More details about each element</h2>
<p>Before we continue it would be great to take a look at each element documentation page because there is a lot of  valuable info there. As you see, each interface element has some <strong>properties</strong> that are setters and/or getters  like <strong>top</strong>, <strong>backgroundColor</strong>, etc), some <strong>methods</strong> (<strong>add()</strong>, <strong>open()</strong>) and <strong>events</strong> &#8211;  usually user interaction events (touchstart, doubletap, etc) or specific events (open,close). Very similar with the web elements.</p>
<p>I want to specify some things:<br />
<strong>sizes</strong> are in pixels but <strong>without</strong> the usual &#8220;px&#8221; notation, or in percents &#8211;  but this requires to be written as a string:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #660066;">top</span><span style="color: #339933;">:</span><span style="color: #CC0000;">25</span><span style="color: #339933;">,</span>
width<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;50%&quot;</span>
...</pre></div></div>

<p><strong>colors</strong> are in hexa rgb , the short or the long form , don&#8217;t use names:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #660066;">backgroundColor</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#f00&quot;</span><span style="color: #339933;">,</span>
borderColor<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#ff0055&quot;</span>
...</pre></div></div>

<p>Let&#8217;s try to elaborate a little.</p>
<h2>The Window element, again</h2>
<p>The window element is created using the function <strong>Titanium.UI.createWindow</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> win1 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>  
    title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Tab 1'</span><span style="color: #339933;">,</span>
    backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#fff'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>What the above code means? That we pass to the <strong>createWindow </strong>function an object argument with all the properties that we want to set.</p>
<p>This could be written like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> win1 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
win1.<span style="color: #660066;">title</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'Tab 1'</span>
win1.<span style="color: #660066;">backgroundColor</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'#fff'</span><span style="color: #339933;">;</span></pre></div></div>

<p>I think it&#8217;s pretty clear so I won&#8217;t go further with the code for <strong>view</strong>, <strong>tabs</strong> and so on. It&#8217;s similar to this only that you use <strong>Titanium.UI.createView</strong>, etc</p>
<h2>How the tabGroup, tabs and the windows are related</h2>
<p>The logic behind the above UI elements it&#8217;s as it follows:</p>
<p>The <strong>tabGroup</strong> is the root of the application, the &#8220;master&#8221;, it cannot be included in any other UI element.<br />
This holds the <strong>tabs</strong>( at least one)  and a tab, when clicked, opens the window associated with it.</p>
<p>Here is a sample code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// create tab group</span>
<span style="color: #003366; font-weight: bold;">var</span> tabGroup <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTabGroup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// create base UI tabs and  windows</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> win1 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>  
    title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Tab 1'</span><span style="color: #339933;">,</span>
    backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#fff'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> tab1 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>  
    icon<span style="color: #339933;">:</span><span style="color: #3366CC;">'KS_nav_views.png'</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Tab 1'</span><span style="color: #339933;">,</span>
    window<span style="color: #339933;">:</span>win1
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> win2 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>  
    title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Tab 2'</span><span style="color: #339933;">,</span>
    backgroundColor<span style="color: #339933;">:</span><span style="color: #3366CC;">'#fff'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> tab2 <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">UI</span>.<span style="color: #660066;">createTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>  
    icon<span style="color: #339933;">:</span><span style="color: #3366CC;">'KS_nav_views.png'</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Tab 2'</span><span style="color: #339933;">,</span>
    window<span style="color: #339933;">:</span>win2
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//  add tab</span>
&nbsp;
tabGroup.<span style="color: #660066;">addTab</span><span style="color: #009900;">&#40;</span>tab1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
tabGroup.<span style="color: #660066;">addTab</span><span style="color: #009900;">&#40;</span>tab2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
<span style="color: #006600; font-style: italic;">// open tab group</span>
tabGroup.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The above code will generate a similar interface with the screenshots without the labels &#8220;I am window 1&#8243; etc and the red view. This would be a good exercise for you <img src='http://cssgallery.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<h3>Important !</h3>
<p>As you see we set the same <strong>titles</strong> to <strong>tab1 &#8211; win1</strong> and to <strong>tab2 &#8211; win2</strong>. This is not mandatory from the code point of view. The window associated to each tab is specified using the <strong>window</strong> property that points to the previous declared window. Why it&#8217;s like this then? It&#8217;s about usability. The user needs to have the same values when he/she has to associate two visual elements or will get confused. Also Apple might not like this when you will submit your app.</p>
<h2>Resources</h2>
<p>The above code it&#8217;s found in the default app.js file that you get when you create a new project. I only explained a little how things are.</p>
<p>A <strong>very very</strong> good resource it&#8217;s the KitcheSink project form Appcelerator team, found <strong><a href="http://github.com/appcelerator/titanium_mobile/downloads">here</a></strong>.</p>
<p>For the advanced coders <strong><a href="http://cssgallery.info/create-a-nifty-tooltip-in-titanium/">this is another tutorial</a></strong> on how to create a <strong>tooltip</strong> with Titanium  that basically it&#8217;s just a view with a background image.</p>
<p>I think it&#8217;s enough for <strong>day 1</strong>, the post is too long and I&#8217;ll only add that I&#8217;m waiting for your questions, suggestions and critics if I made any mistake <img src='http://cssgallery.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  With your questions/suggestions I&#8217;ll update the post or create a new one linked to &#8220;day 1&#8243;.</p>
<p><strong class="spanish">Check the Spanish version of this post:<br />
 <a href="http://nosoloweb.es/siete-dias-con-titanium-dia-1-ventanas-vistas-navegacion-y-pestanas/" rel="me">Siete días con Titanium – Día 1 – Ventanas, vistas, navegación y pestañas</a></strong></p>
<div style="clear:both;">&nbsp;</div><div class="shr-publisher-1543"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-1-windows-views-navigation-and-tabs%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-1-windows-views-navigation-and-tabs%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-1-windows-views-navigation-and-tabs%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->

<h3>Related posts:</h3><ol><li><a href='http://cssgallery.info/seven-days-with-titanium-day-2-tables-and-pickers/' rel='bookmark' title='Seven days with Titanium – day 2 &#8211; tables and pickers'>Seven days with Titanium – day 2 &#8211; tables and pickers</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-6%e2%80%93animations-and-transforms/' rel='bookmark' title='Seven days with Titanium – day 6 – animations and transforms'>Seven days with Titanium – day 6 – animations and transforms</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-0-introduction/' rel='bookmark' title='Seven days with Titanium &#8211; day 0 &#8211; introduction'>Seven days with Titanium &#8211; day 0 &#8211; introduction</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://cssgallery.info/seven-days-with-titanium-day-1-windows-views-navigation-and-tabs/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Seven days with Titanium &#8211; day 0 &#8211; introduction</title>
		<link>http://cssgallery.info/seven-days-with-titanium-day-0-introduction/</link>
		<comments>http://cssgallery.info/seven-days-with-titanium-day-0-introduction/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 14:58:16 +0000</pubDate>
		<dc:creator>Dan Tamas</dc:creator>
				<category><![CDATA[Development tools]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Titanium Appcelerator]]></category>
		<category><![CDATA[Appcelerator]]></category>
		<category><![CDATA[titanium appcelerator]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://cssgallery.info/?p=1521</guid>
		<description><![CDATA[<h2>What is all about?</h2>
I intend this to be a set of seven tutorials to help beginners understand how to work with the Titanium mobile framework.

The guys at <a href="http://www.appcelerator.com/">Appcelerator</a> did a great job with the framework allowing to us, the web developers, to have access on native applications for mobile devices ( Apple iDevices, Android and soon BlackBerry).

The framework reached the 1.4 version and each day more developers seem to be interested in using it - especially because it's free. The community is great and you'll find answers on almost any problem you might have. But  for the beginners is still a little difficult to start. From here surged the idea of this set of tutorials in which I will try to cover the basics of the development process for iPhone and Android.
<img src="http://cssgallery.info/wp-content/uploads/2010/08/Titanium-Appcelerator.png" alt="Titanium Appcelerator" title="Titanium Appcelerator" width="630" class="size-full wp-image-1530" />]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div class="tweetmeme_button" style="float: right; margin: 10px !important;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-0-introduction%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-0-introduction%2F&amp;source=dan_tamas&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h2>What is all about?</h2>
<p>I intend this to be a set of seven tutorials to help beginners understand how to work with the Titanium mobile framework.</p>
<p>The guys at <a href="http://www.appcelerator.com/">Appcelerator</a> did a great job with the framework allowing to us, the web developers, to have access on native applications for mobile devices ( Apple iDevices, Android and soon BlackBerry).</p>
<p>The framework reached the 1.4 version and each day more developers seem to be interested in using it &#8211; especially because it&#8217;s free. The community is great and you&#8217;ll find answers on almost any problem you might have. But  for the beginners is still a little difficult to start. From here surged the idea of this set of tutorials in which I will try to cover the basics of the development process for iPhone and Android.<br />
<img src="http://cssgallery.info/wp-content/uploads/2010/08/Titanium-Appcelerator.png" alt="Titanium Appcelerator" title="Titanium Appcelerator" width="630" class="size-full wp-image-1530" /></p>
<h2>Some things to start</h2>
<p>Each post will contain a header with the previous tutorials written, for an easy follow.  It will also have a footer part where some links of interest will be published.</p>
<p>It won&#8217;t be daily posts, I will write when I&#8217;ll have enough time to test and write the examples. I prefer a better written post to a fast one. And each post might be updated to add forgotten things (or to fix issues) so don&#8217;t forget to bookmark it.</p>
<p>The provided code will be licensed under the MIT license  so you will be able to use it as you wish.</p>
<h2>What should I know and/or what do I need?</h2>
<p>Basically you need only Javascript knowledge. Some  OOP coding routine would be great but is not mandatory ( we learn on the fly <img src='http://cssgallery.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .</p>
<ul
	<li>To develop for Android you will need Android SDK( Linux / OsX / Windows )</li>
<li>To develop for iPhone you will need a Mac ( Apple&#8217;s rules not mine)</li>
</ul>
<p>I will not show you how to install any of the frameworks, SDKs, etc.  There are good tutorials and HowTo&#8217;s that will show you this so I don&#8217;t want to repeat what&#8217;s already out there.</p>
<h2>What do I need to forget?</h2>
<p>May look strange but you really have to forget about something: <strong>DOM</strong>. Why? Because there is no DOM in there. We are not anymore in the HTML world. So nothing from  HTML applies here. There are similar things (events for example) but everything it&#8217;s just an analogy to make it easier to use it.</p>
<p>Forget also about using  a library ( yes, no MooTools, jQuery, etc…), or at least for a start. Again why? Because all these libraries are DOM oriented  and are used to fight with multiple browsers, to please each of them  and this adds bloatware to your code &#8211; code that will not be used by the devices anyway.</p>
<p>Why &#8220;at least for a start&#8221; ? Well, later you might miss some functions and methods these libraries have (let&#8217;s say the array methods like filter, each, unique, etc… ) but you will be able to implement this by your own and avoid a 150k library.</p>
<h2>What you will NOT learn in these tutorials:</h2>
<p>You won&#8217;t learn Javascript (you need to know it already). You will not learn ObjC and/or Java (in the end this is the purpose of Titanium). I will try to provide the code for each thing you will learn about  as well as screenshots and maybe videos.</p>
<p>And at last</p>
<h2>What will you learn:</h2>
<h3><a href="http://cssgallery.info/seven-days-with-titanium-–-day-1-–-windowsviewsnavigation-and-tabs/">Day 1</a>:</h3>
<p>Some things about navigation, windows, views and tabs &#8211;  the basics of the interface. I will try to briefly explain what does each of these elements and how to use them.</p>
<h3><a href="http://cssgallery.info/seven-days-with-titanium-%E2%80%93-day-2-tables-and-pickers/">Day 2:</a></h3>
<p>Tables and pickers (or option pickers, the &#8216;select&#8217; tag equivalent)</p>
<h3><a href="http://cssgallery.info/seven-days-with-titanium-–-day-3-ajaxxhr-and-webviews/">Day 3:</a></h3>
<p>Ajax (actually XHR) &#8211; on how to use the HttpClient for webpages, XML, JSON and YQL; The webview &#8211;  how to embed html code in your apps.</p>
<h3><a href="http://cssgallery.info/seven-days-with-titanium-–-day-4-–-media-–-images-movies-and-sounds/">Day 4:</a></h3>
<p>Media &#8211; images, movies and sounds</p>
<h3><a href="http://cssgallery.info/seven-days-with-titanium-day-5-gps-and-maps/">Day 5:</a></h3>
<p>GPS and maps.</p>
<h3><a href="http://cssgallery.info/seven-days-with-titanium-day-6%E2%80%93animations-and-transforms/">Day 6:</a></h3>
<p>Some eye-candy with animations and transforms</p>
<h3><a href="http://cssgallery.info/seven-days-with-titanium-day-7-orientation-and-accelerometer/" title="Orientation and accelerometer">Day 7:</a></h3>
<p>About orientation and accelerometer.</p>
<h3>Day 8:</h3>
<p>This will be a post-tutorials day  where I&#8217;ll sum up the lessons,  add links and so on.</p>
<p>I know I said seven days  and in the end are 9, but this one and the last do  not count as &#8220;learning&#8221; days. There is a lot of stuff left out  like scrollviews, sliders, some modules &#8211; Facebook? &#8211;  more advanced techniques  &#8211;  like app events &#8211;  but hopefully these will be the subject of another tutorials.</p>
<p>Let me know your thoughts, if you have ideas of what should I write about &#8211;  remember that this is a beginner&#8217;s guide &#8211;  or to ask questions.</p>
<p>See you in <strong>day 1</strong>.</p>
<h2 style="color:#ff0000">Update:</h2>
<p><a href="http://developer.appcelerator.com/blog/2010/08/introducing-new-getting-started-guides.html">PDF documents on how to install Titanium on each of the supported platforms</a> ( Linux / OsX / Windows ) can be found on Titanium Appcelerator blog, go get them <img src='http://cssgallery.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong class="spanish">Check the Spanish version of this post:<br />
 <a href="http://nosoloweb.es/siete-dias-con-titanium-dia-0-introduccion/" rel="me">Siete días con Titanium – Día 0 – Introducción</a></strong></p>
<div style="clear:both;">&nbsp;</div><div class="shr-publisher-1521"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' shr_layout='button_count' shr_showfaces='false' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-0-introduction%2F'></a><a class='shareaholic-fbsend' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-0-introduction%2F'></a><a class='shareaholic-googleplusone' shr_size='medium' shr_count='true' shr_href='http%3A%2F%2Fcssgallery.info%2Fseven-days-with-titanium-day-0-introduction%2F'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->

<h3>Related posts:</h3><ol><li><a href='http://cssgallery.info/seven-days-with-titanium-day-1-windows-views-navigation-and-tabs/' rel='bookmark' title='Seven days with Titanium – day 1 – windows, views, navigation and tabs'>Seven days with Titanium – day 1 – windows, views, navigation and tabs</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-2-tables-and-pickers/' rel='bookmark' title='Seven days with Titanium – day 2 &#8211; tables and pickers'>Seven days with Titanium – day 2 &#8211; tables and pickers</a></li>
<li><a href='http://cssgallery.info/seven-days-with-titanium-day-4-media-images-movies-and-sounds/' rel='bookmark' title='Seven days with Titanium – day 4 – Media – images, movies and sounds'>Seven days with Titanium – day 4 – Media – images, movies and sounds</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://cssgallery.info/seven-days-with-titanium-day-0-introduction/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (User is logged in)
Page Caching using disk: basic (User agent is rejected)
Database Caching using disk: basic

Served from: www.cssgallery.info @ 2012-02-04 19:19:33 -->
