I had this idea already weeks ago, but now I had the time to realize it.
I had this idea already weeks ago, but now I had the time to realize it.
Now its far enough to be shown. It’s nothing ready or save, more a preview.
It’s free Gesture drawing.
It gets slower with more gestures saved, I don’t know where the maximum is.
]]>
< ![CDATA[
//config
var tolerance=7;
var itemID=0x070001;
var bgColor=0x00000000;
var gestureColor=0xffffffff;
//endconfig
if(typeof add===’undefined’)add=null;
try{
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
gestures=JSON.parse(item.getTag())||[];
for(var a=0;a
{
if(LL.getItemById(gestures[a][1])==null)gestures.splice(a,1);
}
item.setTag(JSON.stringify(gestures));
paint=new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(gestureColor);
paint.setStrokeWidth(5);
paint.setStrokeJoin(Paint.Join.ROUND);
image=item.getBoxBackground(“n”);
if(image.getWidth()!=item.getWidth()||image.getHeight()!=item.getHeight())image=LL.createImage(item.getWidth(),item.getHeight());
canvas=image.draw();
image.getBitmap().eraseColor(Color.TRANSPARENT);
canvas.drawColor(bgColor);
this.gesture=[];
this.gesture.push([event.getX(),event.getY()]);
break;
case MotionEvent.ACTION_MOVE:
this.gesture.push([event.getX(),event.getY()]);
canvas.drawLine(this.gesture[this.gesture.length-2][0],this.gesture[this.gesture.length-2][1],event.getX(),event.getY(),paint);
image.update();
break;
case MotionEvent.ACTION_UP:
this.gesture.push([event.getX(),event.getY()]);
canvas.drawLine(this.gesture[this.gesture.length-2][0],this.gesture[this.gesture.length-2][1],event.getX(),event.getY(),paint);
if(add!=null)
{
gestures.push([scaleGesture(this.gesture),add]);
item.setTag(JSON.stringify(gestures));
add=null;
Android.makeNewToast(“Saved!”,true).show();
}
else
{
var sg=scaleGesture(this.gesture);
schleife:for(var x=0;x
{
var sp=gestures[x][0];
var gesDiff=0;
for(var i=0;i
{
var p0=sg[i];
var diff=200;
for(var a=Math.round((i/sg.length)*sp.length)-Math.round(sp.length/4)<0?0:Math.round((i/sg.length)*sp.length)-Math.round(sp.length/4);a< =Math.round((i/sg.length)*sp.length)+Math.round(sp.length/4)&&a
{
var p1=sp[a];
var newDiff=Math.sqrt(Math.pow(p0[0]-p1[0],2)+Math.pow(p0[1]-p1[1],2));
if(newDiff
{
diff=newDiff;
}
}
if(diff>tolerance*4)
{
continue schleife;
}
gesDiff=gesDiff+diff;
}
if(gesDiff/sg.length
{
break;
}
}
if(x==gestures.length)Android.makeNewToast(“No gesture detected”,true).show();
else LL.startActivity(LL.getItemById(gestures[x][1]).getIntent());
}
image.getBitmap().eraseColor(Color.TRANSPARENT);
canvas.drawColor(bgColor);
image.save();
item.setBoxBackground(image,”n”);
break;
}
}
catch(NullPointerException)
{
gestures=JSON.parse((LL.getItemById(itemID)).getTag())||[];
for(var a=0;a
{
if(LL.getItemById(gestures[a][1])==null)gestures.splice(a,1);
}
event=LL.getEvent();
for(var a=0;a
{
if(gestures[a][1]==event.getItem().getId())
{
if(!confirm(“This shortcut has already a gesture. Do you want to replace it?”))return;
gestures.splice(a,1);
break;
}
}
LL.getItemById(itemID).setTag(JSON.stringify(gestures));
Android.makeNewToast(“The next drawn Gesture will be set to this shortcut”,true).show();
add=event.getItem().getId();
}
function scaleGesture(GESTURE)
{
var maxx=0,minx=item.getWidth(),maxy=0,miny=item.getHeight();
for(var i=0;i
{
if(GESTURE[i][0]
if(GESTURE[i][0]>maxx)maxx=GESTURE[i][0];
if(GESTURE[i][1]
if(GESTURE[i][1]>maxy)maxy=GESTURE[i][1];
}
var scaled=[];
for(var i=0;i
{
scaled.push([(GESTURE[i][0]-minx)/(maxx-minx)*100,(GESTURE[i][1]-miny)/(maxy-miny)*100]);
}
return scaled;
}
]]>
< ![CDATA[
Amazing!
I am impressed.
]]>
< ![CDATA[
Beautiful work… Im interested to know about your app drawer too
]]>
< ![CDATA[
Hammer
🙂
]]>
< ![CDATA[
Impressive. What is the live Wallpaper ?
]]>
< ![CDATA[
Xavier Nicaise
audio glow lwp
]]>
< ![CDATA[
‘Schleife’
Ah! So you can continue a ‘for’ inside another ‘for’…impressed. Didn’t know.
Good job.
]]>
< ![CDATA[
the name doesn’t matter, you can use any other name (beside reserved ones).
‘schleife’ just maens loop in german 😀
BTW: this works also with break
]]>
< ![CDATA[
when changing the itemID is that for the gesture shortcut we created?
]]>
< ![CDATA[
Curtis Sylvester Jr.
yes.
]]>
< ![CDATA[
then something is wrong because i created my shortcut, grabbed its ID and put it in the script. then i ran the script from [choose app shortcut here] (which flashed a notice for next drawing being saved), i went to draw my gesture to save and the same notice came up again…. this time taking about 5 minutes to shut up. the gesture never got saved
]]>
< ![CDATA[
I haven’t tried this script for a while, maybe it’s broken in the current version… My phone is broken ATM, I can’t try.
]]>
< ![CDATA[
I added it from the repository importer as the instructions say but when I swipe over it it says “At line 56: missing ; after for-loop condition”. How do I fix it? Also what is the proper way to change the itemID?
Edit: I added the script in the first comment & now I’m having the same problem as Curtis Sylvester Jr.​ What’s wrong?
]]>
< ![CDATA[
bahrta sai
i could not reproduce the error. And honetly, I haven’t looked at this script for more than a year, I have no idea if it will work in the current version.
]]>
< ![CDATA[
bahrta sai​ do you have the latest version of repository importer?
If so, what your line 56 look like? 
]]>
< ![CDATA[
bahrta sai the script in the first comment is outdated. I am currently rebuilding this functionality from scratch as part of my MultiTool. Are you interested in testing it?
]]>