[Attach panel] Initial implement C# attach-panel API
authormoon87.park <moon87.park@samsung.com>
Tue, 25 Apr 2017 06:28:41 +0000 (15:28 +0900)
committermoon87.park <moon87.park@samsung.com>
Tue, 25 Apr 2017 10:24:30 +0000 (19:24 +0900)
Change-Id: I84587c7545c813fe5b8b4255ba2601b6b775359a

12 files changed:
src/Tizen.Applications.AttachPanel/Interop/Interop.AttachPanel.cs
src/Tizen.Applications.AttachPanel/Interop/Interop.Libraries.cs
src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel.csproj
src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel.project.lock.json
src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/AttachPanel.cs [new file with mode: 0755]
src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/AttachPanelManager.cs [new file with mode: 0755]
src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/ContentCategory.cs [new file with mode: 0755]
src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/EventType.cs [new file with mode: 0755]
src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/ResultEventArgs.cs [new file with mode: 0755]
src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/StateEventArgs.cs [new file with mode: 0755]
src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/StateType.cs [new file with mode: 0755]
src/Tizen.Applications.AttachPanel/Tizen.Applications/Tizen.Applications.AttachPanel.cs [deleted file]

index 6d746fe..3718191 100755 (executable)
@@ -1,6 +1,6 @@
 using System;
 using System.Runtime.InteropServices;
-using Tizen;
+using Tizen.Applications;
 
 internal static partial class Interop
 {
@@ -12,8 +12,17 @@ internal static partial class Interop
             InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
             OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
             PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
+            AlreadyExists = -0x02850000 | 0x01,
+            NotInitialized = -0x02850000 | 0x02,
+            UnsupportedContentCategory = -0x02850000 | 0x03,
+            AlreadyDestroyed = -0x02850000 | 0x05,
         }
 
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void AttachPanelEventCallback(IntPtr attachPanel, int eventType, IntPtr eventInfo, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void AttachPanelResultCallback(IntPtr attachPanel, int category, IntPtr result, int resultCode, IntPtr userData);
+
         [DllImport(Libraries.AttachPanel, EntryPoint = "attach_panel_create")]
         internal static extern ErrorCode CreateAttachPanel(IntPtr conform, ref IntPtr attach_panel);
 
@@ -30,13 +39,13 @@ internal static partial class Interop
         internal static extern ErrorCode SetExtraData(IntPtr attach_panel, int content_category, IntPtr extraData);
 
         [DllImport(Libraries.AttachPanel, EntryPoint = "attach_panel_set_result_cb")]
-        internal static extern ErrorCode SetResultCb(IntPtr attach_panel, IntPtr result_cb, IntPtr userData);
+        internal static extern ErrorCode SetResultCb(IntPtr attach_panel, AttachPanelResultCallback callback, IntPtr userData);
 
         [DllImport(Libraries.AttachPanel, EntryPoint = "attach_panel_unset_result_cb")]
         internal static extern ErrorCode UnsetResultCb(IntPtr attach_panel);
 
         [DllImport(Libraries.AttachPanel, EntryPoint = "attach_panel_set_event_cb")]
-        internal static extern ErrorCode SetEventCb(IntPtr attach_panel, IntPtr event_cb, IntPtr userData);
+        internal static extern ErrorCode SetEventCb(IntPtr attach_panel, AttachPanelEventCallback callback, IntPtr userData);
 
         [DllImport(Libraries.AttachPanel, EntryPoint = "attach_panel_unset_event_cb")]
         internal static extern ErrorCode UnsetEventCb(IntPtr attach_panel);
index 7e83aa4..4b4049b 100755 (executable)
@@ -2,6 +2,6 @@ internal static partial class Interop
 {
     internal static partial class Libraries
     {
-        public const string AttachPanel = "libattach-panel.so.0";
+        public const string AttachPanel = "libattach-panel.so.0.1.0";
     }
-}
\ No newline at end of file
+}
index d9bd227..c875bba 100755 (executable)
   <ItemGroup>
     <Compile Include="Interop\Interop.AttachPanel.cs" />
     <Compile Include="Interop\Interop.Libraries.cs" />
