Codename One Animation Trouble (also in Solitaire demo)?

What happened to the Codename One animation? I use a lot of them, and since December, my application no longer works. When I left in June, everything was fine (and it has been like this for more than a year).

My application is a game with checkers (checkers) and has been available in application stores since 2013. After watching the CN1 Poker demo, I completely rewrote my GUI because I wanted to add such animations to my application. Now what happens is that I suddenly get an index from related exceptions. I narrowed it down to the following situation:

cont.addComponent(comp);
...
...
cont.getComponent(0);  <-- index out of bound exception: 0 out of 0

I already used newVM = true in June, which, in my opinion, became the default. I tried to fix the situation by adding

cont.animateLayoutAndWait(100);

after calling addComponent. This fixed the index from the associated exceptions, but now the application just crashes at random times after it works normally for a short time. I tried, but could not find the source of the problem. Something has changed in CN1, so my code no longer works. (See also the old forum, searching for “drafts,” where I posted a complete list of my main design.)

Solitaire, , . Solitaire iOS/Android. , , , , . . , . .

GUI, Solitaire: , , GridLayout (10,10), Solitaire SolitaireLayout(). , : DOWN , , , .

:

Button pc = (Button)piecesCnt.getComponentAt(a1);
Button to = (Button)piecesCnt.getComponentAt(a2);

piecesCnt.removeComponent(pc);
piecesCnt.addComponent(a1, createPieceButton(Piece.EMPTY_PIECE, true));
piecesCnt.removeComponent(to);
piecesCnt.addComponent(a2, pc);

piecesCnt.animateLayoutAndWait(1000);

, , GridLayout, , () /, , Solitaire.

SolitaireLayout GridLayout? , ? .

Android () . Solitaire CN1 ( 3.2.6, libs 2016-01-11). 10 , , . Simulator , iOS Android .

(Windows 7, NetBeans 8.0.2): - , . - ? 3 , . - ; . - . ( .)

iOS 9.2 (iPad 4), iOS 8.4 (iPhone 4): - [?] . - /. - , , , , , . . - /: 0 1. - "" . iPhone: - : -J, club-10, club-K, diamond-Q; .. 2 .

Android 5.1.1 (Nexus 7) . - . () , . , , , 1. . , , , . . - , . , , () . ( , ). - , , ( ), . - , ; . , . .

, , , . , -, Codename. , . , !

+4
2

, , , . , ( ).

, /, .

: https://www.codenameone.com/blog/new-animation-manager.html

, , , . Component.removeComponent() , , .

, :

form.getAnimationManager().flushAnimation(() -> doThisAfterAnimation());

.

"" , , , 1000 , , , ( add/ ).

, , flushAnimation, , . , , , , . add/remove , ...

+1

, 16 . Solitaire 8 31 , , . , , . Januari 11 , / .

, Solitaire ​​ .

:

1) ? , , .

// simplified code (background layer omitted)
public void start() {
    if(current != null){
        current.show();
        return;
    }

    Form form = new Form("Draughts 2");
    Container piecesCnt = new Container(new GridLayout(10, 10));
    for (int i=0; i<100; i++) {
        piecesCnt.addComponent(createPieceButton(piece(i), true));
    }
    form.addComponent(piecesCnt);
    form.show();

    new UITimer(() -> {
        testAnimation(piecesCnt, 0,9 , 9,0);    // moves UNDER other pieces
        testAnimation(piecesCnt, 9,0 , 0,9);    //   "   OVER    "     "
        testAnimation(piecesCnt, 1,0 , 9,8);    //   "   OVER    "     "
        testAnimation(piecesCnt, 9,8 , 1,0);    //   "   UNDER   "     "
    }).schedule(1500, false, form);
}

private void testAnimation(Container piecesCnt, int x1,int y1, int x2,int y2) {
    int a1 = 10 * y1 + x1;
    int a2 = 10 * y2 + x2;        
    Button pc = (Button)piecesCnt.getComponentAt(a1);
    Button to = (Button)piecesCnt.getComponentAt(a2);
    piecesCnt.removeComponent(pc);
    piecesCnt.addComponent(a1, createPieceButton(Piece.EMPTY_PIECE, true));
    piecesCnt.removeComponent(to);
    piecesCnt.addComponent(a2, pc);
    piecesCnt.animateLayoutAndWait(1000);
}

2) , () ?

3) TestAnimation? ( , .)


2016-01-14 (. "" ):

flushAnimations:

1) :

private void flushAnimations(Form f) {
    f.getAnimationManager().flushAnimation(() -> {});
}

. .

2) flushAnimations:

testAnimation(piecesCnt, 0,9 , 9,0);
f.getAnimationManager().flushAnimation(() -> {
    testAnimation(piecesCnt, 9,0 , 0,9);
    f.getAnimationManager().flushAnimation(() -> {
        testAnimation(piecesCnt, 1,0 , 9,8);
        f.getAnimationManager().flushAnimation(() -> {
            testAnimation(piecesCnt, 9,8 , 1,0);
        });
    });
});

iOS, Android: . , .

UITimer:

blockUI(piecesCnt);
new UITimer(() -> { testAnimation(piecesCnt, 0,9 , 9,0); }).schedule(2000, false, f);
new UITimer(() -> { testAnimation(piecesCnt, 9,0 , 0,9); }).schedule(3500, false, f);
new UITimer(() -> { testAnimation(piecesCnt, 1,0 , 9,8); }).schedule(5000, false, f);
new UITimer(() -> { testAnimation(piecesCnt, 9,8 , 1,0); }).schedule(6500, false, f);
new UITimer(() -> { 
    unblockUI(piecesCnt); 
}).schedule(8000, false, f);

private boolean blocked = false;    
private void blockUI(Container piecesCnt) {
    blocked = true;
    int n = piecesCnt.getComponentCount();
    for (int i=0; i<n; i++) {
        piecesCnt.getComponentAt(i).setDraggable(false);
    }
}
private void unblockUI(Container piecesCnt) {
    ...
}

, . autoplay, , > 100 , 1 . , .

, - Poker and Solitaire (Autoplay!) .

, , , , : http://toernooibase.kndb.nl/opvraag/applet.php?taal=1&kl=46&Id=4579&r=10&jr=16&wed=845502. (' > ') . ( , , , 1 , .)

, 13 , / . , CN1Poker, , - Android: , . ( Simulator iOS.)

, " "? , . , - : animateLayoutAndWait / ( , ).

( 3 ), CN1, CN1 , . , , ​​.

0

Source: https://habr.com/ru/post/1623927/


All Articles