<?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/"
xmlns:series="http://organizeseries.com/"
> <channel><title>BuildMobile</title> <atom:link href="http://buildmobile.com/feed/" rel="self" type="application/rss+xml" /><link>http://buildmobile.com</link> <description>Everything Mobile: Mobile Web, iOS, Android, Windows Phone and Beyond.</description> <lastBuildDate>Mon, 29 Apr 2013 17:17:30 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.5.1</generator> <item><title>Build a Responsive, Mobile-Friendly Website From Scratch: Semantic HTML</title><link>http://buildmobile.com/build-a-responsive-mobile-friendly-website-from-scratch-dive-into-the-code/</link> <comments>http://buildmobile.com/build-a-responsive-mobile-friendly-website-from-scratch-dive-into-the-code/#comments</comments> <pubDate>Tue, 16 Apr 2013 17:37:35 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Discussion]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5691</guid> <description><![CDATA[In the last article, as promised, we&#8217;ve begun doing some practical work with the planning and creation of a mockup. Now, we’ve focused on how to build a personal project&#8230;]]></description> <content:encoded><![CDATA[<p>In <a
title="Build a Responsive, Mobile-Friendly Website From Scratch: Design a Mockup" href="http://buildmobile.com/build-a-responsive-mobile-friendly-website-from-scratch-design-a-mockup/" target="_blank">the last article</a>, as promised, we&#8217;ve begun doing some practical work with the planning and creation of a mockup. Now, we’ve focused on how to build a personal project wireframe thinking responsively and—consequently—how a responsive design can adapt to three target layouts: Default (PC desktop), Portrait Tablet, and Smartphone.</p><p>We’ve seen how to arrange the elements of a typical website in the three main devices’ categories by creating a template that represents the common content elements. In this third part of this series, I’ll concentrate on writing the HTML code and work on the structure of the homepage, while in the very next, I&#8217;ll be setting the first CSS styling rules to build the initial design of our project.</p><h3>First Step: HTML code</h3><p>Let&#8217;s begin building the structure of our website through the use of HTML code. To avoid confusion and miss some steps, we&#8217;ll proceed by dividing the layout into three parts, just like we did during the mockup design phase. We&#8217;ll pause from time to time on parts of the code that are inherent only to that single part. The first part we&#8217;ll face with will of course be the header, that is the part that in our mockup consists of the following elements: banner, newsletter-box, and main menu bar. Now, what we have to do as our first task is declare the type document that for HTML5 is indicated in the following way:</p><pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html&gt;</pre><p>Next, we must add the section that is necessary to help the web browser to interpret the content in the following body section. This section contains specific tags, CSS stylesheets, and other elements that remain hidden and are not displayed in the browser. These elements are generally called <strong>meta information</strong> (basically &#8220;information about information&#8221;) because their function is to describe what kind of information is on the page.</p><p>The first meta-tag which needs a specification is &#8220;meta charset&#8221;; it defines what character coding is used in the page. In our case, we set it to UTF-8, which is a variable width Unicode format compatible with ASCII or plain text for the basic alphanumeric characters. By using the &#8220;upper half&#8221; of the 8-bit ASCII set and extension codes, it can handle over a million unique characters.</p><p>It&#8217;s a requirement that any web page defines the formatting of the page within it&#8217;s header info so that all the browsers know exactly how to read and interpret the content. Otherwise, they&#8217;ll show the characters using their &#8220;best guess,&#8221; which isn&#8217;t always accurate. The guess could be wrong, and this will lead to showing the wrong characters to the users.</p><p>The next item we have to pay attention to is the <strong>viewport</strong> property. Setting a viewport tells the browser how content should fit on the device&#8217;s screen and informs the browser that the site is optimized for mobile. For example&#8230;</p><pre class="brush: xml; title: ; notranslate">&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;</pre><p>&#8230;tells the browser to set the viewport to the width of the device with an initial scale of 1. After this, we insert into the title tag the name we&#8217;ve chosen for our website. Finally, we have to link our HTML page to the <strong>CSS stylesheets</strong> that we&#8217;ll use to define the style of our homepage; the HTML &#8220;link&#8221; element specifies relationships between the current document and other documents. With this line of code&#8230;</p><pre class="brush: xml; title: ; notranslate">&lt;link rel=&quot;stylesheet&quot; href=&quot;css/common.css&quot; type=&quot;text/css&quot; /&gt;</pre><p>&#8230;we link the document to the common stylesheet (that is, the document which contains all the common CSS rules that will be shared by the three versions of the project), while this one&#8230;</p><pre class="brush: xml; title: ; notranslate">&lt;link rel=&quot;stylesheet&quot; href=&quot;css/responsive.css&quot; type=&quot;text/css&quot; /&gt;</pre><p>&#8230;recalls to the file where there are the specifications of the particular rules that will be applied only to that particular device indicated. Please note that since we&#8217;re using HTML5, you don&#8217;t actually need to specify <code>type="text/css"</code>.</p><p>Close the head tag and move on to the <strong>body</strong> section. At this point, we have to create two separate divs: one for the <strong>banner</strong>, and one for the <strong>newsletter box</strong>.</p><p>In the first, in addition to the id, it&#8217;s a good practice for accessibility to use a WAI-ARIA role; generally roles describe widgets and structure. Structural roles are added to markup as attributes of elements, which makes it perfect for our purposes.</p><p><strong>WAI-ARIA</strong> (<em>Web Accessibility Initiative &#8211; Accessible Rich Internet Applications</em>) is a technical specification published by the World Wide Web Consortium that specifies how to increase the accessibility of web pages. It allows web pages (or portions of pages) to declare themselves as applications rather than as static documents by adding role, property, and state information to dynamic web applications in order to make controls and content updates accessible to users with disabilities. That&#8217;s why all these kinds of specifications are so important.</p><p>Let&#8217;s continue our project by building a <strong>newsletter opt-In form</strong>. first of all, add a form with &lt;form&gt; tags. The opening tag should include the form name, a method which can be either &#8220;query&#8221; or &#8220;post,&#8221; and the destination or &#8220;action&#8221; where the form should send the input (I put a # to indicate that it is not fixed).</p><p>Now, add a text field with a label to collect the email address and assign an ID and a class for the following changes of style you might apply to your form. Finally, add a submit button to the form. The information put into the form fields will be sent to the receiving page for processing when the visitor clicks the submit button. Insert the word &#8220;Submit&#8221; for the input type, name and value fields to create a submit button, and close the form and div tags.</p><p>So, at this point, you should have the following code:</p><pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html&gt;
&lt;html&gt;
   &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;/&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
      &lt;title&gt;Website name&lt;/title&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;css/common.css&quot; type=&quot;text/css&quot; /&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;css/responsive.css&quot; type=&quot;text/css&quot; /&gt;
  &lt;/head&gt;
   &lt;body&gt;
      &lt;header&gt;
         &lt;div id=&quot;banner&quot; role=&quot;banner&quot;&gt;
&lt;img src=&quot;./images/banner.png&quot; alt=&quot;Banner&quot; /&gt;&lt;/div&gt;
         &lt;div id=&quot;newsletter-box&quot;&gt;
            &lt;form name=&quot;newsletter-form&quot; action=&quot;#&quot; method=&quot;post&quot;&gt;
               &lt;label for=&quot;newsletter-email&quot;&gt;Newsletter:&lt;/label&gt;
               &lt;input type=&quot;email&quot; id=&quot;newsletter-email&quot; class=&quot;newsletter-email&quot; name=&quot;email&quot; required=&quot;required&quot; placeholder=&quot;Your email&quot; /&gt;
               &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
            &lt;/form&gt;
         &lt;/div&gt;
      &lt;/header&gt;</pre><p>Let&#8217;s proceed with the central part of our layout, namely the one used for different types of content.</p><p>First and foremost, let&#8217;s create a classic <strong>menu</strong>, composed of five options that will be the main categories of the whole website: Homepage, News, Graphics, Mobile, and Web Design. In this case, the element most suitable for our purpose is the <strong>nav</strong> element, which is a semantic element used for declaring a navigational section of a website (that is, a section of a page that links to other pages or to parts within the page).</p><p>Within the nav tag, let&#8217;s add an unordered list (to which we&#8217;ll assign a class called &#8220;menu-item&#8221;). For the content section, let&#8217;s create a main div whose ID is &#8220;content&#8221;, a wrapper div, and put an article within it. The <strong>article</strong> element is a specialized kind of section; it has a more specific semantic meaning as an independent, self-contained part of the page. In our sample, it&#8217;ll be used to contain the description of the purpose of our website.</p><p>As for the wrapper div, it will contain three more elements: a div which contains all the information about the author (and a photo,if you want), an aside in which the author can add his screencasts, and another aside intended for his latest tweets. Two points on the <strong>aside</strong> element: it is used for tangentially-related content. However, in the interpretation of this new element there lies some confusion as to how it should be used; remember that just because some content appears to the left or right of the main content isn’t enough reason to use the aside element. The better way to decide whether you should use an aside or not involves asking yourself if the content within the aside can be removed without reducing the meaning of the main content or if the main content is truly dependent on the aside. Pullquotes, glossaries, or even related links are some examples of tangentially related content that are appropriate for an aside.</p><p>The code for this second part is the following:</p><pre class="brush: xml; title: ; notranslate">
      &lt;nav class=&quot;menu&quot;&gt;
         &lt;ul class=&quot;menu-list&quot;&gt;
            &lt;li class=&quot;menu-item&quot;&gt;
               &lt;a class=&quot;menu-item-link&quot; href=&quot;./homepage&quot; title=&quot;Homepage&quot;&gt;Homepage&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;menu-item&quot;&gt;
               &lt;a class=&quot;menu-item-link&quot; href=&quot;./news&quot; title=&quot;News&quot;&gt;News&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;menu-item&quot;&gt;
               &lt;a class=&quot;menu-item-link&quot; href=&quot;./graphics&quot; title=&quot;Graphics&quot;&gt;Graphics&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;menu-item&quot;&gt;
               &lt;a class=&quot;menu-item-link&quot; href=&quot;./mobile&quot; title=&quot;Mobile&quot;&gt;Mobile&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;menu-item&quot;&gt;
               &lt;a class=&quot;menu-item-link&quot; href=&quot;./webdesign&quot; title=&quot;Web Design&quot;&gt;Web Design&lt;/a&gt;
            &lt;/li&gt;
         &lt;/ul&gt;
      &lt;/nav&gt;
      &lt;div id=&quot;content&quot;&gt;
         &lt;article id=&quot;description-box&quot;&gt;
            &lt;h3&gt;Title&lt;/h3&gt;
            &lt;p&gt;
               Your content here
            &lt;/p&gt;
         &lt;/article&gt;
         &lt;div id=&quot;wrapper&quot;&gt;
            &lt;div id=&quot;author-info-box&quot;&gt;
               &lt;p&gt;
                  Information about the author &lt;br /&gt;
               &lt;/p&gt;
            &lt;/div&gt;
	    &lt;aside id=&quot;video-box&quot;&gt;
               &lt;video&gt;
 &lt;source src=&quot;movie.mp4&quot; type='video/mp4;' /&gt;
 &lt;source src=&quot;movie.webm&quot; type='video/webm;' /&gt;
&lt;/video&gt;
            &lt;/aside&gt;
            &lt;aside id=&quot;twitter-box&quot;&gt;
               &lt;p&gt;
                  &lt;img class=&quot;twitter-bird&quot; src=&quot;./images/twitter-bird.png&quot; alt=&quot;Twitter Bird&quot; /&gt;
                  Follow me on Twitter! &lt;br /&gt;
                  We're in (number of follower)
               &lt;/p&gt;
            &lt;/aside&gt;
               &lt;br class=&quot;clear-both&quot; /&gt;
         &lt;/div&gt;
      &lt;/div&gt;
</pre><p>The last remaining part is the section called <strong>footer</strong>, which generally contains information about its sections, the author, links to related documents, copyright data, and so on. In some cases, you can also find links to profiles or personal pages of ubiquitous social networks such as Facebook, Twitter, Google+, and LinkedIn. So, we place the principal information in a paragraph inserted in the new HTML5 tag &lt;footer&gt; and the links directed to the social profiles mentioned above in a div whose main class is named &#8220;social-bar&#8221;.</p><p>Here is the code of this last part:</p><pre class="brush: xml; title: ; notranslate">
      &lt;footer id=&quot;main-footer&quot;&gt;
         &lt;p&gt;
            Author's name. All rights reserved. Copyright &amp;copy; 2012 - 2013.
         &lt;/p&gt;
         &lt;div class=&quot;social-bar&quot;&gt;
            &lt;a href=&quot;./facebook&quot; title=&quot;Facebook&quot;&gt;
               &lt;img src=&quot;./images/icons/facebook.png&quot; alt=&quot;Facebook icon&quot; /&gt;
            &lt;/a&gt;
            &lt;a href=&quot;./twitter&quot; title=&quot;Twitter&quot;&gt;
               &lt;img src=&quot;./images/icons/twitter.png&quot; alt=&quot;Twitter icon&quot; /&gt;
            &lt;/a&gt;
            &lt;a href=&quot;./googleplus&quot; title=&quot;Google+&quot;&gt;
               &lt;img src=&quot;./images/icons/google.png&quot; alt=&quot;Google+ icon&quot; /&gt;
            &lt;/a&gt;
            &lt;a href=&quot;./linkedin&quot; title=&quot;LinkedIn&quot;&gt;
               &lt;img src=&quot;./images/icons/linkedin.png&quot; alt=&quot;Linkedin icon&quot; /&gt;
            &lt;/a&gt;
         &lt;/div&gt;
      &lt;/footer&gt;
   &lt;/body&gt;
