3 // Copyright (c) 2012 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 /*@file: IntCommonUtil.cpp
20 *@brief: To define the common method of Internet application
25 #include "IntCommonLib.h"
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Media;
32 CommonBitmapTable CommonUtil::__commonBitmapTable[] = {
34 // -------- End of table -----------------------------------------------------
37 } // DO NOT REPLACE THIS LINE
41 CommonUtil::GetString(const String& resourceId)
46 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
50 tmpString = "(Error)";
54 r = pAppResource->GetString(resourceId, tmpString);
56 TryCatch( !IsFailed(r),,"CommonUtil::GetString ,pAppResource->GetString Failed %s",GetErrorMessage(r));
60 tmpString = "(Error)";
65 CommonUtil::GetBitmapN(const String& path, const int width, const int height)
67 Bitmap* pBitmap = null;
68 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
70 if (pAppResource == null)
80 if (width <= 0 || height <= 0)
85 AppLogDebug("Calling Decode method for image %ls", path.GetPointer());
86 pBitmap = pAppResource->GetBitmapN(path, BITMAP_PIXEL_FORMAT_ARGB8888);
87 AppLogDebug("Image Decoded successfully");
94 if (width > 0 && height > 0)
96 pBitmap->Scale(Dimension(width, height));
104 CommonUtil::GetBitmap(uint id)
106 AppLogDebug("CommonUtil::GetBitmap entered");
108 Bitmap* pBitmap = null;
110 if (__commonBitmapTable[id].ptr)
112 pBitmap = __commonBitmapTable[id].ptr;
113 AppLogDebug("found already used bitmap pointer");
117 AppLogDebug("Not found #%d bitmap data in cache. Start loading...\n", (int) id);
118 pBitmap = GetBitmapN(__commonBitmapTable[id].filename,
119 __commonBitmapTable[id].width,
120 __commonBitmapTable[id].height);
123 AppLogDebug("Error: Failed to load #%d bitmap.\n", (int) id);
127 __commonBitmapTable[id].ptr = pBitmap;
130 __commonBitmapTable[id].refcount++;
131 AppLogDebug("CommonUtil::GetBitmap exit");
136 CommonUtil::GetNinepatchedBitmapN(const String& strPath, const int width, const int height)
138 Bitmap* pBmp = UiApp::GetInstance()->GetAppResource()->GetBitmapN(strPath);
142 AppLogDebug("Couldn't create bitmap %ls error(%s)",strPath.GetPointer(),GetErrorMessage(GetLastResult()));
146 Bitmap* pBitmap = null;
147 result r = E_SUCCESS;
149 Canvas* pCanvas = new(std::nothrow) Canvas();
150 TryCatch(pCanvas != null, , "Canvas new Fail.");
151 r = pCanvas->Construct(Rectangle(0,0,width, height));
152 TryCatch(r == E_SUCCESS, , "Canvas Construct Fail.");
154 r = pCanvas->DrawNinePatchedBitmap(Rectangle(0,0,width, height), *pBmp);
158 AppLogDebug("DrawNinePatchedBitmap Error %ls", GetErrorMessage(r));
159 pCanvas->DrawBitmap(Rectangle(0,0,width, height), *pBmp);
162 pBitmap = new(std::nothrow) Bitmap();
163 TryCatch(pBitmap != null, , "Bitmap new Fail.");
165 r = pBitmap->Construct(*pCanvas, Rectangle(0,0,width, height));
166 TryCatch(r == E_SUCCESS, , "Bitmap Construct Fail.");