File tree 2 files changed +26
-4
lines changed
library/scene/src/main/java/com/bytedance/scene
2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change 23
23
import android .animation .ValueAnimator ;
24
24
import android .app .Activity ;
25
25
import android .content .res .Resources ;
26
+ import android .provider .Settings ;
26
27
import android .view .View ;
27
28
import android .view .animation .Animation ;
28
29
import android .view .animation .AnimationSet ;
35
36
import androidx .annotation .RestrictTo ;
36
37
37
38
import com .bytedance .scene .utlity .AnimationUtilityKt ;
39
+ import com .bytedance .scene .utlity .DurationScaleType ;
38
40
39
41
import java .util .List ;
40
42
@@ -184,9 +186,18 @@ private void reverse(Animation animation) {
184
186
}
185
187
}
186
188
189
+ /**
190
+ * Scene follow [Settings.Global.ANIMATOR_DURATION_SCALE] as default but Activity follow [Settings.Global.TRANSITION_ANIMATION_SCALE]
191
+ *
192
+ * @param view
193
+ */
187
194
public void applySystemDurationScale (View view ) {
195
+ this .applySystemDurationScale (view , Settings .Global .ANIMATOR_DURATION_SCALE );
196
+ }
197
+
198
+ public void applySystemDurationScale (View view , @ DurationScaleType String durationScaleType ) {
188
199
if (this .animation != null ) {
189
- float durationScale = AnimationUtilityKt .getDurationScale (view );
200
+ float durationScale = AnimationUtilityKt .getDurationScale (view , durationScaleType );
190
201
this .animation .setDuration ((long ) (this .animation .getDuration () * durationScale ));
191
202
}
192
203
}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package com.bytedance.scene.utlity
2
2
3
3
import android.provider.Settings
4
4
import android.view.View
5
+ import androidx.annotation.StringDef
5
6
import kotlin.math.max
6
7
7
8
/* *
@@ -10,12 +11,22 @@ import kotlin.math.max
10
11
*/
11
12
/* *
12
13
* if system > Build.VERSION_CODES.TIRAMISU, can use ValueAnimator.getDurationScale() instead
13
- *
14
- * Scene follow [Settings.Global.ANIMATOR_DURATION_SCALE] but Activity follow [Settings.Global.TRANSITION_ANIMATION_SCALE]
15
14
*/
16
15
internal fun getDurationScale (view : View ): Float {
16
+ return getDurationScale(view, Settings .Global .ANIMATOR_DURATION_SCALE )
17
+ }
18
+
19
+ @StringDef(
20
+ value = [Settings .Global .ANIMATOR_DURATION_SCALE , Settings .Global .TRANSITION_ANIMATION_SCALE , Settings .Global .WINDOW_ANIMATION_SCALE ]
21
+ )
22
+ @Retention(
23
+ AnnotationRetention .SOURCE
24
+ )
25
+ annotation class DurationScaleType
26
+
27
+ internal fun getDurationScale (view : View , @DurationScaleType durationScaleType : String ): Float {
17
28
val durationScale = Settings .Global .getFloat(
18
- view.context.contentResolver, Settings . Global . ANIMATOR_DURATION_SCALE , 1.0f
29
+ view.context.contentResolver, durationScaleType , 1.0f
19
30
)
20
31
return max(0.0f , durationScale)
21
32
}
You can’t perform that action at this time.
0 commit comments