cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [2/2] git commit: [wp] implemented OnInit so splash screen can be shown before cordova page is loaded
Date Fri, 30 May 2014 00:42:07 GMT
[wp] implemented OnInit so splash screen can be shown before cordova page is loaded


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/commit/988517df
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/tree/988517df
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/diff/988517df

Branch: refs/heads/master
Commit: 988517df7fffae4aab0527816de6015abac5a9dc
Parents: 8e12d55
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Thu May 29 17:41:49 2014 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Thu May 29 17:41:49 2014 -0700

----------------------------------------------------------------------
 src/wp/SplashScreen.cs | 112 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 105 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/blob/988517df/src/wp/SplashScreen.cs
----------------------------------------------------------------------
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 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)
+        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();
             });
         }
     }


Mime
View raw message