Created
May 28, 2012 22:03
-
-
Save piceman/2821401 to your computer and use it in GitHub Desktop.
how easy to disable the variable reference of titamium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Titanium.UI.currentWindow; | |
// | |
// BASIC SWITCH | |
// | |
var s=Ti.UI.createTableView({ | |
}); | |
var ss = Ti.UI.createScrollView({ | |
top : 0, | |
bottom : 0, | |
width : Ti.UI.FILL, | |
contentHeight : 'auto', | |
backgroundColor: 'red' | |
}); | |
var basicSwitchLabel = Titanium.UI.createLabel({ | |
text : 'Basic Switch value = false', | |
color : '#999', | |
font : { | |
fontFamily : 'Helvetica Neue', | |
fontSize : 15 | |
}, | |
textAlign : 'center', | |
top : 10, | |
height : 'auto' | |
}); | |
var basicSwitch = Titanium.UI.createSwitch({ | |
value : false, | |
top : 30 | |
}); | |
basicSwitch.addEventListener('change', function(e) { | |
basicSwitchLabel.text = 'Basic Switch value = ' + e.value + ' act val ' + basicSwitch.value; | |
}); | |
// | |
// CHANGE SWITCH | |
// | |
var changeButton = Titanium.UI.createButton({ | |
title : 'Change Switch', | |
height : 40, | |
width : 200, | |
top : 90 | |
}); | |
changeButton.addEventListener('click', function() { | |
if(basicSwitch.value === false) { | |
basicSwitch.value = true; | |
} else { | |
basicSwitch.value = false; | |
} | |
}); | |
// | |
// HIDE/SHOW SWITCH | |
// | |
var hideShowButton = Titanium.UI.createButton({ | |
title : 'Hide/Show Switch', | |
height : 40, | |
width : 200, | |
top : 140 | |
}); | |
var hidden = false; | |
hideShowButton.addEventListener('click', function() { | |
if(hidden === true) { | |
basicSwitch.show(); | |
hidden = false; | |
} else { | |
basicSwitch.hide(); | |
hidden = true; | |
} | |
}); | |
// | |
// SWITCH IN TOOLBAR | |
// | |
var toolbarButton = Titanium.UI.createButton({ | |
title : 'Toggle Switch in Toolbar', | |
height : 40, | |
width : 200, | |
top : 240 | |
}); | |
var inToolbar = false; | |
toolbarButton.addEventListener('click', function() { | |
if(!inToolbar) { | |
var toolbarSwitch = Titanium.UI.createSwitch({ | |
value : false | |
}); | |
win.setToolbar([toolbarSwitch]); | |
inToolbar = true; | |
} else { | |
inToolbar = false; | |
win.setToolbar(null, { | |
animated : true | |
}); | |
} | |
}); | |
// | |
// SWITCH IN NAVBAR | |
// | |
var navbarButton = Titanium.UI.createButton({ | |
title : 'Toggle Switch in Navbar', | |
height : 40, | |
width : 200, | |
top : 190 | |
}); | |
var inNavbar = false; | |
navbarButton.addEventListener('click', function() { | |
if(!inNavbar) { | |
var navbarSwitch = Titanium.UI.createSwitch({ | |
value : false | |
}); | |
win.setRightNavButton(navbarSwitch); | |
inNavbar = true; | |
} else { | |
win.rightNavButton = null; | |
inNavbar = false; | |
} | |
}); | |
// | |
// SWITCH TO TITLE CONTROL | |
// | |
var titleButton = Titanium.UI.createButton({ | |
title : 'Toggle Swtich in Title', | |
height : 40, | |
width : 200, | |
top : 290 | |
}); | |
var inTitle = false; | |
titleButton.addEventListener('click', function() { | |
if(inTitle) { | |
win.titleControl = null; | |
win.title = 'Switch'; | |
inTitle = false; | |
} else { | |
var titleSwitch = Titanium.UI.createSwitch({ | |
value : false | |
}); | |
win.titleControl = titleSwitch; | |
inTitle = true; | |
} | |
}); | |
if(Titanium.Platform.name == 'iPhone OS') { | |
win.add(basicSwitchLabel); | |
win.add(basicSwitch); | |
win.add(changeButton); | |
win.add(hideShowButton); | |
win.add(toolbarButton); | |
win.add(navbarButton); | |
win.add(titleButton); | |
} | |
if(Titanium.Platform.osname == 'android') { | |
// | |
// CHECKBOX | |
// | |
ss.add(basicSwitchLabel); | |
ss.add(basicSwitch); | |
ss.add(changeButton); | |
ss.add(hideShowButton); | |
var checkBox = Titanium.UI.createSwitch({ | |
style : Titanium.UI.Android.SWITCH_STYLE_CHECKBOX, | |
title : "CheckBox: " + false, | |
value : false, | |
top : 190, | |
left : 60 | |
}); | |
checkBox.addEventListener('change', function(e) { | |
checkBox.title = "CheckBox: " + e.value; | |
}); | |
// | |
// TOGGLEBUTTON W/ TITLE | |
// | |
var titleSwitch = Titanium.UI.createSwitch({ | |
style : Titanium.UI.Android.SWITCH_STYLE_TOGGLEBUTTON, | |
titleOff : "LO", | |
titleOn : "HI", | |
value : false, | |
top : 240 | |
}); | |
ss.add(checkBox); | |
ss.add(titleSwitch); | |
//以下註解互換, hide/show switch就會失去效果 | |
//unremark this line to enable hide/show switch function | |
//win.add(ss); | |
//prove the titanium cannot find the ui reference under scrollview in tableviewrow | |
var data=[]; | |
var row=Ti.UI.createTableViewRow(); | |
row.add(ss); | |
data.push(row); | |
s.setData(data); | |
win.add(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
replace this file with switch.js in KitchenSink-2.0.1GA
you will find how unstable of Titanium when it is used for android..
Don't make same mistake lke me..