SlideShare a Scribd company logo
1 of 9
Download to read offline
Animations - Part II
Layout animations are some of the most important yet easy to use animations in Codename One. They make the application flow feel reactive and responsive.
Layout Animation
© Codename One 2017 all rights reserved
✦Layout animations rely on the behavior of Codename
One which doesn’t implicitly “reflow” components
✦Instead of calling revalidate() we can call
animateLayout(int) or equivalent to animate the
components to their final correct place/size
✦This is useful for smooth UI’s where components
should “flow” into place rather than jump into it
At the core of layout animations is the concept of explicit reflow. In Codename One layouts determine the position of components. That means that if you add a new
component it will be positioned by the layout, however there is a big caveat. If you add the component after the form was shown it won’t position itself unless you do
something like rotate the device which implicitly lays out the component. You need to ask for layout explicitly. You can invoke revalidate to force layout, this is valuable for
cases where you can add multiple components. In those cases the layout logic can happen only once and can be much simpler.

Layout animation works by animating the validate effect. It takes the components from their previously invalid or incorrect positions and moves them into their real final
position. Normally when you add a component you won’t set a size or position to it as those will be determined by the layout manager, but with layout animations this
can be useful as you can position a component explicitly and then it will animate from that position.

This allows you to create a flow in the UI so components “settle” into place, this serves to draw attention to changes in the UI in most cases
Unlayout Animations
© Codename One 2017 all rights reserved
✦ animateUnlayout() and equivalent methods do the
opposite, they move an element to an “illegal” place from
the valid position thru an animation
✦ This is useful if we want to remove a component, we can
move it offscreen then call animateUnlayoutAndWait() to
animate that process then remove the component
✦ It’s assumed that animateUnlayout will be followed by code
to correct the UI after it completes
Animate unlayout is the exact opposite or evil twin of the animate layout method. Animate layout takes layout in an invalid state and returns it to normal layout with an
animation. Animate unlayout takes layout in an invalid state, returns it to normal instantly then animates it into the invalid state. 

So if we want to move a component out of the form with an animation we can set its X position to the screen width. If we call animate layout we will get an effect of the
component sliding into the screen from right to left. If we invoke animate unlayout we get the effect of the component sliding out of the screen.

When we run animateLayout we do something that’s effectively the equivalent of revalidate() so the UI is valid once we finished. With animate unlayout the situation is the
exact opposite. The UI becomes invalid when we are done which means a typical animateUnlayout will be followed by an animate layout or revalidate. The purpose of
animateUnlayout is strictly as a visual effect unlike the its animateLayout counterpart
Variations
© Codename One 2017 all rights reserved
✦ There are several variations of both animate layout &
unlayout
✦ AndWait versions use invokeAndBlock, they are useful for
chaining effects e.g. unlayout and wait followed by layout
✦ Fade versions of the method also add a fade in or fade out
effect respectively
✦ Hierarchy animates a full hierarchy, this is a complicated
proposition and should normally be avoided
There are a few varieties and a bit of noise but layout animations generally fall into the two categories I mentioned

AndWait versions of the methods use invoke and block to help you serialize calls to layout and unlayout. This is useful when you want to create an elaborate effect with
one piece relying on the completion of the next piece

Fade versions of the layout methods can fade components in or out. For unlayout components are faded out and for layout they are faded in. This allows components to
materialize or dematerialize gracefully

