16
16
17
17
package com .android .launcher3 ;
18
18
19
- import static android .view .View .VISIBLE ;
20
- import static com .android .launcher3 .LauncherState .NORMAL ;
21
- import static com .android .launcher3 .anim .AnimatorSetBuilder .ANIM_OVERVIEW_FADE ;
22
- import static com .android .launcher3 .anim .AnimatorSetBuilder .ANIM_OVERVIEW_SCALE ;
23
- import static com .android .launcher3 .anim .AnimatorSetBuilder .ANIM_WORKSPACE_FADE ;
24
- import static com .android .launcher3 .anim .AnimatorSetBuilder .ANIM_WORKSPACE_SCALE ;
25
- import static com .android .launcher3 .anim .Interpolators .ACCEL ;
26
- import static com .android .launcher3 .anim .Interpolators .DEACCEL ;
27
- import static com .android .launcher3 .anim .Interpolators .DEACCEL_1_7 ;
28
- import static com .android .launcher3 .anim .Interpolators .OVERSHOOT_1_2 ;
29
- import static com .android .launcher3 .anim .Interpolators .clampToProgress ;
30
- import static com .android .launcher3 .anim .PropertySetter .NO_ANIM_PROPERTY_SETTER ;
31
-
32
19
import android .animation .Animator ;
33
20
import android .animation .AnimatorListenerAdapter ;
34
21
import android .animation .AnimatorSet ;
42
29
import com .android .launcher3 .anim .PropertySetter ;
43
30
import com .android .launcher3 .anim .PropertySetter .AnimatedPropertySetter ;
44
31
import com .android .launcher3 .uioverrides .UiFactory ;
32
+ import com .android .mxlibrary .util .XLog ;
45
33
46
34
import java .lang .annotation .Retention ;
47
35
import java .lang .annotation .RetentionPolicy ;
48
36
import java .util .ArrayList ;
49
37
38
+ import static android .view .View .VISIBLE ;
39
+ import static com .android .launcher3 .LauncherState .NORMAL ;
40
+ import static com .android .launcher3 .anim .AnimatorSetBuilder .ANIM_OVERVIEW_FADE ;
41
+ import static com .android .launcher3 .anim .AnimatorSetBuilder .ANIM_OVERVIEW_SCALE ;
42
+ import static com .android .launcher3 .anim .AnimatorSetBuilder .ANIM_WORKSPACE_FADE ;
43
+ import static com .android .launcher3 .anim .AnimatorSetBuilder .ANIM_WORKSPACE_SCALE ;
44
+ import static com .android .launcher3 .anim .Interpolators .ACCEL ;
45
+ import static com .android .launcher3 .anim .Interpolators .DEACCEL ;
46
+ import static com .android .launcher3 .anim .Interpolators .DEACCEL_1_7 ;
47
+ import static com .android .launcher3 .anim .Interpolators .OVERSHOOT_1_2 ;
48
+ import static com .android .launcher3 .anim .Interpolators .clampToProgress ;
49
+ import static com .android .launcher3 .anim .PropertySetter .NO_ANIM_PROPERTY_SETTER ;
50
+
50
51
/**
51
52
* TODO: figure out what kind of tests we can write for this
52
- *
53
+ * <p>
53
54
* Things to test when changing the following class.
54
- * - Home from workspace
55
- * - from center screen
56
- * - from other screens
57
- * - Home from all apps
58
- * - from center screen
59
- * - from other screens
60
- * - Back from all apps
61
- * - from center screen
62
- * - from other screens
63
- * - Launch app from workspace and quit
64
- * - with back
65
- * - with home
66
- * - Launch app from all apps and quit
67
- * - with back
68
- * - with home
69
- * - Go to a screen that's not the default, then all
70
- * apps, and launch and app, and go back
71
- * - with back
72
- * -with home
73
- * - On workspace, long press power and go back
74
- * - with back
75
- * - with home
76
- * - On all apps, long press power and go back
77
- * - with back
78
- * - with home
79
- * - On workspace, power off
80
- * - On all apps, power off
81
- * - Launch an app and turn off the screen while in that app
82
- * - Go back with home key
83
- * - Go back with back key TODO: make this not go to workspace
84
- * - From all apps
85
- * - From workspace
86
- * - Enter and exit car mode (becase it causes an extra configuration changed)
87
- * - From all apps
88
- * - From the center workspace
89
- * - From another workspace
55
+ * - Home from workspace
56
+ * - from center screen
57
+ * - from other screens
58
+ * - Home from all apps
59
+ * - from center screen
60
+ * - from other screens
61
+ * - Back from all apps
62
+ * - from center screen
63
+ * - from other screens
64
+ * - Launch app from workspace and quit
65
+ * - with back
66
+ * - with home
67
+ * - Launch app from all apps and quit
68
+ * - with back
69
+ * - with home
70
+ * - Go to a screen that's not the default, then all
71
+ * apps, and launch and app, and go back
72
+ * - with back
73
+ * -with home
74
+ * - On workspace, long press power and go back
75
+ * - with back
76
+ * - with home
77
+ * - On all apps, long press power and go back
78
+ * - with back
79
+ * - with home
80
+ * - On workspace, power off
81
+ * - On all apps, power off
82
+ * - Launch an app and turn off the screen while in that app
83
+ * - Go back with home key
84
+ * - Go back with back key TODO: make this not go to workspace
85
+ * - From all apps
86
+ * - From workspace
87
+ * - Enter and exit car mode (becase it causes an extra configuration changed)
88
+ * - From all apps
89
+ * - From the center workspace
90
+ * - From another workspace
90
91
*/
91
92
public class LauncherStateManager {
92
93
@@ -101,7 +102,9 @@ public class LauncherStateManager {
101
102
ATOMIC_COMPONENT
102
103
})
103
104
@ Retention (RetentionPolicy .SOURCE )
104
- public @interface AnimationComponents {}
105
+ public @interface AnimationComponents {
106
+ }
107
+
105
108
public static final int NON_ATOMIC_COMPONENT = 1 << 0 ;
106
109
public static final int ATOMIC_COMPONENT = 1 << 1 ;
107
110
@@ -113,10 +116,10 @@ public class LauncherStateManager {
113
116
private final ArrayList <StateListener > mListeners = new ArrayList <>();
114
117
115
118
private StateHandler [] mStateHandlers ;
116
- private LauncherState mState = NORMAL ;
119
+ private LauncherState mState = LauncherState . NORMAL ;
117
120
118
- private LauncherState mLastStableState = NORMAL ;
119
- private LauncherState mCurrentStableState = NORMAL ;
121
+ private LauncherState mLastStableState = LauncherState . NORMAL ;
122
+ private LauncherState mCurrentStableState = LauncherState . NORMAL ;
120
123
121
124
private LauncherState mRestState ;
122
125
@@ -162,8 +165,7 @@ public void goToState(LauncherState state, boolean animated) {
162
165
* Changes the Launcher state to the provided state.
163
166
*
164
167
* @param animated false if the state should change immediately without any animation,
165
- * true otherwise
166
- * @paras onCompleteRunnable any action to perform at the end of the transition, of null.
168
+ * true otherwise
167
169
*/
168
170
public void goToState (LauncherState state , boolean animated , Runnable onCompleteRunnable ) {
169
171
goToState (state , animated , 0 , onCompleteRunnable );
@@ -198,8 +200,17 @@ public void reapplyState(boolean cancelCurrentAnimation) {
198
200
}
199
201
}
200
202
203
+ /**
204
+ * 切换状态动画控制
205
+ *
206
+ * @param state 目标状态
207
+ * @param animated 是否显示动画(长按拖拽进入拖拽模式为true)
208
+ * @param delay 延迟时间
209
+ * @param onCompleteRunnable 状态完成回调
210
+ */
201
211
private void goToState (LauncherState state , boolean animated , long delay ,
202
- final Runnable onCompleteRunnable ) {
212
+ final Runnable onCompleteRunnable ) {
213
+ XLog .e (XLog .getTag (),XLog .TAG_GU_STATE +" state.containerType= " + state .containerType + " , animated= " + animated + " , delay= " + delay );
203
214
if (mLauncher .isInState (state )) {
204
215
if (mConfig .mCurrentAnimation == null ) {
205
216
// Run any queued runnable
@@ -265,7 +276,7 @@ public void onAnimationSuccess(Animator animator) {
265
276
* - MxSettings some start values (e.g. scale) for views that are hidden but about to be shown.
266
277
*/
267
278
public void prepareForAtomicAnimation (LauncherState fromState , LauncherState toState ,
268
- AnimatorSetBuilder builder ) {
279
+ AnimatorSetBuilder builder ) {
269
280
if (fromState == NORMAL && toState .overviewUi ) {
270
281
builder .setInterpolator (ANIM_WORKSPACE_SCALE , OVERSHOOT_1_2 );
271
282
builder .setInterpolator (ANIM_WORKSPACE_FADE , OVERSHOOT_1_2 );
@@ -299,9 +310,10 @@ public void prepareForAtomicAnimation(LauncherState fromState, LauncherState toS
299
310
/**
300
311
* Creates a {@link AnimatorPlaybackController} that can be used for a controlled
301
312
* state transition.
302
- * @param state the final state for the transition.
313
+ *
314
+ * @param state the final state for the transition.
303
315
* @param duration intended duration for normal playback. Use higher duration for better
304
- * accuracy.
316
+ * accuracy.
305
317
*/
306
318
public AnimatorPlaybackController createAnimationToNewWorkspace (
307
319
LauncherState state , long duration ) {
@@ -315,8 +327,8 @@ public AnimatorPlaybackController createAnimationToNewWorkspace(
315
327
}
316
328
317
329
public AnimatorPlaybackController createAnimationToNewWorkspace (LauncherState state ,
318
- AnimatorSetBuilder builder , long duration , Runnable onCancelRunnable ,
319
- @ AnimationComponents int animComponents ) {
330
+ AnimatorSetBuilder builder , long duration , Runnable onCancelRunnable ,
331
+ @ AnimationComponents int animComponents ) {
320
332
mConfig .reset ();
321
333
mConfig .userControlled = true ;
322
334
mConfig .animComponents = animComponents ;
@@ -328,7 +340,7 @@ public AnimatorPlaybackController createAnimationToNewWorkspace(LauncherState st
328
340
}
329
341
330
342
protected AnimatorSet createAnimationToNewWorkspaceInternal (final LauncherState state ,
331
- AnimatorSetBuilder builder , final Runnable onCompleteRunnable ) {
343
+ AnimatorSetBuilder builder , final Runnable onCompleteRunnable ) {
332
344
333
345
for (StateHandler handler : getStateHandlers ()) {
334
346
builder .startTag (handler );
@@ -500,7 +512,8 @@ public static class AnimationConfig extends AnimatorListenerAdapter {
500
512
public long duration ;
501
513
public boolean userControlled ;
502
514
public AnimatorPlaybackController playbackController ;
503
- public @ AnimationComponents int animComponents = ANIM_ALL ;
515
+ public @ AnimationComponents
516
+ int animComponents = ANIM_ALL ;
504
517
private PropertySetter mPropertySetter ;
505
518
506
519
private AnimatorSet mCurrentAnimation ;
@@ -569,7 +582,7 @@ public interface StateHandler {
569
582
* Sets the UI to {@param state} by animating any changes.
570
583
*/
571
584
void setStateWithAnimation (LauncherState toState ,
572
- AnimatorSetBuilder builder , AnimationConfig config );
585
+ AnimatorSetBuilder builder , AnimationConfig config );
573
586
}
574
587
575
588
public interface StateListener {
@@ -580,6 +593,7 @@ public interface StateListener {
580
593
void onStateSetImmediately (LauncherState state );
581
594
582
595
void onStateTransitionStart (LauncherState toState );
596
+
583
597
void onStateTransitionComplete (LauncherState finalState );
584
598
}
585
599
}
0 commit comments