&lt;/html&gt;
</pre><h3>Conclusion</h3><p>In this article, we&#8217;ve seen how to start building a website from scratch with a particular focus on the HTML code and its main elements. In the next article, I&#8217;ll introduce the first CSS rules in order to have a general idea of the graphic style that the homepage of our website will display. Once we pass this step, we&#8217;ll concentrate on the aspects and the procedures to be followed to convert our static homepage into a responsive homepage that will be viewed correctly on numerous different devices.</p> ]]></content:encoded> <wfw:commentRss>http://buildmobile.com/build-a-responsive-mobile-friendly-website-from-scratch-dive-into-the-code/feed/</wfw:commentRss> <slash:comments>5</slash:comments> <series:name><![CDATA[Build a Responsive, Mobile-Friendly Website From Scratch]]></series:name> </item> <item><title>Build a Responsive, Mobile-Friendly Website From Scratch: Design a Mockup</title><link>http://buildmobile.com/build-a-responsive-mobile-friendly-website-from-scratch-design-a-mockup/</link> <comments>http://buildmobile.com/build-a-responsive-mobile-friendly-website-from-scratch-design-a-mockup/#comments</comments> <pubDate>Tue, 09 Apr 2013 19:52:22 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5668</guid> <description><![CDATA[In the first article of this brand new series, I have introduced the main objectives of the series and given a short but complete introduction on the critical components of&#8230;]]></description> <content:encoded><![CDATA[<p>In the <a
title="Build a Responsive, Mobile-Friendly Website From Scratch: Introduction" href="http://buildmobile.com/building-a-responsive-website-introduction/">first article</a> of this brand new series, I have introduced the main objectives of the series and given a short but complete introduction on the critical components of media queries and responsive breakpoints. Now, it&#8217;s time to begin doing some practical work. As I have mentioned before, I’ll start with the planning and creation of a mockup for each of the three main device types on which our responsive website will be designed, tested, and displayed: PC desktops, tablets, and mobile phones.</p><h3>3&#8230;2&#8230;1&#8230; Let&#8217;s Start!</h3><p>Before continuing, I want to give you a little advice: remember that the more mockups you do, the more arduous and confusing your job will become. Responsive mockups are not the same as static mockups; you don’t really know where your content will be placed, because it depends on the screen size.</p><p>Obviously, as we&#8217;ve seen in the previous series, designing mockups for every screen size is nearly impossible, because there are potentially hundreds of screens, layouts, and orientations that you have to accommodate. This is why I suggest that you select your target screens/layouts and build the project mockups only for your top three main devices&#8217; categories.</p><p>For obvious reasons, I won&#8217;t show you how to design and build the entire website, but I&#8217;ll focus on the homepage, although I&#8217;m sure that once you have understood the logic and basis of responsive web design, you&#8217;ll be able to proceed with building the entire portal and everything will fall into place. I should reiterate that creating mockups doesn&#8217;t usually require that you lay out every single view to perfection, and that they are effective as soon as they&#8217;re enough of an abstraction of the final product (website or app) that they give you sufficient information to begin building.</p><p>I have chosen to build my project mockup using <a
title="Build a project mockup using Balsamiq" href="http://buildmobile.com/build-a-project-mockup-using-balsamiq/">Balsamiq Mockups</a>. As I have explained in detail in the linked article, Balsamiq Mockups is a tool that helps developers to create wireframes and communicate with clients and coworkers with visual representations of their design plans. Balsamiq is offline desktop software, and you can work with it using the operating system of your choice, since it runs on Mac, Windows, and Linux.</p><p>Let&#8217;s start planning the mockup of our website working on the PC desktop version.</p><p>First and foremost, let me introduce the kind of website we&#8217;re going to desogm and all of the elements that we&#8217;ll find within it. In fact, when building a web app or website, it&#8217;s a good practice to identify your content ahead of time and designate respective content areas within the website template. For our purposes, we&#8217;ll build a website with main content topics like graphics, web design and mobile development, a place where the design-addicted can read articles about their favourite fields, discuss, learn new techniques, and stay informed.</p><p>Let’s see how can we proceed using the elements of Balsamiq Mockups and focus on one target layout first. We have to work on the placement of blocks on the layouts, and as a first step, I place the browser window shape to represent the profile of any browser page and set its size using slight adjustments with the mouse.</p><p>As for the style of the main page, the first thing to determine is which elements we want to show on our brand new homepage. Generally, we might find a header, a newsletter bar, a menu-list, some sidebars (based on the extra-content you want to enter), a text box for the most important information, an image, or some links, for example.</p><p>Thanks to its simple, intuitive drag-and-drop system, we can easily add everything we want with a few clicks. For the first components of our page, we have to open the category called “Big.” Here, we’ll find the following elements elements: title/headline, the text area, and the image box. So, drag and drop each of these into your mockup.  Then, open the category &#8220;Common&#8221; to find rectangles, text areas, text input boxes, image and icons&#8217; indicators, and link pointers. Let&#8217;s place the two sidebars to the left of the author information box (where it could be nice adding a photo) under the main content box, which occupies the full window width.</p><p>At this point, our design concept should look something like this:</p><p><a
href="http://cdn.buildmobile.com/files/2013/04/pc-desktop-mockup1.png"><img
class="alignnone  wp-image-5672" alt="pc-desktop-mockup" src="http://cdn.buildmobile.com/files/2013/04/pc-desktop-mockup1.png" width="599" height="305" /></a></p><p>Once you’ve dragged and dropped the elements, you’ll see that each element has extensive editing options. When you click on the title/headline or within the text box, you’ll see a typical text editor, where you’ll be able to specify the characteristics or content. You can modify texts selecting size, text alignment, format, and color. You can also set the background color, set the border color, add a scrollbar, and play with opacity and focus.</p><p>For images, we can show or hide a border, crop the image, and hyperlink the chosen image to lead to a new URL or screen. Since this is a mockup project intended mainly to keep in mind all the page elements and their arrangement, is not necessary in my opinion to make ultra-precise stylistic changes. What is important is to have a sort of &#8220;skeleton,&#8221; or a point of departure to fix attention on what is necessary to build into the structure with the help of the HTML code and the CSS3 styling rules.</p><p>Once we&#8217;re done with this first passage, let&#8217;s continue planning our tablet version.</p><p><a
href="http://cdn.buildmobile.com/files/2013/04/tablet-mockup.png"><img
class="alignnone  wp-image-5673" alt="tablet-mockup" src="http://cdn.buildmobile.com/files/2013/04/tablet-mockup.png" width="599" height="305" /></a></p><p>As you can see in the image above, all the elements used in this second mockup are the same; the only thing that has changed is their arrangement. In the top part of the page, almost everything has the same style: the banner and the newsletter bar occupy all the window width on the PC desktop as well as the tablet version.</p><p>What <em>has</em> changed is the alignment of the menu-list items. In order to make the reading of menu items clear and easy even on a screen with a reduced size, I have planned to increase the space between all the present items. Additionally, the bottom part of the mockup introduces some slight changes: the sidebars that were placed on the left side of the author box have been moved under this and positioned next to each other in order to give them a larger width. Look below for clarity.</p><p><a
href="http://cdn.buildmobile.com/files/2013/04/smartphone-mockup.png"><img
class="alignnone  wp-image-5674" alt="smartphone-mockup" src="http://cdn.buildmobile.com/files/2013/04/smartphone-mockup-1024x521.png" width="600" height="305" /></a></p><p>As our last step in the mockup process, let&#8217;s tackle the smartphone version.  I have placed the iPhone shape (as said before, it’s the only one available to represent the profile of all modern smartphones) and duplicated it twice to allow you to view what the user would see by scrolling through the site from the top to the bottom.</p><p>As you can see, for the top part of the portal, the arrangement of the newsletter elements has changed, andthe menu-item list is also different compared to the PC desktop and tablet mockups. The input box and the submit button are presented vertically in order to make the process of writing and sending data faster and simpler. As for the menu, the best solution to adopt in this case (since the menu is composed of only five items) is to create a drop-down menu that the user can easily touch to load the page he desires to visit.</p><p>All the other components of the page are set to their max width to make the content intuitive and accessible. Even if at this stage you cannot see it, for the text view, you can think about a simple trick to make your users satisfied. Remember that, if your content is too long, they would have to scroll down the page many times to reach the end, and this could easily cause disorientation and boredom. So you could solve this &#8220;too much content&#8221; problem by placing a &#8220;Read more&#8221; link that takes the user directly to the information he demands and makes the homepage more streamlined, easier to load, and pleasant to visit, even on a narrow smartphone screen.</p><h3>Conclusion</h3><p>In this article, we&#8217;ve seen how to build a project mockup thinking responsively and—consequently—how a responsive design can adapt to three target layouts: Default (PC desktop), Portrait Tablet, and Smartphone. We&#8217;ve seen how to arrange the elements of a typical website in the three main devices&#8217; categories by creating a template that represents the common content elements. In the third part of this series, we&#8217;ll start to write the HTML code and work on the structure of the homepage and set the first CSS styling rules to build an initial design.</p> ]]></content:encoded> <wfw:commentRss>http://buildmobile.com/build-a-responsive-mobile-friendly-website-from-scratch-design-a-mockup/feed/</wfw:commentRss> <slash:comments>4</slash:comments> <series:name><![CDATA[Build a Responsive, Mobile-Friendly Website From Scratch]]></series:name> </item> <item><title>Build a Responsive, Mobile-Friendly Website From Scratch: Introduction</title><link>http://buildmobile.com/building-a-responsive-website-introduction/</link> <comments>http://buildmobile.com/building-a-responsive-website-introduction/#comments</comments> <pubDate>Mon, 25 Mar 2013 14:51:30 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[Responsive Design]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5635</guid> <description><![CDATA[In the last series (&#8220;Understanding Responsive Web Design&#8220;), I defined the basic features of this new and important responsive approach to mobile-friendly, device-agnostic design. Now, let&#8217;s set the stage for&#8230;]]></description> <content:encoded><![CDATA[<p>In the last series (&#8220;<a
title="Understanding Responsive Web Design" href="http://buildmobile.com/series/understanding-responsive-web-design/">Understanding Responsive Web Design</a>&#8220;), I defined the basic features of this new and important responsive approach to mobile-friendly, device-agnostic design. Now, let&#8217;s set the stage for a more concrete work.</p><p>We&#8217;ve seen that there are many aspects to take into consideration throughout the responsive design process: screen size, operating platform, user behavior, and so on. We have explored the various measurement options for fonts in a website, and we&#8217;ve covered the best way to approach <a
title="Responsive Web Design: Using Fonts Responsively" href="http://buildmobile.com/understanding-responsive-web-design-how-to-manage-fonts/">typography</a> in terms of responsive web design. We&#8217;ve explored the characteristics of four different <a
title="Responsive Web Design: Fluid Layouts" href="http://buildmobile.com/responsive-web-design-fluid-layouts/">layout types</a> and their respective fields of implementation. We&#8217;ve covered some common problems that a web designer may encounter when managing responsive <a
title="Understanding Responsive Web Design: Responsive Imagery" href="http://buildmobile.com/understanding-responsive-web-design-how-to-manage-images/">images</a> (and pointed out potential solutions). Finally, we&#8217;ve explored the problem of <a
title="Understanding Responsive Web Design: Cross-browser Compatibility" href="http://buildmobile.com/understanding-responsive-web-design-cross-browser-compatibility/">cross-browser compatibility</a> and proposed different ways to achieve it.</p><p>Now it&#8217;s time to demonstrate some <strong>real-world technical applications</strong> of the responsive web design and build a real responsive website.</p><h3>Objectives</h3><p>Let&#8217;s start with defining the objectives of this new series, and highlight what you&#8217;ll learn. Thanks to this tutorial&#8230;</p><ol><li>You&#8217;ll learn how to create a responsive design mockup, taking into account the main features of a website, the users&#8217; needs, and the way to effectively combine responsive graphics and web design. The mockup of the website won&#8217;t be unique to one platform, and it&#8217;ll provide an example of the possible structure of a portal from several standpoints—imagining the view on three different devices: smartphones, tablets, and desktop PCs.</li><li>You&#8217;ll learn how to take full advantage of modern web technologies, namely HTML5 and CSS3, applying them step-by-step to each component of your web content.</li><li>You&#8217;ll see how to implement some rules related to responsive web design, by applying what we have analyzed conceptually in prior articles.</li></ol><h3>Media Queries</h3><p>One of the foundations or responsive design is <strong>media queries</strong>, which ultimately make the site accessible and usable by the largest number of users, including those who do not use recent versions of popular browsers such as Internet Explorer, Mozilla Firefox, and Chrome.</p><p>Let&#8217;s start by getting our hands dirty with media queries; they represent one the most important tools that a web designer has to make their website responsive and mobile-friendly.</p><p>Media queries are composed of <strong>two main parts</strong>:</p><ul><li><strong>@ media screen</strong> — The first part of a media query is the type of support. You might recognize this syntax from writing your own CSS styles, especially if you used this method before when designing printing options for your website.</li><li>(<strong>min-width: 500px</strong>) — The second part is the query itself. It includes the function to be evaluated (in this case, the minimum width of the browser window) and the corresponding value to test that the rule has been applied (in this case, a value of 500px).</li></ul><p>Thinking about responsive web design, there is a tendency to focus exclusively on the width property, but there quite a few other attributes to consider when designing for a variety of screen sizes. There are many more valid properties associated with media queries. They are:</p><ol><li><strong>width / height</strong> — With these properties, you can set the width and height of the display area including any scroll bar. You can use the prefixes min and max.</li><li><strong>device-width/height</strong> — These properties set the width and the height of the rendering surface, that is, the width and height of the entire screen of the device and not simply of the display area of the document. Even in this case, you can still use the min and max prefixes.</li><li><strong>orientation</strong> — it sets a vertical or horizontal orientation. By specifying particular rules in the CSS stylesheet, you will be able to define how the various elements of a web page will be displayed on the device, in this case, depending on the orientation of the device we use. We can then specify the type of orientation; landscape and portrait that allow us to change the layout of your design according to the current orientation of the browser.</li><li><strong>aspect-ratio</strong> — This is a property that sets the ratio between the width and height of the display of a document. Even in this case, you can <em>still</em> use the min and max prefixes.</li><li><strong>device-aspect-ratio</strong> — This attribute monitors the ratio between the width and height of the device. Prefixes min and max are allowed.</li><li><strong>color</strong> — This applies certain CSS styles for all color devices. Prefixes min and max are allowed, but very few black and white devices (besides inexpensive Kindles) remain as popular browsing options</li><li><strong>color-index</strong> — This describes the number of colors in the palette supported by a device. It can have min and max prefixes.</li><li><strong>monochrome</strong> — This property indicates the number of bits per pixel of a monochrome device (grayscale).</li><li><strong>resolution —</strong> Resolution sets the resolution (i.e. the density of pixels) of the output device. The values ​​of the resolution can be expressed in DPI (dots per inch) or in DPCM (dots per centimeter).</li><li><strong>scan</strong> — a valid property for television screens that indicates the type of scan, interlaced or progressive. The values ​​can be precisely progressive or interlaced.</li><li><strong>grid</strong> — Grid indicates whether the device is a bitmap type or a &#8220;grid&#8221; equivalent.</li></ol><h3>Breakpoints</h3><p>After this short overview of the main (and often underutilized) properties of media queries, let&#8217;s proceed by pointing out what are the best responsive <strong>breakpoints</strong> and how to determine them for a given project.</p><p>Breakpoints in terms of responsive web design are browser widths that have a media query declaration to change the layout once the browser is within a declared width range. More specifically, a breakpoint is a point on a line that starts from 0, where there is a change (via CSS) within the layout of the page. Breakpoints are defined with numeric values ​​and units of measurement based on the media queries entered into your CSS stylesheets.</p><p>In general, every responsive website has a minimum of two breakpoints — one for tablets and one for mobile devices. Each breakpoint corresponds to a media query. In the media query below, I wrote CSS that only takes effect when the minimum width of the browser window (min-width) is equal to a specific value (that can be 320px, 480px, 768px, etc..).</p><p>Here is an example of one of these standard breakpoints:</p><pre class="brush: css; title: ; notranslate">@media only screen and (min-width : 320px) {
/* Styles */
}</pre><p>But, <strong>how many breakpoints does a web designer need to create?</strong> This depends on the characteristics of the website, on its layout, and on the techniques that you decided to implement in order to turn your design plans into something truly interactive and responsive In essence, we could answer the previous question in this way: <span
style="text-decoration: underline;">You need a breakpoint for every device that you deliberately choose to support.</span></p><h4>Breakpoints According to the Devices</h4><p>Today, the prevailing practice tends to set breakpoints based on the size of the screen (or browser window) of the following popular device types:</p><ul><li>Smartphone (with portrait or landscape orientation)</li><li>Tablet (with portrait or landscape orientation as well)</li><li>Netbook</li><li>Desktop PC monitor with high or very high resolution</li></ul><p>Translating this scheme into pixels, you can see how for smartphone and tablet categories, the &#8220;standard&#8221; sizes adopted mainly correspond to the screen dimensions of the iPhone and iPad:</p><ul><li>320px — iPhone in portrait orientation</li><li>480px — iPhone in landscape orientation</li><li>768px — iPad in portrait orientation</li><li>1024px — iPad in landscape orientation (as well as netbooks, since these devices typically have a horizontal resolution of 1024px).</li></ul><p>Someone might argue that not all smartphones and tablets are iPhones or iPads, and they&#8217;d be unquestionably correct. But, in this case the screen size of the Apple device is used more as a reference point for a greater category of devices. Moreover, creating a breakpoint for each and every device would be totally absurd.</p><p>A good practice could be defining a set of main breakpoints possibly combined with some secondary breakpoints in order to fit the document to specific devices. You could also think about creating a custom breakpoint; this is very straightforward but requires a familiarity with media queries, so I suggest practicing initially with basic media queries and common breakpoints.</p><p>It&#8217;s extremely important to test your dynamic layouts, including the breakpoints themselves, and the CSS that executes under certain screen size conditions. If you do not have both of those aspects of your responsive design in good order, you&#8217;ll end up with glaring layout and functionality problems that make your website less responsive than if you hadn&#8217;t attempted any mobile-friendly accommodations. Test your designs thoroughly!</p><h3>Conclusion</h3><p>I have introduced the main objectives of the series, and above all, I have given a short but complete introduction on the critical components of media queries and responsive breakpoints. In the next article, I&#8217;ll start with the planning and the creation of a mockup for each of the three main device types on which our website will be designed, tested, and displayed.</p><p><em>Want to learn more about Responsive Web Design? Check out SitePoint&#8217;s new book, <a
href="http://www.sitepoint.com/books/responsive1/" target="_blank">Jump Start Responsive Web Design</a>!</em></p> ]]></content:encoded> <wfw:commentRss>http://buildmobile.com/building-a-responsive-website-introduction/feed/</wfw:commentRss> <slash:comments>7</slash:comments> <series:name><![CDATA[Build a Responsive, Mobile-Friendly Website From Scratch]]></series:name> </item> <item><title>Why Mobile Apps Need Privacy Policies (and How To Get Yours Right)</title><link>http://buildmobile.com/why-mobile-apps-need-privacy-policies-and-how-to-get-yours-right/</link> <comments>http://buildmobile.com/why-mobile-apps-need-privacy-policies-and-how-to-get-yours-right/#comments</comments> <pubDate>Tue, 19 Mar 2013 14:40:41 +0000</pubDate> <dc:creator>Veronica Picciafuoco</dc:creator> <category><![CDATA[Android]]></category> <category><![CDATA[iOS]]></category> <category><![CDATA[Windows Phone]]></category> <category><![CDATA[business]]></category> <category><![CDATA[Discussion]]></category> <category><![CDATA[legal]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5627</guid> <description><![CDATA[Privacy Policies and other legal documentation are occasionally viewed as an afterthought of the mobile development process—something to be hastily included after all of the conceptual design and development work&#8230;]]></description> <content:encoded><![CDATA[<p>Privacy Policies and other legal documentation are occasionally viewed as an afterthought of the mobile development process—something to be hastily included after all of the conceptual design and development work is complete. This legal safeguarding may seem like a last-minute addition that doesn&#8217;t merit much thought, but it may be the most important component of your entire business.</p><p>Privacy Policies are <em>not</em> all alike, and there are numerous ways that a missing clause or a mismatch between your legal documents and your app itself can cause catastrophic problems. Quite a few ubiquitous and successful mobile apps have run into massive legal headaches and astronomical fines due to flaws in their privacy policy and a failure to integrate and unify their legal protection with the &#8220;private parts&#8221; of their app architecture.</p><p>Only a few weeks ago, social app <a
href="https://path.com/" target="_blank">Path</a> was fined nearly 1 million dollars by the FTC (Federal Trade Commission) <a
href="http://business.ftc.gov/blog/2013/01/ftc-path-case-helps-app-developers-stay-right-er-path" target="_blank">for privacy violations</a>. The $800,000 penalty stemmed from two lethal mistakes made by the app:</p><ol><li>storing third-party names and numbers from their users&#8217; address books, without proper disclosure;</li><li>failing to comply with the provisions of <a
href="http://www.ftc.gov/privacy/coppafaqs.shtm" target="_blank">COPPA</a>, a law that applies to every app that <span
style="text-decoration: underline;">knowingly</span> collects information from children.</li></ol><p>This means that if you extract phone contacts from your users, not only must you notify them, you must also explain within the app&#8217;s privacy policy how any why the information is used. If you collect users&#8217; birth dates, you can likely figure out if children are using your app and do something about it. You essentially have two legal avenues: comply with COPPA or make sure users represent that they&#8217;re over 13.</p><p>But there&#8217;s more. The FTC published <a
href="http://www.ftc.gov/os/2013/02/130201mobileprivacyreport.pdf" target="_blank">a long document with recommendations for app developers</a> and even platform-specific advisement for big platforms like Android and iOS.</p><h3>Privacy by Design</h3><p>The FTC wants app developers to use a (relatively) new approach called &#8220;Privacy by Design.&#8221;  &#8220;Companies should build in privacy at every stage in developing their products.&#8221; This means a number of things:</p><ul><li>before building an app or a feature, think of the privacy implications;</li><li>if you collect information, protect it. Follow the <a
href="http://business.ftc.gov/documents/bus83-mobile-app-developers-start-security" target="_blank">security recommendations of the FTC</a> (with special attention to the third-party software you used) and be careful not to overpromise or make <a
href="http://www.wac6.com/wac6/2010/08/boilerplate-bites-twitter.html" target="_blank">generic reassuring statements</a>;</li><li>keep your policy updated! Every time you roll out a new update to the app store, stop for a second and think if you added something that has an impact on your privacy statements. Added a new analytic script? It should go in there. Added &#8220;find friends via Facebook&#8221;? Go and edit your privacy policy.</li></ul><h3>What Does It Mean for App Developers?</h3><p>There are <a
href="http://www.startuppercolator.com/privacy-by-design-01-10-2013/" target="_blank">known best practices</a>—some of them coming from the <a
href="http://www.cwclaw.com/publications/alertDetail.aspx?id=684" target="_blank">California Attorney General</a>—to give you some legal protection and prevent problems, privacy breaches, and lawsuits. But this is what the FTC actually says that developers should do.</p><h4>You should have a privacy policy and it must be accessible from the app store.</h4><p>The simple way to accomplish this is to simply link the policy when you submit the app. But, this means the privacy policy should live on your website. You could also provide the full text of the policy within the app, or a short statement describing the app’s privacy practices. Need a privacy policy from scratch? There are many options: <a
href="https://www.docracy.com/6016/mobile-privacy-policy" target="_blank">Docracy&#8217;s open source standard</a>, a <a
href="http://privacychoice.org/policymaker" target="_blank">privacy policy generator</a>, and many other free resources you can find on Google.</p><h4>You should provide &#8220;just-in-time disclosures&#8221; and obtain affirmative express consent when collecting sensitive information from outside the platform’s API.</h4><p>You already know that iOS pops up a notification that a certain app is requesting access to the user&#8217;s location or other private data. In this case, the disclosure and the consent are taken care by Apple. But, your app might as well collect other important stuff, and a pop-up notification is the best way to make sure the users know. FTC names financial, health, or children’s data, but also a generic &#8220;sharing sensitive data with third parties&#8221; as sensitive private information, so it&#8217;s best to err on the side of caution.</p><h4>Know the legal implications of the code you&#8217;re using.</h4><p>It&#8217;s normal for app developers to use third-party packages, SDK, and the like. You should make sure this code is secure and fully understand exactly what information it pulls, because you&#8217;re ultimately legally responsible for it. There&#8217;s <a
href="http://business.ftc.gov/documents/bus83-mobile-app-developers-start-security" target="_blank">a long list of questions to ask yourself</a>, including:</p><ul><li>Does this library or SDK have known security vulnerabilities?</li><li>Has it been tested in real-world settings?</li><li>Have other developers reported problems?</li></ul><h3>Conclusion</h3><p>Path was fined $800,000. While this is was in connection with COPPA violations, it&#8217;s the start of <a
href="http://www.wac6.com/wac6/2013/02/why-paths-ftc-settlement-differs-from-twitters-or-facebooks.html" target="_blank">broader policing of privacy practices</a>, even against non-American developers. If you cater to the American mobile market, you can still be fined by U.S. Authorities. It&#8217;s time for app developers to lawyer up and get a properly-written, constantly-curated privacy policy. The FTC is encouraging the adoption of public standards and suggests tightened integration among app developers, trade associations, ad networks, and mobile platforms, so this is definitely a topic to keep under the radar. You wouldn&#8217;t want a legal problem to cripple your app right as it&#8217;s starting to soar.</p> ]]></content:encoded> <wfw:commentRss>http://buildmobile.com/why-mobile-apps-need-privacy-policies-and-how-to-get-yours-right/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Understanding Responsive Web Design: Cross-browser Compatibility</title><link>http://buildmobile.com/understanding-responsive-web-design-cross-browser-compatibility/</link> <comments>http://buildmobile.com/understanding-responsive-web-design-cross-browser-compatibility/#comments</comments> <pubDate>Wed, 13 Mar 2013 13:06:22 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile Web Development]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5594</guid> <description><![CDATA[In the last article, I described three ways to work with with images from a responsive design standpoint, discussing the best solution to adopt while serving properly-sized imagery to a&#8230;]]></description> <content:encoded><![CDATA[<p>In the <a
title="Understanding Responsive Web Design: Responsive Imagery" href="http://buildmobile.com/understanding-responsive-web-design-how-to-manage-images/">last article</a>, I described three ways to work with with images from a responsive design standpoint, discussing the best solution to adopt while serving properly-sized imagery to a variety of screen sizes. In today&#8217;s article, I&#8217;ll focus on imagery management from another point of view, that is <strong>cross-browser compatibility</strong>.</p><p>During the creation of a website — especially if your aim to make its structure responsive — one of the most important and frequent problems that a web designer has to face involves cross-browser compatibility, that is, compatibility across different browsers.</p><p>What does &#8220;compatibility&#8221; stands for? The designer of a website must ensure that their design works properly and that its appearance is error-free and functional on any platform used to view it. It &#8216;s definitely one of the most complicated and frustrating aspects you must consider when designing a new project, but it&#8217;s essential that the you do not leave anything to chance and keep cross-browser compatibility in mind throughout the design process.</p><p>Many of the new CSS capabilities introduced in the new CSS3 version are still not widely supported by all major browsers. In fact, some are not recognized and therefore ignored completely, which can pose major problems if your design relied on unsupported CSS. It&#8217;s not just a variety of browser types either; different <em>versions</em> of the same browser can support (or fail to support) various design techniques, which complicates cross-browser compatibility even further.</p><p>Let&#8217;s get back to image management, which probably is the weak point of the RWD approach, especially for browser compatibility issues. Photos and media need to be flexible and adapt to different devices, and at the same time, it&#8217;s crucial that they don&#8217;t slow down page loading in the process. Therefore, there is still no definitive, ideal solution to problems such as different screen sizes, restricted bandwidth (in cases of mobile browsing), performance on high-resolution (&#8220;retina&#8221;) displays, and so on.</p><p>It is clear that using a single image (the largest possible version) for all devices is not an advisable solution. Think about the time a poor smartphone-2G user would take to load your design. After your ultra-slow image loads, those high-resolution images will probably display at about one quarter of their original size.</p><p>The largest problem is that media queries do not work with older browsers. Consequently, a responsive web page with many CSS3 rules applied can be seen correctly only by those who have recently-updated browsers with strong CSS3 support. Fortunately, there are three JavaScript solutions that can help us serve responsive websites to older browsers lacking CSS3 support: <strong>Respond.js</strong>, <strong>Modernizr</strong>, and <strong>adaptive.960.js</strong>. Let&#8217;s have a look together.</p><h3>Respond.js</h3><p>The first solution is also the simplest one — I&#8217;m talking about a script called respond.js, which enables the older browser versions to understand and execute CSS3 media queries. Here&#8217;s all it takes to get started.</p><pre class="brush: jscript; title: ; notranslate">&lt;script type=&quot;text/javascript&quot; src=&quot;js/respond.min.js&quot;&gt;&lt;/script&gt;</pre><p>This script is called on the page (as shown above) and adds support to media queries, min-width, max-width, and all media types (e.g. screen) for older browsers. This script can help your CSS3 instructions work properly, even for older browsers.</p><p>Respond.js may seem like it&#8217;s too easy to be an ideal solution, but for many projects this is an great solution because the code is read from the latest CSS3 PC browser and all browser designed for smartphones. The sole purpose of the script is to make older browsers read the CSS3 instructions within media queries. Nothing more, nothing less.</p><h3>Modernizr</h3><p>The second solution is the use of a tool called Modernizr. As explained in <a
href="http://modernizr.com/docs/" target="_blank">the documentation page of its website</a>, &#8220;Modernizr is a small JavaScript library that detects the availability of native implementations for next-generation web technologies, i.e. features that stem from the HTML5 and CSS3 specifications.&#8221;</p><p>Many of these features are already implemented in at least one major browser (most of them in two or more), and what Modernizr does is—very simply—tells you whether the current browser has this feature natively implemented or not. This is an indispensable tool that gives you fine control over the experience through JavaScript-driven feature detection.</p><p>After the first phase of detecting features, Modernizr creates a JavaScript object with the results and adds classes to the HTML element for you to target with your CSS. It&#8217;s a gorgeous solution, because it makes it easy for you to write conditional JavaScript and CSS to handle each situation, whether a browser supports a feature or not.</p><p>Modernizr supports these browsers: IE6+, Firefox 3.5+, Opera 9.6+, Safari 2+, Chrome, Mobile Safari, Android WebKit browser, Opera Mobile, and Firefox Mobile.</p><p>You can <a
href="http://modernizr.com/" target="_blank">download the full version</a> of the library and implement it according to your specifications. However, if you only needs to test the compatibility of CSS3 in your browser, you can set the various options offered by the library and create your own compressed code. Paste the code into an external .js file and include it at the tag of your HTML document. The Modernizr team recommend to include the library just after importing CSS.</p><p>You should have this code:</p><pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
 &lt;head&gt;
  &lt;title&gt;Your title&lt;/title&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;modernizr-latest.js&quot;&quot;&gt;&lt;/script&gt;
 &lt;/head&gt;
 &lt;body&gt;Your content&lt;/body&gt;
