|
1 | | -/* |
2 | | - * Copyright 2021-2022 MicroEJ Corp. All rights reserved. |
3 | | - * Use of this source code is governed by a BSD-style license that can be found with this software. |
4 | | - */ |
5 | | -package com.microej.demo.widget.circulardottedprogress; |
6 | | - |
7 | | -import com.microej.demo.widget.circulardottedprogress.widget.CircularDottedProgress; |
8 | | -import com.microej.demo.widget.common.Page; |
9 | | - |
10 | | -import ej.microui.display.Colors; |
11 | | -import ej.motion.Motion; |
12 | | -import ej.motion.circ.CircEaseInOutFunction; |
13 | | -import ej.mwt.Widget; |
14 | | -import ej.mwt.animation.Animation; |
15 | | -import ej.mwt.style.EditableStyle; |
16 | | -import ej.mwt.style.dimension.OptimalDimension; |
17 | | -import ej.mwt.stylesheet.cascading.CascadingStylesheet; |
18 | | -import ej.mwt.stylesheet.selector.TypeSelector; |
19 | | -import ej.mwt.util.Alignment; |
20 | | -import ej.widget.container.LayoutOrientation; |
21 | | -import ej.widget.container.SimpleDock; |
22 | | - |
23 | | -/** |
24 | | - * Circular Dotted Progress page. |
25 | | - */ |
26 | | -public class CircularDottedProgressPage implements Page { |
27 | | - |
28 | | - private static final int BAR_COLOR = 0xEE502E; |
29 | | - private static final int CIRCULAR_SIZE = 100; |
30 | | - private static final int DOT_SIZE = 5; |
31 | | - private static final int START_ANGLE = 270; |
32 | | - private static final int PROGRESS_MAX = 360; |
33 | | - |
34 | | - @Override |
35 | | - public String getName() { |
36 | | - return "Circular Dotted Progress"; //$NON-NLS-1$ |
37 | | - } |
38 | | - |
39 | | - @Override |
40 | | - public void populateStylesheet(CascadingStylesheet stylesheet) { |
41 | | - |
42 | | - EditableStyle style = stylesheet.getSelectorStyle(new TypeSelector(CircularDottedProgress.class)); |
43 | | - style.setColor(BAR_COLOR); |
44 | | - style.setExtraInt(CircularDottedProgress.BACKGROUND_COLOR, Colors.BLACK); |
45 | | - style.setExtraInt(CircularDottedProgress.PROGRESS_DIAMETER, CIRCULAR_SIZE); |
46 | | - style.setExtraInt(CircularDottedProgress.DOT_SIZE, DOT_SIZE); |
47 | | - style.setDimension(OptimalDimension.OPTIMAL_DIMENSION_XY); |
48 | | - style.setHorizontalAlignment(Alignment.HCENTER); |
49 | | - style.setVerticalAlignment(Alignment.VCENTER); |
50 | | - |
51 | | - } |
52 | | - |
53 | | - @Override |
54 | | - public Widget getContentWidget() { |
55 | | - SimpleDock dottedDock = new SimpleDock(LayoutOrientation.VERTICAL); |
56 | | - |
57 | | - // circular dotted progress bar, progress clockwise |
58 | | - AnimatedCircularDottedProgress dottedProgress = new AnimatedCircularDottedProgress(START_ANGLE, true); |
59 | | - |
60 | | - dottedDock.setCenterChild(dottedProgress); |
61 | | - |
62 | | - return dottedDock; |
63 | | - } |
64 | | - |
65 | | - private static class AnimatedCircularDottedProgress extends CircularDottedProgress implements Animation { |
66 | | - |
67 | | - private static final int ANIMATION_DURATION = 5_000; |
68 | | - |
69 | | - private final Motion progressMotion; |
70 | | - private long startTime; |
71 | | - |
72 | | - AnimatedCircularDottedProgress(float startAngle, boolean clockwise) { |
73 | | - super(startAngle, clockwise); |
74 | | - this.progressMotion = new Motion(CircEaseInOutFunction.INSTANCE, 0, PROGRESS_MAX, ANIMATION_DURATION); |
75 | | - } |
76 | | - |
77 | | - @Override |
78 | | - protected void onShown() { |
79 | | - this.startTime = System.currentTimeMillis(); |
80 | | - getDesktop().getAnimator().startAnimation(this); |
81 | | - } |
82 | | - |
83 | | - @Override |
84 | | - protected void onHidden() { |
85 | | - getDesktop().getAnimator().stopAnimation(this); |
86 | | - } |
87 | | - |
88 | | - @Override |
89 | | - public boolean tick(long currentTimeMillis) { |
90 | | - long elapsedTime = currentTimeMillis - this.startTime; |
91 | | - float angle = this.progressMotion.getValue(elapsedTime); |
92 | | - setProgress(angle); |
93 | | - |
94 | | - requestRender(); |
95 | | - return elapsedTime < ANIMATION_DURATION; |
96 | | - } |
97 | | - } |
98 | | - |
99 | | -} |
| 1 | +/* |
| 2 | + * Copyright 2021-2022 MicroEJ Corp. All rights reserved. |
| 3 | + * Use of this source code is governed by a BSD-style license that can be found with this software. |
| 4 | + */ |
| 5 | +package com.microej.demo.widget.circulardottedprogress; |
| 6 | + |
| 7 | +import com.microej.demo.widget.circulardottedprogress.widget.CircularDottedProgress; |
| 8 | +import com.microej.demo.widget.common.Page; |
| 9 | + |
| 10 | +import ej.bon.Util; |
| 11 | +import ej.microui.display.Colors; |
| 12 | +import ej.motion.Motion; |
| 13 | +import ej.motion.circ.CircEaseInOutFunction; |
| 14 | +import ej.mwt.Widget; |
| 15 | +import ej.mwt.animation.Animation; |
| 16 | +import ej.mwt.style.EditableStyle; |
| 17 | +import ej.mwt.style.dimension.OptimalDimension; |
| 18 | +import ej.mwt.stylesheet.cascading.CascadingStylesheet; |
| 19 | +import ej.mwt.stylesheet.selector.TypeSelector; |
| 20 | +import ej.mwt.util.Alignment; |
| 21 | +import ej.widget.container.LayoutOrientation; |
| 22 | +import ej.widget.container.SimpleDock; |
| 23 | + |
| 24 | +/** |
| 25 | + * Page showing a circular dotted progress. |
| 26 | + */ |
| 27 | +public class CircularDottedProgressPage implements Page { |
| 28 | + |
| 29 | + private static final int BAR_COLOR = 0xEE502E; |
| 30 | + private static final int CIRCULAR_SIZE = 100; |
| 31 | + private static final int DOT_SIZE = 5; |
| 32 | + private static final int START_ANGLE = 270; |
| 33 | + private static final int PROGRESS_MAX = 360; |
| 34 | + |
| 35 | + @Override |
| 36 | + public String getName() { |
| 37 | + return "Circular Dotted Progress"; //$NON-NLS-1$ |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public void populateStylesheet(CascadingStylesheet stylesheet) { |
| 42 | + |
| 43 | + EditableStyle style = stylesheet.getSelectorStyle(new TypeSelector(CircularDottedProgress.class)); |
| 44 | + style.setColor(BAR_COLOR); |
| 45 | + style.setExtraInt(CircularDottedProgress.BACKGROUND_COLOR, Colors.BLACK); |
| 46 | + style.setExtraInt(CircularDottedProgress.PROGRESS_DIAMETER, CIRCULAR_SIZE); |
| 47 | + style.setExtraInt(CircularDottedProgress.DOT_SIZE, DOT_SIZE); |
| 48 | + style.setDimension(OptimalDimension.OPTIMAL_DIMENSION_XY); |
| 49 | + style.setHorizontalAlignment(Alignment.HCENTER); |
| 50 | + style.setVerticalAlignment(Alignment.VCENTER); |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public Widget getContentWidget() { |
| 56 | + SimpleDock dottedDock = new SimpleDock(LayoutOrientation.VERTICAL); |
| 57 | + |
| 58 | + // circular dotted progress bar, progress clockwise |
| 59 | + AnimatedCircularDottedProgress dottedProgress = new AnimatedCircularDottedProgress(START_ANGLE, true); |
| 60 | + |
| 61 | + dottedDock.setCenterChild(dottedProgress); |
| 62 | + |
| 63 | + return dottedDock; |
| 64 | + } |
| 65 | + |
| 66 | + private static class AnimatedCircularDottedProgress extends CircularDottedProgress implements Animation { |
| 67 | + |
| 68 | + private static final int ANIMATION_DURATION = 5_000; |
| 69 | + |
| 70 | + private final Motion progressMotion; |
| 71 | + private long startTime; |
| 72 | + |
| 73 | + AnimatedCircularDottedProgress(float startAngle, boolean clockwise) { |
| 74 | + super(startAngle, clockwise); |
| 75 | + this.progressMotion = new Motion(CircEaseInOutFunction.INSTANCE, 0, PROGRESS_MAX, ANIMATION_DURATION); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + protected void onShown() { |
| 80 | + this.startTime = Util.platformTimeMillis(); |
| 81 | + getDesktop().getAnimator().startAnimation(this); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + protected void onHidden() { |
| 86 | + getDesktop().getAnimator().stopAnimation(this); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public boolean tick(long platformTimeMillis) { |
| 91 | + long elapsedTime = platformTimeMillis - this.startTime; |
| 92 | + float angle = this.progressMotion.getValue(elapsedTime); |
| 93 | + setProgress(angle); |
| 94 | + |
| 95 | + requestRender(); |
| 96 | + return elapsedTime < ANIMATION_DURATION; |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | +} |
0 commit comments