2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
\r
4 // Licensed under the Flora License, Version 1.1 (the License);
\r
5 // you may not use this file except in compliance with the License.
\r
6 // You may obtain a copy of the License at
\r
8 // http://floralicense.org/license/
\r
10 // Unless required by applicable law or agreed to in writing, software
\r
11 // distributed under the License is distributed on an AS IS BASIS,
\r
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 // See the License for the specific language governing permissions and
\r
14 // limitations under the License.
\r
18 * @file: MfUtility.cpp
\r
19 * @brief: This file contains the implementation of MfUtility class, which is a common utility function class and
\r
20 * contains helper functions which are used throughout the Application.
\r
23 #include "MfUtility.h"
\r
25 using namespace Tizen::App;
\r
26 using namespace Tizen::Base;
\r
27 using namespace Tizen::Base::Utility;
\r
28 using namespace Tizen::Graphics;
\r
29 using namespace Tizen::Locales;
\r
31 MfUtility::MfUtility(void)
\r
33 // Empty Implementation
\r
37 MfUtility::~MfUtility(void)
\r
39 // Empty Implementation
\r
43 MfUtility::operator =(const MfUtility& mfUtility)
\r
48 MfUtility::MfUtility(const MfUtility& mfUtility)
\r
55 MfUtility::ConvertFileSizeToString(long long int fileSize)
\r
57 AppLogDebug("Entry");
\r
58 AppResource* pAppResource = null;
\r
60 pAppResource = Application::GetInstance()->GetAppResource();
\r
62 float preciseFileSize = (float)fileSize / (float)MB_DIVISOR;
\r
64 if ((int)preciseFileSize == 0.0)
\r
66 preciseFileSize = (float)fileSize / (float)KB_DIVISOR;
\r
67 if ((int)preciseFileSize == 0)
\r
70 pAppResource->GetString(L"IDS_BYTES", bytes);
\r
71 size.Append(fileSize);
\r
78 pAppResource->GetString(L"IDS_COM_BODY_KB", kb);
\r
79 size.Append(preciseFileSize);
\r
87 pAppResource->GetString(L"IDS_COM_BODY_MB", mb);
\r
88 size.Append(preciseFileSize);
\r
92 AppLogDebug("Exit");
\r
97 MfUtility::ConvertDateTimeToString(Tizen::Base::DateTime fileCreationTime)
\r
99 AppLogDebug("Entry");
\r
100 String dateAndTime;
\r
101 String cutomizedPattern;
\r
102 DateTimeFormatter* pDateFormatter = null;
\r
103 //DateTimeFormatter* pTimeFormatter = null;
\r
104 DateTime dirCreationTime;
\r
105 Locale locale(LANGUAGE_ENG, COUNTRY_US);
\r
107 dirCreationTime = fileCreationTime;
\r
109 pDateFormatter = DateTimeFormatter::CreateDateFormatterN(locale, DATE_TIME_STYLE_DEFAULT);
\r
110 TryCatch(pDateFormatter != null, dateAndTime.Append("Not Found"), "Failed to get date time formatter");
\r
112 // Customized pattern
\r
113 cutomizedPattern.Append(L"d MMM, yyyy HH:mm");
\r
114 pDateFormatter->ApplyPattern(cutomizedPattern);
\r
116 // Format creation time with date formatter
\r
117 pDateFormatter->Format(dirCreationTime, dateAndTime);
\r
119 //if (pDateFormatter != null)
\r
121 delete pDateFormatter;
\r
122 pDateFormatter = null;
\r
125 AppLogDebug("Exit");
\r
126 return dateAndTime;
\r
130 AppLogDebug("Exit");
\r
131 return dateAndTime;
\r
134 Tizen::Graphics::Bitmap*
\r
135 MfUtility::GetNinepatchedBitmapN(const String& strPath, const int width, const int height)
\r
137 Bitmap* bmp = null;
\r
138 AppResource* pAppResource = null;
\r
140 pAppResource = Application::GetInstance()->GetAppResource();
\r
141 bmp = pAppResource->GetBitmapN(strPath, BITMAP_PIXEL_FORMAT_ARGB8888);
\r
148 Bitmap* ret = null;
\r
149 result r = E_SUCCESS;
\r
151 Canvas* pCanvas = new (std::nothrow) Canvas();
\r
152 TryCatch(pCanvas != null, , "Canvas new Fail.");
\r
153 r = pCanvas->Construct(Rectangle(0, 0, width, height));
\r
154 TryCatch(r == E_SUCCESS, , "Canvas Construct Fail.");
\r
156 r = pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, width, height), *bmp);
\r
157 if (r != E_SUCCESS)
\r
159 AppLogDebug("DrawNinePatchedBitmap Error %S", GetErrorMessage(r));
\r
160 pCanvas->DrawBitmap(Rectangle(0, 0, width, height), *bmp);
\r
162 ret = new (std::nothrow) Bitmap();
\r
163 TryCatch(ret != null, , "Bitmap new Fail.");
\r
164 r = ret->Construct(*pCanvas, Rectangle(0, 0, width, height));
\r
165 TryCatch(r == E_SUCCESS, , "Bitmap Construct Fail.");
\r
171 if (pCanvas != null)
\r
184 if (pCanvas != null)
\r
197 Tizen::Graphics::Bitmap*
\r
198 MfUtility::MergeBitmapN(const Tizen::Base::String& firstBitmapPath, const Tizen::Base::String& secondBitmapPath, const int width, const int height)
\r
200 Bitmap* pFirstBitmap = null;
\r
201 Bitmap* pSecondBitmap = null;
\r
203 Bitmap* pMergedBitmap = null;
\r
205 AppResource* pAppResource = null;
\r
207 pAppResource = Application::GetInstance()->GetAppResource();
\r
208 pFirstBitmap = pAppResource->GetBitmapN(firstBitmapPath, BITMAP_PIXEL_FORMAT_ARGB8888);
\r
209 pSecondBitmap = pAppResource->GetBitmapN(secondBitmapPath, BITMAP_PIXEL_FORMAT_ARGB8888);
\r
211 if (!pFirstBitmap || !pSecondBitmap)
\r
216 result r = E_SUCCESS;
\r
218 Canvas* pCanvas = new (std::nothrow) Canvas();
\r
219 TryCatch(pCanvas != null, , "Canvas new Fail.");
\r
221 r = pCanvas->Construct(Rectangle(0, 0, width, height));
\r
222 TryCatch(r == E_SUCCESS, , "Canvas Construct Fail.");
\r
224 pCanvas->DrawBitmap(Rectangle(0, 0, width, height), *pFirstBitmap);
\r
225 pCanvas->DrawBitmap(Rectangle(0, 0, width, height), *pSecondBitmap);
\r
227 pMergedBitmap = new (std::nothrow) Bitmap();
\r
228 pMergedBitmap->Construct(*pCanvas, Rectangle(0, 0, width, height));
\r
230 if (pFirstBitmap != null)
\r
232 delete pFirstBitmap;
\r
233 pFirstBitmap = null;
\r
236 if (pSecondBitmap != null)
\r
238 delete pSecondBitmap;
\r
239 pSecondBitmap = null;
\r
242 if (pCanvas != null)
\r
248 return pMergedBitmap;
\r
251 if (pCanvas != null)
\r
257 if (pFirstBitmap != null)
\r
259 delete pFirstBitmap;
\r
260 pFirstBitmap = null;
\r
263 if (pSecondBitmap != null)
\r
265 delete pSecondBitmap;
\r
266 pSecondBitmap = null;
\r
271 Tizen::Graphics::Bitmap*
\r
272 MfUtility::MergeBitmapN(Tizen::Graphics::Bitmap* pFirstBitmap, const Tizen::Graphics::Bitmap* pSecondBitmap, const int width, const int height)
\r
274 result r = E_SUCCESS;
\r
275 Bitmap* pMergedBitmap = null;
\r
276 Canvas* pCanvas = null;
\r
278 TryCatch(pFirstBitmap != null, , "Failed to fetch the background bitmap.");
\r
279 TryCatch(pSecondBitmap != null, , "Failed to fetch the foreground bitmap.");
\r
281 pCanvas = new (std::nothrow) Canvas();
\r
282 TryCatch(pCanvas != null, , "Canvas new Fail.");
\r
284 r = pCanvas->Construct(Rectangle(0, 0, width, height));
\r
285 TryCatch(r == E_SUCCESS, , "Canvas Construct Fail.");
\r
287 pCanvas->DrawBitmap(Rectangle(0, 0, width, height), *pFirstBitmap);
\r
288 pCanvas->DrawBitmap(Point(0, 0), *pSecondBitmap);
\r
290 pMergedBitmap = new (std::nothrow) Bitmap();
\r
291 pMergedBitmap->Construct(*pCanvas, Rectangle(0, 0, width, height));
\r
293 delete pFirstBitmap;
\r
294 delete pSecondBitmap;
\r
297 return pMergedBitmap;
\r
299 if (pCanvas != null)
\r
304 if (pFirstBitmap != null)
\r
306 delete pFirstBitmap;
\r
309 if (pSecondBitmap != null)
\r
311 delete pSecondBitmap;
\r
317 Tizen::Graphics::Bitmap*
\r
318 MfUtility::MergeNinePatchedBitmapN(const Tizen::Base::String& firstBitmapPath, const Tizen::Base::String& secondBitmapPath, const int width, const int height, Tizen::Graphics::Point* pPoint)
\r
320 AppResource* pAppResource = null;
\r
321 result r = E_SUCCESS;
\r
323 Bitmap* pFirstBitmap = null;
\r
324 Bitmap* pSecondBitmap = null;
\r
326 Bitmap* pMergedBitmap = null;
\r
328 Point startPoint(0,0);
\r
329 Canvas* pCanvas = null;
\r
331 if (pPoint == null)
\r
338 startPoint.x = pPoint->x;
\r
339 startPoint.y = pPoint->y;
\r
342 pAppResource = Application::GetInstance()->GetAppResource();
\r
343 pFirstBitmap = GetNinepatchedBitmapN(firstBitmapPath, width, height);
\r
344 pSecondBitmap = pAppResource->GetBitmapN(secondBitmapPath, BITMAP_PIXEL_FORMAT_ARGB8888);
\r
346 TryCatch(pFirstBitmap != null, , "Failed to fetch the background bitmap.");
\r
347 TryCatch(pSecondBitmap != null, , "Failed to fetch the foreground bitmap.");
\r
349 pCanvas = new (std::nothrow) Canvas();
\r
350 TryCatch(pCanvas != null, , "Canvas new Fail.");
\r
352 r = pCanvas->Construct(Rectangle(0, 0, width, height));
\r
353 TryCatch(r == E_SUCCESS, , "Canvas Construct Fail.");
\r
355 pCanvas->DrawBitmap(Rectangle(0, 0, width, height), *pFirstBitmap);
\r
356 pCanvas->DrawBitmap(startPoint, *pSecondBitmap);
\r
358 pMergedBitmap = new (std::nothrow) Bitmap();
\r
359 pMergedBitmap->Construct(*pCanvas, Rectangle(0, 0, width, height));
\r
361 if (pFirstBitmap != null)
\r
363 delete pFirstBitmap;
\r
364 pFirstBitmap = null;
\r
367 if (pSecondBitmap != null)
\r
369 delete pSecondBitmap;
\r
370 pSecondBitmap = null;
\r
373 if (pCanvas != null)
\r
379 return pMergedBitmap;
\r
382 if (pCanvas != null)
\r
388 if (pFirstBitmap != null)
\r
390 delete pFirstBitmap;
\r
391 pFirstBitmap = null;
\r
394 if (pSecondBitmap != null)
\r
396 delete pSecondBitmap;
\r
397 pSecondBitmap = null;
\r