Applied latest source code
[apps/native/preloaded/Settings.git] / src / StResourceManager.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                StResourceManager.cpp
19  * @brief               This is the implementation file for ResourceManager class.
20  */
21
22 #include <FMedia.h>
23 #include "StResourceManager.h"
24
25 using namespace Tizen::App;
26 using namespace Tizen::Base;
27 using namespace Tizen::Graphics;
28 using namespace Tizen::Media;
29 using namespace Tizen::Ui;
30
31 Bitmap*
32 ResourceManager::GetBitmapN(const Tizen::Base::String& imagePath)
33 {
34         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
35         if (pAppResource == null)
36         {
37                 AppLogDebug("[%s] Unable to get app resource.");
38                 return null;
39         }
40
41         return pAppResource->GetBitmapN(imagePath);
42 }
43
44 Bitmap*
45 ResourceManager::GetApplicationBitmapN(const String& imageAbsolutePath)
46 {
47         result r = E_SUCCESS;
48         Bitmap* pBitmap = null;
49         Image* pImage = new (std::nothrow) Image();
50
51         String fullname;
52         fullname.Append(imageAbsolutePath);
53
54         if (pImage != null)
55         {
56                 r = pImage->Construct();
57                 TryCatch(r == E_SUCCESS, , "Image Construct Failed = (%s)\n", GetErrorMessage(r));
58                 if (fullname.EndsWith(L"jpg") || fullname.EndsWith(L"JPG") || fullname.EndsWith(L"jpeg") || fullname.EndsWith(L"JPEG"))
59                 {
60                         pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);
61                 }
62                 else if (fullname.EndsWith(L"bmp") || fullname.EndsWith(L"BMP"))
63                 {
64                         pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);
65                 }
66                 else if (fullname.EndsWith(L"png") || fullname.EndsWith(L"PNG") || fullname.EndsWith(L"wbmp") || fullname.EndsWith(L"WBMP"))
67                 {
68                         pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_ARGB8888);
69                 }
70                 else if (fullname.EndsWith(L"gif") || fullname.EndsWith(L"GIF"))
71                 {
72                         pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);
73                 }
74
75                 TryCatch(pBitmap != null, , "not found image path or not enough memory %ls error = %s", fullname.GetPointer()
76                                 , GetErrorMessage(GetLastResult()));
77
78                 delete pImage;
79                 return pBitmap;
80         }
81
82 CATCH:
83         if (pImage != null)
84         {
85                 delete pImage;
86         }
87
88         return null;
89 }
90
91 String
92 ResourceManager::GetString(const Tizen::Base::String& stringId)
93 {
94         String str;
95         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
96
97         if (pAppResource == null)
98         {
99                 AppLogDebug("Unable to get resource instance.");
100                 return str;
101         }
102
103         pAppResource->GetString(stringId, str);
104
105         return str;
106 }