Skip to content

Commit 1f9d8d4

Browse files
committed
refactor: getDurationScale add DurationScaleType parameter
1 parent b0a9e25 commit 1f9d8d4

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

library/scene/src/main/java/com/bytedance/scene/animation/AnimationOrAnimator.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.animation.ValueAnimator;
2424
import android.app.Activity;
2525
import android.content.res.Resources;
26+
import android.provider.Settings;
2627
import android.view.View;
2728
import android.view.animation.Animation;
2829
import android.view.animation.AnimationSet;
@@ -35,6 +36,7 @@
3536
import androidx.annotation.RestrictTo;
3637

3738
import com.bytedance.scene.utlity.AnimationUtilityKt;
39+
import com.bytedance.scene.utlity.DurationScaleType;
3840

3941
import java.util.List;
4042

@@ -184,9 +186,18 @@ private void reverse(Animation animation) {
184186
}
185187
}
186188

189+
/**
190+
* Scene follow [Settings.Global.ANIMATOR_DURATION_SCALE] as default but Activity follow [Settings.Global.TRANSITION_ANIMATION_SCALE]
191+
*
192+
* @param view
193+
*/
187194
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) {
188199
if (this.animation != null) {
189-
float durationScale = AnimationUtilityKt.getDurationScale(view);
200+
float durationScale = AnimationUtilityKt.getDurationScale(view, durationScaleType);
190201
this.animation.setDuration((long) (this.animation.getDuration() * durationScale));
191202
}
192203
}

library/scene/src/main/java/com/bytedance/scene/utlity/AnimationUtility.kt

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.bytedance.scene.utlity
22

33
import android.provider.Settings
44
import android.view.View
5+
import androidx.annotation.StringDef
56
import kotlin.math.max
67

78
/**
@@ -10,12 +11,22 @@ import kotlin.math.max
1011
*/
1112
/**
1213
* 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]
1514
*/
1615
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 {
1728
val durationScale = Settings.Global.getFloat(
18-
view.context.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f
29+
view.context.contentResolver, durationScaleType, 1.0f
1930
)
2031
return max(0.0f, durationScale)
2132
}

0 commit comments

Comments
 (0)