3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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 /*@file: IntCommonUtil.cpp
20 *@brief: To define the common method of Internet application
26 #include "IntCommonLib.h"
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Media;
32 using namespace Tizen::System;
34 const int FONT_MAIN_TEXT_SIZE_GIANT = 98;
35 const int FONT_MAIN_TEXT_SIZE_HUGE = 81;
36 const int FONT_MAIN_TEXT_SIZE_LARGE = 64;
37 const int FONT_MAIN_TEXT_SIZE_NORMAL = 44;
38 const int FONT_MAIN_TEXT_SIZE_SMALL = 36;
39 const wchar_t* SETTING_INFO_KEY_FONT_SIZE = L"http://tizen.org/setting/font.size";
41 CommonBitmapTable CommonUtil::__commonBitmapTable[] = {
43 // -------- End of table -----------------------------------------------------
46 } // DO NOT REPLACE THIS LINE
50 CommonUtil::GetString(const String& resourceId)
55 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
59 tmpString = "(Error)";
63 r = pAppResource->GetString(resourceId, tmpString);
65 TryCatch( !IsFailed(r),,"CommonUtil::GetString ,pAppResource->GetString Failed %s",GetErrorMessage(r));
69 tmpString = "(Error)";
74 CommonUtil::GetBitmapN(const String& path, const int width, const int height)
76 Bitmap* pBitmap = null;
77 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
79 if (pAppResource == null)
89 if (width <= 0 || height <= 0)
94 AppLogDebug("Calling Decode method for image %ls", path.GetPointer());
95 pBitmap = pAppResource->GetBitmapN(path, BITMAP_PIXEL_FORMAT_ARGB8888);
96 AppLogDebug("Image Decoded successfully");
103 if (width > 0 && height > 0)
105 pBitmap->Scale(Dimension(width, height));
113 CommonUtil::GetBitmap(uint id)
115 AppLogDebug("CommonUtil::GetBitmap entered");
117 Bitmap* pBitmap = null;
119 if (__commonBitmapTable[id].ptr)
121 pBitmap = __commonBitmapTable[id].ptr;
122 AppLogDebug("found already used bitmap pointer");
126 AppLogDebug("Not found #%d bitmap data in cache. Start loading...\n", (int) id);
127 pBitmap = GetBitmapN(__commonBitmapTable[id].filename,
128 __commonBitmapTable[id].width,
129 __commonBitmapTable[id].height);
132 AppLogDebug("Error: Failed to load #%d bitmap.\n", (int) id);
136 __commonBitmapTable[id].ptr = pBitmap;
139 __commonBitmapTable[id].refcount++;
140 AppLogDebug("CommonUtil::GetBitmap exit");
145 CommonUtil::GetNinepatchedBitmapN(const String& strPath, const int width, const int height)
147 Bitmap* pBmp = UiApp::GetInstance()->GetAppResource()->GetBitmapN(strPath);
151 AppLogDebug("Couldn't create bitmap %ls error(%s)",strPath.GetPointer(),GetErrorMessage(GetLastResult()));
155 Bitmap* pBitmap = null;
156 result r = E_SUCCESS;
158 Canvas* pCanvas = new(std::nothrow) Canvas();
159 TryCatch(pCanvas != null, , "Canvas new Fail.");
160 r = pCanvas->Construct(Rectangle(0,0,width, height));
161 TryCatch(r == E_SUCCESS, , "Canvas Construct Fail.");
163 r = pCanvas->DrawNinePatchedBitmap(Rectangle(0,0,width, height), *pBmp);
167 AppLogDebug("DrawNinePatchedBitmap Error %ls", GetErrorMessage(r));
168 pCanvas->DrawBitmap(Rectangle(0,0,width, height), *pBmp);
171 pBitmap = new(std::nothrow) Bitmap();
172 TryCatch(pBitmap != null, , "Bitmap new Fail.");
174 r = pBitmap->Construct(*pCanvas, Rectangle(0,0,width, height));
175 TryCatch(r == E_SUCCESS, , "Bitmap Construct Fail.");
209 CommonUtil::GetFontSize(void)
211 int fontSize = FONT_MAIN_TEXT_SIZE_NORMAL;
212 String fontSizeValue;
214 if (SettingInfo::GetValue(SETTING_INFO_KEY_FONT_SIZE, fontSizeValue) == E_SUCCESS)
216 if (fontSizeValue.Equals(L"giant", false))
218 fontSize = FONT_MAIN_TEXT_SIZE_GIANT;
220 else if (fontSizeValue.Equals(L"huge", false))
222 fontSize = FONT_MAIN_TEXT_SIZE_HUGE;
224 else if (fontSizeValue.Equals(L"large", false))
226 fontSize = FONT_MAIN_TEXT_SIZE_LARGE;
228 else if (fontSizeValue.Equals(L"medium", false))
230 fontSize = FONT_MAIN_TEXT_SIZE_NORMAL;
234 fontSize = FONT_MAIN_TEXT_SIZE_SMALL;