&lt;/html&gt;
</pre><p>Now you have a JavaScript library that indicates you whether the CSS3 or HTML5 functions you used are supported or not. Let the page run on the browser and look at the code with Chrome developer tools or Firebug.</p><p>You should see something like this:</p><pre class="brush: xml; title: ; notranslate">&lt;html class=&quot;js flexbox canvas canvastext webgl no-touch geolocation postmessage websqldatabase no-indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage no-borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio no-localstorage no-sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths&quot;&gt;
....
&lt;/html&gt;</pre><h3>adapt.960.js</h3><p>The third solution that we consider is very different from the previous two, especially because it does not make use of CSS3 and accordingly of media queries. However, the concept is very similar to the CSS3 media queries.</p><p>If we use CSS3 in a single file, this library requires us to separate the code into several CSS files, one for each device type. The library parses the resolution of the device and calls the CSS designed for that specific screen resolution.</p><p>We can <a
href="http://adapt.960.gs/" target="_blank">download the script</a> and see immediately how it works. Activate the library on your page with the following line:</p><pre class="brush: jscript; title: ; notranslate">&lt;script type=&quot;text/javascript&quot; src=&quot;js/adapt.min.js&quot;&gt;&lt;/script&gt;</pre><p>Then, copy the following code:</p><pre class="brush: jscript; title: ; notranslate">&lt;script type=&quot;text/javascript&quot;&gt;
var ADAPT_CONFIG = {
 // Where is your CSS?
 path: 'assets/css/',
 dynamic: true,
 callback: myCallback,
 range: [
   '0px    to 760px  = mobile.css',
   '760px  to 980px  = 720.css',
   '980px  to 1280px = 960.css',
   '1280px to 1600px = 1200.css',
   '1600px to 1920px = 1560.css',
   '1940px to 2540px = 1920.css',
   '2540px           = 2520.css'
 ]
};
&lt;/script&gt;
</pre><p>We see the list of CSS files within the &#8220;range,&#8221; one for each group of resolutions. Each of these files contains CSS properties related only to a specific device, just as the code enclosed within the CSS media queries.</p><p>The common CSS—that is the CSS that should apply to all screen sizes—should be included in a different CSS file, which for convenience we can call <em>master.css</em> and retrieve it before the integration of this library, just like normal CSS file:</p><pre class="brush: css; title: ; notranslate">&lt;link href=&quot;assets/master.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;</pre><h3>Conclusion</h3><p><strong>Which of the three solutions should we adopt?</strong> They are all valid, sensible approaches. If you choose to apply the first solution (respond.js), you&#8217;ll have to write and manage a single CSS file, unlike adapt.960.js, which requires multiple CSS files. Finally, if you choose to try Modernizr, you&#8217;ll take advantage of new CSS3 capabilities in the browsers that can support them and still have easy and reliable means of controlling the situation for the browsers that cannot.</p><p>If you believe that, within few years, older browsers will be irrelevant and that mobile browsers will supersede their desktop counterparts, I believe that it is better to work with media queries and extend support for older browsers with JavaScripts plugins that are available.</p><p>Remember that there are also web-based services to test a responsive website and simulate resizing of the browser window. Two of these are <a
title="responsive.is" href="http://responsive.is/typecast.com">responsive.is</a>, which is very easy to use, and <a
title="www.studiopress.com" href="http://www.studiopress.com/responsive/">studiopress.com</a>, which, after entering the web address, makes different views of your website appear side-by-side.</p><p>In addition to web-based solutions, there are also applications that can be installed directly on your personal computer. Among them, we find <a
title="Opera Mobile Emulator" href="http://www.opera.com/it/developer/mobile-emulator">Opera Mobile Emulator</a>, which is available for Mac, Linux, and Windows. After installing and opening the application, you&#8217;ll have a list of devices that it can emulate (with the unfortunate exception of Apple devices).</p><p>To conclude this article, I&#8217;d like to share a very useful online tool to test the compatibility of your live website: <a
title="crossbrowsertesting.com" href="http://crossbrowsertesting.com/">crossbrowsertesting.com</a>. You must choose an operating system and a web browser, and that&#8217;s all. A series of well-organized screenshots on multiple browsers will allow you to have a complete view of your site, and in this way, it will be easier to understand on which elements you should modify to make your project perfectly compatible with any platform.</p><p><em>Want to learn more about Responsive Web Design? Check out SitePoint&#8217;s new book, <a
href="http://www.sitepoint.com/books/responsive1/" target="_blank">Jump Start Responsive Web Design</a>!</em></p> ]]></content:encoded> <wfw:commentRss>http://buildmobile.com/understanding-responsive-web-design-cross-browser-compatibility/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <series:name><![CDATA[Understanding Responsive Web Design]]></series:name> </item> <item><title>Build Multilingual Android Apps Using Custom Localization</title><link>http://buildmobile.com/build-a-multilingual-survey-app-in-android-os/</link> <comments>http://buildmobile.com/build-a-multilingual-survey-app-in-android-os/#comments</comments> <pubDate>Tue, 12 Mar 2013 22:23:46 +0000</pubDate> <dc:creator>Christa Joe</dc:creator> <category><![CDATA[Android]]></category> <category><![CDATA[Android Discussion]]></category> <category><![CDATA[Android Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5608</guid> <description><![CDATA[In today’s tech-savvy world, companies are craving actionable feedback from their customers, typically in the form of surveys and other customer feedback mechanisms. This has become a common, efficient practice&#8230;]]></description> <content:encoded><![CDATA[<p>In today’s tech-savvy world, companies are craving actionable feedback from their customers, typically in the form of surveys and other customer feedback mechanisms. This has become a common, efficient practice that provides organized data for the company and an easy, straightforward process for the customers themselves. Just a single click saves the data to the common server and eliminates the hassle of paper-based survey forms. Multilingual survey apps are even more useful and powerful, as they help surveyors gather region-specific data and conduct international surveys from a single system.</p><p>The concept of Custom Localization in Android SDK plays a major role in providing strong support for multilingual interactivity. Custom Localization means that the user should be able to change the app language using the app settings without having to change the language of the entire mobile device. One of the limitations is that the multilingual support for Indian languages is not a part of the Android SDK, which poses a major challenge for developers performing custom localization on Android OS.</p><p>Using the Android SDK platform, the concept of localization can be easily handled, but the major challenge is the insufficient support of localization for Indian native languages. For any foreign language, the device locale can be set to the language name. For example, users from France can change the language of their device to French, and all of the written content will be converted to the French language. One of the advantages of the following survey-based application is that it supports the regional languages of India, such as Tamil, Marathi, Hindi, and many more.</p><h3>Description</h3><p>Android SDK provides an API function that allows the usage of external fonts. These fonts allow rendering of characters and symbols used by different languages. To use this approach, each and every component is initialized in an activity class, and its font type is set to ensure that the correct font is rendered. This approach solves the problem of regional language support, but it cannot be considered a perfect solution, as it creates large amounts of unnecessary objects and references in the activity class.</p><p>The following points should be noted to develop a multilingual support application:</p><p>The Android SDK provides a resource type to create custom attributes for views. A custom attribute can be created as a &#8220;langtext.” Please refer to the following code snippet for clarity:</p><pre class="brush: xml; title: ; notranslate">
&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?--&gt;
</pre><p>In the strings.xml file, the string values were created in a key-value pair manner. Below is a demonstration.</p><pre class="brush: xml; title: ; notranslate">&lt;/pre&gt;
error
Error // text in english
गलती //text in hindi
తప్పు //text in telugu
&lt;pre&gt;</pre><p>These strings are created in such a way that by adding the language type (e.g: en, hi, tu) in the value of key_&lt;somevalue&gt;, it will return the actual string value in the selected language.</p><p>A custom view can be created, which extends the TextView class of Android. In this class, override the setTypeface. Using this method, set the required font file to the textview. Please refer to the following code snippet:</p><pre class="brush: java; title: ; notranslate">
package com.wb.mobile.android.ot.ui.customviews;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
import com.sample.mobile.android.ot.R;
import com.sample.mobile.android.ot.ui.activities.SplashScreen;
import com.sample.mobile.android.ot.utils.Constants;
import com.sample.mobile.android.ot.utils.Helper;
/**
 * Custom implementation of textview for supporting multiple languages.
 *
 * @author magarwal
 *
 */
