[NUI] Add BackgroundResourceLoaded,ResourceLoaded events as internal API (#499)
authordongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 4 Oct 2018 01:51:46 +0000 (10:51 +0900)
committerGitHub <noreply@github.com>
Thu, 4 Oct 2018 01:51:46 +0000 (10:51 +0900)
src/Tizen.NUI/src/public/BaseComponents/ImageView.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs

index 6c74588..22f4e12 100755 (executable)
@@ -737,6 +737,69 @@ namespace Tizen.NUI.BaseComponents
         private bool? _borderOnly = null;
         private string _url = null;
         private bool? _orientationCorrection = null;
+
+
+        internal class ResourceLoadedEventArgs : EventArgs
+        {
+            private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
+            public ResourceLoadingStatusType Status
+            {
+                get
+                {
+                    return status;
+                }
+                set
+                {
+                    status = value;
+                }
+            }
+        }
+
+        private EventHandler<ResourceLoadedEventArgs> _resourceLoadedEventHandler;
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void _resourceLoadedCallbackType(IntPtr view);
+        private _resourceLoadedCallbackType _resourceLoadedCallback;
+
+        internal event EventHandler<ResourceLoadedEventArgs> ResourceLoaded
+        {
+            add
+            {
+                if (_resourceLoadedEventHandler == null)
+                {
+                    _resourceLoadedCallback = OnResourceLoaded;
+                    this.ResourceReadySignal(this).Connect(_resourceLoadedCallback);
+                }
+
+                _resourceLoadedEventHandler += value;
+            }
+            remove
+            {
+                _resourceLoadedEventHandler -= value;
+
+                if (_resourceLoadedEventHandler == null && this.ResourceReadySignal(this).Empty() == false)
+                {
+                    this.ResourceReadySignal(this).Disconnect(_resourceLoadedCallback);
+                }
+            }
+        }
+
+        private void OnResourceLoaded(IntPtr view)
+        {
+            ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
+            e.Status = (ResourceLoadingStatusType)NDalicManualPINVOKE.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
+
+            if (_resourceLoadedEventHandler != null)
+            {
+                _resourceLoadedEventHandler(this, e);
+            }
+        }
+
+        internal ResourceLoadingStatusType GetResourceStatus()
+        {
+            return (ResourceLoadingStatusType)NDalicManualPINVOKE.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
+        }
+
+
     }
 
 }
index c95100e..73b68b4 100755 (executable)
@@ -1563,6 +1563,11 @@ namespace Tizen.NUI.BaseComponents
                 this.KeyInputFocusGainedSignal().Disconnect(_keyInputFocusGainedCallback);
             }
 
+            if (_backgroundResourceLoadedCallback != null)
+            {
+                this.ResourcesLoadedSignal().Disconnect(_backgroundResourceLoadedCallback);
+            }
+
             // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
             // Restore current CPtr.
             swigCPtr = currentCPtr;
@@ -5566,6 +5571,67 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        internal class BackgroundResourceLoadedEventArgs : EventArgs
+        {
+            private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
+            public ResourceLoadingStatusType Status
+            {
+                get
+                {
+                    return status;
+                }
+                set
+                {
+                    status = value;
+                }
+            }
+        }
+
+        private EventHandler<BackgroundResourceLoadedEventArgs> _backgroundResourceLoadedEventHandler;
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void _backgroundResourceLoadedCallbackType(IntPtr view);
+        private _backgroundResourceLoadedCallbackType _backgroundResourceLoadedCallback;
+
+        internal event EventHandler<BackgroundResourceLoadedEventArgs> BackgroundResourceLoaded
+        {
+            add
+            {
+                if (_backgroundResourceLoadedEventHandler == null)
+                {
+                    _backgroundResourceLoadedCallback = OnBackgroundResourceLoaded;
+                    this.ResourcesLoadedSignal().Connect(_backgroundResourceLoadedCallback);
+                }
+
+                _backgroundResourceLoadedEventHandler += value;
+            }
+            remove
+            {
+                _backgroundResourceLoadedEventHandler -= value;
+
+                if (_backgroundResourceLoadedEventHandler == null && ResourcesLoadedSignal().Empty() == false)
+                {
+                    this.ResourcesLoadedSignal().Disconnect(_backgroundResourceLoadedCallback);
+                }
+            }
+        }
+
+        private void OnBackgroundResourceLoaded(IntPtr view)
+        {
+            BackgroundResourceLoadedEventArgs e = new BackgroundResourceLoadedEventArgs();
+            e.Status = (ResourceLoadingStatusType)NDalicManualPINVOKE.View_GetVisualResourceStatus(this.swigCPtr, Property.BACKGROUND);
+            
+            if (_backgroundResourceLoadedEventHandler != null)
+            {
+                _backgroundResourceLoadedEventHandler(this, e);
+            }
+        }
+
+        internal ResourceLoadingStatusType GetBackgroundResourceStatus()
+        {
+            return (ResourceLoadingStatusType)NDalicManualPINVOKE.View_GetVisualResourceStatus(this.swigCPtr, Property.BACKGROUND);
+        }
+
+
     }
 
     /// <summary>
@@ -5598,4 +5664,12 @@ namespace Tizen.NUI.BaseComponents
         WrapContent = -2,
     }
 
+    internal enum ResourceLoadingStatusType
+    {
+        Invalid = -1,
+        Preparing = 0,
+        Ready,
+        Failed,
+    }
+
 }