[ElmSharp] Add efl_util window property APIs in ElmSharp (#389)
authorarosis78 <35049857+arosis78@users.noreply.github.com>
Mon, 13 Aug 2018 06:43:04 +0000 (15:43 +0900)
committerGitHub <noreply@github.com>
Mon, 13 Aug 2018 06:43:04 +0000 (15:43 +0900)
src/ElmSharp/ElmSharp/Window.cs
src/ElmSharp/Interop/Interop.Eutil.WindowProperty.cs [new file with mode: 0755]
src/ElmSharp/Interop/Interop.Libraries.cs
test/ElmSharp.Test/TC/WindowUtilTest.cs [new file with mode: 0755]
test/ElmSharp.Test/tizen-manifest.xml

index c716671..6cc803a 100755 (executable)
@@ -310,6 +310,55 @@ namespace ElmSharp
     };
 
     /// <summary>
+    /// Enumeration of notification window's priority level.
+    /// </summary>
+    /// <since_tizen> preview </since_tizen>
+    public enum NotificationLevel
+    {
+        /// <summary>
+        /// No (reset) notification level. This value makes the window place in normal layer.
+        /// </summary>
+        None = -1,
+
+        /// <summary>
+        /// Default notification level.
+        /// </summary>
+        Default = 10,
+
+        /// <summary>
+        /// Higher notification level than default.
+        /// </summary>
+        Medium = 20,
+
+        /// <summary>
+        /// Higher notification level than medium.
+        /// </summary>
+        High = 30,
+
+        /// <summary>
+        /// The highest notification level.
+        /// </summary>
+        Top = 40,
+    };
+
+    /// <summary>
+    /// Enumeration of screen mode.
+    /// </summary>
+    /// <since_tizen> preview </since_tizen>
+    public enum ScreenMode
+    {
+        /// <summary>
+        /// The mode which turns the screen off after a timeout.
+        /// </summary>
+        Default,
+
+        /// <summary>
+        /// The mode which keeps the screen turned on.
+        /// </summary>
+        AlwaysOn,
+    }
+
+    /// <summary>
     /// The Window is a container that contains the graphical user interface of a program.
     /// </summary>
     /// <since_tizen> preview </since_tizen>
@@ -949,6 +998,88 @@ namespace ElmSharp
         }
 
         /// <summary>
