From: Piotr Dabrowski Date: Tue, 6 Aug 2013 12:32:18 +0000 (+0200) Subject: [SelfCamera] updated SelfCamera sources X-Git-Tag: 2.2.1_release~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cd0d0ead32423375f057bca6368b39843268627c;p=samples%2Fweb%2FSelfCamera.git [SelfCamera] updated SelfCamera sources Change-Id: I0b6bc54794937d59dfcdd34f6c1456d01fa2c5c8 --- diff --git a/js/main.js b/js/main.js index bf01bac..9ad7d3b 100644 --- a/js/main.js +++ b/js/main.js @@ -25,7 +25,7 @@ function SelfCamera() { "use strict"; var DELAY_2_SECOND = 2, DELAY_5_SECOND = 5, DELAY_10_SECOND = 10; SelfCamera.prototype = { - countdown: 0, // current value after clicking the camera button + countdown: -1, // current value after clicking the camera button countdownTimeoutID: -1, countSound: new Audio('sounds/sounds_count.wav'), img: document.createElement('canvas'), @@ -160,10 +160,10 @@ function SelfCamera() { var data, self = this, onSuccess = function (fileHandle) { this.setLoadDirectory(this.getFileDirectoryURI(fileHandle)); tizen.content.scanFile(fileName, function () { - self.loadThumbnail(); + self.loadThumbnail(false, false); }, function () { console.error('scanFile: file not found'); - self.loadThumbnail(); + self.loadThumbnail(false, false); }); }.bind(this); @@ -212,7 +212,7 @@ function SelfCamera() { SelfCamera.prototype.setFileName = function setFileName(filename) { this.filename = filename; - this.loadThumbnail(); + this.loadThumbnail(false, false); }; SelfCamera.prototype.getTimestamp = function getTimestamp() { @@ -235,7 +235,7 @@ function SelfCamera() { SelfCamera.prototype.savePhoto = function savePhoto() { var self = this; this.saveCanvas(this.img, this.saveDirectory + this.filename); - setTimeout(function(){ self.loadThumbnail(true); }, 500); + setTimeout(function(){ self.loadThumbnail(true, true); }, 500); }; SelfCamera.prototype.findLastPhoto = function findLastPhoto(onFind) { @@ -261,18 +261,13 @@ function SelfCamera() { SelfCamera.prototype.onCountdownTimeout = function onCountdownTimeout() { this.countdown -= 1; if (this.countdown < 0) { - clearTimeout(this.countdownTimeoutID); - this.countdownTimeoutID = -1; - $('#countdown').text('').hide(); - $('#countdown').hide(); - this.shutterSound.currentTime = 0; + this.clearCountdown(); this.shutterSound.play(); try { this.takePhoto(); } catch (e) { console.error(e); } - this.bindTimerClicks(); } else { $('#countdown').text(this.countdown); this.countSound.currentTime = 0; @@ -295,6 +290,14 @@ function SelfCamera() { this.countSound.play(); }; + SelfCamera.prototype.clearCountdown = function clearCountdown() { + $('#countdown').text('').hide(); + this.countdown = -1; + clearTimeout(this.countdownTimeoutID); + this.countdownTimeoutID = -1; + this.bindTimerClicks(); + }; + SelfCamera.prototype.bindVideoEvents = function () { var self = this; $(this.video).on("stalled", function (e) { @@ -304,34 +307,26 @@ function SelfCamera() { var margin = ($(window).width() - $(self.video).width()) / 2, width = Math.round($(window).height() * self.video.videoWidth / self.video.videoHeight); - $(self.video).css({ 'margin-left': margin + 'px', 'width': width + 'px' }); - - if (self.countdown > 0) { - self.startCountdown(self.countdown); - } }); $(this.video).on('click', function () { this.play(); }); }; SelfCamera.prototype.bindEvents = function bindEvents() { var self = this; + document.addEventListener('webkitvisibilitychange', function (event) { - clearTimeout(this.countdownTimeoutID); - this.countdownTimeoutID = -1; + self.clearCountdown(); if (document.webkitVisibilityState === 'visible') { if (self.video !== null) { self.reloadSaveDirectory(function () { self.video.play(); }); } - self.loadThumbnail(); - if (self.countdown > 0) { - self.startCountdown(self.countdown); - } + self.loadThumbnail(true, false); } else { if (self.video !== null) { self.video.pause(); @@ -351,7 +346,12 @@ function SelfCamera() { $(window).on('tizenhwkey', function (e) { if (e.originalEvent.keyName === "back") { - tizen.application.getCurrentApplication().exit(); + if (self.countdownTimeoutID !== -1) { + self.clearCountdown(); + self.loadThumbnail(true, false); + } else { + tizen.application.getCurrentApplication().exit(); + } } }); @@ -389,8 +389,10 @@ function SelfCamera() { return dirURI; }; - SelfCamera.prototype.loadThumbnail = function (show) { + SelfCamera.prototype.loadThumbnail = function (show, animate) { var self = this; + show = show || false; + animate = animate || false; this.findLastPhoto(function (file) { if (file) { self.filename = file; @@ -398,7 +400,12 @@ function SelfCamera() { $('#upImage').css('background-image', 'url(' + file + ')'); $('#thumbnail').css('background-image', 'url("./images/transparent.png")'); if (show) { - $('#thumbnail').css({'opacity':0}).show().animate({'opacity':1}); + if (animate) { + $('#thumbnail').css({'opacity':0}).show().animate({'opacity':1}); + } + else { + $('#thumbnail').show(); + } } } else { self.filename = ''; @@ -427,7 +434,7 @@ function SelfCamera() { var self = this; this.reloadSaveDirectory(function () { self.systemIO = new SystemIO(); - self.loadThumbnail(true); + self.loadThumbnail(true, false); self.startPreview(); self.bindEvents(); });