|
1 | | -package gwt.material.design.client.ui.animate; |
| 1 | + package gwt.material.design.client.ui.animate; |
2 | 2 |
|
3 | 3 | /* |
4 | 4 | * #%L |
|
26 | 26 | import gwt.material.design.client.ui.html.ListItem; |
27 | 27 | import gwt.material.design.client.ui.html.UnorderedList; |
28 | 28 |
|
29 | | -/** |
30 | | - * Provides core and meaningful animation |
31 | | - * @author kevzlou7979 |
32 | | - */ |
33 | | -public class MaterialAnimator { |
34 | | - |
35 | | - public static void animate(final Transition transition, final Widget w, int delayMillis, Runnable callback) { |
36 | | - animate(transition, w, delayMillis, 800, callback); |
37 | | - } |
38 | | - |
39 | | - public static void animate(final Transition transition, final Widget w, int delayMillis, int durationMillis) { |
40 | | - animate(transition, w, delayMillis, durationMillis, null); |
41 | | - } |
42 | | - |
43 | | - public static void animate(final Transition transition, final Widget w, int delayMillis) { |
44 | | - animate(transition, w, delayMillis, 800, null); |
45 | | - } |
46 | | - |
47 | | - public static void animate(final Transition transition, final Widget w, int delayMillis, final int durationMillis, final Runnable callback) { |
48 | | - final String name = String.valueOf(DOM.createUniqueId()); |
49 | | - w.getElement().setId(name); |
50 | | - w.getElement().getStyle().setProperty("WebkitAnimationDuration",durationMillis+"ms"); |
51 | | - w.getElement().getStyle().setProperty("animationDuration",durationMillis+"ms"); |
52 | | - switch (transition) { |
53 | | - case SHOW_STAGGERED_LIST: |
54 | | - if(w instanceof UnorderedList) { |
55 | | - UnorderedList ul = (UnorderedList) w; |
56 | | - |
57 | | - for(Widget li : ul) { |
58 | | - if(li instanceof ListItem) { |
59 | | - li.getElement().getStyle().setOpacity(0); |
60 | | - } |
61 | | - } |
62 | | - } |
63 | | - break; |
64 | | - case SHOW_GRID: |
65 | | - w.getElement().getStyle().setOpacity(0); |
66 | | - break; |
67 | | - default: |
68 | | - break; |
69 | | - } |
70 | | - |
71 | | - new Timer() { |
72 | | - @Override |
73 | | - public void run() { |
74 | | - switch (transition) { |
75 | | - case SHOW_STAGGERED_LIST: |
76 | | - showStaggeredList(name); |
77 | | - break; |
78 | | - case FADE_IN_IMAGE: |
79 | | - fadeInImage(name); |
80 | | - break; |
81 | | - case SHOW_GRID: |
82 | | - w.addStyleName("display-animation"); |
83 | | - showGrid(name); |
84 | | - break; |
85 | | - case CLOSE_GRID: |
86 | | - w.addStyleName("display-animation"); |
87 | | - closeGrid(name); |
88 | | - break; |
89 | | - default: |
90 | | - // For core animation components |
91 | | - w.addStyleName("animated " + transition.getCssName()); |
92 | | - animationFinishedCallback(name, "animated " + transition.getCssName(), durationMillis, callback); |
93 | | - break; |
94 | | - } |
95 | | - } |
96 | | - }.schedule(delayMillis); |
97 | | - |
98 | | - w.removeStyleName("materialcss"); |
99 | | - } |
100 | | - |
101 | | - protected static native void animationFinishedCallback(String name, String oldClass, int durationMillis, Runnable callback) /*-{ |
102 | | - //$wnd.jQuery('#' + name).css("animationDuration", + durationMillis + "ms"); |
103 | | - $wnd.jQuery('#' + name).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() { |
104 | | - if(callback != null) { |
105 | | - |
106 | | - } |
107 | | - $wnd.jQuery('#' + name).removeClass(oldClass); |
108 | | - }); |
109 | | - }-*/; |
110 | | - |
111 | | - protected static native void closeGrid(String name) /*-{ |
112 | | - $wnd.closeGrid('#' + name); |
113 | | - }-*/; |
114 | | - |
115 | | - protected static native void showGrid(String name) /*-{ |
116 | | - $wnd.showGrid('#' + name); |
117 | | - }-*/; |
118 | | - |
119 | | - protected static native void fadeInImage(String name) /*-{ |
120 | | - $wnd.Materialize.fadeInImage('#' + name); |
121 | | - }-*/; |
122 | | - |
123 | | - protected static native void showStaggeredList(String name) /*-{ |
124 | | - $wnd.Materialize.showStaggeredList('#' + name); |
125 | | - }-*/; |
126 | | -} |
| 29 | + /** |
| 30 | + * Provides core and meaningful animation |
| 31 | + * @author kevzlou7979 |
| 32 | + */ |
| 33 | + public class MaterialAnimator { |
| 34 | + |
| 35 | + public static void animate(final Transition transition, final Widget w, int delayMillis, Runnable callback) { |
| 36 | + animate(transition, w, delayMillis, 800, callback, false); |
| 37 | + } |
| 38 | + |
| 39 | + public static void animate(final Transition transition, final Widget w, int delayMillis, int durationMillis) { |
| 40 | + animate(transition, w, delayMillis, durationMillis, null, false); |
| 41 | + } |
| 42 | + |
| 43 | + public static void animate(final Transition transition, final Widget w, int delayMillis, boolean infinite) { |
| 44 | + animate(transition, w, delayMillis, 800, null, infinite); |
| 45 | + } |
| 46 | + |
| 47 | + public static void animate(final Transition transition, final Widget w, int delayMillis) { |
| 48 | + animate(transition, w, delayMillis, 800, null, false); |
| 49 | + } |
| 50 | + |
| 51 | + public static void stopAnimation(Widget w) { |
| 52 | + w.removeStyleName("infinite"); |
| 53 | + } |
| 54 | + |
| 55 | + public static void animate(final Transition transition, final Widget w, int delayMillis, final int durationMillis, final Runnable callback, final boolean infinite) { |
| 56 | + final String name = String.valueOf(DOM.createUniqueId()); |
| 57 | + w.getElement().setId(name); |
| 58 | + w.getElement().getStyle().setProperty("WebkitAnimationDuration",durationMillis+"ms"); |
| 59 | + w.getElement().getStyle().setProperty("animationDuration",durationMillis+"ms"); |
| 60 | + switch (transition) { |
| 61 | + case SHOW_STAGGERED_LIST: |
| 62 | + if(w instanceof UnorderedList) { |
| 63 | + UnorderedList ul = (UnorderedList) w; |
| 64 | + |
| 65 | + for(Widget li : ul) { |
| 66 | + if(li instanceof ListItem) { |
| 67 | + li.getElement().getStyle().setOpacity(0); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + break; |
| 72 | + case SHOW_GRID: |
| 73 | + w.getElement().getStyle().setOpacity(0); |
| 74 | + break; |
| 75 | + default: |
| 76 | + break; |
| 77 | + } |
| 78 | + |
| 79 | + new Timer() { |
| 80 | + @Override |
| 81 | + public void run() { |
| 82 | + switch (transition) { |
| 83 | + case SHOW_STAGGERED_LIST: |
| 84 | + showStaggeredList(name); |
| 85 | + break; |
| 86 | + case FADE_IN_IMAGE: |
| 87 | + fadeInImage(name); |
| 88 | + break; |
| 89 | + case SHOW_GRID: |
| 90 | + w.addStyleName("display-animation"); |
| 91 | + showGrid(name); |
| 92 | + break; |
| 93 | + case CLOSE_GRID: |
| 94 | + w.addStyleName("display-animation"); |
| 95 | + closeGrid(name); |
| 96 | + break; |
| 97 | + default: |
| 98 | + // For core animation components |
| 99 | + if(infinite) { |
| 100 | + w.addStyleName("infinite"); |
| 101 | + } |
| 102 | + w.addStyleName("animated " + transition.getCssName()); |
| 103 | + animationFinishedCallback(name, "animated " + transition.getCssName(), durationMillis, callback); |
| 104 | + break; |
| 105 | + } |
| 106 | + } |
| 107 | + }.schedule(delayMillis); |
| 108 | + |
| 109 | + w.removeStyleName("materialcss"); |
| 110 | + } |
| 111 | + |
| 112 | + protected static native void animationFinishedCallback(String name, String oldClass, int durationMillis, Runnable callback) /*-{ |
| 113 | + //$wnd.jQuery('#' + name).css("animationDuration", + durationMillis + "ms"); |
| 114 | + $wnd.jQuery('#' + name).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() { |
| 115 | + if(callback != null) { |
| 116 | + |
| 117 | + } |
| 118 | + $wnd.jQuery('#' + name).removeClass(oldClass); |
| 119 | + }); |
| 120 | + }-*/; |
| 121 | + |
| 122 | + protected static native void closeGrid(String name) /*-{ |
| 123 | + $wnd.closeGrid('#' + name); |
| 124 | + }-*/; |
| 125 | + |
| 126 | + protected static native void showGrid(String name) /*-{ |
| 127 | + $wnd.showGrid('#' + name); |
| 128 | + }-*/; |
| 129 | + |
| 130 | + protected static native void fadeInImage(String name) /*-{ |
| 131 | + $wnd.Materialize.fadeInImage('#' + name); |
| 132 | + }-*/; |
| 133 | + |
| 134 | + protected static native void showStaggeredList(String name) /*-{ |
| 135 | + $wnd.Materialize.showStaggeredList('#' + name); |
| 136 | + }-*/; |
| 137 | + } |
0 commit comments