1 /*
2  * Copyright (C) 2010 The Android Open Source Project
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 #ifndef ANDROID_CONFIGURATION_H
18 #define ANDROID_CONFIGURATION_H
19 
20 #include <android/asset_manager.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 struct AConfiguration;
27 typedef struct AConfiguration AConfiguration;
28 
29 enum {
30     ACONFIGURATION_ORIENTATION_ANY  = 0x0000,
31     ACONFIGURATION_ORIENTATION_PORT = 0x0001,
32     ACONFIGURATION_ORIENTATION_LAND = 0x0002,
33     ACONFIGURATION_ORIENTATION_SQUARE = 0x0003,
34 
35     ACONFIGURATION_TOUCHSCREEN_ANY  = 0x0000,
36     ACONFIGURATION_TOUCHSCREEN_NOTOUCH  = 0x0001,
37     ACONFIGURATION_TOUCHSCREEN_STYLUS  = 0x0002,
38     ACONFIGURATION_TOUCHSCREEN_FINGER  = 0x0003,
39 
40     ACONFIGURATION_DENSITY_DEFAULT = 0,
41     ACONFIGURATION_DENSITY_LOW = 120,
42     ACONFIGURATION_DENSITY_MEDIUM = 160,
43     ACONFIGURATION_DENSITY_TV = 213,
44     ACONFIGURATION_DENSITY_HIGH = 240,
45     ACONFIGURATION_DENSITY_XHIGH = 320,
46     ACONFIGURATION_DENSITY_XXHIGH = 480,
47     ACONFIGURATION_DENSITY_XXXHIGH = 640,
48     ACONFIGURATION_DENSITY_ANY = 0xfffe,
49     ACONFIGURATION_DENSITY_NONE = 0xffff,
50 
51     ACONFIGURATION_KEYBOARD_ANY  = 0x0000,
52     ACONFIGURATION_KEYBOARD_NOKEYS  = 0x0001,
53     ACONFIGURATION_KEYBOARD_QWERTY  = 0x0002,
54     ACONFIGURATION_KEYBOARD_12KEY  = 0x0003,
55 
56     ACONFIGURATION_NAVIGATION_ANY  = 0x0000,
57     ACONFIGURATION_NAVIGATION_NONAV  = 0x0001,
58     ACONFIGURATION_NAVIGATION_DPAD  = 0x0002,
59     ACONFIGURATION_NAVIGATION_TRACKBALL  = 0x0003,
60     ACONFIGURATION_NAVIGATION_WHEEL  = 0x0004,
61 
62     ACONFIGURATION_KEYSHIDDEN_ANY = 0x0000,
63     ACONFIGURATION_KEYSHIDDEN_NO = 0x0001,
64     ACONFIGURATION_KEYSHIDDEN_YES = 0x0002,
65     ACONFIGURATION_KEYSHIDDEN_SOFT = 0x0003,
66 
67     ACONFIGURATION_NAVHIDDEN_ANY = 0x0000,
68     ACONFIGURATION_NAVHIDDEN_NO = 0x0001,
69     ACONFIGURATION_NAVHIDDEN_YES = 0x0002,
70 
71     ACONFIGURATION_SCREENSIZE_ANY  = 0x00,
72     ACONFIGURATION_SCREENSIZE_SMALL = 0x01,
73     ACONFIGURATION_SCREENSIZE_NORMAL = 0x02,
74     ACONFIGURATION_SCREENSIZE_LARGE = 0x03,
75     ACONFIGURATION_SCREENSIZE_XLARGE = 0x04,
76 
77     ACONFIGURATION_SCREENLONG_ANY = 0x00,
78     ACONFIGURATION_SCREENLONG_NO = 0x1,
79     ACONFIGURATION_SCREENLONG_YES = 0x2,
80 
81     ACONFIGURATION_SCREENROUND_ANY = 0x00,
82     ACONFIGURATION_SCREENROUND_NO = 0x1,
83     ACONFIGURATION_SCREENROUND_YES = 0x2,
84 
85     ACONFIGURATION_UI_MODE_TYPE_ANY = 0x00,
86     ACONFIGURATION_UI_MODE_TYPE_NORMAL = 0x01,
87     ACONFIGURATION_UI_MODE_TYPE_DESK = 0x02,
88     ACONFIGURATION_UI_MODE_TYPE_CAR = 0x03,
89     ACONFIGURATION_UI_MODE_TYPE_TELEVISION = 0x04,
90     ACONFIGURATION_UI_MODE_TYPE_APPLIANCE = 0x05,
91     ACONFIGURATION_UI_MODE_TYPE_WATCH = 0x06,
92 
93     ACONFIGURATION_UI_MODE_NIGHT_ANY = 0x00,
94     ACONFIGURATION_UI_MODE_NIGHT_NO = 0x1,
95     ACONFIGURATION_UI_MODE_NIGHT_YES = 0x2,
96 
97     ACONFIGURATION_SCREEN_WIDTH_DP_ANY = 0x0000,
98 
99     ACONFIGURATION_SCREEN_HEIGHT_DP_ANY = 0x0000,
100 
101     ACONFIGURATION_SMALLEST_SCREEN_WIDTH_DP_ANY = 0x0000,
102 
103     ACONFIGURATION_LAYOUTDIR_ANY  = 0x00,
104     ACONFIGURATION_LAYOUTDIR_LTR  = 0x01,
105     ACONFIGURATION_LAYOUTDIR_RTL  = 0x02,
106 
107     ACONFIGURATION_MCC = 0x0001,
108     ACONFIGURATION_MNC = 0x0002,
109     ACONFIGURATION_LOCALE = 0x0004,
110     ACONFIGURATION_TOUCHSCREEN = 0x0008,
111     ACONFIGURATION_KEYBOARD = 0x0010,
112     ACONFIGURATION_KEYBOARD_HIDDEN = 0x0020,
113     ACONFIGURATION_NAVIGATION = 0x0040,
114     ACONFIGURATION_ORIENTATION = 0x0080,
115     ACONFIGURATION_DENSITY = 0x0100,
116     ACONFIGURATION_SCREEN_SIZE = 0x0200,
117     ACONFIGURATION_VERSION = 0x0400,
118     ACONFIGURATION_SCREEN_LAYOUT = 0x0800,
119     ACONFIGURATION_UI_MODE = 0x1000,
120     ACONFIGURATION_SMALLEST_SCREEN_SIZE = 0x2000,
121     ACONFIGURATION_LAYOUTDIR = 0x4000,
122     ACONFIGURATION_SCREEN_ROUND = 0x8000,
123 
124     ACONFIGURATION_MNC_ZERO = 0xffff,
125 };
126 
127 /**
128  * Create a new AConfiguration, initialized with no values set.
129  */
130 AConfiguration* AConfiguration_new();
131 
132 /**
133  * Free an AConfiguration that was previously created with
134  * AConfiguration_new().
135  */
136 void AConfiguration_delete(AConfiguration* config);
137 
138 /**
139  * Create and return a new AConfiguration based on the current configuration in
140  * use in the given AssetManager.
141  */
142 void AConfiguration_fromAssetManager(AConfiguration* out, AAssetManager* am);
143 
144 /**
145  * Copy the contents of 'src' to 'dest'.
146  */
147 void AConfiguration_copy(AConfiguration* dest, AConfiguration* src);
148 
149 /**
150  * Return the current MCC set in the configuration.  0 if not set.
151  */
152 int32_t AConfiguration_getMcc(AConfiguration* config);
153 
154 /**
155  * Set the current MCC in the configuration.  0 to clear.
156  */
157 void AConfiguration_setMcc(AConfiguration* config, int32_t mcc);
158 
159 /**
160  * Return the current MNC set in the configuration.  0 if not set.
161  */
162 int32_t AConfiguration_getMnc(AConfiguration* config);
163 
164 /**
165  * Set the current MNC in the configuration.  0 to clear.
166  */
167 void AConfiguration_setMnc(AConfiguration* config, int32_t mnc);
168 
169 /**
170  * Return the current language code set in the configuration.  The output will
171  * be filled with an array of two characters.  They are not 0-terminated.  If
172  * a language is not set, they will be 0.
173  */
174 void AConfiguration_getLanguage(AConfiguration* config, char* outLanguage);
175 
176 /**
177  * Set the current language code in the configuration, from the first two
178  * characters in the string.
179  */
180 void AConfiguration_setLanguage(AConfiguration* config, const char* language);
181 
182 /**
183  * Return the current country code set in the configuration.  The output will
184  * be filled with an array of two characters.  They are not 0-terminated.  If
185  * a country is not set, they will be 0.
186  */
187 void AConfiguration_getCountry(AConfiguration* config, char* outCountry);
188 
189 /**
190  * Set the current country code in the configuration, from the first two
191  * characters in the string.
192  */
193 void AConfiguration_setCountry(AConfiguration* config, const char* country);
194 
195 /**
196  * Return the current ACONFIGURATION_ORIENTATION_* set in the configuration.
197  */
198 int32_t AConfiguration_getOrientation(AConfiguration* config);
199 
200 /**
201  * Set the current orientation in the configuration.
202  */
203 void AConfiguration_setOrientation(AConfiguration* config, int32_t orientation);
204 
205 /**
206  * Return the current ACONFIGURATION_TOUCHSCREEN_* set in the configuration.
207  */
208 int32_t AConfiguration_getTouchscreen(AConfiguration* config);
209 
210 /**
211  * Set the current touchscreen in the configuration.
212  */
213 void AConfiguration_setTouchscreen(AConfiguration* config, int32_t touchscreen);
214 
215 /**
216  * Return the current ACONFIGURATION_DENSITY_* set in the configuration.
217  */
218 int32_t AConfiguration_getDensity(AConfiguration* config);
219 
220 /**
221  * Set the current density in the configuration.
222  */
223 void AConfiguration_setDensity(AConfiguration* config, int32_t density);
224 
225 /**
226  * Return the current ACONFIGURATION_KEYBOARD_* set in the configuration.
227  */
228 int32_t AConfiguration_getKeyboard(AConfiguration* config);
229 
230 /**
231  * Set the current keyboard in the configuration.
232  */
233 void AConfiguration_setKeyboard(AConfiguration* config, int32_t keyboard);
234 
235 /**
236  * Return the current ACONFIGURATION_NAVIGATION_* set in the configuration.
237  */
238 int32_t AConfiguration_getNavigation(AConfiguration* config);
239 
240 /**
241  * Set the current navigation in the configuration.
242  */
243 void AConfiguration_setNavigation(AConfiguration* config, int32_t navigation);
244 
245 /**
246  * Return the current ACONFIGURATION_KEYSHIDDEN_* set in the configuration.
247  */
248 int32_t AConfiguration_getKeysHidden(AConfiguration* config);
249 
250 /**
251  * Set the current keys hidden in the configuration.
252  */
253 void AConfiguration_setKeysHidden(AConfiguration* config, int32_t keysHidden);
254 
255 /**
256  * Return the current ACONFIGURATION_NAVHIDDEN_* set in the configuration.
257  */
258 int32_t AConfiguration_getNavHidden(AConfiguration* config);
259 
260 /**
261  * Set the current nav hidden in the configuration.
262  */
263 void AConfiguration_setNavHidden(AConfiguration* config, int32_t navHidden);
264 
265 /**
266  * Return the current SDK (API) version set in the configuration.
267  */
268 int32_t AConfiguration_getSdkVersion(AConfiguration* config);
269 
270 /**
271  * Set the current SDK version in the configuration.
272  */
273 void AConfiguration_setSdkVersion(AConfiguration* config, int32_t sdkVersion);
274 
275 /**
276  * Return the current ACONFIGURATION_SCREENSIZE_* set in the configuration.
277  */
278 int32_t AConfiguration_getScreenSize(AConfiguration* config);
279 
280 /**
281  * Set the current screen size in the configuration.
282  */
283 void AConfiguration_setScreenSize(AConfiguration* config, int32_t screenSize);
284 
285 /**
286  * Return the current ACONFIGURATION_SCREENLONG_* set in the configuration.
287  */
288 int32_t AConfiguration_getScreenLong(AConfiguration* config);
289 
290 /**
291  * Set the current screen long in the configuration.
292  */
293 void AConfiguration_setScreenLong(AConfiguration* config, int32_t screenLong);
294 
295 /**
296  * Return the current ACONFIGURATION_SCREENROUND_* set in the configuration.
297  */
298 int32_t AConfiguration_getScreenRound(AConfiguration* config);
299 
300 /**
301  * Set the current screen round in the configuration.
302  */
303 void AConfiguration_setScreenRound(AConfiguration* config, int32_t screenRound);
304 
305 /**
306  * Return the current ACONFIGURATION_UI_MODE_TYPE_* set in the configuration.
307  */
308 int32_t AConfiguration_getUiModeType(AConfiguration* config);
309 
310 /**
311  * Set the current UI mode type in the configuration.
312  */
313 void AConfiguration_setUiModeType(AConfiguration* config, int32_t uiModeType);
314 
315 /**
316  * Return the current ACONFIGURATION_UI_MODE_NIGHT_* set in the configuration.
317  */
318 int32_t AConfiguration_getUiModeNight(AConfiguration* config);
319 
320 /**
321  * Set the current UI mode night in the configuration.
322  */
323 void AConfiguration_setUiModeNight(AConfiguration* config, int32_t uiModeNight);
324 
325 /**
326  * Return the current configuration screen width in dp units, or
327  * ACONFIGURATION_SCREEN_WIDTH_DP_ANY if not set.
328  */
329 int32_t AConfiguration_getScreenWidthDp(AConfiguration* config);
330 
331 /**
332  * Set the configuration's current screen width in dp units.
333  */
334 void AConfiguration_setScreenWidthDp(AConfiguration* config, int32_t value);
335 
336 /**
337  * Return the current configuration screen height in dp units, or
338  * ACONFIGURATION_SCREEN_HEIGHT_DP_ANY if not set.
339  */
340 int32_t AConfiguration_getScreenHeightDp(AConfiguration* config);
341 
342 /**
343  * Set the configuration's current screen width in dp units.
344  */
345 void AConfiguration_setScreenHeightDp(AConfiguration* config, int32_t value);
346 
347 /**
348  * Return the configuration's smallest screen width in dp units, or
349  * ACONFIGURATION_SMALLEST_SCREEN_WIDTH_DP_ANY if not set.
350  */
351 int32_t AConfiguration_getSmallestScreenWidthDp(AConfiguration* config);
352 
353 /**
354  * Set the configuration's smallest screen width in dp units.
355  */
356 void AConfiguration_setSmallestScreenWidthDp(AConfiguration* config, int32_t value);
357 
358 /**
359  * Return the configuration's layout direction, or
360  * ACONFIGURATION_LAYOUTDIR_ANY if not set.
361  */
362 int32_t AConfiguration_getLayoutDirection(AConfiguration* config);
363 
364 /**
365  * Set the configuration's layout direction.
366  */
367 void AConfiguration_setLayoutDirection(AConfiguration* config, int32_t value);
368 
369 /**
370  * Perform a diff between two configurations.  Returns a bit mask of
371  * ACONFIGURATION_* constants, each bit set meaning that configuration element
372  * is different between them.
373  */
374 int32_t AConfiguration_diff(AConfiguration* config1, AConfiguration* config2);
375 
376 /**
377  * Determine whether 'base' is a valid configuration for use within the
378  * environment 'requested'.  Returns 0 if there are any values in 'base'
379  * that conflict with 'requested'.  Returns 1 if it does not conflict.
380  */
381 int32_t AConfiguration_match(AConfiguration* base, AConfiguration* requested);
382 
383 /**
384  * Determine whether the configuration in 'test' is better than the existing
385  * configuration in 'base'.  If 'requested' is non-NULL, this decision is based
386  * on the overall configuration given there.  If it is NULL, this decision is
387  * simply based on which configuration is more specific.  Returns non-0 if
388  * 'test' is better than 'base'.
389  *
390  * This assumes you have already filtered the configurations with
391  * AConfiguration_match().
392  */
393 int32_t AConfiguration_isBetterThan(AConfiguration* base, AConfiguration* test,
394         AConfiguration* requested);
395 
396 #ifdef __cplusplus
397 };
398 #endif
399 
400 #endif // ANDROID_CONFIGURATION_H
401