Академический Документы
Профессиональный Документы
Культура Документы
Unit 1:
Unit 1: Introducing the Course
1-1
Choose a Framework
You can develop your apps using popular HTML5 mobile
frameworks including
1-2
1-3
Debug your app while it's running on the device, using the integrated
weinre remote debugger.
Intel App Preview is available for iOS, Android, and Windows Phone.
Figure 5: Test your app on physical devices with Intel App Preview
1-4
Android multi-touch
Oauth support
Enhanced audio
Accelerated canvas
1-5
Create input forms that read and submit data to/from an application
server
Test and package your app to run natively on Android and iPhone
devices.
Required Software
The following software is REQUIRED to be installed on your computer:
Intel XDK
http://xdk-software.intel.com/
1-6
Reviews test how well you remember the concepts from the unit.
1-7
1-8
1-9
Beer List
1 - 10
1 - 11
1 - 12
Steps
Download and Install Intel XDK
1 - 13
1 - 14
Unit Summary
The course has been designed assuming that you already understand
HTML, CSS, and some Javascript.
You will build a web application to keep track of your friends with
beer.
1 - 15
Unit 2:
Getting Started with Intel XDK New
Unit Objectives
After completing this unit, you should be able to:
Use the visual designer to create a Hello World page in your app.
Unit Topics
2-1
2013 Intel Corporation.
Native apps are typically distributed via app stores, however, HTML5
apps can also be deployed as mobile web sites that run in a user's
mobile web browser.
2-2
2013 Intel Corporation.
2-3
2013 Intel Corporation.
Designing Apps
As depicted in Figure 1, Develop mode enables you to visually prototype
the look and feel of your application.
While in Design view, you can drag and drop components from the
UI Controls Palette onto the Design Canvas.
2-4
2013 Intel Corporation.
Developing Apps
As depicted in Figure 2, toggling to Code view enables you to modify the
code generated by the visual designer, as well as edit javascript and css
application assets. Code hints appear as you type.
The emulator enables you to simulate your app running on multiple devices
under varying environmental conditions:
2-5
2013 Intel Corporation.
The Geo Location panel allows you to simulate how your app would
behave if it were running from different physical locations. You can
also configure heading, speed, altitude, GPS accuracy, and GPS
timeout. You can even have it replay a route that was saved to a GPS
Exchange Format (GPX) file.
2-6
2013 Intel Corporation.
Figure 5: Upload your app and test it on devices using Intel App Preview
iOS Ad-Hoc
Distribution
Windows 8 Store
Android
Windows Phone 8
Tizen
Amazon
Nook
Figure 7: Intel XDK uses Apache Cordova to convert your web app into
native apps for all popular platforms.
2-8
2013 Intel Corporation.
You can also have XDK New create a distribution package for deployment
across the following web platforms:
WebApp
Enables you to post your code on a local or remote web server, or host
in AppMobi. (Your code may be downloaded as a .zip file)
Chrome
Packages your app for distribution in the Google Chrome store.
Facebook
Packages your app for distribution via the Facebook social network.
2-9
2013 Intel Corporation.
While you are not obligated to use appMobi, it is a convenient resource for
providing the following application support resources:
Live Update enables you to notify users that a new version of your
app is available. You have the option to push app updates immediately
instead of waiting for your users to upgrade at their leisure.
2 - 10
2013 Intel Corporation.
Steps
Create a New Project
11. From the Controls panel, drag a Header and drop it onto the design
canvas.
12. In the Header Settings panel, turn on the checkbox adjacent to the Title
property and enter the following title:
Friends with Beer
2 - 11
2013 Intel Corporation.
15. In the Text Settings panel, change the text to the following:
Welcome to Friends with Beer!
2 - 12
2013 Intel Corporation.
2 - 13
2013 Intel Corporation.
Label
Description
Elements
Resources
Network
Sources
Displays all of the JavaScript files that were loaded into the
browser as part of the request. You can set breakpoints and
step through your code one line at a time. You can also
define watch expressions to keep an eye on the contents of
your variables.
Timeline
Profiles
Audits
Console
2 - 14
2013 Intel Corporation.
As depicted in Figure
13, you can use the
debugger controls to
interactively step
through your code.
You can also set watch
expressions in order to
view how your code
changes the contents of
your variables.
2 - 15
2013 Intel Corporation.
Figure 14: Variables that are output via console.log appear in the Chromium
debugger Console view
Figure 15: Invoking application methods from the Chromium console view.
2 - 16
2013 Intel Corporation.
Figure 16: Add the <script> from the Test tab onto all html pages that you
need to remotely debug.
2 - 17
2013 Intel Corporation.
As depicted in figure 17, after you click the Begin Debugging on Device
button, the weinre extension for the Chromium browser appears, enabling
you to troubleshoot your app as it's runs on your device. The debugger
functions nearly identically to the one that you used in the Emulate panel.
2 - 18
2013 Intel Corporation.
Use the weinre debugger to step through code in your app running on a
physical device.
Steps
Open a Project
10. After the code that you inserted from the prior step, insert a for loop
that loops from 0 to 4:
for (var i=0; i<5; i++) {
}
11. Inside the for loop, insert a statement that outputs the value of the
variable i to the debugging console:
console.log(i);
12. Select File > Save from the code editor's menu.
2 - 19
2013 Intel Corporation.
2 - 20
2013 Intel Corporation.
39. Note that the console output from your mobile app running on your
device appears in the weinre remote debugger console view.
40. Click on the End Debugging Button to end your remote debugging
session.
End of Walkthrough --
2 - 21
2013 Intel Corporation.
Getting Help
Intel XDK New ships with online documentation and sample applications,
and has community support resources available as well. As illustrated by
Figure 19, help features are available by clicking on the yellow question
mark button.
2 - 22
2013 Intel Corporation.
Perhaps the most relevant documentation for this course is the Intel XDK
API documentation, which contains information about available javaScript
methods in the intel.xdk namespace. You can access these resources
directly from:
http://www.html5dev-software.intel.com/documentation/jsAPI/index.html
Figure 21: Documation for the intel.xdk javascript package
This package documents methods that enable you to access the following
resources:
2 - 23
2013 Intel Corporation.
2 - 24
2013 Intel Corporation.
Description
Rolling Can
Flood Puzzle
Springboard
Buttons
2 - 25
2013 Intel Corporation.
Name
Description
App
Framework
Geolocation
Tab Nav
RPN
Calculator
Basic Hybrid
App
Hello World
PhoneGap
Audio
Towers of
Hanoi
Counting
Beads
IQM List
View
2 - 26
2013 Intel Corporation.
The Friends with Beer application that you're going to create uses a similar
navigational structure. You'll review and learn how to apply the techniques
used to create this app later in the course.
Steps
Create a New Project from a Sample
11. Click on the Emulate tab and review how the application runs onscreen. Note the tab-based navigation that's docked to the bottom of the
screen.
12. Click on the Develop tab.
13. Click on the index.html file.
14. Review the structure of the HTML. Note that each page is represented
by a set of logical pages, set off by a <div> tag with data-role=page.
15. Review the structure of the tab bar which manifests from the
<div data-role=footer> markup.
16. Open the file app/tabbedImages.js and review the code. Note that jQM
pages fire an event named pageshow when they appear to a user.
End of Walkthrough --
2 - 27
2013 Intel Corporation.
Unit Summary
Intel XDK New ships with over a dozen sample apps that demonstrate
frequently requested mobile application features.
2 - 28
2013 Intel Corporation.
Unit Review
1. Do you need to install any software other than Intel XDK New in order
to develop, test, build, and deploy a mobile app?
3. Which physical device features can you test with the Emulator?
2 - 29
2013 Intel Corporation.
Unit 3:
Page Layout
Unit Objectives
After completing this unit, you should be able to:
Defining Pages
Adding Content
Unit Topics
3-1
2013 Intel Corporation.
Defining Pages
jQuery mobile uses a combination of HTML tags and HTML5 custom data
properties to implement a page-based architecture for layout. An HTML
file may contain either a single page widget, or multiple page widgets.
Pages are typically indicated by <div> tags with a data-role property equal
to page. Most jQuery Mobile pages, therefore use the the following
structure:
<div data-role="page" id="page1">
<!-- fixed page header -->
<-- page body -->
<!-- fixed page footer -->
</div>
Note: The Intel XDK New visual wysiwyg designer does not support
defining multiple pages within a single .html file.
You'll typically define pages with the following attributes:
Attribute
Description
data-dom-cache
data-theme
3-2
2013 Intel Corporation.
Page Layout
3-3
2013 Intel Corporation.
You can also set button position by applying the ui-btn-right and ui-btn-left
style classes. This is particularly useful if you need to place a single button
on the right of a header as illustrated by the following example:
<div data-role="header">
<h1>Edit Contact</h1>
<a id="btnSave"
data-icon="check"
class="ui-btn-right">Save</a>
</div>
3-4
2013 Intel Corporation.
Page Layout
3-5
2013 Intel Corporation.
3-6
2013 Intel Corporation.
Page Layout
class="ui-btn-active ui-state-persist"
>About</a>
</li>
<li><a href="contacts.html">Contacts</a></li>
<li><a href="beers.html">Beers</a></li>
<li><a href="drink.html">Drink!</a></li>
</ul>
</div>
</div>
class="ui-btn-active ui-state-persist"
>About</a>
</li>
<li><a href="contacts.html"
data-transition="slide">Contacts</a></li>
<li><a href="beers.html"
data-transition="fade">Beers</a></li>
<li><a href="drink.html"
data-transition="none">Drink!</a></li>
</ul>
</div>
</div>
fade
turn
slide
pop
flow
slideup
flip
slidefade
slidedown
none
3-7
2013 Intel Corporation.
You can set the buttons to display horizontally by adding the datatype=horizontal attribute to the controlgroup container as illustrated
below:
Description
data-corners
data-mini
3-8
2013 Intel Corporation.
Page Layout
Defining Buttons
Buttons are coded with standard HTML anchor and input elements, then
enhanced by jQuery Mobile to make them more attractive and useable on a
mobile device. You'll typically use anchor links to define navigation
buttons, reserving input or button elements for form submission.
As previously described, the basic syntax for defining a button is the
following:
<a href="index.html" data-role="button">Home</a>
You can add icons to buttons by applying the data-icon property to the
anchor tag as illustrated below:
<a
href="index.html"
data-role="button"
data-icon="home">Home</a>
Icons may be positioned at the top, left, bottom, or right of the button's text
by setting the data-iconpos property:
<a
href="index.html"
data-role="button"
data-icon="home"
data-icon-pos="top">Home</a>
You can change the button's theme, causing it to display with either a light
background and dark text or a dark background and light text by applying
the data-theme property:
<a
href="index.html"
data-role="button"
data-theme="b"
>Home</a>
3-9
2013 Intel Corporation.
3 - 10
2013 Intel Corporation.
Page Layout
Figure 9: During this lab, you'll Implement tab-style navigation and create
placeholder pages.
Steps
Open a Project
3 - 11
2013 Intel Corporation.
Label : Home
Theme: (b) dark
Icon: home
Icon position: top
11. Click on the button adjacent to the Home button and configure the
following properties:
Label : Friends
Icon: user
Icon position: top
12. Click on the button adjacent to the Friends button and configure the
following properties:
Label : Beers
Icon: heart
Icon position: top
13. Drag an additional button from the Controls > Form panel and drop it
to the far right of the controlgroup in the footer.
14. Configure the following properties:
Label : Drink!
Icon: video
Icon position: top
15. Go to Code view and add the following attributes to the Home
button:
href : index.html
data-transition: slide
href: friends.html
data-transition: slide
href: beers.html
data-transition: slide
href: drink.html
data-transition: fade
3 - 12
2013 Intel Corporation.
Page Layout
20. Click on the Emulate tab. The footer should appear similar to Figure
10 .
24. When prompted, select the jQuery Mobile framework and click
Select.
25. Return to the index.html file
26. Enter Code View
27. Copy the contents of the entire page to your clipboard
28. Return to friends.html
29. Enter Code view
30. Paste the contents of your clipboard into the friends.html file.
31. Cut the following code to your clipboard and paste it into the anchor
tag that points to contacts.html:
data-theme="b"
beers.html
drink.html
3 - 13
2013 Intel Corporation.
38. Confirm that you can navigate between the pages by clicking/tapping
on the footer's navigation bar.
End of Walkthrough
3 - 14
2013 Intel Corporation.
Page Layout
Adding Content
You'll typically implement the page content area as a <div> tag with the
attribute data-role="content", placing it between the page header and
footer as illustrated below:
<div data-role="page" id="page1">
<div data-role="header" data-position="fixed">
<h1>Friends with Beer</h1>
</div>
<div data-role="content">
Hello World
</div>
<div data-role="footer" data-position="fixed">
<!-- footer goes here -->
</div>
</div>
Figure 11: Drag and dropping rows and columns into the content area
Note that as you drag widgets from the Controls pallette, valid drop targets
become highlighted with a cyan colored background in the design canvas.
When you hover over a valid drop target, its color changes to orange.
3 - 15
2013 Intel Corporation.
3 - 16
2013 Intel Corporation.
Page Layout
Adding Text
As depicted in Figure 12, you can add text to page by dragging and
dropping the Text widget from the Controls-Media panel and dropping it
onto the design canvas.
The Text Settings panel enables you to perform the following functions:
3 - 17
2013 Intel Corporation.
Font Size
Font Style
Font Weight
Color
Font Family
Text Decoration
Text Align
Line Height
Style classes that are defined for one element can be applied to other
elements in the WYSIWYG designer.
You'll learn how to extend these styling capabilities via Code View in unit
9.
Adding Images
The IMG widget enables you to add
jpg, png, or gif images to your
content. As depicted in Figure 14,
any images that have been placed in
your project's folder structure may be
selected from the drop-down list in
the IMG Settings panel. You can also
configure Alt text (to meet section
508 accessibility requirements), edit
a visible caption, and set the
generated elements DOM identifier.
Figure 14: Configuring an IMG
widget
3 - 18
2013 Intel Corporation.
Page Layout
Steps
Open a Project
6. From the Controls > Media panel, drag a Text widget and drop it onto
the design canvas, placing it between the header and footer.
7. Open walk3_2/resources/homepagetext.txt in Code view.
8. Copy the contents of the first paragraph of homepagetext.txt to your
clipboard.
9. Open index.html in Design view.
10. In the Design canvas, click on the Text widget.
11. In the Text Settings panel, paste the contents of your clipboard into the
Text field.
Define Typographic Styles
12. In the Text Settings panel, click on the Text button and select New...
13. Enter a style class name of homepage
14. Enter the following properties:
Font-Size:
Font-Family:
Line-Height:
0.9em
sans-serif
normal
3 - 19
2013 Intel Corporation.
15. From the Controls > Media panel, drag an IMG widget and drop it
underneath the Text block on the Design Canvas.
16. Configure the following IMG settings:
Src: Resources/Beer.jpg
Alt: Beer: The cause and solution to all of our problems
17. From the Controls > Media panel, drag a Text widget and drop it onto
the design canvas, placing it directly underneath the image.
18. Open walk3_2/resources/homepagetext.txt in Code view.
19. Starting with the second paragraph, copy the contents of
homepagetext.txt to your clipboard.
20. Open index.html in Design view.
21. In the Design canvas, click on the Text widget.
22. In the Text Settings panel, paste the contents of your clipboard into the
Text field.
Apply the homepagetext Text Style
23. In the Text Settings > Styles panel, click on the Text menu and select
homepagetext as illustrated below:
3 - 20
2013 Intel Corporation.
Page Layout
Unit Summary
The Intel XDK App Designer enables you to lay out your pages using a
rows/column metaphor.
Style classes that are defined for an element can be applied to other
elements within your app.
The App Designer will automatically locate all images that have been
placed within your project folder.
3 - 21
2013 Intel Corporation.
Unit Review
1. Pages do not need to be linked to a mobile javascript framework
(true/false)
3 - 22
2013 Intel Corporation.
Unit 4:
Working with Data
Unit Objectives
After completing this unit, you should be able to:
Unit Topics
4-1
2013 Intel Corporation.
Use the $.ajax() method to read and post external data using
Javascript's native XmlHttpRequest() method.
The success handler receives the data as a javascript object. You do not
need to use the eval() method or an equivalent to parse the JSON into a
native JavaScript object.
Web apps will not be able to make cross-domain requests unless the
remote host supports cross-origin resource sharing (CORS)
4-2
2013 Intel Corporation.
Note that the ? Used in the callback url is replaced at runtime by a jQuery
with a randomly generated set of numbers. JSONP GET requests
therefore typically resemble the following:
Use $.getJSON() whenever you need to retrieve JSON data from a remote
domain that does not support CORS.
4-3
2013 Intel Corporation.
In the preceding code snippet, the pageinit event is triggered once the
index.html page has completed loading in the browser. In jQuery Mobile,
listening for pageinit event should be used in lieu of document.onready().
The pagechange event is triggered whenever an anchor tag is activated by
a user, causing jQM to intercept the request and load the requested html
page. You can parse the second argument returned to the pagechange event
handler to determine the id property contained within the div tag
containing the data-role=page attribute as illustrated below:
<div class="upage" data-role="page" id="page1">
4-4
2013 Intel Corporation.
Encapsulation
Code Reuse
Inside of the JavaScript object, you'll place all of the page's dynamic
properties and methods:
var BeersPage = {
initialized: false,
init: function() {
this.initialized = true;
}
}
Note that in the preceding case, the init() method refers to the initialized
variable using the this scope as both the init() method and the initialized
property are both members of the same object.
You could then invoke the init() method for beersPage through the
following syntax:
BeersPage.init();
4-5
2013 Intel Corporation.
4-6
2013 Intel Corporation.
Steps
Open the Project
8. Inside the <script>, listen for the pageinit event to be triggered by the
index page:
Your code should appear similar to the following:
<script type="text/javascript">
$(document).bind('pageinit', function() {
});
</script>
4-7
2013 Intel Corporation.
9. Inside the event handler function, define a variable named page that
retrieves the file name of the current url. Your code should resemble
the following:
var page = event.target.baseURI.split('/');
page = page[page.length - 1];
10. After the code that you inserted from the prior step, check for the
existence of the global variable App.initialized. If the variable has bot
been defined, set it equal to true and call a method named App.init()
which you will define later in this exercise.
$(document).bind('pageinit', function(event,obj) {
var page = event.target.baseURI.split('/');
page = page[page.length - 1];
if (!App.initialized) {
App.initialized = true;
App.init();
}
}
11. After the code that you inserted from the prior step, insert a switch/case
statement that evaluates the contents of the page variable and checks it
against each of your application's pages.
switch (page) {
case 'index.html' :
break;
case 'beers.html' :
break;
case 'friends.html' :
break;
case 'drink.html' :
break;
}
12. Where indicated by the comment, define an object named App with
the following properties:
initialized: false
beers: null
4-8
2013 Intel Corporation.
14. Define two method for the App object named init() and cacheBeers().
var App = {
initialized: false,
beers: null,
init: function() {
},
cacheBeers: function() {
}
}
15. Invoke the cacheBeers() method from the init() method as illustrated
below:
var App = {
initialized: false,
beers: null,
init: function() {
this.cacheBeers();
},
cacheBeers: function() {
}
}
16. Inside the cacheBeers method, define a local variable named me that
points to the Beers class and set the initialized property to true.
var me = this;
17. Immediately after the code that you inserted from the prior step, make
a JSON-P request to the following URL, placing the result in the Beers
class data property and dumping its results to the debugging console.
http://xdktraining.com/ftxdknew/data/beer.cfc?
method=getBeerList&callback=?
4-9
2013 Intel Corporation.
22. Type the following code in the debugger's console view to output the
list of Beers:
App.beers
--End of Walkthrough--
4 - 10
2013 Intel Corporation.
Grouping Lists
You can create grouped lists as illustrated in Figure 4 by applying the
data-autodividers="true" property to the <ul> entity as illustrated below.
Note the following:
By default, the group name will be the uppercased first character of the
item's text.
<ul
data-role="listview"
data-autodividers="true">
<li><h3>Drucker, Aidan</h3></li>
<li><h3>Drucker, Dylan</h3></li>
<li><h3>Drucker, Steve</h3></li>
<li><h3>Gallerizzo, David</h3>
</li>
</ul>
4 - 11
2013 Intel Corporation.
Define an autodividersSelector
method that dynamically returns the
group name based on list item
properties.
Markup:
Script:
$("#personsList").listview({
autodividers: true,
autodividersSelector: function(li) {
return li.attr("data-lastname");
}
});
$("#personsList").listview("refresh");
Generating html markup for each item and append to the ListView.
4 - 12
2013 Intel Corporation.
-1 if a < b
0 if a == b
1 if b > a
Constructing a Template
Using templates improves code readability while reducing syntax errors
that inevitably result from performing complex multi-variable string
concatenation with the + operator.
While, jQuery 1.x no longer supports built-in template methods, but you
can easily add a substitute by extending JavaScript's String class as
illustrated by the following snippet:
String.prototype.format = function () {
var args = arguments;
return this.replace(
/\{(\d+)\}/g,
function (m, n) { return args[n]; }
);
};
4 - 13
2013 Intel Corporation.
You can then convert the contents of the script to an HTML string using
jQuery's html() method:
var itemTemplate = $("#tplListItem").html();
Now that you've got your template in place, you can easily loop through
your dataset, appending markup to your list. Note that once you have
completed adding list items, you must programmatically refresh the list as
illustrated by the following example:
var list = $('ul#personsList');
list.empty(); // remove all items
for (var i=0; i< data.length; i++) {
var item = data[i];
var str = itemTemplate.format(item.id, item.name);
list.append(str);
}
// redraw the list absolutely REQUIRED!!!
list.listview("refresh");
4 - 14
2013 Intel Corporation.
To add a carat indicator, insert the following into each list item:
<span
class="ui-icon ui-icon-arrow-r ui-icon-shadow"> </span>
4 - 15
2013 Intel Corporation.
Steps
Open the Project
4 - 16
2013 Intel Corporation.
Filter
Auto Dividers
id
15. Save the file and test the application in the emulator. The list should
appear.
Define a List Item Template
16. Where indicated by the comment, define a template for the list items
that you need to dynamically instantiate. Assign an id property to the
template of tplBeerItem The output from the template needs to
contain markup similar to the following:
<li data-value="1" country="United States">
<h3>Samuel Adams Boston Lager</h3>
<span class="ui-li-count">0</span>
</li>
21. Clear the default list items from the list. Your code should appear
similar to the following:
list.empty();
22. After the code that you inserted from the prior step, define a variable
named beerTemplate that points to the html in the tplBeerItem element.
var beerTemplate = $("#tplBeerItem").html();
4 - 17
2013 Intel Corporation.
23. After the code that you inserted from the prior step, loop through the
data retrieved from the JSON-P transaction. Your code should appear
similar to the following:
for (var i=0; i<App.beers.length; i++) {
var item = App.beers[i];
}
26. Save the file and test the application in the emulator. You will need to
test the app by launching the index.html file and then clicking on the
Beers button in the footer. Note that the dividers are not displaying
correctly.
Configure Custom AutoDividers
30. Save the file and re-test in the emulator. Your list dividers should now
contain the names of the countries from where the beers were made.
End of Walkthrough --
4 - 18
2013 Intel Corporation.
Description
window.openDatabase()
WorkerUtils.openDatabase()
Description
string
string
Database version.
string
Display name
long
function
4 - 19
2013 Intel Corporation.
Description
4 - 20
2013 Intel Corporation.
?', [id]);
Attribute
Description
insertId
rowsAffected
rows
4 - 21
2013 Intel Corporation.
Description
code
message
Constant
Code
Description
UNKNOWN_ERR
DATABASE_ERR
VERSION_ERR
4 - 22
2013 Intel Corporation.
Constant
Code
Description
TOO_LARGE_ERR
QUOTA_ERR
SYNTAX_ERR
CONTRAINT_ERR
TIMEOUT_ERR
4 - 23
2013 Intel Corporation.
4 - 24
2013 Intel Corporation.
Steps
Open the Project
The init() method defines two local database tables - beer which
will hold a cached list of beers and friend which will store
extended contact information for your friends.
The runQuery() method executes the structured query language
(SQL) code that you pass into it, passing the results to a callback
function.
The writeRecord() method performs insert and update operations
on the specified table.
The importTable() method copies an array of objects into the
specified database table.
4 - 25
2013 Intel Corporation.
16. Inside the SQL callback function, loop through the data returned from
the sql transaction:
FriendsWithBeerDB.runQuery(sql, function(records) {
for (var i=0; i<records.length; i++) {
}
});
4 - 26
2013 Intel Corporation.
17. Inside the for-loop, append dynamically generated list items to the
ListView. Your code should appear as follows:
FriendsWithBeerDB.runQuery(sql, function(records) {
for (var i=0; i<records.length; i++) {
var item = records[i];
list.append(
beerTemplate.format(
item.id,
item.country,
item.name,
item.thecount
)
);
}
});
19. Save the file and test the app in the emulator. You should see the full
list of beers appear on the Beers tab.
End of Walkthrough
4 - 27
2013 Intel Corporation.
4 - 29
2013 Intel Corporation.
Field
Description
id
displayName
name
nickname
addresses
phoneNumbers
emails
ims
note
photos
categories
urls
You would use the following syntax to output a contact's display name to
an alert box:
onSuccess: function(contacts) {
for (var i=0; i<contacts.length; i++) {
window.alert(contacts[i].displayName);
}
}
4 - 30
2013 Intel Corporation.
Description
formatted
familyName
givenName
middleName
To output a contact's first name followed by their last name, you would use
the following syntax:
onSuccess: function(contacts) {
for (var i=0; i<contacts.length; i++) {
window.alert(
''.concat(
contacts[i].name.givenName,
' ',
contacts[i].name.familyName
)
)
}
}
4 - 31
2013 Intel Corporation.
Description
pref
type
formatted
streetAddress
locality
region
postalCode
country
4 - 32
2013 Intel Corporation.
Description
type
value
pref
4 - 33
2013 Intel Corporation.
4 - 34
2013 Intel Corporation.
Steps
Open the Project
Label:
Icon:
Icon Position:
id:
Import
ui-icon-user
icon only
btnImportContacts
10. Where indicated by the comment, review the Contacts object and its
method's associated comments.
4 - 35
2013 Intel Corporation.
11. Inside the Contacts init() method, define an event listener for the tap
event on the btnImportContacts button.
init: function() {
$("#btnImportContacts").bind("tap", function(e) {
}
}
12. Inside the tap event handler, insert an if-else block that determines
whether the navigator.contacts object exists.
If navigator.contacts does not exist, display an alert() message that
informs the user that the feature is not available.
init: function() {
this.initialized = true;
$("#btnImportContacts").bind("tap", function(e) {
if (navigator.contacts) {
} else {
alert("Function not available");
}
}
}
13. Inside the if-block, insert a window.prompt() that asks the user for the
name of the contact that they want to import. If the user enters a
response, pass it along to the importContacts method of the Contacts
object.
init: function() {
this.initialized = true;
$("#btnImportContacts").bind("tap", function(e) {
if (navigator.contacts) {
var friendName = window.prompt(
"Enter your friend's name",
""
);
if (friendName != null) {
Contacts.importContacts(friendName);
}
} else {
alert("Function not available");
}
}
}
14. Save the file and test in the Emulator. You should see a Function not
available message when attempting to import contacts from the
emulator.
4 - 36
2013 Intel Corporation.
17. After the code that you inserted in the prior step, define a local variable
named options that is a new ContactFindOptions object.
var options = new ContactFindOptions();
18. Set the filter property of the options object to the value of the
argument that was passed into the function.
options.filter=friendName;
19. Set the multiple property of the options object to retrieve multiple
contact records.
options.multiple = true;
20. Define a local variable named fields that contains an array of strings
for the contact information that you need to retrieve (name, address,
phone, email):
var fields = [
"displayName",
"name",
"addresses",
"phoneNumbers",
"emails"
];
22. Inside the onImport method, hide the Please Wait message.
$.mobile.loading( "hide" );
23. After the code that you inserted in the prior step, define the following
local variables:
address = null
phone = null
email = null
count = 0
friend = null
4 - 37
2013 Intel Corporation.
24. After the code that you inserted in the prior step, insert a for-loop to
iterate through the contacts data returned to the function.
for (var i=0; i<contacts.length; i++) {
}
25. Inside the for-loop, insert an if() block that checks if the contact's given
name is not undefined.
if (contacts[i].name.givenName != undefined) {
}
27. After the code that you inserted from the prior step, set the variable
friend equal to an array containing two objects with two properties
name and value.
In the first object, the name should be equal to firstName and the
value property should equal the contact's given name.
In the second object, the name should be equal to lastName and
the value property should equal the contact's family name.
28. After the code that you inserted in the prior step, insert a conditional
that checks for the existence of a contact's address.
if (contacts[i].addresses) {
}
4 - 38
2013 Intel Corporation.
29. Inside the if() block, set the address variable equal to the result from
calling the Contacts.getPreferred() method, passing in the contact's
addresses.
if (contacts[i].addresses) {
address = Contacts.getPreferred(contacts[i].addresses);
}
30. Immediately after the code that you inserted in the prior step, add the
resulting street address and zipcode to the friends array as indicated
below:
if (contacts[i].addresses) {
address = Contacts.getPreferred(contacts[i].addresses);
friend.push(
{ name: "address", value: address.streetAddress}
);
friend.push(
{ name: "zipcode", value: address.postalCode}
);
}
31. After the contact's IF block, insert another conditional that evaluates
whether or not any phone numbers exist for the contact.
if (contacts[i].phoneNumbers) {
}
32. Inside the if() block, push another object onto the friend array that
contains the contact's preferred phone number.
if (contacts[i].phoneNumbers) {
friend.push(
{
name: "phone",
value:
Contacts.getPreferred(contacts[i].phoneNumbers).value});
}
)
}
33. After the if() block that you inserted from the prior steps, insert another
conditional that evaluates whether the contact object has an emails
property.
if (contacts[i].emails) {
}
4 - 39
2013 Intel Corporation.
34. Inside the if() block, push another object containing user's preferred
email address onto the friend array.
if (contacts[i].emails) {
friend.push(
{
name: "email",
value: Contacts.getPreferred(contacts[i].emails).value});
}
)
}
35. Immediately after the last if() block, write the data from the friend
object to your WebSQL database.
FriendsWithBeerDB.writeRecord('friend',null, friend);
36. Immediately outside the for-loop in the onImport() method, output the
value from the count variable to the user in an alert box.
alert(count + " Contacts Imported");
4 - 40
2013 Intel Corporation.
Unit Summary
Web apps will not be able to make cross-domain requests unless the
remote host supports cross-origin resource sharing (CORS)
You can listen for tap events on list items and then programmatically
retrieve properties associated with the item that was tapped.
4 - 41
2013 Intel Corporation.
Unit Review
1. AJAX requests can only be made to the same domain that a web app is
hosted on (true/false).
4. The ListView search filter can only search for data that's visible to the
user.
7. Which hardware resources can only be accessed via the Cordova API?
4 - 42
2013 Intel Corporation.
Objectives
After completing this lab, you should be able to:
Steps
1. Open /lab/lab4/lab4.xdk
2. Open contacts.html
3. Drag a LISTVIEW widget onto the design canvas and configure its
properties.
4. Return to index.html
5. Modify the Contact's displayList() method to output data from the
WebSQL table into the LISTVIEW that you defined from step 3.
6. Modify the onImport() method to refresh the LISTVIEW after your
contacts have been imported.
End of Lab --
4 - 43
2013 Intel Corporation.
Unit 5:
Creating Input Forms
Unit Objectives
After completing this unit, you should be able to:
Creating Forms
Validating Form Input
Persisting Form Data
Unit Topics
5-1
2013 Intel Corporation.
Creating Forms
Intel XDK New supports the following types of form fields:
Checkbox
Date
Number
Checkbox Group
Email Address
Datetime
Flip Switch
Telephone Number
Text
Password
URL
Hidden
Search
Radio
Slider
Select
Radio Group
Text Area
Month
Some of these capabilities are directly supported by the Intel XDK New
GUI as depicted in Figure 1. Others you will need to add using code view.
5-2
2013 Intel Corporation.
5-3
2013 Intel Corporation.
5-5
2013 Intel Corporation.
5-6
2013 Intel Corporation.
Design a form
Steps
Open the Project
Icon:
Icon position:
id:
ui-icon-back
icon only
btnBack
8. Go to Code mode.
9. Locate the anchor tag that was generated for the back button and add
the following attribute:
data-rel="back"
5-7
2013 Intel Corporation.
Icon:
ui-icon-check
Icon Position: Icon only
id:
btnSave
13. From the Controls > Layout panel, drag a Row widget and drop it
onto the center of the design canvas.
14. Configure the following property:
is Form: checked
15. From the Controls > Form palette, drag an Input widget and drop it
onto the Row widget in the Design Canvas.
16. Configure the following properties:
Label:
Type:
Placeholder:
Name:
id:
(unchecked)
text
First Name
firstName
firstName
17. From the Controls > Form palette, drag an Input widget and drop it
directly underneath the First Name field on the Design Canvas.
18. Configure the following properties:
Label:
Type:
Placeholder:
Name:
id:
(unchecked)
text
Last Name
lastName
lastName
19. From the Controls > Form palette, drag an Input widget and drop it
directly underneath the Last Name field on the Design Canvas.
20. Configure the following properties:
Label:
Type:
Placeholder:
Name:
id:
(unchecked)
text
Street Address
address
address
21. From the Controls > Form palette, drag an Input widget and drop it
directly underneath the Address field on the Design Canvas.
22. Configure the following properties:
Label:
(unchecked)
5-8
2013 Intel Corporation.
Type:
Placeholder:
Name:
id:
number
Zip Code
zipcode
zipcode
23. From the Controls > Form palette, drag an Input widget and drop it
directly underneath the Zip Code field on the Design Canvas.
24. Configure the following properties:
Label:
Type:
Placeholder:
Name:
id:
(unchecked)
email
you@you.com
email
email
25. From the Controls > Form palette, drag an Input widget and drop it
directly underneath the email field on the Design Canvas.
26. Configure the following properties:
Label:
Type:
Placeholder:
Name:
id:
(unchecked)
telephone
Tel
phone
phone
27. From the Controls > Form palette, drag a Select widget and drop it
directly underneath the telephone field on the Design Canvas.
28. Configure the following properties:
Label:
Options:
Name:
id:
(unchecked)
Select a Beer
beerId
beerId
init
populateBeerField
34. Review your code to ensure that it appears similar to the following:
5-9
2013 Intel Corporation.
var ContactForm = {
friendId: null,
init: function() {
},
populateBeerField : function() {
}
};
37. After the code that you inserted from the prior step, insert a for-loop
that loops through the beer data that's cached in the variable App.beers.
populateBeerField : function() {
var beerField = $("select#beerId");
for (var i=0; i< App.beers.length; i++) {
}
}
38. Inside the for-loop, insert code that dynamically outputs the data from
App.beers as <option> elements inside of the select widget.
populateBeerField : function() {
var beerField = $("select#beerId");
for (var i=0; i< App.beers.length; i++) {
beerField.append(
'<option value="{0}">{1}</option>'.format(
App.beers[i].id,
App.beers[i].name
)
);
}
}
39. After the for-loop, insert a statement to refresh the display of the select
widget.
beerField.selectmenu("refresh", true);
5 - 10
2013 Intel Corporation.
42. From the Controls > Form palette, drag a button widget and drop it on
the right edge of the page header.
43. Configure the following properties:
Icon:
ui-icon-plus
Icon Position: Icon only
id:
btnAdd
44. Go to Code mode and locate the generated markup for the button.
45. Add the following attributes to the anchor tag that wraps the add
button:
href=contactform.html
data-transition=flip
49. Inside the button tap callback function, set the friendId property in the
ContactForm object to null.
$("#btnAdd").bind("tap", function(e) {
ContactForm.friendId = null;
});
5 - 11
2013 Intel Corporation.
Description
required
remote
minlength
url
date
dateISO
number
digits
creditcard
equalTo
It also comes with extensions to validate other data types as well, including
US phone numbers.
5 - 12
2013 Intel Corporation.
The submitHandler is invoked when the the user presses the form's
submit button and all form fields pass validation.
The rules object defines data validation rules on form fields. In this
case, lastName is the id of a text field.
5 - 13
2013 Intel Corporation.
You can also attach the required validation rule to a field by invoking a
form's validate() method (injected by the plugin):
$( "#myform" ).validate({
rules: {
lastName: {
required: true
}
}
});
5 - 14
2013 Intel Corporation.
5 - 15
2013 Intel Corporation.
As illustrated in the following snippet, you can style the error message by
defining a css class on the label.error selector.
label.error {
float: left;
color: red;
padding-top: .5em;
vertical-align: top;
font-weight:bold
}
5 - 16
2013 Intel Corporation.
Steps
Open the Project
5 - 17
2013 Intel Corporation.
11. After the code that you inserted in the prior step, invoke form.validate
and configure the following rules:
13. Inside the init() method of the ContactForm object, invoke the
initValidation() method.
var ContactForm = {
init: function() {
this.populateBeerField();
this.initValidation();
},
populateBeerField: function() {
// omitted for brevity
},
initValidation: function() {
// omitted for brevity
}
}
5 - 18
2013 Intel Corporation.
id: btnSave
22. Save the file and test the app in the emulator. Clicking the save button
should trigger the display of the error validation messages.
Theme the Error Messages
5 - 19
2013 Intel Corporation.
25. Save the file and re-test the app in the emulator. You should see that
your error messages are now formatted.
End of Walkthrough --
5 - 20
2013 Intel Corporation.
Delete records
$("form#contactform").serializeArray();
5 - 21
2013 Intel Corporation.
Call the form.serialize() method to retrieve all form field values and
serialize them into a single encoded string for posting to the app server.
5 - 22
2013 Intel Corporation.
Steps
Open the Project
8. Drag an Input widget from the Controls > Form palette and drop it
directly underneath the beers select box on the design canvas.
9. Configure the following properties:
10. Go to code mode and add a disabled property to the lat and lng fields.
5 - 23
2013 Intel Corporation.
13. Inside the if() block, use the form.serializeArray() method to serialize
all of the form fields into a local variable named fields.
var fields = form.serializeArray();
14. Immediately after the code that you inserted in the last step, append the
values of the disabled lat and lng fields to the fields array.
fields[fields.length] = {
name: 'lat',
value: $('#lat').val()
};
fields[fields.length] = {
name: 'lng',
value: $('#lng').val()
};
15. Immediately after the code that you inserted in the last step, invoke the
FriendsWithBeerDB.writeRecord() method to transfer the data from
the fields variable into your webSQL database.
FriendsWithBeerDB.writeRecord(
'friend',
this.friendId,
fields,
function() {
}
);
16. Inside the writeRecord() callback function, use the alert() method to
output a message to the user and then reload the contacts.html page.
5 - 24
2013 Intel Corporation.
18. Save the file and test the application in the emulator. You should now
be able to create new contact records!
Attach a tap event listener to the List Items in the
Friends List
20. Inside the event handler, retrieve the numeric identifier in the list item
and transfer its value to the ContactForm.friendId property.
$('#friendsList > li').bind('tap', function(e) {
ContactForm.friendId = this.getAttribute('data-value');
});
21. Immediately after the code that you inserted in the prior step,
programmatically change the page to contactform.html
$('#friendsList li').bind('tap', function(e) {
var ContactForm.friendId = this.getAttribute(
'data-value');
$.mobile.changePage('contactform.html');
});
22. Save the file and test in the emulator. Clicking on an item in the
Friends list should now transfer control to the data entry form.
Load Data Into the Form
24. Inside the loadRecord() method, define an if() block that evaluates
whether the value of the ContactForm.friendId property is null.
loadRecord: function() {
if (this.friendId != null) {
}
}
26. Inside the runQuery callback function, loop through the properties of
the first record that was returned from the database query, transferring
the values from the query result into the form.
loadRecord: function() {
if (this.friendId != null) {
var sql = "select * from friend where id = {0}";
sql.format(this.friendId);
FriendsWithBeerDB.runQuery(sql, function(records) {
var rec = records[0];
for (var i in rec) {
$("#" + i).val(rec[i]);
}
});
}
}
27. Immediately after the for-loop that you entered in the prior step, refresh
the beerId select menu.
$("#beerId").selectmenu("refresh", true);
5 - 27
2013 Intel Corporation.
Unit Summary
Intel XDK New and jQuery Mobile support all HTML5 form element
types.
You can easily adapt the jQuery Validation Plugin to work with jQuery
mobile.
5 - 28
2013 Intel Corporation.
Unit Review
1. The name and id properties of an input field should always be identical
(true/false)
2. Which method do you invoke in order to get the value of a form field?
3. Which method do you invoke in order to set the value of a form field?
4. You must call the refresh method of a text input field after changing its
value (true/false)
5. Which method can you invoke to easily combine the values from all of
your form fields in order to transmit them to a server?
7. Describe how to populate a <select> control with options that are read
dynamically from an application server.
5 - 29
2013 Intel Corporation.
Unit 6:
Adding GEO Features
Unit Objectives
After completing this unit, you should be able to:
Instantiate a map
Unit Topics
6-1
2013 Intel Corporation.
Directions API
Elevation API
Geocoding API
Places API
Regardless of whether you use the free or paid-for versions of the API you
will be limited to a maximum of 10 queries per second per API. You can
purchase more bandwidth on an as-needed basis.
6-2
2013 Intel Corporation.
However, if you wish to track map usage or you need a larger number of
daily Page Views then utilizing the Purchased Key Version. API keys are
tied to both your Google account and the domain name from where your
application will be hosted. The process to obtain an API key can be found
at the following URL:
https://developers.google.com/maps/documentation/javascript/tutorial#api_
key
As noted in the instructions, you are allowed to use the key from any
domain, but it is strongly encouraged to restrict the usage from the
domain(s) you manage.
Your Purchased Key license comes with the following restrictions:
1. 25,000 per Page View per day limit on map loads.
2. The Maps API does not include advertising.
3. Your service must be freely accessible to end users. Read terms of use
for details governing this.
4. You may not alter or obscure the logos or attribution on the map.
5. Maps should not be used to display illegal activity or reveal personal
information
6-3
2013 Intel Corporation.
Take the API key and inject it into the script tag that loads the maps API as
illustrated below:
<!--- load maps API --->
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?
key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE">
</script>
You must specific true or false for the sensor URL parameter,
depending on if the device has Geospatial System (GS) capabilities
or not. You should set this to TRUE for mobile apps..
For cases where you are using the Free Version of the Google Maps
Javascript API V3, the following call would suffice for most solutions:
<!--- load maps API --->
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?
&sensor=FALSE">
</script>
6-5
2013 Intel Corporation.
Each of these libraries has an associated minified version for you to work
with. When implementing for JQM you will use a special minified version
of the main library file jquery.ui.map.full.min.js.
To handle the most basic of map implementations your to implement the
plug-in will look like the following:
<!--- Google Maps / JQuery Plugin --->
<script type="text/javascript"
src="ui/jquery.ui.map.full.min.js">
</script>
6-6
2013 Intel Corporation.
In order to style the map you will either provide in-line styles for the
<div> tag or provide some parameters for the div to constrain the size. In
this example, you could include a <style> block at the top of the file, or
place the style within a CSS file. The entry for the ID 'map_canvas' could
look like this:
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { width: 100%; height: 380px }
</style>
When implementing for mobile you will want pay particular attention to
the map canvas parameters. Depending on how the styles have been
implemented with the application you may have to push the map into a
fixed height.
Instantiating a map with the JQM Google Maps plugin typically requires
you to call a constructor named gmap() as illustrated below. Note the use
of #map_canvas which is used to point the map to our map_canvas
<div> and the use of the mapOptions variable to set some basic
parameters for the map,.
<!-- loading a Google Map using jQuery -->
<script type="text/javascript">
var mapOptions = {
'center': '38.986000000, -76.940131000',
'zoom': 15,
disableDefaultUI: false
};
$('#map_canvas').gmap({
center: mapOptions.center,
mapTypeId: google.maps.MapTypeId.SATELLITE,
zoom: mapOptions.zoom,
disableDefaultUI: mapOptions.disableDefaultUI
});
</script>
6-7
2013 Intel Corporation.
6-8
2013 Intel Corporation.
The value of the map type is case sensitive and coincides with the different
map types you can choose from the standard maps UI.
<!-- Instantiating a map using the Satellite Map type -->
$('#map_canvas').gmap({
'center': mapOptions.center,
'mapTypeId': google.maps.MapTypeId.SATELLITE,
'zoom': mapOptions.zoom,
'disableDefaultUI': mapOptions.disableDefaultUI
});
6-9
2013 Intel Corporation.
Description
streetViewControl
panControl
scaleControl
mapTypeControl
6 - 10
2013 Intel Corporation.
Steps
Open the Project
10. After the code that you inserted in the prior step, add a <script> tag
that loads the jQuery Google Map plugin.
<script type="text/javascript"
src="js/jquery.ui.map.js"></script>
6 - 11
2013 Intel Corporation.
13. From the Controls > Layout palette, drag a ROW widget and drop it
directly underneath the row that you inserted in the prior step.
14. Go to Code view.
15. Locate the markup that was generated for the second row widget and
add an id property with a value of map as illustrated below:
<div class="grid grid-pad urow uib_row_2 row-height-2"
data-uib="layout/row"
id="map">
17. Open index.html in code view. Note that a ContactDetail object has
been defined for you.
18. Inside the ContactDetail object, define an init() method.
19. Inside the init() method, define a local variable named $mapContainer
that points to the map row that you defined in step 15.
var $mapContainer = $("#map");
20. After the code that you inserted in the previous step, use the gmap()
method to instantiate a map that's centered on the lat/lng position that
you noted from step 7.
21. Review your code to ensure that it appears similar to the following:
var ContactDetail = {
friendId: null,
gMap: null,
init: function() {
var $mapContainer = $("#map");
this.gMap = $mapContainer.gmap({
center: new google.maps.LatLng ("38.908696",
"-77.036527"),
zoom: 16
});
}
}
23. In the Contacts.displayList() method, modify the tap event listener for
the friendsList list items to load the contactDetail.html page. Your code
should appear as follows:
$('#friendsList li').bind('tap', function(e) {
ContactForm.friendId = this.getAttribute('data-value');
ContactDetail.friendId = ContactForm.friendId;
$.mobile.changePage('contactdetail.html');
});
24. Save the file and test. Tapping on a list item should display a small
sliver map on the ContactDetail page.
6 - 12
2013 Intel Corporation.
27. Save the file and test in the Emulator. You should see a larger map,
however that still doesn't quite render correctly.
28. Return to index.html in CODE mode.
29. At the bottom of the ContactDetail.init() method, insert a setTimeout()
method that refreshes the map after 500 milliseconds.
setTimeout("$('#map').gmap('refresh')",500);
30. Save the file and test the application in the emulator.
End of Walkthrough --
6 - 13
2013 Intel Corporation.
In the following example illustrates Geocoding and address and storing the
resulting lat/long into a variable. The map is then centered on the specified
position.
<!-- get lat and lng of address -->
var geocoder = new google.maps.Geocoder();
geocoder.geocode(
{
address : '1600 Pennsylvania Ave Washington DC'
},
function(results, status) {
var location;
if(status != google.maps.GeocoderStatus.OK) {
alert("Address not found");
} else {
location = results[0].geometry.location;
}
$('#map_canvas').gmap({
center: location,
zoom: 15,
disableDefaultUI: false
});
});
6 - 14
2013 Intel Corporation.
Steps
Open the Project
6 - 15
2013 Intel Corporation.
12. Go to code view and add the following property to the edit button's
anchor tag:
href=contactform.html
13. Save the file and test the application in your emulator.
Geocode the Address
17. Directly under the code that you inserted from the prior step, call the
geocoder.Geocode method, passing it the address and zip code that the
user entered in the form.
geoCode: function() {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
address : $('#address').val() + " " + $('#zipcode').val()
}, function(results,status) {
});
}
18. Inside the geocoder callback function, insert code to populate the lat
and lng text fields with the resulting geocode data. If the geocding
failed, set the values of the lat and lng field to the empty string. Your
code should appear similar to the following:
geoCode: function() {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
address : $('#address').val() + " " + $('#zipcode').val()
}, function(results,status) {
if(status != google.maps.GeocoderStatus.OK) {
alert("Address not found");
$("#lat").val('');
$("#lng").val('');
} else {
$("#lat").val(results[0].geometry.location.lat());
$("#lng").val(results[0].geometry.location.lng());
}
});
}
6 - 16
2013 Intel Corporation.
20. Save the file and test the app in the Emulator. Editing a contact record
should cause the address to be geocoded with the results getting placed
into the lat/lng input fields.
-- End of Walkthrough --
6 - 17
2013 Intel Corporation.
Using Overlays
Google Maps enables you to add transparency layers to your map that
visualize the following datasets:
Layer
Description
KmlLayer
HeatmapLayer
FusionTablesLayer
TrafficLayer
TransitLayer
WeatherLayer and
CloudLayer
BicyclingLayer
Renders a layer of bike paths and/or bicyclespecific overlays into a common layer. This layer is
returned by default within the DirectionsRenderer
when requesting directions of travel mode
BICYCLING.
PanoramioLayer
6 - 18
2013 Intel Corporation.
With the Panoramio version of the Google Maps API loaded, it becomes a
simple matter to instantiate the map with local photos:
var $mapContainer = $("#map");
$mapContainer.gmap({
center: new google.maps.LatLng ("38.908696", "-77.036527"),
zoom: 16,
callback: function(map) {
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
var pl = new google.maps.panoramio.PanoramioLayer();
pl.setMap(map);
}
});
6 - 19
2013 Intel Corporation.
The bounds attribute identifies whether or not you want the map to
automatically zoom in on the marker when the marker is instantiated.
6 - 20
2013 Intel Corporation.
Steps
Open the Project
6 - 21
2013 Intel Corporation.
9. After the code that you inserted in the prior walkthrough, set the
ContactDetail.mapCenter property equal to the a Google LatLng object
that's set to the lat/lng position retrieved from the database query.
me.mapCenter = new google.maps.LatLng (
records[0].lat, records[0].lng
);
10. Invoke the initMap() method from the WebSQL function callback.
Center the Map and Add Overlays
13. Inside the callback function, instantiate the traffic and panoramio
layers and apply them to the map.
this.gMap = $mapContainer.gmap({
center: this.mapCenter,
zoom: 16,
callback: function(map) {
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
var panoramioLayer = new
google.maps.panoramio.PanoramioLayer();
panoramioLayer.setMap(map);
}
});
6 - 22
2013 Intel Corporation.
14. At the bottom of the map instance callback function, add a map marker
to the center of the map.
this.gMap = $mapContainer.gmap({
center: this.mapCenter,
zoom: 16,
callback: function(map) {
me.map = map;
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
var panoramioLayer = new
google.maps.panoramio.PanoramioLayer();
panoramioLayer.setMap(map);
this.addMarker({
position: map.getCenter()
});
}
});
15. Save the file and test in the emulator using a friend record that has
been successfully geocoded.
-- End of Walkthrough --
6 - 23
2013 Intel Corporation.
Unit Summary
There are multiple licensing options for the Google Maps Javascript
API V3, including a paid for subscription model
To facilitate using Google Maps with jQuery and JQM you can use the
Google Maps V3 plugin for jQuery and jQuery Mobile
6 - 24
2013 Intel Corporation.
Unit Review
1. What do you need to get started using the Google Maps API?
4. What are the types of overlays that you can place on a Google Map?
6 - 25
2013 Intel Corporation.
Unit 7:
Using Device Features
Unit Objectives
After completing this unit, you should be able to:
Launch the device's email client with the subject, body, and to: fields
pre-filled
Unit Topics
7-1
2013 Intel Corporation.
7-2
2013 Intel Corporation.
Description
accuracy
altitude
speed
timestamp
7-3
2013 Intel Corporation.
7-4
2013 Intel Corporation.
Steps
Open the Project
Figure 3: ContactDetail
page layout
7-5
2013 Intel Corporation.
15. After the code that you added in the prior step, define a local variable
named html that processes the contact's information through the
template.
var html = tplContact.format(
this.contactData.firstName,
this.contactData.lastName,
this.contactData.address,
this.contactData.beername
);
16. After the code that you inserted in the prior step, output the contents of
the html variable to the #contactdetails <div> element.
$("#contactdetails").html(html);
7-6
2013 Intel Corporation.
23. Inside the success callback function, convert the device's latitude and
longitude coordinates to a google maps lat/lng object and store the
resulting object into the ContactDetail.currentPosition property.
navigator.geolocation.getCurrentPosition(
function(position) {
me.currentPosition =
new google.maps.LatLng(
position.coords.latitude,
position.coords.longitude
);
},
function(error) {
}
);
24. After the code that you inserted in the prior step, define a local variable
named miles that contains the calculated distance between the device
and the selected friend.
Note: The calcDistance function is defined on line 102 of index.html
var miles = calcDistance(
me.mapCenter.lat(),
me.mapCenter.lng(),
position.coords.latitude,
position.coords.longitude
);
25. Immediately after the code that you inserted in the prior step, output
the value from miles into the <span id=contactdistance> element.
$("#distancetofriend").html(miles + " miles ");
26. Inside the error function callback, output an alert() that indicates that
an error occurred in retrieving the device's coordinates.
27. Where indicated by the comment inside of the ContactDetail.init()
method, invoke the outputDistance function.
28. Save the file and test. Tapping on a contact should now display the
distance between the device and the contact's address as illustrated by
the screenshot in Figure 2.
End of Walkthrough -7-7
2013 Intel Corporation.
Note that the iOS browser will automatically try to detect and hyperlink
strings that match a phone number pattern. You can disable this behavior
by adding the following meta tag to your html:
<meta name = "format-detection" content = "telephone=no">
Syntax
Description
mailto:
&cc=
&bcc=
&subject
&body=
7-8
2013 Intel Corporation.
Description
near
ll
7-9
2013 Intel Corporation.
Argument
Description
sll
spn
Zoom level
saddr
daddr
The following snippet illustrates how to generate a link that, when pressed,
would launch an iOS device's maps app with turn-by-turn directions:
var fromAddr = escape("1400 16th St NW 20036");
var toAddr = escape("2000 K St NW 20036");
var tpl='<a href="maps://?daddr={0}&saddr={1}">Click Me</a>'
location.href = tpl.format(fromAddr,toAddr);
You can also open the native Google Maps app by using the geo: uri. As
illustrated by the following use case, you can pass a latitude and longitude
as a comma-delimited list. The z argument indicates zoom level on a scale
of 1-23 where 1 is the whole earth and 23 is is the highest zoom level.
<a href="geo://?
saddr=20.544,34.34&daddr=20.866,45.345">Navigate!</a>
7 - 10
2013 Intel Corporation.
7 - 11
2013 Intel Corporation.
Add buttons to a UI
Steps
Open the Project
Mini: checked
Icon: ui-icon-phone
Icon Position: Icon only
Id: btnPhone
8. From the Controls > Form panel, drag a BUTTON widget and drop it
onto the design canvas, directly underneath the btnPhone button.
9. Configure the following Button properties:
Mini: checked
Icon: ui-icon-mail
Icon Position: Icon Only
Id: btnMail
10. From the Controls > Form panel, drag a BUTTON widget and drop it
onto the design canvas, directly underneath the btnMail button.
7 - 12
2013 Intel Corporation.
Mini: checked
Icon: ui-icon-navigation
Icon Position: Icon Only
Id: btnNav
15. Inside the ConfigureButtons() method, bind a tap event listener to the
btnPhone button so that it launches the user's phone application and
dials their friend's phone number when tapped.
16. Verify that your code appears similar to the following:
$("#btnPhone").bind("tap", function(e) {
var ph = ContactDetail.contactData.phone;
if (ph != "") {
var telLink = "tel:" + ph;
location.href=telLink;
} else {
alert("Phone Number Not Available");
}
});
7 - 13
2013 Intel Corporation.
24. Launch Intel App Preview on your device, scan the QR code, and test
your app.
Create an Event Listener for the Nav Button
25. After the code that you inserted from step 22, bind a tap event listener
to the #btnNav button. Your code should appear similar to the
following:
$("#btnNav").bind("tap", function(e) {
});
26. Inside the event handler function, insert an if-elseif-else block that
determines whether the user is using an Android device or an iOS
device. If the device is not iOS or Android, output an alert message.
Your code should appear similar to the following:
$("#btnNav").bind("tap", function(e) {
if (/Android/i.test(navigator.userAgent)) {
} else if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
} else {
alert('Device not supported');
return;
}
});
27. Inside the if() block for Android, define a local variable named
mapsUrl and set it equal to the google maps url with GET parameters
named daddr and saddr that point to lat/lng placeholders.
if (/Android/i.test(navigator.userAgent)) {
var mapsUrl = "http://maps.google.com/maps?daddr={0},
{1}&saddr={2},{3}";
}
7 - 14
2013 Intel Corporation.
28. After the code that you inserted in the prior step, replace the
placeholders with the lat/lng coordinates of the contactData and
currentPosition properties of the ContactDetail object.
mapsUrl = mapsUrl.format(
ContactDetail.contactData.lat,
ContactDetail.contactData.lng,
ContactDetail.currentPosition.lat(),
ContactDetail.currentPosition.lng()
);
29. After the code that you inserted from the prior step, launch the url in an
inAppBrowser.
window.open(mapsUrl, '_blank', 'location=yes');
30. Inside the if() block for iOS, define a local variable named mapsUrl
and set it equal to the Apple maps url with GET parameters named
daddr and saddr that point to lat/lng placeholders.
if (/Android/i.test(navigator.userAgent)) {
var mapsUrl = "http://maps.google.com/maps";
} else if (/iPhone|iPad|iPod/i.test(navigator.userAgent)){
var mapsUrl = "maps://?daddr={0},{1}&saddr={2},{3}";
} else {
/* omitted for brevity */
}
31. After the code that you inserted in the prior step, replace the
placeholders with the lat/lng coordinates of the contactData and
currentPosition properties of the ContactDetail object.
mapsUrl = mapsUrl.format(
ContactDetail.contactData.lat,
ContactDetail.contactData.lng,
ContactDetail.currentPosition.lat(),
ContactDetail.currentPosition.lng()
);
32. After the code that you inserted in the prior step, launch the url by
setting the location.href property as illustrated below:
location.href = mapsUrl;
7 - 15
2013 Intel Corporation.
FirefoxOS Devices
(window.DeviceOrientationEvent) {
// insert coolness here
} else {
alert("Aw, Snap! Can't determine device orientation");
}
You can subsequently add an event listener that is triggered whenever the
user's device changes orientation along different axes. In the following
example, the event handler simply outputs the orientation of the device to
the debugging console.
window.addEventListener('deviceorientation', function(e) {
var out = "alpha: {0}, beta: {1}, gamma: {2}";
console.log(out.format(
e.alpha,
e.beta,
e.gamma
));
});
7 - 16
2013 Intel Corporation.
acceleration info:
e.acceleration.x
e.acceleration.y
e.acceleration.z
//
//
//
//
//
//
//
//
rotation rate
e.rotationRate.alpha
e.rotationRate.beta
e.rotationRate.gamma
}, false);
7 - 17
2013 Intel Corporation.
Steps
Open the Project
7 - 18
2013 Intel Corporation.
7 - 19
2013 Intel Corporation.
Urban Airship
PushWoosh
Mixpanel
This course details how to receive push notifications from the PushMobi
service to Android devices.
7 - 20
2013 Intel Corporation.
7 - 21
2013 Intel Corporation.
After registering your project, you'll need to click on the APIs & Auth tab
and enable Google Cloud Messaging for Android as illustrated in Figure 8.
7 - 22
2013 Intel Corporation.
You can retrieve the first item by opening the Browser Key section of your
APIs Web Application detail page as illustrated by Figure 10.
Once you've copied the browser key to your clipboard, you must paste it
into the Api Key (5d) field in the Intel XDK Build > Push screen as
illustrated in figure 7.
7 - 23
2013 Intel Corporation.
The second piece of information the project's identifier, you can get by
clicking on your project's Overview tab as illustrated by figure 11. You'll
need to copy the Project Number and paste it into the Project Id (5C) field
as illustrated in Figure 7.
Note that if your app does not require authentication, you can simply
substitute the device's unique identifer (UUID) for both the username and
password as illustrated below:
intel.xdk.notification.checkPushUser(
intel.xdk.device.uuid,
intel.xdk.device.uuid
);
7 - 24
2013 Intel Corporation.
7 - 25
2013 Intel Corporation.
intel.xdk.notification.getNotificationList()
Returns an array of strings that correspond to the identifiers for
received messages.
intel.xdk.notification.getNotificationData(notification id)
Returns an object containing the properties of the specified notification
Object property names include: msg and data.
intel.xdk.notification.deletePushNotifications(notification id)
Deletes the specified notification
7 - 27
2013 Intel Corporation.
Testing on a Device
Test your app on a physical device by going through the application build
process, install the app on your device, and then access the PushMobi
service under the XDK Services tab as illustrated in figure 13.
7 - 28
2013 Intel Corporation.
Steps
Figure 14: Handling
Push Notifications
7 - 29
2013 Intel Corporation.
7 - 30
2013 Intel Corporation.
32. Immediately after the code that you inserted in the prior step, add an
event listener that invokes the notifications.receivedpush method
when an intel.xdk.notification.push.receive event is fired.
var onDeviceReady=function(){
//hide splash screen
intel.xdk.device.hideSplashScreen();
document.addEventListener(
"intel.xdk.notification.push.enable",
notifications.register,
false
);
document.addEventListener(
"intel.xdk.notification.push.receive",
notifications.receivedPush,
false
);
};
33. Immediately after the code that you inserted in the prior step, check to
see if the device is registered with the PushMobi service. Your code
should appear as follows:
var onDeviceReady=function(){
//hide splash screen
intel.xdk.device.hideSplashScreen();
document.addEventListener(
"intel.xdk.notification.push.enable",
notifications.register,
false
);
document.addEventListener(
"intel.xdk.notification.push.receive",
notifications.receivedPush,
false
);
intel.xdk.notification.checkPushUser(
intel.xdk.device.uuid,
intel.xdk.device.uuid
);
};
7 - 31
2013 Intel Corporation.
Unit Summary
You can retrieve a device's current position by using either the Cordova
API or the build-in navigator.geolocation.getCurrentPosition() method.
You can activate the phone dialer and email client by calling special
URI's.
The devicemotion api enables you to detect changes in how the device
is being handled including shake gestures.
Intel XDK New directly supports the PushMobi front-end for sending
push notifications.
You will need to configure PushMobi for each of the platforms that
you intend to support (iOS, Android, Windows Mobile)
7 - 32
2013 Intel Corporation.
Unit Review
1. You must use the Cordova API to access the device's accelerometer
(true/false)?
2. Describe the process for activating the device's phone dialer and
default email application.
5. Intel XDK apps can only receive push notifications from the PushMobi
service (true/false)
7 - 33
2013 Intel Corporation.
Unit 8:
Integrating Multimedia
Unit Objectives
After completing this unit, you should be able to:
Unit Topics
8-1
2013 Intel Corporation.
Description
autoplay
controls
height
width
loop
preload
poster
Gives the address of an image file that the user agent can
show while no video data is available. The attribute, if
present, must contain a valid non-empty URL potentially
surrounded by spaces. The image is supposed to be a
representative frame from the video.
8-2
2013 Intel Corporation.
Integrating Multimedia
Attribute
Description
src
Browser
WebM
MP4
Android
Yes
Partial
iOS
No
Yes
Blackberry
No
Yes
IE Mobile
No
Yes
Opera Mobile
No
Yes
Chrome Android
Yes
Yes
Firefox Android
Yes
Partial
width="320"
height="240"
controls="true">
Autoplay
Controls
Loop
Preload
Video Caption
Description
paused
ended
readyState
played
seeking
duration
startTime
seekable
8-4
2013 Intel Corporation.
Integrating Multimedia
Read/Write
Property
Description
playbackRate
defaultPlaybackRate
volume
currentTime
muted
Method
Description
load()
pause()
play()
canPlayType(type)
ondurationchange
onplaying
onemptied
onseeked
onerror
onseeking
onloadedmetadata
onstalled
onloadstart
onsuspend
onpause
ontimeupdate
onplay
onvolumechange
onwaiting
8-5
2013 Intel Corporation.
Using these properties and methods, you could create your own
playback/pause button as illustrated by the following snippet:
<head>
<script language="javascript">
enablebuttons = function() {
document.getElementById('playbutton').disabled =
false;
}
playpause = function() {
var objMedia = document.getElementById('mymedia');
var objButton = document.getElementById('playbutton');
if (objMedia.paused) {
objMedia.play();
objButton.value="Pause";
} else {
objMedia.pause();
objButton.value="Play";
}
}
</script>
</head>
<body>
<video
width="320"
height="240"
controls="false"
onCanPlayThrough="enableButtons()"
id="mymedia">
<source src="video1.webm" type="video/webm" />
<source src="video1.mp4" type="video/mp4" />
</video>
<input type="button"
value="Play"
onClick="playpause()"
id="playbutton">
...
</body>
8-6
2013 Intel Corporation.
Integrating Multimedia
8-7
2013 Intel Corporation.
Intel XDK New includes a design-time video widget that will insert the
<iframe> code for you you simply need to enter the embed URL into the
YouTube Settings panel as illustrated in figure 3.
8-8
2013 Intel Corporation.
Integrating Multimedia
Description
autoplay
controls
loop
preload
As illustrated below, you should include both mp3 and Ogg Vorbis files in
order to support the broadest range of devices.
<audio
controls="false"
onCanPlayThrough="enableButtons()"
id="mymedia">
<source src="audiofile.mp3" type="audio/mpeg" />
<source src="audiofile.ogg" type="audio/ogg" />
</audio>
8-9
2013 Intel Corporation.
Description
currentTime
duration
muted
paused
volume
Event
canplay
Description
The media can be played, but may need to pause while
downloading.
ended
play
8 - 10
2013 Intel Corporation.
Integrating Multimedia
The following code snippet illustrates how you could use the HTML5
Audio API to load a sound file.
var musicBuffer = null;
// Fix up prefixing
window.AudioContext = window.AudioContext ||
window.webkitAudioContext;
var context = new AudioContext();
function loadSound(url) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
// Decode asynchronously
request.onload = function() {
context.decodeAudioData(
request.response,
function(buffer) {
musicBuffer = buffer;
},
function (err) {
alert("Could not decode audio file");
}
);
}
request.send();
}
loadSound('100BottlesOfBeerOntheWall.mp3');
Steps
Open the Project
Src:
Autoplay:
Loop:
//player.vimeo.com/video/9608723
checked
checked
11. Return to the drink.html file in Intel XDK New's Design mode.
12. Right-click/Cmd-click on the Vimeo video and select Delete.
13. Right-click/Cmd-click on the Column object and select Delete.
14. From the Controls > Media panel, drag a Video widget and drop it onto
the center of the Design Canvas.
8 - 12
2013 Intel Corporation.
Integrating Multimedia
Webm Src:
Mp4 Src:
Autoplay:
Controls:
Loop:
//xdktraining.com/ftxdknew/friends.webm
//xdktraining.com/ftxdknew/friends.mp4
true
true
true
8 - 13
2013 Intel Corporation.
Unit Summary
You can play audio and video without the user of a plug-in
The HTML5 <audio> and <video> elements have API methods that
you can use to design custom player controls.
You should support both WebM and MP4 video formats to ensure the
highest degree of compatibility.
Intel XDK New has design-time widgets for HTML5 video as well as
playing assets hosted on YouTube.com and Vimeo.com
The HTML5 Audio API contains a very robust set of methods for
handling audio, however, it is not currently supported by the native
Android browser.
8 - 14
2013 Intel Corporation.
Integrating Multimedia
Unit Review
1. What is the purpose of the <video> element's poster property?
2. What video file formats are natively supported by iOS and Android?
8 - 15
2013 Intel Corporation.
Unit 9:
Theming
Unit Objectives
After completing this unit, you should be able to:
Unit Topics
9-1
2013 Intel Corporation.
Rounded borders
Transparency
Downloadable Fonts
Enhanced Typography
Shadowing
Description
-webkit-
-moz-
Mobile Firefox
-o-
Mobile Opera
-ms-
Mobile IE
#c0c0c0; // fallback
linear-gradient(#ffffff,#c0c0c0);
-webkit-linear-gradient(#ffffff,#c0c0c0);
-moz-linear-gradient(#ffffff,#c0c0c0);
-o-linear-gradient(#ffffff,#c0c0c0);
Consequently, most app developers typically use a 3rd party tool to handle
vendor prefixes and make CSS authoring a bit less redundant. Two of those
products are Sass and LESS.
9-2
2013 Intel Corporation.
Theming
About Sass
Sass (Syntactically Awesome Stylesheets) is an extension of CSS that a
allows you to use variables, nested rules, inline imports, with a fully CSScompatible syntax. Sass helps keep large stylesheets well-organized, and
get small stylesheets up and running quickly, particularly with the help of
the Compass style library.
Sass is essentially a stylesheet compiler. You author .scss files (Sassy CSS)
which are then converted into production-ready CSS files by a commandline utility.
Vendor prefixes in Sass are handled through a mechanism called mixins
which are analogous to javascript functions. However, whereas a
JavaScript function typically returns result data based on a set of
parameters, a Sass mixin generates css styles based on passed-in data.
For instance, the following declaration in Sass:
.myCustomClass {
@include border-radius(5px);
}
9-3
2013 Intel Corporation.
About LESS
LESS is similar to Sass it's a dynamic stylesheet language that's designed
to make CSS authoring more robust and easier to maintain. Less is
actually used behind-the-scenes by Intel XDK New to manage app styles.
9-4
2013 Intel Corporation.
Theming
Downloading a Font
CSS3 capable browsers can download fonts and use them to format your
text. Use the @font-face selector to define a font name and associated
download url. You can then reference the font in subsequent style
definitions as indicated below:
@font-face {
font-family: 'Droid Sans';
src: url(fonts/Droid_Sans.ttf);
}
h1{
font-family: 'Droid Sans';
}
Description
text-fill-color
text-stroke-color
text-stroke-width
9-6
2013 Intel Corporation.
Theming
Applying Transparency
CSS 3 allows you to
declare colors as Red,
Green, Blue, and Alpha
transparency. Alpha
transparency is
specified as a numeric value between zero (fully transparent) and one
(opaque). Note that you should also specify a fallback color to use for
browsers that do not support RGBA
<style>
p {
font-family:arial;
font-size: 30px;
color: rgba(255,255,255,0.4);
text-align: center;
padding-top: 30px;
}
#appetizer {
background:url(../images/appetizer.jpg);
width: 475px;
height: 102px
}
</style>
<div id="appetizer"><p>This is a watermark</p></div>
9-7
2013 Intel Corporation.
9-8
2013 Intel Corporation.
Theming
After you select a font, the Google Fonts interface generates the <link>
element and font-family css declarations that you'll use to invoke the font
from within your app. It also displays an estimate impact on page load
time.
9-9
2013 Intel Corporation.
9 - 10
2013 Intel Corporation.
Theming
Steps
Open the Project
10. Return to Intel XDK New and open index.html in Code view
11. At the top of the file, where indicated by the comment, paste the
<link> tag from your clipboard.
9 - 11
2013 Intel Corporation.
12. In the <style> block near the top of the file, add a body and paragraph
tag selector that specifies Rambla as the font-family and bold as the
font-weight.
body, p {
font-family: 'Rambla', sans-serif;
font-weight: bold;
}
9 - 12
2013 Intel Corporation.
Theming
Enhancing Backgrounds
You can enhance the backgrounds of images in CSS3 by specifiying
background gradients and background images for html elements. If you
plan to use background images, consider base-64 encoding them into your
spreadsheet for improved performance.
-webkit-linear-gradient(gold, goldenrod);
-moz-linear-gradient(gold, goldenrod);
-ms-linear-gradient(gold, goldenrod);
-o-linear-gradient(gold, goldenrod);
<style>
body {
background-image: -webkit-gradient(
linear, left top, left bottom,
color-stop(0%,#ffffff),
color-stop(50%,#f20e0e),
color-stop(100%,#3e21ff)
);
// other vendor prefixes omitted for brevity
}
</style>
9 - 13
2013 Intel Corporation.
Most designers choose to create gradients visually, and many use the
Ultimate CSS Gradient generator depicted in Figure 10.
9 - 14
2013 Intel Corporation.
Theming
Specifying background-position
Use the background-position property to set the starting position of a
background image.
Valid settings include the following:
Value
Description
left top
left center
left bottom
right top
right center
right bottom
center top
center center
center bottom
x% y%
xy
Images encoded into a stylesheet typically appear as follows (note that the
image data has been truncated for brevity):
.body {
background-image: url('data:image/png;base64,iVBORw==');
background-size: cover;
background-repeat: no-repeat;
}
9 - 16
2013 Intel Corporation.
Theming
.ui-header-fixed {
background-image: url('resources/headerbackground.png')
}
.ui-header-fixed {
background-image: -webkit-linear-gradient(#9f5628,#5d2f17);
}
.ui-header-fixed {
background-image: url('resources/headerbackground.png'),
-webkit-linear-gradient(#9f5628, #5d2f17) !important;
}
To specify a background image for page headers, attach a backgroundimage property to the .ui-header-fixed class as illustrated in the previous
section.
9 - 17
2013 Intel Corporation.
Steps
Open the Project
/ftIntelXdkNew/walk/walk9_2/walk9_2.xdk
5. In the project file listing, right-click on the css folder and select New
File.
6. Rename the new file to custom.css
7. Open the index.html file in code view
8. Where indicated by the comment, insert a <link> element to load the
custom.css file.
Apply a Background to your Pages
9. Open custom.css
10. Define a style class named .ui-page that sets the following properties:
background-image: url('../resources/background.png');
background-size: cover;
11. Save the file and test in the emulator. You should see that there's now
beer in the background in each page of your app.
9 - 18
2013 Intel Corporation.
Theming
Base-64 Encode an Image
22. Add another class selector to the definition that you inserted in the
prior step named .ui-footer-fixed. Your code should appear as follows:
.ui-header-fixed, .ui-footer-fixed {
background-image: url('../resources/headerbackground.png'),
-webkit-linear-gradient( #9f5628, #5d2f17) !important;
}
23. Save the file and test in the emulator. Your header and footer should
now have a glossy-wood background.
Format the Control Bar
26. Save the file and test. Note that the selected button style class remains
inconsistent with the rest of the footer.
9 - 19
2013 Intel Corporation.
29. Save the file and test. Your output should appear similar to figure 9.
Note that the list views in the Friends and Beers list still need to be
themed.
End of Walkthrough --
9 - 20
2013 Intel Corporation.
Theming
Use the Inspector panel to set global theme settings on the first tab and
tweak the individual style options for each swatch.
When you drag and drop a color from the QuickSwatch panel onto an
element in the preview panel, ThemeRoller automatically calculates
text color and shadow, borders, gradients and button states. The sliders
make it easy to adjust the lightness and saturation of the colors. Use
the Adobe Kuler Swatches to load complementary color palettes from
Adobe's popular color palette sharing site.
Steps
Open the Project
/ftIntelXdkNew/walk/walk9_3/walk9_3.xdk
9 - 22
2013 Intel Corporation.
Theming
End of Walkthrough --
9 - 23
2013 Intel Corporation.
Unit Summary
There are a number of 3rd party tools that you can use to help mitigate
vendor-prefix compatibility issues.
Google and Adobe offer a combined 1000+ fonts freely available for
download.
You can theme your app by overriding jQuery Mobile CSS classes and
by generating a CSS file from ThemeRoller.
9 - 24
2013 Intel Corporation.
Theming
Unit Review
1. What are the benefits and drawbacks to using base-64 encoding?
2. List three tools that you can use to either visually prototype CSS3
styles or mitigate vendor prefix issues.
4. Which style class can you override to set a background image for all of
the pages in your app?
9 - 25
2013 Intel Corporation.
Unit 10:
Going into Production
Unit Objectives
After completing this unit, you should be able to:
Unit Topics
10 - 1
2013 Intel Corporation.
For Android builds, the overview tab will indicate that your app is ready to
be packaged into a production-ready .apk file. However, while this is
technically a true statement, there are a number of settings that you will
want to modify before you proceed with packaging.
The Details panel allows you to set your application title, version,
permissions, orientation, and codebase.
The Plugins panel gives you the ability to upload Cordova plugins for
use in your app.
The Credentials tab lets you enter credentials for working with the
Facebook APIs.
The Push tab configures your app for Push Notification support from
the Google Cloud Messaging Service and PushMobi.
10 - 2
2013 Intel Corporation.
Application Name
The name of the application that is displayed to the user when it's
installed on the device.
Application Version ID
The version number of the app (typically 1.0 for your initial release).
Application Permissions
The device resources that your app uses. Note that if your app tries to
access a resource for which it has not been granted permission, it will
usually fail silently.
Device Configuration
Choose the devices that you'll support. You must select Phone+Tablet
for Android builds.
Operating System
This will default to Android 4.2 with backwards compatibility to
Android 2.3
Code Base
There are three options that impact the size (in bytes) of your buildGold, Lean, and Lean with App Game Interface. Apps that use
Cordova APIs must choose Gold
10 - 3
2013 Intel Corporation.
The splash screen for phones must be a 720w x1280h PNG, JPG, or
JFIF.
The tablet splash screen must be a 1600w x 2560h PNG, JPG, or JFIF
During the build process, the launch icon and splash screens will be
automatically resized, while maintaining the same aspect ratio, to support
different device screen resolutions.
10 - 4
2013 Intel Corporation.
10 - 5
2013 Intel Corporation.
10 - 6
2013 Intel Corporation.
10 - 7
2013 Intel Corporation.
Steps
Open the Project
10 - 8
2013 Intel Corporation.
12. Click the browse button adjacent to the Android Launch Icon field.
13. Select the walk10_1/resources/icon.png file.
14. Click the browse button adjacent to the Phone Splash Screen field.
15. Select the walk10_1/resources/splash.png file.
Create a Build
End of Walkthrough
10 - 9
2013 Intel Corporation.
Unit Summary
You can email .apk files to your users or post them to a web server.
App distribution does not require uploading your app to Google Play.
10 - 10
2013 Intel Corporation.
Unit Review
1. Which device resource permissions can be set within the Build
process?
10 - 11
2013 Intel Corporation.