Refactoring OnInitialize 99/315099/2
authorsunghyun kim <scholb.kim@samsung.com>
Thu, 25 Jul 2024 05:35:19 +0000 (14:35 +0900)
committersunghyun kim <scholb.kim@samsung.com>
Thu, 25 Jul 2024 06:13:14 +0000 (15:13 +0900)
OnInitialize() is too long.
so i seperated this function.

Change-Id: I3ed9cf2bcc37a675e998bb9c00ca02b22460a62b

widget_viewer_dali/internal/widget_view/widget_view_impl.cpp
widget_viewer_dali/internal/widget_view/widget_view_impl.h

index 438ecf89096813631f945a6af09c430b4711f2b0..fa57bf2fe5ed73eacadede624bfd7576c7d7a2e4 100644 (file)
@@ -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()
index 3369835c1fb64d7e82f71204ea38c977649217cb..3d11d7c9755dac272c3a85bd5fc5d598416b1575 100644 (file)
@@ -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
    */