<?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>SitePoint &#187; Mobile</title> <atom:link href="http://www.sitepoint.com/category/mobile/feed/" rel="self" type="application/rss+xml" /><link>http://www.sitepoint.com</link> <description>Learn CSS &#124; HTML5 &#124; JavaScript &#124; Wordpress &#124; Tutorials-Web Development &#124; Reference &#124; Books and More</description> <lastBuildDate>Mon, 13 May 2013 13:12:07 +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>Strengthen User Authentication and Preserve User Experience</title><link>http://www.sitepoint.com/strengthen-user-authentication-and-preserve-user-experience/</link> <comments>http://www.sitepoint.com/strengthen-user-authentication-and-preserve-user-experience/#comments</comments> <pubDate>Tue, 07 May 2013 09:25:58 +0000</pubDate> <dc:creator>Roman Yudkin</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Web security]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=66050</guid> <description><![CDATA[Veteran web industry security expert Roman Yudkin provides an overview of how to strengthen user authentication processes without diminishing your site visitors' experience.]]></description> <content:encoded><![CDATA[<p></p><p>Alphanumeric passwords have long been the primary method of authentication and access control on the Web. In recent years, however, relying on passwords as the sole method of authentication has proven to be unsustainable and not secure.</p><p><a
href="http://www.verizonenterprise.com/DBIR/2013/">Research</a> shows that authentication-based attacks were used in the majority of major data breaches in 2012. Simply moving beyond passwords to implement stronger forms of user authentication would prevent nearly 80 per cent of hacking attacks on companies.</p><p>Because people often use the same password on multiple websites, a large-scale password leak at one site creates a domino effect that harms security for many other websites and applications. When 1.5 million user credentials were leaked from Gawker Media Group, spammers and hackers immediately used those credentials to access user accounts on other websites. Hundreds of thousands of accounts on Twitter were compromised and used to spread spam and malicious links. Amazon and LinkedIn had to enforce password resets for their entire user communities.</p><p>Such debacles harm not only the individual users whose accounts are compromised; they also harm the organization, website or application itself. The negative repercussions of a data breach can include legal liability, fines, loss of customers, damage to brand reputation, plus the cost of fixing security and IT systems amidst a crisis.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>When hackers stole more than 8 million user passwords from LinkedIn and eHarmony accounts in 2012, LinkedIn <a
href="http://www.securityweek.com/linkedin-breach-cost-1m-says-2-3-million-security-upgrades-coming">estimated</a> it spent more than $1 million to clean up the breach and would need to spend another $2-$3 million for additional security upgrades. In 2011 Sony was forced to <a
href="http://www.cbsnews.com/8301-504083_162-20065621-504083.html">spend</a> more than $170 million to remedy the fallout from a data breach that leaked more than 100 million PlayStation passwords.</p><p>Mobile developers must also consider better authentication methods. The majority of smartphone and tablet owners <a
href="http://www.confidenttechnologies.com/news_events/survey-shows-smartphone-users-choose-convenience-over-security">do not password protect their devices</a>, despite having them connected to sensitive applications including work networks and banking applications. Users do that because typing passwords to log into mobile apps is too cumbersome. Experts at the CTIA Wireless conference even <a
href="http://www.mobilemarketer.com/cms/news/commerce/11217.html">stated</a> that growth of mobile commerce will be stunted until new, easier-to-use authentication methods are developed.</p><p>To achieve effective, strong user authentication on websites and applications, developers must balance security with usability. Do this by evaluating the security needs of the business as well as the characteristics of the user population. Is the user base comprised of employees, business partners, or the general public? This will help determine risk level and how stringent the authentication requirements should be.</p><h2>Recommendations For Strong Authentication</h2><h3>Make sure the basics are covered</h3><p>Since most websites and applications will likely choose to continue using a password as the first layer of authentication, make sure these basic security measures covered:</p><ul><li>Enforce a dictionary check to ensure that users cannot choose common words for their password.</li><li>Require a strong username that includes a numeric character. Often the username is the easiest portion of the login credentials for a hacker to guess. Do not use the user’s email address as their username.</li><li>Limit the number of failed login attempts to three and temporarily suspend account access unless the user can authenticate through other means.</li><li>If the login fails, don’t identify which portion of the credentials was incorrect. Stating that the ‘password is incorrect’ or the ‘username doesn’t exist’ enables hackers to harvest account information. A general statement such as “Incorrect login, please try again” helps prevent account harvesting.</li><li>Use SSL to create an encrypted link between your server and the user’s web browser during account enrolment, the login process and the password reset process.</li><li>Provide users with advice on how to choose a strong username and password. Research shows that users do choose better passwords when given advice on how to do so. One option is to have a password strength meter built into the page.</li><li>Hash user passwords using bcrypt, scrypt, or other hash algorithms specifically designed to store passwords. Do not use SHA1, MD5 or other algorithms that were not designed for hashing passwords, as they are not secure.</li><li>Use Salt. Use a unique salt for each user account/password and store that salt with the password. An additional layer of system wide salt that is not stored with the password can also add extra strength if the database is stolen because it is not stored with the passwords but is known to you.</li></ul><p>These steps may seem rudimentary to some readers, but a study conducted by researchers at Cambridge University showed that most websites did not even enforce these minimum standards.<a
title="" href="#_edn1">[i]</a></p><h3>SaaS solutions for generating one-time passwords</h3><p>With the growth of Software-as-a-Service (SaaS) providers, it’s easier than ever to adopt authentication solutions that generate one-time passwords for users without any hardware investment or significant integration efforts. While one-time passwords will not stop a sophisticated man-in-the-middle threat, they do protect against the most common security threats: users choosing weak passwords, reusing the same password or having their passwords stolen using keystroke-logging malware.</p><p>By generating one-time passwords for users each time authentication is needed, organizations can ensure strong passwords are used and that previously stolen or leaked passwords cannot be used to access accounts.</p><p>The growing number of user devices with touchscreens enables new approaches to SaaS authentication schemes, including image-based and graphical approaches. Increasingly users are asked to draw a pattern, touch points on a picture or identify a series of secret images to authenticate. When evaluating such approaches, it’s important to make sure the solution generates one-time passwords and is not simply a static pattern or image. User’s fingerprints and smudges on the touchscreen can reveal their secret pattern or touch points if it is a static approach.</p><p>One way to generate one-time passwords using an image-based approach is to have the user choose a few secret categories of things – such as dogs, flowers and cars. Each time authentication is needed the user is presented with a series of pictures on the touchscreen and must tap the ones that fit his previously chosen categories. The specific images are different every time and displayed in a different location on the screen every time, but the user will always look for his same categories. As the user clicks or taps on the pictures that fit his categories, a one-time password is generated behind the scenes and submitted to the server for verification.</p><p>Graphical authentication approaches are easier for users to remember than complex passwords and they are faster for users to perform on smartphones and tablets than typing an alphanumeric password. For this reason, they are a good method for adding a layer of security or a one-time password without inconveniencing users.</p><h3>Risk-based authentication</h3><p>Organizations requiring even stronger security should consider integrating a risk engine with their authentication solutions. Using behavioral and contextual risk profiling, risk engines can dynamically trigger additional layers of authentication only when needed. This increases security without inconveniencing users because users will rarely encounter the additional steps. Risk-based authentication solutions should identify device reputation, and evaluate the geolocation of the user’s IP address and time of day they are accessing the site.</p><p>Also examine the frequency of the login attempts, which could indicate a brute force attack. If a high-risk or suspicious situation is identified, require an additional authentication step from the user. The additional authentication step could simply be second layer of authentication, or it could be a second factor of authentication.</p><h3>Multifactor Authentication</h3><p>Organizations whose websites or applications could be a high-profile target for hackers should adopt out-of-band, multifactor authentication. Multifactor authentication involves at least two of the following authentication factors:</p><ul><li>Something you know (i.e. a password, secret image categories or other shared secret)</li><li>Something you have (i.e. a mobile phone or authentication token)</li><li>Something you are (i.e. biometrics such as a fingerprint)</li></ul><p>Multifactor authentication solutions that rely on the mobile phone as the second factor are increasingly popular. The most common approach involves sending an authentication code to the user’s phone via an SMS text message and having the user type the code into the web page to authenticate. Knowing that banks often use this approach, cybercriminals are increasingly targeting the SMS channel for attack. Using malicious software they are able to compromise a user’s online account, intercept and reroute the authentication text messages to their own phones, then use the code to gain access to the user’s account.</p><p>A more secure approach is to adopt a multi-layered, multifactor authentication solution that remains completely out-of-band from the web session on the PC. Organizations can use push technology to send an authentication challenge to users’ smartphones. Users must solve the authentication challenge on their phone and send back their response/approval via push technology, which uses a server-to-server communication channel and is more secure than SMS.</p><p>For example, using the image-based authentication approach described earlier, when a user logs into their online bank account on the PC they enter their username and password. Using push technology, the bank sends an image-based authentication challenge to the user’s smartphone. The user must tap the images that fit his secret categories and tap a submit button to send his selection back to the bank for verification. The process remains entirely out-of-band from the web session because there is no data to type into the web page on the PC.</p><p>In addition to being out-of-band, the process is multi-layered and multi-factor. The user must have possession of the registered second factor device (their phone) but also apply a shared secret (knowledge of their secret categories) on the phone. Even if someone else had possession of the user’s mobile phone or intercepted the delivery of the out-of-band authentication challenge, they would not be able to complete the process because they would not know which images to identify.</p><p>When evaluating multifactor authentication solutions that rely on the user’s mobile phone as the second factor, look for solutions that remain completely out-of-band from the web session on the PC and those that use push technology rather than plain text SMS.</p><p><b>Biometrics and Behavioral Biometrics</b></p><p>Biometrics and behavioral biometrics are also increasingly viable authentication options. Most laptops, smartphones and tablets now come with built-in video cameras that can be used for facial recognition, and fingerprint scanners are quite common in mobile and desktop environments. Smartphone applications can be used for voice recognition. However, drawbacks of biometric authentication include the need to maintain the equipment and ‘body parts’ to get accurate readings; biometric ID data must also be stored in databases and is therefore susceptible to theft and forgery.</p><p>Depending upon the type of organization or account being accessed, users may not be willing to provide biometric data for authentication. For example, users may be willing to use a fingerprint scanner to authenticate for their bank account, but not for a social networking or shopping site.</p><p>Behavioral biometrics are technologies that tracks the user’s behavioral patterns such as keystroke speed and mouse movements. These and other behavioral profiling techniques can help to successfully identify individual users, especially when used in conjunction with another authentication factor. Behavioral biometrics are usually analyzed behind the scenes, unnoticed by the user, so they do not inconvenience the user, which helps improve the usability of security.</p><h1>Conclusion</h1><p>Authentication standards on most websites and applications are woefully lacking. Relying solely on passwords puts the organization, its users and its data at risk. Not every website needs multifactor authentication, but most can benefit from using multiple layers of authentication or one-time passwords. User education is also critical for improving authentication. Unless the user clearly understands the reasons for additional authentication requirements, they will find ways to circumvent the policies.</p><p>Finally, it’s important to remember that ‘security’ is a process–organizations must continually re-evaluate security needs, identify areas for improvement and make a security roadmap for future improvements. A website or application can never be completely secure, but developers and security professionals should aim to strengthen security to the point where it will deter most attackers while maintaining ease of use for end-users.</p><div><br
clear="all" /></p><hr
align="left" size="1" width="33%" /><div><p><a
title="" href="#_ednref1">[i]</a> “The password thicket: technical and market failures in human authentication on the web” by Joseph Bonneau and Sören Preibusch</p></div></div><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/strengthen-user-authentication-and-preserve-user-experience/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Build a Responsive, Mobile-Friendly Website From Scratch: CSS stylesheet</title><link>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-css-stylesheet/</link> <comments>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-css-stylesheet/#comments</comments> <pubDate>Tue, 07 May 2013 07:10:27 +0000</pubDate> <dc:creator>Annarita Tranfici</dc:creator> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Discussion]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5731</guid> <description><![CDATA[In the fourth part of her series, Annarita Tranfici introduces the first CSS rules in order to have a general idea of the graphic style that the homepage will display.]]></description> <content:encoded><![CDATA[<p></p><p>In the last article of this series, I’ve shown how to start building a website from scratch with a particular focus on the HTML code and its main elements.</p><p>Now it&#8217;s time to introduce the first CSS rules in order to have a general idea of the graphic style that the homepage of our website will display, especially for the pc-desktop version.</p><p>First of all, before having a look on the rules we have to apply in order to create a particular design for our homepage, let&#8217;s see how it will appear in our browser window (my default browser is Chrome but, with the application of some specific rules, you&#8217;ll be able to obtain the same result for all modern web-browsers).</p><p>The homepage of our totally customizable website should look more or less as following:</p><p><a
href="http://buildmobile.com/files/2013/04/website-screenshot-desktop-version.png"><img
class="wp-image-5732 aligncenter" alt="website-screenshot-desktop-version" src="http://buildmobile.com/files/2013/04/website-screenshot-desktop-version-1024x910.png" width="614" height="546" /></a>As you can see, I have imagined a very big banner to allow the designer to express all his creativity and chosen colors that combine in a clear and positive way (I really love them!). Having said that, let&#8217;s dive deep into the code.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>As for the HTML section, in this case we&#8217;ll proceed step-by-step from the upper part of our layout to the bottom part. The code for the very first part (which includes the elements of banner, newsletter bar and menu) will be shown piece after piece with a very short comment, as for the other items of the page.</p><p>The first one is the banner element, with this code for styling:</p><pre class="brush: css; title: ; notranslate">
#banner
{
   width: 100%;
   margin-top: 0.2em;
}
</pre><p>These first rules simple enough to understand. To space the banner from the top of the browser window we&#8217;re applying a margin of 0.2em and to let our banner-image cover all the width of our browser&#8217;s window, we&#8217;ve set the corresponding rule with a percentage of 100.</p><p>Let&#8217;s go on with the rules for styling our newsletter-box. In this case we have to pay attention for the rules to put on the id and the ones to consider for the class since I have decided, for personal clarity, to not choose different names for elements that substantially indicate the same part. So, for the class we set a background color (which will be the color of the box and a margin-top of 0.2 em&#8211;you&#8217;ll find out why it&#8217;s better to use these kind of measurements for a responsive website in <a
title="Responsive Web Design: Using Fonts Responsively" href="http://buildmobile.com/understanding-responsive-web-design-how-to-manage-fonts/">this</a> article, which will give you a short overview on the most common units used in Web Design) to slightly space the newsletter-box from the banner above.</p><p>The id &#8220;newsletter-box&#8221;, that is the space where we&#8217;ll find the input field and the submit button, has three simple rules, to define the spacing with the box that contains the above-mentioned elements. As you can see, there&#8217;s an id (&#8220;mobile-newsletter-box&#8221;) that seems to be inappropriate to the version we&#8217;re analysing.  Actually, it&#8217;s not so: since there&#8217;ll be a change of view when passing from a pc-desktop version to a tablet version or a mobile-phone one, we have to &#8220;suggest&#8221; to our stylesheet how to perform and display the page elements.</p><p>In this case, as you&#8217;ll see in the next article when we&#8217;ll discuss about the rules to set thinking responsively, the disposition of all the elements characterizing the newsletter bar will totally change. What we have to do now is avoid having the mobile-display shown in the pc-desktop version. To achieve this result, we simply set to the rule &#8220;display&#8221; the none parameter.</p><p>A nice effect I&#8217;d like to talk about is the transition I have applied to the white box where the user inserts his e-mail to receive news. Setting to the element a transition, the resulting effect is an enlargement of the box; the other thing I&#8217;ve done is to indicate the time that this has to last. This is a CSS3 rule that creates a simple and light movement with a very pleasant output.</p><p>The last rule to discuss is the width applied when the newsletter box is clicked: setting this to 17em, the box will appear larger than usual.</p><pre class="brush: css; title: ; notranslate">
.newsletter-box
{
   background-color: #c32526;
   margin-top: 0.2em;
}
#newsletter-box
{
   margin-top: 0.5em;
   height: 1.8em;
   padding: 0.3em;
}
#mobile-newsletter-box
{
   display: none;
}
#newsletter-email
{
   width: 12em;
   -webkit-transition: all 1s;
   -moz-transition: width 1s;
   -o-transition: width 1s;
   -ms-transition: width 1s;
   transition: width 1s;
}
#newsletter-email:focus
{
   width: 17em;
}
</pre><p>Let&#8217;s go on now analyzing our navigation bar. To delete the default bullet points of our menu list, we set the parameter to none, while to center it we recourse to the well-known rule &#8220;text-align: center&#8221;. Then we change the padding and the margin rules to the size that seems to be appropriate for our purpose. To let the elements of the list appear one after another horizontally, we change the display from the default setting &#8220;block&#8221; to &#8220;inline&#8221; and also, in this case, specify the margin parameters.</p><p>Now, it&#8217;s time to have a look at the rules applied to the link elements: as font, I&#8217;ve chosen &#8220;Bebas Neue&#8221; (you can download it <a
title="Bebas Neue font" href="http://www.dafont.com/bebas-neue.font">here</a>). I&#8217;ve set a font-size of 1.3 em, removed the underlining with the rule &#8220;text-decoration: none&#8221; and set the color I preferred. This color changes when the cursor moves on the menu items and, moreover, when the user clicks on the link of the page he desires to visit, there&#8217;s a 3D effect, and you can obtain it setting the rule &#8220;position: relative&#8221; on the menu links and the parameters top and left on the active state of the same element. In this way, you&#8217;ll have a slight movement that will give you the impression of a clickable 3D button.</p><pre class="brush: css; title: ; notranslate">ul.menu-list
{
   list-style-type: none;
   padding: 0;
   margin: 1em 0em;
   text-align: center;
}
li.menu-item
{
   display: inline;
   margin: 0em 1.5em;
}
a.menu-item-link
{
   font-family: &quot;Bebas Neue&quot;,Calibri,Arial,Helvetica,sans-serif;
   font-size: 1.3em;
   text-decoration: none;
   color: #c31f05;
position: relative;
}
a.menu-item-link:hover
{
   color: #000000;
}
a.menu-item-link:active
{
   top: 0.1em;
   left: 0.1em;
}
#menu-select
{
   display: none;
}
</pre><p>Now, move on to the general part, that is on the rules applied to elements such as heading, paragraphs, images, boxes appearance and so on. Here is the code with the specifications of the rules for the layout I have thought out, planned and realized.</p><pre class="brush: css; title: ; notranslate">
body
{
   max-width: 1024px;
   margin: 0 auto;
   font-family: &quot;Cwmagic&quot;,Calibri,Arial,Helvetica,sans-serif;
   background-color: #E3E3E3;
   font-size: 1.2em;
   line-height: 1.5em;
}
img
{
   border: 0em;
}
h1,
h2,
h3
{
   text-align: center;
}
.float-left
{
   float: left;
}
.float-right
{
   float: right;
}
.clear-both
{
   clear: both;
}
.shadow
{
   -webkit-box-shadow: 0.4em 0.4em 0.2em #5C5B5B;
   -moz-box-shadow: 0.4em 0.4em 0.2em #5C5B5B;
   -o-box-shadow: 0.4em 0.4em 0.2em #5C5B5B;
   -ms-box-shadow: 0.4em 0.4em 0.2em #5C5B5B;
   box-shadow: 0.4em 0.4em 0.2em #5C5B5B;
   margin-right: 0.4em !important;
}
.long-box,
.small-box
{
   background-color: #cdcdcd;
   padding: 0em 0.3em;
   margin: 0em;
   margin-bottom: 1em;
}
.small-box
{
   width: 47%;
}
p
{
   margin-top: 0;
   margin-bottom: 0.5em;
}
</pre><p>I won&#8217;t explain the rules one by one as for the first part, especially because they are almost all the same. The only thing to which I&#8217;d like you&#8217;d pay attention is the classes float left, float right and clear both; in fact, I&#8217;ve preferred to create a class which &#8220;identifies&#8221; these rules and applies them to the elements in the HTML code rather than repeating the elements. Another element worthy of note is the CSS3 rule &#8220;<a
title="box-shadow" href="http://www.css3.info/preview/box-shadow/">shadow</a>&#8220;.</p><blockquote><p>This property allows designers to easily implement multiple drop shadows (outer or inner) on box elements, specifying values for color, size, blur and offset.</p><p>It can accept a comma-separated list of shadows, each defined by 2-4 length values (specifying in order the horizontal offset, vertical offset, optional blur distance and optional spread distance of the shadow), an optional color value and an optional ‘inset‘ keyword (to create an inner shadow, rather than the default outer shadow).</p><p>Browser support is growing of late with Mozilla (Firefox), Webkit (Safari/Chrome/Konqueror), Opera and the IE9 Platform Preview all offering a decent implementation of the specification.</p></blockquote><p>Let&#8217;s conclude this article with the rules applied to elements present in the footer, that is the footer itself and the bar containing the icons for the linking to the most important social networks&#8217; profile.</p><pre class="brush: css; title: ; notranslate">
#main-footer
{
   background-color: #c32526;
   text-align: center;
}
.social-bar a
{
   text-decoration: none;
   margin-right: 3em;
}
</pre><p>Finally, let&#8217;s see how to manage fonts in the CSS stylesheet, bearing in mind that Internet Explorer requires a different format for the fonts, that is &#8220;eot&#8221;. Here is the code.</p><pre class="brush: css; title: ; notranslate">
/*
 ***********************************
     FONT FOR INTERNET EXPLORER
 ***********************************
*/
@font-face
{
   font-family: &quot;Bebas Neue&quot;;
   src: url(../css/bebasneue.eot);
}
@font-face
{
   font-family: &quot;Palatino Linotype&quot;;
   src: url(../css/pala.eot);
}
/*
 ***********************************
       FONT FOR OTHER BROWSERS
 ***********************************
*/
@font-face
{
   font-family: &quot;Bebas Neue&quot;;
   src:
      local(&quot;Bebas Neue&quot;),
      local(&quot;Bebas Neue&quot;),
      url(&quot;../css/bebasneue.ttf&quot;);
}
@font-face
{
   font-family: &quot;Palatino Linotype&quot;;
   src:
      local(&quot;Palatino Linotype&quot;),
      local(&quot;Palatino Linotype&quot;),
      url(&quot;../css/pala.ttf&quot;);
}
</pre><h2>Conclusion</h2><p>In this article we&#8217;ve seen the basic rules to create a simple layout for a website. After concentrating on the pc-desktop version, in the next part we&#8217;ll see which are the rules to apply to make this layout responsive.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-css-stylesheet/feed/</wfw:commentRss> <slash:comments>0</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: Semantic HTML</title><link>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-dive-into-the-code/</link> <comments>http://www.sitepoint.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]]></category> <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 wireframe thinking responsively and—consequently—how a responsive design can adapt to three target layouts: Default (PC desktop), Portrait Tablet, and Smartphone. We’ve seen how to arrange [...]]]></description> <content:encoded><![CDATA[<p></p><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:<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></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;/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><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-dive-into-the-code/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: Design a Mockup</title><link>http://www.sitepoint.com/build-a-responsive-mobile-friendly-website-from-scratch-design-a-mockup/</link> <comments>http://www.sitepoint.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]]></category> <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 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 [...]]]></description> <content:encoded><![CDATA[<p></p><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.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></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://buildmobile.com/files/2013/04/pc-desktop-mockup1.png"><img
class="alignnone  wp-image-5672" alt="pc-desktop-mockup" src="http://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://buildmobile.com/files/2013/04/tablet-mockup.png"><img
class="alignnone  wp-image-5673" alt="tablet-mockup" src="http://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://buildmobile.com/files/2013/04/smartphone-mockup.png"><img
class="alignnone  wp-image-5674" alt="smartphone-mockup" src="http://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><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.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://www.sitepoint.com/building-a-responsive-website-introduction/</link> <comments>http://www.sitepoint.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]]></category> <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 a more concrete work. We&#8217;ve seen that there are many aspects to take into consideration throughout the responsive design process: screen size, operating platform, user [...]]]></description> <content:encoded><![CDATA[<p></p><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.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></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><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.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://www.sitepoint.com/why-mobile-apps-need-privacy-policies-and-how-to-get-yours-right/</link> <comments>http://www.sitepoint.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[Mobile]]></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 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 [...]]]></description> <content:encoded><![CDATA[<p></p><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.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></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><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.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://www.sitepoint.com/understanding-responsive-web-design-cross-browser-compatibility/</link> <comments>http://www.sitepoint.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]]></category> <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 variety of screen sizes. In today&#8217;s article, I&#8217;ll focus on imagery management from another point of view, that is cross-browser compatibility. During the creation of [...]]]></description> <content:encoded><![CDATA[<p></p><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.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></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><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.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://www.sitepoint.com/build-a-multilingual-survey-app-in-android-os/</link> <comments>http://www.sitepoint.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> <category><![CDATA[Mobile]]></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 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 [...]]]></description> <content:encoded><![CDATA[<p></p><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.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></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://buildmobile.com/files/2013/03/aalang.png" width="207" height="303" /><br
/> <img
class="aligncenter size-full wp-image-5612" alt="aalang2" src="http://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://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><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.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://www.sitepoint.com/build-contacts-app-with-html5-css-javascript-wakanda-studio/</link> <comments>http://www.sitepoint.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]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Discussion]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[HTML5 Tutorials & Articles]]></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 style manipulation. Nobody was convinced to use it for intensive programming applications due to its limitations and several serious security problems. But, in the past [...]]]></description> <content:encoded><![CDATA[<p></p><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.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></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://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://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://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://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://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://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://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://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://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://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://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://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://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://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 applicationServer_SidegetPhoneContact SolutiongetPhoneContact.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><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.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://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-finishing-the-app/</link> <comments>http://www.sitepoint.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]]></category> <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 function left and the Cordova configuration file that we will use to set properties for our project and define several directives for the Adobe PhoneGap [...]]]></description> <content:encoded><![CDATA[<p></p><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-65957"></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.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></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://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://bitbucket.org/AurelioDeRosa/currency-converter" target="_blank" class="broken_link">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://bitbucket.org/AurelioDeRosa/currency-converter" target="_blank" class="broken_link">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><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.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://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-rate-updates/</link> <comments>http://www.sitepoint.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]]></category> <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 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 [...]]]></description> <content:encoded><![CDATA[<p></p><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:<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></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><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.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://www.sitepoint.com/understanding-responsive-web-design-how-to-manage-images/</link> <comments>http://www.sitepoint.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]]></category> <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 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 [...]]]></description> <content:encoded><![CDATA[<p></p><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-65956"></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.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></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><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.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> <item><title>5 Essential Elements of a Successful Business App</title><link>http://www.sitepoint.com/5-essential-elements-of-a-successful-business-app/</link> <comments>http://www.sitepoint.com/5-essential-elements-of-a-successful-business-app/#comments</comments> <pubDate>Mon, 25 Feb 2013 18:10:57 +0000</pubDate> <dc:creator>Kyle Sanders</dc:creator> <category><![CDATA[Android Discussion]]></category> <category><![CDATA[iOS Discussion]]></category> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Web Discussion]]></category> <category><![CDATA[Windows Phone Discussion]]></category> <category><![CDATA[Business]]></category> <category><![CDATA[Discussion]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5531</guid> <description><![CDATA[The ever-growing population of smartphone owners has led more and more companies to develop mobile business apps to cater to customers and generate leads. What used to be an optional &#8220;nice to have&#8221; mobile component is now becoming an essential part of any business, regardless of industry. But, to build a great mobile presence for [...]]]></description> <content:encoded><![CDATA[<p></p><p>The ever-growing population of smartphone owners has led more and more companies to develop mobile business apps to cater to customers and generate leads. What used to be an optional &#8220;nice to have&#8221; mobile component is now becoming an essential part of any business, regardless of industry. But, to build a great mobile presence for your business, you need a lot more than just the realization that you need an app or the decision to build it. Many poorly-conceived small business mobile apps end up as nothing more than an expensive novelty.</p><p>If you don&#8217;t take time to develop a fully-functional, properly-planned app that offers real value to users, all of your efforts will go wasted. We&#8217;ve learned some important lessons through creating countless mobile apps for small businesses; here are the five essential elements that play pivotal roles in the building of successful business apps.</p><h3>A Professional Developer</h3><p>The first thing your mobile app needs is a professional developer. It&#8217;s tempting to view mobile development as a commodity—it&#8217;s not. Seeking the lowest price for your development (and ending up with the lowest quality) can result in major headaches, glaring software glitches, and brand damage. You should never try to cut corners and costs by hiring someone with little experience in mobile application development. Professional, seasoned developers know the ins and outs of mobile operating systems, version control, optimization, best practices, and the latest web technologies. With a veteran (or veterans) working on your project, you&#8217;ll be assured a mobile app that&#8217;s a strong benefit to your business instead of a frustrating hindrance.</p><h3>An Adequate Budget</h3><p>You can&#8217;t start the development process without an adequate development budget; having a half-built app and no funding to finish is arguably worse than having never started. You&#8217;d be amazed at just how complicated it can be for a developer to breathe life into what initially seemed like a simple design. The process often involves a designer, a project manager, and input from executives, marketers, and salesman. You have consider all of the moving parts of your design and how much it will cost to incorporate all of the multifaceted needs of each stakeholder. If your budget is not enough to cover these development costs, you might not be able to make your app as functional as you wanted it to be, and both customers and stakeholders could end up disappointed.</p><h3>Original Content That Will Keep Your Customers Coming Back</h3><p>You are not going to have thousands of customers lining up to download your app—even if it&#8217;s free—unless you have something truly valuable to offer. Many businesses expect a lot of exposure from their app without a real investment into the app&#8217;s content. Others make a substantial commitment of content upfront, but then consider the app a <em>completed</em> project instead of an <em>ongoing</em> project. Neither is a good long-term strategy for maintaining and leveraging a mobile app to benefit your business. You&#8217;ll want a steady stream of special offers, updates, or other reasons to revisit your business app.</p><p>A good litmus test of your app&#8217;s appeal is to simply play the role of the prospective user. Ask yourself why you&#8217;d notice the app, why you&#8217;d want or need it, and what would cause you to keep it on your mobile device&#8217;s small screen and limited storage. If you struggle with the answers, you may want to remedy the problem with original, valuable, regular content updates.</p><h3>Careful Branding to Grab Your User&#8217;s Attention</h3><p>You will need to find ways to grab your user&#8217;s attention the first time they load your business application. Clever loading screens and new user tutorials are a great way to do this, but you need to make sure you do not go overboard with your introduction efforts. Mobile users are inherently busy multitaskers; you never want to keep them from their purpose without good reason. You are <em>not</em> dealing with a captive audience; Users can leave your app or turn off their phone at a moment&#8217;s notice. You&#8217;ve already won the competition for their attention and gotten your app installed on their device; offer them some carefully-designed welcome messaging that&#8217;s just as easy to use as it is to bypass.</p><h3>Loading Indicators that Keep Your Users in the Loop</h3><p>There is nothing more frustrating than trying to navigate through an application just to be directed to a blank, unresponsive screen. One of the first thing your users will think if you do not have loading indicators is that the application is frozen or malfunctioning. Loading indicators and animations let your users know that the app is fully-functional, working, and waiting on your phone&#8217;s network or hardware to respond. A process indicator might be even more useful, because it tells the user how much of the process has been completed and the specific steps involved. This may sound like a small, inconsequential addition to an app, but in the minds of many users, it&#8217;s the difference between a buggy, crash-prone app and a snappy, responsive, user-friendly one.</p><h3>Conclusion</h3><p>&#8220;We need a mobile app&#8221; is just the beginning of your planning process. You need to take time to think about what you want your users to accomplish and how you design to suit their needs. Do not cut corners during your design, development, funding, or testing—your shortcuts will likely be noticed in a very public way. But, if you test your app thoroughly, design it thoughtfully, and keep the essentials in mind, it will be a valuable asset worthy of your time, investment, and brand.</p><p><em>Do you have any essentials to add to the list? Have you worked on mobile projects that lack thorough planning? Do you have any hard-earned development lessons to share?</em></p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/5-essential-elements-of-a-successful-business-app/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Build Menus in Android with Java and XML: Contextual and Popup Menus</title><link>http://www.sitepoint.com/build-intuitive-extensible-menus-in-android-with-java-and-xml-2/</link> <comments>http://www.sitepoint.com/build-intuitive-extensible-menus-in-android-with-java-and-xml-2/#comments</comments> <pubDate>Fri, 22 Feb 2013 12:32:41 +0000</pubDate> <dc:creator>Abbas Suterwala</dc:creator> <category><![CDATA[Android]]></category> <category><![CDATA[Android Discussion]]></category> <category><![CDATA[Android Tutorials]]></category> <category><![CDATA[Mobile]]></category> <guid
isPermaLink="false">http://buildmobile.com/?p=5485</guid> <description><![CDATA[In the previous article in this series, we learned how to create standard options menus for your Android app using XML or built directly through Java programming. Besides these typical options menus, Android developers can also create specialized menu types such as the contextual menu and the popup menu within their Android apps. A contextual [...]]]></description> <content:encoded><![CDATA[<p></p><p>In the <a
title="Build Intuitive, Extensible Menus in Android With Java and XML: Introduction" href="http://buildmobile.com/menus-in-android/" target="_blank">previous article in this series</a>, we learned how to create standard options menus for your Android app using XML or built directly through Java programming. Besides these typical options menus, Android developers can also create specialized menu types such as the <strong>contextual menu</strong> and the <strong>popup menu</strong> within their Android apps.</p><p>A <strong>contextual menu</strong> is a menu which affects (or appears on) specific items and generally has options that affect only that particular item. The contextual menu in Android appears when a user presses and holds on a specific item. The contextual menu will be presented to the user, and he or she will be able to choose from the array of options.</p><p>Android also lets you create <strong>popup menus</strong> in your application. A popup menu is a modal menu that can be programmed to appear when a button is clicked.</p><p>In this article, we are going to demonstrate how we can create contextual and popup menus within our Android apps.</p><h3>Registering the View for Contextual Menus<b> </b></h3><p>To start, we are going to build a basic example by creating a contextual menu on one single item. A contextual menu is created within a view, so we will register that view for the contextual menu first and then move on to the menu itself.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p>Bu, lets first create an Android activity within layout main.xml file as follows:</p><pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;fill_parent&quot;
android:orientation=&quot;vertical&quot;
&gt;
&lt;TextView
android:id=&quot;@+id/&lt;span style=&quot;text-decoration: underline;&quot;&gt;Username&lt;/span&gt;&quot;
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;60dip&quot;
android:text=&quot;Hold For contextual menu&quot;
android:padding=&quot;4dip&quot;
/&gt;
&lt;EditText
android:id=&quot;@+id/usernameEdittext&quot;
android:layout_height=&quot;wrap_content&quot;
android:singleLine=&quot;true&quot;
android:background=&quot;#&lt;span style=&quot;text-decoration: underline;&quot;&gt;ffffff&lt;/span&gt;&quot;
android:layout_width=&quot;400dip&quot; &gt;
&lt;/EditText&gt;
&lt;/LinearLayout&gt;
</pre><p>In the above layout, we have just created one TextView and one edit view within the layout. Now, we&#8217;ll write the code for the activity is as follows:</p><pre class="brush: java; title: ; notranslate">
package com.contexualandpopupmenudemon;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.EditText;
public class ContextualAndPopupmenuDemo extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText UserNameEditText = (EditText)findViewById(R.id.usernameEdittext);
registerForContextMenu(UserNameEditText);
}
}
</pre><p>In the activity above, we have overridden the onCreate method in which we have set the main layout. Then, we find the EditText using the function findViewById.</p><p>Once we get the EditView, we call registerForContextMenu on that view. This function registers the view and allows us to display a context menu.</p><h3>Creating the Contextual Menu<b> </b></h3><p>Once we have registered the view for a contextual menu, we will create a menu in XML for our contextual menu. To create a menu in XML format, create a contextual.xml file in the menu folder of your resources. Add the following code to your contextual.xml file:</p><pre class="brush: xml; title: ; notranslate">
&lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
&lt;item android:id=&quot;@+id/fetch&quot;
android:title=&quot;Fetch New &lt;span style=&quot;text-decoration: underline;&quot;&gt;Username&lt;/span&gt;&quot; /&gt;
&lt;item android:id=&quot;@+id/check&quot;
android:title=&quot;Check For Duplicate&quot; /&gt;
&lt;/menu&gt;
</pre><p>In our contextual menu, we have created two items: one to acquire usernames, and one to check for duplicates. Once we have created the menu in XML format, we will have to override the onCreateContextMenu function as follows:</p><pre class="brush: java; title: ; notranslate">
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
if (v.getId()==R.id.usernameEdittext) {
getMenuInflater().inflate(R.menu.contextual, menu);
}
}
</pre><p>In this code, we determine if the ID of the view is the specific one we are looking for. If it is, we initiate the menu as described in <a
title="Build Menus in Android with Java and XML: Introduction" href="http://buildmobile.com/menus-in-android/" target="_blank">the previous article in this series</a>.</p><p>Now, if you hold for a few seconds on the EditText, you should be able to see the following contextual menu:</p><p
style="text-align: center"><a
href="http://buildmobile.com/build-intuitive-extensible-menus-in-android-with-java-and-xml-2/image001-13/" rel="attachment wp-att-5486"><img
class="size-full wp-image-5486 aligncenter" alt="image001" src="http://buildmobile.com/files/2013/02/image001.png" width="568" height="518" /></a></p><p>If you don’t want to build this menu in XML, you can build an identical menu in Java using the following programming:</p><pre class="brush: java; title: ; notranslate">
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
if (v.getId()==R.id.usernameEdittext) {
menu.add(0, 1, 0, &quot;Fetch New Username&quot;);
menu.add(0, 2, 0, &quot;Check For Duplicate&quot;);
}
}
</pre><p>Now, if you run the app again, you will see a very similar menu to what we created through XML formatting.</p><h3>Responding to Clicks on Contextual Menus</h3><p>To respond to user selections on our contextual menus, we must implement the onContextItemSelected function within our activity. To respond to our menu items, we implement the onContextItemSelected as shown below:</p><pre class="brush: java; title: ; notranslate">
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.fetch:
showToast(&quot;Fetch Clicked&quot;);
return true;
case R.id.check:
showToast(&quot;Check Clicked&quot;);
return true;
default:
return super.onContextItemSelected(item);
}
}
public void showToast(String message) {
Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT);
toast.show();
}
</pre><p>In the programming above the menu item that&#8217;s chosen is passed to the function onContextItemSelected, and we can call getItemId to identify which menu item was clicked. Then, we call the appropriate function (that matches the user&#8217;s choice) to handle this menu click . Currently, the only functionality that results from selecting a menu option is a toast with a message. So, now if you click on the &#8220;Fetch New Username&#8221; option, you should see the following:</p><p
style="text-align: center"><a
href="http://buildmobile.com/build-intuitive-extensible-menus-in-android-with-java-and-xml-2/image003-6/" rel="attachment wp-att-5487"><img
class="size-full wp-image-5487 aligncenter" alt="image003" src="http://buildmobile.com/files/2013/02/image003.png" width="568" height="518" /></a></p><h3>Creating a Popup Menu</h3><p>A popup menu (supported only after Android API level 11) is a modal menu that you can create and display near a view. For demonstration purposes, we will create a popup menu when an &#8220;Options&#8221; button is clicked on the activity. First, let’s add this &#8220;Options&#8221; button to our layout.xml file, as shown below.</p><pre class="brush: xml; title: ; notranslate">
&lt;Button
android:id=&quot;@+id/&lt;span style=&quot;text-decoration: underline;&quot;&gt;btnoptions&lt;/span&gt;&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;Options&quot;
android:onClick=&quot;CreatePopupMenu&quot;/&gt;
</pre><p>This will create the necessary &#8220;Options&#8221; button for our popup menu. When selected, the function CreatePopupMenu will be called. Then, we create a new popup.xml file in our res/menu folder with the following content:</p><pre class="brush: xml; title: ; notranslate">
&lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
&lt;item android:id=&quot;@+id/option1&quot;
android:title=&quot;Option 1&quot; /&gt;
&lt;item android:id=&quot;@+id/option2&quot;
android:title=&quot;Option 2&quot; /&gt;
&lt;/menu&gt;
</pre><p>In our popup.xml file above, we have created two menu items: option1, and option2. Then, we add the function CreatePopupMenu to our activity using the following programming:</p><pre class="brush: java; title: ; notranslate">
public void CreatePopupMenu(View v) {
PopupMenu mypopupmenu = new PopupMenu(this, v);
MenuInflater inflater = mypopupmenu.getMenuInflater();
inflater.inflate(R.menu.&lt;i&gt;popup&lt;/i&gt;, mypopupmenu.getMenu());
mypopupmenu.show();
}
</pre><p>Above, we create a new PopupMenu object and then include our popup.xml menu within it. Then, we show the popup menu by calling the <em>show</em> function.</p><p>So, now if we run the app and click on our new &#8220;Options&#8221; button, you should be able to see the menu shown below.</p><p
style="text-align: center"><a
href="http://buildmobile.com/build-intuitive-extensible-menus-in-android-with-java-and-xml-2/image005-7/" rel="attachment wp-att-5488"><img
class="size-full wp-image-5488 aligncenter" alt="image005" src="http://buildmobile.com/files/2013/02/image005.png" width="568" height="518" /></a></p><h3>Responding to Popup Menu Clicks<b> </b></h3><p>To respond to popup menu clicks, you have to set a menu item click listener, which is a class that implements the OnMenuItemClickListener interface. It has one method in it—onMenuItemClick. We will implement this interface in our activity itself. So, we must change the class definition as follows:</p><pre class="brush: java; title: ; notranslate">
public class ContextualAndPopupmenuDemo extends Activity implements OnMenuItemClickListener{
Then we change CreatePopupMenu and implement onMenuItemClick as follows
public void CreatePopupMenu(View v) {
PopupMenu mypopupmenu = new PopupMenu(this, v);
mypopupmenu.setOnMenuItemClickListener(this);
MenuInflater inflater = mypopupmenu.getMenuInflater();
inflater.inflate(R.menu.popup, mypopupmenu.getMenu());
mypopupmenu.show();
}
@Override
public boolean onMenuItemClick(MenuItem arg0) {
switch (arg0.getItemId()) {
case R.id.option1:
showToast(&quot;Option1 Clicked&quot;);
return true;
case R.id.option2:
showToast(&quot;Option2 Clicked&quot;);
return true;
default:
return super.onContextItemSelected(arg0);
}
}
</pre><p>In the function, onMenuItemClick—depending on the menu item clicked—will display the appropriate toast. If we click on one of the menu options, we should see the toast shown below.</p><p><img
class="aligncenter size-full wp-image-5491" alt="image008" src="http://buildmobile.com/files/2013/02/image008.jpg" width="568" height="518" /></p><h3>Conclusion<b> </b></h3><p>In Android, you can create a wide variety of menus for various settings and circumstances. You can define those menus in an XML file, or you can add them via java code directly. You can respond to the menu items depending on the type of menu (contextual, popup) you have created. When you offer application-wide settings, you should typically use the &#8220;Options&#8221; menu. If you want to offer specialized options or settings for a particular item, then you probably should use the contextual menu.</p><p>For the contextual menu to appear, the user has to hold for some time on the desired option. If you want to show a menu on some other user action such as a click of a button or tapping an image, you can use popup menu for that purpose as well. Regardless of your app idea or the functionality that you have in mind, you now have the tools needed to capture user input and build a sensible, intuitive app experience. Have fun while implementing these various menu types in your next Android app.</p><div
class='after-content-widget-1'><div
id="sitepointcontextualcontentmanagerwidget-5" class="widget widget_sitepointcontextualcontentmanagerwidget">&nbsp;</div></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-intuitive-extensible-menus-in-android-with-java-and-xml-2/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <series:name><![CDATA[Build Menus in Android with Java and XML]]></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 52/80 queries in 0.372 seconds using memcached
Object Caching 2213/2363 objects using memcached

Served from: www.sitepoint.com @ 2013-05-13 13:37:58 --