Created
March 7, 2012 01:53
-
-
Save alanleard/1990394 to your computer and use it in GitHub Desktop.
Circle Pictures
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
var win = Ti.UI.createWindow({backgroundColor:'#000'}); | |
var dialog = Titanium.UI.createOptionDialog({ | |
options: ['Camera','Gallery', 'Cancel'], | |
cancel:2 | |
}); | |
dialog.show(); | |
dialog.addEventListener('click', function(e){ | |
if(e.index === 1){ | |
gallery(); | |
} else if(e.index === 0){ | |
camera(); | |
} | |
}); | |
win.addEventListener('longpress', function(){ | |
dialog.show(); | |
}); | |
function open(event){ | |
//mainView.hide(); | |
var galImage = event.media; | |
// create new file name and remove old | |
var filename = Titanium.Filesystem.applicationDataDirectory + "/" + new Date().getTime() + ".png"; | |
bgImage = Titanium.Filesystem.getFile(filename); | |
bgImage.write(galImage); | |
var view = Ti.UI.createScrollView({ | |
backgroundColor:'#000', | |
borderRadius:150, | |
height:300, | |
width:300, | |
contentHeight:'auto', | |
contentWidth:'auto', | |
minZoomScale:0.25, | |
maxZoomScale:3.0, | |
zoomScle:1.0 | |
}); | |
var image = Ti.UI.createImageView({ | |
image:bgImage.nativePath, | |
height:'auto', | |
width:'auto' | |
}); | |
view.add(image); | |
win.add(view); | |
var button = Ti.UI.createButton({ | |
title:'Capture', | |
width:200, | |
height:40, | |
bottom:10 | |
}); | |
button.addEventListener('click', function(){ | |
bgImage.write(view.toImage()); | |
var img = Ti.UI.createImageView({ | |
width:200, | |
height:200, | |
image:bgImage.nativePath, | |
backgroundColor:'#000' | |
}); | |
Titanium.Media.saveToPhotoGallery(img.toImage()); | |
win.remove(button); | |
win.remove(view); | |
win.add(img); | |
}); | |
win.add(button); | |
} | |
function gallery(){ | |
Titanium.Media.openPhotoGallery( | |
{ | |
success: function(event){ | |
open(event); | |
}, | |
cancel:function() | |
{ | |
dialog.show(); | |
}, | |
error:function(error) | |
{ | |
dialog.show(); | |
} | |
}); | |
} | |
function camera(){ | |
var overlay = Titanium.UI.createView({ | |
backgroundImage:'whiteBG.png' | |
}); | |
var tkPic = Ti.UI.createButton({ | |
title:'Take Picture', | |
height:30, | |
width:150, | |
bottom:70 | |
}); | |
tkPic.addEventListener('click',function() | |
{ | |
Ti.Media.takePicture(); | |
}); | |
overlay.add(tkPic); | |
Titanium.Media.showCamera({ | |
success:function(event) | |
{ | |
open(event); | |
}, | |
cancel:function() | |
{ | |
}, | |
error:function(error) | |
{ | |
var a = Titanium.UI.createAlertDialog({title:'Camera'}); | |
if (error.code == Titanium.Media.NO_CAMERA) | |
{ | |
a.setMessage('Sorry, you need a camera.'); | |
dialog.show(); | |
} | |
else | |
{ | |
a.setMessage('Unexpected error: ' + error.code); | |
win.close(); | |
} | |
a.show(); | |
}, | |
overlay:overlay, | |
showControls:false, // don't show system controls | |
mediaTypes:Ti.Media.MEDIA_TYPE_PHOTO, | |
autohide:true | |
//allowEditing:true // tell the system not to auto-hide and we'll do it ourself | |
}); | |
} | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment