Created
August 25, 2011 01:34
-
-
Save goofmint/1169759 to your computer and use it in GitHub Desktop.
Facebook photo uploader
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
| log = (obj) -> Ti.API.log obj | |
| Ti.UI.setBackgroundColor '#000' | |
| # create tab group | |
| tabGroup = Ti.UI.createTabGroup() | |
| # Base window | |
| win = Ti.UI.createWindow title: 'Photo Uploader', backgroundColor: '#fff' | |
| # For Facebook from here. | |
| Ti.Facebook.appid = "xxxxxxxxxxxxxxxxxxxxx" | |
| Ti.Facebook.permissions = ['publish_stream', 'read_stream'] | |
| login = Ti.Facebook.createLoginButton top: 10, style: 'wide' | |
| win.add login | |
| Ti.Facebook.addEventListener 'login', (e) -> | |
| alert "Login successful" if e.success | |
| alert e.error if e.error | |
| Ti.Facebook.addEventListener 'logout', (e) -> | |
| Ti.API.info 'logout event' | |
| alert "Logout..." | |
| # Dumy tab | |
| tab = Ti.UI.createTab title:'', window:win | |
| tabGroup.addTab tab | |
| win.tabBarHidden = true | |
| camera = Ti.UI.createButton backgroundImage: './images/light_camera.png', height:33, width:33 | |
| camera.addEventListener 'click', -> | |
| dialog = Titanium.UI.createOptionDialog | |
| title: '写真またはライブラリから選択', cancel: 2 | |
| options: ["写真を撮る", "既存の項目を選択", "キャンセル"] | |
| dialog.addEventListener 'click', (e) -> | |
| return if e.cancel == true | |
| if e.index == 0 | |
| Ti.Media.showCamera | |
| success: (event) -> | |
| image.image = event.media | |
| win.add image | |
| if e.index == 1 | |
| Ti.Media.openPhotoGallery | |
| success: (event) -> | |
| image.image = event.media | |
| win.add image | |
| dialog.show() | |
| # Send button | |
| send = Ti.UI.createButton title: "送信", width: 50, height: 32 | |
| send.addEventListener 'click', -> | |
| win.title = 'Uploading Photo...' | |
| blob = image.image | |
| data = { | |
| caption: text.value | |
| picture: blob | |
| } | |
| Ti.Facebook.request 'photos.upload', data, showRequestResult | |
| win.rightNavButton = send | |
| # Text area | |
| text = Ti.UI.createTextArea | |
| height:70, | |
| width:300, | |
| top:50, | |
| color:'#888', | |
| keyboardToolbar: [camera] | |
| borderWidth:2, | |
| borderColor:'#bbb', | |
| borderRadius:5 | |
| win.add text | |
| # Event after photo uploaded. | |
| showRequestResult = (e) -> | |
| s = '' | |
| if e.success | |
| s = "SUCCESS" | |
| text.value = "" | |
| image.image = null | |
| if e.result | |
| s += "; " + e.result | |
| else | |
| s = "FAIL" | |
| if e.error | |
| s += "; " + e.error | |
| alert s | |
| # Dumy image | |
| image = Ti.UI.createImageView(top: 130) | |
| # Finish | |
| tabGroup.open() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment