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 __BEGIN_DECLS 23 24 struct AConfiguration; 25 typedef struct AConfiguration AConfiguration; 26 27 enum { 28 ACONFIGURATION_ORIENTATION_ANY = 0x0000, 29 ACONFIGURATION_ORIENTATION_PORT = 0x0001, 30 ACONFIGURATION_ORIENTATION_LAND = 0x0002, 31 ACONFIGURATION_ORIENTATION_SQUARE = 0x0003, 32 33 ACONFIGURATION_TOUCHSCREEN_ANY = 0x0000, 34 ACONFIGURATION_TOUCHSCREEN_NOTOUCH = 0x0001, 35 ACONFIGURATION_TOUCHSCREEN_STYLUS = 0x0002, 36 ACONFIGURATION_TOUCHSCREEN_FINGER = 0x0003, 37 38 ACONFIGURATION_DENSITY_DEFAULT = 0, 39 ACONFIGURATION_DENSITY_LOW = 120, 40 ACONFIGURATION_DENSITY_MEDIUM = 160, 41 ACONFIGURATION_DENSITY_HIGH = 240, 42 ACONFIGURATION_DENSITY_NONE = 0xffff, 43 44 ACONFIGURATION_KEYBOARD_ANY = 0x0000, 45 ACONFIGURATION_KEYBOARD_NOKEYS = 0x0001, 46 ACONFIGURATION_KEYBOARD_QWERTY = 0x0002, 47 ACONFIGURATION_KEYBOARD_12KEY = 0x0003, 48 49 ACONFIGURATION_NAVIGATION_ANY = 0x0000, 50 ACONFIGURATION_NAVIGATION_NONAV = 0x0001, 51 ACONFIGURATION_NAVIGATION_DPAD = 0x0002, 52 ACONFIGURATION_NAVIGATION_TRACKBALL = 0x0003, 53 ACONFIGURATION_NAVIGATION_WHEEL = 0x0004, 54 55 ACONFIGURATION_KEYSHIDDEN_ANY = 0x0000, 56 ACONFIGURATION_KEYSHIDDEN_NO = 0x0001, 57 ACONFIGURATION_KEYSHIDDEN_YES = 0x0002, 58 ACONFIGURATION_KEYSHIDDEN_SOFT = 0x0003, 59 60 ACONFIGURATION_NAVHIDDEN_ANY = 0x0000, 61 ACONFIGURATION_NAVHIDDEN_NO = 0x0001, 62 ACONFIGURATION_NAVHIDDEN_YES = 0x0002, 63 64 ACONFIGURATION_SCREENSIZE_ANY = 0x00, 65 ACONFIGURATION_SCREENSIZE_SMALL = 0x01, 66 ACONFIGURATION_SCREENSIZE_NORMAL = 0x02, 67 ACONFIGURATION_SCREENSIZE_LARGE = 0x03, 68 ACONFIGURATION_SCREENSIZE_XLARGE = 0x04, 69 70 ACONFIGURATION_SCREENLONG_ANY = 0x00, 71 ACONFIGURATION_SCREENLONG_NO = 0x1, 72 ACONFIGURATION_SCREENLONG_YES = 0x2, 73 74 ACONFIGURATION_UI_MODE_TYPE_ANY = 0x00, 75 ACONFIGURATION_UI_MODE_TYPE_NORMAL = 0x01, 76 ACONFIGURATION_UI_MODE_TYPE_DESK = 0x02, 77 ACONFIGURATION_UI_MODE_TYPE_CAR = 0x03, 78 79 ACONFIGURATION_UI_MODE_NIGHT_ANY = 0x00, 80 ACONFIGURATION_UI_MODE_NIGHT_NO = 0x1, 81 ACONFIGURATION_UI_MODE_NIGHT_YES = 0x2, 82 83 ACONFIGURATION_MCC = 0x0001, 84 ACONFIGURATION_MNC = 0x0002, 85 ACONFIGURATION_LOCALE = 0x0004, 86 ACONFIGURATION_TOUCHSCREEN = 0x0008, 87 ACONFIGURATION_KEYBOARD = 0x0010, 88 ACONFIGURATION_KEYBOARD_HIDDEN = 0x0020, 89 ACONFIGURATION_NAVIGATION = 0x0040, 90 ACONFIGURATION_ORIENTATION = 0x0080, 91 ACONFIGURATION_DENSITY = 0x0100, 92 ACONFIGURATION_SCREEN_SIZE = 0x0200, 93 ACONFIGURATION_VERSION = 0x0400, 94 ACONFIGURATION_SCREEN_LAYOUT = 0x0800, 95 ACONFIGURATION_UI_MODE = 0x1000, 96 }; 97 98 /** 99 * Create a new AConfiguration, initialized with no values set. 100 */ 101 AConfiguration* AConfiguration_new(); 102 103 /** 104 * Free an AConfiguration that was previously created with 105 * AConfiguration_new(). 106 */ 107 void AConfiguration_delete(AConfiguration* config); 108 109 /** 110 * Create and return a new AConfiguration based on the current configuration in 111 * use in the given AssetManager. 112 */ 113 void AConfiguration_fromAssetManager(AConfiguration* out, AAssetManager* am); 114 115 /** 116 * Copy the contents of 'src' to 'dest'. 117 */ 118 void AConfiguration_copy(AConfiguration* dest, AConfiguration* src); 119 120 /** 121 * Return the current MCC set in the configuration. 0 if not set. 122 */ 123 int32_t AConfiguration_getMcc(AConfiguration* config); 124 125 /** 126 * Set the current MCC in the configuration. 0 to clear. 127 */ 128 void AConfiguration_setMcc(AConfiguration* config, int32_t mcc); 129 130 /** 131 * Return the current MNC set in the configuration. 0 if not set. 132 */ 133 int32_t AConfiguration_getMnc(AConfiguration* config); 134 135 /** 136 * Set the current MNC in the configuration. 0 to clear. 137 */ 138 void AConfiguration_setMnc(AConfiguration* config, int32_t mnc); 139 140 /** 141 * Return the current language code set in the configuration. The output will 142 * be filled with an array of two characters. They are not 0-terminated. If 143 * a language is not set, they will be 0. 144 */ 145 void AConfiguration_getLanguage(AConfiguration* config, char* outLanguage); 146 147 /** 148 * Set the current language code in the configuration, from the first two 149 * characters in the string. 150 */ 151 void AConfiguration_setLanguage(AConfiguration* config, const char* language); 152 153 /** 154 * Return the current country code set in the configuration. The output will 155 * be filled with an array of two characters. They are not 0-terminated. If 156 * a country is not set, they will be 0. 157 */ 158 void AConfiguration_getCountry(AConfiguration* config, char* outCountry); 159 160 /** 161 * Set the current country code in the configuration, from the first two 162 * characters in the string. 163 */ 164 void AConfiguration_setCountry(AConfiguration* config, const char* country); 165 166 /** 167 * Return the current ACONFIGURATION_ORIENTATION_* set in the configuration. 168 */ 169 int32_t AConfiguration_getOrientation(AConfiguration* config); 170 171 /** 172 * Set the current orientation in the configuration. 173 */ 174 void AConfiguration_setOrientation(AConfiguration* config, int32_t orientation); 175 176 /** 177 * Return the current ACONFIGURATION_TOUCHSCREEN_* set in the configuration. 178 */ 179 int32_t AConfiguration_getTouchscreen(AConfiguration* config); 180 181 /** 182 * Set the current touchscreen in the configuration. 183 */ 184 void AConfiguration_setTouchscreen(AConfiguration* config, int32_t touchscreen); 185 186 /** 187 * Return the current ACONFIGURATION_DENSITY_* set in the configuration. 188 */ 189 int32_t AConfiguration_getDensity(AConfiguration* config); 190 191 /** 192 * Set the current density in the configuration. 193 */ 194 void AConfiguration_setDensity(AConfiguration* config, int32_t density); 195 196 /** 197 * Return the current ACONFIGURATION_KEYBOARD_* set in the configuration. 198 */ 199 int32_t AConfiguration_getKeyboard(AConfiguration* config); 200 201 /** 202 * Set the current keyboard in the configuration. 203 */ 204 void AConfiguration_setKeyboard(AConfiguration* config, int32_t keyboard); 205 206 /** 207 * Return the current ACONFIGURATION_NAVIGATION_* set in the configuration. 208 */ 209 int32_t AConfiguration_getNavigation(AConfiguration* config); 210 211 /** 212 * Set the current navigation in the configuration. 213 */ 214 void AConfiguration_setNavigation(AConfiguration* config, int32_t navigation); 215 216 /** 217 * Return the current ACONFIGURATION_KEYSHIDDEN_* set in the configuration. 218 */ 219 int32_t AConfiguration_getKeysHidden(AConfiguration* config); 220 221 /** 222 * Set the current keys hidden in the configuration. 223 */ 224 void AConfiguration_setKeysHidden(AConfiguration* config, int32_t keysHidden); 225 226 /** 227 * Return the current ACONFIGURATION_NAVHIDDEN_* set in the configuration. 228 */ 229 int32_t AConfiguration_getNavHidden(AConfiguration* config); 230 231 /** 232 * Set the current nav hidden in the configuration. 233 */ 234 void AConfiguration_setNavHidden(AConfiguration* config, int32_t navHidden); 235 236 /** 237 * Return the current SDK (API) version set in the configuration. 238 */ 239 int32_t AConfiguration_getSdkVersion(AConfiguration* config); 240 241 /** 242 * Set the current SDK version in the configuration. 243 */ 244 void AConfiguration_setSdkVersion(AConfiguration* config, int32_t sdkVersion); 245 246 /** 247 * Return the current ACONFIGURATION_SCREENSIZE_* set in the configuration. 248 */ 249 int32_t AConfiguration_getScreenSize(AConfiguration* config); 250 251 /** 252 * Set the current screen size in the configuration. 253 */ 254 void AConfiguration_setScreenSize(AConfiguration* config, int32_t screenSize); 255 256 /** 257 * Return the current ACONFIGURATION_SCREENLONG_* set in the configuration. 258 */ 259 int32_t AConfiguration_getScreenLong(AConfiguration* config); 260 261 /** 262 * Set the current screen long in the configuration. 263 */ 264 void AConfiguration_setScreenLong(AConfiguration* config, int32_t screenLong); 265 266 /** 267 * Return the current ACONFIGURATION_UI_MODE_TYPE_* set in the configuration. 268 */ 269 int32_t AConfiguration_getUiModeType(AConfiguration* config); 270 271 /** 272 * Set the current UI mode type in the configuration. 273 */ 274 void AConfiguration_setUiModeType(AConfiguration* config, int32_t uiModeType); 275 276 /** 277 * Return the current ACONFIGURATION_UI_MODE_NIGHT_* set in the configuration. 278 */ 279 int32_t AConfiguration_getUiModeNight(AConfiguration* config); 280 281 /** 282 * Set the current UI mode night in the configuration. 283 */ 284 void AConfiguration_setUiModeNight(AConfiguration* config, int32_t uiModeNight); 285 286 /** 287 * Perform a diff between two configurations. Returns a bit mask of 288 * ACONFIGURATION_* constants, each bit set meaning that configuration element 289 * is different between them. 290 */ 291 int32_t AConfiguration_diff(AConfiguration* config1, AConfiguration* config2); 292 293 /** 294 * Determine whether 'base' is a valid configuration for use within the 295 * environment 'requested'. Returns 0 if there are any values in 'base' 296 * that conflict with 'requested'. Returns 1 if it does not conflict. 297 */ 298 int32_t AConfiguration_match(AConfiguration* base, AConfiguration* requested); 299 300 /** 301 * Determine whether the configuration in 'test' is better than the existing 302 * configuration in 'base'. If 'requested' is non-NULL, this decision is based 303 * on the overall configuration given there. If it is NULL, this decision is 304 * simply based on which configuration is more specific. Returns non-0 if 305 * 'test' is better than 'base'. 306 * 307 * This assumes you have already filtered the configurations with 308 * AConfiguration_match(). 309 */ 310 int32_t AConfiguration_isBetterThan(AConfiguration* base, AConfiguration* test, 311 AConfiguration* requested); 312 313 __END_DECLS 314 315 #endif /* ANDROID_CONFIGURATION_H */ 316