sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FAppAppResource.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                        FAppAppResource.h
20  * @brief                       This is the header file for the %AppResource class.
21  *
22  * This header file contains the declarations of the %AppResource class.
23  */
24
25 #ifndef _FAPP_APP_RESOURCE_H_
26 #define _FAPP_APP_RESOURCE_H_
27
28 #include <FBaseObject.h>
29 #include <FBaseString.h>
30 #include <FBaseColHashMap.h>
31 #include <FAppTypes.h>
32 #include <FGrpBitmapCommon.h>
33
34 namespace Tizen { namespace Locales { class Locale; } }
35 namespace Tizen { namespace Graphics { class Bitmap; } }
36
37 namespace Tizen { namespace App
38 {
39
40 /**
41 * @class                AppResource
42 * @brief                This class provides convenient methods to load application resources at run time.
43 *
44 * @since        2.0
45 *
46 * @final        This class is not intended for extension.
47 *
48 * The %AppResource class provides convenient methods to load application resources at run time: @n
49 * - Use AppResource::GetString() to get handle and display localized strings.
50 * - Use AppResource::GetBitmapN() to obtain a bitmap image that matches the screen density.
51 * - If the matching image does not exist, the image of the baseline density folder, ScreenDensity-High is used.
52 *
53 * The instance of this class can be obtained through App::GetAppResource().
54 * The following example demonstrates how to use the %AppResource class to get strings.
55 *
56 * @code
57 #include <FApp.h>
58
59 using namespace Tizen::App;
60
61 void
62 MyClass::StringResourceSample(void)
63 {
64         String hello;
65         AppResource *pAppResource = App::GetInstance()->GetAppResource();
66         if (pAppResource)
67         {
68                 pAppResource->GetString(L"IDS_HELLO", hello);
69         }
70 }
71 * @endcode
72 *
73 *
74 *
75 * The following example demonstrates how to use the %AppResource class to retrieve bitmaps.
76 * @code
77 #include <FApp.h>
78
79 using namespace Tizen::App;
80 using namespace Tizen::Graphics;
81
82 void
83 MyClass::BitmapResourceSample(void)
84 {
85         AppResource *pAppResource = App::GetInstance()->GetAppResource();
86         Bitmap* pBitmap = null;
87
88         if (pAppResource)
89         {
90                 pBitmap = pAppResource->GetBitmapN(L"Tizen.png", BITMAP_PIXEL_FORMAT_ARGB8888);
91         }
92 }
93 * @endcode
94 */
95
96 class _OSP_EXPORT_ AppResource
97         : public Tizen::Base::Object
98 {
99 public:
100         /**
101         * Gets the string at the specified resource ID.
102         *
103         * @since        2.0
104         *
105         * @return               An error code
106         * @param[in]    resourceId              The resource ID of type Tizen::Base::String that describes the resource
107         * @param[out]   loadedString    The string obtained from the loaded application resource
108         * @exception    E_SUCCESS                                 The method is successful.
109         * @exception    E_FAILURE                       The argument passed is not found.
110         * @exception    E_INVALID_ARG                   The argument passed to a method contains an invalid resource ID.
111         */
112         result GetString(const Tizen::Base::String& resourceId, Tizen::Base::String& loadedString) const;
113
114         /**
115         * Gets the bitmap at the specified path. @n
116         * The %GetBitmapN() method interprets the given resource path and reads the best matching image file for the current device resolution. @n
117         * To load the bitmap image from a file, give the name of the file as the input parameter and not the file path (For example: "img.png").
118         * Then, the system will first look for the image file in the folder specific to the current device resolution, such as
119         * '720x1280' and if the file does not exist, it will then search the folder that corresponds to the current screen density,
120     * such as 'screen-density-xhigh'. After searching the density folder, all the other density folders are searched in the order high to low.
121         * Currently supported image formats are: JPEG, GIF, PNG, BMP, TIFF, and WBMP.
122         *
123         * @since        2.0
124         *
125         * @return               A pointer to the Bitmap instance generated from the specified file
126         * @param[in]    imagePath                               The relative path starting from the directory @b "res/screen-density-XXX/" or @b "res/AxB", @n
127         *                                                                               where A and B represent the screen width and height of the supported device models, respectively.
128         * @param[in]    pixelFormat                             The pixel format of the resulting bitmap
129         * @exception    E_SUCCESS                               The method is successful.
130         * @exception    E_INVALID_ARG                   A specified input parameter is invalid.
131         * @exception    E_UNSUPPORTED_FORMAT    The image file format or specified pixel format is not supported.
132         * @exception    E_FILE_NOT_FOUND                The specified file cannot be found.
133         * @exception    E_SYSTEM                                A system error has occurred.
134         * @remarks      The specific error code can be accessed using the GetLastResult() method.
135         * @remarks      There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is E_OUT_OF_MEMORY or not. For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
136         */
137         Tizen::Graphics::Bitmap* GetBitmapN(const Tizen::Base::String& imagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat) const;
138
139         /**
140         * Gets the bitmap at the specified path. @n
141         * The %GetBitmapN() method interprets the given resource path and reads the best matching image file for the current device resolution. @n
142         * To load the bitmap image from a file, give the name of the file as the input parameter and not the file path (For example: "img.png").
143         * Then, the system will first look for the image file in the folder specific to the current device resolution, such as
144         * '720x1280' and if the file does not exist, it will then search the folder that corresponds to the current screen density,
145         * such as 'screen-density-xhigh'. After searching the density folder, all the other density folders are searched in the order high to low.
146         * Currently supported image formats are: JPEG, GIF, PNG, BMP, TIFF, and WBMP.
147         *
148         * In this method, the system decides the proper pixel format.
149         * Currently supported image formats are: JPEG, GIF, PNG, BMP, TIFF, and WBMP.
150         *
151         * @since        2.0
152         *
153         * @return               A pointer to the Tizen::Graphics::Bitmap instance generated from the specified file
154         * @param[in]    imagePath                               The relative path starting from the density directory @b "res/screen-density-XXX/" or @b "res/AxB", @n
155         *                                                                               where A and B represent the width and height of the screen of the supported device models, respectively
156         * @exception    E_SUCCESS                               The method is successful.
157         * @exception    E_INVALID_ARG                   The specified input parameter is invalid.
158         * @exception    E_UNSUPPORTED_FORMAT    The image file format is not supported.
159         * @exception    E_FILE_NOT_FOUND                The specified file cannot be found.
160         * @exception    E_SYSTEM                                A system error has occurred.
161         * @remarks      The specific error code can be accessed using the GetLastResult() method.
162         * @remarks      There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is E_OUT_OF_MEMORY or not. For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
163         */
164         Tizen::Graphics::Bitmap* GetBitmapN(const Tizen::Base::String& imagePath) const;
165
166         /**
167         * Gets the %AppResource instance pointer.
168         *
169         * @since  2.0
170         *
171         * @return A pointer to the %AppResource instance, @n
172         *                 else @c null if it fails
173         */
174         static AppResource* GetInstance(void);
175
176         /**
177         * @if VISPARTNER
178         * Gets the application resource instance of the specified @c appId.
179         *
180         * @since        2.0
181         *
182         * @visibility  partner
183         * @privilege   %http://tizen.org/privilege/appsetting
184         *
185         * @return       A pointer to the %AppResource instance, @n
186         *               else @c null if it fails
187         * @param[in]    appId                The AppId of the installed application
188         * @exception    E_SUCCESS            The method is successful.
189         * @exception    E_DATA_NOT_FOUND      The instance of specified @c appId does not provide the string resource.
190         * @exception    E_OUT_OF_MEMORY      The memory is insufficient.
191         * @exception    E_APP_NOT_INSTALLED  The specified @c appId is not found in the list of installed applications.
192         * @exception    E_SYSTEM        Initializing string and bitmap resource has failed due to a system error.
193         * @exception    E_PRIVILEGE_DENIED  The application does not have the privilege to call this method.
194         * @remarks The specific error code can be accessed using the GetLastResult() method.
195         * @endif
196         */
197         static AppResource* GetInstanceByAppId(const AppId& appId);
198
199         /**
200         * @if VISPARTNER
201         * Releases the application resource instance of the specified @c appId.
202         *
203         * @since        2.0
204         *
205         * @visibility  partner
206         * @privilege   %http://tizen.org/privilege/appsetting
207         *
208         * @return       An error code
209         * @param[in]    appId                The AppId of the installed application
210         * @exception    E_SUCCESS            The method is successful.
211         * @exception    E_OBJ_NOT_FOUND      The application resource instance of the specified @c appId is not found.
212         * @exception    E_PRIVILEGE_DENIED  The application does not have the privilege to call this method.
213         * @remarks     Individual instances are managed by the platform. @n
214         *              It is recommended to release instances to reduce memory usage.
215         * @endif
216         */
217         static result ReleaseInstanceByAppId(const AppId& appId);
218
219 private:
220         /**
221          * This default constructor is intentionally declared as private to implement the %Singleton semantic.
222          *
223          * @since       2.0
224          */
225         AppResource(void);
226
227         /**
228          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
229          *
230          * @since       2.0
231          */
232         AppResource(const AppResource& rhs);
233
234         /**
235          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
236          *
237          * @since       2.0
238          */
239         AppResource& operator =(const AppResource& rhs);
240
241         /**
242          * This destructor is intentionally declared as private to implement the %Singleton semantic.
243          *
244          * @since       2.0
245          */
246         virtual ~AppResource(void);
247
248         /**
249          * Initializes this instance.
250          *
251          * @since       2.0
252          *
253          * @return      An error code
254          * @exception   E_SUCCESS       The method is successful.
255          * @exception   E_OUT_OF_MEMORY The memory is insufficient.
256          * @exception   E_SYSTEM        A system error has occurred.
257          */
258         result Construct(void);
259         result Construct(const AppId& appId);
260         static void Reinitialize(void);
261         void Reinitialize(const AppId& appId);
262
263 private:
264         class _AppResourceImpl* __pAppResourceImpl;
265
266         friend class _AppResourceImpl;
267         static Tizen::Base::Collection::HashMap* pContainer;
268 }; // AppResource
269
270 } } // Tizen::App
271
272 #endif