From 5283db6cc2bdedc66e31b356d1c2101c9f76bd6b Mon Sep 17 00:00:00 2001 From: sunghyun kim Date: Thu, 25 Jul 2024 14:35:19 +0900 Subject: [PATCH] Refactoring OnInitialize OnInitialize() is too long. so i seperated this function. Change-Id: I3ed9cf2bcc37a675e998bb9c00ca02b22460a62b --- .../internal/widget_view/widget_view_impl.cpp | 239 ++++++++++-------- .../internal/widget_view/widget_view_impl.h | 25 ++ 2 files changed, 157 insertions(+), 107 deletions(-) diff --git a/widget_viewer_dali/internal/widget_view/widget_view_impl.cpp b/widget_viewer_dali/internal/widget_view/widget_view_impl.cpp index 438ecf8..fa57bf2 100644 --- a/widget_viewer_dali/internal/widget_view/widget_view_impl.cpp +++ b/widget_viewer_dali/internal/widget_view/widget_view_impl.cpp @@ -274,6 +274,135 @@ WidgetView::~WidgetView() { } +void WidgetView::InitializeWidgets() +{ + auto self = Self(); + char* instanceId = NULL; + + int ret = widget_instance_create( mWidgetId.c_str(), &instanceId ); + if( ret < 0 || !instanceId ) + { + DALI_LOG_ERROR("WidgetView::InitializeWidgets: widget_instance_create is failed [%s].\n", mWidgetId.c_str() ); + return; + } + + DALI_LOG_RELEASE_INFO("WidgetView::InitializeWidgets: widget_instance_create is called. [widget id = %s, instance id = %s] [%p]\n", + mWidgetId.c_str(), instanceId, this ); + + mInstanceId = instanceId; + + SetUpdatePeriod(); + SetPreviewImage(); +} + +void WidgetView::SetUpdatePeriod() +{ + // Set UpdatePeriod + if( mUpdatePeriod > 0.0f) + { + widget_instance_h instance = widget_instance_get_instance( mWidgetId.c_str(), mInstanceId.c_str() ); + if( !instance ) + { + DALI_LOG_ERROR("WidgetView::SetUpdatePeriod: widget_instance_get_instance is failed. [%s]\n", mInstanceId.c_str() ); + return; + } + + int ret = widget_instance_set_period( instance, mUpdatePeriod ); + widget_instance_unref(instance); + if( ret < 0 ) + { + DALI_LOG_ERROR("WidgetView::SetUpdatePeriod: widget_instance_set_period is failed [%s].\n", mWidgetId.c_str() ); + return; + } + } +} + +void WidgetView::SetPreviewImage() +{ + auto self = Self(); + char* previewPath = NULL; + std::string previewImage; + widget_size_type_e sizeType; + + // Preview image + widget_service_get_size_type( mWidgetWidth, mWidgetHeight, &sizeType ); + + previewPath = widget_service_get_preview_image_path( mWidgetId.c_str(), sizeType ); + if( previewPath ) + { + previewImage = previewPath; + free( previewPath ); + } + else + { + previewImage = WIDGET_VIEW_RESOURCE_DEFAULT_IMG; + } + + DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::SetPreviewImage: preview image path = %s [%p]\n", previewImage.c_str(), this ); + + mPreviewActor = Dali::Actor::New(); + mPreviewActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mPreviewActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mPreviewActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + + mPreviewImage = Toolkit::ImageView::New( previewImage ); + mPreviewImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mPreviewImage.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mPreviewImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + + self.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); + self.SetProperty( Actor::Property::SIZE, Vector2(mWidgetWidth, mWidgetHeight)); + + self.Add( mPreviewActor ); + mPreviewActor.Add( mPreviewImage ); +} + +void WidgetView::InitializeLayout() +{ + mStateTextActor = Dali::Actor::New(); + mStateTextActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mStateTextActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mStateTextActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + + // Loading text + mLoadingText = Toolkit::TextLabel::New( ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString ); + mLoadingText.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mLoadingText.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mLoadingText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); + mLoadingText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE ); + mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" ); + mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) ); + + mPreviewActor.Add( mStateTextActor ); + mStateTextActor.Add( mLoadingText ); + + // Retry text + mRetryText = Toolkit::TextLabel::New( ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString ); + mRetryText.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mRetryText.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mRetryText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); + mRetryText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE ); + mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" ); + mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) ); + + mStateTextActor.Add( mRetryText ); + mRetryText.SetProperty( Actor::Property::VISIBLE, false ); + +} + +void WidgetView::InitializeEvents() +{ + auto self = Self(); + self.TouchedSignal().Connect( this, &WidgetView::OnTouch ); + self.WheelEventSignal().Connect( this, &WidgetView::OnWheelEvent ); + + // Accessibility + self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::FILLER); + self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false); +} + bool WidgetView::PauseWidget() { mPausedManually = true; @@ -985,114 +1114,10 @@ Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetTerminated void WidgetView::OnInitialize() { - auto self = Self(); - char* instanceId = NULL; - char* previewPath = NULL; - std::string previewImage; - widget_size_type_e sizeType; - - int ret = widget_instance_create( mWidgetId.c_str(), &instanceId ); - if( ret < 0 || !instanceId ) - { - DALI_LOG_ERROR("WidgetView::OnInitialize: widget_instance_create is failed [%s].\n", mWidgetId.c_str() ); - return; - } - - DALI_LOG_RELEASE_INFO("WidgetView::OnInitialize: widget_instance_create is called. [widget id = %s, instance id = %s] [%p]\n", - mWidgetId.c_str(), instanceId, this ); - - mInstanceId = instanceId; - - // Set UpdatePeriod - if( mUpdatePeriod > 0.0f) - { - widget_instance_h instance = widget_instance_get_instance( mWidgetId.c_str(), mInstanceId.c_str() ); - if( !instance ) - { - DALI_LOG_ERROR("WidgetView::OnInitialize: widget_instance_get_instance is failed. [%s]\n", mInstanceId.c_str() ); - return; - } - ret = widget_instance_set_period( instance, mUpdatePeriod ); - widget_instance_unref(instance); - if( ret < 0 ) - { - DALI_LOG_ERROR("WidgetView::OnInitialize: widget_instance_set_period is failed [%s].\n", mWidgetId.c_str() ); - return; - } - } - - // Preview image - widget_service_get_size_type( mWidgetWidth, mWidgetHeight, &sizeType ); - - previewPath = widget_service_get_preview_image_path( mWidgetId.c_str(), sizeType ); - if( previewPath ) - { - previewImage = previewPath; - free( previewPath ); - } - else - { - previewImage = WIDGET_VIEW_RESOURCE_DEFAULT_IMG; - } - - DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: preview image path = %s [%p]\n", previewImage.c_str(), this ); - - - mPreviewActor = Dali::Actor::New(); - mPreviewActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mPreviewActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mPreviewActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - - mPreviewImage = Toolkit::ImageView::New( previewImage ); - mPreviewImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mPreviewImage.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mPreviewImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - - self.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - self.SetProperty( Actor::Property::SIZE, Vector2(mWidgetWidth, mWidgetHeight)); - - self.Add( mPreviewActor ); - mPreviewActor.Add( mPreviewImage ); - - mStateTextActor = Dali::Actor::New(); - mStateTextActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mStateTextActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mStateTextActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - - // Loading text - mLoadingText = Toolkit::TextLabel::New( ( mLoadingTextString.empty() )? GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) : mLoadingTextString ); - mLoadingText.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLoadingText.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLoadingText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mLoadingText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mLoadingText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE ); - mLoadingText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" ); - mLoadingText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) ); - - mPreviewActor.Add( mStateTextActor ); - mStateTextActor.Add( mLoadingText ); - - // Retry text - mRetryText = Toolkit::TextLabel::New( ( mRetryTextString.empty() )? GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) : mRetryTextString ); - mRetryText.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mRetryText.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mRetryText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mRetryText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mRetryText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE ); - mRetryText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" ); - mRetryText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, TextPixelToPointSize( DEFAULT_FONT_PIXEL_SIZE ) ); - - mStateTextActor.Add( mRetryText ); - mRetryText.SetProperty( Actor::Property::VISIBLE, false ); - - // launch widget + InitializeWidgets(); + InitializeLayout(); LaunchWidget(); - self.TouchedSignal().Connect( this, &WidgetView::OnTouch ); - self.WheelEventSignal().Connect( this, &WidgetView::OnWheelEvent ); - - // Accessibility - self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::FILLER); - self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false); + InitializeEvents(); } Dali::Toolkit::DevelControl::ControlAccessible* WidgetView::CreateAccessibleObject() diff --git a/widget_viewer_dali/internal/widget_view/widget_view_impl.h b/widget_viewer_dali/internal/widget_view/widget_view_impl.h index 3369835..3d11d7c 100644 --- a/widget_viewer_dali/internal/widget_view/widget_view_impl.h +++ b/widget_viewer_dali/internal/widget_view/widget_view_impl.h @@ -452,6 +452,31 @@ private: // From Control virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize ) override ; private: + /** + * @brief Initilize Widget + */ + void InitializeWidgets(); + + /** + * @brief Set the update period of widget + */ + void SetUpdatePeriod(); + + /** + * @brief Set the preview image of widget + */ + void SetPreviewImage(); + + /** + * @brief Initilize Layout + */ + void InitializeLayout(); + + /** + * @brief Initilize Events + */ + void InitializeEvents(); + /** * @brief Call a PauseWidget internally */ -- 2.34.1