Created
January 30, 2011 06:05
-
-
Save mogya/802605 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
Titanium.UI.setBackgroundColor('#000'); | |
var tabGroup = Titanium.UI.createTabGroup(); | |
var win = Titanium.UI.createWindow({ | |
title:'10 min twitter client', | |
tabBarHidden:true, | |
backgroundColor:'#fff' | |
}); | |
var tab1 = Titanium.UI.createTab({ | |
window:win | |
}); | |
var textarea = Titanium.UI.createTextArea({ | |
top:0, | |
height:100, | |
borderColor:'black', | |
appearance:Titanium.UI.KEYBOARD_APPEARANCE_DEFAULT, | |
returnKeyType:Titanium.UI.RETURNKEY_SEND | |
}); | |
win.add(textarea); | |
textarea.addEventListener('return',function(){ | |
//status update | |
twitterApi.statuses_update({ | |
onSuccess: function(responce){ | |
alert('tweet success'); | |
Ti.API.info(responce); | |
}, | |
onError: function(error){ | |
Ti.API.error(error); | |
}, | |
parameters:{status: textarea.value} | |
}); | |
}); | |
function formatDate() | |
{ | |
var date = new Date; | |
var datestr = date.getMonth()+'/'+date.getDate()+'/'+date.getFullYear(); | |
if (date.getHours()>=12) | |
{ | |
datestr+=' '+(date.getHours()==12 ? date.getHours() : date.getHours()-12)+':'+date.getMinutes()+' PM'; | |
} | |
else | |
{ | |
datestr+=' '+date.getHours()+':'+date.getMinutes()+' AM'; | |
} | |
return datestr; | |
} | |
var tableView = Ti.UI.createTableView({ | |
top:100 | |
}); | |
win.add(tableView); | |
var border = Ti.UI.createView({ | |
backgroundColor:"#576c89", | |
height:2, | |
bottom:0 | |
}); | |
var tableHeader = Ti.UI.createView({ | |
backgroundColor:"#e2e7ed", | |
width:320, | |
height:60 | |
}); | |
// fake it til ya make it.. create a 2 pixel | |
// bottom border | |
tableHeader.add(border); | |
var arrow = Ti.UI.createView({ | |
backgroundImage:"../images/whiteArrow.png", | |
width:23, | |
height:60, | |
bottom:10, | |
left:20 | |
}); | |
var statusLabel = Ti.UI.createLabel({ | |
text:"Pull to reload", | |
left:55, | |
width:200, | |
bottom:30, | |
height:"auto", | |
color:"#576c89", | |
textAlign:"center", | |
font:{fontSize:13,fontWeight:"bold"}, | |
shadowColor:"#999", | |
shadowOffset:{x:0,y:1} | |
}); | |
var lastUpdatedLabel = Ti.UI.createLabel({ | |
text:"Last Updated: "+formatDate(), | |
left:55, | |
width:200, | |
bottom:15, | |
height:"auto", | |
color:"#576c89", | |
textAlign:"center", | |
font:{fontSize:12}, | |
shadowColor:"#999", | |
shadowOffset:{x:0,y:1} | |
}); | |
var actInd = Titanium.UI.createActivityIndicator({ | |
left:20, | |
bottom:13, | |
width:30, | |
height:30 | |
}); | |
tableHeader.add(arrow); | |
tableHeader.add(statusLabel); | |
tableHeader.add(lastUpdatedLabel); | |
tableHeader.add(actInd); | |
tableView.headerPullView = tableHeader; | |
var pulling = false; | |
var reloading = false; | |
function beginReloading() | |
{ | |
//get tweets | |
twitterApi.statuses_home_timeline({ | |
onSuccess: function(tweets){ | |
tableView.setData([]); | |
for(var i=0;i<tweets.length;i++){ | |
var tweet = tweets[i]; | |
var row = Titanium.UI.createTableViewRow({ | |
height:'auto' | |
}); | |
var photo = Titanium.UI.createImageView({ | |
image:tweet.user.profile_image_url, | |
width:64,height:64, | |
top:5,left:5, | |
borderRadius:5 | |
}); | |
var name = Titanium.UI.createLabel({ | |
text:tweet.user.name, | |
left:75, | |
top:5, | |
height:'auto' | |
}); | |
var text = Titanium.UI.createLabel({ | |
text:tweet.text, | |
left:75, | |
top:30, | |
height:'auto' | |
}); | |
row.add(photo,name,text); | |
tableView.appendRow(row); | |
} | |
endReloading(); | |
}, | |
onError: function(error){ | |
Ti.API.error(error); | |
} | |
}); | |
} | |
function endReloading() | |
{ | |
// when you're done, just reset | |
tableView.setContentInsets({top:0},{animated:true}); | |
reloading = false; | |
lastUpdatedLabel.text = "Last Updated: "+formatDate(); | |
statusLabel.text = "Pull down to refresh..."; | |
actInd.hide(); | |
arrow.show(); | |
} | |
tableView.addEventListener('scroll',function(e) | |
{ | |
var offset = e.contentOffset.y; | |
if (offset <= -65.0 && !pulling) | |
{ | |
var t = Ti.UI.create2DMatrix(); | |
t = t.rotate(-180); | |
pulling = true; | |
arrow.animate({transform:t,duration:180}); | |
statusLabel.text = "Release to refresh..."; | |
} | |
else if (pulling && offset > -65.0 && offset < 0) | |
{ | |
pulling = false; | |
var t = Ti.UI.create2DMatrix(); | |
arrow.animate({transform:t,duration:180}); | |
statusLabel.text = "Pull down to refresh..."; | |
} | |
}); | |
tableView.addEventListener('scrollEnd',function(e) | |
{ | |
if (pulling && !reloading && e.contentOffset.y <= -65.0) | |
{ | |
reloading = true; | |
pulling = false; | |
arrow.hide(); | |
actInd.show(); | |
statusLabel.text = "Reloading..."; | |
tableView.setContentInsets({top:60},{animated:true}); | |
arrow.transform=Ti.UI.create2DMatrix(); | |
beginReloading(); | |
} | |
}); | |
tabGroup.addTab(tab1); | |
tabGroup.open(); | |
Ti.include("lib/twitter_api.js"); | |
//initialization | |
Ti.App.twitterApi = new TwitterApi({ | |
consumerKey:'Kg2v5t0SngQppWn7PsnA', | |
consumerSecret:'wW2zjjygzjFaHbP6EEpPixVa0WITQL2hzyJ5513O98' | |
}); | |
var twitterApi = Ti.App.twitterApi; | |
twitterApi.init(); | |
beginReloading(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment