From 05efe285a4a66c6383e99ac9331236144744e903 Mon Sep 17 00:00:00 2001 From: Jay Cho Date: Mon, 23 Mar 2020 17:01:33 +0900 Subject: [PATCH] [ElmSharp] Add ElmSharp.Wearable preloading (#1465) * Add ElmSharp.Wearable preloading * Update method name that calls Wearable preload * Add more features on PreloadedWindow for CricleSurface --- .../ElmSharp.Wearable/Preload.cs | 35 ++++++++++++++ src/ElmSharp/ElmSharp/PreloadedWindow.cs | 46 ++++++++++++++++++- 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/ElmSharp.Wearable/ElmSharp.Wearable/Preload.cs diff --git a/src/ElmSharp.Wearable/ElmSharp.Wearable/Preload.cs b/src/ElmSharp.Wearable/ElmSharp.Wearable/Preload.cs new file mode 100644 index 000000000..801340995 --- /dev/null +++ b/src/ElmSharp.Wearable/ElmSharp.Wearable/Preload.cs @@ -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(); + } + } +} diff --git a/src/ElmSharp/ElmSharp/PreloadedWindow.cs b/src/ElmSharp/ElmSharp/PreloadedWindow.cs index 64c43175e..8890506ca 100644 --- a/src/ElmSharp/ElmSharp/PreloadedWindow.cs +++ b/src/ElmSharp/ElmSharp/PreloadedWindow.cs @@ -14,13 +14,21 @@ * limitations under the License. */ +using System; +using System.ComponentModel; +using System.Reflection; + namespace ElmSharp { - internal class PreloadedWindow : Window + /// + /// Pre-created window which prepares features that takes time in advance. + /// + [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; -- 2.34.1