* @param {string} fileName
*/
createFile: function SystemIO_createFile(directoryHandle, fileName) {
- console.log('SystemIO_createFile', directoryHandle, fileName);
try {
return directoryHandle.createFile(fileName);
} catch (e) {
- console.error('SystemIO_createFile error:', e);
+ console.error('SystemIO_createFile error: ' + e.message);
return false;
}
},
* @param {string} content encoding
*/
writeFile: function SystemIO_writeFile(fileHandle, fileContent, onSuccess, onError, contentEncoding) {
- console.log('SystemIO_writeFile', fileHandle, fileContent.length, contentEncoding);
onError = onError || function () {};
fileHandle.openStream('w', function (fileStream) {
- console.log('SystemIO_writeFile:_onOpenStreamSuccess', fileStream);
if (contentEncoding === 'base64') {
fileStream.writeBase64(fileContent);
} else {
* @param {string} mode
*/
openDir: function SystemIO_openDir(directoryPath, onSuccess, onError, openMode) {
- console.log('SystemIO_openDir', directoryPath, openMode);
openMode = openMode || 'rw';
onSuccess = onSuccess || function () {};
try {
tizen.filesystem.resolve(directoryPath, onSuccess, onError, openMode);
} catch (e) {
- console.log('SystemIO_openDir error:' + e.message);
+ console.error('SystemIO_openDir error:' + e.message);
}
},
/**
* Get list of files
*
- * @param {string} directory path
- * @param {function} on success callback
- * @param {function} on error callback
+ * @param {string} directoryPath directory path
+ * @param {function} onSuccess on success callback
+ * @param {function} onError on error callback
* @param {string} fileMask
*/
dir: function SystemIO_dir(directoryPath, onSuccess, onError, fileMask) {
- console.log('SystemIO_dir', directoryPath, fileMask);
fileMask = fileMask || '';
onSuccess = onSuccess || function () {};
}
function onOpenDirError(e) {
- console.log('onOpenDirError', e.message);
+ console.error('onOpenDirError: ' + e.message);
}
try {
this.openDir(directoryPath, onOpenDir, onOpenDirError, 'r');
} catch (e) {
- console.log('SystemIO_dir error:' + e.message);
+ console.error('SystemIO_dir error:' + e.message);
}
},
* @returnss {array}
*/
getPathData: function SystemIO_getPathData(filePath) {
- console.log('SystemIO_getPathData', filePath);
var path = {
originalPath: filePath,
fileName: '',
* @param {string} file encoding
*/
saveFileContent: function SystemIO_saveFileContent(filePath, fileContent, onSaveSuccess, fileEncoding) {
- console.log('SystemIO_saveFileContent', filePath, fileContent.length, fileEncoding);
var pathData = this.getPathData(filePath),
self = this,
fileHandle;
function onOpenDirSuccess(dir) {
- console.log('SystemIO_saveFileContent:_onOpenDirSuccess', dir);
// create new file
fileHandle = self.createFile(dir, pathData.fileName);
if (fileHandle !== false) {
* @param {function} success callback
*/
deleteNode: function SystemIO_deleteNode(nodePath, onSuccess) {
- console.log('SystemIO_deleteNode', nodePath);
var pathData = this.getPathData(nodePath),
self = this;
function onDeleteSuccess() {
- console.log('SystemIO_deleteNode:_onDeleteSuccess');
onSuccess();
}
function onDeleteError(e) {
- console.log('SystemIO_deleteNode:_onDeleteError', e);
+ console.error('SystemIO_deleteNode:_onDeleteError', e);
}
function onOpenDirSuccess(dir) {
- console.log('SystemIO_deleteNode:_onOpenDirSuccess', dir);
var onListFiles = function (files) {
- console.log('SystemIO_deleteNode:_onListFiles', files);
if (files.length > 0) {
// file exists;
if (files[0].isDirectory) {
* Deletes specified file
*
* @param {File} dir
- * @param {string} file path
- * @param {function} delete success callback
- * @param {function} delete error callback
+ * @param {string} filePath file path
+ * @param {function} onDeleteSuccess delete success callback
+ * @param {function} onDeleteError delete error callback
*/
deleteFile: function SystemIO_deleteFile(dir, filePath, onDeleteSuccess, onDeleteError) {
- console.log('SystemIO_deleteFile', filePath);
try {
dir.deleteFile(filePath, onDeleteSuccess, onDeleteError);
} catch (e) {
* @returns {boolean}
*/
deleteDir: function SystemIO_deleteDir(dir, dirPath, onDeleteSuccess, onDeleteError) {
- console.log('SystemIO_deleteDir', dir, dirPath);
try {
dir.deleteDirectory(dirPath, false, onDeleteSuccess, onDeleteError);
} catch (e) {
}
return true;
+ },
+
+ /**
+ * The method check the file exists;
+ * @param {string} filePath
+ * @param {function} onCheck success callback
+ * @returns {undefined}
+ */
+ fileExists: function SystemIO_fileExists(filePath, onCheck) {
+ var pathData = this.getPathData(filePath);
+
+ function onOpenDirSuccess(dir) {
+ try {
+ dir.resolve(pathData.fileName);
+ onCheck(true);
+ } catch (error) {
+ onCheck(false);
+ }
+ }
+
+ // if directory not exists, the file also not exists;
+ function onOpenDirError(error) {
+ onCheck(false);
+ }
+
+ // open directory
+ this.openDir(pathData.dirName, onOpenDirSuccess, onOpenDirError);
}
};
}());
*/
/*jslint devel: true*/
-/*global $, Audio, window, localStorage, tizen, canvas, SystemIO */
+/*global $, Audio, window, localStorage, tizen, canvas, SystemIO, document, navigator, clearInterval, setInterval, setTimeout */
var selfCamera;
function SelfCamera() {
"use strict";
this.timer = value;
$('#timer2, #timer5, #timer10').removeClass('selected');
$('#timer' + value).addClass('selected');
+ selfCamera.video.play();
+ };
+
+ SelfCamera.prototype.refreshPhoto = function (fileHandle, onSuccess, onError) {
+ var filePath = fileHandle.toURI().replace('file://', '');
+ if (typeof (onSuccess) !== 'function') {
+ onSuccess = function () {};
+ }
+ if (typeof (onError) !== 'function'){
+ onError = function () {};
+ }
+ tizen.content.scanFile(filePath, onSuccess, onError);
};
SelfCamera.prototype.onCaptureVideoSuccess = function onCaptureVideoSuccess(stream) {
};
SelfCamera.prototype.onCaptureVideoError = function onCaptureVideoError(e) {
- console.error(e.message);
+ console.error(e);
};
SelfCamera.prototype.startPreview = function startPreview() {
SelfCamera.prototype.increaseSequence = function increaseSequence() {
var seq, str;
function fillStr(num) {
- var str = num;
- if (num < 10) {
- str = '0' + str;
- }
- if (num < 100) {
- str = '0' + str;
+ num = num.toString();
+ if (num.length < 2) {
+ num = '00' + num;
+ } else if (num.length < 3) {
+ num = '0' + num;
}
- return str;
+ return num;
}
if (this.sequence) {
var regexp = new RegExp('^' + this.saveDirectory);
if (this.filename) {
$('#upImage').css('background-image', 'url(' + this.loadDirectory + this.filename.replace(regexp, '') + ')');
+ $('#thumbnail').css('background-image', 'url("./images/transparent.png")');
}
};
- SelfCamera.prototype.launchGallery = function launchGallery() {
- var service, onReply;
- this.filename = this.loadDirectory + this.IMG_PREFIX + this.sequence + '.png';
+ SelfCamera.prototype.onFileExistsCheck = function (exists) {
+ if (!exists) {
+ this.setLastPhoto();
+ }
+ };
- service = new tizen.ApplicationControl('http://tizen.org/appcontrol/operation/view', null, null, null);
+ SelfCamera.prototype.launchPreview = function launchPreview() {
+ var service, onReply, self = this;
+ if (this.filename === '') {
+ return false;
+ }
- onReply = {
- onsuccess: function (data) {},
- onfailure: function () {
- alert('fail');
+ function fillStr(num) {
+ num = num.toString();
+ if (num.length < 2) {
+ num = '00' + num;
+ } else if (num.length < 3) {
+ num = '0' + num;
}
+ return num;
+ }
+
+ this.showPhotoPreview(this.loadDirectory + this.filename);
+ return true;
+ };
+
+ SelfCamera.prototype.showGallery = function showGallery(service) {
+ var onReply, self = this;
+ onReply = {
+ onsuccess: function (data) {
+ self.showPhotoPreview(data[0].value[0]);
+ },
+ onfailure: function () {}
};
try {
- tizen.application.launchAppControl(service, null, function () {}, function (err) {
+ tizen.application.launchAppControl(service, null, function () {
+ }, function (err) {
console.error('Gallery launch failed: ' + err.message);
}, onReply);
} catch (exc) {
}
};
+ SelfCamera.prototype.showPhotoPreview = function showPhotoPreview(file) {
+ var service, onReply, self = this;
+ service = new tizen.ApplicationControl('http://tizen.org/appcontrol/operation/view', file, "image/*");
+ onReply = {onsuccess: function () {}, onfailure: function () {}};
+
+ try {
+ tizen.application.launchAppControl(service, null, function () {}, function (err) {
+ console.error('Photo launch failed: ' + err.message);
+ }, onReply);
+ } catch (exc) {
+ alert('Exception: ' + exc.message);
+ }
+ };
+
SelfCamera.prototype.setLoadDirectory = function setLoadDirectory(dirName) {
this.loadDirectory = dirName;
if (!this.loadDirectory.match(/\/$/)) {
var data, onSuccess = function (fileHandle) {
this.setLoadDirectory(fileHandle.parent.toURI());
this.loadThumbnail();
+ this.refreshPhoto(fileHandle);
}.bind(this);
try {
- data = canvas.toDataURL().replace('data:image/png;base64,', '');
+ data = canvas.toDataURL().replace('data:image/png;base64,', '').replace('data:,', '');
+ if (data === '') {
+ throw {message: "No image source"};
+ }
} catch (e) {
+ this.filename = '';
console.error('canvas.toDataUrl error: ' + e.message);
- alert('canvas.toDataUrl error.');
+ alert("Data source error: " + e.message);
+ return;
}
try {
}
};
- SelfCamera.prototype.captureImage = function captureImage(filename, video) {
+ SelfCamera.prototype.captureImage = function captureImage(video) {
this.img.width = video.videoWidth;
this.img.height = video.videoHeight;
this.img.getContext('2d').drawImage(video, 0, 0);
SelfCamera.prototype.takePhoto = function takePhoto() {
this.increaseSequence();
- this.filename = this.saveDirectory + 'selfcam_widget_' + this.sequence + '.png';
+ this.filename = 'selfcam_widget_' + this.sequence + '.png';
- this.captureImage(this.filename, this.video);
+ this.captureImage(this.video);
this.savePhoto();
};
SelfCamera.prototype.savePhoto = function savePhoto() {
- this.saveCanvas(this.img, this.filename);
+ this.saveCanvas(this.img, this.saveDirectory + this.filename);
};
SelfCamera.prototype.findLastPhoto = function findLastPhoto(onFind) {
function onDir(files) {
if (files && files.length > 0) {
files = files.sort(function (a, b) {
- return (a.name === b.name) ? 0 : (a.name < b.name ? -1 : 1);
+ return (a.created === b.created) ? 0 : (a.created < b.created ? -1 : 1);
});
onFind(files.pop());
} else {
}
function onError(e) {
- console.error('systemIO.dir error: ', e.message);
+ console.error('systemIO.dir error: ' + e.message);
}
- this.systemIO.dir(this.saveDirectory, onDir, onError, this.IMG_PREFIX);
+ this.systemIO.dir(this.saveDirectory, onDir, onError, null);
};
SelfCamera.prototype.onCountdownInterval = function onCountdownInterval() {
};
SelfCamera.prototype.bindEvents = function bindEvents() {
+ var self = this;
+
+ document.addEventListener('webkitvisibilitychange', function (event) {
+ if (document.webkitVisibilityState === 'visible') {
+ setTimeout(function () { $('#background').get(0).play(); }, 200);
+ self.systemIO.fileExists(self.filename, self.onFileExistsCheck.bind(self));
+ }
+ });
$('shutter').mousedown(function (ev) {
$('shutter').addClass('active');
$('shutter').removeClass('active');
});
+ this.video.addEventListener("canplay", function () {
+ self.centerPreview();
+ });
+
$('#exit').on('click', function () {
var app = tizen.application.getCurrentApplication();
app.exit();
$('#timer5').on('click', this.setTimer.bind(this, DELAY_5_SECOND));
$('#timer10').on('click', this.setTimer.bind(this, DELAY_10_SECOND));
- $('#thumbnail').on('click', this.launchGallery.bind(this));
+ $('#thumbnail').on('click', this.launchPreview.bind(this));
$('#shutter').on('touchstart', this.startCountdown.bind(this));
$('#background').on('click', function () { this.play(); });
};
- SelfCamera.prototype.init = function init() {
- this.video = document.getElementById('background');
- this.systemIO = new SystemIO();
+ SelfCamera.prototype.centerPreview = function () {
+ $('#center').width($('#background').width());
+ $('#center').css('margin-left', '-'+($('#background').width()/2)+'px');
+ };
+
+ SelfCamera.prototype.setLastPhoto = function () {
this.findLastPhoto(function (file) {
if (file) {
this.setLoadDirectory(file.parent.toURI());
this.setFileName(file.name);
+ $('#thumbnail').css('background-image', 'url("./images/transparent.png")');
+ } else {
+ $('#upImage').css('background-image', '');
+ $('#thumbnail').css('background-image', 'url("./images/none.png")');
+ this.filename = '';
}
}.bind(this));
+ };
+
+ SelfCamera.prototype.init = function init() {
+ this.video = document.getElementById('background');
+ this.systemIO = new SystemIO();
+ this.setLastPhoto();
this.setTimer(DELAY_2_SECOND);
this.startPreview();
this.bindEvents();