You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2015/03/10 22:27:46 UTC

[1/3] cordova-plugin-splashscreen git commit: Extend WP8 Splash Screen to respect SplashScreen and SplashScreenDelay preferences from config file

Repository: cordova-plugin-splashscreen
Updated Branches:
  refs/heads/master 8bc540e45 -> 6b1e72c63


Extend WP8 Splash Screen to respect SplashScreen and SplashScreenDelay preferences from config file


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/688b138e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/tree/688b138e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/diff/688b138e

Branch: refs/heads/master
Commit: 688b138e317f78978550f0d43da0e0d4eae25f3e
Parents: d2e62a5
Author: Georgi Alexandrov <ge...@telerik.com>
Authored: Thu Mar 5 15:56:44 2015 +0200
Committer: Georgi Alexandrov <ge...@telerik.com>
Committed: Mon Mar 9 14:30:14 2015 +0200

----------------------------------------------------------------------
 src/wp/SplashScreen.cs | 126 +++++++++++++++++++++++++++++++-------------
 1 file changed, 89 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/blob/688b138e/src/wp/SplashScreen.cs
----------------------------------------------------------------------
diff --git a/src/wp/SplashScreen.cs b/src/wp/SplashScreen.cs
index 4d3545b..0eaaaac 100644
--- a/src/wp/SplashScreen.cs
+++ b/src/wp/SplashScreen.cs
@@ -40,26 +40,35 @@ namespace WPCordovaClassLib.Cordova.Commands
     /// </summary>
     public class SplashScreen : BaseCommand
     {
+        private readonly Preferences preferences = new Preferences();
         private Popup popup;
-        private bool autohide = true;
 
         private static bool WasShown = false;
 
         public SplashScreen()
         {
-            Image SplashScreen = new Image();
-            BitmapImage splash_image = new BitmapImage();
-            splash_image.SetSource(Application.GetResourceStream(new Uri(@"SplashScreenImage.jpg", UriKind.Relative)).Stream);
-            SplashScreen.Source = splash_image;
+            this.LoadPreferencesFromConfiguration();
+
+            Image SplashScreen = new Image()
+            {
+                Height = Application.Current.Host.Content.ActualHeight,
+                Width = Application.Current.Host.Content.ActualWidth,
+                Stretch = Stretch.Fill
+            };
+
+            var imageResource = Application.GetResourceStream(preferences.SplashScreenImage);
+            if (imageResource != null)
+            {
+                BitmapImage splash_image = new BitmapImage();
+                splash_image.SetSource(imageResource.Stream);
+                SplashScreen.Source = splash_image;
+            }
 
             // Instansiate the popup and set the Child property of Popup to SplashScreen
-            popup = new Popup() {IsOpen = false, Child = SplashScreen };
+            this.popup = new Popup() { IsOpen = false, Child = SplashScreen };
             // Orient the popup accordingly
-            popup.HorizontalAlignment = HorizontalAlignment.Stretch;
-            popup.VerticalAlignment = VerticalAlignment.Center;
-            
-
-            LoadConfigValues();
+            this.popup.HorizontalAlignment = HorizontalAlignment.Stretch;
+            this.popup.VerticalAlignment = VerticalAlignment.Center;
         }
 
         public override void OnInit()
@@ -68,27 +77,52 @@ namespace WPCordovaClassLib.Cordova.Commands
             if (!WasShown)
             {
                 WasShown = true;
-                show();
+                this.show();
             }
         }
 
-        void LoadConfigValues()
+        private static void GetPreference(XDocument document, string preferenceName, Action<string> action)
         {
-            StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("config.xml", UriKind.Relative));
+            var attribute = from results in document.Descendants()
+                            where (string)results.Attribute("name") == preferenceName
+                            select (string)results.Attribute("value");
 
-            if (streamInfo != null)
+            var value = attribute.FirstOrDefault();
+            if (!string.IsNullOrWhiteSpace(value))
             {
-                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";
+                action(value);
+            }      
+        }
 
