750 likes | 921 Views
B.Y.O.L.: Titanium - Create Mobile Training as a Native App Using Javascript. Jeff Batt eLearning Brothers Product Development Manager. Jeff Batt eLearning Brothers Product Development Manager. My Approach. www.kinetic-media.com. twitter.com/jeffbatt01. www.youtube.com/jeffbatt01.
E N D
B.Y.O.L.: Titanium - Create Mobile Training as a Native App Using Javascript Jeff Batt eLearning Brothers Product Development Manager Jeff Batt eLearning Brothers Product Development Manager
My Approach www.kinetic-media.com twitter.com/jeffbatt01 www.youtube.com/jeffbatt01 • How to guy - Focus on how you use the tools • Everyone is on a different level - I’m starting at the beginning • Tutorials about everything will be found on my blog (www.kinetic-media.com)
Download Files Files to download: http://kinetic-media.com/downloads-titanium/
Session Objectives • What is Appcelerator Titanium? • Playing sound • Where to get Titanium • Playing video • Windows and views • Swiping events • Creating labels • Creating image views • Creating a button • Creating a switch • Adding interactivity • Creating tables • Adding interactivity in tables
Appcelerator Titanium jQuery Mobile & Phonegap Differences between Titanium & Phonegap
Alloy VS Classic Alloy Classic VS
Alloy - MVC index.xml index.tss index.js
Starting a New Project Classic: Alloy:
Creating a Window Classic Code: app.js //Establish the window and color var window = Titanium.UI.createWindow({ backgroundColor:'red' }); //Open the window window.open();
Creating a Window Alloy Code: index.xml <Alloy> <Window class="container"> </Window> </Alloy> index.tss ".container": { backgroundColor:"red" }
Windows and Views View 1 Window 1 View 2 View 3
Different Types of Views Image View Window 1 Table View Scroll View
Analogy - Creating Objects then Adding to Window Get the Actor Get the Object var actor = Ti.UI.createView({ });
Analogy - Creating Objects then Adding to Window Add Attributes to Actor - Makeup - Costume - etc Add Attributes to the Object - Width - Height - etc var actor = Ti.UI.createView({ backgroundColor:'red', width:100, height:100, top:20 });
Analogy - Creating Objects then Adding to Window Add the actor to the stage/camera Add object to the window or view var actor = Ti.UI.createView({ backgroundColor:'red', width:100, height:100, top:20 }); window.add(actor); image.addEventListener('click', function(){ alert('This is a test'); })
Analogy - Creating Objects then Adding to Window XML - Get the Actor <Alloy> <Window class="container"> <ImageView id="actor" onClick="doClick" image="images/Checkmark.png" /> </Window> </Alloy> TSS - Define Attributes "#actor":{ top: 10, width: 260, height: 95 } JS - Script what the actor does function doClick(e) { //Tell the actor what to do }
Creating a View Classic Code: app.js //Create the view and it's attributes var view1 = Ti.UI.createView({ backgroundColor:'red', width:100, height:100, top:20 }); //Add the view to the window or view window.add(view1);
Creating a View Alloy Code: index.xml <Alloy> <Window class="container"> <View id="view" /> </Window> </Alloy> index.tss ".container": { backgroundColor:"white" }, "#view": { backgroundColor:"red", width: 50, height: 50, top: 10 }
Adding Objects to a View Classic Code: app.js //Create the view and it's attributes var view1 = Ti.UI.createView({ backgroundColor:'red', width:100, height:100, top:20 }); //Create the object and its attributes var view2 = Ti.UI.createView({ backgroundColor:'black', width: 20, height: 20, top: 10 }); //Add the second object to the view not the window view1.add(view2); //Add the view to the window or view window.add(view1);
Adding Objects to a View Alloy Code: index.xml <View id="view"> <View id="view2"></View> </View> index.tss "#view": { backgroundColor:"red", width: 50, height: 50, top: 10 } "#view2": { backgroundColor:"black", width: 20, height: 20, top: 5 }
Adding Content to Views - Creating Labels Classic Code: app.js //This is the code to create a label var label1 = Ti.UI.createLabel({ color:'#999', text:'This is a text', font:{fontSize:20, fontfamily:'Helvetica Neue'}, textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER, width: Ti.UI.SIZE, height: Ti.UI.SIZE, }) //You then add your label to the window or view window.add(label1)
Adding Content to Views - Creating Labels Alloy Code: index.xml <Label id="label1">This is a text</Label> index.tss "#label1": { top: 30, textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER } "Label": { width: Ti.UI.SIZE, height: Ti.UI.SIZE, color: "#000" }
Adding Content to Views - Creating Labels Alloy Code (Option 2): index.xml <Label id="label1" color="#900" text="A simple label" textAlign="Ti.UI.TEXT_ALIGNMENT_CENTER" top="30" width="Ti.UI.SIZE" height="Ti.UI.SIZE" />
Adding Content to Views - Image View Classic Code: app.js //Create the image and point to the file in a folder var image = Ti.UI.createImageView({ image: 'images/Checkmark.png', //You can also add position or other attributes }) //Add the image to the window or view window.add(image);
Adding Content to Views - Image View Alloy Code: index.xml <ImageView id="image" image="images/Checkmark.png" /> index.tss "#image": { } **NOTE** Alloy assets have to be within the assets folder
Adding Event Listeners Classic Code: app.js var image = Ti.UI.createImageView({ image: 'images/Checkmark.png', }) window.add(image); image.addEventListener('click', function(){ alert('This is a test'); })
Adding Event Listeners Alloy Code: index.xml <ImageView id="image" onClick="doClick" image="images/Checkmark.png" /> index.js function doClick(e) { alert("This is a test"); }
Adding Content to Views - Creating a Button Classic Code: app.js var button = Ti.UI.createButton({ title:'Click Me', top: 10, width: 100, height: 50 }); window.add(button); button.addEventListener('click', function(){ alert('You clicked me') })
Adding Content to Views - Creating a Button Alloy Code: index.xml <Button id="button" onClick="doClick" title="Click Me" /> index.js function doClick(e) { alert("This is a test"); } index.tss "#button":{ top: 10, width: 100, height: 50 }
Adding Content to Views - Creating a CUSTOM Button Classic Code: app.js var button = Ti.UI.createButton({ title:'Click Me', //Establish Up image backgroundImage:'images/btn_up.png', //Establish Selected image backgroundSelectedImage: 'images/btn_down.png', top: 10, width: 260, height: 95 }); window.add(button); button.addEventListener('click', function(){ alert('You clicked me') })
Adding Content to Views - Creating a CUSTOM Button Alloy Code: index.xml <Button id="button" onClick="doClick" title="Hello"/> index.js function doClick(e) { alert("Hello"); } index.tss "#button":{ backgroundImage: 'images/btn_up.png', backgroundSelectedImage: 'images/btn_down.png', top: 10, width: 260, height: 95 } **NOTE** Alloy assets have to be within the assets folder
Adding Content to Views - Creating a Switch Classic Code: app.js var basicSwitch = Ti.UI.createSwitch({ value:true, }) window.add(basicSwitch); basicSwitch.addEventListener('change', function(){ alert('Switch Value: '+ basicSwitch.value) })
Adding Content to Views - Creating a Switch Alloy Code: index.xml <Switch id="basicSwitch" value="true" onChange="outputState"/> index.js function outputState(e) { alert('Switch Value: '+ e.value); }
Adding Content to Views - Creating a Text Field Classic Code: app.js var textField = Ti.UI.createTextField({ borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, color:’#336699’, top: 10, left: 10, width: 250, height: 60 }) window.add(textField);
Adding Content to Views - Creating a Text Field Alloy Code: index.xml <TextField id="textField" /> index.tss "#textField": { borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, color: "#336699", top: 10, left: 10, width: 250, height: 60 }
Creating Tables Classic Code: app.js var tableData = [ {title:'Apples'}, {title: 'Bananas'}, {title: 'Bananas'}, {title: 'Potatoes'} ]; var table = Ti.UI.createTableView({ data: tableData }) window.add(table);
Creating Tables Alloy Code: index.xml <TableView id="table"> <TableViewRow title="Apple"/> <TableViewRow title="Bananas"/> <TableViewRow title="Carrots"/> <TableViewRow title="Potatoes"/> </TableView>
Adding Events to Tables Classic Code: app.js table.addEventListener('click', function(e){ if(e.index == 0){ alert('You clicked 1') } else if (e.index == 1){ alert('You clicked 2') } })
Adding Events to Tables Alloy Code: index.xml <TableView id="table" onClick="tableCheck"> <TableViewRowtitle="Apple"/> </TableView> index.js function tableCheck(e) { if(e.index == 0){ alert('You clicked 1') } else if (e.index == 1){ alert('You clicked 2') } }
Creating Tables Sections Classic Code: app.js var sectionFruit = Ti.UI.createTableViewSection({headerTitle: 'Fruit'}); sectionFruit.add(Ti.UI.createTableViewRow({title:'Apples'})); sectionFruit.add(Ti.UI.createTableViewRow({title:'Bananas'})); var sectionVeg = Ti.UI.createTableViewSection({headerTitle: 'Veggies'}); sectionVeg.add(Ti.UI.createTableViewRow({title:'Carrots'})); sectionVeg.add(Ti.UI.createTableViewRow({title:'Potatoes'})); var table = Ti.UI.createTableView({ data: [sectionFruit, sectionVeg] }) window.add(table);
Creating Tables Sections Alloy Code: index.xml • <TableView id="table"> • <TableViewSection id="sectionFruit" headerTitle="Fruit"> • <TableViewRow title="Apple"/> • <TableViewRow title="Bananas"/> • </TableViewSection> • <TableViewSection id="sectionVeg" headerTitle="Vegetables"> • <TableViewRow title="Carrots"/> • <TableViewRow title="Potatoes"/> • </TableViewSection> • </TableView>
Creating Tabs Classic Code: app.js var tabsGroup = Titanium.UI.createTabGroup(); //Create the Win1 var win1 = Titanium.UI.createWindow({ backgroundColor:'red' }); var tab1 = Titanium.UI.createTab({ icon: '/images/44-shoebox.png', title: 'Reference', window: win1 }); var win2 = Titanium.UI.createWindow({ backgroundColor:'green' }); var tab2 = Titanium.UI.createTab({ icon: '/images/46-movie-2.png', title: 'Sample', window: win2 }); tabsGroup.addTab(tab1); tabsGroup.addTab(tab2); tabsGroup.open();
Creating Tabs Alloy Code: index.xml <TabGroup> <Tab title="Tab 1" icon="KS_nav_ui.png"> <Window id="window1" title="Tab 1"> <Label>I am Window 1</Label> </Window> </Tab> <Tab title="Tab 2" icon="KS_nav_views.png"> <Window id="window2" title="Tab 2"> <Label>I am Window 2</Label> </Window> </Tab> </TabGroup> index.tss "#window1":{ backgroundColor:"white" }, "#window2":{ backgroundColor:"white" }
Creating a Web View Classic Code: app.js var webView = Ti.UI.createWebView({ url:'http://www.kinetic-media.com/jquery' }); window.add(webView);
Creating a Web View Alloy Code: index.xml <WebView id="webview" url="http://www.kinetic-media.com/jquery" />
Creating a Scroll View Classic Code: app.js var scrollView = Ti.UI.createScrollView({ contentWidth: '80%', contentHeight: 'auto', showVerticalScrollIndicator: true, showHorizontalScrollIndicator: false, height: '80%', width: '80%' }); var view = Ti.UI.createView({ backgroundColor:'#336699', borderRadius: 10, top: 10, height: 2000, width: 1000 }); scrollView.add(view); window.add(scrollView);
Creating a Scroll View Alloy Code: index.xml <ScrollView id="scrollView" showVerticalScrollIndicator="true" showHorizontalScrollIndicator="true" height="80%" width="80%"> <View id="view" backgroundColor="#336699" borderRadius="10" top="10" height="2000" width="1000" /> </ScrollView>
Creating a Scrollable View Classic Code: app.js var win = Ti.UI.createWindow(); var view1 = Ti.UI.createView({ backgroundColor:'#123' }); var view2 = Ti.UI.createView({ backgroundColor:'#246' }); var view3 = Ti.UI.createView({ backgroundColor:'#48b' }); var scrollableView = Ti.UI.createScrollableView({ views:[view1,view2,view3], showPagingControl:true }); win.add(scrollableView); win.open();
Creating a Scrollable View Alloy Code: index.xml <ScrollableView id="scrollableView" showPagingControl="true"> <View id="view1" backgroundColor="#123" /> <View id="view2" backgroundColor="#246" /> <View id="view3" backgroundColor="#48b" /> </ScrollableView>