Apply new indicator UI.
[platform/framework/native/uifw.git] / src / ui / FUi_ResourceManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17 #include <dlfcn.h>
18 #include <pthread.h>
19 #include <feedback/feedback.h>
20 #include <FBaseInteger.h>
21 #include <FBaseByteBuffer.h>
22 #include <FBaseColIMap.h>
23 #include <FBaseColArrayListT.h>
24 #include <FBaseSysLog.h>
25 #include <FIoDirectory.h>
26 #include <FIoFile.h>
27 #include <FGrpBitmap.h>
28 #include <FGrpDimension.h>
29 #include <FGrpColor.h>
30 #include <FMediaImageTypes.h>
31 #include <FUiCtrlAnimationFrame.h>
32 #include <FApp_AppInfo.h>
33 #include <FAppPkg_PackageManagerImpl.h>
34 #include <FIo_DirectoryImpl.h>
35 #include <FGrp_BitmapImpl.h>
36 #include <FGrp_CanvasImpl.h>
37 #include <FGrp_CoordinateSystem.h>
38 #include <FGrp_Screen.h>
39 #include <FMedia_ImageDecoder.h>
40 #include <FSys_SystemInfoImpl.h>
41 #include "FUi_ControlManager.h"
42 #include "FUi_CoordinateSystemUtils.h"
43 #include "FUi_ResourceManager.h"
44 #include "FUi_ResourceStringLoader.h"
45 #include "FUi_ResourceConfigLoader.h"
46 #include "FUi_ResourceConfigParser.h"
47 #include "FUi_ResourceMapContainer.h"
48
49 using namespace Tizen::App;
50 using namespace Tizen::App::Package;
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Io;
54 using namespace Tizen::Graphics;
55 using namespace Tizen::Media;
56 using namespace Tizen::Ui::Controls;
57 using namespace Tizen::Ui::_Resource;
58
59 namespace
60 {
61 const int DEFAULT_SCREEN_WIDTH = 720;
62 const int DEFAULT_SCREEN_HEIGHT = 1280;
63
64 const int DPI_FOR_XHIGH = 290;
65 const int DPI_FOR_HIGH = 200;
66 const int DPI_FOR_MIDDLE = 150;
67 const int DPI_FOR_LOW = 0;
68
69 template<typename T> class ResourceFallbackItemComparer
70         : public IComparerT <T>
71 {
72 public:
73         ResourceFallbackItemComparer(void) {}
74         virtual ~ResourceFallbackItemComparer(void) {}
75         virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
76         {
77                 if (obj1->scaleFactor > obj2->scaleFactor)
78                 {
79                         cmp = 1;
80                         return E_SUCCESS;
81                 }
82                 else if (obj1->scaleFactor < obj2->scaleFactor)
83                 {
84                         cmp = -1;
85                         return E_SUCCESS;
86                 }
87                 else
88                 {
89                         cmp = 0;
90                         return E_SUCCESS;
91                 }
92         }
93 };
94
95 MediaPixelFormat ConvertBitmapPixelFormatToMediaPixelFormat(BitmapPixelFormat format)
96 {
97         MediaPixelFormat out = MEDIA_PIXEL_FORMAT_NONE;
98         switch(format)
99         {
100                 case BITMAP_PIXEL_FORMAT_RGB565:
101                         out = MEDIA_PIXEL_FORMAT_RGB565LE;
102                         break;
103                 case BITMAP_PIXEL_FORMAT_ARGB8888:
104                         out = MEDIA_PIXEL_FORMAT_BGRA8888;
105                         break;
106                 case BITMAP_PIXEL_FORMAT_R8G8B8A8:
107                         out = MEDIA_PIXEL_FORMAT_RGBA8888;
108                         break;
109                 default:
110                         break;
111         }
112         return out;
113 }
114
115 feedback_pattern_e Convert_ResourceFeedbackPatternTofeedback_pattern_e(Tizen::Ui::_ResourceFeedbackPattern pattern)
116 {
117         feedback_pattern_e outPattern = FEEDBACK_PATTERN_TAP;
118         switch (pattern)
119         {
120                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_TAP:
121                         outPattern = FEEDBACK_PATTERN_TAP;
122                         break;
123                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_SIP:
124                         outPattern = FEEDBACK_PATTERN_SIP;
125                         break;
126                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_SIP_BACKSPACE:
127                         outPattern = FEEDBACK_PATTERN_SIP_BACKSPACE;
128                         break;
129                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_MAX_CHARACTER:
130                         outPattern = FEEDBACK_PATTERN_MAX_CHARACTER;
131                         break;
132                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY0:
133                         outPattern = FEEDBACK_PATTERN_KEY0;
134                         break;
135                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY1:
136                         outPattern = FEEDBACK_PATTERN_KEY1;
137                         break;
138                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY2:
139                         outPattern = FEEDBACK_PATTERN_KEY2;
140                         break;
141                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY3:
142                         outPattern = FEEDBACK_PATTERN_KEY3;
143                         break;
144                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY4:
145                         outPattern = FEEDBACK_PATTERN_KEY4;
146                         break;
147                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY5:
148                         outPattern = FEEDBACK_PATTERN_KEY5;
149                         break;
150                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY6:
151                         outPattern = FEEDBACK_PATTERN_KEY6;
152                         break;
153                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY7:
154                         outPattern = FEEDBACK_PATTERN_KEY7;
155                         break;
156                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY8:
157                         outPattern = FEEDBACK_PATTERN_KEY8;
158                         break;
159                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY9:
160                         outPattern = FEEDBACK_PATTERN_KEY9;
161                         break;
162                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY_STAR:
163                         outPattern = FEEDBACK_PATTERN_KEY_STAR;
164                         break;
165                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_KEY_SHARP:
166                         outPattern = FEEDBACK_PATTERN_KEY_SHARP;
167                         break;
168                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_HOLD:
169                         outPattern = FEEDBACK_PATTERN_HOLD;
170                         break;
171                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_MULTI_TAP:
172                         outPattern = FEEDBACK_PATTERN_MULTI_TAP;
173                         break;
174                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_HW_TAP:
175                         outPattern = FEEDBACK_PATTERN_HW_TAP;
176                         break;
177                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_HW_HOLD:
178                         outPattern = FEEDBACK_PATTERN_HW_HOLD;
179                         break;
180                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_MESSAGE:
181                         outPattern = FEEDBACK_PATTERN_MESSAGE;
182                         break;
183                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_MESSAGE_ON_CALL:
184                         outPattern = FEEDBACK_PATTERN_MESSAGE_ON_CALL;
185                         break;
186                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_EMAIL:
187                         outPattern = FEEDBACK_PATTERN_EMAIL;
188                         break;
189                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_EMAIL_ON_CALL:
190                         outPattern = FEEDBACK_PATTERN_EMAIL_ON_CALL;
191                         break;
192                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_WAKEUP:
193                         outPattern = FEEDBACK_PATTERN_WAKEUP;
194                         break;
195                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_WAKEUP_ON_CALL:
196                         outPattern = FEEDBACK_PATTERN_WAKEUP_ON_CALL;
197                         break;
198                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_SCHEDULE:
199                         outPattern = FEEDBACK_PATTERN_SCHEDULE;
200                         break;
201                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_SCHEDULE_ON_CALL:
202                         outPattern = FEEDBACK_PATTERN_SCHEDULE_ON_CALL;
203                         break;
204                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_TIMER:
205                         outPattern = FEEDBACK_PATTERN_TIMER;
206                         break;
207                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_TIMER_ON_CALL:
208                         outPattern = FEEDBACK_PATTERN_TIMER_ON_CALL;
209                         break;
210                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_GENERAL:
211                         outPattern = FEEDBACK_PATTERN_GENERAL;
212                         break;
213                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_GENERAL_ON_CALL:
214                         outPattern = FEEDBACK_PATTERN_GENERAL_ON_CALL;
215                         break;
216                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_POWERON:
217                         outPattern = FEEDBACK_PATTERN_POWERON;
218                         break;
219                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_POWEROFF:
220                         outPattern = FEEDBACK_PATTERN_POWEROFF;
221                         break;
222                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_CHARGERCONN:
223                         outPattern = FEEDBACK_PATTERN_CHARGERCONN;
224                         break;
225                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_CHARGERCONN_ON_CALL:
226                         outPattern = FEEDBACK_PATTERN_CHARGERCONN_ON_CALL;
227                         break;
228                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_FULLCHARGED:
229                         outPattern = FEEDBACK_PATTERN_FULLCHARGED;
230                         break;
231                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_FULLCHARGED_ON_CALL:
232                         outPattern = FEEDBACK_PATTERN_FULLCHARGED_ON_CALL;
233                         break;
234                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_LOWBATT:
235                         outPattern = FEEDBACK_PATTERN_LOWBATT;
236                         break;
237                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_LOWBATT_ON_CALL:
238                         outPattern = FEEDBACK_PATTERN_LOWBATT_ON_CALL;
239                         break;
240                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_LOCK:
241                         outPattern = FEEDBACK_PATTERN_LOCK;
242                         break;
243                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_UNLOCK:
244                         outPattern = FEEDBACK_PATTERN_UNLOCK;
245                         break;
246                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_CALLCONNECT:
247                         outPattern = FEEDBACK_PATTERN_CALLCONNECT;
248                         break;
249                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_DISCALLCONNECT:
250                         outPattern = FEEDBACK_PATTERN_DISCALLCONNECT;
251                         break;
252                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_MINUTEMINDER:
253                         outPattern = FEEDBACK_PATTERN_MINUTEMINDER;
254                         break;
255                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_VIBRATION:
256                         outPattern = FEEDBACK_PATTERN_VIBRATION;
257                         break;
258                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_SHUTTER:
259                         outPattern = FEEDBACK_PATTERN_SHUTTER;
260                         break;
261                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_LIST_REORDER:
262                         outPattern = FEEDBACK_PATTERN_LIST_REORDER;
263                         break;
264                 case Tizen::Ui::_RESOURCE_FEEDBACK_PATTERN_SLIDER_SWEEP:
265                         outPattern = FEEDBACK_PATTERN_SLIDER_SWEEP;
266                         break;
267                 default:
268                         break;
269         }
270         return outPattern;
271 }
272 }
273
274 namespace Tizen { namespace Graphics
275 {
276 result
277 _CreateCoordinateTransformer(_ICoordinateSystemTransformer*& pTransformer, int srcResolution, _BaseScreenSize srcBaseScreenSize, Dimension destResolution, _BaseScreenSize destBaseScreenSize);
278 }}
279
280 namespace Tizen { namespace Ui
281 {
282         
283 int _SCREEN_HEIGHT_ = 0;
284
285 Color _GetDefaultBackgroundColor(void)
286 {
287         Color color;
288         GET_COLOR_CONFIG(BASIC::background, color);
289         return color;
290 }
291 Color _GetDefaultForegroundColor(void)
292 {
293         Color color;
294         GET_COLOR_CONFIG(BASIC::foreground, color);
295         return color;
296 }
297
298 _ResourceManager* pRsrcMgr = null;
299
300 _ResourceManager*
301 _ResourceManager::GetInstance(void)
302 {
303         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
304
305         if (pRsrcMgr == null)
306         {
307                 pthread_once(&onceBlock, CreateInstance);
308                 pRsrcMgr->DoPostInitialization();
309         }
310         return pRsrcMgr;
311 }
312
313 void
314 _ResourceManager::CreateInstance(void)
315 {
316         static _ResourceManager pManager;
317         pRsrcMgr = &pManager;
318         _CanvasImpl::SetThemeInfoCallback(_GetDefaultForegroundColor, _GetDefaultBackgroundColor);
319 }
320
321 _ResourceManager::_ResourceManager(void)
322         : __pStringLoader(null)
323         , __pTransformer(null)
324         , __appBasePortraitMode("")
325         , __appBaseLandscapeMode("")
326         , __targetPortraitMode("")
327         , __targetLandscapeMode("")
328         , __defaultPortraitMode(L"720x1280")
329         , __defaultLandscapeMode(L"1280x720")
330         , __systemTheme(L"")
331         , __userTheme(L"")
332         , __appliedUserTheme(false)
333         , __initializeFeedback(false)
334         , __appBaseWidth(-1)
335         , __appBaseHeight(-1)
336         , __targetWidth(0)
337         , __targetHeight(0)
338         , __deviceDPI(0)
339         , __feedbackStatus(_RESOURCE_FEEDBACK_STATUS_INIT)
340         , __feedbackAcquireCount(0)
341         , __pFallbackList(null)
342 {
343         __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT] = null;
344         __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE] = null;
345         __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT] = null;
346         __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE] = null;
347
348         int appBaseWidth = DEFAULT_SCREEN_WIDTH;
349         int appBaseHeight = DEFAULT_SCREEN_HEIGHT;
350
351         result r = E_SUCCESS;
352
353         int appLogicalResolution = _CoordinateSystem::GetInstance()->GetLogicalResolutionInt();
354
355         if (_CreateCoordinateTransformer(__pTransformer,DEFAULT_SCREEN_WIDTH, _CoordinateSystem::GetInstance()->GetLogicalBaseScreenSize(), 
356                         Dimension(appLogicalResolution, appLogicalResolution), _CoordinateSystem::GetInstance()->GetPhysicalBaseScreenSize()) != E_SUCCESS)
357         {
358
359                 SysAssert(0);
360         }
361         r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/screen.dpi", __deviceDPI);
362         SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] system error occurred");
363
364         switch(appLogicalResolution)
365         {
366                 case 240:
367                         appBaseWidth = 240;
368                         appBaseHeight = 400;
369                         break;
370                 case 320:
371                         appBaseWidth = 320;
372                         appBaseHeight = 480;
373                         break;
374                 case 480:
375                         appBaseWidth = 480;
376                         appBaseHeight = 800;
377                         break;
378                 case 720:
379                         appBaseWidth = 720;
380                         appBaseHeight = 1280;
381                         break;
382                 default:
383                         r = Tizen::System::_SystemInfoImpl::GetSysInfo("http://tizen.org/feature/screen.width", appBaseWidth);
384                         SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] system error occurred");
385                         r = Tizen::System::_SystemInfoImpl::GetSysInfo("http://tizen.org/feature/screen.height", appBaseHeight);
386                         SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] system error occurred");
387                         break;
388         }
389         __appBaseWidth = appBaseWidth;
390         __appBaseHeight = appBaseHeight;
391
392         __appBasePortraitMode.Append(appBaseWidth);
393         __appBasePortraitMode.Append(L"x");
394         __appBasePortraitMode.Append(appBaseHeight);
395
396         __appBaseLandscapeMode.Append(appBaseHeight);
397         __appBaseLandscapeMode.Append(L"x");
398         __appBaseLandscapeMode.Append(appBaseWidth);
399         int _width = 0;
400         int _height = 0;
401         r = Tizen::System::_SystemInfoImpl::GetSysInfo("http://tizen.org/feature/screen.width", _width);
402         SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] system error occurred");
403         r = Tizen::System::_SystemInfoImpl::GetSysInfo("http://tizen.org/feature/screen.height", _height);
404         SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] system error occurred");
405
406         __targetWidth = _width;
407         __targetHeight = _height;
408         __targetPortraitMode.Append(_width);
409         __targetPortraitMode.Append(L"x");
410         __targetPortraitMode.Append(_height);
411
412         __targetLandscapeMode.Append(_height);
413         __targetLandscapeMode.Append(L"x");
414         __targetLandscapeMode.Append(_width);
415
416         Dimension dim = _CoordinateSystemUtils::InverseTransform(Dimension(_Screen::GetWidth(), _Screen::GetHeight()));
417         __logicalWidth = dim.width;
418         __logicalHeight = dim.height;
419         LoadThemeInformation(__systemTheme, __userTheme);
420         // theme 2.0
421         __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT] = new (std::nothrow) MapContainer();
422         SysTryReturnVoidResult(NID_UI, __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT], E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
423         __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->SetResolution(__appBasePortraitMode);
424         if (!(InitializeTheme(*__pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT])))
425         {
426                 SysAssert(0);
427         }
428         __pStringLoader = new (std::nothrow) StringLoader();
429         SysTryReturnVoidResult(NID_UI, __pStringLoader, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
430 }
431
432 bool
433 _ResourceManager::InitializeTheme(MapContainer& mapContainer)
434 {
435         bool r = false;
436         String themeFile(L"");
437         mapContainer.CreateMap(RESOURCE_TYPE_SHAPE);
438         mapContainer.CreateMap(RESOURCE_TYPE_FIXED_VALUE);
439         mapContainer.CreateMap(RESOURCE_TYPE_DIMENSION);
440         mapContainer.CreateMap(RESOURCE_TYPE_IMAGE);
441         mapContainer.CreateMap(RESOURCE_TYPE_COLOR);
442         mapContainer.CreateMap(RESOURCE_TYPE_ANIMATION);
443         mapContainer.SetResolution(__appBasePortraitMode);
444         themeFile = String(L"/usr/share/osp/themes/"+__systemTheme + ".xml");
445         ConfigParser* pParser = new (std::nothrow) ConfigParser();
446         SysTryReturn(NID_UI, pParser, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
447         r = pParser->Parse(themeFile, mapContainer);
448         LoadConfig(__appBasePortraitMode, mapContainer, __appBaseWidth, __appBaseHeight);
449         if (__userTheme.GetLength() > 0)
450         {
451                 themeFile = String(_AppInfo::GetAppRootPath()+L"res/themes/" +__userTheme + L"/" +__userTheme + ".xml");
452                 r = pParser->Parse(themeFile, mapContainer);
453         }
454         delete pParser;
455         return r;
456 }
457
458 void
459 _ResourceManager::LoadConfig(const String& resolution, MapContainer& mapContainer, int width, int height)
460 {
461         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetTransformerN(__appBaseWidth, _CoordinateSystem::GetInstance()->GetLogicalBaseScreenSize(),
462         Dimension(width, height), BASE_SCREEN_SIZE_NORMAL);
463
464         if (pTransformer)
465         {
466                 _SCREEN_HEIGHT_ = pTransformer->Transform(__logicalHeight);
467         }
468         else
469         {
470                 _SCREEN_HEIGHT_ = __logicalHeight;
471         }
472
473         SysLog(NID_UI, "_SCREEN_HEIGHT_ : %d, resolution : %ls", _SCREEN_HEIGHT_, resolution.GetPointer());
474         int count = ConfigLoader::GetInstance()->GetInitFuncCount();
475         for (int i = 0; i < count; i++)
476         {
477                 _Init_Func func = null;
478                 ConfigLoader::GetInstance()->GetInitFunc(i, func);
479                 if (func)
480                 {
481                         func(mapContainer, resolution);
482                 }
483         }
484         delete pTransformer;
485 }
486
487 void
488 _ResourceManager::DoPostInitialization(void)
489 {
490         if (_AppInfo::IsOspCompat())
491         {
492                 SysLog(NID_UI, "Compatibility symbols are loaded.");
493                 SetSystemColor();
494         }
495 }
496
497 MapContainer*
498 _ResourceManager::GetMapContainer(MapContainerType type)
499 {
500         MapContainer* pContainer = null;
501         switch (type)
502         {
503                 case MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT:
504                         pContainer = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT];
505                         break;
506                 case MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE:
507                         if (__pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE])
508                         {
509                                 pContainer = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE];
510                         }
511                         else
512                         {
513                                 pContainer = new (std::nothrow) MapContainer();
514                                 SysTryReturn(NID_UI, pContainer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
515                                 pContainer->SetResolution(__appBaseLandscapeMode);
516                                 pContainer->CreateMap(RESOURCE_TYPE_SHAPE);
517                                 pContainer->CreateMap(RESOURCE_TYPE_DIMENSION);
518                                 pContainer->CreateMap(RESOURCE_TYPE_FIXED_VALUE);
519                                 LoadConfig(__appBaseLandscapeMode, *pContainer, __appBaseWidth, __appBaseHeight);
520                                 __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE] = pContainer;
521                         }
522                         break;
523                 case MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT:
524                         if (__pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT])
525                         {
526                                 pContainer = __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT];
527                         }
528                         else
529                         {
530                                 if(__defaultPortraitMode == __appBasePortraitMode)
531                                 {
532                                         __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT] = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT];
533                                         __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE] = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE];
534                                         pContainer = __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT];
535                                 }
536                                 else
537                                 {
538                                         pContainer = new (std::nothrow) MapContainer();
539                                         SysTryReturn(NID_UI, pContainer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
540                                         pContainer->SetResolution(__defaultPortraitMode);
541                                         pContainer->CreateMap(RESOURCE_TYPE_SHAPE);
542                                         pContainer->CreateMap(RESOURCE_TYPE_DIMENSION);
543                                         pContainer->CreateMap(RESOURCE_TYPE_FIXED_VALUE);
544                                         LoadConfig(__defaultPortraitMode, *pContainer, DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
545                                         __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT] = pContainer;
546                                 }
547                         }
548                         break;
549                 case MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE:
550                         if (__pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE])
551                         {
552                                 pContainer = __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE];
553                         }
554                         else
555                         {
556                                 if(__defaultPortraitMode == __appBasePortraitMode)
557                                 {
558                                         __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT] = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT];
559                                         __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE] = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE];
560                                         pContainer = __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE];
561                                 }
562                                 else
563                                 {
564                                         pContainer = new (std::nothrow) MapContainer();
565                                         SysTryReturn(NID_UI, pContainer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
566                                         pContainer->SetResolution(__defaultLandscapeMode);
567                                         pContainer->CreateMap(RESOURCE_TYPE_SHAPE);
568                                         pContainer->CreateMap(RESOURCE_TYPE_DIMENSION);
569                                         pContainer->CreateMap(RESOURCE_TYPE_FIXED_VALUE);
570                                         LoadConfig(__defaultLandscapeMode, *pContainer, DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
571                                         __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE] = pContainer;
572                                 }
573                         }
574                         break;
575                 default:
576                         break;
577         }
578         return pContainer;
579 }
580
581 _ResourceManager::~_ResourceManager(void)
582 {
583         delete __pStringLoader;
584         __pStringLoader = null;
585         delete __pTransformer;
586         __pTransformer = null;
587         delete __pFallbackList;
588         __pFallbackList = null;
589         bool deleteDefaultMap = true;
590         if (__pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT] == __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT])
591         {
592                 deleteDefaultMap = false;
593         }
594         delete __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT];
595         __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT] = null;
596         delete __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE];
597         __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE] = null;
598
599         if (deleteDefaultMap)
600         {
601                 delete __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT];
602                 __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT] = null;
603                 delete __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE];
604                 __pMapContainer[MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE] = null;
605         }
606
607         if (__initializeFeedback)
608         {
609                 if(feedback_deinitialize() != FEEDBACK_ERROR_NONE)
610                 {
611                         SysAssert(0);
612                 }
613         }
614 }
615 void
616 _ResourceManager::ReloadTheme(Tizen::Base::String& themeName, bool userdefine)
617 {
618         if(userdefine)
619         {
620                 __userTheme = themeName;
621         }
622         else
623         {
624                 __systemTheme = themeName;
625         }
626 }
627
628 result
629 _ResourceManager::GetBitmapInternalN(const String& fileName, BitmapPixelFormat pixelFormat, _ControlOrientation orientation, Bitmap*& pBitmap)
630 {
631         result r = E_SYSTEM;
632         Bitmap* pTempBitmap = null;
633         int foundFolderWidth = 0;
634         String fullName = FindImagePath(fileName, foundFolderWidth);
635         if(foundFolderWidth == __targetWidth)
636         {
637                 pTempBitmap = new (std::nothrow) Bitmap;
638                 SysTryReturn(NID_UI, pTempBitmap, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(r));
639                 r = _BitmapImpl::GetInstance(*pTempBitmap)->Construct(fullName, pixelFormat);
640                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
641                 pBitmap = pTempBitmap;
642                 return r;
643         }
644         else
645         {
646                 if (_BitmapImpl::HasNinePatchedBitmapTag(fileName))
647                 {
648                         pTempBitmap = new (std::nothrow) Bitmap;
649                         SysTryReturn(NID_UI, pTempBitmap, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(r));
650                         r = _BitmapImpl::GetInstance(*pTempBitmap)->Construct(fullName, pixelFormat);
651                         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
652                         pBitmap = pTempBitmap;
653                         return r;
654                 }
655                 else
656                 {
657                         ByteBuffer* pImageBuffer = null;
658                         int imageWidth = 0;
659                         int imageHeight = 0;
660                         MediaPixelFormat format = ConvertBitmapPixelFormatToMediaPixelFormat(pixelFormat);
661                         pImageBuffer = _ImageDecoder::DecodeToBufferN(fullName, format, imageWidth, imageHeight);
662                         if (pImageBuffer)
663                         {
664                                 pTempBitmap = _BitmapImpl::GetNonScaledBitmapN(*pImageBuffer, Dimension(imageWidth, imageHeight), pixelFormat);
665                                 delete pImageBuffer;
666                         }
667                         if(pTempBitmap != null)
668                         {
669                                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pTempBitmap))
670                                 {
671                                         pBitmap = pTempBitmap;
672                                         r = E_SUCCESS;
673                                 }
674                                 else
675                                 {
676                                         float scaleFactor = (float)((float)__targetWidth/(float)foundFolderWidth);
677
678                                         r = pTempBitmap->Scale(Dimension(imageWidth*scaleFactor, imageHeight*scaleFactor));
679                                         if (r == E_SUCCESS)
680                                         {
681                                                 pBitmap = pTempBitmap;
682                                         }
683                                         else
684                                         {
685                                                 delete pTempBitmap;
686                                         }
687                                 }
688                         }
689                 }
690         }
691         return r;
692 CATCH:
693         delete pTempBitmap;
694         return r;
695 }
696
697 result
698 _ResourceManager::GetBitmapN(const String& bitmapId, BitmapPixelFormat pixelFormat, _ControlOrientation orientation, Bitmap*& pBitmap)
699 {
700         result r = E_SYSTEM;
701         String* pFileName = null;
702         r = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetImageMap()->GetValue(bitmapId, pFileName);
703         if (r == E_SUCCESS)
704         {
705                 r = GetBitmapInternalN(*pFileName, pixelFormat, orientation, pBitmap);
706         }
707         return r;
708 }
709
710 result
711 _ResourceManager::GetString(const String& stringId, String& string)
712 {
713         return __pStringLoader->GetString(stringId, string);
714 }
715
716 result
717 _ResourceManager::GetColor(const String& colorId, Color& color)
718 {
719         result r = E_SYSTEM;
720         Color* pColor = null;
721         r = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetColorMap()->GetValue(colorId, pColor);
722         if(r == E_SUCCESS)
723         {
724                 color = *pColor;
725         }
726         return r;
727 }
728
729 result
730 _ResourceManager::GetDimension(const String& dimensionId, _ControlOrientation orientation, Dimension& dimension)
731 {
732         result r = E_SUCCESS;
733         Dimension dim(0, 0);
734
735         FloatDimension* pDimension = null;
736         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
737         {
738                 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT)->GetDimensionMap()->GetValue(dimensionId, pDimension);
739                 if (r != E_SUCCESS)
740                 {
741                         r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetDimensionMap()->GetValue(dimensionId, pDimension);
742                 }
743         }
744         else
745         {
746                 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetDimensionMap()->GetValue(dimensionId, pDimension);
747                 if (r != E_SUCCESS)
748                 {
749                         r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT)->GetDimensionMap()->GetValue(dimensionId, pDimension);
750                 }
751         }
752         if (r == E_SUCCESS)
753         {
754                 dim.SetSize(pDimension->width, pDimension->height);
755         }
756
757         if (r != E_SUCCESS)
758         {
759                 r = GetDefaultShapeWithScaling(dimensionId, orientation, dim);
760         }
761
762         if (r == E_SUCCESS)
763         {
764                 dimension = dim;
765         }
766
767         return r;
768 }
769
770 result
771 _ResourceManager::GetDimension(const Tizen::Base::String& dimensionId, _ControlOrientation orientation, Tizen::Graphics::FloatDimension& dimension)
772 {
773         result r = E_SUCCESS;
774         FloatDimension dim(0, 0);
775
776         FloatDimension* pDimension = null;
777         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
778         {
779                 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT)->GetDimensionMap()->GetValue(dimensionId, pDimension);
780                 if (r != E_SUCCESS)
781                 {
782                         r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetDimensionMap()->GetValue(dimensionId, pDimension);
783                 }
784         }
785         else
786         {
787                 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetDimensionMap()->GetValue(dimensionId, pDimension);
788                 if (r != E_SUCCESS)
789                 {
790                         r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT)->GetDimensionMap()->GetValue(dimensionId, pDimension);
791                 }
792         }
793         if (r == E_SUCCESS)
794         {
795                 dim = *pDimension;
796         }
797
798         if (r != E_SUCCESS)
799         {
800                 r = GetDefaultShapeWithScaling(dimensionId, orientation, dim);
801         }
802
803         if (r == E_SUCCESS)
804         {
805                 dimension = dim;
806         }
807
808         return r;
809 }
810
811 result
812 _ResourceManager::GetAnimationN(const String& animationId, ArrayList*& pList)
813 {
814         ResourceAnimationFrameList* pFrameList = null;
815         AnimationFrame* pFrame = null;
816         Bitmap* pBitmap = null;
817
818         result r = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetAnimationMap()->GetValue(animationId, pFrameList);
819         SysTryReturnResult(NID_UI, r == E_SUCCESS, E_SYSTEM,"System error is occured.");
820
821         if (pFrameList == null)
822         {
823                 return E_SYSTEM;
824         }
825         Tizen::Base::Collection::LinkedListT<ResourceAnimationFrame>* pAnimationList = static_cast<Tizen::Base::Collection::LinkedListT<ResourceAnimationFrame>* >(pFrameList->GetAnimationList());
826         if (pAnimationList == null)
827         {
828                 return E_SYSTEM;
829         }
830         int count = pAnimationList->GetCount();
831         if (count == 0)
832         {
833                 return E_SYSTEM;
834         }
835         pList = new (std::nothrow) ArrayList();
836         int i = 0;
837         for (; i < count ; i++)
838         {
839                 ResourceAnimationFrame frame;
840                 r = pAnimationList->GetAt(i, frame);
841                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM,"System error is occured.");
842                 r = GetBitmapInternalN(frame.__fileName, BITMAP_PIXEL_FORMAT_ARGB8888, _CONTROL_ORIENTATION_PORTRAIT, pBitmap);
843                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM,"System error is occured.");
844                 pFrame = new (std::nothrow) AnimationFrame(*pBitmap, frame.__duration);
845                 pList->Add(pFrame);
846                 delete pBitmap;
847         }
848         return E_SUCCESS;
849
850 CATCH:
851         delete pBitmap;
852         delete pFrame;
853         delete pList;
854         pList = null;
855         return E_SYSTEM;
856 }
857 result
858 _ResourceManager::GetShape(const String& shapeId, _ControlOrientation orientation, int& value)
859 {
860         result r = E_SUCCESS;
861         int outValue(-1);
862
863         Float* pFloat = null;
864         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
865         {
866                 r = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetShapeMap()->GetValue(shapeId, pFloat);
867                 if (r != E_SUCCESS)
868                 {
869                         r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pFloat);
870                 }
871         }
872         else
873         {
874                 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pFloat);
875                 if (r != E_SUCCESS)
876                 {
877                         r = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetShapeMap()->GetValue(shapeId, pFloat);
878                 }
879         }
880
881         if (r == E_SUCCESS)
882         {
883                 outValue = pFloat->ToInt();
884         }
885
886         if (r != E_SUCCESS)
887         {
888                 r = GetDefaultShapeWithScaling(shapeId, orientation, outValue);
889         }
890
891         if (r == E_SUCCESS)
892         {
893                 value = outValue;
894         }
895
896         return r;
897 }
898
899 result
900 _ResourceManager::GetShape(const Tizen::Base::String& shapeId, _ControlOrientation orientation, float& value)
901 {
902         result r = E_SUCCESS;
903         float outValue(-1);
904
905         Float* pFloat = null;
906         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
907         {
908                 r = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetShapeMap()->GetValue(shapeId, pFloat);
909                 if (r != E_SUCCESS)
910                 {
911                         r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pFloat);
912                 }
913         }
914         else
915         {
916                 r = GetMapContainer(MAP_CONTAINER_TYPE_APP_BASE_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pFloat);
917                 if (r != E_SUCCESS)
918                 {
919                         r = __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetShapeMap()->GetValue(shapeId, pFloat);
920                 }
921         }
922
923         if (r == E_SUCCESS)
924         {
925                 outValue = pFloat->ToFloat();
926         }
927
928         if (r != E_SUCCESS)
929         {
930                 r = GetDefaultShapeWithScaling(shapeId, orientation, outValue);
931         }
932
933         if (r == E_SUCCESS)
934         {
935                 value = outValue;
936         }
937         return r;
938 }
939
940 result
941 _ResourceManager::GetFixedValue(const String& fixedValueId, _ControlOrientation orientation, int& value)
942 {
943         result r = E_SUCCESS;
944         Float* pFloat = null;
945         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
946         {
947                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetFixedValueMap()->GetValue(fixedValueId, pFloat);
948                 if (r != E_SUCCESS)
949                 {
950
951                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetFixedValueMap()->GetValue(fixedValueId, pFloat);
952                 }
953         }
954         else
955         {
956                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetFixedValueMap()->GetValue(fixedValueId, pFloat);
957                 if (r != E_SUCCESS)
958                 {
959                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetFixedValueMap()->GetValue(fixedValueId, pFloat);
960                 }
961         }
962
963         if (r != E_SUCCESS)
964         {
965                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
966                 {
967                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(fixedValueId, pFloat);
968                         if (r != E_SUCCESS)
969                         {
970                                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(fixedValueId, pFloat);
971                         }
972                 }
973                 else
974                 {
975                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(fixedValueId, pFloat);
976                         if (r != E_SUCCESS)
977                         {
978                                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(fixedValueId, pFloat);
979                         }
980                 }
981         }
982
983         if (r == E_SUCCESS)
984         {
985                 value = pFloat->ToInt();
986         }
987
988         return r;
989 }
990
991 result
992 _ResourceManager::GetFixedValue(const Tizen::Base::String& fixedValueId, _ControlOrientation orientation, float& value)
993 {
994         result r = E_SUCCESS;
995         Float* pFloat = null;
996         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
997         {
998                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetFixedValueMap()->GetValue(fixedValueId, pFloat);
999                 if (r != E_SUCCESS)
1000                 {
1001
1002                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetFixedValueMap()->GetValue(fixedValueId, pFloat);
1003                 }
1004         }
1005         else
1006         {
1007                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetFixedValueMap()->GetValue(fixedValueId, pFloat);
1008                 if (r != E_SUCCESS)
1009                 {
1010                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetFixedValueMap()->GetValue(fixedValueId, pFloat);
1011                 }
1012         }
1013
1014         if (r != E_SUCCESS)
1015         {
1016                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1017                 {
1018                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(fixedValueId, pFloat);
1019                         if (r != E_SUCCESS)
1020                         {
1021                                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(fixedValueId, pFloat);
1022                         }
1023                 }
1024                 else
1025                 {
1026                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(fixedValueId, pFloat);
1027                         if (r != E_SUCCESS)
1028                         {
1029                                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(fixedValueId, pFloat);
1030                         }
1031                 }
1032         }
1033
1034         if (r == E_SUCCESS)
1035         {
1036                 value = pFloat->ToFloat();
1037         }
1038
1039         return r;
1040 }
1041
1042 bool
1043 _ResourceManager::IsCustomColor(const Tizen::Base::String& colorId)
1044 {
1045         return __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetColorMap()->IsUserThemeItem(colorId);
1046 }
1047 bool
1048 _ResourceManager::IsCustomBitmap(const Tizen::Base::String& bitmapId)
1049 {
1050         return __pMapContainer[MAP_CONTAINER_TYPE_APP_BASE_PORTRAIT]->GetImageMap()->IsUserThemeItem(bitmapId);
1051 }
1052
1053 result
1054 _ResourceManager::PlayFeedback(_ResourceFeedbackPattern pattern)
1055 {
1056         if (unlikely(__initializeFeedback == false))
1057         {
1058                 feedback_error_e error = (feedback_error_e)feedback_initialize();
1059                 if(error != FEEDBACK_ERROR_NONE)
1060                 {
1061                         SysAssert(0);
1062                 }
1063                 __initializeFeedback = true;
1064         }
1065         if (__feedbackStatus == _RESOURCE_FEEDBACK_STATUS_PLAYED)
1066         {
1067                 SysLog(NID_UI, "feedback is already played.");
1068                 return E_SUCCESS;
1069         }
1070         feedback_pattern_e playPattern = Convert_ResourceFeedbackPatternTofeedback_pattern_e(pattern);
1071         __feedbackStatus = _RESOURCE_FEEDBACK_STATUS_PLAYED;
1072         int r = feedback_play(playPattern);
1073         if (r == FEEDBACK_ERROR_NONE)
1074         {
1075                 SysLog(NID_UI, "It succeeded to play feedback.");
1076                 return E_SUCCESS;
1077         }
1078         else
1079         {
1080                 SysLog(NID_UI, "It failed to play feedback.");
1081                 return E_SYSTEM;
1082         }
1083         return E_SUCCESS;
1084 }
1085
1086 result
1087 _ResourceManager::GetDefaultShapeWithScaling(const String& shapeId, _ControlOrientation orientation, int& integer)
1088 {
1089         result r = E_SUCCESS;
1090         Float* pFloat = null;
1091         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1092         {
1093                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(shapeId, pFloat);
1094                 if (r != E_SUCCESS)
1095                 {
1096                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pFloat);
1097                 }
1098         }
1099         else
1100         {
1101                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pFloat);
1102                 if (r != E_SUCCESS)
1103                 {
1104                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(shapeId, pFloat);
1105                 }
1106         }
1107         if (r == E_SUCCESS)
1108         {
1109                 integer = pFloat->ToInt();
1110         }
1111
1112         if (r == E_SUCCESS)
1113         {
1114                 int temp = __pTransformer->Transform(integer);
1115                 if (temp == 0 && integer > 0)
1116                 {
1117                         integer = 1;
1118                 }
1119                 else
1120                 {
1121                         integer = temp;
1122                 }
1123         }
1124         return r;
1125 }
1126
1127 result
1128 _ResourceManager::GetDefaultShapeWithScaling(const Tizen::Base::String& shapeId, _ControlOrientation orientation, Tizen::Graphics::FloatDimension& dimension)
1129 {
1130         result r = E_SUCCESS;
1131         FloatDimension dim(0,0);
1132         FloatDimension* pDimension = null;
1133         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1134         {
1135                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetDimensionMap()->GetValue(shapeId, pDimension);
1136                 if (r != E_SUCCESS)
1137                 {
1138                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetDimensionMap()->GetValue(shapeId, pDimension);
1139                 }
1140         }
1141         else
1142         {
1143                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetDimensionMap()->GetValue(shapeId, pDimension);
1144                 if (r != E_SUCCESS)
1145                 {
1146                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetDimensionMap()->GetValue(shapeId, pDimension);
1147                 }
1148         }
1149         if (r == E_SUCCESS)
1150         {
1151                 dimension = __pTransformer->Transform(*pDimension);
1152         }
1153
1154         return r;
1155 }
1156
1157 result
1158 _ResourceManager::GetDefaultShapeWithScaling(const Tizen::Base::String& shapeId, _ControlOrientation orientation, float& outValue)
1159 {
1160         result r = E_SUCCESS;
1161         Float* pFloat = null;
1162
1163         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1164         {
1165                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(shapeId, pFloat);
1166                 if (r != E_SUCCESS)
1167                 {
1168                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pFloat);
1169                 }
1170         }
1171         else
1172         {
1173                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetShapeMap()->GetValue(shapeId, pFloat);
1174                 if (r != E_SUCCESS)
1175                 {
1176                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetShapeMap()->GetValue(shapeId, pFloat);
1177                 }
1178         }
1179
1180         if (r == E_SUCCESS)
1181         {
1182                 outValue = pFloat->ToFloat();
1183                 outValue = __pTransformer->Transform(outValue);
1184         }
1185
1186         return r;
1187 }
1188
1189 result
1190 _ResourceManager::GetDefaultShapeWithScaling(const String& shapeId, _ControlOrientation orientation, Dimension& dimension)
1191 {
1192         result r = E_SUCCESS;
1193         Dimension dim(0,0);
1194         FloatDimension* pDimension = null;
1195         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1196         {
1197                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetDimensionMap()->GetValue(shapeId, pDimension);
1198                 if (r != E_SUCCESS)
1199                 {
1200                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetDimensionMap()->GetValue(shapeId, pDimension);
1201                 }
1202         }
1203         else
1204         {
1205                 r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_LANDSCAPE)->GetDimensionMap()->GetValue(shapeId, pDimension);
1206                 if (r != E_SUCCESS)
1207                 {
1208                         r = GetMapContainer(MAP_CONTAINER_TYPE_DEFAULT_PORTRAIT)->GetDimensionMap()->GetValue(shapeId, pDimension);
1209                 }
1210         }
1211         if (r == E_SUCCESS)
1212         {
1213                 dim.SetSize(pDimension->width, pDimension->height);
1214         }
1215
1216         if (r == E_SUCCESS)
1217         {
1218                 Dimension temp = __pTransformer->Transform(dim);
1219                 if (temp.width == 0 && dim.width > 0)
1220                 {
1221                         temp.width = 1;
1222                 }
1223                 if (temp.height == 0 && dim.height > 0)
1224                 {
1225                         temp.height = 1;
1226                 }
1227                 dimension = temp;
1228         }
1229         return r;
1230 }
1231
1232 result
1233 _ResourceManager::LoadThemeInformation(String& systemTheme, String& userTheme)
1234 {
1235         AppId appId = _AppInfo::GetPackageId();
1236         IMap* pList = null;
1237         pList = _PackageManagerImpl::GetInstance()->GetUiThemeListN(appId);
1238
1239         if (pList)
1240         {
1241                 IMapEnumerator* pMapEnum = pList->GetMapEnumeratorN();
1242                 while (pMapEnum->MoveNext() == E_SUCCESS)
1243                 {
1244                         String* pKey = static_cast<String*> (pMapEnum->GetKey());
1245                         String* pValue = static_cast<String*> (pMapEnum->GetValue());
1246                         String key(*pKey);
1247                         key.ToLowerCase();
1248                         if (key == L"systemtheme")
1249                         {
1250                                 systemTheme = *pValue;
1251                                 systemTheme.ToLowerCase();
1252                         }
1253                         if (key == L"userdefinedtheme")
1254                         {
1255                                 userTheme = *pValue;
1256                         }
1257                 }
1258                 delete pMapEnum;
1259
1260                 pList->RemoveAll(true);
1261                 delete pList;
1262         }
1263         if (systemTheme.GetLength() < 1)
1264         {
1265                 systemTheme = L"black";
1266         }
1267         return E_SUCCESS;
1268 }
1269
1270 void
1271 _ResourceManager::GetThemeName(String& systemTheme, String& userTheme) const
1272 {
1273         systemTheme = __systemTheme;
1274         userTheme = __userTheme;
1275 }
1276
1277 void
1278 _ResourceManager::SetSystemColor(void)
1279 {
1280         void* handle =null;
1281         Color* pColor = null;
1282         Color* (*GetSystemColor)(const String&) = null;
1283
1284         handle = dlopen ("libosp-compat.so", RTLD_LAZY);
1285         if (!handle)
1286         {
1287                 return;
1288         }
1289         GetSystemColor = reinterpret_cast<Color*(*)(const String&)>(dlsym(handle, "_GetSystemColor"));
1290         if (dlerror() != NULL)
1291         {
1292                 goto CATCH;
1293         }
1294
1295         pColor = GetSystemColor(L"TITLE_TEXT");
1296         if (pColor != null)
1297         {
1298                 GET_COLOR_CONFIG(HEADER::TITLE_TEXT_NORMAL, *pColor);
1299         }
1300
1301         pColor = GetSystemColor(L"BODY_TEXT");
1302         if (pColor != null)
1303         {
1304                 GET_COLOR_CONFIG(BUTTON::TEXT_NORMAL, *pColor);
1305         }
1306
1307         pColor = GetSystemColor(L"FOREGROUND");
1308         if (pColor != null)
1309         {
1310                 GET_COLOR_CONFIG(BASIC::foreground, *pColor);
1311         }
1312
1313         pColor = GetSystemColor(L"BACKGROUND");
1314         if (pColor != null)
1315         {
1316                 GET_COLOR_CONFIG(BASIC::background, *pColor);
1317         }
1318
1319         pColor = GetSystemColor(L"LIST_BACKGROUND");
1320         if (pColor != null)
1321         {
1322                 GET_COLOR_CONFIG(FORM::BG_NORMAL, *pColor);
1323         }
1324
1325         pColor = GetSystemColor(L"FORM_BACKGROUND");
1326         if (pColor != null)
1327         {
1328                 GET_COLOR_CONFIG(FORM::BG_NORMAL, *pColor);
1329         }
1330
1331         pColor = GetSystemColor(L"FORM_GROUP_BACKGROUND");
1332         if (pColor != null)
1333         {
1334                 GET_COLOR_CONFIG(PANEL::GROUPED_STYLE_BG_NORMAL, *pColor);
1335         }
1336
1337         pColor = GetSystemColor(L"POPUP_BACKGROUND");
1338         if (pColor != null)
1339         {
1340                 GET_COLOR_CONFIG(POPUP::BG_NORMAL, *pColor);
1341         }
1342
1343         pColor = GetSystemColor(L"GROUP_ITEM_TEXT");
1344         if (pColor != null)
1345         {
1346                 GET_COLOR_CONFIG(CHECKBUTTON::TEXT_NORMAL, *pColor);
1347         }
1348
1349         pColor = GetSystemColor(L"LIST_ITEM_TEXT");
1350         if (pColor != null)
1351         {
1352                 GET_COLOR_CONFIG(LISTVIEW::ITEM_TEXT_NORMAL, *pColor);
1353         }
1354
1355         pColor = GetSystemColor(L"LIST_ITEM_PRESSED_TEXT");
1356         if (pColor != null)
1357         {
1358                 GET_COLOR_CONFIG(LISTVIEW::ITEM_TEXT_PRESSED, *pColor);
1359         }
1360
1361         pColor = GetSystemColor(L"LIST_ITEM_HIGHLIGHTED_TEXT");
1362         if (pColor != null)
1363         {
1364                 GET_COLOR_CONFIG(LISTVIEW::ITEM_TEXT_HIGHLIGHTED, *pColor);
1365         }
1366
1367         //fall through
1368 CATCH:
1369         dlclose(handle);
1370         return;
1371 }
1372 bool
1373 _ResourceManager::GetDensityDirectory(const String& directoryName, float& scaleFactor)
1374 {
1375         float denominator = 0.0;
1376         float numerator = 0.0;
1377         if(!(directoryName.StartsWith(L"screen-density",0)))
1378         {
1379                 return false;
1380         }
1381
1382         if (__deviceDPI >= DPI_FOR_XHIGH)
1383         {
1384                 numerator = 9.0;
1385         }
1386         else if (__deviceDPI >= DPI_FOR_HIGH)
1387         {
1388                 numerator = 6.0;
1389         }
1390         else if (__deviceDPI >= DPI_FOR_MIDDLE)
1391         {
1392                 numerator = 4.0;
1393         }
1394         else if (__deviceDPI < DPI_FOR_MIDDLE && __deviceDPI > DPI_FOR_LOW)
1395         {
1396                 numerator = 3.0;
1397         }
1398         else
1399         {
1400                 return false;
1401         }
1402
1403         if(directoryName.Contains(L"xhigh"))
1404         {
1405                 denominator = 9.0;
1406         }
1407         else if(directoryName.Contains(L"high"))
1408         {
1409                 denominator = 6.0;
1410         }
1411         else if(directoryName.Contains(L"middle"))
1412         {
1413                 denominator = 4.0;
1414         }
1415         else if(directoryName.Contains(L"low"))
1416         {
1417                 denominator = 3.0;
1418         }
1419         else
1420         {
1421                 return false;
1422         }
1423
1424         scaleFactor = numerator / denominator;
1425         return true;
1426 }
1427
1428 bool
1429 _ResourceManager::GetResolutionDirectory(const String& directoryName, float& scaleFactor)
1430 {
1431         if(!(directoryName.Contains(L"0")))
1432         {
1433                 return false;
1434         }
1435
1436         int index = 0;
1437         if(directoryName.IndexOf(L"x", 0, index) != E_SUCCESS)
1438         {
1439                 return false;
1440         }
1441         String width = 0;
1442
1443         if(directoryName.SubString(0, index - 1, width))
1444         {
1445                 int denominatorInt = 0;
1446                 float denominator = 0;
1447                 float numerator = 0;
1448                 if(Integer::Parse(width, denominatorInt) == E_SUCCESS)
1449                 {
1450                         denominator = (float)denominatorInt;
1451                         numerator = __targetWidth;
1452                         scaleFactor = numerator / denominator;
1453                         return true;
1454                 }
1455         }
1456         return false;
1457 }
1458
1459 String
1460 _ResourceManager::FindImagePath(const String& fileName, int& foundFolderWidth)
1461 {
1462         bool find = false;
1463         String fullName(L"");
1464         ResourceFallbackItem* pItem = null;
1465
1466         if(__userTheme.GetLength() > 0)
1467         {
1468                 String resDirectory = _AppInfo::GetAppRootPath() + L"res/themes/"+__userTheme;
1469                 if(__pFallbackList == null)
1470                 {
1471                         __pFallbackList = new (std::nothrow) ArrayListT<ResourceFallbackItem*>;
1472                         SysTryReturn(NID_UI, __pFallbackList, L"", E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
1473                         Directory dir;
1474                         result r = dir.Construct(resDirectory);
1475                         if (r == E_SUCCESS)
1476                         {
1477                                 DirEnumerator* pDirEnum = dir.ReadN();
1478                                 if (pDirEnum != null)
1479                                 {
1480                                         while (pDirEnum->MoveNext() == E_SUCCESS)
1481                                         {
1482                                                 DirEntry entry = pDirEnum->GetCurrentDirEntry();
1483                                                 if(entry.IsDirectory())
1484                                                 {
1485                                                         float scaleFactor = 0;
1486                                                         String directoryName = entry.GetName();
1487                                                         if(GetDensityDirectory(directoryName, scaleFactor))
1488                                                         {
1489                                                                 pItem = new (std::nothrow) ResourceFallbackItem;
1490                                                                 SysTryCatch(NID_UI, pItem, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
1491                                                                 pItem->scaleFactor = scaleFactor;
1492                                                                 pItem->directoryName = directoryName;
1493                                                                 __pFallbackList->Add(pItem);
1494                                                         }
1495                                                         else if(GetResolutionDirectory(directoryName, scaleFactor))
1496                                                         {
1497                                                                 pItem = new (std::nothrow) ResourceFallbackItem;
1498                                                                 SysTryCatch(NID_UI, pItem, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
1499                                                                 pItem->scaleFactor = scaleFactor;
1500                                                                 pItem->directoryName = directoryName;
1501                                                                 __pFallbackList->Add(pItem);
1502                                                         }
1503                                                 }
1504                                         }
1505                                         ResourceFallbackItemComparer<ResourceFallbackItem*> comparer;
1506                                         __pFallbackList->Sort(comparer);
1507                                         delete pDirEnum;
1508                                 }
1509                                 for(int i = 0 ; i < __pFallbackList->GetCount() ; i++)
1510                                 {
1511                                         ResourceFallbackItem* pItem;
1512                                         if(__pFallbackList->GetAt(i,pItem) == E_SUCCESS)
1513                                         {
1514                                                 if(pItem->scaleFactor < 1.001 && pItem->scaleFactor > 0.999)
1515                                                 {
1516                                                         __pFallbackList->RemoveAt(i);
1517                                                         __pFallbackList->InsertAt(pItem,0);
1518                                                         if(pItem->directoryName.Contains(L"0"))
1519                                                         {
1520                                                                 break;
1521                                                         }
1522                                                 }
1523                                         }
1524                                 }
1525                         }
1526                 }
1527                 for(int i = 0 ; i <__pFallbackList->GetCount() ; i++)
1528                 {
1529                         ResourceFallbackItem* pItem;
1530                         __pFallbackList->GetAt(i,pItem);
1531                         fullName = resDirectory + L"/" + pItem->directoryName + L"/" + fileName;
1532                         if (File::IsFileExist(fullName))
1533                         {
1534                                 find = true;
1535                                 foundFolderWidth = __targetWidth / pItem->scaleFactor;
1536                                 if(foundFolderWidth > __targetWidth)
1537                                 {
1538                                         if( foundFolderWidth < __targetWidth + 3)
1539                                         {
1540                                                 foundFolderWidth = __targetWidth;
1541                                         }
1542                                 }
1543                                 else
1544                                 {
1545                                         if( foundFolderWidth >__targetWidth - 3)
1546                                         {
1547                                                 foundFolderWidth = __targetWidth;
1548                                         }
1549                                 }
1550                                 break;
1551                         }
1552                 }
1553         }
1554         if(!find)
1555         {
1556                 fullName = String(L"/usr/share/osp/bitmaps/" + __targetPortraitMode+ "/" + __systemTheme + L"/" + fileName);
1557                 if (File::IsFileExist(fullName))
1558                 {
1559                         find = true;
1560                         foundFolderWidth = __targetWidth;
1561                 }
1562                 else
1563                 {
1564                         fullName = String(L"/usr/share/osp/bitmaps/" + __defaultPortraitMode+ "/" + __systemTheme + L"/" + fileName);
1565                         if (File::IsFileExist(fullName))
1566                         {
1567                                 find = true;
1568                                 foundFolderWidth = DEFAULT_SCREEN_WIDTH;
1569                         }
1570                 }
1571         }
1572
1573         if(!find)
1574         {
1575                 fullName = String(L"/usr/share/osp/bitmaps/" + __targetPortraitMode + "/" + fileName);
1576                 if (File::IsFileExist(fullName))
1577                 {
1578                         find = true;
1579                         foundFolderWidth = __targetWidth;
1580                 }
1581                 else
1582                 {
1583                         fullName = String(L"/usr/share/osp/bitmaps/" + __defaultPortraitMode+ "/" + fileName);
1584                         if (File::IsFileExist(fullName))
1585                         {
1586                                 find = true;
1587                                 foundFolderWidth = DEFAULT_SCREEN_WIDTH;
1588                         }
1589                 }
1590         }
1591
1592         if(!find)
1593         {
1594                 return L"";
1595         }
1596         else
1597         {
1598                 return fullName;
1599         }
1600 CATCH:
1601         delete __pFallbackList;
1602         __pFallbackList = null;
1603         return L"";
1604 }
1605
1606 void
1607 _ResourceManager::AcquireFeedback(void)
1608 {
1609         ++__feedbackAcquireCount;
1610 }
1611
1612 void
1613 _ResourceManager::ReleaseFeedback(void)
1614 {
1615         --__feedbackAcquireCount;
1616         if(__feedbackAcquireCount == 0)
1617         {
1618                 __feedbackStatus = _RESOURCE_FEEDBACK_STATUS_INIT;
1619         }
1620 }
1621
1622 }}//Tizen::Ui