a

Monday, 10 August 2015

 Titanium basics

Exercise -1

Create a Titanium project using both Studio and the Command Line Interface
Solution
$ ti create -d /tiproject/newworkspace --id com.vmware.sample

Exercise -2

 Run a Titanium project in the simulator/emulator
Solution
$ ti create -d /tiproject/newworkspace --id com.vmware.sample

Exercise -3
Configure app properties such as the SDK version, target platforms
Exercise -4

Pass Context Between Windows using CommonJS

Solution

app/lib/foo.js:
// For a classic Titanium project, save the file to 'Resources/foo.js'
var data = {};
function setData (obj){
    data = obj;
}
function getData () {  
    return data;
}

// The special variable 'exports' exposes the functions as public
exports.setData = setData;
exports.getData = getData;
app/views/index.xml:
<Alloy>
    <Window backgroundColor="blue">
        <Label onClick="openWindow">Open the Red Window!</Label>
    </Window>
</Alloy>
app/controllers/index.xml:
var foo = require('foo');
foo.setData({foobar: 42});
function openWindow () {
    var win2 = Alloy.createController('win2').getView();
    win2.open();
}

$.index.open();
app/views/win2.xml:
<Alloy>
    <Window backgroundColor="red">
        <Label id="label">I am a red window.</Label>
    </Window>
</Alloy>
app/controllers/win2.js:
var foo = require('foo');
$.label.text = foo.getData().foobar;
Exercise -5

Pass Context Between Windows using Alloy Controller
Solution

function openWindow () {

var win2 = Alloy.createController('win2', {foobar: 42}).getView();
win2.open();
}
For Alloy projects, you can also pass in context with the Alloy.createController method and retrieve it in the controller code.
var args = arguments[0] || {};
$.label.text = args.foobar;

No comments:

Post a Comment