2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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
8 // http://floralicense.org/license/
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 exprs or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file HmApplicationUtils.cpp
19 * @brief Keeps the implementations for Utility functions,
20 * Implementations of the various Utility function which may be used throughout the application
25 #include <FGraphics.h>
28 #include "HmApplicationUtils.h"
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Media;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
40 ApplicationUtils::GetApplicationIconBitmapN(const String& imagePath, const String& appCaption, bool isResourceBitmap)
43 Canvas* pCanvas = null;
44 Bitmap* pBitmap = null;
45 Bitmap* pAppIconBitmap = null;
46 EnrichedText appEnrichedCaption;
47 EnrichedText appEnrichedShadowCaption;
48 TryReturn(!imagePath.IsEmpty(), null, "Invalid Parameter");
52 pBitmap = GetResourceBitmapN(imagePath);
57 pBitmap = GetBitmapN(imagePath);
58 // creates bitmap for the icon if is default icon path
61 pBitmap = GetResourceBitmapN(IDB_DEFAULT_APP_ICON);
65 TryCatch(pBitmap != null, , "Failed to create bitmap");
67 if (pBitmap->GetHeight() != APP_ICON_IMAGE_SIZE || pBitmap->GetWidth() != APP_ICON_IMAGE_SIZE)
69 pBitmap->Scale(Dimension(APP_ICON_IMAGE_SIZE, APP_ICON_IMAGE_SIZE));
71 // get a Canvas instance
72 pCanvas = new (std::nothrow) Canvas();
73 TryCatch(pCanvas != null, , "Failed to allocate for Canvas");
75 r = pCanvas->Construct(Rectangle(0, 0, W_APPLICATION_ICON, H_APPLICATION_ICON));
76 TryCatch(r == E_SUCCESS, , "pCanvas->Construct failed with error %s", GetErrorMessage(r));
77 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
80 r = pCanvas->DrawBitmap(Point((W_APPLICATION_ICON - pBitmap->GetWidth()) / 2, Y_APP_ICON_IMAGE_START) /*, APP_ICON_IMAGE_SIZE, APP_ICON_IMAGE_SIZE)*/, *pBitmap);
81 TryCatch(r == E_SUCCESS, , "pCanvas->DrawBitmap failed with error %s", GetErrorMessage(r));
83 if (!appCaption.IsEmpty())
87 TextElement captionElement;
89 IList* pFontsList = Font::GetSystemFontListN();
91 if (pFontsList != null)
93 IEnumerator* pEnum = pFontsList->GetEnumeratorN();
97 while (pEnum->MoveNext() == E_SUCCESS)
99 String* pFontName = static_cast<String*>(pEnum->GetCurrent());
101 if (pFontName && pFontName->Contains(L"HelveticaNeue"))
103 fontToUse = *pFontName;
112 pFontsList->RemoveAll(true);
117 if (fontToUse.IsEmpty())
119 r = font.Construct(FONT_STYLE_PLAIN, FONT_SIZE_APP_CAPTION);
120 TryCatch(r == E_SUCCESS, , "font.Construct failed with error = %s", GetErrorMessage(r));
124 AppLogDebug("FontTest :: Calling with font.Construct(name) ");
125 r = font.Construct(fontToUse, FONT_STYLE_PLAIN, FONT_SIZE_APP_CAPTION);
126 TryCatch(r == E_SUCCESS, , "font.Construct failed with error = %s", GetErrorMessage(r));
130 r = captionElement.Construct(appCaption);
131 TryCatch(r == E_SUCCESS, , "captionElement.Construct failed with error = %s", GetErrorMessage(r));
132 captionElement.SetTextColor(COLOR_APP_ICON_CAPTION);
133 captionElement.SetFont(font);
134 captionElement.SetOutlineColor(COLOR_APP_CAPTION_SHADOW1);
135 appEnrichedCaption.Construct(Dimension(W_APPLICATION_ICON, H_APP_CAPTION_TEXT));
136 appEnrichedCaption.SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER);
137 appEnrichedCaption.SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
138 appEnrichedCaption.SetTextWrapStyle(TEXT_WRAP_NONE);
139 appEnrichedCaption.SetTextAbbreviationEnabled(true);
140 appEnrichedCaption.Add(captionElement);
142 // app name shadow text
143 TextElement shadowCaptionElement;
144 r = shadowCaptionElement.Construct(appCaption);
145 TryCatch(r == E_SUCCESS, , "shadowCaptionElement.Construct failed with error = %s", GetErrorMessage(r));
146 shadowCaptionElement.SetTextColor(COLOR_APP_CAPTION_SHADOW2);
147 shadowCaptionElement.SetFont(font);
148 shadowCaptionElement.SetOutlineColor(COLOR_APP_CAPTION_SHADOW2);
149 appEnrichedShadowCaption.Construct(Dimension(W_APPLICATION_ICON, H_APP_CAPTION_TEXT));
150 appEnrichedShadowCaption.SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER);
151 appEnrichedShadowCaption.SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
152 appEnrichedShadowCaption.SetTextWrapStyle(TEXT_WRAP_NONE);
153 appEnrichedShadowCaption.SetTextAbbreviationEnabled(true);
154 appEnrichedShadowCaption.Add(shadowCaptionElement);
156 pCanvas->DrawText(Point(0, Y_APP_ICON_IMAGE_START + APP_ICON_IMAGE_SIZE + 2), appEnrichedShadowCaption);
157 pCanvas->DrawText(Point(0, Y_APP_ICON_IMAGE_START + APP_ICON_IMAGE_SIZE), appEnrichedCaption);
160 pAppIconBitmap = new (std::nothrow) Bitmap();
161 TryCatch(pAppIconBitmap != null, , "Failed to allocate for Bitmap");
162 r = pAppIconBitmap->Construct(*pCanvas, Rectangle(0, 0, W_APPLICATION_ICON, H_APPLICATION_ICON));
163 TryCatch(r == E_SUCCESS, , "pCanvas->Construct failed with error %s", GetErrorMessage(r));
177 return pAppIconBitmap;
193 if (pAppIconBitmap != null)
195 delete pAppIconBitmap;
196 pAppIconBitmap = null;
203 ApplicationUtils::GetBitmapN(const String& imageAbsolutePath)
205 result r = E_SUCCESS;
206 Bitmap* pBitmap = null;
207 Image* pImage = new (std::nothrow) Image();
210 fullname.Append(imageAbsolutePath);
214 r = pImage->Construct();
215 // goes to CATCH to release memory and return null if failed to construct Image
216 TryCatch(r == E_SUCCESS, , "Image Construct Failed = (%s)\n", GetErrorMessage(r));
217 // creates bitmap for the specified path of the image which is of jpeg format.
218 if (fullname.EndsWith(L"jpg") || fullname.EndsWith(L"JPG") || fullname.EndsWith(L"jpeg") || fullname.EndsWith(L"JPEG"))
220 pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);
222 // creates bitmap for the specified path of the image which is of bmp format.
223 else if (fullname.EndsWith(L"bmp") || fullname.EndsWith(L"BMP"))
225 pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);
227 // creates bitmap for the specified path of the image which is of png and wbmp formats.
228 else if (fullname.EndsWith(L"png") || fullname.EndsWith(L"PNG") || fullname.EndsWith(L"wbmp") || fullname.EndsWith(L"WBMP"))
230 pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_ARGB8888);
232 // creates bitmap for the specified path of the image which is of gif format.
233 else if (fullname.EndsWith(L"gif") || fullname.EndsWith(L"GIF"))
235 pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);
238 // goes to CATCH to release memory and return null if failed to construct bitmap
239 TryCatch(pBitmap != null, , "not found image path or not enough memory %ls error = %s", fullname.GetPointer()
240 , GetErrorMessage(GetLastResult()));
257 ApplicationUtils::GetResourceBitmapN(const String& imageName)
260 TryReturn(!imageName.IsEmpty(), null, "Invalid parameter");
262 AppResource* pAppResource = UiApp::GetInstance()->GetAppResource();
263 Bitmap* pBitmap = null;
265 // creates bitmap for the specified image name from the application resource.
266 pBitmap = pAppResource->GetBitmapN(imageName, BITMAP_PIXEL_FORMAT_ARGB8888);
268 TryReturn(pBitmap != null, pBitmap, "failed to create bitmap error = %s", GetErrorMessage(GetLastResult()));
274 ApplicationUtils::GetStringResource(const String& stringId, String& retString)
276 result r = E_INVALID_ARG;
278 if (!stringId.IsEmpty())
280 AppResource* pAppResource = UiApp::GetInstance()->GetAppResource();
281 r = pAppResource->GetString(stringId, retString);
287 //Shows delete confirmation message box
289 ApplicationUtils::ShowDeletePopup(String& applicationName)
291 MessageBox messsageBox;
294 String displayMessage;
296 //get the resource string
297 GetStringResource(L"IDS_IDLE_POP_UNINSTALL_PS_Q", message);
298 //format the message by including the application name
299 displayMessage.Format(256, message.GetPointer(), applicationName.GetPointer());
300 messsageBox.Construct(messageTitle, displayMessage, MSGBOX_STYLE_YESNO);
301 //Show message box and wait for user response
302 messsageBox.ShowAndWait(modalResult);
307 ApplicationUtils::ApplicationUtils(void)
309 // No implementation required
312 ApplicationUtils::~ApplicationUtils(void)
314 // No implementation required