public class MultiLingualTextView extends TextView {
	private String mLangText;
	public String getLangText() {
		return mLangText;
	}
	public MultiLingualTextView(Context context) {
		super(context);
	}
	public MultiLingualTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		TypedArray typedArray = context.obtainStyledAttributes(attrs,
				R.styleable.CustomTextView, 0, 0);
		String lang = SplashScreen.getUserSettings().getString(
				Constants.LANG_CONSTANST_STR, Constants.LANG_CONSTANST_EN);
		String langText = typedArray
				.getString(R.styleable.CustomTextView_langText);
		mLangText = langText;
		if (Helper.checkString(langText)) {
			this.setText(Helper.getStringResource(getContext(), lang + &quot;_&quot;
					+ langText, &quot;string&quot;));
		}
	}
	public MultiLingualTextView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
	}
	@Override
	public void setTypeface(Typeface tf) {
		String lang = SplashScreen.getUserSettings().getString(
				Constants.LANG_CONSTANST_STR, Constants.LANG_CONSTANST_EN);
		if (lang.equalsIgnoreCase(Constants.LANG_CONSTANST_EN)) {
			super.setTypeface(tf);
		} else {
			super.setTypeface(Helper.getTypeface(getContext()));
		}
	}
	@Override
	public void setTypeface(Typeface tf, int style) {
		String lang = SplashScreen.getUserSettings().getString(
				Constants.LANG_CONSTANST_STR, Constants.LANG_CONSTANST_EN);
		if (lang.equalsIgnoreCase(Constants.LANG_CONSTANST_EN)) {
			super.setTypeface(tf);
		} else {
			super.setTypeface(Helper.getTypeface(getContext()));
		}
	}
	public void setLangText(String langText) {
		mLangText = langText;
		String lang = SplashScreen.getUserSettings().getString(
				Constants.LANG_CONSTANST_STR, Constants.LANG_CONSTANST_EN);
		if (Helper.checkString(langText)) {
			this.setText(Helper.getStringResource(getContext(), lang + &quot;_&quot;
					+ langText, &quot;string&quot;));
		}
	}
}
</pre><p>Now we need to consider the function that retrieves the value of a string resource, which is demonstrated in the following code snippet:</p><pre class="brush: java; title: ; notranslate">
/**
* get the translated string value associated with a key.
*
* @param context
*            -- activity reference for accessing API's
* @param name
*            -- key for which string is needed.
* @param type
*            -- &quot;string&quot; as in R.string.sth
* @return -- translated value.
*/
public static String getStringResource(Context context, String name,
String type) {
try {
int id = context.getResources().getIdentifier(name, type,
context.getPackageName());
return context.getResources().getString(id);
} catch (Exception e) {
Helper.printStackTrace(e);
return name;
}
}
</pre><p>Applied to the Android OS, this code will render text content in the user&#8217;s language of choice, even if that language is one of the unsupported Indian languages. Our custom code makes for multilingual interactivity that could be used anywhere in the world.</p><p><img
class="aligncenter size-full wp-image-5611" alt="aalang" src="http://cdn.buildmobile.com/files/2013/03/aalang.png" width="207" height="303" /><br
/> <img
class="aligncenter size-full wp-image-5612" alt="aalang2" src="http://cdn.buildmobile.com/files/2013/03/aalang2.png" width="207" height="303" /></p><p><img
class="aligncenter size-full wp-image-5613" alt="aalang3" src="http://cdn.buildmobile.com/files/2013/03/aalang3.png" width="207" height="303" /></p><h3>Conclusion</h3><p>If you&#8217;re not catering to users beyond your own nation&#8217;s borders, you&#8217;re likely missing out on huge opportunities. If you&#8217;re intimidated by making your app multilingual, hopefully this demonstration shows Android&#8217;s multilingual capabilities, as well as custom coding that can accommodate even the unsupported languages. If you&#8217;re looking for more users, a bigger audience, or entry into international marketplaces, you&#8217;d be crazy not to build multilingual support into your Android app.</p> ]]></content:encoded> <wfw:commentRss>http://buildmobile.com/build-a-multilingual-survey-app-in-android-os/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Build a Contacts Management App Using HTML5, JS, CSS3, and Wakanda Studio</title><link>http://buildmobile.com/build-contacts-app-with-html5-css-javascript-wakanda-studio/</link> <comments>http://buildmobile.com/build-contacts-app-with-html5-css-javascript-wakanda-studio/#comments</comments> <pubDate>Thu, 07 Mar 2013 18:32:09 +0000</pubDate> <dc:creator>Saad Mousliki</dc:creator> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Discussion]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Mobile Tools]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5571</guid> <description><![CDATA[Many years ago, JavaScript developers were considered second-class citizens in the programming world. JavaScript was only used to perform some easy client-side tasks such as alert messages, form validation, and&#8230;]]></description> <content:encoded><![CDATA[<p>Many years ago, JavaScript developers were considered second-class citizens in the programming world. JavaScript was only used to perform some easy client-side tasks such as alert messages, form validation, and style manipulation. Nobody was convinced to use it for intensive programming applications due to its limitations and several serious security problems.</p><p>But, in the past few years with the arrival of HTML5, JQuery, NodeJS, WebRTC, Google API, and others, JavaScript has become a mature language for developing a robust business applications via server-side coding, NoSQL Databases, JSON format, REST for communication and many other worthy methods.</p><p>In this article, we will prove how possible (and even <em>easy</em>) it is to develop a mobile web application that retrieves the phone contacts on disconnected mode and retrieves contacts from a remote server in connected mode using HTML5, JavaScript, and CSS3. We&#8217;ll package it using PhoneGap to build to a native mobile app that will work online and offline.</p><h3>Background</h3><p>Before starting using this guide, you should have some basics on HTML5, JavaScript, and the mobile development world. In this article, I&#8217;ll also use the <a
href="http://doc.wakanda.org/Datastore/Datastore.100-588923.en.html" target="_blank">Wakanda DataStore</a> as a NoSQL database that will be remotely added by our native app to get data using REST/HTTP and JSON format, so having some basics on Wakanda could be very helpful.</p><h3>Using The Code</h3><p><strong>Application Architecture</strong></p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5572" alt="application-architecture" src="http://cdn.buildmobile.com/files/2013/03/application-architecture.png" width="542" height="230" /></p><p>The PhoneGap build input for this mobile application is freely available for download. It&#8217;s a zip file developed using the Wakanda Studio smartphone part. The bundle contains numerous noteworthy files.</p><p>First and most importantly, it contains the index.html file, which is the main page of our application. This page has three views: one for the homepage that contains two buttons to choose between connected or disconnected mode, a view containing a grid that will load data from the remote Wakanda Server, and a third view that contains a richText widget, which will load the list of mobile contacts using the PhoneGap contact API.</p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5573" alt="phonegap-build-input" src="http://cdn.buildmobile.com/files/2013/03/phonegap-build-input-533x1024.png" width="320" height="614" /></p><p
style="text-align: left;">The second file worth mentioning is the config.xml file. This XML file provides some necessary settings to the PhoneGap build service. which to package the app and prepare it for mobile devices. Below is the config.xml data.</p><pre class="brush: xml; title: ; notranslate">
&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?--&gt;
    GET CONTACTS
        An application that gets contacts from DataStore and also from phone
        Saad Mousliki