The hierarchy related animate methods such as animateHierarchy are very problematic. They recurse into a hierarchy and try to layout all of the elements within but this is
tricky as you can run into a lot of edge cases such as a component that moves from outside the clipping bounds of its parent container.
© Codename One 2017 all rights reserved
In this video I activated slow motion mode which is very useful for debugging animations but for some reason the unlayout effect wasn’t slowed down so you can only
see the deletion briefly and then the animate layout that follows is slow. Lets go over the code that creates this animation
CheckoutForm
quantityButton.addActionListener(e -> {
String sel = quantityButton.getSelectedString();
if(sel == null) {
return;
}
if(sel.equals(PICKER_STRINGS[0])) {
Display.getInstance().callSerially(() -> {
dishContainer.setX(getDisplayWidth());
Container p = dishContainer.getParent();
p.animateUnlayoutAndWait(250, 255);
dishContainer.remove();
p.animateLayoutAndWait(200);
Restaurant.getInstance().cart.get().
dishQuantity.remove(di);
updatePrice();
});
} else {
This entire animation is done in 5 lines of code. Lets go over them one by one. First we set the deleted dish container to the display width which pushes it out of the
visible range with a setX call.
CheckoutForm
quantityButton.addActionListener(e -> {
String sel = quantityButton.getSelectedString();
if(sel == null) {
return;
}
if(sel.equals(PICKER_STRINGS[0])) {
Display.getInstance().callSerially(() -> {
dishContainer.setX(getDisplayWidth());
Container p = dishContainer.getParent();
p.animateUnlayoutAndWait(250, 255);
dishContainer.remove();
p.animateLayoutAndWait(200);
Restaurant.getInstance().cart.get().
dishQuantity.remove(di);
updatePrice();
});
} else {
We now perform animate unlayout and wait. We maintain full opacity which corresponds to the second argument. This animates the removal of the dish from the screen
by sliding it to the right.
CheckoutForm
quantityButton.addActionListener(e -> {
String sel = quantityButton.getSelectedString();
if(sel == null) {
return;
}
if(sel.equals(PICKER_STRINGS[0])) {
Display.getInstance().callSerially(() -> {
dishContainer.setX(getDisplayWidth());
Container p = dishContainer.getParent();
p.animateUnlayoutAndWait(250, 255);
dishContainer.remove();
p.animateLayoutAndWait(200);
Restaurant.getInstance().cart.get().
dishQuantity.remove(di);
updatePrice();
});
} else {
We next remove the component that we animated out. This is important as we are currently in an invalid state but the component is still in the hierarchy.
CheckoutForm
quantityButton.addActionListener(e -> {
String sel = quantityButton.getSelectedString();
if(sel == null) {
return;
}
if(sel.equals(PICKER_STRINGS[0])) {
Display.getInstance().callSerially(() -> {
dishContainer.setX(getDisplayWidth());
Container p = dishContainer.getParent();
p.animateUnlayoutAndWait(250, 255);
dishContainer.remove();
p.animateLayoutAndWait(200);
Restaurant.getInstance().cart.get().
dishQuantity.remove(di);
updatePrice();
});
} else {
Now we can animate the other element into their new place, since the dish was removed there is more available space and we can use it by shifting everything into the
new location

More Related Content

Similar to Animations - Part 2 - Transcript.pdf

Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsNaman Dwivedi
 
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...Shift Conference
 
Animations - Part 3.pdf
Animations - Part 3.pdfAnimations - Part 3.pdf
Animations - Part 3.pdfShaiAlmog1
 
AngularJS Animations
AngularJS AnimationsAngularJS Animations
AngularJS AnimationsEyal Vardi
 
What is the Hero Class in Flutter Development.pptx
What is the Hero Class in Flutter Development.pptxWhat is the Hero Class in Flutter Development.pptx
What is the Hero Class in Flutter Development.pptxBOSC Tech Labs
 
Motion graphics Terminology
Motion graphics TerminologyMotion graphics Terminology
Motion graphics TerminologyJoe Nasr
 
2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorialtutorialsruby
 
2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorialtutorialsruby
 
Programming-In-Alice.pptx
Programming-In-Alice.pptxProgramming-In-Alice.pptx
Programming-In-Alice.pptxCarlos134964
 
Procedure of animation in 3 d autodesk maya tools & techniques
Procedure of animation in 3 d autodesk maya tools & techniquesProcedure of animation in 3 d autodesk maya tools & techniques
Procedure of animation in 3 d autodesk maya tools & techniquesijcga
 
Unity3d scripting tutorial
Unity3d scripting tutorialUnity3d scripting tutorial
Unity3d scripting tutorialhungnttg
 
How to create ui using droid draw
How to create ui using droid drawHow to create ui using droid draw
How to create ui using droid drawinfo_zybotech
 
iOS Transition Animations The proper way to do it.pdf
iOS Transition Animations The proper way to do it.pdfiOS Transition Animations The proper way to do it.pdf
iOS Transition Animations The proper way to do it.pdfSatawareTechnologies4
 
UILayout plug-in for APEX
UILayout plug-in for APEXUILayout plug-in for APEX
UILayout plug-in for APEXTobias Arnhold
 
Creating an Uber Clone - Part XXIV - Transcript.pdf
Creating an Uber Clone - Part XXIV - Transcript.pdfCreating an Uber Clone - Part XXIV - Transcript.pdf
Creating an Uber Clone - Part XXIV - Transcript.pdfShaiAlmog1
 

Similar to Animations - Part 2 - Transcript.pdf (20)

Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
 
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
 
Animations - Part 3.pdf
Animations - Part 3.pdfAnimations - Part 3.pdf
Animations - Part 3.pdf
 
AngularJS Animations
AngularJS AnimationsAngularJS Animations
AngularJS Animations
 
What is the Hero Class in Flutter Development.pptx
What is the Hero Class in Flutter Development.pptxWhat is the Hero Class in Flutter Development.pptx
What is the Hero Class in Flutter Development.pptx
 
Motion graphics Terminology
Motion graphics TerminologyMotion graphics Terminology
Motion graphics Terminology
 
Unity 3d scripting tutorial
Unity 3d scripting tutorialUnity 3d scripting tutorial
Unity 3d scripting tutorial
 
2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial
 
2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial
 
004
004004
004
 
Programming-In-Alice.pptx
Programming-In-Alice.pptxProgramming-In-Alice.pptx
Programming-In-Alice.pptx
 
Procedure of animation in 3 d autodesk maya tools & techniques
Procedure of animation in 3 d autodesk maya tools & techniquesProcedure of animation in 3 d autodesk maya tools & techniques
Procedure of animation in 3 d autodesk maya tools & techniques
 
Unity3d scripting tutorial
Unity3d scripting tutorialUnity3d scripting tutorial
Unity3d scripting tutorial
 
Swift
SwiftSwift
Swift
 
How to create ui using droid draw
How to create ui using droid drawHow to create ui using droid draw
How to create ui using droid draw
 
iOS Transition Animations The proper way to do it.pdf
iOS Transition Animations The proper way to do it.pdfiOS Transition Animations The proper way to do it.pdf
iOS Transition Animations The proper way to do it.pdf
 
Custom components
Custom componentsCustom components
Custom components
 
Animation in iOS
Animation in iOSAnimation in iOS
Animation in iOS
 
UILayout plug-in for APEX
UILayout plug-in for APEXUILayout plug-in for APEX
UILayout plug-in for APEX
 
Creating an Uber Clone - Part XXIV - Transcript.pdf
Creating an Uber Clone - Part XXIV - Transcript.pdfCreating an Uber Clone - Part XXIV - Transcript.pdf
Creating an Uber Clone - Part XXIV - Transcript.pdf
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfShaiAlmog1
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 

Recently uploaded

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Animations - Part 2 - Transcript.pdf

  • 1. Animations - Part II Layout animations are some of the most important yet easy to use animations in Codename One. They make the application flow feel reactive and responsive.
  • 2. Layout Animation © Codename One 2017 all rights reserved ✦Layout animations rely on the behavior of Codename One which doesn’t implicitly “reflow” components ✦Instead of calling revalidate() we can call animateLayout(int) or equivalent to animate the components to their final correct place/size ✦This is useful for smooth UI’s where components should “flow” into place rather than jump into it At the core of layout animations is the concept of explicit reflow. In Codename One layouts determine the position of components. That means that if you add a new component it will be positioned by the layout, however there is a big caveat. If you add the component after the form was shown it won’t position itself unless you do something like rotate the device which implicitly lays out the component. You need to ask for layout explicitly. You can invoke revalidate to force layout, this is valuable for cases where you can add multiple components. In those cases the layout logic can happen only once and can be much simpler. Layout animation works by animating the validate effect. It takes the components from their previously invalid or incorrect positions and moves them into their real final position. Normally when you add a component you won’t set a size or position to it as those will be determined by the layout manager, but with layout animations this can be useful as you can position a component explicitly and then it will animate from that position. This allows you to create a flow in the UI so components “settle” into place, this serves to draw attention to changes in the UI in most cases
  • 3. Unlayout Animations © Codename One 2017 all rights reserved ✦ animateUnlayout() and equivalent methods do the opposite, they move an element to an “illegal” place from the valid position thru an animation ✦ This is useful if we want to remove a component, we can move it offscreen then call animateUnlayoutAndWait() to animate that process then remove the component ✦ It’s assumed that animateUnlayout will be followed by code to correct the UI after it completes Animate unlayout is the exact opposite or evil twin of the animate layout method. Animate layout takes layout in an invalid state and returns it to normal layout with an animation. Animate unlayout takes layout in an invalid state, returns it to normal instantly then animates it into the invalid state. So if we want to move a component out of the form with an animation we can set its X position to the screen width. If we call animate layout we will get an effect of the component sliding into the screen from right to left. If we invoke animate unlayout we get the effect of the component sliding out of the screen. When we run animateLayout we do something that’s effectively the equivalent of revalidate() so the UI is valid once we finished. With animate unlayout the situation is the exact opposite. The UI becomes invalid when we are done which means a typical animateUnlayout will be followed by an animate layout or revalidate. The purpose of animateUnlayout is strictly as a visual effect unlike the its animateLayout counterpart
  • 4. Variations © Codename One 2017 all rights reserved ✦ There are several variations of both animate layout & unlayout ✦ AndWait versions use invokeAndBlock, they are useful for chaining effects e.g. unlayout and wait followed by layout ✦ Fade versions of the method also add a fade in or fade out effect respectively ✦ Hierarchy animates a full hierarchy, this is a complicated proposition and should normally be avoided There are a few varieties and a bit of noise but layout animations generally fall into the two categories I mentioned AndWait versions of the methods use invoke and block to help you serialize calls to layout and unlayout. This is useful when you want to create an elaborate effect with one piece relying on the completion of the next piece Fade versions of the layout methods can fade components in or out. For unlayout components are faded out and for layout they are faded in. This allows components to materialize or dematerialize gracefully The hierarchy related animate methods such as animateHierarchy are very problematic. They recurse into a hierarchy and try to layout all of the elements within but this is tricky as you can run into a lot of edge cases such as a component that moves from outside the clipping bounds of its parent container.
  • 5. © Codename One 2017 all rights reserved In this video I activated slow motion mode which is very useful for debugging animations but for some reason the unlayout effect wasn’t slowed down so you can only see the deletion briefly and then the animate layout that follows is slow. Lets go over the code that creates this animation
  • 6. CheckoutForm quantityButton.addActionListener(e -> { String sel = quantityButton.getSelectedString(); if(sel == null) { return; } if(sel.equals(PICKER_STRINGS[0])) { Display.getInstance().callSerially(() -> { dishContainer.setX(getDisplayWidth()); Container p = dishContainer.getParent(); p.animateUnlayoutAndWait(250, 255); dishContainer.remove(); p.animateLayoutAndWait(200); Restaurant.getInstance().cart.get(). dishQuantity.remove(di); updatePrice(); }); } else { This entire animation is done in 5 lines of code. Lets go over them one by one. First we set the deleted dish container to the display width which pushes it out of the visible range with a setX call.
  • 7. CheckoutForm quantityButton.addActionListener(e -> { String sel = quantityButton.getSelectedString(); if(sel == null) { return; } if(sel.equals(PICKER_STRINGS[0])) { Display.getInstance().callSerially(() -> { dishContainer.setX(getDisplayWidth()); Container p = dishContainer.getParent(); p.animateUnlayoutAndWait(250, 255); dishContainer.remove(); p.animateLayoutAndWait(200); Restaurant.getInstance().cart.get(). dishQuantity.remove(di); updatePrice(); }); } else { We now perform animate unlayout and wait. We maintain full opacity which corresponds to the second argument. This animates the removal of the dish from the screen by sliding it to the right.
  • 8. CheckoutForm quantityButton.addActionListener(e -> { String sel = quantityButton.getSelectedString(); if(sel == null) { return; } if(sel.equals(PICKER_STRINGS[0])) { Display.getInstance().callSerially(() -> { dishContainer.setX(getDisplayWidth()); Container p = dishContainer.getParent(); p.animateUnlayoutAndWait(250, 255); dishContainer.remove(); p.animateLayoutAndWait(200); Restaurant.getInstance().cart.get(). dishQuantity.remove(di); updatePrice(); }); } else { We next remove the component that we animated out. This is important as we are currently in an invalid state but the component is still in the hierarchy.
  • 9. CheckoutForm quantityButton.addActionListener(e -> { String sel = quantityButton.getSelectedString(); if(sel == null) { return; } if(sel.equals(PICKER_STRINGS[0])) { Display.getInstance().callSerially(() -> { dishContainer.setX(getDisplayWidth()); Container p = dishContainer.getParent(); p.animateUnlayoutAndWait(250, 255); dishContainer.remove(); p.animateLayoutAndWait(200); Restaurant.getInstance().cart.get(). dishQuantity.remove(di); updatePrice(); }); } else { Now we can animate the other element into their new place, since the dish was removed there is more available space and we can use it by shifting everything into the new location