+        /// Gets or sets the priority level for the specified notification window.
+        /// </summary>
+        /// <privilege>
+        /// http://tizen.org/privilege/window.priority.set
+        /// </privilege>
+        /// /// <remarks>
+        /// This can be used for a notification type window only.
+        /// </remarks>
+        /// <since_tizen> preview </since_tizen>
+        public NotificationLevel NotificationLevel
+        {
+            get
+            {
+                int level;
+                Interop.Eutil.efl_util_get_notification_window_level(Handle, out level);
+                return (NotificationLevel)level;
+            }
+            set
+            {
+                Interop.Eutil.efl_util_set_notification_window_level(Handle, (int)value);
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets the window's screen mode.
+        /// This API is useful when the application need to keep the display turned on.
+        /// If the application set the mode to ScreenMode.AlwaysOn to its window and the window is shown wholly or partially,
+        /// the window manager requests the display system to keep the display on as long as the window is shown.
+        /// If the window is no longer shown, then the window manger request the display system to go back to normal operation.
+        /// Default screen mode of window is ScreenMode.Default.
+        /// </summary>
+        /// <privilege>
+        /// http://tizen.org/privilege/display
+        /// </privilege>
+        /// <remarks>
+        /// This needs the privilege. If the application which is not get the privilege use this API, the window manager generates the permission deny error.
+        /// </remarks>
+        /// <since_tizen> preview </since_tizen>
+        public ScreenMode ScreenMode
+        {
+            get
+            {
+                int mode;
+                Interop.Eutil.efl_util_get_window_screen_mode(Handle, out mode);
+                return (ScreenMode)mode;
+            }
+            set
+            {
+                Interop.Eutil.efl_util_set_window_screen_mode(Handle, (int)value);
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets the user's preferred brightness of the specified window.
+        /// This is useful when the application need to change the brightness of the screen when it is appeared on the screen.
+        /// If the application sets the brightness 0 to 100 to its window and the application window is shown wholly or partially,
+        /// the window manager requests the display system to change the brightness of the screen using user's preferred brightness.
+        /// If the window is no longer shown, then the window manger request the display system to go back to default brightness.
+        /// If the brightness is less than 0, this means to use the default screen brightness.
+        /// </summary>
+        /// <privilege>
+        /// http://tizen.org/privilege/display
+        /// </privilege>
+        /// <remarks>
+        /// This needs the privilege. If the application which is not get the privilege use this API, the window manager generates the permission deny error.
+        /// </remarks>
+        /// <since_tizen> preview </since_tizen>
+        public int Brightness
+        {
+            get
+            {
+                int brightness;
+                Interop.Eutil.efl_util_get_window_brightness(Handle, out brightness);
+                return brightness;
+            }
+            set
+            {
+                Interop.Eutil.efl_util_set_window_brightness(Handle, value);
+            }
+        }
+
+        /// <summary>
         /// Creates a socket to provide the service for the Plug widget.
         /// </summary>
         /// <param name="name">A service name.</param>
@@ -976,6 +1107,28 @@ namespace ElmSharp
         }
 
         /// <summary>
+        /// Sets the alpha window's visual state to opaque state.
+        /// This sets the alpha window's visual state to opaque state.
+        /// If the alpha window sets the visual state to the opaque,
+        /// then the window manager could handle it as the opaque window while calculating visibility.
+        /// This will have no effect when used by a non-alpha window.
+        /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        public void SetOpaqueState()
+        {
+            Interop.Eutil.efl_util_set_window_opaque_state(RealHandle, 1);
+        }
+
+        /// <summary>
+        /// Unsets the alpha window's visual state to opaque state.
+        /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        public void UnsetOpaqueState()
+        {
+            Interop.Eutil.efl_util_set_window_opaque_state(RealHandle, 0);
+        }
+
+        /// <summary>
         /// Sets the window to be skipped by focus.
         /// This sets the window to be skipped by normal input.
         /// This means the Windows Manager will be asked to not focus this window as well as omit it from things like the taskbar, pager etc.
diff --git a/src/ElmSharp/Interop/Interop.Eutil.WindowProperty.cs b/src/ElmSharp/Interop/Interop.Eutil.WindowProperty.cs
new file mode 100755 (executable)
index 0000000..912cd7f
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Eutil
+    {
+        [DllImport(Libraries.Eutil)]
+        internal static extern int efl_util_set_notification_window_level(IntPtr window, int level);
+
+        [DllImport(Libraries.Eutil)]
+        internal static extern int efl_util_get_notification_window_level(IntPtr window, out int level);
+
+        [DllImport(Libraries.Eutil)]
+        internal static extern int efl_util_set_window_opaque_state(IntPtr window, int opaque);
+
+        [DllImport(Libraries.Eutil)]
+        internal static extern int efl_util_set_window_screen_mode(IntPtr window, int mode);
+
+        [DllImport(Libraries.Eutil)]
+        internal static extern int efl_util_get_window_screen_mode(IntPtr window, out int mode);
+
+        [DllImport(Libraries.Eutil)]
+        internal static extern int efl_util_set_window_brightness(IntPtr window, int brightness);
+
+        [DllImport(Libraries.Eutil)]
+        internal static extern int efl_util_get_window_brightness(IntPtr window, out int brightness);
+    }
+}
\ No newline at end of file
index 7f1ca6a..559475a 100644 (file)
@@ -27,5 +27,6 @@ internal static partial class Interop
         internal const string EcoreInput = "libecore_input.so.1";
         internal const string Eo = "libeo.so.1";
         internal const string Eext = "libefl-extension.so.0";
+        internal const string Eutil = "libcapi-ui-efl-util.so.0";
     }
 }
