From 8e12d550a1bbb54d67d1bdd2e79cdac50e894128 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Thu, 29 May 2014 17:40:38 -0700 Subject: [PATCH 1/3] [wp] plugin must be autoloaded for AutoHideSplashScreen preference to work --- plugin.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin.xml b/plugin.xml index c37989f..54d750b 100644 --- a/plugin.xml +++ b/plugin.xml @@ -89,6 +89,7 @@ + @@ -101,6 +102,7 @@ + From 988517df7fffae4aab0527816de6015abac5a9dc Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Thu, 29 May 2014 17:41:49 -0700 Subject: [PATCH 2/3] [wp] implemented OnInit so splash screen can be shown before cordova page is loaded --- src/wp/SplashScreen.cs | 112 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 105 insertions(+), 7 deletions(-) diff --git a/src/wp/SplashScreen.cs b/src/wp/SplashScreen.cs index 2eda771..da519d5 100644 --- a/src/wp/SplashScreen.cs +++ b/src/wp/SplashScreen.cs @@ -26,6 +26,11 @@ using Microsoft.Phone.Info; using System.Windows.Controls.Primitives; using System.Diagnostics; using System.Windows.Media.Imaging; +using System.Windows.Resources; +using System.IO; +using System.Xml.Linq; +using System.Linq; +using System.Windows.Threading; namespace WPCordovaClassLib.Cordova.Commands { @@ -36,6 +41,9 @@ namespace WPCordovaClassLib.Cordova.Commands public class SplashScreen : BaseCommand { private Popup popup; + private bool autohide = true; + + private static bool WasShown = false; public SplashScreen() { @@ -45,24 +53,114 @@ namespace WPCordovaClassLib.Cordova.Commands SplashScreen.Source = splash_image; // Instansiate the popup and set the Child property of Popup to SplashScreen - this.popup = new Popup() {IsOpen = false, Child = SplashScreen }; + popup = new Popup() {IsOpen = false, Child = SplashScreen }; // Orient the popup accordingly - this.popup.HorizontalAlignment = HorizontalAlignment.Stretch; - this.popup.VerticalAlignment = VerticalAlignment.Center; + popup.HorizontalAlignment = HorizontalAlignment.Stretch; + popup.VerticalAlignment = VerticalAlignment.Center; + + + LoadConfigValues(); } - public void show(string options) + public override void OnInit() { + // we only want to autoload the first time a page is loaded. + if (!WasShown) + { + WasShown = true; + show(); + } + } + + void LoadConfigValues() + { + StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("config.xml", UriKind.Relative)); + + if (streamInfo != null) + { + StreamReader sr = new StreamReader(streamInfo.Stream); + //This will Read Keys Collection for the xml file + XDocument document = XDocument.Parse(sr.ReadToEnd()); + + var preferences = from results in document.Descendants() + where (string)results.Attribute("name") == "AutoHideSplashScreen" + select (string)results.Attribute("value") == "true"; + + if (preferences.Count() > 0 && preferences.First() == false) + { + autohide = false; + } + } + } + + public void show(string options = null) + { + if (popup.IsOpen) + { + return; + } + Deployment.Current.Dispatcher.BeginInvoke(() => { - this.popup.IsOpen = true; + popup.Child.Opacity = 0; + + Storyboard story = new Storyboard(); + DoubleAnimation animation; + animation = new DoubleAnimation(); + animation.From = 0.0; + animation.To = 1.0; + animation.Duration = new Duration(TimeSpan.FromSeconds(0.2)); + + Storyboard.SetTarget(animation, popup.Child); + Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity")); + story.Children.Add(animation); + + Debug.WriteLine("Fading the splash screen in"); + + story.Begin(); + + popup.IsOpen = true; + + if (autohide) + { + DispatcherTimer timer = new DispatcherTimer(); + timer.Tick += (object sender, EventArgs e) => + { + hide(); + }; + timer.Interval = TimeSpan.FromSeconds(1.2); + timer.Start(); + } }); } - public void hide(string options) + + + public void hide(string options = null) { + if (!popup.IsOpen) + { + return; + } + Deployment.Current.Dispatcher.BeginInvoke(() => { - this.popup.IsOpen = false; + popup.Child.Opacity = 1.0; + + Storyboard story = new Storyboard(); + DoubleAnimation animation; + animation = new DoubleAnimation(); + animation.From = 1.0; + animation.To = 0.0; + animation.Duration = new Duration(TimeSpan.FromSeconds(0.4)); + + Storyboard.SetTarget(animation, popup.Child); + Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity")); + story.Children.Add(animation); + story.Completed += (object sender, EventArgs e) => + { + popup.IsOpen = false; + }; + story.Begin(); }); } } From f37c1557b664c07852d9b764be3deb631ba85322 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Thu, 29 May 2014 17:58:28 -0700 Subject: [PATCH 3/3] [wp8] updated quirk for and combined iOS,WP8,BB10 quirks as they are all the same --- doc/index.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/doc/index.md b/doc/index.md index c39bee7..00f7d24 100644 --- a/doc/index.md +++ b/doc/index.md @@ -60,11 +60,7 @@ Dismiss the splash screen. navigator.splashscreen.hide(); -### BlackBerry 10 Quirk - -The `config.xml` file's `AutoHideSplashScreen` setting must be `false`. - -### iOS Quirk +### BlackBerry 10, WP8, iOS Quirk The `config.xml` file's `AutoHideSplashScreen` setting must be `false`. To delay hiding the splash screen for two seconds, add a