From a6f285242582081d02c0e19724671a04afe8211e Mon Sep 17 00:00:00 2001 From: bentmar Date: Mon, 2 Sep 2019 22:26:57 +0200 Subject: [PATCH] [Android] fix animations not animating (#7298) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * [Android] fix animations not animating fixes #7255 fixes #7291 fixes #7278 I found that if the Animation duration scale setting has never been changed in the developer settings, the scale we get will allways be 0. So instead of defaulting to 0 we default to 1. This means if i havent touched the setting it will behave as it did pre 4.2. Also if somehow the context is null, we should default to enabling animations since this is far more "normal" than disabling animations. * Update Xamarin.Forms.Platform.Android/AndroidTicker.cs Co-Authored-By: Javier Suárez Ruiz * Fix code * Use tabs, return false if fail, enable warning --- Xamarin.Forms.Platform.Android/AndroidTicker.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Xamarin.Forms.Platform.Android/AndroidTicker.cs b/Xamarin.Forms.Platform.Android/AndroidTicker.cs index 6640d93..6b2c389 100644 --- a/Xamarin.Forms.Platform.Android/AndroidTicker.cs +++ b/Xamarin.Forms.Platform.Android/AndroidTicker.cs @@ -43,7 +43,7 @@ namespace Xamarin.Forms.Platform.Android // If power saver is active, then animations will not run _energySaveModeDisabled = !powerSaveOn; - + // Notify the ticker that this value has changed, so it can manage animations in progress OnSystemEnabledChanged(); } @@ -56,8 +56,20 @@ namespace Xamarin.Forms.Platform.Android return false; } - var scale = global::Android.Provider.Settings.Global.GetFloat(resolver, global::Android.Provider.Settings.Global.AnimatorDurationScale, 0); - return scale > 0; + float animationScale; + + if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1) + { + animationScale = global::Android.Provider.Settings.Global.GetFloat(resolver, global::Android.Provider.Settings.Global.AnimatorDurationScale, 1); + } + else + { +#pragma warning disable 0618 + animationScale = global::Android.Provider.Settings.System.GetFloat(resolver, global::Android.Provider.Settings.System.AnimatorDurationScale, 1); +#pragma warning restore 0618 + } + + return animationScale > 0; } public void Dispose() @@ -95,4 +107,4 @@ namespace Xamarin.Forms.Platform.Android SendSignals(); } } -} \ No newline at end of file +} -- 2.7.4