diff --git a/test/ElmSharp.Test/TC/WindowUtilTest.cs b/test/ElmSharp.Test/TC/WindowUtilTest.cs
new file mode 100755 (executable)
index 0000000..4005a92
--- /dev/null
@@ -0,0 +1,167 @@
+using Tizen.Applications;
+/*
+ * 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;
+using System.IO;
+using ElmSharp;
+using System.Diagnostics;
+
+namespace ElmSharp.Test
+{
+    class WindowUtilTest : TestCaseBase
+    {
+        public override string TestName => "WindowUtilTest";
+        public override string TestDescription => "Window Util Test";
+
+        void DeleteWin(Window window)
+        {
+            window.Hide();
+            window.Unrealize();
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+        }
+
+        Window CreateWin(Window parent, WindowType type, bool whiteBg)
+        {
+            Window win = new Window(parent, "testwin", type);
+            win.Show();
+
+            win.BackButtonPressed += (s, e) =>
+            {
+                DeleteWin(win);
+            };
+
+            if (whiteBg)
+            {
+                Conformant conformant = new Conformant(win);
+                conformant.Show();
+                Box box = new Box(win)
+                {
+                    AlignmentX = -1,
+                    AlignmentY = -1,
+                    WeightX = 1,
+                    WeightY = 1,
+                };
+                box.Show();
+                var bg = new Background(win);
+                bg.Color = Color.White;
+                bg.SetContent(box);
+                conformant.SetContent(bg);
+            }
+
+            Button button = new Button(win)
+            {
+                Text = "Delete Window",                
+            };
+            button.Resize(win.ScreenSize.Width, 100);
+            button.Move(0, win.ScreenSize.Height - 105);
+            button.SetPartColor("bg", Color.Red);
+            button.Show();
+
+            button.Clicked += (e, o) =>
+            {
+                DeleteWin(win);
+            };
+
+            return win;
+        }
+
+        public override void Run(Window window)
+        {
+            int buttonW = window.ScreenSize.Width / 2 - 10;
+            int buttonH = 110;
+
+            Button button1 = new Button(window)
+            {
+                Text = "Brightness</br>30",
+            };
+            button1.Resize(buttonW, buttonH);
+            button1.Move(5, 5);
+            button1.Show();
+
+            button1.Clicked += (e, o) =>
+            {
+                window.Brightness = 30;
+            };
+
+            Button button2 = new Button(window)
+            {
+                Text = "Brightness</br>Default",
+            };
+            button2.Resize(buttonW, buttonH);
+            button2.Move(buttonW + 15, 5);
+            button2.Show();
+
+            button2.Clicked += (e, o) =>
+            {
+                window.Brightness = -1;
+            };
+
+            Button button3 = new Button(window)
+            {
+                Text = "ScreenMode</br>AlwaysOn",
+            };
+            button3.Resize(buttonW, buttonH);
+            button3.Move(5, buttonH + 15);
+            button3.Show();
+
+            button3.Clicked += (e, o) =>
+            {
+                window.ScreenMode = ScreenMode.AlwaysOn;
+            };
+
+            Button button4 = new Button(window)
+            {
+                Text = "ScreenMode</br>Default",
+            };
+            button4.Resize(buttonW, buttonH);
+            button4.Move(buttonW + 15, buttonH + 15);
+            button4.Show();
+
+            button4.Clicked += (e, o) =>
+            {
+                window.ScreenMode = ScreenMode.Default;
+            };
+
+            Button button5 = new Button(window)
+            {
+                Text = "Window Notification Level</br>Top",
+            };
+            button5.Resize(window.ScreenSize.Width - 10, buttonH);
+            button5.Move(5, (buttonH +10)* 2 + 5);
+            button5.Show();
+
+            button5.Clicked += (e, o) =>
+            {
+                Window win = CreateWin(window, WindowType.Notification, true);
+
+                Console.WriteLine("Notifiaction Level : {0}", win.NotificationLevel);
+                win.NotificationLevel = NotificationLevel.Top;
+                Console.WriteLine("Notifiaction Level : {0}", win.NotificationLevel);
+
+                Label label = new Label(win)
+                {
+                    Text = string.Format("This Notification Window Level : {0}", win.NotificationLevel),
+                    Color = Color.White,
+                };
+                label.Resize(window.ScreenSize.Width, 100);
+                label.Move(0, 100);
+                label.Show();
+            };
+        }
+    }
+}
index bf61e8a..421f843 100755 (executable)
@@ -8,5 +8,7 @@
     <shortcut-list />
     <privileges>
         <privilege>http://tizen.org/privilege/internet</privilege>
+        <privilege>http://tizen.org/privilege/display</privilege>
+        <privilege>http://tizen.org/privilege/window.priority.set</privilege>
     </privileges>
 </manifest>