Hi, I’m writing a small script to add an item to desktop

Hi, I’m writing a small script to add an item to desktop

var l = LL.getCurrentDesktop();

var item=l.getItemByLabel(“foo”);

if (!item){

var item=l.addShortcut(“foo”,new Intent(),600,1200);

}

ce=item.getProperties().edit();

   ce.setBoolean(“i.onGrid”,false);

ce.setString(“s.labelVsIconPosition”,”RIGHT”);

   box=ce.getBox(“i.box”);

   box.setAlignment(“LEFT”,”MIDDLE”);

ce.commit();

item.setSize(150,150);

item.setRotation(315);

Android.makeNewToast(“Done”,true).show();

It works, but item’s position is X 544,934 Y 1134,648. How to fix it?

6 Commentsto Hi, I’m writing a small script to add an item to desktop

  1. If you create a new item, it’s normally attached to the grid, so you are setting it 1200 cells away. It’s best to first create an item at 0/0, then detach and move it.

  2. TrianguloY says:

    Lukas Morawietz​ I need to check, but I think that when you use addShortcut, the x and y are always set in ‘detached mode’

    Azariasz Trzciński​​ the problem is that, as Lukas said, the item is set by default on grid mode, and it’s position is slightly altered to match the cell. For this reason when you detach it, it has different x and y.

    You can either follow Lukas suggestion (I recommend that too) or in the container properties, layout, check ‘detach by default’

  3. TrianguloY you’re right, the shortcut is created in the nearest cell.

  4. Thanks!!! You’re very helpfull!

  5. I think it’s because of rotation

  6. TrianguloY says:

    Jappie Toutenhoofd is right too.

    When you rotate an item, it is rotated keeping it’s center, it’s position is the top left corner of the minimum box containing the item and it change.

    You should set the scale/size, rotation, and position in that order for exact precision

Leave a Reply

Your email address will not be published. Required fields are marked *