-                if (preferences.Count() > 0 &&  preferences.First() == false)
+        private void LoadPreferencesFromConfiguration()
+        {
+            StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("config.xml", UriKind.Relative));
+            if (streamInfo != null)
+            {
+                using (StreamReader sr = new StreamReader(streamInfo.Stream))
                 {
-                    autohide = false;
+                    //This will Read Keys Collection for the xml file
+                    XDocument document = XDocument.Parse(sr.ReadToEnd());
+
+                    GetPreference(document, "AutoHideSplashScreen", value =>
+                    {
+                        var autoHideSplashScreen = false;
+                        if (bool.TryParse(value, out autoHideSplashScreen))
+                        {
+                            preferences.AutoHideSplashScreen = autoHideSplashScreen;
+                        }
+                    });
+
+                    GetPreference(document, "SplashScreenDelay", value =>
+                    {
+                        var splashScreenDelay = 0;
+                        if (int.TryParse(value, out splashScreenDelay))
+                        {
+                            preferences.SplashScreenDelay = splashScreenDelay;
+                        }
+                    });
+
+                    GetPreference(document, "SplashScreen", value => preferences.SplashScreenImage = new Uri(value, UriKind.Relative));
                 }
             }
         }
@@ -97,12 +131,12 @@ namespace WPCordovaClassLib.Cordova.Commands
         {
             Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
-                if (popup.IsOpen)
+                if (this.popup.IsOpen)
                 {
                     return;
                 }
 
-                popup.Child.Opacity = 0;
+                this.popup.Child.Opacity = 0;
 
                 Storyboard story = new Storyboard();
                 DoubleAnimation animation;
@@ -119,22 +153,15 @@ namespace WPCordovaClassLib.Cordova.Commands
 
                 story.Begin();
 
-                popup.IsOpen = true;
+                this.popup.IsOpen = true;
 
-                if (autohide)
+                if (this.preferences.AutoHideSplashScreen)
                 {
-                    DispatcherTimer timer = new DispatcherTimer();
-                    timer.Tick += (object sender, EventArgs e) =>
-                    {
-                        hide();
-                    };
-                    timer.Interval = TimeSpan.FromSeconds(1.2);
-                    timer.Start();
+                    this.StartAutoHideTimer();
                 }
-            }); 
+            });
         }
 
-
         public void hide(string options = null)
         {
             Deployment.Current.Dispatcher.BeginInvoke(() =>
@@ -163,5 +190,30 @@ namespace WPCordovaClassLib.Cordova.Commands
                 story.Begin();
             });
         }
+
+        private void StartAutoHideTimer()
+        {
+            var timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(preferences.SplashScreenDelay) };
+            timer.Tick += (object sender, EventArgs e) =>
+            {
+                this.hide();
+                timer.Stop();
+            };
+            timer.Start();
+        }
+
+        private class Preferences
+        {
+            public bool AutoHideSplashScreen { get; set; }
+            public Uri SplashScreenImage { get; set; }
+            public int SplashScreenDelay { get; set; }
+
+            public Preferences()
+            {
+                this.SplashScreenDelay = 3000;
+                this.AutoHideSplashScreen = true;
+                this.SplashScreenImage = new Uri("SplashScreenImage.jpg", UriKind.Relative);
+            }
+        }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[3/3] cordova-plugin-splashscreen git commit: [WP8] code cleanup, minor refactors, comments to clarify some stuff.

Posted by pu...@apache.org.
[WP8] code cleanup, minor refactors, comments to clarify some stuff.


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/6b1e72c6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/tree/6b1e72c6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/diff/6b1e72c6

Branch: refs/heads/master
Commit: 6b1e72c6312f1c449d15a11be445b858c6689d6a
Parents: 98edfeb
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Mar 10 14:27:29 2015 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Mar 10 14:27:29 2015 -0700

----------------------------------------------------------------------
 src/wp/SplashScreen.cs | 196 +++++++++++++++++++++-----------------------
 1 file changed, 92 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/blob/6b1e72c6/src/wp/SplashScreen.cs
----------------------------------------------------------------------
diff --git a/src/wp/SplashScreen.cs b/src/wp/SplashScreen.cs
index 0eaaaac..e8ef4c0 100644
--- a/src/wp/SplashScreen.cs
+++ b/src/wp/SplashScreen.cs
@@ -40,14 +40,24 @@ namespace WPCordovaClassLib.Cordova.Commands
     /// </summary>
     public class SplashScreen : BaseCommand
     {
-        private readonly Preferences preferences = new Preferences();
         private Popup popup;
 
+        // Time until we dismiss the splashscreen
+        private int prefDelay = 3000; 
+
+        // Whether we hide it by default
+        private bool prefAutoHide = true;
+
+        // Path to image to use
+        private string prefImagePath = "SplashScreenImage.jpg";
+
+        // static because autodismiss is only ever applied once, at app launch
+        // subsequent page loads should not cause the SplashScreen to be shown.
         private static bool WasShown = false;
 
         public SplashScreen()
         {
-            this.LoadPreferencesFromConfiguration();
+            LoadConfigPrefs();
 
             Image SplashScreen = new Image()
             {
@@ -56,7 +66,8 @@ namespace WPCordovaClassLib.Cordova.Commands
                 Stretch = Stretch.Fill
             };
 
-            var imageResource = Application.GetResourceStream(preferences.SplashScreenImage);
+            Uri imagePath = new Uri(prefImagePath, UriKind.RelativeOrAbsolute);
+            var imageResource = Application.GetResourceStream(imagePath);
             if (imageResource != null)
             {
                 BitmapImage splash_image = new BitmapImage();
@@ -65,36 +76,26 @@ namespace WPCordovaClassLib.Cordova.Commands
             }
 
             // Instansiate the popup and set the Child property of Popup to SplashScreen
-            this.popup = new Popup() { IsOpen = false, Child = SplashScreen };
-            // Orient the popup accordingly
-            this.popup.HorizontalAlignment = HorizontalAlignment.Stretch;
-            this.popup.VerticalAlignment = VerticalAlignment.Center;
+            popup = new Popup() { IsOpen = false, 
+                                  Child = SplashScreen,
+                                  HorizontalAlignment = HorizontalAlignment.Stretch,
+                                  VerticalAlignment = VerticalAlignment.Center
+
+            };
         }
 
         public override void OnInit()
         {
-            // we only want to autoload the first time a page is loaded.
-            if (!WasShown)
+            // we only want to autoload on the first page load.
+            // but OnInit is called for every page load.
+            if (!SplashScreen.WasShown)
             {
-                WasShown = true;
-                this.show();
+                SplashScreen.WasShown = true;
+                show();
             }
         }
 
-        private static void GetPreference(XDocument document, string preferenceName, Action<string> action)
-        {
-            var attribute = from results in document.Descendants()
-                            where (string)results.Attribute("name") == preferenceName
-                            select (string)results.Attribute("value");
-
-            var value = attribute.FirstOrDefault();
-            if (!string.IsNullOrWhiteSpace(value))
-            {
-                action(value);
-            }      
-        }
-
-        private void LoadPreferencesFromConfiguration()
+        private void LoadConfigPrefs()
         {
             StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("config.xml", UriKind.Relative));
             if (streamInfo != null)
@@ -102,118 +103,105 @@ namespace WPCordovaClassLib.Cordova.Commands
                 using (StreamReader sr = new StreamReader(streamInfo.Stream))
                 {
                     //This will Read Keys Collection for the xml file
-                    XDocument document = XDocument.Parse(sr.ReadToEnd());
+                    XDocument configFile = XDocument.Parse(sr.ReadToEnd());
 
-                    GetPreference(document, "AutoHideSplashScreen", value =>
-                    {
-                        var autoHideSplashScreen = false;
-                        if (bool.TryParse(value, out autoHideSplashScreen))
-                        {
-                            preferences.AutoHideSplashScreen = autoHideSplashScreen;
-                        }
-                    });
-
-                    GetPreference(document, "SplashScreenDelay", value =>
+                    string configAutoHide = configFile.Descendants()
+                                        .Where(x => (string)x.Attribute("name") == "AutoHideSplashScreen")
+                                        .Select(x => (string)x.Attribute("value"))
+                                        .FirstOrDefault();
+                    bool.TryParse(configAutoHide, out prefAutoHide);
+
+
+                    string configDelay = configFile.Descendants()
+                                      .Where(x => (string)x.Attribute("name") == "SplashScreenDelay")
+                                      .Select(x => (string)x.Attribute("value"))
+                                      .FirstOrDefault();
+                    int.TryParse(configDelay, out prefDelay);
+
+                    string configImage = configFile.Descendants()
+                                        .Where(x => (string)x.Attribute("name") == "SplashScreen")
+                                        .Select(x => (string)x.Attribute("value"))
+                                        .FirstOrDefault();
+
+                    if (!String.IsNullOrEmpty(configImage))
                     {
-                        var splashScreenDelay = 0;
-                        if (int.TryParse(value, out splashScreenDelay))
-                        {
-                            preferences.SplashScreenDelay = splashScreenDelay;
-                        }
-                    });
-
-                    GetPreference(document, "SplashScreen", value => preferences.SplashScreenImage = new Uri(value, UriKind.Relative));
+                        prefImagePath = configImage;
+                    }
                 }
             }
         }
 
         public void show(string options = null)
         {
-            Deployment.Current.Dispatcher.BeginInvoke(() =>
+
+            if (!popup.IsOpen)    
             {
-                if (this.popup.IsOpen)
+                Deployment.Current.Dispatcher.BeginInvoke(() =>
                 {
-                    return;
-                }
+                    popup.Child.Opacity = 0;
 
-                this.popup.Child.Opacity = 0;
+                    Storyboard story = new Storyboard();
+                    DoubleAnimation animation = new DoubleAnimation()
+                                                    {
+                                                        From = 0.0,
+                                                        To = 1.0,
+                                                        Duration = new Duration(TimeSpan.FromSeconds(0.2))
+                                                    };
 
-                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);
 
-                Storyboard.SetTarget(animation, popup.Child);
-                Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity"));
-                story.Children.Add(animation);
+                    story.Begin();
 
-                Debug.WriteLine("Fading the splash screen in");
+                    popup.IsOpen = true;
 
-                story.Begin();
-
-                this.popup.IsOpen = true;
-
-                if (this.preferences.AutoHideSplashScreen)
-                {
-                    this.StartAutoHideTimer();
-                }
-            });
+                    if (prefAutoHide)
+                    {
+                        StartAutoHideTimer();
+                    }
+                });
+            }
         }
 
         public void hide(string options = null)
         {
-            Deployment.Current.Dispatcher.BeginInvoke(() =>
+            if (popup.IsOpen)
             {
-                if (!popup.IsOpen)
+                Deployment.Current.Dispatcher.BeginInvoke(() =>
                 {
-                    return;
-                }
 
-                popup.Child.Opacity = 1.0;
+                    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 story = new Storyboard();
+                    DoubleAnimation animation = new DoubleAnimation()
+                                                    {
+                                                        From = 1.0,
+                                                        To = 0.0,
+                                                        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();
-            });
+                    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();
+                });
+            }
         }
 
         private void StartAutoHideTimer()
         {
-            var timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(preferences.SplashScreenDelay) };
+            var timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(prefDelay) };
             timer.Tick += (object sender, EventArgs e) =>
             {
-                this.hide();
+                hide();
                 timer.Stop();
             };
             timer.Start();
         }
-
-        private class Preferences
-        {
-            public bool AutoHideSplashScreen { get; set; }
-            public Uri SplashScreenImage { get; set; }
-            public int SplashScreenDelay { get; set; }
-
-            public Preferences()
-            {
-                this.SplashScreenDelay = 3000;
-                this.AutoHideSplashScreen = true;
-                this.SplashScreenImage = new Uri("SplashScreenImage.jpg", UriKind.Relative);
-            }
-        }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[2/3] cordova-plugin-splashscreen git commit: Merge branch 'galexandrov/wp8-fixes' of https://github.com/Icenium/cordova-plugin-splashscreen

Posted by pu...@apache.org.
Merge branch 'galexandrov/wp8-fixes' of https://github.com/Icenium/cordova-plugin-splashscreen


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/98edfeb7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/tree/98edfeb7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/diff/98edfeb7

Branch: refs/heads/master
Commit: 98edfeb73e09aaaece29edff7770861892cbfe89
Parents: 8bc540e 688b138
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Mar 10 12:53:16 2015 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Mar 10 12:53:16 2015 -0700

----------------------------------------------------------------------
 src/wp/SplashScreen.cs | 126 +++++++++++++++++++++++++++++++-------------
 1 file changed, 89 insertions(+), 37 deletions(-)
----------------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org