--- /dev/null
+/*
+ * Copyright (c) 2020 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.Threading.Tasks;
+using Tizen.NUI;
+using Tizen.NUI.WindowSystem.Shell;
+
+namespace Oobe.Common.Services
+{
+ /// <summary>
+ /// SoftKeys managing service.
+ /// </summary>
+ public sealed class SoftKeyClientService
+ {
+ private const int MaxInitializeAttempts = 10;
+ private const int IntitializeAttemptInterval = 3000;
+
+ private static SoftKeyClientService instance;
+
+ private TizenShell shell;
+ private SoftkeyClient client;
+ private TaskCompletionSource<bool> initialized;
+
+ private SoftKeyClientService()
+ {
+ initialized = new TaskCompletionSource<bool>();
+ ScheduleInitialize();
+ }
+
+ /// <summary>
+ /// Returns a service
+ /// </summary>
+ public static SoftKeyClientService Instance
+ {
+ get
+ {
+ if (instance == null)
+ {
+ instance = new SoftKeyClientService();
+ }
+
+ return instance;
+ }
+ }
+
+ /// <summary>
+ /// Shows soft keys system-wide
+ /// </summary>
+ public async Task Show()
+ {
+ Tizen.Log.Warn("oobe", $"Show");
+ bool initDone = await initialized.Task;
+ if (initDone)
+ {
+ Tizen.Log.Warn("oobe", $"client.Show()");
+ client.Opacity = SoftkeyOpacityState.Opaque;
+ client.Show();
+ }
+ }
+
+ /// <summary>
+ /// Hides soft keys system-wide
+ /// </summary>
+ public async Task Hide()
+ {
+ Tizen.Log.Warn("oobe", $"Hide");
+ bool initDone = await initialized.Task;
+ if (initDone)
+ {
+ Tizen.Log.Warn("oobe", $"client.Hide()");
+ client.Opacity = SoftkeyOpacityState.Transparent;
+ client.Hide();
+ }
+ }
+
+ private void Initialize()
+ {
+ shell = new TizenShell();
+ client = new SoftkeyClient(shell, Window.Instance);
+ initialized.SetResult(true);
+ }
+
+ private void ScheduleInitialize()
+ {
+ int attempt = 0;
+ Tizen.Log.Warn("oobe", $"ScheduleInitialize");
+
+ Timer timer = new Timer(IntitializeAttemptInterval);
+ timer.Tick += (sender, args) =>
+ {
+ attempt++;
+
+ if (attempt > MaxInitializeAttempts)
+ {
+ Tizen.Log.Error("oobe", $"Max initialize attempts reached");
+ initialized.SetResult(false);
+ return false;
+ }
+
+ try
+ {
+ Tizen.Log.Warn("oobe", $"Attempt to intialize: {attempt}");
+ Initialize();
+ }
+ catch (Exception e)
+ {
+ Tizen.Log.Warn("oobe", $"SoftKeyClientService.Initialize failed {e.Message}");
+ return true;
+ }
+
+ return false;
+ };
+ timer.Start();
+ }
+ }
+}
using System;
using System.Globalization;
using Oobe.Common.Resources;
+using Oobe.Common.Services;
using Oobe.Managers;
using Tizen.NUI;
using Tizen.NUI.Components;
Window.Instance.Hide();
}
+ protected override void OnTerminate()
+ {
+ Tizen.Log.Debug("oobe", "OnTerminate");
+ SoftKeyClientService.Instance.Show();
+ base.OnTerminate();
+ }
+
protected override void OnAppControlReceived(Tizen.Applications.AppControlReceivedEventArgs e)
{
Tizen.Log.Debug("oobe", "OnAppControlReceived: " + e.ReceivedAppControl.Operation);
Window.Instance.Show();
Initialize();
+ SoftKeyClientService.Instance.Hide();
}
private void Reset()