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