</pre><p>(You could take a look to <a
href="https://build.phonegap.com/docs/config-xml" target="_blank">the official PhoneGap documentation</a> to learn more about how to write this file.)<br
/> Two additional noteworthy files are splash.png and icon.png. These two files serve as the splash screen and the icon that will be displayed when installing the packaged app on your mobile device.</p><p>Next is the walib folder, which contains the WAF (Wakanda Application Framework) API—a set of JavaScript libraries used to manipulate UI, HTTP/REST communication, mapping, etc.</p><p>And, of course, the widely-used scripts and styles folders, which contain the JavaScript and CSS files used by the mobile app.</p><p>(Note: To learn more about how to create this application using Wakanda Studio and pre-package it to be accepted by PhoneGap, take a look to <a
href="http://doc.wakanda.org/Quick-Start/Quick-Start.100-695763.en.html" target="_blank">this guide</a> and <a
href="http://hackanda.wordpress.com/" target="_blank">this blog</a>.)</p><h3>The HTML5 Interface</h3><p>The HTML5 page is generated using the Wakanda Studio GUI Designer with the dragging and dropping of widgets and careful styling using the properties tabs. Below is an example of a Wakanda HTML5 interface in progress; lets go through the surprisingly-easy process of designing the interface for our mobile app.</p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5574" alt="properties-tab" src="http://cdn.buildmobile.com/files/2013/03/properties-tab.png" width="598" height="307" /></p><h4>Step 1</h4><p>After installing the Wakanda Studio version 3, open the studio by double clicking its icon. Click on the &#8220;Create New Solution&#8221; button.</p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5575" alt="solution-button" src="http://cdn.buildmobile.com/files/2013/03/solution-button.png" width="598" height="249" /></p><h4 style="text-align: left;">Step 2</h4><p
style="text-align: left;">Give a name to your solution e.g. “CreateHTML5Page.” Check the “Add a blank project to the solution” checkbox and click the &#8220;OK&#8221; button.</p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5576" alt="ok-button" src="http://cdn.buildmobile.com/files/2013/03/ok-button.png" width="473" height="376" /></p><h3>Step 3</h3><p>Now, click on the “WebFolder” folder and double-click on the index.html file.</p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5577" alt="index-file" src="http://cdn.buildmobile.com/files/2013/03/index-file.png" width="315" height="431" /></p><h3>Step 4</h3><p>Go to the right side of the studio; you will find an arrow to choose between platforms: desktop, tablet, or smartphone. Choose the smartphone page.</p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5578" alt="smartphone-page" src="http://cdn.buildmobile.com/files/2013/03/smartphone-page.png" width="599" height="325" /></p><h4>Step 5</h4><p>At this step, the page is empty and should be designed using the widget tab on the left and the properties tab on the right. First, we will add a navigation widget to the page by dragging and dropping the desired widget onto the page.</p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5579" alt="widget" src="http://cdn.buildmobile.com/files/2013/03/widget.png" width="598" height="521" /></p><h4>Step 6</h4><p>After that, we must add some views (navigation options) to the navigation views widget using the properties tab of this widget.</p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5580" alt="widget-tab" src="http://cdn.buildmobile.com/files/2013/03/widget-tab.png" width="501" height="461" /></p><h4>Step 7</h4><p>Now, we will add a pair of buttons to the first view.</p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5581" alt="first-view" src="http://cdn.buildmobile.com/files/2013/03/first-view.png" width="599" height="369" /></p><p>You could modify the button titles and other properties (width, height, color, etc.) using the properties tab on the right side.</p><h4 style="text-align: left;">Step 8</h4><p
style="text-align: left;">To specify an event to the button, we should click on the events button on the right side tab and choose the “onClick” event.</p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5582" alt="onclick" src="http://cdn.buildmobile.com/files/2013/03/onclick.png" width="599" height="369" /></p><h4>Step 9</h4><p>For example, we could add code that allows switching between views. We will use the navigation view method “goToNextView”, so when we click on this button we will go to the View number 2. Look below for clarity.</p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5583" alt="view2" src="http://cdn.buildmobile.com/files/2013/03/view2.png" width="587" height="331" /></p><pre class="brush: jscript; title: ; notranslate">
button1.click = function button1_click (event)
{
$$(&quot;navigationView3&quot;).goToNextView();
}
</pre><p>(Note: To learn more on how to create a mobile web app using Wakanda Studio, take a look to <a
href="http://www.youtube.com/watch?v=GZKWZbWF7g4">this video</a> for a step-by-step description of how to create and test mobile apps on an iPod.)</p><p>After creating a page, we should pre-package (prepare it to be packaged by PhoneGap build) it using the step-by-step described in <a
href="http://hackanda.wordpress.com/">this blog</a>.</p><h3>Retrieving Contacts Using the PhoneGap Contact API<strong></strong></h3><p>The following JavaScript code will be executed when the &#8220;Get contacts from phone&#8221; button is clicked.</p><pre class="brush: jscript; title: ; notranslate">
var options = new ContactFindOptions(), name, phoneNumber;
options.filter = &quot;&quot;;
options.multiple = true;
var fields = [&quot;name&quot;, &quot;phoneNumbers&quot;];
function onSuccess(contacts) {
var res = &quot;&quot;;
for(var index = 0, len = contacts.length; index &lt; len; index++) { name = contacts[index].name; name = name != null ? name.formatted : &quot;&quot;; phoneNumber = contacts[index].phoneNumbers; phoneNumber = phoneNumber != null &amp;&amp; phoneNumber.length &gt; 0 ? phoneNumber[0].value : &quot;&quot;;
res += name + &quot;   : &quot; + phoneNumber + &quot;\n&quot;;
}
$$('textField2').setValue(res);
navView.goToView(3);
}
function onError() {
alert('onError!');
}
navigator.contacts.find(fields, onSuccess, onError, options);
</pre><p>For  more details about this code, take a look to <a
href="http://docs.phonegap.com/en/1.0.0/phonegap_contacts_contacts.md.html">the PhoneGap contact API</a>. <b></b></p><h3>Package the App Using PhoneGap Build</h3><p><a
href="http://www.youtube.com/watch?v=1TyMqnfrDFo">This video</a> will show you how to package the web app, starting by uploading the .zip file to getting the .ipa file. For the complete description, we&#8217;ll start by downloading the .zip file offered at the beginning of this article and unzipping it.</p><p>Take the &#8220;Client_Side&#8221; folder within the .zip file and zip it to get the desired input file for the PhoneGap build service.</p><p><img
class="aligncenter size-full wp-image-5584" alt="phonegap-build" src="http://cdn.buildmobile.com/files/2013/03/phonegap-build.png" width="488" height="261" /></p><p>You should have an account on PhoneGap build to upload and build the application, so if you don&#8217;t have an account yet, you could create one.</p><p>After creating an account, go to the apps page, upload the zip file (Client_Side.zip), and build it! Look below for clarity.<b></b></p><p
style="text-align: center;"><img
class="aligncenter  wp-image-5585" alt="zip-file" src="http://cdn.buildmobile.com/files/2013/03/zip-file.png" width="598" height="355" /></p><h3>Setting Up Server-Side Elements<b></b></h3><p><b> </b>For the server-side application, you should take the &#8220;Server_Side&#8221; folder and run it on Wakanda 3 Server, using a command line or Wakanda Studio. The command line is:</p><p><b>&#8220;C:\Wakanda Server.exe&#8221;  &#8221;C:\Download the application\Server_Side\getPhoneContact Solution\getPhoneContact.waSolution&#8221;  </b><b></b></p><p>After that, you should go to the &#8220;Client_Side&#8221; folder, and within the &#8220;scripts&#8221; folder, open the index-smartphone.js and add the IP address of the machine where you have hosted your Wakanda application on the following lines:</p><pre class="brush: jscript; title: ; notranslate">
WAF.config.baseURL = &quot;http://@IP_of_the_Wakanda_Server:8081&quot;;
WAF.core.restConnect.defaultService = 'cors';
WAF.core.restConnect.baseURL = &quot;http://@IP_of_the_Wakanda_Server:8081&quot;;
WAF.onAfterInit = function onAfterInit() { // @lock
// @region namespaceDeclaration// @startlock
var documentEvent = {}; // @document
var button2 = {}; // @button
var button1 = {}; // @button
</pre><p>Now, you could access the Wakanda DataStore remotely using the WAF API. <b> </b></p><p>(Note: To build the .ipa for your iPhone, you should provide a provisioning key and the password of your Apple store account.)</p><h3>Conclusion</h3><p>This application is a simple demonstration of Wakanda Studio, as well as a much greater testament to the capabilities of HTML5, JavaScript, and CSS3 for the creation of powerful mobile apps. Using the process of development used in this example (from HTML5, JavaScript, and CSS to native app), we could deliver a cross-platform native mobile application in very little time, so by using PhoneGap, a developer with little background in Java or Objective-C can start developing native mobile apps for many mobile platforms simultaneously. Developing this application, testing it, and packaging it using PhoneGap build took be less than a day&#8217;s work.</p> ]]></content:encoded> <wfw:commentRss>http://buildmobile.com/build-contacts-app-with-html5-css-javascript-wakanda-studio/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Build a Currency Converter with jQuery Mobile and Cordova: Finishing The App</title><link>http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-finishing-the-app/</link> <comments>http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-finishing-the-app/#comments</comments> <pubDate>Tue, 05 Mar 2013 16:42:54 +0000</pubDate> <dc:creator>Aurelio De Rosa</dc:creator> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[jQuery Mobile]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5561</guid> <description><![CDATA[In the previous part of this series, I showed several other functions of the functions.js file, highlighting their key points. In this sixth and final part, I&#8217;ll describe the last&#8230;]]></description> <content:encoded><![CDATA[<p>In <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Rate Updates" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/" target="_blank">the previous part of this series</a>, I showed several other functions of the <code>functions.js</code> file, highlighting their key points. In this sixth and final part, I&#8217;ll describe the last function left and the Cordova configuration file that we will use to set properties for our project and define several directives for the <a
href="http://build.phonegap.com/" target="_blank">Adobe PhoneGap Build service</a>.<br
/> <span
id="more-5561"></span></p><h3>Initializing the Application</h3><p>First, within the <code>index.html</code> file, I&#8217;ll attach the function, <code>initApplication()</code>—which I&#8217;ll describe in a few moments—to the <code>deviceready</code> event, which is fired when Cordova is fully loaded.</p><pre class="brush: jscript; title: ; notranslate">
$(document).one('deviceready', initApplication);
</pre><p>Once started, the function translates the multi-language written copy described in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Translation and Conversion Logic" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/" target="_blank">Build a Currency Converter with jQuery Mobile and Cordova: Translation and Conversion Logic</a>, calling the <code>translateMainPage()</code> function if the user&#8217;s preferred spoken language is available. Then, it calls the <code>openLinksInApp()</code> function to manage external links, as described in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Rate Updates" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/" target="_blank">part 5</a>. These two actions are independent from the rest of the application, even if the device doesn&#8217;t satisfy the requirements.</p><pre class="brush: jscript; title: ; notranslate">
translateMainPage();
openLinksInApp();
</pre><p>After running the two operations mentioned above, &#8220;Currency Converter&#8221; tests the device against the requirements (discussed in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Translation and Conversion Logic" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/" target="_blank">part 4</a>), and if they aren&#8217;t satisfied, it disables the &#8220;Convert&#8221; button and exits the function.</p><pre class="brush: jscript; title: ; notranslate">
if (checkRequirements() === false)
{
  $('#submit-button').button('disable');
  return;
}
</pre><p>Now that the basic operations have been executed, we can run the other and more heavy (actually, they&#8217;re not really that heavy) functions. So, to give the user a feeling that something is happening behind the scenes, one function displays the loader widget. Then, it continues updating the interface, filling the two select boxes with the stored currency values by calling <code>fillCurrenciesSelection()</code>, the function to update the rates, <code>updateExchangeRates()</code>, and the final function that updates the labels by reading the date and time of the last currency exchange rate update, <code>updateLastUpdate()</code>.</p><pre class="brush: jscript; title: ; notranslate">
$.mobile.loading('show');
fillCurrenciesSelection();
updateExchangeRates();
updateLastUpdate();
</pre><p>At this point, all the necessary processes have been called, and we need to attach handlers to some of the pages&#8217; elements and events. The first handler will update the rates as soon as the <code>online</code> event is fired. The latter, as you may guess, fires when a Cordova application detects that it&#8217;s connected to the Internet.</p><pre class="brush: jscript; title: ; notranslate">
$(document).on('online', updateExchangeRates);
</pre><p>The next handler is very important, since it&#8217;s the one the execute the money conversion and because it&#8217;s attached to the &#8220;Convert&#8221; button. After it has retrieved the values of the money and the two currencies selected from the interface, it calls the <code>convert()</code> method of the <code>Currency</code> class to made the conversion calculation. Then, it calls the <code>numberToString()</code> to localize the result based on the user preferences and injects the end result into the page. Finally, it updates the app settings with the last currencies chosen by the user.</p><pre class="brush: jscript; title: ; notranslate">
$('#submit-button').click(function(event) {
  event.preventDefault();
  // Convert the value
  var result = Currency.convert(
    $('#from-value').val(),
    $('#from-type').val(),
    $('#to-type').val()
  );
   // Localize the result
   navigator.globalization.numberToString(
    result,
    function(number)
    {
      $('#result').text(number.value);
    },
    function()
    {
      $('#result').text(result);
    }
  );
  // Update settings
  var settings = Settings.getSettings();
  if ($.isEmptyObject(settings))
    settings = new Settings();
  settings.fromCurrency = $('#from-type').val();
  settings.toCurrency = $('#to-type').val();
  settings.save();
});
</pre><p>Having finished the &#8220;Convert&#8221; button functionality, we can now move on to the &#8220;Reset&#8221; button. Its behavior is quite straightforward. If the user clicks it, we set the input field for the money to convert and the conversion result to zero. We also reset the last chosen currencies by changing the selected currency types for both the select boxes to the first currencies listed.</p><pre class="brush: jscript; title: ; notranslate">
$('#reset-button').click(function(event) {
  event.preventDefault();
  $('#from-value').val(0);
  $('#form-converter select').prop('selectedIndex', 0).selectmenu('refresh');
  $('#result').text(0);
});
</pre><p>The last handler we need to put in place is for the &#8220;Update data&#8221; button—the one at the top-right of the main screen. The attached function simply tests for an Internet connection, and if it&#8217;s found, runs the <code>updateExchangeRates()</code> function. Otherwise it notifies the user that it&#8217;s not connected to the Internet.</p><pre class="brush: jscript; title: ; notranslate">
$('#update-button').click(function(event) {
  event.preventDefault();
  if (navigator.network.connection.type === Connection.NONE)
  {
    console.log('The connection is off. Can\'t update exchange rates.');
    navigator.notification.alert(
      'Your device has the connections disabled. Can\'t update exchange rates.',
      function(){},
      'Error'
    );
  }
  else
    updateExchangeRates();
});
</pre><p>Now that all of the pieces are in their place, we can hide the loading widget from the user so that they&#8217;ll know that that all background operations are finished.</p><pre class="brush: jscript; title: ; notranslate">
$.mobile.loading('hide');
</pre><p>As a conclusion of the whole discussion, here is a screenshot of our &#8220;Currency Converter&#8221; app:</p><p><a
href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-finishing-the-app/currency-converter-main-page/" rel="attachment wp-att-5563"><img
class="alignnone size-medium wp-image-5563" alt="Currency Converter main page" src="http://cdn.buildmobile.com/files/2013/03/Currency-Converter-main-page-200x300.png" width="200" height="300" /></a></p><h3>Create the Cordova Configuration</h3><p>Since we&#8217;ll use the <a
href="http://build.phonegap.com" target="_blank">Adobe PhoneGap Build</a> service to package our project, in order to set its metadata (the version, the name, the author, and so on), we&#8217;ll use a configuration file called <code>config.xml</code>. Explaining the format in detail is outside the scope of this article, but I&#8217;ll highlight the main concepts and focus on the important <code>&lt;access&gt;</code> tag. To have an in-depth look of what you can do with this file, you can read the <a
title="Using config.xml" href="https://build.phonegap.com/docs/config-xml" target="_blank">official documentation page</a>.</p><p>The cited file follows the <a
title="W3C widget specification" href="http://www.w3.org/TR/widgets/" target="_blank">W3C widget specification</a> and must reside in the root of the project files, at the same level as the <code>index.html</code> file. The root of the whole document is a <code>&lt;widget&gt;</code> tag that has several attributes, but the mains ones are <code>id</code> (the unique identifier of the app) and <code>version</code> (that specifies the version of the app). Inside the <code>&lt;widget&gt;</code> tag, you can include several elements:</p><ul><li><strong>name</strong> (required): Specify the name of the application. It doesn&#8217;t have to be unique.</li><li><strong>description</strong> (required): Specify the description of your work. This will be shown in the app&#8217;s marketplace listing.</li><li><strong>author</strong> (optional): The app&#8217;s author. Unfortunately, you can only specify one author, so you can&#8217;t have details for multiple authors.</li><li><strong>icon</strong> (optional): The icon to display on the devices that will install your app. If you do not specify it, the Cordova logo will be used.</li><li><strong>feature</strong> (optional): Specify the features you want to use. Some operating systems, before installing the app, ask the user to provide permissions for those features. In &#8220;Currency Converter&#8221;, the only required feature is access to the Internet connection.</li><li><strong>preference</strong> (optional): A set of preferences you want to apply, such as the Cordova version, to use when packaging the project.</li><li><strong>splash</strong> (optional): This tag sets the splash screen of the application—the image to show while it&#8217;s loading.</li></ul><p>The <code>&lt;access&gt;</code> tag is very important because, citing <a
href="https://build.phonegap.com/docs/config-xml" target="_blank">the documentation</a>, it <q
cite="https://build.phonegap.com/docs/config-xml">provides your app with access to resources on other domains—in particular, it allows your app to load pages from external domains that can take over your entire webview.</q> Recalling what we discussed in the section &#8220;Managing External Links&#8221; of <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Rate Updates" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/" target="_blank">the previous part</a>, in order to open the external links in the Cordova WebView, we must add them to the app whitelist. Using the <code>&lt;access&gt;</code> tag, you have several ways to add links. In fact, you can specify each link you want to add individually. Consider the following example:</p><p><code>&lt;access origin="https://www.audero.it" /&gt;</code><br
/> <code>&lt;access origin="https://www.buildmobile.com" /&gt;</code></p><p>For each of the above approved domains, you can also include all the subdomains using the <code>subdomains</code> attribute:</p><p><code>&lt;access origin="https://www.audero.it" subdomains="true" /&gt;</code></p><p>Since our app won&#8217;t retrieve links from external and unsafe sources, we can shorten the process allowing for any external resource using the <code>*</code> special character like the following example:</p><p><code>&lt;access origin="*" /&gt;</code></p><p>Now that I&#8217;ve pointed out the key points of the format, you can understand the source of the configuration file of our project. The complete file is below.</p><pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;widget xmlns     = &quot;http://www.w3.org/ns/widgets&quot;
        xmlns:gap	= &quot;http://phonegap.com/ns/1.0&quot;
        id        = &quot;com.audero.free.utility.currencyconverter&quot;
        version   = &quot;1.0.0&quot;&gt;
   &lt;name&gt;Currency converter&lt;/name&gt;
   &lt;description&gt;Currency converter is a simple app that helps you convert from a currency to another. You can update the exchange rates anytime you want so you'll have always an up-to-date conversion.&lt;/description&gt;
   &lt;author href=&quot;http://www.audero.it&quot; email=&quot;aurelioderosa@gmail.com&quot;&gt;Aurelio De Rosa&lt;/author&gt;
   &lt;feature name=&quot;http://api.phonegap.com/1.0/network&quot;/&gt;
   &lt;preference name=&quot;phonegap-version&quot; value=&quot;2.3.0&quot; /&gt;
   &lt;preference name=&quot;target-device&quot; value=&quot;universal&quot; /&gt;
   &lt;access origin=&quot;*&quot; /&gt;
   &lt;!-- Icons --&gt;
   &lt;icon src=&quot;icon.png&quot; width=&quot;64&quot; height=&quot;64&quot; gap:role=&quot;default&quot; /&gt;
   &lt;icon src=&quot;images/icon-72x72.png&quot; width=&quot;72&quot; height=&quot;72&quot; gap:platform=&quot;android&quot; gap:density=&quot;hdpi&quot; /&gt;
   &lt;icon src=&quot;images/icon-96x96.png&quot; width=&quot;96&quot; height=&quot;96&quot; gap:platform=&quot;android&quot; gap:density=&quot;xhdpi&quot; /&gt;
   &lt;icon src=&quot;images/icon-72x72.png&quot; width=&quot;72&quot; height=&quot;72&quot; gap:platform=&quot;ios&quot; /&gt;
   &lt;!-- Splash Screens --&gt;
   &lt;gap:splash src=&quot;splash.png&quot; /&gt;
   &lt;gap:splash src=&quot;images/splash-160x220.png&quot; gap:platform=&quot;android&quot; gap:density=&quot;ldpi&quot; /&gt;
   &lt;gap:splash src=&quot;splash.png&quot; gap:platform=&quot;android&quot; gap:density=&quot;mdpi&quot; /&gt;
   &lt;gap:splash src=&quot;images/splash-450x650.png&quot; gap:platform=&quot;android&quot; gap:density=&quot;hdpi&quot; /&gt;
&lt;/widget&gt;
</pre><h3>Conclusion</h3><p>I have to compliment those of you who completed the whole series. The growing number of hybrid apps released, including the one we just built, prove that you can build amazing games and utilities using web technologies that you&#8217;ve already mastered. There are pros and cons in choosing to develop a hybrid app, but this is definitively one additional tool in your development tool belt. My last contribution is giving you the link to the <a
href="https://github.com/AurelioDeRosa/Currency-Converter" target="_blank">Currency Converter repository</a>. Here you&#8217;ll find and download the full and ready-to-work package. For those of you that are too lazy to build the app, I have also created <a
title="Download Currency Converter installers" href="https://build.phonegap.com/apps/327164/share" target="_blank">a public page</a> where you can download the installer for every platform supported by the <a
href="http://build.phonegap.com/" target="_blank">Adobe Build PhoneGap service</a>. As a final note, <a
href="https://github.com/AurelioDeRosa/Currency-Converter" target="_blank">Currency Converter</a> is released under the CC BY 3.0 (&#8220;Creative Commons Attribution 3.0&#8243;) license.</p><p>I hope you enjoyed the series and have more comfort and confidence with hybrid apps. Thanks for following!</p> ]]></content:encoded> <wfw:commentRss>http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-finishing-the-app/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <series:name><![CDATA[Build a Currency Converter with jQuery Mobile and Cordova]]></series:name> </item> <item><title>Build a Currency Converter with jQuery Mobile and Cordova: Rate Updates</title><link>http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/</link> <comments>http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/#comments</comments> <pubDate>Fri, 01 Mar 2013 01:07:15 +0000</pubDate> <dc:creator>Aurelio De Rosa</dc:creator> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[jQuery Mobile]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5510</guid> <description><![CDATA[In the previous article in this series, I described the classes and functions needed to perform currency conversions within our app. I also illustrated the Cordova Globalization API and how&#8230;]]></description> <content:encoded><![CDATA[<p>In <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Translation and Conversion Logic" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/" target="_blank">the previous article in this series</a>, I described the classes and functions needed to perform currency conversions within our app. I also illustrated the <a
href="http://docs.phonegap.com/en/2.3.0/cordova_globalization_globalization.md.html#Globalization" target="_blank">Cordova Globalization API</a> and how we can use it to translate the written instructions on the main page of &#8220;Currency Converter.&#8221; In this next installment, I&#8217;ll show you the remaining functions of the <code>functions.js</code> file and a brief overview of the Cordova <a
title="Cordova Connection API" href="http://docs.phonegap.com/en/2.3.0/cordova_connection_connection.md.html#Connection" target="_blank">Connection</a> and <a
title="Cordova InAppBrowser API" href="http://docs.phonegap.com/en/2.3.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser" target="_blank">InAppBrowser</a> APIs.<br
/> <span
id="more-5510"></span></p><h3>Utility Functions</h3><h4>Updating the &#8220;Last Update&#8221; Label</h4><p><a
title="Build a Currency Converter with jQuery Mobile and Cordova: Introduction" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova/" target="_blank">In the introductory article</a> of this series, I explained that our project will store the downloaded currency rates so that the user can use the application offline. Since the currency exchange rates change every day, it&#8217;s important to notify the user of how old his exchange rates are. If he feels that they are too old, he can run an update and download the latest. For this reason, the main page has the following code:</p><pre class="brush: xml; title: ; notranslate">
&lt;label id=&quot;last-update-label&quot;&gt;Last update of exchange rates:&lt;/label&gt;
&lt;span id=&quot;last-update&quot;&gt;&lt;/span&gt;
</pre><p>The <code>&lt;span&gt;</code> having <code>id="last-update"</code> is where we&#8217;ll inject the date of the last update. Th date will be written in the format that best suits the user preferences determined by the <a
title="Globalization API official documentation" href="http://docs.phonegap.com/en/2.3.0/cordova_globalization_globalization.md.html#Globalization" target="_blank">Globalization API</a>, which I explained in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Translation and Conversion Logic" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/" target="_blank">the previous article</a>. Recalling <a
title="Build a Currency Converter with jQuery Mobile and Cordova: JavaScript and User Settings" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-3/" target="_blank">the third article</a> where we talked about the user settings, you should recall that we update and save the date each time the user request an exchange rates update via the <code>Settings</code> class and its methods.</p><p>The function that updates the text of the above <code>&lt;span&gt;</code> tag is <code>updateLastUpdate(),</code> and its markup is the following:</p><pre class="brush: jscript; title: ; notranslate">
function updateLastUpdate()
{
  if (typeof Settings.getSettings().lastUpdate === 'undefined')
  {
    $('#last-update').text('-');
    return;
  }
  // Show the last time the rates have been updated
  navigator.globalization.dateToString(
    new Date(Settings.getSettings().lastUpdate),
    function (date)
    {
      $('#last-update').text(date.value);
    },
    function ()
    {
      $('#last-update').text('-');
    }
  );
}
</pre><h4>Updating the Rates</h4><p>The method that deals with the actual updating is <code>updateExchangeRates()</code>. At the very beginning of the method, there is a test to verify whether the device is connected to the Internet or not. The test is done using the Cordova Connection API—an object that gives access to the device’s cellular and wifi connection information. It has one property called <code>type</code> that checks the active network connection that is being used and can assume the following values (as constants):</p><ul><li>Connection.UNKNOWN</li><li>Connection.ETHERNET</li><li>Connection.WIFI</li><li>Connection.CELL_2G</li><li>Connection.CELL_3G</li><li>Connection.CELL_4G</li><li>Connection.NONE</li></ul><p>If the device has an active connection, the function makes a call to the European Central Bank RSS feed to retrieve the rates using the jQuery <code>ajax()</code> method. Once retrieved, the rates are stored using the <code>Currency</code> class, and the <code>lastUpdate</code> data of the user&#8217;s settings is updated as well, so the user knows that they&#8217;re working with the latest currency exchange rates.</p><p>The two select boxes and the &#8220;last update&#8221; label of the main page are updated using this current data. Then, the two select menus are filled using a function called <code>fillCurrenciesSelection()</code>, which I&#8217;ll describe in a few moments. As a final note, if the rate update fails, the user is notified with an alert of this failure shown using the Cordova Notification API.</p><p>So, what exactly will happen if the first test fails? Well, if the device does not have an active Internet connection, the app will check if there are any stored rates. If there are no stored currency exchange rates, the user is notified of the issue, and the &#8220;Convert&#8221; button is disabled, because there aren&#8217;t any ways to run any currency conversions.</p><p>The code that implements this functionality is listed below:</p><pre class="brush: jscript; title: ; notranslate">
/**
 * Update the exchange rates using the ECB web service
 */
function updateExchangeRates()
{
  if (navigator.network.connection.type !== Connection.NONE)
  {
    $.mobile.loading(
      'show',
      {
        text: 'Updating rates...',
        textVisible: true
      }
    );
    $.get(
      'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml',
      null,
      function(data)
      {
        var $currenciesElements = $(data).find('Cube[currency]');
        // The EURO is the default currency, so it isn't in the retrieved data
        var currencies = [new Currency('EUR', '1')];
        var i;
        for(i = 0; i &lt; $currenciesElements.length; i++)
        {
          currencies.push(
            new Currency(
              $($currenciesElements[i]).attr('currency'),
              $($currenciesElements[i]).attr('rate')
            )
          );
        }
        currencies.sort(Currency.compare);
        // Store the data
        for(i = 0; i &lt; currencies.length; i++)
          currencies[i].save();
        // Update settings
        var settings = Settings.getSettings();
        if ($.isEmptyObject(settings))
          settings = new Settings();
        settings.lastUpdate = new Date();
        settings.save();
        fillCurrenciesSelection();
        updateLastUpdate();
        $('#submit-button').button('enable');
      },
      'XML'
    )
    .error(function() {
      console.log('Unable to retrieve exchange rates from the provider.');
      navigator.notification.alert(
        'Unable to retrieve exchange rates from the provider.',
        function(){},
        'Error'
      );
      if (Currency.getCurrencies().length === 0)
        $('#submit-button').button('disable');
    })
    .complete(function() {
      $.mobile.loading('hide');
    });
  }
  // Check if there are data into the local storage
  else if (Currency.getCurrencies().length === 0)
  {
    console.log('The connection is off and there aren\'t rates previously stored.');
    navigator.notification.alert(
      'Your device has the connection disabled and there aren\'t rates previously stored.\n' +
      'Please turn on your connection.',
      function(){},
      'Error'
    );
    $('#submit-button').button('disable');
  }
}
</pre><h4>Filling the Select Boxes</h4><p>The function to update the select boxes isn&#8217;t very hard to grasp. It simply retrieves the stored currencies using the <code>getCurrencies()</code> method of the <code>Currency</code> class and then insert each of them using the jQuery <code>append()</code> method. It&#8217;s worth noting that after all the currencies are inserted, this function searches for the last origin and destination currencies saved within the user preferences If these last used currencies are found, they are automatically selected. In this scenario, the listview widget needs to be refreshed, which accomplished using the method <code>selectmenu()</code> and passing the string <code>refresh</code> to it.</p><p>The complete source of <code>fillCurrenciesSelection()</code> is listed below:</p><pre class="brush: jscript; title: ; notranslate">
/**
 * Use the stored currencies to update the selection lists
 */
function fillCurrenciesSelection()
{
  var currencies = Currency.getCurrencies();
  var $fromCurrencyType = $('#from-type');
  var $toCurrencyType = $('#to-type');
  // Empty elements
  $fromCurrencyType.empty();
  $toCurrencyType.empty();
  // Load all the stored currencies
  for(var i = 0; i &lt; currencies.length; i++)
  {
    $fromCurrencyType.append('
' +      currencies[i].abbreviation + '
');
    $toCurrencyType.append('
' +      currencies[i].abbreviation + '
');
  }
  // Update the selected option using the last currencies used
  var settings = Settings.getSettings();
  if (!$.isEmptyObject(settings))
  {
    var currency = $fromCurrencyType.find('[value=&quot;' + settings.fromCurrency + '&quot;]');
    if (currency !== null)
      $(currency).attr('selected', 'selected');
    currency = $toCurrencyType.find('[value=&quot;' + settings.toCurrency + '&quot;]');
    if (currency !== null)
      $(currency).attr('selected', 'selected');
  }
  $fromCurrencyType.selectmenu('refresh');
  $toCurrencyType.selectmenu('refresh');
}
</pre><h4>Managing External Links</h4><p>As you&#8217;ve seen in <a
title="Build a Currency Converter with jQuery Mobile and Cordova: Constructing The Interface" href="http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-2/" target="_blank">the interface design</a> of &#8220;Currency Converter&#8221;, the <code>aurelio.html</code> file have several external links within it. Those links aren&#8217;t very useful, but I do need to explain an important concept.</p><p>Until a few versions ago, Cordova opened external links in the same Cordova WebView that was running the application. So, once it opened a link, when the user clicked the &#8220;back&#8221; button, the last project&#8217;s page was shown exactly as it was before the user left it. But, in the most recent release of the framework, this behavior was changed; now, the external links are opened by default using the Cordova WebView if the URL is in your app&#8217;s whitelist. URLs that aren&#8217;t on your whitelist are opened using the InAppBrowser API.</p><p>Citing the official documentation, <q
cite="http://docs.phonegap.com/en/2.3.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser">the InAppBrowser is a web-browser that is shown in your app when you use the window.open call.</q> This API has three methods: <code>addEventListener()</code>, <code>removeEventListener()</code>, and <code>close()</code>. The first allows you to listen for three events (<code>loadstart</code>, <code>loadstop</code>, and <code>exit)</code> and allows you to attach a function that runs as soon as those events are fired. The second method, as you might guess, is used to remove a previously-attached listener. Finally, the <code>close()</code> method is used to close the InAppBrowser window.</p><p>If the user opens a link that is shown in the InAppBrowser or the system browser and then goes &#8220;back&#8221; to the application, all the CSS and jQuery Mobile enhancements are lost. This happens because the external link doesn&#8217;t the reference the cited files and when the user goes back into the app; the file is loaded as it were requested for the first time, but without passing through the main page. Obviously, this is something you&#8217;ll want to avoid, which highlights the importance of the the whitelist within the Cordova configuration file and the next function come in help.</p><p>The aim of the <code>openLinksInApp()</code> function is to catch the clicks on all the external links (recognized by using the <code>target="_blank"</code> attribute), preventing the unwanted default behavior and opening them using the <code>window.open()</code> method. As you&#8217;ll see in the code shown below, I&#8217;ll use the <code>_target</code> parameter so that the links will be opened using the WebView, because I&#8217;ll put these URLs in the Cordova whitelist. Using this technique, we&#8217;ll avoid the issues described above, and your app will continue to look and function as expected.</p><pre class="brush: jscript; title: ; notranslate">
/**
 * Open all the links as internals
 */
function openLinksInApp()
{
   $(&quot;a[target=\&quot;_blank\&quot;]&quot;).on('click', function(event) {
      event.preventDefault();
      window.open($(this).attr('href'), '_target');
   });
}
</pre><h3>Conclusion</h3><p>In this article, I described several other functions of the <code>functions.js</code> file, highlighting the key points of each. I also explained the Cordova Connection and the InAppBrowser API and how they work. As we&#8217;ve seen, dealing with external links is extremely important when you&#8217;re using jQuery Mobile to build your mobile app interface. In the next and final article in this series, I&#8217;ll show you the function that initializes the application, called <code>initApplication()</code>, and the Cordova configuration file that we will use alongside the <a
href="http://build.phonegap.com/" target="_blank">Adobe PhoneGap Build</a> service to package our &#8220;Currency Converter&#8221; app.</p> ]]></content:encoded> <wfw:commentRss>http://buildmobile.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <series:name><![CDATA[Build a Currency Converter with jQuery Mobile and Cordova]]></series:name> </item> <item><title>Understanding Responsive Web Design: Responsive Imagery</title><link>http://buildmobile.com/understanding-responsive-web-design-how-to-manage-images/</link> <comments>http://buildmobile.com/understanding-responsive-web-design-how-to-manage-images/#comments</comments> <pubDate>Wed, 27 Feb 2013 17:34:32 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile Web Discussion]]></category> <category><![CDATA[Discussion]]></category> <category><![CDATA[mobile]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5536</guid> <description><![CDATA[In this fifth part of our Understanding Responsive Web Design series, I&#8217;ll show you one of the typical problems that a web designer faces when building a responsive website: the&#8230;]]></description> <content:encoded><![CDATA[<p>In this fifth part of our <a
title="Understanding Responsive Web Design" href="http://buildmobile.com/series/understanding-responsive-web-design/" target="_blank">Understanding Responsive Web Design</a> series, I&#8217;ll show you one of the typical problems that a web designer faces when building a responsive website: the management of the images. As you&#8217;ve seen so far, the challenges that a mobile designer faces are numerous, and it&#8217;s not so strange or unusual to think that one of the biggest is serving multiple image formats to multiple screen sizes. There are currently three strategies that a developer can choose when it comes to responsive imagery: he can choose between: &#8220;fighting&#8221; the browser, &#8220;resigning&#8221; himself, or relying on the server. Let&#8217;s try to understand the advantages and downsides of each option.<br
/> <span
id="more-5536"></span></p><h3>Fighting the Browser</h3><p>Most front-end developers choose to apply the first strategy and fight the browser. What does &#8220;fighting the browser&#8221; stand for? It means doing your best to give the &#8220;right&#8221; image (that is, the image that has the correct size for the device used to view the website) to the browser so that it can be loaded before the browser had downloaded the &#8220;wrong&#8221; one (that is, the &#8220;default&#8221; or the desktop version of the image). This is an increasingly difficult task, as modern browsers and ever-quickening bandwidth means that users try to download images as quickly as possible.</p><h3>Resigning</h3><p>Sometimes the simplest and most comfortable strategy is the only viable option: admit defeat. Generally, this approach involves loading the default image onto small screens, and secondly, if necessary, loading a larger image for screens with larger dimensions. While this method is easy and straightforward, it&#8217;s not recommended, because in the second case, two requests are sent to the browser when only one is necessary.</p><h3>Relying on the Server</h3><p>The third strategy involves the use of the server, a server-side programming language and some basic forms of detection to determine which image to load. All of the logic is executed before the browser is able to see and interpret the HTML code. Unfortunately, this strategy has its own flaws: the act of maintaining an ever-growing list of mobile devices and screen sizes would become very complicated and require constant upkeep.</p><p>To help you understand better what this technique does and how it can be used, let&#8217;s consider an example. In the following example, I&#8217;ll show you a few lines of PHP, but don&#8217;t worry, you don&#8217;t have to me a PHP expert to create responsive images, and you&#8217;ll understand the example even if you haven&#8217;t worked with PHP before. Let&#8217;s assume that you&#8217;re creating a page dynamically and that you&#8217;re injecting an <code>&lt;img&gt;</code> tag using the following line of code:</p><pre class="brush: php; title: ; notranslate">echo '&lt;img src=&quot;heavy-image.png&quot; /&gt;';</pre><p>As you might already know, mobile connections aren&#8217;t nearly as fast as their desktop counterparts. So, to speed up the rendering of your page for mobile devices, you&#8217;d like to inject a lightweight version of the image if the user is using&#8230; perhaps an iPhone. What you can do server-side is check the user-agent that made the request and—if the device was an iPhone—inject the smaller image. The next snippet demonstrates this technique:</p><pre class="brush: php; title: ; notranslate">
if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') === false) {
  // Not an iPhone
  echo '&lt;img src=&quot;heavy-image.png&quot; /&gt;;
}
else {
  // An iPhone
  echo '&lt;img src=&quot;light-image.png&quot; /&gt;;
}
</pre><p>As you can see, the method is very easy to implement, however this approach isn&#8217;t very reliable because the user-agent information itself isn&#8217;t 100% reliable. If the method fails, you could have some glaring problems with your imagery.</p><h3>Is One Method Better Than The Others?</h3><p>Obviously, each approach has its own unique advantages and limitations, and it&#8217;s unlikely that one single method will be the ideal choice for all of your mobile projects. However, there are some additional techniques and resources that a developer may use to create responsive images.</p><h4>Sencha.io Src</h4><p>The first option is very fast and simple. It is a service developed by James Pearce that returns the image you choose to load resized to fit your exact needs. Its name is Sencha.io Src, and all you have to do is put the Sencha.io Src URL location of your image as the image&#8217;s source.</p><pre class="brush: xml; title: ; notranslate">&lt;img src=&quot;http://src.sencha.io/http://mysite.com/images/my-image.jpg&quot; /&gt;</pre><p>The service uses the user agent string of the requesting device to determine the desired image size and resize the image accordingly. By default, the image is scaled to 100% of the width of the screen. Sencha.io Src has a high level of customization; it&#8217;s possible to set a specific width or any other parameter. For example, if you want to set the image width to 250 pixels, you have simply to add the size into the URL as follows:</p><pre class="brush: xml; title: ; notranslate">&lt;img src=&quot;http://src.sencha.io/250/http://mysite.com/images/my-image.jpg&quot; /&gt;</pre><p>The service also caches the request, so the image will not be reloaded each time the page is loaded.</p><h3>Adaptive Images</h3><p>A similar solution is proposed by Matt Wilcox. It involves determining the size of the screen first, and then creating (and caching) a scaled version of the correct image dimensions. This is an ideal technique to make the images of an existing website responsive. After downloading the code (which you can find at <a
href="http://adaptive-images.com/" target="_blank">adaptive-images.com</a>), to make this solution operational and running properly, you need to follow three simple steps:</p><ol><li>Add two files, <strong>.htaccess</strong> and <strong>adaptive-images.php</strong>, to the root folder;</li><li>Create a cache folder and allow write permission;</li><li>Add the following line of Javascript code at the beginning of your document:</li></ol><pre class="brush: jscript; title: ; notranslate">&lt;script&gt;document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';&lt;/script&gt;</pre><p>Thanks to this one line of code, the screen resolution is captured and stored in a browser cookie. It&#8217;s possible to configure multiple options in the file adaptive-images.php, but the primary purpose of the file is setting the variables for the resolutions (<code>$resolutions</code>).</p><pre class="brush: php; title: ; notranslate">$resolutions = array (800, 480, 320);</pre><p>These resolutions are the &#8220;breakpoints&#8221; of images based on the screen resolution (a width to be measured in pixels). In this case, This tool will serve out a small, mobile-friendly image for devices with a pixel width of 320 or smaller. If the display exceeds 320 pixels, the new reference value is 480, which is the next numerical value in the array above.</p><p>Once created, the images will be stored in the cache folder (where you can change the filename), so that you will no longer need to generate them.</p><p>In addition to what I showed, I want to highlight that the key point of the discussion on adaptive images concerns their size. This is certainly an important factor, but we often forget that it is not the only one. For example, resizing an image for smaller displays often reduces the impact and the recognition of the image. In these cases, it may be necessary to modify the image. Even a simple cropping of the edges or of the superfluous elements can help the image retain it&#8217;s impact and significance at a smaller size.</p><h3>Conclusion</h3><p>In this article I described three ways to work with with images from a responsive design point of view. The first is fighting the browser—that is, doing your best to give to the browser the &#8220;right&#8221; image to download. The second is choosing services like Sencha.io which use the user agent string of the device from which the request is sent to understand screen size and resize the image accordingly. The last involves to adaptive images—in this case, the developer only needs to determine the size of the screen and the image will scale to accommodate.</p><p>In conclusion, between the three approaches discussed above, the one of the adaptive images is probably the best solution as it requires no dependency to another site or link. In the next articles in the series, we&#8217;ll examine other methods that a developer can use to manage all the images of a responsive website.</p><p><em>Want to learn more about Responsive Web Design? Check out SitePoint&#8217;s new book, <a
href="http://www.sitepoint.com/books/responsive1/" target="_blank">Jump Start Responsive Web Design</a>!</em></p> ]]></content:encoded> <wfw:commentRss>http://buildmobile.com/understanding-responsive-web-design-how-to-manage-images/feed/</wfw:commentRss> <slash:comments>6</slash:comments> <series:name><![CDATA[Understanding Responsive Web Design]]></series:name> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 4/45 queries in 0.070 seconds using memcached
Object Caching 911/1110 objects using memcached
Content Delivery Network via cdn.buildmobile.com

Served from: buildmobile.com @ 2013-05-19 10:52:43 -->