[Tizen] Added layout direction change by system language 88/147088/1
authortaeyoon0.lee <taeyoon0.lee@samsung.com>
Mon, 28 Aug 2017 14:39:53 +0000 (23:39 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Fri, 1 Sep 2017 01:54:16 +0000 (10:54 +0900)
Change-Id: Ia48f37a873655013d7fa23ba65a98a5ca1af58ef

adaptors/common/adaptor-impl.cpp
adaptors/common/adaptor-impl.h
adaptors/common/locale-utils.cpp
adaptors/common/locale-utils.h
adaptors/tizen/adaptor-impl-tizen.cpp
adaptors/ubuntu/adaptor-impl-ubuntu.cpp
packaging/dali-adaptor.spec

index 2eb5e82..4042991 100644 (file)
@@ -20,6 +20,9 @@
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/common/stage.h>
+#include <dali/public-api/actors/layer.h>
+#include <dali/devel-api/actors/actor-devel.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/core.h>
 #include <dali/integration-api/context-notifier.h>
@@ -55,6 +58,8 @@
 #include <tizen-logging.h>
 #include <image-loading.h>
 
+#include <locale-utils.h>
+
 using Dali::TextAbstraction::FontClient;
 
 namespace Dali
@@ -189,6 +194,8 @@ void Adaptor::Initialize( Dali::Configuration::ContextLoss configuration )
   {
     Dali::SetMaxTextureSize( mEnvironmentOptions->GetMaxTextureSize() );
   }
+
+  SetupSystemInformation();
 }
 
 Adaptor::~Adaptor()
@@ -823,6 +830,13 @@ float Adaptor::GetStereoBase() const
   return mCore->GetStereoBase();
 }
 
+void Adaptor::SetRootLayoutDirection( std::string locale )
+{
+  Dali::Stage stage = Dali::Stage::GetCurrent();
+
+  stage.GetRootLayer().SetProperty( DevelActor::Property::LAYOUT_DIRECTION, Internal::Adaptor::Locale::GetLayoutDirection( locale ) );
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index f48f29e..5920b85 100644 (file)
@@ -345,6 +345,12 @@ public:
    */
   void SurfaceResizeComplete( Dali::Adaptor::SurfaceSize surfaceSize );
 
+  /**
+   * Sets layout direction of root by system language
+   * @param[in] locale System locale
+   */
+  void SetRootLayoutDirection( std::string locale );
+
 public:  //AdaptorInternalServices
 
   /**
@@ -516,6 +522,11 @@ private:
    */
   void GetDataStoragePath(std::string& path);
 
+  /**
+   * Sets up system information if needs
+   */
+  void SetupSystemInformation();
+
 private:
 
   /**
index d14856b..6df8616 100644 (file)
@@ -46,7 +46,7 @@ const LocaleDirection LOCALE_DIRECTION_LOOKUP_TABLE[] =
   { "am", "Amharic",            Dali::ImfManager::LeftToRight },
   { "ar", "Arabic",             Dali::ImfManager::RightToLeft },
   { "as", "Assamese",           Dali::ImfManager::LeftToRight },
-  { "az", "Azeri",              Dali::ImfManager::LeftToRight },
+  { "az", "Azerbaijani",        Dali::ImfManager::RightToLeft },
   { "be", "Belarusian",         Dali::ImfManager::LeftToRight },
   { "bg", "Bulgarian",          Dali::ImfManager::LeftToRight },
   { "bn", "Bengali",            Dali::ImfManager::LeftToRight },
@@ -165,6 +165,22 @@ Dali::ImfManager::TextDirection GetTextDirection( std::string locale )
   return direction;
 }
 
+// ToDo: ImfManager enum should be removed from this function or locale-util should be modified.
+DevelActor::LayoutDirection::Type GetLayoutDirection( std::string locale )
+{
+  Dali::ImfManager::TextDirection textDirection( Dali::ImfManager::LeftToRight );
+  DevelActor::LayoutDirection::Type direction( DevelActor::LayoutDirection::LTR );
+
+  textDirection = GetTextDirection( locale );
+
+  if( textDirection == Dali::ImfManager::RightToLeft )
+  {
+    direction = DevelActor::LayoutDirection::RTL;
+  }
+
+  return direction;
+}
+
 } // namespace Locale
 
 } // namespace Adaptor
index b04182b..7d7cec6 100644 (file)
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <string>
+#include <dali/devel-api/actors/actor-devel.h>
 
 // INTERNAL INCLUDES
 #include <imf-manager.h>
@@ -38,6 +39,8 @@ namespace Locale
 
 Dali::ImfManager::TextDirection GetTextDirection( std::string locale );
 
+DevelActor::LayoutDirection::Type GetLayoutDirection( std::string locale );
+
 } // namespace Locale
 
 } // namespace Adaptor
index 1619139..67afe39 100644 (file)
@@ -25,6 +25,8 @@
 #include <ecore-wl-render-surface.h>
 #endif
 
+#include <system_settings.h>
+
 namespace Dali
 {
 
@@ -34,6 +36,30 @@ namespace Internal
 namespace Adaptor
 {
 
+namespace
+{
+
+static void OnSystemLanguageChanged( system_settings_key_e key, void* data )
+{
+  char* locale = NULL;
+  if( system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale ) != SYSTEM_SETTINGS_ERROR_NONE ||
+      locale == NULL )
+  {
+    DALI_LOG_ERROR( "DALI OnSystemLanguageChanged failed " );
+    return;
+  }
+
+  Adaptor* adaptor = static_cast< Adaptor* >( data );
+  if( adaptor != NULL )
+  {
+    adaptor->SetRootLayoutDirection( locale );
+  }
+
+  free( locale );
+}
+
+} // namesapce
+
 void Adaptor::GetDataStoragePath( std::string& path)
 {
 #ifdef USE_APPFW
@@ -82,6 +108,28 @@ void Adaptor::SurfaceInitialized()
 #endif
 }
 
+void Adaptor::SetupSystemInformation()
+{
+  if( system_settings_set_changed_cb( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, OnSystemLanguageChanged, this ) != SYSTEM_SETTINGS_ERROR_NONE )
+  {
+    DALI_LOG_ERROR( "DALI system_settings_set_changed_cb failed.\n" );
+    return;
+  }
+
+  char* locale = NULL;
+  if( system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale ) != SYSTEM_SETTINGS_ERROR_NONE ||
+      locale == NULL )
+  {
+    DALI_LOG_ERROR( "DALI OnSystemLanguageChanged failed " );
+    return;
+  }
+
+  SetRootLayoutDirection( locale );
+
+  free( locale );
+
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index be25b7b..4f1201c 100644 (file)
@@ -41,6 +41,10 @@ void Adaptor::SurfaceInitialized()
 {
 }
 
+void Adaptor::SetupSystemInformation()
+{
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index 2cf0dae..77a92a7 100644 (file)
@@ -117,6 +117,7 @@ BuildRequires:  pkgconfig(capi-appfw-app-control)
 BuildRequires:  pkgconfig(screen_connector_provider)
 BuildRequires:  pkgconfig(ecore-imf)
 %endif
+
 BuildRequires:  pkgconfig(capi-system-system-settings)
 
 # for feedback plugin