This commit is contained in:
Mahdi Dibaiee 2014-05-02 19:43:10 +04:30
parent 88df69beaf
commit 709ce388cc
20 changed files with 153 additions and 139 deletions

View File

@ -1,22 +0,0 @@
<widget id='com.mdibaiee.sketchy' version='1.2.1'>
<name>Sketchy</name>
<description>
Free full-featured Sketch app
</description>
<author email='mdibaiee@aol.com' href='http://dibaiee.ir'>
Mahdi Dibaiee
</author>
<content src='index.html'/>
<access origin='*'/>
<preference name='KeepRunning' value='false'/>
<preference name='SplashScreen' value='sketchy'/>
<preference name='SetFullScreen' value='true'/>
<preference name='FullScreen' value='true'/>
<preference name='DisallowOverscroll' value='true'/>
<icon src='icon.png'/>
</widget>

View File

@ -5,8 +5,9 @@
<title>Sketchy</title> <title>Sketchy</title>
<meta charset='UTF-8'> <meta charset='UTF-8'>
<link rel='stylesheet' href='css/main.css'> <link rel='stylesheet' href='css/main.css'>
<script src='cordova.js'></script>
</head> </head>
<body> <body>
<header> <header>

View File

@ -1,123 +1,136 @@
$(document).ready(function() { $(document).ready(function() {
$('*').off('click mousemove mousedown mouseup mouseleave').on('click mousemove mousedown mouseup mouseleave', function(e) { $(document).on('resume', function() {
e.preventDefault; sizeAndPos();
}) })
document.addEventListener('deviceready', function() {
sizeAndPos();
/*$('a[href^="http"]').tap(function(e) { $('*').off('click mousemove mousedown mouseup mouseleave').on('click mousemove mousedown mouseup mouseleave', function(e) {
e.preventDefault(); e.preventDefault;
var href = $(this).attr('href');
var view = new MozActivity({
name: 'view',
data: {
type: 'url',
url: href
}
}) })
return false;
}).click(function(e) {
e.preventDefault();
return false;
})*/
/*$('a[href^="mailto"]').tap(function(e) { /*$('a[href^="http"]').tap(function(e) {
e.preventDefault(); e.preventDefault();
var mail = new MozActivity({ var href = $(this).attr('href');
name: 'new', var view = new MozActivity({
data: { name: 'view',
type: 'mail', data: {
url: $(this).attr('href') type: 'url',
} url: href
}) }
return false; })
}).click(function(e) {
e.preventDefault();
return false;
})*/
window.save = function() { return false;
var f = c.getImageData(0, 0, width(), height()); }).click(function(e) {
switch(save.background) { e.preventDefault();
case 'white': { return false;
c.fillStyle = 'white'; })*/
c.globalCompositeOperation = 'destination-over';
c.fillRect(0, 0, width(), height()); /*$('a[href^="mailto"]').tap(function(e) {
c.fillStyle = settings.color; e.preventDefault();
c.globalCompositeOperation = settings.composite; var mail = new MozActivity({
break; name: 'new',
} data: {
case 'current color': { type: 'mail',
c.fillStyle = settings.bg; url: $(this).attr('href')
c.globalCompositeOperation = 'destination-over'; }
c.fillRect(0, 0, width(), height()); })
c.globalCompositeOperation = settings.composite; return false;
break; }).click(function(e) {
} e.preventDefault();
} return false;
var data = $c[0].toDataURL(); })*/
if( save.type == 'sketchy project' ) {
var list = JSON.parse(localStorage.getItem('projects'));
var index;
if( list && list.some(function(a, i) { if( a.name == save['file name'] ) {index = i; return true} return false }) ) { window.save = function() {
if( confirm('A sketch with this name already exists. Do you want to overwrite ' + save['file name'] + '?') ) { var f = c.getImageData(0, 0, width(), height());
console.log(index); switch(save.background) {
list[index] = { case 'white': {
name: save['file name'], c.fillStyle = 'white';
data: data, c.globalCompositeOperation = 'destination-over';
points: window.points, c.fillRect(0, 0, width(), height());
settings: settings c.fillStyle = settings.color;
} c.globalCompositeOperation = settings.composite;
localStorage.setItem('projects', JSON.stringify(list)); break;
}
case 'current color': {
c.fillStyle = settings.bg;
c.globalCompositeOperation = 'destination-over';
c.fillRect(0, 0, width(), height());
c.globalCompositeOperation = settings.composite;
break;
} }
} }
else { var data = $c[0].toDataURL();
list ? list.push({ if( save.type == 'sketchy project' ) {
name: save['file name'], var list = JSON.parse(localStorage.getItem('projects'));
data: data, var index;
points: window.points, if( list && list.some(function(a, i) { if( a.name == save['file name'] ) {index = i; return true} return false }) ) {
settings: settings if( confirm('A sketch with this name already exists. Do you want to overwrite ' + save['file name'] + '?') ) {
}) : list = [{ console.log(index);
name: save['file name'], list[index] = {
data: data, name: save['file name'],
points: window.points, data: data,
settings: settings points: window.points,
}]; settings: settings
localStorage.setItem('projects', JSON.stringify(list)); }
} localStorage.setItem('projects', JSON.stringify(list));
} else { }
var sd = window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) { }
var fdata = dataToBlob(data); else {
var req = fs.root.getFile(save['file name'] + '.png', {create: true}, function(file) { list ? list.push({
file.createWriter(function(writer) { name: save['file name'],
writer.write(fdata); data: data,
alert('Your Sketch was saved successfuly: ' + this.result); points: window.points,
}, function() { settings: settings
alert('Something bad happened trying to save your sketch ' + save['file name'] + '\n Possible reasons:\n Duplicate Name \n Not enough permission') }) : list = [{
}) name: save['file name'],
}) data: data,
}, function(error) { points: window.points,
alert('Couldn\'t access filesystem\n' + error.message); settings: settings
}); }];
} localStorage.setItem('projects', JSON.stringify(list));
c.putImageData(f, 0, 0); }
} } else {
window.load = function() { var img = dataToBlob(data);
var file = JSON.parse(localStorage.getItem('projects')).filter(function(a) { return a.name == load.file })[0]; var sd = window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
var img = document.createElement('img'); window.alert('SD');
img.src = file.data; /*var req = fs.root.getFile(save['file name'] + '.png', {create: true}, function(entry) {
img.onload = function() { alert('Entry');
c.clearRect(0, 0, width(), height()); entry.createWriter(function(writer) {
c.drawImage(img, 0, 0); writer.write(img);
window.points = file.points; alert('Your Sketch was saved successfuly');
window.points.history = [{ data: c.createImageData($c.width(), $c.height()), points: []}, { data: c.getImageData(0, 0, width(), height()), points: file.points}]; }, function() {
$c.first().css('background', file.settings.bg); alert('Something bad happened trying to save your sketch ' + save['file name'] + '\n Possible reasons:\n Duplicate Name \n Not enough permission')
window.settings.bg = file.settings.bg; })
})*/
}, function(e) {
alert('SD Error')
//alert('Couldn\'t access filesystem\nERR: ' + e.code);
});
} }
c.putImageData(f, 0, 0);
} }
window.load = function() {
var file = JSON.parse(localStorage.getItem('projects')).filter(function(a) { return a.name == load.file })[0];
var img = document.createElement('img');
img.src = file.data;
img.onload = function() {
c.clearRect(0, 0, width(), height());
c.drawImage(img, 0, 0);
window.points = file.points;
window.points.history = [{ data: c.createImageData($c.width(), $c.height()), points: []}, { data: c.getImageData(0, 0, width(), height()), points: file.points}];
$c.first().css('background', file.settings.bg);
window.settings.bg = file.settings.bg;
}
}
if( !localStorage.getItem('sawVote') ) { if( !localStorage.getItem('sawVote') ) {
$('.vote').removeClass('hidden'); $('.vote').removeClass('hidden');
localStorage.setItem('sawVote', true); localStorage.setItem('sawVote', true);
} }
}, false)
}) })

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -21,6 +21,13 @@ module.exports = function(grunt) {
dest: 'build/web/js', dest: 'build/web/js',
filter: 'isFile' filter: 'isFile'
}, },
{
expand: true,
cwd: 'Shared/js',
src: '**',
dest: 'build/android/js',
filter: 'isFile'
},
{ {
expand: true, expand: true,
cwd: 'Mobile/js/', cwd: 'Mobile/js/',
@ -79,7 +86,7 @@ module.exports = function(grunt) {
{ {
expand: true, expand: true,
cwd: 'Android', cwd: 'Android',
src: ['index.html', 'config.xml', 'res/**', 'icon.png'], src: ['index.html', 'config.xml', 'AndroidManifest.xml', 'res/**', 'icon.png'],
dest: 'build/android' dest: 'build/android'
}, },
{ {

View File

@ -61,7 +61,8 @@ $(document).ready(function() {
}]; }];
localStorage.setItem('projects', JSON.stringify(list)); localStorage.setItem('projects', JSON.stringify(list));
} else { } else {
window.open(data, '_blank').focus(); $('<a href="' + data + '" download="' + save['file name'] + '.png"></a>').click();
//window.open(data, '_blank').focus();
} }
c.putImageData(f, 0, 0); c.putImageData(f, 0, 0);

View File

@ -0,0 +1,2 @@
<uses-permission android:name='android.permission.WRITE_EXTERNAL_STORAGE' />

View File

@ -13,7 +13,7 @@
</author> </author>
<content src='index.html'/> <content src='index.html'/>
<access origin='*'/> <access origin='*'/>
<feature name="http://api.phonegap.com/1.0/device" /> <!--<feature name="http://api.phonegap.com/1.0/device" />-->
<preference name='KeepRunning' value='false'/> <preference name='KeepRunning' value='false'/>
<preference name='SplashScreen' value='sketchy'/> <preference name='SplashScreen' value='sketchy'/>
@ -21,7 +21,12 @@
<preference name='FullScreen' value='true'/> <preference name='FullScreen' value='true'/>
<preference name='DisallowOverscroll' value='true'/> <preference name='DisallowOverscroll' value='true'/>
<icon src='icon.png'/> <feature name='File'>
<param name='android-package' value='org.apache.cordova.file' />
</feature>
<plugins>
<plugin name='File' value='org.apache.cordova.file' />
</plugins>
</widget> </widget>

View File

@ -5,8 +5,9 @@
<title>Sketchy</title> <title>Sketchy</title>
<meta charset='UTF-8'> <meta charset='UTF-8'>
<link rel='stylesheet' href='css/main.css'> <link rel='stylesheet' href='css/main.css'>
<script src='cordova.js'></script>
</head> </head>
<body> <body>
<header> <header>

View File

@ -1 +1 @@
$(document).ready(function(){$("*").off("click mousemove mousedown mouseup mouseleave").on("click mousemove mousedown mouseup mouseleave",function(a){a.preventDefault}),window.save=function(){var a=c.getImageData(0,0,width(),height());switch(save.background){case"white":c.fillStyle="white",c.globalCompositeOperation="destination-over",c.fillRect(0,0,width(),height()),c.fillStyle=settings.color,c.globalCompositeOperation=settings.composite;break;case"current color":c.fillStyle=settings.bg,c.globalCompositeOperation="destination-over",c.fillRect(0,0,width(),height()),c.globalCompositeOperation=settings.composite}var b=$c[0].toDataURL();if("sketchy project"==save.type){var d,e=JSON.parse(localStorage.getItem("projects"));e&&e.some(function(a,b){return a.name==save["file name"]?(d=b,!0):!1})?confirm("A sketch with this name already exists. Do you want to overwrite "+save["file name"]+"?")&&(console.log(d),e[d]={name:save["file name"],data:b,points:window.points,settings:settings},localStorage.setItem("projects",JSON.stringify(e))):(e?e.push({name:save["file name"],data:b,points:window.points,settings:settings}):e=[{name:save["file name"],data:b,points:window.points,settings:settings}],localStorage.setItem("projects",JSON.stringify(e)))}else{window.requestFileSystem(LocalFileSystem.PERSISTENT,0,function(a){{var c=dataToBlob(b);a.root.getFile(save["file name"]+".png",{create:!0},function(a){a.createWriter(function(a){a.write(c),alert("Your Sketch was saved successfuly: "+this.result)},function(){alert("Something bad happened trying to save your sketch "+save["file name"]+"\n Possible reasons:\n Duplicate Name \n Not enough permission")})})}},function(a){alert("Couldn't access filesystem\n"+a.message)})}c.putImageData(a,0,0)},window.load=function(){var a=JSON.parse(localStorage.getItem("projects")).filter(function(a){return a.name==load.file})[0],b=document.createElement("img");b.src=a.data,b.onload=function(){c.clearRect(0,0,width(),height()),c.drawImage(b,0,0),window.points=a.points,window.points.history=[{data:c.createImageData($c.width(),$c.height()),points:[]},{data:c.getImageData(0,0,width(),height()),points:a.points}],$c.first().css("background",a.settings.bg),window.settings.bg=a.settings.bg}},localStorage.getItem("sawVote")||($(".vote").removeClass("hidden"),localStorage.setItem("sawVote",!0))}); $(document).ready(function(){$(document).on("resume",function(){sizeAndPos()}),document.addEventListener("deviceready",function(){sizeAndPos(),$("*").off("click mousemove mousedown mouseup mouseleave").on("click mousemove mousedown mouseup mouseleave",function(a){a.preventDefault}),window.save=function(){var a=c.getImageData(0,0,width(),height());switch(save.background){case"white":c.fillStyle="white",c.globalCompositeOperation="destination-over",c.fillRect(0,0,width(),height()),c.fillStyle=settings.color,c.globalCompositeOperation=settings.composite;break;case"current color":c.fillStyle=settings.bg,c.globalCompositeOperation="destination-over",c.fillRect(0,0,width(),height()),c.globalCompositeOperation=settings.composite}var b=$c[0].toDataURL();if("sketchy project"==save.type){var d,e=JSON.parse(localStorage.getItem("projects"));e&&e.some(function(a,b){return a.name==save["file name"]?(d=b,!0):!1})?confirm("A sketch with this name already exists. Do you want to overwrite "+save["file name"]+"?")&&(console.log(d),e[d]={name:save["file name"],data:b,points:window.points,settings:settings},localStorage.setItem("projects",JSON.stringify(e))):(e?e.push({name:save["file name"],data:b,points:window.points,settings:settings}):e=[{name:save["file name"],data:b,points:window.points,settings:settings}],localStorage.setItem("projects",JSON.stringify(e)))}else{dataToBlob(b),window.requestFileSystem(LocalFileSystem.PERSISTENT,0,function(){window.alert("SD")},function(){alert("SD Error")})}c.putImageData(a,0,0)},window.load=function(){var a=JSON.parse(localStorage.getItem("projects")).filter(function(a){return a.name==load.file})[0],b=document.createElement("img");b.src=a.data,b.onload=function(){c.clearRect(0,0,width(),height()),c.drawImage(b,0,0),window.points=a.points,window.points.history=[{data:c.createImageData($c.width(),$c.height()),points:[]},{data:c.getImageData(0,0,width(),height()),points:a.points}],$c.first().css("background",a.settings.bg),window.settings.bg=a.settings.bg}},localStorage.getItem("sawVote")||($(".vote").removeClass("hidden"),localStorage.setItem("sawVote",!0))},!1)});

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -1 +1 @@
"use strict";$(document).ready(function(){function a(){var b=c.getImageData(0,0,width(),height());switch(a.background){case"white":c.fillStyle="white",c.globalCompositeOperation="destination-over",c.fillRect(0,0,width(),height()),c.fillStyle=settings.color,c.globalCompositeOperation=settings.composite;break;case"current color":c.fillStyle=settings.bg,c.globalCompositeOperation="destination-over",c.fillRect(0,0,width(),height()),c.globalCompositeOperation=settings.composite}var d=$c[0].toDataURL();if("sketchy project"==a.type){var e,f=JSON.parse(localStorage.getItem("projects"));f&&f.some(function(b,c){return b.name==a["file name"]?(e=c,!0):!1})?confirm("A sketch with this name already exists. Do you want to overwrite "+a["file name"]+"?")&&(console.log(e),f[e]={name:a["file name"],data:d,points:window.points,settings:settings},localStorage.setItem("projects",JSON.stringify(f))):f?f.push({name:a["file name"],data:d,points:window.points,settings:settings}):f=[{name:a["file name"],data:d,points:window.points,settings:settings}],localStorage.setItem("projects",JSON.stringify(f))}else window.open(d,"_blank").focus();c.putImageData(b,0,0)}function b(){var a=JSON.parse(localStorage.getItem("projects")).filter(function(a){return a.name==b.file})[0],d=document.createElement("img");d.src=a.data,d.onload=function(){c.clearRect(0,0,width(),height()),c.drawImage(d,0,0),window.points=a.points,window.points.history=[{data:c.createImageData($c.width(),$c.height()),points:[]},{data:c.getImageData(0,0,width(),height()),points:a.points}],$c.first().css("background",a.settings.bg),window.settings.bg=a.settings.bg}}yepnope({test:window.mobile,yep:["js/mobile.js","js/libs/color-picker-touch.js"],nope:["js/libs/color-picker.js"]}),$(window).resize(sizeAndPos),window.load=b,window.save=a}); "use strict";$(document).ready(function(){function a(){var b=c.getImageData(0,0,width(),height());switch(a.background){case"white":c.fillStyle="white",c.globalCompositeOperation="destination-over",c.fillRect(0,0,width(),height()),c.fillStyle=settings.color,c.globalCompositeOperation=settings.composite;break;case"current color":c.fillStyle=settings.bg,c.globalCompositeOperation="destination-over",c.fillRect(0,0,width(),height()),c.globalCompositeOperation=settings.composite}var d=$c[0].toDataURL();if("sketchy project"==a.type){var e,f=JSON.parse(localStorage.getItem("projects"));f&&f.some(function(b,c){return b.name==a["file name"]?(e=c,!0):!1})?confirm("A sketch with this name already exists. Do you want to overwrite "+a["file name"]+"?")&&(console.log(e),f[e]={name:a["file name"],data:d,points:window.points,settings:settings},localStorage.setItem("projects",JSON.stringify(f))):f?f.push({name:a["file name"],data:d,points:window.points,settings:settings}):f=[{name:a["file name"],data:d,points:window.points,settings:settings}],localStorage.setItem("projects",JSON.stringify(f))}else $('<a href="'+d+'" download="'+a["file name"]+'.png"></a>').click();c.putImageData(b,0,0)}function b(){var a=JSON.parse(localStorage.getItem("projects")).filter(function(a){return a.name==b.file})[0],d=document.createElement("img");d.src=a.data,d.onload=function(){c.clearRect(0,0,width(),height()),c.drawImage(d,0,0),window.points=a.points,window.points.history=[{data:c.createImageData($c.width(),$c.height()),points:[]},{data:c.getImageData(0,0,width(),height()),points:a.points}],$c.first().css("background",a.settings.bg),window.settings.bg=a.settings.bg}}yepnope({test:window.mobile,yep:["js/mobile.js","js/libs/color-picker-touch.js"],nope:["js/libs/color-picker.js"]}),$(window).resize(sizeAndPos),window.load=b,window.save=a});

6
deploy-android Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
grunt;
cp -R build/android/* ~/Documents/Workshop/Sketchy-Android/sketchy/www/
cd ~/Documents/Workshop/Sketchy-Android/sketchy
phonegap run android

Binary file not shown.

Binary file not shown.