Created
June 13, 2012 08:37
-
-
Save otarza/2922820 to your computer and use it in GitHub Desktop.
This file contains 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
// this sets the background color of the master UIView (when there are no windows/tab groups on it) | |
Titanium.UI.setBackgroundColor('#000'); | |
// create tab group | |
var tabGroup = Titanium.UI.createTabGroup(); | |
var win = Ti.UI.currentWindow; | |
var alertDialog = Titanium.UI.createAlertDialog({ | |
title : 'System Message', | |
buttonNames : ['OK'] | |
}); | |
var scrollView = Ti.UI.createScrollView({ | |
top : 12, | |
right : 12, | |
bottom : 12, | |
left : 12, | |
backgroundColor : 'black', | |
zIndex : 2, | |
showVerticalScrollIndicator : false | |
}); | |
var arrow = Ti.UI.createView({ | |
backgroundImage : "whiteArrow.png", | |
width : 23, | |
height : 72, | |
top : 0, | |
left : 10 | |
}); | |
/* | |
var vLabel = Titanium.UI.createLabel({ | |
backgroundImage: "whiteArrow.png", | |
width:23, | |
height:60, | |
bottom:10, | |
left:20 | |
}); | |
arrow.add(vLabel);*/ | |
var data = [{ | |
title : "Row 1", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 2", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 3", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 4", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 5", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 6", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 7", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 8", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 9", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 10", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 11", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 12", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 13", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 14", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 15", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 16", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 17", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 18", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 1", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 2", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 3", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 4", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 5", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 6", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 7", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 8", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 9", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 10", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 11", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 12", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 13", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 14", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 15", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 16", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 17", | |
color : '#000', | |
height : 50 | |
}, { | |
title : "Row 18", | |
color : '#000', | |
height : 50 | |
}]; | |
var tableView = Ti.UI.createTableView({ | |
data : data, | |
width : Ti.Platform.displayCaps.platformWidth, | |
height : (51 * data.length), | |
backgroundColor : '#FFF', | |
zIndex : 1, | |
top : 84, | |
scrollable : false | |
}); | |
scrollView.add(arrow); | |
scrollView.add(tableView); | |
// update the offset value whenever scroll event occurs | |
var processing = false; | |
var offset = 0; | |
var HEIGHT = 72; | |
var t = Ti.UI.create2DMatrix(); | |
scrollView.addEventListener('scroll', function(e) { | |
if (e.y != null) { | |
offset = e.y; | |
if (offset == 0) { | |
Ti.API.info('Processing!!'); | |
processing = true; | |
t = t.rotate(-180); | |
arrow.animate({ | |
transform : t, | |
duration : 180 | |
}); | |
} | |
Ti.API.info('offset: ' + offset); | |
} | |
}); | |
// set the initial position of the scrollView's content | |
var init = setInterval(function(e) { | |
Ti.API.info('check if ' + offset + ' = 50'); | |
if (offset == HEIGHT) { | |
Ti.API.info('we have just done what the scrollView\'s contentOffset should be doing'); | |
clearInterval(init); | |
} | |
scrollView.scrollTo(0, HEIGHT); | |
}, 100); | |
// Pull-to-Refresh Listeners | |
var bottomOfScreenOffset = ((51 * 20) - Ti.Platform.displayCaps.platformHeight); | |
var lastRowOffset = bottomOfScreenOffset - HEIGHT; | |
Ti.API.debug("lastRowOffset: " + lastRowOffset + "\n bottomOfScreenOffset: " + bottomOfScreenOffset); | |
scrollView.addEventListener('touchend', function() { | |
if (offset == 0) { | |
Ti.API.info('REFRESH !!!!'); | |
//processing = true; | |
//alertDialog.message = "REFRESH !!!!"; | |
//alertDialog.show(); | |
//scrollView.scrollTo(0, 50); | |
if (processing) { | |
setTimeout(function() { | |
scrollView.scrollTo(0, HEIGHT); | |
processing = false; | |
var t = Ti.UI.create2DMatrix(); | |
arrow.animate({ | |
transform : t, | |
duration : 180 | |
}); | |
alert("here"); | |
}, 2000); | |
} else if (offset < HEIGHT) { | |
scrollView.scrollTo(0, HEIGHT); | |
Ti.API.info('Dont refresh, go back to base'); | |
} | |
} | |
/* | |
else if (offset == bottomOfScreenOffset) { | |
Ti.API.info('LOAD MORE !!!!'); | |
//alertDialog.message = "LOAD MORE !!!!"; | |
//alertDialog.show(); | |
scrollView.scrollTo(0, lastRowOffset); | |
} else if (offset > lastRowOffset) { | |
scrollView.scrollTo(0, lastRowOffset); | |
Ti.API.info('Dont load more, go back to base'); | |
}*/ | |
}); | |
// | |
// create base UI tab and root window | |
// | |
var win1 = Titanium.UI.createWindow({ | |
title : 'Tab 1', | |
backgroundColor : 'black' | |
}); | |
var tab1 = Titanium.UI.createTab({ | |
icon : 'KS_nav_views.png', | |
title : 'Tab 1', | |
window : win1 | |
}); | |
var label1 = Titanium.UI.createLabel({ | |
color : '#999', | |
text : 'I am Window 1', | |
font : { | |
fontSize : 20, | |
fontFamily : 'Helvetica Neue' | |
}, | |
textAlign : 'center', | |
width : 'auto' | |
}); | |
win1.add(scrollView); | |
// | |
// create controls tab and root window | |
// | |
var win2 = Titanium.UI.createWindow({ | |
title : 'Tab 2', | |
backgroundColor : '#fff' | |
}); | |
var tab2 = Titanium.UI.createTab({ | |
icon : 'KS_nav_ui.png', | |
title : 'Tab 2', | |
window : win2 | |
}); | |
var label2 = Titanium.UI.createLabel({ | |
color : '#999', | |
text : 'I am Window 2', | |
font : { | |
fontSize : 20, | |
fontFamily : 'Helvetica Neue' | |
}, | |
textAlign : 'center', | |
width : 'auto' | |
}); | |
win2.add(label2); | |
// | |
// add tabs | |
// | |
tabGroup.addTab(tab1); | |
tabGroup.addTab(tab2); | |
// open tab group | |
tabGroup.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment