Created
April 24, 2012 18:13
-
-
Save srahim/2482221 to your computer and use it in GitHub Desktop.
Overlay rotate animation.
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 = Titanium.UI.createWindow(); | |
var t = Ti.UI.create2DMatrix(); | |
var identityTransform = Ti.UI.create2DMatrix(); | |
var a = Titanium.UI.createAnimation(); | |
a.transform = t; | |
a.duration = 1000; | |
//Function to process the current orientation | |
function getOrientation(o) | |
{ | |
switch (o) | |
{ | |
case Titanium.UI.UPSIDE_PORTRAIT: | |
t = t.rotate(-180);//identityTransform; | |
a.transform = t; | |
a.duration = 500; | |
return 'reverse portrait'; | |
case Titanium.UI.LANDSCAPE_LEFT: | |
t = t.rotate(-90); | |
a.transform = t; | |
a.duration = 500; | |
return 'landscape'; | |
case Titanium.UI.LANDSCAPE_RIGHT: | |
t = t.rotate(90); | |
a.transform = t; | |
a.duration = 500; | |
return 'reverse landscape'; | |
default: | |
t = identityTransform; | |
a.transform = t; | |
a.duration = 500; | |
return 'portrait and others'; | |
} | |
} | |
//creating the red rectangle for the zoom view. | |
var scanner = Titanium.UI.createView({ | |
width:200, | |
height:200, | |
borderColor:'red', | |
borderWidth:5, | |
borderRadius:15, | |
anchorPoint:{x:0.5,y:0.5} | |
}); | |
//creating the button to take photo | |
var button = Titanium.UI.createButton({ | |
color:'grey', | |
bottom:10, | |
width:100, | |
height:50, | |
font:{fontSize:20,fontWeight:'bold',fontFamily:'Helvetica Neue'}, | |
//title:'Take Picture' | |
anchorPoint:{x:0.5,y:0.5} | |
}); | |
var imageView = Titanium.UI.createImageView({ | |
image:'digital_camera.png', | |
width:40, | |
height:40, | |
anchorPoint:{x:0.5, y:0.5} | |
}); | |
button.add(imageView); | |
var messageView = Titanium.UI.createView({ | |
height:30, | |
width:250, | |
visible:false | |
}); | |
var indView = Titanium.UI.createView({ | |
height:30, | |
width:250, | |
backgroundColor:'#000', | |
borderRadius:10, | |
opacity:0.7 | |
}); | |
messageView.add(indView); | |
// message | |
var message = Titanium.UI.createLabel({ | |
text:'Picture Taken', | |
color:'#fff', | |
font:{fontSize:20,fontWeight:'bold',fontFamily:'Helvetica Neue'}, | |
width:'auto', | |
height:'auto' | |
}); | |
messageView.add(message); | |
var overlay = Titanium.UI.createView(); | |
overlay.add(scanner); | |
overlay.add(button); | |
overlay.add(messageView); | |
button.addEventListener('click',function() | |
{ | |
scanner.borderColor = 'blue'; | |
Ti.Media.takePicture(); | |
messageView.animate({visible:true}); | |
setTimeout(function() | |
{ | |
scanner.borderColor = 'red'; | |
messageView.animate({visible:false}); | |
},500); | |
}); | |
Titanium.Media.showCamera({ | |
success:function(event) | |
{ | |
Ti.API.debug("picture was taken"); | |
// place our picture into our window | |
var imageView = Ti.UI.createImageView({ | |
image:event.media, | |
width:win.width, | |
height:win.height | |
}); | |
win.add(imageView); | |
// programatically hide the camera | |
Ti.Media.hideCamera(); | |
}, | |
cancel:function() | |
{ | |
}, | |
error:function(error) | |
{ | |
var a = Titanium.UI.createAlertDialog({title:'Camera'}); | |
if (error.code == Titanium.Media.NO_CAMERA) | |
{ | |
a.setMessage('Please run this test on device'); | |
} | |
else | |
{ | |
a.setMessage('Unexpected error: ' + error.code); | |
} | |
a.show(); | |
}, | |
overlay:overlay, | |
showControls:false, // don't show system controls | |
mediaTypes:Ti.Media.MEDIA_TYPE_PHOTO, | |
autohide:false // tell the system not to auto-hide and we'll do it ourself | |
}); | |
Ti.Gesture.addEventListener('orientationchange',function(e) | |
{ | |
// device orientation | |
var orient = getOrientation(e.orientation); | |
Ti.API.info("current orientation : "+ orient); | |
scanner.animate(a); | |
imageView.animate(a); | |
}); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment