[ElmSharp] Add ElmSharp.Wearable preloading (#1465)
authorJay Cho <chojoong@gmail.com>
Mon, 23 Mar 2020 08:01:33 +0000 (17:01 +0900)
committerGitHub <noreply@github.com>
Mon, 23 Mar 2020 08:01:33 +0000 (17:01 +0900)
* Add ElmSharp.Wearable preloading

* Update method name that calls Wearable preload

* Add more features on PreloadedWindow for CricleSurface

src/ElmSharp.Wearable/ElmSharp.Wearable/Preload.cs [new file with mode: 0644]
src/ElmSharp/ElmSharp/PreloadedWindow.cs

diff --git a/src/ElmSharp.Wearable/ElmSharp.Wearable/Preload.cs b/src/ElmSharp.Wearable/ElmSharp.Wearable/Preload.cs
new file mode 100644 (file)
index 0000000..8013409
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace ElmSharp.Wearable
+{
+    static class Preload
+    {
+        static public void WarmupWidgets(PreloadedWindow win)
+        {
+            var surface = new CircleSurface(win.BaseConformant);
+            win.BaseCircleSurface = surface;
+            new CircleDateTimeSelector(win, surface).Unrealize();
+            new CircleProgressBar(win, surface).Unrealize();
+            new CircleScroller(win, surface).Unrealize();
+            new CircleSlider(win, surface).Unrealize();
+            new CircleSpinner(win, surface).Unrealize();
+            new MoreOption(win).Unrealize();
+        }
+    }
+}
index 64c4317..8890506 100644 (file)
  * limitations under the License.
  */
 
+using System;
+using System.ComponentModel;
+using System.Reflection;
+
 namespace ElmSharp
 {
-    internal class PreloadedWindow : Window
+    /// <summary>
+    /// Pre-created window which prepares features that takes time in advance.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class PreloadedWindow : Window
     {
         static PreloadedWindow s_precreated;
 
-        public PreloadedWindow(bool useBaseLayout=true) : base("PreloadWindow")
+        internal PreloadedWindow(bool useBaseLayout=true) : base("PreloadWindow")
         {
             s_precreated = this;
             if (useBaseLayout)
@@ -29,6 +37,11 @@ namespace ElmSharp
             BackButtonPressed += DummyHandler;
             BackButtonPressed -= DummyHandler;
             void DummyHandler(object sender, System.EventArgs e) { }
+
+            if (Elementary.GetProfile() == "wearable")
+            {
+                WarmupWearableWidgets();
+            }
         }
 
         public Layout BaseLayout
@@ -37,9 +50,23 @@ namespace ElmSharp
             protected set;
         }
 
+        public Conformant BaseConformant
+        {
+            get;
+            protected set;
+        }
+
+        public object BaseCircleSurface
+        {
+            get;
+            set;
+        }
+
+
         public void InitializeBaseLayout()
         {
             var conformant = new Conformant(this);
+            BaseConformant = conformant;
             conformant.Show();
 
             var layout = new Layout(conformant);
@@ -69,6 +96,21 @@ namespace ElmSharp
             //TODO: Consider to call Image.LoadAsync()
         }
 
+        public void WarmupWearableWidgets()
+        {
+            try
+            {
+                Assembly assem = Assembly.Load("ElmSharp.Wearable");
+                var type = assem.GetType("ElmSharp.Wearable.Preload");
+                type.GetMethod("WarmupWidgets", BindingFlags.Public | BindingFlags.Static).Invoke(null, new object[] { this });
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e.ToString());
+                Console.WriteLine("Fail to preload ElmSharp.Wearable");
+            }
+        }
+
         public static PreloadedWindow GetInstance()
         {
             var instance = s_precreated;