Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this sets the background color of the master UIView (when there are no windows/tab groups on it)
- Titanium.UI.setBackgroundImage('Default.png');
- /*globals Titanium, Ti, alert, JSON */
- Titanium.Facebook.appid = "171989632875493";
- Titanium.Facebook.permissions = ['publish_stream', 'read_stream'];
- // capture facebook login/out
- Titanium.Facebook.addEventListener('login', triggerFBLogin);
- Titanium.Facebook.addEventListener('logout', triggerFBLogout);
- //deine windows to be used in application
- var pWin = Titanium.UI.createWindow({className:'pWin',zIndex: 1});
- var lWin = Titanium.UI.createWindow({
- className:'lWin',
- zIndex: 10,
- backgroundImage:'images/loginbox.png',
- height:118,
- width:223,
- bottom:32,
- left: pWin.center.x-115,
- });
- var win1 = Titanium.UI.createWindow({className:'win1',zIndex: 5});
- var win2 = Titanium.UI.createWindow({className:'win2',zIndex: 5});
- var win3 = Titanium.UI.createWindow({className:'win3',zIndex: 5});
- var win4 = Titanium.UI.createWindow({className:'win4',zIndex: 5});
- var loginLabel = Titanium.UI.createLabel({
- text: 'Please login using Facebook to use MyCoCo...',
- color: '#ffffff',
- font: {fontSize:14},
- width: 190,
- height: 40,
- top: 15,
- left: 20
- });
- lWin.add(loginLabel);
- // //global activity indicator
- var toolActInd = Titanium.UI.createActivityIndicator();
- toolActInd.style = Titanium.UI.iPhone.ActivityIndicatorStyle.PLAIN;
- toolActInd.font = {fontFamily:'Helvetica Neue', fontSize:15,fontWeight:'bold'};
- toolActInd.color = 'white';
- toolActInd.message = 'Loading...';
- pWin.setToolbar([toolActInd],{animated:true});
- // Login Button
- lWin.add(Titanium.Facebook.createLoginButton({
- style:'wide',
- bottom:20
- }));
- function checkLogin() {
- if(Titanium.Facebook.loggedIn==false) {
- MyCoCo.win_t1.close();
- MyCoCo.win_t2.close();
- MyCoCo.win_t3.close();
- MyCoCo.win_t4.close();
- MyCoCo.loginWin.open();
- }
- }
- function triggerFBLogin() {
- MyCoCo.loginWin.close();
- }
- function triggerFBLogout() {
- MyCoCo.loginWin.open();
- }
- //not really sure how to do this, so I'll try it this way, check every 10 seconds to ensure login is current
- checkLogin();
- setInterval('checkLogin',10000);
- var bottomTabs = Titanium.UI.createTabGroup({
- height: 40,
- bottom: 0
- });
- // Create the individual tabs with titles and icons
- var tab1 = Titanium.UI.createTab({
- window: win1,
- icon: 'images/icons/112-group.png',
- title:"FB Friends"
- });
- var tab2 = Titanium.UI.createTab({
- window: win2,
- icon: 'images/icons/85-trophy.png',
- title:"My CoCos"
- });
- var tab3 = Titanium.UI.createTab({
- window: win3,
- icon: 'images/icons/86-camera.png',
- title:"From Me"
- });
- var tab4 = Titanium.UI.createTab({
- window: win4,
- icon: 'images/icons/20-gear2.png',
- title:"Settings"
- });
- bottomTabs.addTab(tab1);
- bottomTabs.addTab(tab2);
- bottomTabs.addTab(tab3);
- bottomTabs.addTab(tab4);
- bottomTabs.open();
- tab1.addEventListener('focus',function() {
- win1.open();
- toolActInd.show();
- var tableView = Titanium.UI.createTableView({minRowHeight:100});
- win1.add(tableView);
- // create close button on window nav
- var close = Titanium.UI.createButton({
- title:'Close'
- });
- close.addEventListener('click', function()
- {
- win1.close();
- });
- if (Titanium.Platform.osname == 'iphone' || Titanium.Platform.osname == 'ipad') {
- win1.setRightNavButton(close);
- }
- // run query, populate table view and open window
- var query = "SELECT uid, name, pic_square, status FROM user ";
- query += "where uid IN (SELECT uid2 FROM friend WHERE uid1 = " + Titanium.Facebook.uid + ")";
- query += "order by last_name limit 20";
- Titanium.API.info('user id ' + Titanium.Facebook.uid);
- Titanium.Facebook.request('fql.query', {query: query}, function(r)
- {
- if (!r.success) {
- if (r.error) {
- alert(r.error);
- } else {
- alert("call was unsuccessful");
- }
- return;
- }
- var result = JSON.parse(r.result);
- var data = [];
- for (var c=0;c<result.length;c++)
- {
- var row = result[c];
- var tvRow = Titanium.UI.createTableViewRow({
- height:'auto',
- selectedBackgroundColor:'#fff',
- backgroundColor:'#fff'
- });
- var imageView;
- imageView = Titanium.UI.createImageView({
- image:row.pic_square === null ? '../images/custom_tableview/user.png' : row.pic_square,
- left:10,
- width:50,
- height:50
- });
- tvRow.add(imageView);
- var userLabel = Titanium.UI.createLabel({
- font:{fontSize:16, fontWeight:'bold'},
- left:70,
- top:5,
- right:5,
- height:20,
- color:'#576996',
- text:row.name
- });
- tvRow.add(userLabel);
- var statusLabel = Titanium.UI.createLabel({
- font:{fontSize:13},
- left:70,
- top:25,
- right:20,
- height:'auto',
- color:'#222',
- text:(!row.status || !row.status.message ? 'No status message' : row.status.message)
- });
- tvRow.add(statusLabel);
- tvRow.uid = row.uid;
- data[c] = tvRow;
- }
- tableView.setData(data, { animationStyle : Titanium.UI.iPhone.RowAnimationStyle.DOWN });
- win1.open();
- });
- })
Add Comment
Please, Sign In to add comment