From a28f8095a15c9336da24584415ef5368abcb3598 Mon Sep 17 00:00:00 2001 From: dongsug-song <35130733+dongsug-song@users.noreply.github.com> Date: Thu, 4 Oct 2018 10:51:46 +0900 Subject: [PATCH] [NUI] Add BackgroundResourceLoaded,ResourceLoaded events as internal API (#499) --- .../src/public/BaseComponents/ImageView.cs | 63 ++++++++++++++++++ src/Tizen.NUI/src/public/BaseComponents/View.cs | 74 ++++++++++++++++++++++ 2 files changed, 137 insertions(+) diff --git a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs index 6c74588..22f4e12 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs @@ -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 _resourceLoadedEventHandler; + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void _resourceLoadedCallbackType(IntPtr view); + private _resourceLoadedCallbackType _resourceLoadedCallback; + + internal event EventHandler 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); + } + + } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index c95100e..73b68b4 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -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 _backgroundResourceLoadedEventHandler; + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void _backgroundResourceLoadedCallbackType(IntPtr view); + private _backgroundResourceLoadedCallbackType _backgroundResourceLoadedCallback; + + internal event EventHandler 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); + } + + } /// @@ -5598,4 +5664,12 @@ namespace Tizen.NUI.BaseComponents WrapContent = -2, } + internal enum ResourceLoadingStatusType + { + Invalid = -1, + Preparing = 0, + Ready, + Failed, + } + } -- 2.7.4