-
Notifications
You must be signed in to change notification settings - Fork 78
/
ScaledTransitionHandler.java
51 lines (44 loc) · 1.83 KB
/
ScaledTransitionHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.kaichunlin.transition;
import android.view.View;
import com.kaichunlin.transition.internal.TransitionController;
/**
* The progress valued passed to @link {@link #onUpdateScaledProgress(TransitionController, View, float)} has taken the start and
* end range into consideration. The method will only be called when the progress is within range, and the value passed has been
* scaled to always be [0..1].
* <p>
* Created by Kai on 2015/8/6.
*/
public abstract class ScaledTransitionHandler implements TransitionHandler {
private final boolean updateOnceOutsideRange;
private boolean updateMinProgress = true;
private boolean updateMaxProgress = true;
public ScaledTransitionHandler() {
this(false);
}
public ScaledTransitionHandler(boolean updateOnceOutsideRange) {
this.updateOnceOutsideRange = updateOnceOutsideRange;
}
@Override
public final void onUpdateProgress(TransitionController controller, View target, float progress) {
final float start = controller.getStart();
final float end = controller.getEnd();
if (progress < start) {
if (updateOnceOutsideRange && updateMinProgress) {
onUpdateScaledProgress(controller, target, 0);
}
updateMinProgress = false;
return;
}
updateMinProgress = true;
if (progress > end) {
if (updateOnceOutsideRange && updateMaxProgress) {
onUpdateScaledProgress(controller, target, 1);
}
updateMaxProgress = false;
return;
}
updateMaxProgress = true;
onUpdateScaledProgress(controller, target, (progress - start) / (end - start));
}
protected abstract void onUpdateScaledProgress(TransitionController controller, View target, float modifiedProgress);
}