"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'),
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);
SelfCamera.prototype.setFileName = function setFileName(filename) {
this.filename = filename;
- this.loadThumbnail();
+ this.loadThumbnail(false, false);
};
SelfCamera.prototype.getTimestamp = function getTimestamp() {
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) {
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;
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) {
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();
$(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();
+ }
}
});
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;
$('#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 = '';
var self = this;
this.reloadSaveDirectory(function () {
self.systemIO = new SystemIO();
- self.loadThumbnail(true);
+ self.loadThumbnail(true, false);
self.startPreview();
self.bindEvents();
});