2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #include <FBaseInteger.h>
20 #include <FBaseByteBuffer.h>
21 #include <FBaseColIMap.h>
22 #include <FBaseColArrayListT.h>
23 #include <FBaseSysLog.h>
24 #include <FIoDirectory.h>
26 #include <FGrpBitmap.h>
27 #include <FGrpDimension.h>
28 #include <FGrpColor.h>
29 #include <FMediaImageTypes.h>
30 #include <FApp_AppInfo.h>
31 #include <FAppPkg_PackageManagerImpl.h>
32 #include <FIo_DirectoryImpl.h>
33 #include <FGrp_BitmapImpl.h>
34 #include <FGrp_CanvasImpl.h>
35 #include <FGrp_CoordinateSystem.h>
36 #include <FMedia_ImageDecoder.h>
37 #include <FSys_SystemInfoImpl.h>
38 #include "FUi_ControlManager.h"
39 #include "FUi_ResourceManager.h"
40 #include "FUi_ResourceStringLoader.h"
41 #include "FUi_ResourceConfigLoader.h"
42 #include "FUi_ResourceConfigParser.h"
43 #include "FUi_ResourceMapContainer.h"
45 using namespace Tizen::App;
46 using namespace Tizen::App::Package;
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49 using namespace Tizen::Io;
50 using namespace Tizen::Graphics;
51 using namespace Tizen::Media;
52 using namespace Tizen::Ui::_Resource;
56 const int DEFAULT_SCREEN_WIDTH = 720;
57 const int DEFAULT_SCREEN_HEIGHT = 1280;
59 const int DPI_FOR_XHIGH = 290;
60 const int DPI_FOR_HIGH = 200;
61 const int DPI_FOR_MIDDLE = 150;
62 const int DPI_FOR_LOW = 0;
64 template<typename T> class ResourceFallbackItemComparer
65 : public IComparerT <T>
68 ResourceFallbackItemComparer(void) {}
69 virtual ~ResourceFallbackItemComparer(void) {}
70 virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
72 if (obj1->scaleFactor > obj2->scaleFactor)
77 else if (obj1->scaleFactor < obj2->scaleFactor)
90 MediaPixelFormat ConvertBitmapPixelFormatToMediaPixelFormat(BitmapPixelFormat format)
92 MediaPixelFormat out = MEDIA_PIXEL_FORMAT_NONE;
95 case BITMAP_PIXEL_FORMAT_RGB565:
96 out = MEDIA_PIXEL_FORMAT_RGB565LE;
98 case BITMAP_PIXEL_FORMAT_ARGB8888:
99 out = MEDIA_PIXEL_FORMAT_BGRA8888;
101 case BITMAP_PIXEL_FORMAT_R8G8B8A8:
102 out = MEDIA_PIXEL_FORMAT_RGBA8888;
111 namespace Tizen { namespace Graphics
114 _CreateCoordinateTransformer(_ICoordinateSystemTransformer*& pTransformer, int srcResolution, _BaseScreenSize srcBaseScreenSize, Dimension destResolution, _BaseScreenSize destBaseScreenSize);
117 namespace Tizen { namespace Ui
120 Color _GetDefaultBackgroundColor(void)
123 _ResourceManager::GetInstance()->GetColor(L"DEFAULTCOLORTABLE::background", color);
126 Color _GetDefaultForegroundColor(void)
129 _ResourceManager::GetInstance()->GetColor(L"DEFAULTCOLORTABLE::foreground", color);
133 _ResourceManager* pRsrcMgr = null;
136 _ResourceManager::GetInstance(void)
138 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
140 if (pRsrcMgr == null)
142 pthread_once(&onceBlock, CreateInstance);
147 _ResourceManager::CreateInstance(void)
149 static _ResourceManager pManager;
150 pRsrcMgr = &pManager;
151 _CanvasImpl::SetThemeInfoCallback(_GetDefaultForegroundColor, _GetDefaultBackgroundColor);
154 _ResourceManager::_ResourceManager(void)
155 : __pStringLoader(null)
156 , __pTransformer(null)
157 , __appBasePortraitMode("")
158 , __appBaseLandscapeMode("")
159 , __targetPortraitMode("")
160 , __targetLandscapeMode("")
161 , __defaultPortraitMode(L"720x1280")
162 , __defaultLandscapeMode(L"1280x720")
165 , __appliedUserTheme(false)
167 , __appBaseHeight(-1)
171 , __pFallbackList(null)
173 __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT] = null;
174 __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE] = null;
175 __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT] = null;
176 __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE] = null;
178 int appBaseWidth = DEFAULT_SCREEN_WIDTH;
179 int appBaseHeight = DEFAULT_SCREEN_HEIGHT;
181 result r = E_SUCCESS;
183 int appLogicalResolution = _CoordinateSystem::GetInstance()->GetLogicalResolutionInt();
185 if (_CreateCoordinateTransformer(__pTransformer,DEFAULT_SCREEN_WIDTH, BASE_SCREEN_SIZE_NORMAL, Dimension(appLogicalResolution, appLogicalResolution), BASE_SCREEN_SIZE_NORMAL) != E_SUCCESS)
191 r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/screen.dpi", __deviceDPI);
192 SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] system error occurred");
194 switch(appLogicalResolution)
210 appBaseHeight = 1280;
213 r = Tizen::System::_SystemInfoImpl::GetSysInfo("http://tizen.org/feature/screen.width", appBaseWidth);
214 SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] system error occurred");
215 r = Tizen::System::_SystemInfoImpl::GetSysInfo("http://tizen.org/feature/screen.height", appBaseHeight);
216 SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] system error occurred");
219 __appBaseWidth = appBaseWidth;
220 __appBaseHeight = appBaseHeight;
222 __appBasePortraitMode.Append(appBaseWidth);
223 __appBasePortraitMode.Append(L"x");
224 __appBasePortraitMode.Append(appBaseHeight);
226 __appBaseLandscapeMode.Append(appBaseHeight);
227 __appBaseLandscapeMode.Append(L"x");
228 __appBaseLandscapeMode.Append(appBaseWidth);
232 r = Tizen::System::_SystemInfoImpl::GetSysInfo("http://tizen.org/feature/screen.width", _width);
233 SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] system error occurred");
234 r = Tizen::System::_SystemInfoImpl::GetSysInfo("http://tizen.org/feature/screen.height", _height);
235 SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] system error occurred");
237 __targetWidth = _width;
238 __targetHeight = _height;
239 __targetPortraitMode.Append(_width);
240 __targetPortraitMode.Append(L"x");
241 __targetPortraitMode.Append(_height);
243 __targetLandscapeMode.Append(_height);
244 __targetLandscapeMode.Append(L"x");
245 __targetLandscapeMode.Append(_width);
247 LoadThemeInformation(__systemTheme, __userTheme);
250 __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT] = new (std::nothrow) MapContainer();
251 SysTryReturnVoidResult(NID_UI, __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT], E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
252 __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->SetResolution(__appBasePortraitMode);
253 if (!(InitializeTheme(*__pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT])))
258 __pStringLoader = new (std::nothrow) StringLoader();
259 SysTryReturnVoidResult(NID_UI, __pStringLoader, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
264 _ResourceManager::InitializeTheme(MapContainer& mapContainer)
267 String themeFile(L"");
269 mapContainer.CreateMap(RESOURCE_TYPE_SHAPE);
270 mapContainer.CreateMap(RESOURCE_TYPE_FIXED_VALUE);
271 mapContainer.CreateMap(RESOURCE_TYPE_DIMENSION);
272 mapContainer.CreateMap(RESOURCE_TYPE_IMAGE);
273 mapContainer.CreateMap(RESOURCE_TYPE_COLOR);
274 mapContainer.SetResolution(__appBasePortraitMode);
275 themeFile = String(L"/usr/share/osp/themes/"+__systemTheme + ".xml");
276 ConfigParser* pParser = new (std::nothrow) ConfigParser();
277 SysTryReturn(NID_UI, pParser, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
278 r = pParser->Parse(themeFile, mapContainer);
279 LoadConfig(__appBasePortraitMode, mapContainer);
281 if (__userTheme.GetLength() > 0)
283 themeFile = String(_AppInfo::GetAppRootPath()+L"res/themes/" +__userTheme + L"/" +__userTheme + ".xml");
284 r = pParser->Parse(themeFile, mapContainer);
292 _ResourceManager::LoadConfig(const String& resolution, MapContainer& mapContainer)
294 int count = ConfigLoader::GetInstance()->GetInitFuncCount();
295 for (int i = 0; i < count; i++)
297 _Init_Func func = null;
298 ConfigLoader::GetInstance()->GetInitFunc(i, func);
301 func(mapContainer, resolution);
306 _ResourceManager::GetMapContainer(MapContainerType type)
308 MapContainer* pContainer = null;
311 case MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT:
312 pContainer = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT];
314 case MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE:
315 if (__pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE])
317 pContainer = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE];
321 pContainer = new (std::nothrow) MapContainer();
322 SysTryReturn(NID_UI, pContainer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
323 pContainer->SetResolution(__appBaseLandscapeMode);
324 pContainer->CreateMap(RESOURCE_TYPE_SHAPE);
325 pContainer->CreateMap(RESOURCE_TYPE_DIMENSION);
326 pContainer->CreateMap(RESOURCE_TYPE_FIXED_VALUE);
327 LoadConfig(__appBaseLandscapeMode, *pContainer);
328 __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE] = pContainer;
331 case MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT:
332 if (__pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT])
334 pContainer = __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT];
338 pContainer = new (std::nothrow) MapContainer();
339 SysTryReturn(NID_UI, pContainer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
340 pContainer->SetResolution(__defaultPortraitMode);
341 pContainer->CreateMap(RESOURCE_TYPE_SHAPE);
342 pContainer->CreateMap(RESOURCE_TYPE_DIMENSION);
343 pContainer->CreateMap(RESOURCE_TYPE_FIXED_VALUE);
344 LoadConfig(__defaultPortraitMode, *pContainer);
345 __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT] = pContainer;
348 case MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE:
349 if (__pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE])
351 pContainer = __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE];
355 pContainer = new (std::nothrow) MapContainer();
356 SysTryReturn(NID_UI, pContainer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
357 pContainer->SetResolution(__defaultLandscapeMode);
358 pContainer->CreateMap(RESOURCE_TYPE_SHAPE);
359 pContainer->CreateMap(RESOURCE_TYPE_DIMENSION);
360 pContainer->CreateMap(RESOURCE_TYPE_FIXED_VALUE);
361 LoadConfig(__defaultLandscapeMode, *pContainer);
362 __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE] = pContainer;
371 _ResourceManager::~_ResourceManager(void)
373 delete __pStringLoader;
374 __pStringLoader = null;
375 delete __pTransformer;
376 __pTransformer = null;
377 delete __pFallbackList;
378 __pFallbackList = null;
379 delete __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT];
380 __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT] = null;
381 delete __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE];
382 __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE] = null;
383 delete __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT];
384 __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT] = null;
385 delete __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE];
386 __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE] = null;
389 _ResourceManager::ReloadTheme(Tizen::Base::String& themeName, bool userdefine)
393 __userTheme = themeName;
397 __systemTheme = themeName;
402 _ResourceManager::GetBitmapInternalN(const String& fileName, BitmapPixelFormat pixelFormat, _ControlOrientation orientation, Bitmap*& pBitmap)
405 Bitmap* pTempBitmap = null;
406 pTempBitmap = new (std::nothrow) Bitmap;
407 SysTryReturn(NID_UI, pTempBitmap, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(r));
409 r = _BitmapImpl::GetInstance(*pTempBitmap)->Construct(fileName, pixelFormat);
410 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
411 pBitmap = pTempBitmap;
420 _ResourceManager::GetBitmapN(const String& bitmapId, BitmapPixelFormat pixelFormat, _ControlOrientation orientation, Bitmap*& pBitmap)
423 String* pFileName = null;
424 r = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetImageMap()->GetValue(bitmapId, pFileName);
427 int foundFolderWidth = 0;
428 String fullName = FindImagePath(*pFileName, foundFolderWidth);
429 if(foundFolderWidth == __targetWidth)
431 r = GetBitmapInternalN(fullName, pixelFormat, orientation, pBitmap);
435 ByteBuffer* pImageBuffer = null;
436 Bitmap* pTempBitmap = null;
439 MediaPixelFormat format = ConvertBitmapPixelFormatToMediaPixelFormat(pixelFormat);
440 pImageBuffer = _ImageDecoder::DecodeToBufferN(fullName, format, imageWidth, imageHeight);
443 pTempBitmap = _BitmapImpl::GetNonScaledBitmapN(*pImageBuffer, Dimension(imageWidth, imageHeight), pixelFormat);
446 if(pTempBitmap != null)
448 if(pTempBitmap->IsNinePatchedBitmap())
450 pBitmap = pTempBitmap;
455 float scaleFactor = (float)((float)__targetWidth/(float)foundFolderWidth);
457 r = pTempBitmap->Scale(Dimension(imageWidth*scaleFactor, imageHeight*scaleFactor));
460 pBitmap = pTempBitmap;
474 _ResourceManager::GetString(const String& stringId, String& string)
476 return __pStringLoader->GetString(stringId, string);
480 _ResourceManager::GetColor(const String& colorId, Color& color)
483 Color* pColor = null;
484 r = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetColorMap()->GetValue(colorId, pColor);
493 _ResourceManager::GetDimension(const String& dimensionId, _ControlOrientation orientation, Dimension& dimension)
495 result r = E_SUCCESS;
498 Dimension* pDimension = null;
499 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
501 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT)->GetDimensionMap()->GetValue(dimensionId, pDimension);
504 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetDimensionMap()->GetValue(dimensionId, pDimension);
509 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetDimensionMap()->GetValue(dimensionId, pDimension);
512 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT)->GetDimensionMap()->GetValue(dimensionId, pDimension);
522 r = GetDefaultShapeWithScaling(dimensionId, orientation, dim);
538 _ResourceManager::GetShape(const String& shapeId, _ControlOrientation orientation, int& value)
540 result r = E_SUCCESS;
543 Integer* pInteger = null;
544 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
546 r = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetShapeMap()->GetValue(shapeId, pInteger);
549 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pInteger);
554 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pInteger);
557 r = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetShapeMap()->GetValue(shapeId, pInteger);
568 r = GetDefaultShapeWithScaling(shapeId, orientation, integer);
573 value = integer.ToInt();
584 _ResourceManager::GetFixedValue(const String& fixedValueId, _ControlOrientation orientation, int& value)
586 result r = E_SUCCESS;
588 Integer* pInteger = null;
589 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
591 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetFixedValueMap()->GetValue(fixedValueId, pInteger);
595 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetFixedValueMap()->GetValue(fixedValueId, pInteger);
600 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetFixedValueMap()->GetValue(fixedValueId, pInteger);
603 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetFixedValueMap()->GetValue(fixedValueId, pInteger);
609 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
611 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(fixedValueId, pInteger);
614 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(fixedValueId, pInteger);
619 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(fixedValueId, pInteger);
622 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(fixedValueId, pInteger);
634 value = integer.ToInt();
645 _ResourceManager::IsCustomColor(const Tizen::Base::String& colorId)
647 return __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetColorMap()->IsUserThemeItem(colorId);
650 _ResourceManager::IsCustomBitmap(const Tizen::Base::String& bitmapId)
652 return __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetImageMap()->IsUserThemeItem(bitmapId);
656 _ResourceManager::GetDefaultShapeWithScaling(const String& shapeId, _ControlOrientation orientation, Integer& integer)
658 result r = E_SUCCESS;
659 Integer* pInteger = null;
660 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
662 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(shapeId, pInteger);
665 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pInteger);
670 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pInteger);
673 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(shapeId, pInteger);
683 int temp = __pTransformer->Transform(integer.ToInt());
684 if (temp == 0 && integer.ToInt() > 0)
697 _ResourceManager::GetDefaultShapeWithScaling(const String& shapeId, _ControlOrientation orientation, Dimension& dimension)
699 result r = E_SUCCESS;
701 Dimension* pDimension = null;
702 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
704 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetDimensionMap()->GetValue(shapeId, pDimension);
707 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetDimensionMap()->GetValue(shapeId, pDimension);
712 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetDimensionMap()->GetValue(shapeId, pDimension);
715 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetDimensionMap()->GetValue(shapeId, pDimension);
725 Dimension temp = __pTransformer->Transform(dim);
726 if (temp.width == 0 && dim.width > 0)
730 if (temp.height == 0 && dim.height > 0)
740 _ResourceManager::LoadThemeInformation(String& systemTheme, String& userTheme)
742 AppId appId = _AppInfo::GetAppId();
744 pList = _PackageManagerImpl::GetInstance()->GetUiThemeListN(appId);
748 IMapEnumerator* pMapEnum = pList->GetMapEnumeratorN();
749 while (pMapEnum->MoveNext() == E_SUCCESS)
751 String* pKey = static_cast<String*> (pMapEnum->GetKey());
752 String* pValue = static_cast<String*> (pMapEnum->GetValue());
755 if (key == L"systemtheme")
757 systemTheme = *pValue;
758 systemTheme.ToLowerCase();
760 if (key == L"userdefinedtheme")
767 pList->RemoveAll(true);
770 if (systemTheme.GetLength() < 1)
772 systemTheme = L"black";
778 _ResourceManager::GetThemeName(String& systemTheme, String& userTheme) const
780 systemTheme = __systemTheme;
781 userTheme = __userTheme;
785 _ResourceManager::SetSystemColor(void)
788 Color* pColor = null;
789 Color* (*GetSystemColor)(const String&) = null;
791 handle = dlopen ("libosp-compat.so", RTLD_LAZY);
796 GetSystemColor = reinterpret_cast<Color*(*)(const String&)>(dlsym(handle, "_GetSystemColor"));
797 if (dlerror() != NULL)
802 pColor = GetSystemColor(L"TITLE_TEXT");
805 GetColor("HEADER::TITLE_TEXT_NORMAL", *pColor);
808 pColor = GetSystemColor(L"BODY_TEXT");
811 GetColor("BUTTON::TEXT_NORMAL", *pColor);
814 pColor = GetSystemColor(L"FOREGROUND");
817 GetColor("foreground", *pColor);
820 pColor = GetSystemColor(L"BACKGROUND");
823 GetColor("background", *pColor);
826 pColor = GetSystemColor(L"LIST_BACKGROUND");
829 GetColor("FORM::BG_NORMAL", *pColor);
832 pColor = GetSystemColor(L"FORM_BACKGROUND");
835 GetColor("FORM::BG_NORMAL", *pColor);
838 pColor = GetSystemColor(L"FORM_GROUP_BACKGROUND");
841 GetColor("DEFAULTCOLORTABLE::form_group_list_bg", *pColor);
844 pColor = GetSystemColor(L"POPUP_BACKGROUND");
847 GetColor("POPUP::BG_NORMAL", *pColor);
850 pColor = GetSystemColor(L"GROUP_ITEM_TEXT");
853 GetColor("CHECKBUTTON::TEXT_NORMAL", *pColor);
856 pColor = GetSystemColor(L"LIST_ITEM_TEXT");
859 GetColor("LISTVIEW::ITEM_TEXT_NORMAL", *pColor);
862 pColor = GetSystemColor(L"LIST_ITEM_PRESSED_TEXT");
865 GetColor("LISTVIEW::ITEM_TEXT_PRESSED", *pColor);
868 pColor = GetSystemColor(L"LIST_ITEM_HIGHLIGHTED_TEXT");
871 GetColor("LISTVIEW::ITEM_TEXT_HIGHLIGHTED", *pColor);
880 _ResourceManager::GetDensityDirectory(String directoryName, float scaleFactor)
884 if(!(directoryName.StartsWith(L"screen-density",0)))
889 if (__deviceDPI >= DPI_FOR_XHIGH)
893 else if (__deviceDPI >= DPI_FOR_HIGH)
897 else if (__deviceDPI >= DPI_FOR_MIDDLE)
901 else if (__deviceDPI < DPI_FOR_MIDDLE && __deviceDPI > DPI_FOR_LOW)
910 if(directoryName.Contains(L"xhigh"))
914 else if(directoryName.Contains(L"high"))
918 else if(directoryName.Contains(L"middle"))
922 else if(directoryName.Contains(L"low"))
931 scaleFactor = (float)((float)numerator / (float)denominator);
936 _ResourceManager::GetResolutionDirectory(String directoryName, float scaleFactor)
938 if(!(directoryName.Contains(L"0")))
944 if(directoryName.IndexOf(L"x", 0, index) != E_SUCCESS)
950 if(directoryName.SubString(0, index - 1, width))
954 if(Integer::Parse(width, denominator) == E_SUCCESS)
956 numerator = __targetWidth;
957 scaleFactor = (float)((float)numerator / (float)denominator);
965 _ResourceManager::FindImagePath(const String& fileName, int& foundFolderWidth)
968 String fullName(L"");
969 ResourceFallbackItem* pItem = null;
971 if(__userTheme.GetLength() > 0)
973 String resDirectory = _AppInfo::GetAppRootPath() + L"res/theme/res";
974 if(__pFallbackList == null)
976 __pFallbackList = new (std::nothrow) ArrayListT<ResourceFallbackItem*>;
977 SysTryReturn(NID_UI, __pFallbackList, L"", E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
979 result r = dir.Construct(resDirectory);
982 DirEnumerator* pDirEnum = dir.ReadN();
983 if (pDirEnum != null)
985 while (pDirEnum->MoveNext() == E_SUCCESS)
987 DirEntry entry = pDirEnum->GetCurrentDirEntry();
988 if(entry.IsDirectory())
990 float scaleFactor = 0;
991 String directoryName = entry.GetName();
992 if(GetDensityDirectory(directoryName, scaleFactor))
994 pItem = new (std::nothrow) ResourceFallbackItem;
995 SysTryCatch(NID_UI, pItem, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
996 pItem->scaleFactor = scaleFactor;
997 pItem->directoryName = directoryName;
998 __pFallbackList->Add(pItem);
1000 else if(GetResolutionDirectory(directoryName, scaleFactor))
1002 pItem = new (std::nothrow) ResourceFallbackItem;
1003 SysTryCatch(NID_UI, pItem, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
1004 pItem->scaleFactor = scaleFactor;
1005 pItem->directoryName = directoryName;
1006 __pFallbackList->Add(pItem);
1010 ResourceFallbackItemComparer<ResourceFallbackItem*> comparer;
1011 __pFallbackList->Sort(comparer);
1014 for(int i = 0 ; i < __pFallbackList->GetCount() ; i++)
1016 ResourceFallbackItem* pItem;
1017 if(__pFallbackList->GetAt(i,pItem) == E_SUCCESS)
1019 if(pItem->scaleFactor < 1.001 && pItem->scaleFactor > 0.999)
1021 __pFallbackList->RemoveAt(i);
1022 __pFallbackList->InsertAt(pItem,0);
1023 if(pItem->directoryName.Contains(L"0"))
1032 for(int i = 0 ; i <__pFallbackList->GetCount() ; i++)
1034 ResourceFallbackItem* pItem;
1035 __pFallbackList->GetAt(i,pItem);
1036 fullName = resDirectory + L"/" + pItem->directoryName + L"/" + fileName;
1037 if (File::IsFileExist(fullName))
1040 foundFolderWidth = __targetWidth / pItem->scaleFactor;
1041 if(foundFolderWidth > __targetWidth)
1043 if( foundFolderWidth < __targetWidth + 3)
1045 foundFolderWidth = __targetWidth;
1050 if( foundFolderWidth >__targetWidth - 3)
1052 foundFolderWidth = __targetWidth;
1061 fullName = String(L"/usr/share/osp/bitmaps/" + __targetPortraitMode+ "/" + __systemTheme + L"/" + fileName);
1062 if (File::IsFileExist(fullName))
1065 foundFolderWidth = __targetWidth;
1069 fullName = String(L"/usr/share/osp/bitmaps/" + __defaultPortraitMode+ "/" + __systemTheme + L"/" + fileName);
1070 if (File::IsFileExist(fullName))
1073 foundFolderWidth = DEFAULT_SCREEN_WIDTH;
1080 fullName = String(L"/usr/share/osp/bitmaps/" + __targetPortraitMode + "/" + fileName);
1081 if (File::IsFileExist(fullName))
1084 foundFolderWidth = __targetWidth;
1088 fullName = String(L"/usr/share/osp/bitmaps/" + __defaultPortraitMode+ "/" + fileName);
1089 if (File::IsFileExist(fullName))
1092 foundFolderWidth = DEFAULT_SCREEN_WIDTH;
1106 delete __pFallbackList;
1107 __pFallbackList = null;