-    <Compile Include="Tizen.Applications\Tizen.Applications.AttachPanel.cs" />
+    <Compile Include="Tizen.Applications.AttachPanel\AttachPanelManager.cs" />
+    <Compile Include="Tizen.Applications.AttachPanel\ContentCategory.cs" />
+    <Compile Include="Tizen.Applications.AttachPanel\StateEventArgs.cs" />
+    <Compile Include="Tizen.Applications.AttachPanel\EventType.cs" />
+    <Compile Include="Tizen.Applications.AttachPanel\ResultEventArgs.cs" />
+    <Compile Include="Tizen.Applications.AttachPanel\StateType.cs" />
+    <Compile Include="Tizen.Applications.AttachPanel\AttachPanel.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
-  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
                Other similar extension points exist, see Microsoft.Common.targets.
@@ -82,4 +87,4 @@
       </FlavorProperties>
     </VisualStudio>
   </ProjectExtensions>
-</Project>
+</Project>
\ No newline at end of file
index afdc02e..94bfec1 100755 (executable)
@@ -2,7 +2,7 @@
   "version": 2,
   "targets": {
     ".NETStandard,Version=v1.3": {
-      "ElmSharp/1.1.0-beta-019": {
+      "ElmSharp/1.1.0-beta-021": {
         "type": "package",
         "compile": {
           "lib/netstandard1.3/ElmSharp.dll": {}
     }
   },
   "libraries": {
-    "ElmSharp/1.1.0-beta-019": {
-      "sha512": "BF+yQuSG0Ct5QiLt0Awtll5GR5DSpzvDj18NpfIvPqDE0mGMtcvtdF0qlBAmM5gh/VDhBawzWDhE39mf6JuH8g==",
+    "ElmSharp/1.1.0-beta-021": {
+      "sha512": "zve6PlIdClYdwWKmuXAtcoMBHMd9J0KYbtIeTvwrXGVge68NP1Kz9D4xkAB3MQL50cGH0Xl1Y7ddOQ2DfuWs5A==",
       "type": "package",
-      "path": "elmsharp/1.1.0-beta-019",
+      "path": "elmsharp/1.1.0-beta-021",
       "files": [
-        "elmsharp.1.1.0-beta-019.nupkg.sha512",
+        "elmsharp.1.1.0-beta-021.nupkg.sha512",
         "elmsharp.nuspec",
-        "lib/netstandard1.3/ElmSharp.dll"
+        "lib/netstandard1.3/ElmSharp.dll",
+        "lib/netstandard1.3/ElmSharp.xml"
       ]
     },
     "Microsoft.NETCore.Platforms/1.0.1": {
diff --git a/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/AttachPanel.cs b/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/AttachPanel.cs
new file mode 100755 (executable)
index 0000000..899c913
--- /dev/null
@@ -0,0 +1,173 @@
+using System;
+
+namespace Tizen.Applications.AttachPanel
+{
+    public partial class AttachPanel
+    {
+        private const string LogTag = "Tizen.Applications.AttachPanel";
+
+        private static IntPtr _attachPanel;
+
+        private static event EventHandler<StateEventArgs> _eventEventHandler;
+        private static event EventHandler<ResultEventArgs> _resultEventHandler;
+
+        private static Interop.AttachPanel.AttachPanelEventCallback SetEventListener;
+        private static Interop.AttachPanel.AttachPanelResultCallback SetResultListener;
+
+        public AttachPanel(IntPtr conformant)
+        {
+            _attachPanel = new IntPtr();
+            Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.CreateAttachPanel(conformant, ref _attachPanel);
+            checkException(err);
+
+            if (_eventEventHandler == null)
+            {
+                StateEventListenStart();
+            }
+
+            if (_resultEventHandler == null)
+            {
+                ResultEventListenStart();
+            }
+        }
+
+        ~AttachPanel()
+        {
+            if (_attachPanel != IntPtr.Zero)
+            {
+                Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.DestroyAttachPanel(_attachPanel);
+                checkException(err);
+                _attachPanel = IntPtr.Zero;
+            }
+        }
+
+        public int State
+        {
+            get
+            {
+                int state;
+                Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.GetState(_attachPanel, out state);
+                checkException(err);
+                return state;
+            }
+        }
+        public int Visible
+        {
+            get
+            {
+                int visible;
+                Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.GetVisibility(_attachPanel, out visible);
+                checkException(err);
+                return visible;
+            }
+        }
+
+        public void AddCategory(ContentCategory category, Bundle extraData)
+        {
+            IntPtr bundle = IntPtr.Zero;
+            if (extraData != null)
+            {
+                bundle = extraData.SafeBundleHandle.DangerousGetHandle();
+            }
+            Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.AddCategory(_attachPanel, (int)category, bundle);
+            checkException(err);
+        }
+
+        public void RemoveCategory(ContentCategory category)
+        {
+            Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.RemoveCategory(_attachPanel, (int)category);
+            checkException(err);
+        }
+
+        public void SetExtraData(ContentCategory category, Bundle extraData)
+        {
+            IntPtr bundle = IntPtr.Zero;
+            if (extraData != null)
+            {
+                bundle = extraData.SafeBundleHandle.DangerousGetHandle();
+            }
+            Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.SetExtraData(_attachPanel, (int)category, bundle);
+            checkException(err);
+        }
+
+        public void Show()
+        {
+            Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Show(_attachPanel);
+            checkException(err);
+        }
+
+        public void Show(bool animation)
+        {
+            if (animation)
+            {
+                Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Show(_attachPanel);
+                checkException(err);
+            }
+            else
+            {
+                Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.ShowWithoutAnimation(_attachPanel);
+                checkException(err);
+            }
+        }
+
+        public void Hide()
+        {
+            Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Hide(_attachPanel);
+            checkException(err);
+        }
+
+        public void Hide(bool animation)
+        {
+            if (animation)
+            {
+                Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Hide(_attachPanel);
+                checkException(err);
+            }
+            else
+            {
+                Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.HideWithoutAnimation(_attachPanel);
+                checkException(err);
+            }
+        }
+
+        public event EventHandler<StateEventArgs> EventChanged
+        {
+            add
+            {
+                if (_eventEventHandler == null)
+                {
+                    StateEventListenStart();
+                }
+                _eventEventHandler += value;
+            }
+            remove
+            {
+                _eventEventHandler -= value;
+                if (_eventEventHandler == null)
+                {
+                    StateEventListenStop();
+                }
+            }
+        }
+
+        public event EventHandler<ResultEventArgs> ResultCallback
+        {
+            add
+            {
+                if (_resultEventHandler == null)
+                {
+                    ResultEventListenStart();
+                }
+                _resultEventHandler += value;
+            }
+            remove
+            {
+                _resultEventHandler -= value;
+                if (_resultEventHandler == null)
+                {
+                    ResultEventListenStop();
+                }
+            }
+        }
+    }
+}
diff --git a/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/AttachPanelManager.cs b/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/AttachPanelManager.cs
new file mode 100755 (executable)
index 0000000..e11dc0e
--- /dev/null
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+
+namespace Tizen.Applications.AttachPanel
+{
+    public partial class AttachPanel
+    {
+        private void StateEventListenStart()
+        {
+            Interop.AttachPanel.ErrorCode err = 0;
+
+            SetEventListener = (attachPanel, eventType, eventInfo, userData) =>
+            {
+                _eventEventHandler?.Invoke(null, new StateEventArgs(attachPanel, (EventType)eventType, eventInfo, userData));
+            };
+            err = Interop.AttachPanel.SetEventCb(_attachPanel, SetEventListener, IntPtr.Zero);
+            checkException(err);
+        }
+        private void StateEventListenStop()
+        {
+            Interop.AttachPanel.ErrorCode err = 0;
+            err =  Interop.AttachPanel.UnsetEventCb(_attachPanel);
+            checkException(err);
+        }
+
+        private void ResultEventListenStart()
+        {
+            Interop.AttachPanel.ErrorCode err = 0;
+            SetResultListener = (attachPanel, category, resulthandler, resultCode, userData) =>
+            {
+                SafeAppControlHandle handle = new SafeAppControlHandle(resulthandler, false);
+                AppControl result = new AppControl(handle);
+                _resultEventHandler?.Invoke(null, new ResultEventArgs(attachPanel, (ContentCategory)category, result, (AppControlReplyResult)resultCode, userData));
+            };
+            err = Interop.AttachPanel.SetResultCb(_attachPanel, SetResultListener, IntPtr.Zero);
+            checkException(err);
+        }
+
+        private void ResultEventListenStop()
+        {
+            Interop.AttachPanel.ErrorCode err = 0;
+            err = Interop.AttachPanel.UnsetResultCb(_attachPanel);
+            checkException(err);
+        }
+
+        internal static void checkException(Interop.AttachPanel.ErrorCode err)
+        {
+            switch (err)
+            {
+                case Interop.AttachPanel.ErrorCode.InvalidParameter:
+                    throw new InvalidOperationException("Invalid parameter error at unmanaged code");
+                case Interop.AttachPanel.ErrorCode.OutOfMemory:
+                    throw new InvalidOperationException("Out of Memory");
+                case Interop.AttachPanel.ErrorCode.PermissionDenied:
+                    throw new UnauthorizedAccessException();
+                case Interop.AttachPanel.ErrorCode.AlreadyExists:
+                    throw new InvalidOperationException("Already Exists");
+                case Interop.AttachPanel.ErrorCode.NotInitialized:
+                    throw new InvalidOperationException("Not initialized");
+                case Interop.AttachPanel.ErrorCode.UnsupportedContentCategory:
+                    throw new InvalidOperationException("Unsupported Content Category");
+                case Interop.AttachPanel.ErrorCode.AlreadyDestroyed:
+                    throw new InvalidOperationException("Already Destroyed");
+            }
+        }
+    }
+}
diff --git a/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/ContentCategory.cs b/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/ContentCategory.cs
new file mode 100755 (executable)
index 0000000..e86b9ea
--- /dev/null
@@ -0,0 +1,57 @@
+namespace Tizen.Applications.AttachPanel
+{
+    /// <summary>
+    /// Enumeration for the attach panel content category.
+    /// </summary>
+    public enum ContentCategory
+    {
+        /// <summary>
+        /// Attaching images from the gallery
+        /// </summary>
+        Image = 1,
+        /// <summary>
+        /// Taking pictures to attach
+        /// </summary>
+        Camera,
+        /// <summary>
+        /// Taking a voice clip to attach
+        /// </summary>
+        Voice,
+        /// <summary>
+        /// Attaching video from the gallery
+        /// </summary>
+        Video,
+        /// <summary>
+        /// Attaching audio from my files
+        /// </summary>
+        Audio,
+        /// <summary>
+        /// Attaching calendar data from the calendar
+        /// </summary>
+        Calendar,
+        /// <summary>
+        /// Attaching contact data from the contacts
+        /// </summary>
+        Contact,
+        /// <summary>
+        /// Attaching files data from my files
+        /// </summary>
+        Myfiles,
+        /// <summary>
+        /// Taking a video clip to attach
+        /// </summary>
+        VideoRecorder,
+        /// <summary>
+        /// Attaching files from the document list
+        /// </summary>
+        Document,
+        /// <summary>
+        /// Launching apps to take pictures will be attached
+        /// </summary>
+        TakePicture,
+        /// <summary>
+        /// Attaching memo data from the memo
+        /// </summary>
+        Memo,
+    }
+}
diff --git a/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/EventType.cs b/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/EventType.cs
new file mode 100755 (executable)
index 0000000..dc460a1
--- /dev/null
@@ -0,0 +1,25 @@
+namespace Tizen.Applications.AttachPanel
+{
+    /// <summary>
+    /// Enumeration for the attach panel event.
+    /// </summary>
+    public enum EventType
+    {
+        /// <summary>
+        /// Attach panel starts the effect to show
+        /// </summary>
+        ShowStart = 1,
+        /// <summary>
+        /// Attach panel finishes the effect to show
+        /// </summary>
+        ShowFinish,
+        /// <summary>
+        /// Attach panel starts the effect to hide the panel
+        /// </summary>
+        HideStart,
+        /// <summary>
+        /// Attach panel finishes the effect to hide the panel
+        /// </summary>
+        HideFinish,
+    }
+}
diff --git a/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/ResultEventArgs.cs b/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/ResultEventArgs.cs
new file mode 100755 (executable)
index 0000000..70371c7
--- /dev/null
@@ -0,0 +1,32 @@
+using System;
+
+namespace Tizen.Applications.AttachPanel
+{
+    public class ResultEventArgs : EventArgs
+    {
+        private readonly IntPtr _attachPanel;
+        private readonly ContentCategory _category;
+        private readonly AppControl _result;
+        private readonly AppControlReplyResult _resultCode;
+        private readonly IntPtr _userData;
+
+        internal ResultEventArgs(IntPtr attachPanel, ContentCategory category, AppControl result, AppControlReplyResult resultCode, IntPtr userData)
+        {
+            _attachPanel = attachPanel;
+            _category = category;
+            _result = result;
+            _resultCode = resultCode;
+            _userData = userData;
+        }
+
+        public IntPtr AttachPanel { get { return _attachPanel; } }
+
+        public ContentCategory Category { get { return _category; } }
+
+        public AppControl Result {  get { return _result; } }
+
+        public AppControlReplyResult ResultCode { get { return _resultCode; } }
+
+        public IntPtr UserData { get { return _userData; } }
+    }
+}
diff --git a/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/StateEventArgs.cs b/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/StateEventArgs.cs
new file mode 100755 (executable)
index 0000000..5314225
--- /dev/null
@@ -0,0 +1,28 @@
+using System;
+
+namespace Tizen.Applications.AttachPanel
+{
+    public class StateEventArgs : EventArgs
+    {
+        private readonly IntPtr _attachPanel;
+        private readonly EventType _eventType;
+        private readonly IntPtr _eventInfo;
+        private readonly IntPtr _userData;
+
+        internal StateEventArgs(IntPtr attachPanel, EventType eventType, IntPtr eventInfo, IntPtr userData)
+        {
+            _attachPanel = attachPanel;
+            _eventType = eventType;
+            _eventInfo = eventInfo;
+            _userData = userData;
+        }
+
+        public IntPtr AttachPanel { get { return _attachPanel;  } }
+
+        public EventType EventType { get { return _eventType;  } }
+
+        public IntPtr EventInfo {  get { return _eventInfo;  } }
+
+        public IntPtr UserData { get { return _userData; } }
+    }
+}
diff --git a/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/StateType.cs b/src/Tizen.Applications.AttachPanel/Tizen.Applications.AttachPanel/StateType.cs
new file mode 100755 (executable)
index 0000000..a2474db
--- /dev/null
@@ -0,0 +1,21 @@
+namespace Tizen.Applications.AttachPanel
+{
+    /// <summary>
+    /// Enumeration for the attach panel's window state.
+    /// </summary>
+    public enum StateType
+    {
+        /// <summary>
+        /// Attach panel is not visible
+        /// </summary>
+        Hidden = 0,
+        /// <summary>
+        /// Attach panel is in partial window mode
+        /// </summary>
+        Partial,
+        /// <summary>
+        /// Attach panel is in full screen mode
+        /// </summary>
+        Full,
+    }
+}
\ No newline at end of file
diff --git a/src/Tizen.Applications.AttachPanel/Tizen.Applications/Tizen.Applications.AttachPanel.cs b/src/Tizen.Applications.AttachPanel/Tizen.Applications/Tizen.Applications.AttachPanel.cs
deleted file mode 100755 (executable)
index d3bde58..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-using System;
-
-namespace Tizen.Applications
-{
-    public class AttachPanel
-    {
-        IntPtr attachpanel;
-
-        public AttachPanel(IntPtr conformant)
-        {
-            attachpanel = new IntPtr();
-            Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.CreateAttachPanel(conformant, ref attachpanel);
-            checkException(err);
-        }
-
-        public int State
-        {
-            get
-            {
-                int state;
-                Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.GetState(attachpanel, out state);
-                checkException(err);
-                return state;
-            }
-        }
-        public int Visible
-        {
-            get
-            {
-                int visible;
-                Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.GetVisibility(attachpanel, out visible);
-                checkException(err);
-                return visible;
-            }
-        }
-        internal static void checkException(Interop.AttachPanel.ErrorCode err)
-        {
-            switch (err)
-            {
-                case Interop.AttachPanel.ErrorCode.InvalidParameter:
-                    throw new InvalidOperationException("Invalid parameter error at unmanaged code");
-                case Interop.AttachPanel.ErrorCode.OutOfMemory:
-                    throw new InvalidOperationException("Out of Memory");
-                case Interop.AttachPanel.ErrorCode.PermissionDenied:
-                    throw new UnauthorizedAccessException();
-            }
-        }
-    }
-}