Android开发者选项中动画相关配置,看这篇就够了!!!

在Android开发者选项中关于动画的设置有三个选项:窗口动画缩放、过渡动画缩放、动画程序时长缩放

这三个“缩放”的具体含义如下:

窗口动画缩放:

Scaling factor for normal window animations. Setting to 0 will disable window animations. //作用于非Activity窗口

过渡动画缩放:

Scaling factor for activity transition animations. Setting to 0 will disable window animations. //作用于Activity窗口

动画程序时长缩放:

Scaling factor for Animator-based animations. This affects both the start delay and duration of all such animations. Setting to 0 will cause animations to end immediately. The default value is 1.//作用于全局的动画时长

在实际的ROM开发定制中,可能遇到定制动画默认值得需求(如为凸显性能,加快动画速度等等),如何修改这三个配置呢?

在SettingsProvider app中,android为我们提供了很多系统配置的默认值,其中窗口动画缩放(WINDOW_ANIMATION_SCALE)和过渡动画缩放(TRANSITION_ANIMATION_SCALE)均被定义为1

目录:frameworks/base/packages/SettingsProvider/res/values/defaults.xml

100%

100%

可以在此处直接修改,或者是通过overlay机制进行重写(推荐使用overlay进行客制化)

defaults.xml中的默认值会在android首次开机时,通过DatabaseHelper.java初始化建表后loadSettings() ->loadSystemSettings()->loadDefaultAnimationSettings()导入SettingDB中。

“动画程序时长缩放”的配置相比较之前的两个属性较为特殊,在default.xml中并未对该属性配置默认值,但为何依然能通过mWindowManager.getAnimationScale(which)判断出其配配置成了value=1呢?答案在WindowManagerService.java中,defaultValue默认被设置成了1.0f

private float mAnimatorDurationScaleSetting = 1.0f;

Override

public float getAnimationScale(int which) {

switch (which) {

case 0: return mWindowAnimationScaleSetting;

case 1: return mTransitionAnimationScaleSetting;

case 2: return mAnimatorDurationScaleSetting;

}

return 0;

}

最后如何通过Java代码设置这三个属性呢?

mWindowManager.setAnimationScale(which, scale);

//获取WindowManager句柄,通过binder调用WindowManagerService中setAnimationScale方法

verride

public void setAnimationScale(int which, float scale) {

if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,

"setAnimationScale()")) {

throw new SecurityException("Requires SET_ANIMATION_SCALE permission");

}

scale = fixScale(scale);

switch (which) {

case 0: mWindowAnimationScaleSetting = scale; break;

case 1: mTransitionAnimationScaleSetting = scale; break;

case 2: mAnimatorDurationScaleSetting = scale; break;

}

// Persist setting

mH.sendEmptyMessage(H.PERSIST_ANIMATION_SCALE);

}

希望我的分析能够给初学者提供一些参考和帮助,有任何疑问欢迎留言。

你可能感兴趣的:(Android开发者选项中动画相关配置,看这篇就够了!!!)