Created
February 23, 2016 19:27
-
-
Save codenameone/47602e679f61712693bd to your computer and use it in GitHub Desktop.
Sample code for using the most common transition types in Codename One
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Toolbar.setGlobalToolbar(true); | |
Form hi = new Form("Transitions", new BoxLayout(BoxLayout.Y_AXIS)); | |
Style bg = hi.getContentPane().getUnselectedStyle(); | |
bg.setBgTransparency(255); | |
bg.setBgColor(0xff0000); | |
Button showTransition = new Button("Show"); | |
Picker pick = new Picker(); | |
pick.setStrings("Slide", "SlideFade", "Cover", "Uncover", "Fade", "Flip"); | |
pick.setSelectedString("Slide"); | |
TextField duration = new TextField("10000", "Duration", 6, TextArea.NUMERIC); | |
CheckBox horizontal = CheckBox.createToggle("Horizontal"); | |
pick.addActionListener((e) -> { | |
String s = pick.getSelectedString().toLowerCase(); | |
horizontal.setEnabled(s.equals("slide") || s.indexOf("cover") > -1); | |
}); | |
horizontal.setSelected(true); | |
hi.add(showTransition). | |
add(pick). | |
add(duration). | |
add(horizontal); | |
Form dest = new Form("Destination"); | |
bg = dest.getContentPane().getUnselectedStyle(); | |
bg.setBgTransparency(255); | |
bg.setBgColor(0xff); | |
dest.setBackCommand( | |
dest.getToolbar().addCommandToLeftBar("Back", null, (e) -> hi.showBack())); | |
showTransition.addActionListener((e) -> { | |
int h = CommonTransitions.SLIDE_HORIZONTAL; | |
if(!horizontal.isSelected()) { | |
h = CommonTransitions.SLIDE_VERTICAL; | |
} | |
switch(pick.getSelectedString()) { | |
case "Slide": | |
hi.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000))); | |
dest.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000))); | |
break; | |
case "SlideFade": | |
hi.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000))); | |
dest.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000))); | |
break; | |
case "Cover": | |
hi.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000))); | |
dest.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000))); | |
break; | |
case "Uncover": | |
hi.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000))); | |
dest.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000))); | |
break; | |
case "Fade": | |
hi.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000))); | |
dest.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000))); | |
break; | |
case "Flip": | |
hi.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000))); | |
dest.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000))); | |
break; | |
} | |
dest.show(); | |
}); | |
hi.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage of CommonTransitions & FlipTransition.
From the Codename One project