2 * Copyright (c) 2017 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using LibTVRefCommonPortable.Utils;
25 /// A custom EventArgs with string field
27 public class TVHomeEventArgs : EventArgs
33 /// A TVHomeStatus type enumeration
35 public enum TVHomeStatus
43 /// A class that represents TV Home application
45 public class App : Application, IPlatformNotification
48 /// A keyword for checking app status
50 public static readonly string AppStatus = "appstatus";
53 /// An event handler for handling Home key pressed event
55 private static EventHandler<TVHomeEventArgs> HomeKeyListener;
58 /// An event handler for handling Menu key pressed event
60 private static EventHandler<TVHomeEventArgs> MenuKeyListener;
63 /// An event handler for handling application installed event
65 private static EventHandler<TVHomeEventArgs> AppInstalledListener;
68 /// An event handler for handling application uninstalled event
70 private static EventHandler<TVHomeEventArgs> AppUninstalledListener;
73 /// An event handler for handling application pinned event
75 private static EventHandler<TVHomeEventArgs> AppPinnedNotificationListener;
79 /// Sets main page to MainPage instance
81 /// <param name="screenWidth">Screen Width</param>
82 /// <param name="screenHeight">Screen Height</param>
83 /// <param name="dpi">Screen DPI</param>
84 /// <param name="scaleRatio">Scale ratio</param>
85 public App(int screenWidth, int screenHeight, int dpi, double scaleRatio)
87 SizeUtils.ScreenWidth = screenWidth;
88 SizeUtils.ScreenHeight = screenHeight;
90 SizeUtils.ScaleRatio = scaleRatio;
95 if (DependencyService.Get<ISystemSettings>() != null && DependencyService.Get<ISystemSettings>().GetSystemModelName(out modelName))
97 SizeUtils.SetModelName(modelName);
102 DebuggingUtils.Err("Cant get model name!!!, " + e.Message);
105 MainPage = new MainPage();
109 /// A method is called when the application starts
111 protected override void OnStart()
113 MessagingCenter.Send<App, TVHomeStatus>(this, "appstatus", TVHomeStatus.OnStart);
117 /// A method is called when the application enters the sleeping state
119 protected override void OnSleep()
121 MessagingCenter.Send<App, TVHomeStatus>(this, "appstatus", TVHomeStatus.OnSleep);
125 /// A method is called when the application resumes from a sleeping state
127 protected override void OnResume()
129 MessagingCenter.Send<App, TVHomeStatus>(this, "appstatus", TVHomeStatus.OnResume);
133 /// A method adds EventHandler to HomeKeyListener
135 /// <param name="listener">The EventHandler for adding</param>
136 public static void SetHomeKeyListener(EventHandler<TVHomeEventArgs> listener)
138 HomeKeyListener += listener;
142 /// A method adds EventHandler to MenuKeyListener
144 /// <param name="listener">The EventHandler for adding</param>
145 public static void SetMenuKeyListener(EventHandler<TVHomeEventArgs> listener)
147 MenuKeyListener += listener;
151 /// A method adds EventHandler to AppInstalledListener
153 /// <param name="listener">The EventHandler for adding</param>
154 public static void SetAppInstalledListener(EventHandler<TVHomeEventArgs> listener)
156 AppInstalledListener += listener;
160 /// A method adds EventHandler to AppUninstalledListener
162 /// <param name="listener">The EventHandler for adding</param>
163 public static void SetAppUninstalledListener(EventHandler<TVHomeEventArgs> listener)
165 AppUninstalledListener += listener;
169 /// A method adds EventHandler to AppPinnedNotificationListener
171 /// <param name="listener">The EventHandler for adding</param>
172 public static void SetAppPinnedNotificationListener(EventHandler<TVHomeEventArgs> listener)
174 AppPinnedNotificationListener += listener;
178 /// A method for handling home key pressed event
180 public void OnHomeKeyPressed()
182 DebuggingUtils.Dbg("[[[ Home Key ]]] ");
183 HomeKeyListener?.Invoke(this, new TVHomeEventArgs()
190 /// A method for handling menu key pressed event
192 public void OnMenuKeyPressed()
194 DebuggingUtils.Dbg("\" Menu Key \" ");
195 MenuKeyListener?.Invoke(this, new TVHomeEventArgs()
201 public void OnNavigationKeyPressed(string keyName)
203 DebuggingUtils.Dbg("OnNavigationKeyPressed, " + keyName);
204 MessagingCenter.Send<App, string>(this, "NavigationKeyPressed", keyName);
208 /// A method for handling application installed event
210 /// <param name="pkgID">An installed package ID</param>
211 public void OnAppInstalled(string pkgID)
213 DebuggingUtils.Dbg("[[[ App Installed ]]] " + pkgID);
214 AppInstalledListener?.Invoke(this, new TVHomeEventArgs()
221 /// A method for handling application uninstalled event
223 /// <param name="pkgID">A uninstalled package ID</param>
224 public void OnAppUninstalled(string pkgID)
226 DebuggingUtils.Dbg("[[[ App Uninstalled ]]] " + pkgID);
227 AppUninstalledListener?.Invoke(this, new TVHomeEventArgs()
234 /// A method for receiving a pin app App Control request
236 public void OnPinAppRequestReceived()
242 /// A method for receiving application pinned notification and invoke pinned event
244 /// <param name="appID">A pinned app ID</param>
245 public void OnAppPinnedNotificationReceived(String appID)
247 DebuggingUtils.Dbg("[[[ App Pinned ]]] " + appID);
248 AppPinnedNotificationListener?.Invoke(this, new TVHomeEventArgs()