[Android] fix animations not animating (#7298)
authorbentmar <bjorn.bentmar@gmail.com>
Mon, 2 Sep 2019 20:26:57 +0000 (22:26 +0200)
committerGerald Versluis <gerald.versluis@microsoft.com>
Mon, 2 Sep 2019 20:26:57 +0000 (22:26 +0200)
* [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 <javiersuarezruiz@hotmail.com>
* Fix code

* Use tabs, return false if fail, enable warning

Xamarin.Forms.Platform.Android/AndroidTicker.cs

index 6640d93..6b2c389 100644 (file)
@@ -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
+}