Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var testOverlay = Ti.UI.createView({
- bottom:0,
- height:200,
- width: platformWidth,
- height : platformHeight,
- left:0,
- // backgroundColor : 'gray'
- });
- var topbarView = Ti.UI.createView({
- width: platformWidth,
- height : resultHeight,
- top : 0,
- left : 0,
- backgroundColor : '#363636',
- opcatity : 0.6
- });
- testOverlay.add(topbarView);
- var topbarTitle = Ti.UI.createLabel({
- text:L("capture_a_moment_string"),
- color:"#FFFFFF",
- textAlign:"left",
- width:Ti.UI.SIZE,
- height:Ti.UI.SIZE,
- left:"10dp",
- font:{fontSize:"24dp", fontFamily: 'HelveticaNeue-UltraLight'}
- });
- topbarView.add(topbarTitle);
- var takeVideoIcon = Ti.UI.createImageView({
- image:imagesPath + "CameraOverlay_TakeVideo.png",
- width:44 + dpi,
- height:44 + dpi,
- right:"10dp"
- });
- topbarView.add(takeVideoIcon);
- var bottombarView = Ti.UI.createView({
- width: platformWidth,
- height : resultHeight,
- bottom : 0,
- left : 0,
- backgroundColor : '#363636',
- opcatity : 0.6
- });
- testOverlay.add(bottombarView);
- var cameraButtonHolder = Ti.UI.createView({
- width : Ti.UI.FILL,
- height : 80 + dpi,
- bottom : 0
- });
- bottombarView.add(cameraButtonHolder);
- var cancelCameraButton = Ti.UI.createView({
- width:80 + dpi,
- height:80 + dpi,
- left:0,
- backgroundColor:"transparent"
- });
- var cancelCameraIcon = Ti.UI.createImageView({
- image:imagesPath + "CameraOverlay_Close.png",
- width:44 + dpi,
- height:44 + dpi
- });
- cancelCameraButton.add(cancelCameraIcon);
- var takePictureButton = Ti.UI.createView({
- width : 80 + dpi,
- height : 80 + dpi,
- backgroundColor : 'transparent'
- });
- var takePictureImage = Ti.UI.createImageView({
- image:imagesPath + "CameraOverlay_TakePicture.png",
- width:44 + dpi,
- height:44 + dpi
- });
- takePictureButton.add(takePictureImage);
- var galleryButton = Ti.UI.createView({
- width:80 + dpi,
- height:80 + dpi,
- right:0,
- backgroundColor:"transparent"
- });
- var galleryButtonImage = Ti.UI.createImageView({
- image:imagesPath + "CameraOverlay_Gallery.png",
- width:44 + dpi,
- height:44 + dpi
- });
- galleryButton.add(galleryButtonImage);
- cameraButtonHolder.add(cancelCameraButton);
- cameraButtonHolder.add(takePictureButton);
- cameraButtonHolder.add(galleryButton);
- var cameraButtonSelectedColor = "#0e76bc";
- cancelCameraButton.addEventListener("singletap", function(e){
- Ti.Media.hideCamera();
- cancelCameraButton.animate({
- backgroundColor : "transparent",
- duration : 150
- }, function(e) {
- parentWindow.closeView();
- });
- });
- takePictureButton.addEventListener('singletap', function(e){
- Ti.Media.takePicture();
- });
- var galleryOpened = false;
- function openKineduPhotoGallery()
- {
- if(!galleryOpened)
- {
- galleryOpened = true;
- Titanium.Media.openPhotoGallery({
- success : function(event) {
- Ti.API.info('Returning from selecting picture');
- var tmp;
- var mediaType;
- if (event.mediaType.indexOf('PHOTO') > -1 || event.mediaType.indexOf('image') > -1) {
- tmp = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, ('baby_temp.png'));
- mediaType = 'photos';
- }
- Ti.App.Properties.setString('mediaType', mediaType);
- var imageFile = event.media;
- var imageAsTaken = Ti.UI.createImageView({
- image : imageFile,
- });
- imageAsTaken.transform(rotateMatrix);
- var image = imageAsTaken.toBlob();
- var imageWidth = image.width;
- var imageHeight = image.height;
- var finalSize = imageWidth;
- var scaleX = 0;
- var scaleY = (imageHeight - imageWidth) / 2;
- if (imageHeight < imageWidth) {
- scaleX = (imageWidth - imageHeight) / 2;
- scaleY = 0;
- finalSize = imageHeight;
- }
- var croppedImage = image.imageAsCropped({
- x : scaleX,
- y : scaleY,
- width : finalSize,
- height : finalSize
- });
- tmp.write(croppedImage);
- galleryOpened = false;
- },
- cancel : function(e) {
- Ti.API.info('Gallery cancelled');
- for(var x in e)
- {
- Ti.API.info('Property ' + x + ' value ' + e[x]);
- }
- galleryOpened = false;
- },
- error : function(error) {
- Ti.API.info('Gallery Error');
- for(var x in error)
- {
- Ti.API.info('Property ' + x + ' value ' + error[x]);
- }
- galleryOpened = false;
- },
- mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]
- });
- }
- }
- galleryButton.addEventListener("singletap", function(e){
- Ti.Media.hideCamera();
- openKineduPhotoGallery();
- });
- function showCamera() {
- Ti.Media.showCamera({
- success : function(event)
- {
- Ti.API.info('Returning from taking picture');
- var tmp;
- var mediaType;
- if (event.mediaType.indexOf('PHOTO') > -1 || event.mediaType.indexOf('image') > -1)
- {
- tmp = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, ('baby_temp.png'));
- mediaType = 'photos';
- }
- else
- {
- tmp = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, ('baby_temp.mp4'));
- mediaType = 'videos'
- }
- Ti.App.Properties.setString('mediaType', mediaType);
- if (mediaType == "photos")
- {
- var imageFile = event.media;
- var imageAsTaken = Ti.UI.createImageView({
- image : imageFile
- });
- var image = imageAsTaken.toBlob();
- var imageWidth = image.width;
- var imageHeight = image.height;
- var finalSize = imageWidth;
- var scaleX = 0;
- var scaleY = (imageHeight - imageWidth) / 2;
- if(imageHeight < imageWidth)
- {
- scaleX = (imageWidth - imageHeight) / 2;
- scaleY = 0;
- finalSize = imageHeight;
- }
- var croppedImage = image.imageAsCropped({
- x : scaleX,
- y : scaleY,
- width : finalSize,
- height : finalSize
- });
- tmp.write(croppedImage);
- }
- Ti.Media.hideCamera();
- },
- cancel : function(e) {
- Ti.API.info('camera canceled');
- for(var x in e)
- {
- Ti.API.info('Property ' + x + ' value ' + e[x]);
- }
- parentWindow.closeView();
- },
- error : function(error) {
- Ti.API.info('camera error');
- for(var x in error)
- {
- Ti.API.info('Property ' + x + ' value ' + error[x]);
- }
- var message;
- if (error.code == Ti.Media.NO_CAMERA)
- {
- message = 'Device does not have camera capabilities';
- }
- else
- {
- message = 'Unexpected error: ' + error.code;
- }
- },
- allowEditing : false,
- overlay:testOverlay,
- mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
- showControls: false,
- videoMaximumDuration : 10000,
- videoQuality : Titanium.Media.QUALITY_MEDIUM,
- saveToPhotoGallery : false,
- autohide : true
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement