如何确定是否在设置中启用了窗口动画

时间:2011-09-23 13:07:31

标签: android

我知道,我可以用

启动设置活动
Intent intent = new Intent(Settings.ACTION_DISPLAY_SETTINGS);
startActivityForResult(intent,1);

但我怎么知道动画是否首先启用了?

如果在设置中启用了动画,我在自定义视图中有一个动画,只想显示它。如果他们被禁用,我想让用户在他第一次启动应用程序时启用它们。

2 个答案:

答案 0 :(得分:13)

  

设置。系统 .TRANSITION_ANIMATION_SCALE和设置。系统 .ANIMATOR_DURATION_SCALE已弃用 API 17

所以我用这个方法找出来。

private boolean areSystemAnimationsEnabled() {
  float duration, transition;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    duration = Settings.Global.getFloat(
                  context.getContentResolver(), 
                  Settings.Global.ANIMATOR_DURATION_SCALE, 1);
    transition = Settings.Global.getFloat(
                  context.getContentResolver(), 
                  Settings.Global.TRANSITION_ANIMATION_SCALE, 1);
  } else {
    duration = Settings.System.getFloat(
                  context.getContentResolver(), 
                  Settings.System.ANIMATOR_DURATION_SCALE, 1);
    transition = Settings.System.getFloat(
                  context.getContentResolver(), 
                  Settings.System.TRANSITION_ANIMATION_SCALE, 1);
  }
  return (duration != 0 && transition != 0);
}

或者,您只能查看ANIMATOR_DURATION_SCALE ...

private float checkSystemAnimationsDuration() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    return Settings.Global.getFloat(
        context.getContentResolver(),
        Settings.Global.ANIMATOR_DURATION_SCALE,
        0);
  } else {
    return Settings.System.getFloat(
        context.getContentResolver(),
        Settings.System.ANIMATOR_DURATION_SCALE,
        0);
  }
}

并相应地设置你的valueAnimator.setDuration()。

ValueAnimator alphaFirstItemAnimator = new ValueAnimator();
alphaFirstItemAnimator.setObjectValues(0.8F, 0F);
alphaFirstItemAnimator.setDuration((long)(DURATION_ANIMATION_MILLIS * checkSystemAnimationsDuration()));
alphaFirstItemAnimator.setInterpolator(new DecelerateInterpolator());
alphaFirstItemAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  public void onAnimationUpdate(ValueAnimator animation) {

  }
});

我希望它有所帮助。

答案 1 :(得分:11)

查看http://developer.android.com/reference/android/provider/Settings.System.html

您可以阅读标志:

  • TRANSITION_ANIMATION_SCALE
  • WINDOW_ANIMATION_SCALE

如果它们为0,则禁用动画。