<Compile Include="Utils\IAppControl.cs" />
<Compile Include="Utils\IApplicationManagerAPIs.cs" />
<Compile Include="Utils\IAppLifeControl.cs" />
+ <Compile Include="Utils\IWindowAPIs.cs" />
<Compile Include="Utils\IPlatformNotification.cs" />
<Compile Include="Utils\IBTAPIs.cs" />
<Compile Include="Utils\IDebuggingAPIs.cs" />
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+namespace LibTVRefCommonPortable.Utils
+{
+ public interface IWindowAPIs
+ {
+ void SetIconified(bool iconified);
+ bool GetIconified();
+ }
+}
<Compile Include="Ports\ApplicationManagerPort.cs" />
<Compile Include="Ports\BTModulePort.cs" />
<Compile Include="Ports\DebuggingPort.cs" />
- <Compile Include="Ports\ElmPort.cs" />
+ <Compile Include="Ports\WindowPort.cs" />
<Compile Include="Ports\FileSystemPort.cs" />
<Compile Include="Ports\FileSystemWatcherPort.cs" />
<Compile Include="Ports\PackageManagerPort.cs" />
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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.Runtime.InteropServices;
-
-namespace LibTVRefCommonTizen.Ports
-{
- public class ElmPort
- {
- internal class Elm
- {
- internal delegate bool EcoreEventHanlderCallback(IntPtr data, int type, IntPtr ei);
-
- [DllImport("libelementary.so.1", EntryPoint = "elm_win_keygrab_set", CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Elm_win_keygrab_set(IntPtr obj, string key, ulong modifiers, ulong not_modifiers, int proirity, int grab_mode);
-
- [DllImport("libelementary.so.1", EntryPoint = "elm_win_iconified_set", CallingConvention = CallingConvention.Cdecl)]
- internal static extern void Elm_win_iconified_set(IntPtr obj, bool iconified);
-
- [DllImport("libelementary.so.1", EntryPoint = "elm_win_iconified_get", CallingConvention = CallingConvention.Cdecl)]
- internal static extern bool Elm_win_iconified_get(IntPtr obj);
- }
-
- public static void SetKeyGrabExclusively(IntPtr window, string key)
- {
- DebuggingPort.D("Grab Key Event for :" + key);
- Elm.Elm_win_keygrab_set(window, key, 0, 0, 0, 1024);
- }
-
- public static void SetIconified(IntPtr window, bool iconified)
- {
- DebuggingPort.D("Iconified :" + iconified);
- Elm.Elm_win_iconified_set(window, iconified);
- }
-
- public static bool GetIconified(IntPtr window)
- {
- return Elm.Elm_win_iconified_get(window);
- }
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.Runtime.InteropServices;
+using LibTVRefCommonPortable.Utils;
+using Xamarin.Forms.Platform.Tizen.Native;
+
+namespace LibTVRefCommonTizen.Ports
+{
+ public class WindowPort : IWindowAPIs
+ {
+ internal class ElmWindow
+ {
+ [DllImport("libelementary.so.1", EntryPoint = "elm_win_keygrab_set", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern IntPtr elm_win_keygrab_set(IntPtr obj, string key, ulong modifiers, ulong not_modifiers, int proirity, int grab_mode);
+
+ [DllImport("libelementary.so.1", EntryPoint = "elm_win_iconified_set", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern void elm_win_iconified_set(IntPtr obj, bool iconified);
+
+ [DllImport("libelementary.so.1", EntryPoint = "elm_win_iconified_get", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern bool elm_win_iconified_get(IntPtr obj);
+ }
+
+ static private Window mainWindow;
+
+ public Window MainWindow
+ {
+ set
+ {
+ mainWindow = value;
+ }
+ }
+
+ public void SetKeyGrabExclusively(string key)
+ {
+ if (mainWindow != null)
+ ElmWindow.elm_win_keygrab_set((IntPtr)mainWindow, key, 0, 0, 0, 1024);
+ }
+
+ public void SetIconified(bool iconified)
+ {
+ if (mainWindow != null)
+ ElmWindow.elm_win_iconified_set((IntPtr)mainWindow, iconified);
+ }
+
+ public bool GetIconified()
+ {
+ if (mainWindow != null)
+ return ElmWindow.elm_win_iconified_get((IntPtr)mainWindow);
+ else
+ return false;
+ }
+
+ public void Active()
+ {
+ if (mainWindow != null)
+ mainWindow.Active();
+ }
+ }
+}
class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication
{
IPlatformNotification notification;
- private Timer timerForKeyGrab;
- private Timer timerForIconified;
+ WindowPort windowPort;
public static string AppResourcePath
{
private set;
}
- private void CallbackForKeyGrab(Object state)
- {
- MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName, true);
- MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, true);
- ElmPort.SetKeyGrabExclusively((IntPtr)(MainWindow), ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName);
- timerForKeyGrab.Dispose();
- timerForKeyGrab = null;
- DebuggingPort.D("KeyGrab finished");
- }
-
- private void CallbackForIconified(Object state)
- {
- ElmPort.SetIconified((IntPtr)MainWindow, true);
- timerForIconified.Dispose();
- timerForIconified = null;
- }
-
protected override void OnCreate()
{
base.OnCreate();
MainWindow.KeyUp += KeyUpListener;
MainWindow.Alpha = true;
- TimerCallback timerDelegate = new TimerCallback(CallbackForKeyGrab);
- timerForKeyGrab = new Timer(timerDelegate, null, 3000, 0);
+ windowPort = new WindowPort();
+ windowPort.MainWindow = MainWindow;
+
+ // Grab key events
+ MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName, true);
+ MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, true);
+ windowPort.SetKeyGrabExclusively(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName);
}
private void KeyUpListener(object sender, ElmSharp.EvasKeyEventArgs e)
DebuggingPort.D("Key Pressed :" + e.KeyName);
if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName) == 0)
{
- if (ElmPort.GetIconified((IntPtr)MainWindow) == true)
- {
- ElmPort.SetIconified((IntPtr)MainWindow, false);
- MainWindow.Active();
- notification.OnHomeKeyPressed();
- }
- else
+ if (notification != null)
{
notification.OnHomeKeyPressed();
- TimerCallback timerDelegate = new TimerCallback(CallbackForIconified);
- timerForIconified = new Timer(timerDelegate, null, 200, 0);
}
}
else if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName) == 0)
global::Xamarin.Forms.DependencyService.Register<FileSystemWatcherPort>();
global::Xamarin.Forms.DependencyService.Register<ApplicationManagerPort>();
global::Xamarin.Forms.DependencyService.Register<FileSystemPort>();
+ global::Xamarin.Forms.DependencyService.Register<WindowPort>();
global::Xamarin.Forms.Platform.Tizen.Forms.Init(app);
app.Run(args);
}
/// </summary>
public partial class MainPage : ContentPage
{
- private bool Iconified = false;
public static readonly BindableProperty CurrentStatusProperty = BindableProperty.Create("CurrentStatus", typeof(HomeStatus), typeof(MainPage), default(HomeStatus));
public HomeStatus CurrentStatus
{
private Dictionary<HomeMenuItem, Panel> SubPanelDictionary;
- private async void PlayHideAnimation()
+ private async void Iconified()
{
+#pragma warning disable CS4014
SubPanelDictionary[SelectedMenuName]?.TranslateTo(0.0, 100, 150);
+ DimmedBgImage.FadeTo(0.0, 150);
+#pragma warning restore CS4014
await PageMainPanel.ScaleTo(0.0, 150);
+ DependencyService.Get<IWindowAPIs>().SetIconified(true);
}
- private async void PlayShowAnimation()
+ private async void Uniconified()
{
+#pragma warning disable CS4014
SubPanelDictionary[SelectedMenuName]?.TranslateTo(0.0, 0.0, 150);
+ DimmedBgImage.FadeTo(0.5, 150);
+#pragma warning restore CS4014
await PageMainPanel.ScaleTo(1.0, 150);
+ DependencyService.Get<IWindowAPIs>().SetIconified(false);
+ }
+
+ private void ToggleIconified()
+ {
+ if (DependencyService.Get<IWindowAPIs>().GetIconified() == true)
+ {
+ PageMainPanel.InitialFocusing();
+ Uniconified();
+ }
+ else
+ {
+ Iconified();
+ }
}
public MainPage()
App.SetHomeKeyListener((e, arg) =>
{
- if (Iconified == true)
- {
- PageMainPanel.InitialFocusing();
- PlayShowAnimation();
- }
- else
- {
- PlayHideAnimation();
- }
-
- Iconified = !Iconified;
+ ToggleIconified();
});
// TODO : this is for the unpin test.
UpdatePinnedApps(PinnedApps);
}
}
+
+ protected override bool OnBackButtonPressed()
+ {
+ ToggleIconified();
+ return true;
+ }
}
}
\ No newline at end of file