now browsing by tag

 
 

Hi all, this is a question for the more experienced script programmers.

Hi all, this is a question for the more experienced script programmers. I was looking at ways to optimize my code and I found that it would be handy if I could assign custom fields to item objects, because then I would be able to store calculated values on the item and if be able to use them in functions to which I would only have to pass the item as argument and not also the calculated value. Actually I wouldn’t even have to pass the items as an argument to the functions because I could make the function run on the item.

After some searching I found this: http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript

I implemented this in a small example script:

dummy = LL.getCurrentDesktop().addShortcut(“dummy”,new Intent(),0,0);

// OLD WAY

/*

function displayCenter(it, center){

it.setLabel(center[0]+”,”+center[1]);

}

function moveToCenter(it, center){

it.setPosition(center[0], center[1]);

}

function center(item){

var r=item.getRotation()*Math.PI/180;

var sin=Math.abs(Math.sin(r));

var cos=Math.abs(Math.cos(r));

var w=item.getWidth()*item.getScaleX();

var h=item.getHeight()*item.getScaleY();

return[item.getPositionX()+(w*cos+h*sin)*0.5,item.getPositionY()+(h*cos+w*sin)*0.5];

}

var center = center(dummy);

displayCenter(dummy, center);

moveToCenter(dummy, center);

*/

//NEW WAY:

myItem = function(){

this.getCenter = function(){

if(this.center==null){

alert(“test”)

var r=this.getRotation()*Math.PI/180;

var sin=Math.abs(Math.sin(r));

var cos=Math.abs(Math.cos(r));

var w=this.getWidth()*this.getScaleX();

var h=this.getHeight()*this.getScaleY();

var center = [this.getPositionX()+(w*cos+h*sin)*0.5,this.getPositionY()+(h*cos+w*sin)*0.5]

this.center = center;

}

return this.center;

};

this.displayCenter = function(){

this.setLabel(this.getCenter()[0]+”, “+this.getCenter()[1]);

};

this.moveToCenter = function(){

this.setPosition(this.getCenter()[0], this.getCenter()[1]);

};

};

myItem.prototype = dummy;

myDummy = new myItem();

myDummy.displayCenter();

myDummy.moveToCenter();

myDummy.setSize(288, myDummy.getHeight()) //ALSO STILL WORKS BOTH WORK ON SAME OBJECT DESPITE THAT I DIDN’T DEFINE A getPositionX() IN myItem 😀

As you can see this enables me to do what I explained herebove, but I haven’t seen anyone do it before, so I am wondering if there is anything bad happening here or I actually found something cool and useful.

Please tell me what you think in the comments.

Thanks for reading 🙂

cdfa

http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript
]]>

Hi all, this is a question for the more experienced users: I was looking at ways to optimize my code and I found…

Hi all, this is a question for the more experienced users: I was looking at ways to optimize my code and I found that I would be handy if I could assign custom fields to item objects, but LL doesn’t allow me to. The I found this: http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript

I implemented this in a small example script:

dummy = LL.getCurrentDesktop().addShortcut(“dummy”,new Intent(),0,0);

myItem = function(){

this.getCenter = function(){

var r=this.getRotation()*Math.PI/180;

var sin=Math.abs(Math.sin(r));

var cos=Math.abs(Math.cos(r));

var w=this.getWidth()*this.getScaleX();

var h=this.getHeight()*this.getScaleY();

return[this.getPositionX()+(w*cos+h*sin)*0.5,this.getPositionY()+(h*cos+w*sin)*0.5];

};

};

myItem.prototype = dummy;

myDummy = new myItem();

alert(myDummy.getCenter()[0])

alert(myDummy.getPositionX()) // BOTH WORK ON SAME OBJECT AND DIDN’T DEFINE A getPositionX() IN myItem 😀

I never seen anyone use this, so I was wondering if there is anything that makes this very inefficient or I actually discovered something pretty cool.

Thanks for reading 🙂

Colin

http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript
]]>

Quick question: would it be more efficient for a script that is executed lots of times per second to get data with…

Quick question: would it be more efficient for a script that is executed lots of times per second to get data with script.getTag() each time or to only do this once, save it to this.valueName and get it from that each time. (The data doesn’t change between script executions, and the tag would only be set once)

Might sound kinda stupid, but just to be sure…

]]>

I just got this idea that I think wouldn’t be relatively easy to implement and would be really useful, especially…

I just got this idea that I think wouldn’t be relatively easy to implement and would be really useful, especially for beginning scripters: could you make a long press on a function suggestion in the script editor take you to the doucumentation for that function on the wiki?

]]>

In 12.5.1 dynamic texts are untouchable.

In 12.5.1 dynamic texts are untouchable. Not in “normal” mode and neither in edit mode. A launcher restart fixes it though.

]]>

I have a script with only this line:

I have a script with only this line:

alert(LL.getEvent().getSource())

When i put the script on an touch event of an item event.getSource() somehow returns the source of the event that was fired before I touched the item. (For example it would say C_RESUMED if I had just switched to that desktop)

]]>

Does anybody know a way to use a custom xml layout file for the childView in a expandable list?

Does anybody know a way to use a custom xml layout file for the childView in a expandable list? Might be a bit of a far out question, but I know there are some really smart guys here.

]]>

This might be suggested before, or there might already be a known way of doing it, but is there a way to get all the…

This might be suggested before, or there might already be a known way of doing it, but is there a way to get all the tags associated with a script? If not, it would be nice to see such method in the scripting api :).

]]>

New script if you want to have multiple things happen on the same event.

New script if you want to have multiple things happen on the same event. Does require some scripting knowlegde to use though. If there are any bugs please let me know, but it should work fairly well. If you have any suggestions on how to improve this let me know too! Import it here: http://www.pierrox.net/android/applications/lightning_launcher/wiki/doku.php?id=script_event_bus

http://www.pierrox.net/android/applications/lightning_launcher/wiki/doku.php?id=script_event_bus
]]>

1:I don’t know of there is a special reason I’m missing this is how it is, but it I make an item invisible with…

1:I don’t know of there is a special reason I’m missing this is how it is, but it I make an item invisible with scripts it becomes visible again after app restart. I would at least like an option to turn this on or off.

2: I thought there used to be an option to turn this off, but since there is also snapping (I think that’s how it’s called) to the edges of items when you are moving an item in edit mode and not only to the center of another item I can’t find it anymore. I actually like the item snapping, but the thing that I would really like an option for or to be turned off by default is that the snapping also works with invisible items. I use quite a lot invisible items in a small space and it gets a bit annoying seeing all the bounding boxes because now the items is just snapping from place to place.

I might be asking for things that not a lot of people would use, but if you can find the time I would really like to see them implemented :).

Thanks for a great launcher

Colin

]]>