--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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;
+using System.Collections.Generic;
+using Tizen.Applications.CoreBackend;
+using Tizen.Applications;
+
+namespace Tizen.NUI
+{
+ class NUIWatchCoreBackend : ICoreBackend
+ {
+ /// <summary>
+ /// Application instance to connect event.
+ /// </summary>
+ protected WatchApplication _application;
+ private string _stylesheet = "";
+
+ /// <summary>
+ /// Dictionary to contain each type of event callback.
+ /// </summary>
+ protected IDictionary<EventType, object> Handlers = new Dictionary<EventType, object>();
+
+ /// <summary>
+ /// The default Constructor.
+ /// </summary>
+ public NUIWatchCoreBackend()
+ {
+ }
+
+ /// <summary>
+ /// The constructor with stylesheet.
+ /// </summary>
+ public NUIWatchCoreBackend(string stylesheet)
+ {
+ _stylesheet = stylesheet;
+ }
+
+ /// <summary>
+ /// Add NUIApplication event to Application.
+ /// Put each type of event callback in Dictionary.
+ /// </summary>
+ /// <param name="evType">Type of event</param>
+ /// <param name="handler">Event callback</param>
+ public void AddEventHandler(EventType evType, Action handler)
+ {
+ Handlers.Add(evType, handler);
+ }
+
+ /// <summary>
+ /// Add NUIApplication event to Application.
+ /// Put each type of event callback in Dictionary.
+ /// </summary>
+ /// <typeparam name="TEventArgs">Argument type for the event</typeparam>
+ /// <param name="evType">Type of event</param>
+ /// <param name="handler">Event callback</param>
+ public void AddEventHandler<TEventArgs>(EventType evType, Action<TEventArgs> handler) where TEventArgs : EventArgs
+ {
+ Handlers.Add(evType, handler);
+ }
+
+
+ /// <summary>
+ /// Dispose function.
+ /// </summary>
+ public void Dispose()
+ {
+ _application.Dispose();
+ }
+
+ /// <summary>
+ /// Exit Application.
+ /// </summary>
+ public void Exit()
+ {
+ _application.Quit();
+ }
+
+ /// <summary>
+ /// Run Application.
+ /// </summary>
+ /// <param name="args">Arguments from commandline.</param>
+ public void Run(string[] args)
+ {
+ args[0] = Tizen.Applications.Application.Current.ApplicationInfo.ExecutablePath;
+ if (args.Length == 1)
+ {
+ _application = WatchApplication.NewWatchApplication();
+ }
+ else if (args.Length > 1)
+ {
+ _application = WatchApplication.NewWatchApplication(args, _stylesheet);
+ }
+
+ _application.BatteryLow += OnBatteryLow;
+ _application.LanguageChanged += OnLanguageChanged;
+ _application.MemoryLow += OnMemoryLow;
+ _application.RegionChanged += OnRegionChanged;
+
+ _application.Initialized += OnInitialized;
+ _application.Resumed += OnResumed;
+ _application.Terminating += OnTerminated;
+ _application.Paused += OnPaused;
+ _application.AppControl += OnAppControl;
+
+ _application.AmbientChanged += OnAmbientChanged;
+ _application.AmbientTick += OnAmbientTick;
+ _application.TimeTick += OnTimeTick;
+
+ _application.MainLoop();
+ }
+
+ private void OnTimeTick(object source, WatchApplication.TimeTickEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnTimeTick Called");
+ var handler = Handlers[NUIEventType.TimeTick] as Action<NUIWatchApplication.TimeTickEventArgs>;
+ handler?.Invoke(new NUIWatchApplication.TimeTickEventArgs(e.WatchTime));
+ }
+
+ private void OnAmbientTick(object source, WatchApplication.AmbientTickEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnAmbientTick Called");
+ var handler = Handlers[NUIEventType.AmbientTick] as Action<NUIWatchApplication.AmbientTickEventArgs>;
+ handler?.Invoke(new NUIWatchApplication.AmbientTickEventArgs(e.WatchTime));
+ }
+
+ private void OnAmbientChanged(object source, WatchApplication.AmbientChangedEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnAmbientChanged Called");
+ var handler = Handlers[NUIEventType.AmbientChanged] as Action<NUIWatchApplication.AmbientChangedEventArgs>;
+ handler?.Invoke(new NUIWatchApplication.AmbientChangedEventArgs(e.Changed));
+ }
+
+ /// <summary>
+ /// Region changed event callback function.
+ /// </summary>
+ /// <param name="source">Application instance</param>
+ /// <param name="e">Event argument for RegionChanged</param>
+ private void OnRegionChanged(object source, NUIApplicationRegionChangedEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnRegionChanged Called");
+ var handler = Handlers[EventType.RegionFormatChanged] as Action<RegionFormatChangedEventArgs>;
+ // Need to make new signal return in native to return right value.
+ handler?.Invoke( new RegionFormatChangedEventArgs(""));
+ }
+
+ /// <summary>
+ /// Memory Low event callback function.
+ /// </summary>
+ /// <param name="source">Application instance</param>
+ /// <param name="e">Event argument for MemoryLow</param>
+ private void OnMemoryLow(object source, NUIApplicationMemoryLowEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnMemoryLow Called");
+ var handler = Handlers[EventType.LowMemory] as Action<LowMemoryEventArgs>;
+ // Need to make new signal return in native to return right value.
+ handler?.Invoke( new LowMemoryEventArgs(LowMemoryStatus.None));
+ }
+
+ /// <summary>
+ /// Language changed event callback function.
+ /// </summary>
+ /// <param name="source">Application instance</param>
+ /// <param name="e">Event argument for LanguageChanged</param>
+ private void OnLanguageChanged(object source, NUIApplicationLanguageChangedEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnLanguageChanged Called");
+ var handler = Handlers[EventType.LocaleChanged] as Action<LocaleChangedEventArgs>;
+ // Need to make new signal return in native to return right value.
+ handler?.Invoke( new LocaleChangedEventArgs(""));
+ }
+
+ /// <summary>
+ /// Battery low event callback function.
+ /// </summary>
+ /// <param name="source">Application instance</param>
+ /// <param name="e">Event argument for BatteryLow</param>
+ private void OnBatteryLow(object source, NUIApplicationBatteryLowEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnBatteryLow Called");
+ var handler = Handlers[EventType.LowBattery] as Action<LowBatteryEventArgs>;
+ // Need to make new signal return in native to return right value.
+ handler?.Invoke(new LowBatteryEventArgs(LowBatteryStatus.None));
+ }
+
+ /// <summary>
+ /// Initialized event callback function.
+ /// </summary>
+ /// <param name="source">Application instance</param>
+ /// <param name="e">Event argument for Initialized</param>
+ private void OnInitialized(object source, NUIApplicationInitEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnInitialized Called");
+ var handler = Handlers[EventType.Created] as Action;
+ handler?.Invoke();
+ }
+
+ /// <summary>
+ /// Terminated event callback function.
+ /// </summary>
+ /// <param name="source">Application instance</param>
+ /// <param name="e">Event argument for Terminated</param>
+ private void OnTerminated(object source, NUIApplicationTerminatingEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnTerminated Called");
+ var handler = Handlers[EventType.Terminated] as Action;
+ handler?.Invoke();
+ }
+
+ /// <summary>
+ /// Resumed event callback function.
+ /// </summary>
+ /// <param name="source">Application instance</param>
+ /// <param name="e">Event argument for Resumed</param>
+ private void OnResumed(object source, NUIApplicationResumedEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnResumed Called");
+ var handler = Handlers[EventType.Resumed] as Action;
+ handler?.Invoke();
+ }
+
+ /// <summary>
+ /// App control event callback function.
+ /// </summary>
+ /// <param name="source">Application instance</param>
+ /// <param name="e">Event argument for AppControl</param>
+ private void OnAppControl(object source, NUIApplicationAppControlEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnAppControl Called");
+ var handler = Handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
+ SafeAppControlHandle handle = new SafeAppControlHandle(e.VoidP, false);
+ handler?.Invoke(new AppControlReceivedEventArgs(new ReceivedAppControl(handle)));
+ }
+
+ /// <summary>
+ /// Paused event callback function.
+ /// </summary>
+ /// <param name="source">Application instance</param>
+ /// <param name="e">Event argument for Paused</param>
+ private void OnPaused(object source, NUIApplicationPausedEventArgs e)
+ {
+ Log.Debug("NUI", "NUIWatchCorebackend OnPaused Called");
+ var handler = Handlers[EventType.Paused] as Action;
+ handler?.Invoke();
+ }
+
+ internal WatchApplication WatchApplicationHandle
+ {
+ get
+ {
+ return _application;
+ }
+ }
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * 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;
+using Tizen.Applications;
+using Tizen.Applications.CoreBackend;
+
+namespace Tizen.NUI
+{
+
+ /// <summary>
+ /// Represents an application that can make watch-face.
+ /// </summary>
+ public class NUIWatchApplication : CoreApplication
+ {
+ /// <summary>
+ /// Occurs whenever the application is resumed.
+ /// </summary>
+ public event EventHandler Resumed;
+
+ /// <summary>
+ /// Occurs whenever the application is paused.
+ /// </summary>
+ public event EventHandler Paused;
+
+ /// <summary>
+ /// Occurs at every second.
+ /// </summary>
+ public event EventHandler TimeTick;
+
+ /// <summary>
+ /// Event arguments that passed via time tick event signal.
+ /// </summary>
+ public class TimeTickEventArgs : EventArgs
+ {
+ private WatchTime _watchTime;
+ /// <summary>
+ /// Default Constructor.
+ /// </summary>
+ public TimeTickEventArgs( WatchTime watchTime )
+ {
+ _watchTime = watchTime;
+ }
+
+ /// <summary>
+ /// WatchTime.
+ /// </summary>
+ public WatchTime WatchTime
+ {
+ get
+ {
+ return _watchTime;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Occurs at each minute in ambient mode.
+ /// http://tizen.org/privilege/alarm.set privilege is needed to receive ambient ticks at each minute.
+ /// </summary>
+ public event EventHandler AmbientTick;
+
+ /// <summary>
+ /// Event arguments that passed via ambient tick event signal.
+ /// </summary>
+ public class AmbientTickEventArgs : EventArgs
+ {
+ private WatchTime _watchTime;
+ /// <summary>
+ /// Default Constructor.
+ /// </summary>
+ public AmbientTickEventArgs(WatchTime watchTime)
+ {
+ _watchTime = watchTime;
+ }
+
+ /// <summary>
+ /// WatchTime.
+ /// </summary>
+ public WatchTime WatchTime
+ {
+ get
+ {
+ return _watchTime;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Occurs when the device enters or exits ambient mode
+ /// </summary>
+ public event EventHandler AmbientChanged;
+
+ /// <summary>
+ /// Event arguments that passed via ambient tick event signal.
+ /// </summary>
+ public class AmbientChangedEventArgs : EventArgs
+ {
+ private bool _changed;
+ /// <summary>
+ /// Default Constructor.
+ /// </summary>
+ public AmbientChangedEventArgs(bool changed)
+ {
+ _changed = changed;
+ }
+
+ /// <summary>
+ /// Changed.
+ /// </summary>
+ public bool Changed
+ {
+ get
+ {
+ return _changed;
+ }
+ }
+ }
+
+ /// <summary>
+ /// The default constructor.
+ /// </summary>
+ public NUIWatchApplication() : base(new NUIWatchCoreBackend())
+ {
+ }
+
+ /// <summary>
+ /// The constructor with stylesheet.
+ /// </summary>
+ public NUIWatchApplication(string stylesheet) : base(new NUIWatchCoreBackend(stylesheet))
+ {
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected override void OnLocaleChanged(LocaleChangedEventArgs e)
+ {
+ Log.Debug("NUI", "OnLocaleChanged() is called!");
+ base.OnLocaleChanged(e);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected override void OnLowBattery(LowBatteryEventArgs e)
+ {
+ Log.Debug("NUI", "OnLowBattery() is called!");
+ base.OnLowBattery(e);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected override void OnLowMemory(LowMemoryEventArgs e)
+ {
+ Log.Debug("NUI", "OnLowMemory() is called!");
+ base.OnLowMemory(e);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
+ {
+ Log.Debug("NUI", "OnRegionFormatChanged() is called!");
+ base.OnRegionFormatChanged(e);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected override void OnCreate()
+ {
+ // This is also required to create DisposeQueue on main thread.
+ DisposeQueue disposeQ = DisposeQueue.Instance;
+ disposeQ.Initialize();
+ Log.Debug("NUI","OnCreate() is called!");
+ base.OnCreate();
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected virtual void OnPreCreate()
+ {
+ Log.Debug("NUI", "OnPreCreate() is called!");
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected override void OnTerminate()
+ {
+ Log.Debug("NUI", "OnTerminate() is called!");
+ base.OnTerminate();
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
+ {
+ Log.Debug("NUI", "OnAppControlReceived() is called!");
+ if (e != null)
+ {
+ Log.Debug("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
+ Log.Debug("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + " IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
+ }
+ base.OnAppControlReceived(e);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected void OnPause()
+ {
+ Log.Debug("NUI", "OnPause() is called!");
+ Paused?.Invoke(this, EventArgs.Empty);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected virtual void OnResume()
+ {
+ Log.Debug("NUI", "OnResume() is called!");
+ Resumed?.Invoke(this, EventArgs.Empty);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected virtual void OnTimeTick(TimeTickEventArgs e)
+ {
+ Log.Debug("NUI", "OnTimeTick() is called!");
+ TimeTick?.Invoke(this, e);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
+ protected virtual void OnAmbientTick(AmbientTickEventArgs e)
+ {
+ Log.Debug("NUI", "OnAmbientTick() is called!");
+ AmbientTick?.Invoke(this, e);
+ }
+
+ /// <summary>
+ /// Overrides this method if want to handle behavior.
+ /// </summary>
+ protected virtual void OnAmbientChanged(AmbientChangedEventArgs e)
+ {
+ Log.Debug("NUI", "OnAmbientChanged() is called!");
+ AmbientChanged?.Invoke(this, e);
+ }
+
+ /// <summary>
+ /// Run NUIWidgetApplication.
+ /// </summary>
+ /// <param name="args">Arguments from commandline.</param>
+ public override void Run(string[] args)
+ {
+ Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
+ Backend.AddEventHandler(EventType.Resumed, OnResume);
+ Backend.AddEventHandler(EventType.Paused, OnPause);
+
+ Backend.AddEventHandler<TimeTickEventArgs>(NUIEventType.TimeTick, OnTimeTick);
+ Backend.AddEventHandler<AmbientTickEventArgs>(NUIEventType.AmbientTick, OnAmbientTick);
+ Backend.AddEventHandler<AmbientChangedEventArgs>(NUIEventType.AmbientChanged, OnAmbientChanged);
+
+ base.Run(args);
+ }
+
+ /// <summary>
+ /// Exit NUIWidgetApplication.
+ /// </summary>
+ public override void Exit()
+ {
+ Backend.Exit();
+ }
+
+ internal WatchApplication ApplicationHandle
+ {
+ get
+ {
+ return ((NUIWatchCoreBackend)this.Backend).WatchApplicationHandle;
+ }
+ }
+
+ /// <summary>
+ /// Get the window instance.
+ /// </summary>
+ public Window Window
+ {
+ get
+ {
+ //return Window.Instance;
+ return ApplicationHandle.GetWindow();
+ }
+ }
+
+ }
+}