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,6 +5,7 @@
<title>Sketchy</title>
<meta charset='UTF-8'>
<link rel='stylesheet' href='css/main.css'>
<script src='cordova.js'></script>
</head>
<body>

View File

@ -1,123 +1,136 @@
$(document).ready(function() {
$('*').off('click mousemove mousedown mouseup mouseleave').on('click mousemove mousedown mouseup mouseleave', function(e) {
e.preventDefault;
$(document).on('resume', function() {
sizeAndPos();
})
document.addEventListener('deviceready', function() {
sizeAndPos();
/*$('a[href^="http"]').tap(function(e) {
e.preventDefault();
var href = $(this).attr('href');
var view = new MozActivity({
name: 'view',
data: {
type: 'url',
url: href
}
$('*').off('click mousemove mousedown mouseup mouseleave').on('click mousemove mousedown mouseup mouseleave', function(e) {
e.preventDefault;
})
return false;
}).click(function(e) {
e.preventDefault();
return false;
})*/
/*$('a[href^="mailto"]').tap(function(e) {
e.preventDefault();
var mail = new MozActivity({
name: 'new',
data: {
type: 'mail',
url: $(this).attr('href')
}
})
return false;
}).click(function(e) {
e.preventDefault();
return false;
})*/
/*$('a[href^="http"]').tap(function(e) {
e.preventDefault();
var href = $(this).attr('href');
var view = new MozActivity({
name: 'view',
data: {
type: 'url',
url: href
}
})
window.save = function() {
var f = 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;
break;
}
}
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 }) ) {
if( confirm('A sketch with this name already exists. Do you want to overwrite ' + save['file name'] + '?') ) {
console.log(index);
list[index] = {
name: save['file name'],
data: data,
points: window.points,
settings: settings
}
localStorage.setItem('projects', JSON.stringify(list));
return false;
}).click(function(e) {
e.preventDefault();
return false;
})*/
/*$('a[href^="mailto"]').tap(function(e) {
e.preventDefault();
var mail = new MozActivity({
name: 'new',
data: {
type: 'mail',
url: $(this).attr('href')
}
})
return false;
}).click(function(e) {
e.preventDefault();
return false;
})*/
window.save = function() {
var f = 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;
break;
}
}
else {
list ? list.push({
name: save['file name'],
data: data,
points: window.points,
settings: settings
}) : list = [{
name: save['file name'],
data: data,
points: window.points,
settings: settings
}];
localStorage.setItem('projects', JSON.stringify(list));
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 }) ) {
if( confirm('A sketch with this name already exists. Do you want to overwrite ' + save['file name'] + '?') ) {
console.log(index);
list[index] = {
name: save['file name'],
data: data,
points: window.points,
settings: settings
}
localStorage.setItem('projects', JSON.stringify(list));
}
}
else {
list ? list.push({
name: save['file name'],
data: data,
points: window.points,
settings: settings
}) : list = [{
name: save['file name'],
data: data,
points: window.points,
settings: settings
}];
localStorage.setItem('projects', JSON.stringify(list));
}
} else {
var img = dataToBlob(data);
var sd = window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
window.alert('SD');
/*var req = fs.root.getFile(save['file name'] + '.png', {create: true}, function(entry) {
alert('Entry');
entry.createWriter(function(writer) {
writer.write(img);
alert('Your Sketch was saved successfuly');
}, function() {
alert('Something bad happened trying to save your sketch ' + save['file name'] + '\n Possible reasons:\n Duplicate Name \n Not enough permission')
})
})*/
}, function(e) {
alert('SD Error')
//alert('Couldn\'t access filesystem\nERR: ' + e.code);
});
}
} else {
var sd = window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
var fdata = dataToBlob(data);
var req = fs.root.getFile(save['file name'] + '.png', {create: true}, function(file) {
file.createWriter(function(writer) {
writer.write(fdata);
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(error) {
alert('Couldn\'t access filesystem\n' + error.message);
});
c.putImageData(f, 0, 0);
}
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;
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') ) {
$('.vote').removeClass('hidden');
localStorage.setItem('sawVote', true);
}
if( !localStorage.getItem('sawVote') ) {
$('.vote').removeClass('hidden');
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',
filter: 'isFile'
},
{
expand: true,
cwd: 'Shared/js',
src: '**',
dest: 'build/android/js',
filter: 'isFile'
},
{
expand: true,
cwd: 'Mobile/js/',
@ -79,7 +86,7 @@ module.exports = function(grunt) {
{
expand: true,
cwd: 'Android',
src: ['index.html', 'config.xml', 'res/**', 'icon.png'],
src: ['index.html', 'config.xml', 'AndroidManifest.xml', 'res/**', 'icon.png'],
dest: 'build/android'
},
{

View File

@ -61,7 +61,8 @@ $(document).ready(function() {
}];
localStorage.setItem('projects', JSON.stringify(list));
} 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);

View File

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

View File

@ -13,7 +13,7 @@
</author>
<content src='index.html'/>
<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='SplashScreen' value='sketchy'/>
@ -21,7 +21,12 @@
<preference name='FullScreen' 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>

View File

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

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.