====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
script_gesture_launcher [2014/08/31 15:07] lm13 [How to use the script] |
script_gesture_launcher [2014/12/20 12:31] (current) lm13 |
||
---|---|---|---|
Line 2: | Line 2: | ||
* Purpose : This script is will use an item as gesture detection area, so you can launch any shortcut by a gesture! | * Purpose : This script is will use an item as gesture detection area, so you can launch any shortcut by a gesture! | ||
* Author : [[https://plus.google.com/+LukasMorawietz|LM13]] | * Author : [[https://plus.google.com/+LukasMorawietz|LM13]] | ||
- | * Current Version : 1.0 | + | * Current Version : 1.1 |
- | * Link : | + | * Link (with video): https://plus.google.com/115366157037831519359/posts/ZzXD1hKNrf2 |
====== Changelog ====== | ====== Changelog ====== | ||
* Version 1.0 (31/8/2014): initial release in wiki | * Version 1.0 (31/8/2014): initial release in wiki | ||
+ | * Version 1.1 (2/9/2014): More stable loading, First gesture Bug fix (hopefully) | ||
====== How to use the script ====== | ====== How to use the script ====== | ||
Line 21: | Line 22: | ||
* With too much gestures it may stop working | * With too much gestures it may stop working | ||
* the first gesture after LL started may be not fully drawn or not detected. | * the first gesture after LL started may be not fully drawn or not detected. | ||
+ | * if more than one gesture is matching, one is selected by database, so avoid similar gestures | ||
+ | * straight horizontal or vertical lines may not work as gesture. | ||
//please report all bugs in the g+ community// | //please report all bugs in the g+ community// | ||
Line 27: | Line 30: | ||
var tolerance=7; | var tolerance=7; | ||
var itemID=0x060029; | var itemID=0x060029; | ||
- | var bgColor=0x00ffffff; | + | var bgColor=0x10ffffff; |
var gestureColor=0xffffffff; | var gestureColor=0xffffffff; | ||
//endconfig | //endconfig | ||
Line 49: | Line 52: | ||
image.update(); | image.update(); | ||
item.setBoxBackground(image,"n"); | item.setBoxBackground(image,"n"); | ||
- | if(typeof gestures==='undefined')gestures=JSON.parse(item.getTag())||[]; | + | done=false; |
- | for(var a=0;a<gestures.length;a++) | + | setTimeout(loadGestures,0); |
- | { | + | |
- | if(LL.getItemById(gestures[a][1])==null)gestures.splice(a,1); | + | |
- | } | + | |
- | item.setTag(JSON.stringify(gestures)); | + | |
break; | break; | ||
case MotionEvent.ACTION_MOVE: | case MotionEvent.ACTION_MOVE: | ||
this.gesture.push([event.getX(),event.getY()]); | 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); | canvas.drawLine(this.gesture[this.gesture.length-2][0],this.gesture[this.gesture.length-2][1],event.getX(),event.getY(),paint); | ||
- | image.update(); | + | image.update();item.setBoxBackground(image,"n"); |
break; | break; | ||
case MotionEvent.ACTION_UP: | case MotionEvent.ACTION_UP: | ||
this.gesture.push([event.getX(),event.getY()]); | 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); | canvas.drawLine(this.gesture[this.gesture.length-2][0],this.gesture[this.gesture.length-2][1],event.getX(),event.getY(),paint); | ||
+ | while(!done); | ||
if(add!=null) | if(add!=null) | ||
{ | { | ||
Line 114: | Line 114: | ||
catch(NullPointerException) | catch(NullPointerException) | ||
{ | { | ||
- | gestures=JSON.parse((LL.getItemById(itemID)).getTag())||[]; | + | item=LL.getItemById(itemID);gestures=JSON.parse(item.getTag())||[]; |
for(var a=0;a<gestures.length;a++) | for(var a=0;a<gestures.length;a++) | ||
{ | { | ||
Line 129: | Line 129: | ||
if(gestures[a][1]==event.getItem().getId()) | if(gestures[a][1]==event.getItem().getId()) | ||
{ | { | ||
- | if(!confirm("This shortcut has already a gesture. Do you want to replace it?"))return; | + | 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); | ||
+ | paint.setColor(gestureColor); | ||
+ | for(var z=1;z<gestures[a][0].length;z++) | ||
+ | { | ||
+ | canvas.drawLine(gestures[a][0][z-1][0]/100*item.getWidth(),gestures[a][0][z-1][1]/100*item.getHeight(),gestures[a][0][z][0]/100*item.getWidth(),gestures[a][0][z][1]/100*item.getHeight(),paint); | ||
+ | } | ||
+ | image.update(); | ||
+ | item.setBoxBackground(image,"n"); | ||
+ | if(!confirm("This shortcut has already a gesture. It is now displayed until something is drawn. Do you want to replace it?"))return; | ||
gestures.splice(a,1); | gestures.splice(a,1); | ||
break; | break; | ||
} | } | ||
} | } | ||
- | LL.getItemById(itemID).setTag(JSON.stringify(gestures)); | + | item.setTag(JSON.stringify(gestures)); |
Android.makeNewToast("The next drawn Gesture will be set to this shortcut",true).show(); | Android.makeNewToast("The next drawn Gesture will be set to this shortcut",true).show(); | ||
add=event.getItem().getId(); | add=event.getItem().getId(); | ||
Line 155: | Line 171: | ||
} | } | ||
return scaled; | return scaled; | ||
+ | } | ||
+ | |||
+ | |||
+ | function loadGestures() | ||
+ | { | ||
+ | if(typeof gestures==='undefined')gestures=JSON.parse(item.getTag())||[]; | ||
+ | for(var a=0;a<gestures.length;a++) | ||
+ | { | ||
+ | if(LL.getItemById(gestures[a][1])==null)gestures.splice(a,1); | ||
+ | } | ||
+ | item.setTag(JSON.stringify(gestures)); | ||
+ | done=true; | ||
} | } | ||
</sxh> | </sxh> |