Configuration.java revision 31245b4f06003f1c8cd44c31b387c96ab4e282f9
1/* 2 * Copyright (C) 2008 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 17package android.content.res; 18 19import android.content.pm.ActivityInfo; 20import android.os.Build; 21import android.os.Parcel; 22import android.os.Parcelable; 23import android.text.TextUtils; 24import android.view.View; 25 26import java.text.Format; 27import java.util.ArrayList; 28import java.util.Locale; 29 30/** 31 * This class describes all device configuration information that can 32 * impact the resources the application retrieves. This includes both 33 * user-specified configuration options (locale and scaling) as well 34 * as device configurations (such as input modes, screen size and screen orientation). 35 * <p>You can acquire this object from {@link Resources}, using {@link 36 * Resources#getConfiguration}. Thus, from an activity, you can get it by chaining the request 37 * with {@link android.app.Activity#getResources}:</p> 38 * <pre>Configuration config = getResources().getConfiguration();</pre> 39 */ 40public final class Configuration implements Parcelable, Comparable<Configuration> { 41 /** @hide */ 42 public static final Configuration EMPTY = new Configuration(); 43 44 /** 45 * Current user preference for the scaling factor for fonts, relative 46 * to the base density scaling. 47 */ 48 public float fontScale; 49 50 /** 51 * IMSI MCC (Mobile Country Code), corresponding to 52 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#MccQualifier">mcc</a> 53 * resource qualifier. 0 if undefined. 54 */ 55 public int mcc; 56 57 /** 58 * IMSI MNC (Mobile Network Code), corresponding to 59 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#MccQualifier">mnc</a> 60 * resource qualifier. 0 if undefined. Note that the actual MNC may be 0; in order to check 61 * for this use the {@link #MNC_ZERO} symbol. 62 */ 63 public int mnc; 64 65 /** 66 * Constant used to to represent MNC (Mobile Network Code) zero. 67 * 0 cannot be used, since it is used to represent an undefined MNC. 68 */ 69 public static final int MNC_ZERO = 0xffff; 70 71 /** 72 * Current user preference for the locale, corresponding to 73 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#LocaleQualifier">locale</a> 74 * resource qualifier. 75 */ 76 public Locale locale; 77 78 /** 79 * Locale should persist on setting. This is hidden because it is really 80 * questionable whether this is the right way to expose the functionality. 81 * @hide 82 */ 83 public boolean userSetLocale; 84 85 /** Constant for {@link #screenLayout}: bits that encode the size. */ 86 public static final int SCREENLAYOUT_SIZE_MASK = 0x0f; 87 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} 88 * value indicating that no size has been set. */ 89 public static final int SCREENLAYOUT_SIZE_UNDEFINED = 0x00; 90 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} 91 * value indicating the screen is at least approximately 320x426 dp units, 92 * corresponds to the 93 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">small</a> 94 * resource qualifier. 95 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting 96 * Multiple Screens</a> for more information. */ 97 public static final int SCREENLAYOUT_SIZE_SMALL = 0x01; 98 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} 99 * value indicating the screen is at least approximately 320x470 dp units, 100 * corresponds to the 101 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">normal</a> 102 * resource qualifier. 103 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting 104 * Multiple Screens</a> for more information. */ 105 public static final int SCREENLAYOUT_SIZE_NORMAL = 0x02; 106 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} 107 * value indicating the screen is at least approximately 480x640 dp units, 108 * corresponds to the 109 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">large</a> 110 * resource qualifier. 111 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting 112 * Multiple Screens</a> for more information. */ 113 public static final int SCREENLAYOUT_SIZE_LARGE = 0x03; 114 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} 115 * value indicating the screen is at least approximately 720x960 dp units, 116 * corresponds to the 117 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">xlarge</a> 118 * resource qualifier. 119 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting 120 * Multiple Screens</a> for more information.*/ 121 public static final int SCREENLAYOUT_SIZE_XLARGE = 0x04; 122 123 /** Constant for {@link #screenLayout}: bits that encode the aspect ratio. */ 124 public static final int SCREENLAYOUT_LONG_MASK = 0x30; 125 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK} 126 * value indicating that no size has been set. */ 127 public static final int SCREENLAYOUT_LONG_UNDEFINED = 0x00; 128 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK} 129 * value that corresponds to the 130 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenAspectQualifier">notlong</a> 131 * resource qualifier. */ 132 public static final int SCREENLAYOUT_LONG_NO = 0x10; 133 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK} 134 * value that corresponds to the 135 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenAspectQualifier">long</a> 136 * resource qualifier. */ 137 public static final int SCREENLAYOUT_LONG_YES = 0x20; 138 139 /** Constant for {@link #screenLayout}: bits that encode the layout direction. */ 140 public static final int SCREENLAYOUT_LAYOUTDIR_MASK = 0xC0; 141 /** Constant for {@link #screenLayout}: bits shift to get the layout direction. */ 142 public static final int SCREENLAYOUT_LAYOUTDIR_SHIFT = 6; 143 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK} 144 * value indicating that no layout dir has been set. */ 145 public static final int SCREENLAYOUT_LAYOUTDIR_UNDEFINED = 0x00; 146 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK} 147 * value indicating that a layout dir has been set to LTR. */ 148 public static final int SCREENLAYOUT_LAYOUTDIR_LTR = 0x01 << SCREENLAYOUT_LAYOUTDIR_SHIFT; 149 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK} 150 * value indicating that a layout dir has been set to RTL. */ 151 public static final int SCREENLAYOUT_LAYOUTDIR_RTL = 0x02 << SCREENLAYOUT_LAYOUTDIR_SHIFT; 152 153 /** Constant for {@link #screenLayout}: a value indicating that screenLayout is undefined */ 154 public static final int SCREENLAYOUT_UNDEFINED = SCREENLAYOUT_SIZE_UNDEFINED | 155 SCREENLAYOUT_LONG_UNDEFINED | SCREENLAYOUT_LAYOUTDIR_UNDEFINED; 156 157 /** 158 * Special flag we generate to indicate that the screen layout requires 159 * us to use a compatibility mode for apps that are not modern layout 160 * aware. 161 * @hide 162 */ 163 public static final int SCREENLAYOUT_COMPAT_NEEDED = 0x10000000; 164 165 /** 166 * Bit mask of overall layout of the screen. Currently there are two 167 * fields: 168 * <p>The {@link #SCREENLAYOUT_SIZE_MASK} bits define the overall size 169 * of the screen. They may be one of 170 * {@link #SCREENLAYOUT_SIZE_SMALL}, {@link #SCREENLAYOUT_SIZE_NORMAL}, 171 * {@link #SCREENLAYOUT_SIZE_LARGE}, or {@link #SCREENLAYOUT_SIZE_XLARGE}. 172 * 173 * <p>The {@link #SCREENLAYOUT_LONG_MASK} defines whether the screen 174 * is wider/taller than normal. They may be one of 175 * {@link #SCREENLAYOUT_LONG_NO} or {@link #SCREENLAYOUT_LONG_YES}. 176 * 177 * <p>The {@link #SCREENLAYOUT_LAYOUTDIR_MASK} defines whether the screen layout 178 * is either LTR or RTL. They may be one of 179 * {@link #SCREENLAYOUT_LAYOUTDIR_LTR} or {@link #SCREENLAYOUT_LAYOUTDIR_RTL}. 180 * 181 * <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting 182 * Multiple Screens</a> for more information. 183 */ 184 public int screenLayout; 185 186 /** @hide */ 187 static public int resetScreenLayout(int curLayout) { 188 return (curLayout&~(SCREENLAYOUT_LONG_MASK | SCREENLAYOUT_SIZE_MASK 189 | SCREENLAYOUT_COMPAT_NEEDED)) 190 | (SCREENLAYOUT_LONG_YES | SCREENLAYOUT_SIZE_XLARGE); 191 } 192 193 /** @hide */ 194 static public int reduceScreenLayout(int curLayout, int longSizeDp, int shortSizeDp) { 195 int screenLayoutSize; 196 boolean screenLayoutLong; 197 boolean screenLayoutCompatNeeded; 198 199 // These semi-magic numbers define our compatibility modes for 200 // applications with different screens. These are guarantees to 201 // app developers about the space they can expect for a particular 202 // configuration. DO NOT CHANGE! 203 if (longSizeDp < 470) { 204 // This is shorter than an HVGA normal density screen (which 205 // is 480 pixels on its long side). 206 screenLayoutSize = SCREENLAYOUT_SIZE_SMALL; 207 screenLayoutLong = false; 208 screenLayoutCompatNeeded = false; 209 } else { 210 // What size is this screen screen? 211 if (longSizeDp >= 960 && shortSizeDp >= 720) { 212 // 1.5xVGA or larger screens at medium density are the point 213 // at which we consider it to be an extra large screen. 214 screenLayoutSize = SCREENLAYOUT_SIZE_XLARGE; 215 } else if (longSizeDp >= 640 && shortSizeDp >= 480) { 216 // VGA or larger screens at medium density are the point 217 // at which we consider it to be a large screen. 218 screenLayoutSize = SCREENLAYOUT_SIZE_LARGE; 219 } else { 220 screenLayoutSize = SCREENLAYOUT_SIZE_NORMAL; 221 } 222 223 // If this screen is wider than normal HVGA, or taller 224 // than FWVGA, then for old apps we want to run in size 225 // compatibility mode. 226 if (shortSizeDp > 321 || longSizeDp > 570) { 227 screenLayoutCompatNeeded = true; 228 } else { 229 screenLayoutCompatNeeded = false; 230 } 231 232 // Is this a long screen? 233 if (((longSizeDp*3)/5) >= (shortSizeDp-1)) { 234 // Anything wider than WVGA (5:3) is considering to be long. 235 screenLayoutLong = true; 236 } else { 237 screenLayoutLong = false; 238 } 239 } 240 241 // Now reduce the last screenLayout to not be better than what we 242 // have found. 243 if (!screenLayoutLong) { 244 curLayout = (curLayout&~SCREENLAYOUT_LONG_MASK) | SCREENLAYOUT_LONG_NO; 245 } 246 if (screenLayoutCompatNeeded) { 247 curLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; 248 } 249 int curSize = curLayout&SCREENLAYOUT_SIZE_MASK; 250 if (screenLayoutSize < curSize) { 251 curLayout = (curLayout&~SCREENLAYOUT_SIZE_MASK) | screenLayoutSize; 252 } 253 return curLayout; 254 } 255 256 /** 257 * Check if the Configuration's current {@link #screenLayout} is at 258 * least the given size. 259 * 260 * @param size The desired size, either {@link #SCREENLAYOUT_SIZE_SMALL}, 261 * {@link #SCREENLAYOUT_SIZE_NORMAL}, {@link #SCREENLAYOUT_SIZE_LARGE}, or 262 * {@link #SCREENLAYOUT_SIZE_XLARGE}. 263 * @return Returns true if the current screen layout size is at least 264 * the given size. 265 */ 266 public boolean isLayoutSizeAtLeast(int size) { 267 int cur = screenLayout&SCREENLAYOUT_SIZE_MASK; 268 if (cur == SCREENLAYOUT_SIZE_UNDEFINED) return false; 269 return cur >= size; 270 } 271 272 /** Constant for {@link #touchscreen}: a value indicating that no value has been set. */ 273 public static final int TOUCHSCREEN_UNDEFINED = 0; 274 /** Constant for {@link #touchscreen}, value corresponding to the 275 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#TouchscreenQualifier">notouch</a> 276 * resource qualifier. */ 277 public static final int TOUCHSCREEN_NOTOUCH = 1; 278 /** @deprecated Not currently supported or used. */ 279 @Deprecated public static final int TOUCHSCREEN_STYLUS = 2; 280 /** Constant for {@link #touchscreen}, value corresponding to the 281 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#TouchscreenQualifier">finger</a> 282 * resource qualifier. */ 283 public static final int TOUCHSCREEN_FINGER = 3; 284 285 /** 286 * The kind of touch screen attached to the device. 287 * One of: {@link #TOUCHSCREEN_NOTOUCH}, {@link #TOUCHSCREEN_FINGER}. 288 */ 289 public int touchscreen; 290 291 /** Constant for {@link #keyboard}: a value indicating that no value has been set. */ 292 public static final int KEYBOARD_UNDEFINED = 0; 293 /** Constant for {@link #keyboard}, value corresponding to the 294 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">nokeys</a> 295 * resource qualifier. */ 296 public static final int KEYBOARD_NOKEYS = 1; 297 /** Constant for {@link #keyboard}, value corresponding to the 298 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">qwerty</a> 299 * resource qualifier. */ 300 public static final int KEYBOARD_QWERTY = 2; 301 /** Constant for {@link #keyboard}, value corresponding to the 302 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">12key</a> 303 * resource qualifier. */ 304 public static final int KEYBOARD_12KEY = 3; 305 306 /** 307 * The kind of keyboard attached to the device. 308 * One of: {@link #KEYBOARD_NOKEYS}, {@link #KEYBOARD_QWERTY}, 309 * {@link #KEYBOARD_12KEY}. 310 */ 311 public int keyboard; 312 313 /** Constant for {@link #keyboardHidden}: a value indicating that no value has been set. */ 314 public static final int KEYBOARDHIDDEN_UNDEFINED = 0; 315 /** Constant for {@link #keyboardHidden}, value corresponding to the 316 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keysexposed</a> 317 * resource qualifier. */ 318 public static final int KEYBOARDHIDDEN_NO = 1; 319 /** Constant for {@link #keyboardHidden}, value corresponding to the 320 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keyshidden</a> 321 * resource qualifier. */ 322 public static final int KEYBOARDHIDDEN_YES = 2; 323 /** Constant matching actual resource implementation. {@hide} */ 324 public static final int KEYBOARDHIDDEN_SOFT = 3; 325 326 /** 327 * A flag indicating whether any keyboard is available. Unlike 328 * {@link #hardKeyboardHidden}, this also takes into account a soft 329 * keyboard, so if the hard keyboard is hidden but there is soft 330 * keyboard available, it will be set to NO. Value is one of: 331 * {@link #KEYBOARDHIDDEN_NO}, {@link #KEYBOARDHIDDEN_YES}. 332 */ 333 public int keyboardHidden; 334 335 /** Constant for {@link #hardKeyboardHidden}: a value indicating that no value has been set. */ 336 public static final int HARDKEYBOARDHIDDEN_UNDEFINED = 0; 337 /** Constant for {@link #hardKeyboardHidden}, value corresponding to the 338 * physical keyboard being exposed. */ 339 public static final int HARDKEYBOARDHIDDEN_NO = 1; 340 /** Constant for {@link #hardKeyboardHidden}, value corresponding to the 341 * physical keyboard being hidden. */ 342 public static final int HARDKEYBOARDHIDDEN_YES = 2; 343 344 /** 345 * A flag indicating whether the hard keyboard has been hidden. This will 346 * be set on a device with a mechanism to hide the keyboard from the 347 * user, when that mechanism is closed. One of: 348 * {@link #HARDKEYBOARDHIDDEN_NO}, {@link #HARDKEYBOARDHIDDEN_YES}. 349 */ 350 public int hardKeyboardHidden; 351 352 /** Constant for {@link #navigation}: a value indicating that no value has been set. */ 353 public static final int NAVIGATION_UNDEFINED = 0; 354 /** Constant for {@link #navigation}, value corresponding to the 355 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">nonav</a> 356 * resource qualifier. */ 357 public static final int NAVIGATION_NONAV = 1; 358 /** Constant for {@link #navigation}, value corresponding to the 359 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">dpad</a> 360 * resource qualifier. */ 361 public static final int NAVIGATION_DPAD = 2; 362 /** Constant for {@link #navigation}, value corresponding to the 363 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">trackball</a> 364 * resource qualifier. */ 365 public static final int NAVIGATION_TRACKBALL = 3; 366 /** Constant for {@link #navigation}, value corresponding to the 367 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">wheel</a> 368 * resource qualifier. */ 369 public static final int NAVIGATION_WHEEL = 4; 370 371 /** 372 * The kind of navigation method available on the device. 373 * One of: {@link #NAVIGATION_NONAV}, {@link #NAVIGATION_DPAD}, 374 * {@link #NAVIGATION_TRACKBALL}, {@link #NAVIGATION_WHEEL}. 375 */ 376 public int navigation; 377 378 /** Constant for {@link #navigationHidden}: a value indicating that no value has been set. */ 379 public static final int NAVIGATIONHIDDEN_UNDEFINED = 0; 380 /** Constant for {@link #navigationHidden}, value corresponding to the 381 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavAvailQualifier">navexposed</a> 382 * resource qualifier. */ 383 public static final int NAVIGATIONHIDDEN_NO = 1; 384 /** Constant for {@link #navigationHidden}, value corresponding to the 385 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavAvailQualifier">navhidden</a> 386 * resource qualifier. */ 387 public static final int NAVIGATIONHIDDEN_YES = 2; 388 389 /** 390 * A flag indicating whether any 5-way or DPAD navigation available. 391 * This will be set on a device with a mechanism to hide the navigation 392 * controls from the user, when that mechanism is closed. One of: 393 * {@link #NAVIGATIONHIDDEN_NO}, {@link #NAVIGATIONHIDDEN_YES}. 394 */ 395 public int navigationHidden; 396 397 /** Constant for {@link #orientation}: a value indicating that no value has been set. */ 398 public static final int ORIENTATION_UNDEFINED = 0; 399 /** Constant for {@link #orientation}, value corresponding to the 400 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#OrientationQualifier">port</a> 401 * resource qualifier. */ 402 public static final int ORIENTATION_PORTRAIT = 1; 403 /** Constant for {@link #orientation}, value corresponding to the 404 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#OrientationQualifier">land</a> 405 * resource qualifier. */ 406 public static final int ORIENTATION_LANDSCAPE = 2; 407 /** @deprecated Not currently supported or used. */ 408 @Deprecated public static final int ORIENTATION_SQUARE = 3; 409 410 /** 411 * Overall orientation of the screen. May be one of 412 * {@link #ORIENTATION_LANDSCAPE}, {@link #ORIENTATION_PORTRAIT}. 413 */ 414 public int orientation; 415 416 /** Constant for {@link #uiMode}: bits that encode the mode type. */ 417 public static final int UI_MODE_TYPE_MASK = 0x0f; 418 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} 419 * value indicating that no mode type has been set. */ 420 public static final int UI_MODE_TYPE_UNDEFINED = 0x00; 421 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} 422 * value that corresponds to 423 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">no 424 * UI mode</a> resource qualifier specified. */ 425 public static final int UI_MODE_TYPE_NORMAL = 0x01; 426 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} 427 * value that corresponds to the 428 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">desk</a> 429 * resource qualifier. */ 430 public static final int UI_MODE_TYPE_DESK = 0x02; 431 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} 432 * value that corresponds to the 433 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">car</a> 434 * resource qualifier. */ 435 public static final int UI_MODE_TYPE_CAR = 0x03; 436 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} 437 * value that corresponds to the 438 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">television</a> 439 * resource qualifier. */ 440 public static final int UI_MODE_TYPE_TELEVISION = 0x04; 441 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} 442 * value that corresponds to the 443 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">appliance</a> 444 * resource qualifier. */ 445 public static final int UI_MODE_TYPE_APPLIANCE = 0x05; 446 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK} 447 * value that corresponds to the 448 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">watch</a> 449 * resource qualifier. */ 450 public static final int UI_MODE_TYPE_WATCH = 0x06; 451 452 /** Constant for {@link #uiMode}: bits that encode the night mode. */ 453 public static final int UI_MODE_NIGHT_MASK = 0x30; 454 /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK} 455 * value indicating that no mode type has been set. */ 456 public static final int UI_MODE_NIGHT_UNDEFINED = 0x00; 457 /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK} 458 * value that corresponds to the 459 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NightQualifier">notnight</a> 460 * resource qualifier. */ 461 public static final int UI_MODE_NIGHT_NO = 0x10; 462 /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK} 463 * value that corresponds to the 464 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NightQualifier">night</a> 465 * resource qualifier. */ 466 public static final int UI_MODE_NIGHT_YES = 0x20; 467 468 /** 469 * Bit mask of the ui mode. Currently there are two fields: 470 * <p>The {@link #UI_MODE_TYPE_MASK} bits define the overall ui mode of the 471 * device. They may be one of {@link #UI_MODE_TYPE_UNDEFINED}, 472 * {@link #UI_MODE_TYPE_NORMAL}, {@link #UI_MODE_TYPE_DESK}, 473 * {@link #UI_MODE_TYPE_CAR}, {@link #UI_MODE_TYPE_TELEVISION}, 474 * {@link #UI_MODE_TYPE_APPLIANCE}, or {@link #UI_MODE_TYPE_WATCH}. 475 * 476 * <p>The {@link #UI_MODE_NIGHT_MASK} defines whether the screen 477 * is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED}, 478 * {@link #UI_MODE_NIGHT_NO} or {@link #UI_MODE_NIGHT_YES}. 479 */ 480 public int uiMode; 481 482 /** 483 * Default value for {@link #screenWidthDp} indicating that no width 484 * has been specified. 485 */ 486 public static final int SCREEN_WIDTH_DP_UNDEFINED = 0; 487 488 /** 489 * The current width of the available screen space, in dp units, 490 * corresponding to 491 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenWidthQualifier">screen 492 * width</a> resource qualifier. Set to 493 * {@link #SCREEN_WIDTH_DP_UNDEFINED} if no width is specified. 494 */ 495 public int screenWidthDp; 496 497 /** 498 * Default value for {@link #screenHeightDp} indicating that no width 499 * has been specified. 500 */ 501 public static final int SCREEN_HEIGHT_DP_UNDEFINED = 0; 502 503 /** 504 * The current height of the available screen space, in dp units, 505 * corresponding to 506 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenHeightQualifier">screen 507 * height</a> resource qualifier. Set to 508 * {@link #SCREEN_HEIGHT_DP_UNDEFINED} if no height is specified. 509 */ 510 public int screenHeightDp; 511 512 /** 513 * Default value for {@link #smallestScreenWidthDp} indicating that no width 514 * has been specified. 515 */ 516 public static final int SMALLEST_SCREEN_WIDTH_DP_UNDEFINED = 0; 517 518 /** 519 * The smallest screen size an application will see in normal operation, 520 * corresponding to 521 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#SmallestScreenWidthQualifier">smallest 522 * screen width</a> resource qualifier. 523 * This is the smallest value of both screenWidthDp and screenHeightDp 524 * in both portrait and landscape. Set to 525 * {@link #SMALLEST_SCREEN_WIDTH_DP_UNDEFINED} if no width is specified. 526 */ 527 public int smallestScreenWidthDp; 528 529 /** 530 * Default value for {@link #densityDpi} indicating that no width 531 * has been specified. 532 */ 533 public static final int DENSITY_DPI_UNDEFINED = 0; 534 535 /** 536 * Value for {@link #densityDpi} for resources that scale to any density (vector drawables). 537 * {@hide} 538 */ 539 public static final int DENSITY_DPI_ANY = 0xfffe; 540 541 /** 542 * Value for {@link #densityDpi} for resources that are not meant to be scaled. 543 * {@hide} 544 */ 545 public static final int DENSITY_DPI_NONE = 0xffff; 546 547 /** 548 * The target screen density being rendered to, 549 * corresponding to 550 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#DensityQualifier">density</a> 551 * resource qualifier. Set to 552 * {@link #DENSITY_DPI_UNDEFINED} if no density is specified. 553 */ 554 public int densityDpi; 555 556 /** @hide Hack to get this information from WM to app running in compat mode. */ 557 public int compatScreenWidthDp; 558 /** @hide Hack to get this information from WM to app running in compat mode. */ 559 public int compatScreenHeightDp; 560 /** @hide Hack to get this information from WM to app running in compat mode. */ 561 public int compatSmallestScreenWidthDp; 562 563 /** 564 * @hide Internal book-keeping. 565 */ 566 public int seq; 567 568 /** @hide Native-specific bit mask for MCC config; DO NOT USE UNLESS YOU ARE SURE. */ 569 public static final int NATIVE_CONFIG_MCC = 0x0001; 570 /** @hide Native-specific bit mask for MNC config; DO NOT USE UNLESS YOU ARE SURE. */ 571 public static final int NATIVE_CONFIG_MNC = 0x0002; 572 /** @hide Native-specific bit mask for LOCALE config; DO NOT USE UNLESS YOU ARE SURE. */ 573 public static final int NATIVE_CONFIG_LOCALE = 0x0004; 574 /** @hide Native-specific bit mask for TOUCHSCREEN config; DO NOT USE UNLESS YOU ARE SURE. */ 575 public static final int NATIVE_CONFIG_TOUCHSCREEN = 0x0008; 576 /** @hide Native-specific bit mask for KEYBOARD config; DO NOT USE UNLESS YOU ARE SURE. */ 577 public static final int NATIVE_CONFIG_KEYBOARD = 0x0010; 578 /** @hide Native-specific bit mask for KEYBOARD_HIDDEN config; DO NOT USE UNLESS YOU 579 * ARE SURE. */ 580 public static final int NATIVE_CONFIG_KEYBOARD_HIDDEN = 0x0020; 581 /** @hide Native-specific bit mask for NAVIGATION config; DO NOT USE UNLESS YOU ARE SURE. */ 582 public static final int NATIVE_CONFIG_NAVIGATION = 0x0040; 583 /** @hide Native-specific bit mask for ORIENTATION config; DO NOT USE UNLESS YOU ARE SURE. */ 584 public static final int NATIVE_CONFIG_ORIENTATION = 0x0080; 585 /** @hide Native-specific bit mask for DENSITY config; DO NOT USE UNLESS YOU ARE SURE. */ 586 public static final int NATIVE_CONFIG_DENSITY = 0x0100; 587 /** @hide Native-specific bit mask for SCREEN_SIZE config; DO NOT USE UNLESS YOU ARE SURE. */ 588 public static final int NATIVE_CONFIG_SCREEN_SIZE = 0x0200; 589 /** @hide Native-specific bit mask for VERSION config; DO NOT USE UNLESS YOU ARE SURE. */ 590 public static final int NATIVE_CONFIG_VERSION = 0x0400; 591 /** @hide Native-specific bit mask for SCREEN_LAYOUT config; DO NOT USE UNLESS YOU ARE SURE. */ 592 public static final int NATIVE_CONFIG_SCREEN_LAYOUT = 0x0800; 593 /** @hide Native-specific bit mask for UI_MODE config; DO NOT USE UNLESS YOU ARE SURE. */ 594 public static final int NATIVE_CONFIG_UI_MODE = 0x1000; 595 /** @hide Native-specific bit mask for SMALLEST_SCREEN_SIZE config; DO NOT USE UNLESS YOU 596 * ARE SURE. */ 597 public static final int NATIVE_CONFIG_SMALLEST_SCREEN_SIZE = 0x2000; 598 /** @hide Native-specific bit mask for LAYOUTDIR config ; DO NOT USE UNLESS YOU ARE SURE.*/ 599 public static final int NATIVE_CONFIG_LAYOUTDIR = 0x4000; 600 601 /** 602 * Construct an invalid Configuration. You must call {@link #setToDefaults} 603 * for this object to be valid. {@more} 604 */ 605 public Configuration() { 606 setToDefaults(); 607 } 608 609 /** 610 * Makes a deep copy suitable for modification. 611 */ 612 public Configuration(Configuration o) { 613 setTo(o); 614 } 615 616 public void setTo(Configuration o) { 617 fontScale = o.fontScale; 618 mcc = o.mcc; 619 mnc = o.mnc; 620 if (o.locale != null) { 621 locale = (Locale) o.locale.clone(); 622 } 623 userSetLocale = o.userSetLocale; 624 touchscreen = o.touchscreen; 625 keyboard = o.keyboard; 626 keyboardHidden = o.keyboardHidden; 627 hardKeyboardHidden = o.hardKeyboardHidden; 628 navigation = o.navigation; 629 navigationHidden = o.navigationHidden; 630 orientation = o.orientation; 631 screenLayout = o.screenLayout; 632 uiMode = o.uiMode; 633 screenWidthDp = o.screenWidthDp; 634 screenHeightDp = o.screenHeightDp; 635 smallestScreenWidthDp = o.smallestScreenWidthDp; 636 densityDpi = o.densityDpi; 637 compatScreenWidthDp = o.compatScreenWidthDp; 638 compatScreenHeightDp = o.compatScreenHeightDp; 639 compatSmallestScreenWidthDp = o.compatSmallestScreenWidthDp; 640 seq = o.seq; 641 } 642 643 public String toString() { 644 StringBuilder sb = new StringBuilder(128); 645 sb.append("{"); 646 sb.append(fontScale); 647 sb.append(" "); 648 if (mcc != 0) { 649 sb.append(mcc); 650 sb.append("mcc"); 651 } else { 652 sb.append("?mcc"); 653 } 654 if (mnc != 0) { 655 sb.append(mnc); 656 sb.append("mnc"); 657 } else { 658 sb.append("?mnc"); 659 } 660 if (locale != null) { 661 sb.append(" "); 662 sb.append(locale); 663 } else { 664 sb.append(" ?locale"); 665 } 666 int layoutDir = (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK); 667 switch (layoutDir) { 668 case SCREENLAYOUT_LAYOUTDIR_UNDEFINED: sb.append(" ?layoutDir"); break; 669 case SCREENLAYOUT_LAYOUTDIR_LTR: sb.append(" ldltr"); break; 670 case SCREENLAYOUT_LAYOUTDIR_RTL: sb.append(" ldrtl"); break; 671 default: sb.append(" layoutDir="); 672 sb.append(layoutDir >> SCREENLAYOUT_LAYOUTDIR_SHIFT); break; 673 } 674 if (smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { 675 sb.append(" sw"); sb.append(smallestScreenWidthDp); sb.append("dp"); 676 } else { 677 sb.append(" ?swdp"); 678 } 679 if (screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) { 680 sb.append(" w"); sb.append(screenWidthDp); sb.append("dp"); 681 } else { 682 sb.append(" ?wdp"); 683 } 684 if (screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) { 685 sb.append(" h"); sb.append(screenHeightDp); sb.append("dp"); 686 } else { 687 sb.append(" ?hdp"); 688 } 689 if (densityDpi != DENSITY_DPI_UNDEFINED) { 690 sb.append(" "); sb.append(densityDpi); sb.append("dpi"); 691 } else { 692 sb.append(" ?density"); 693 } 694 switch ((screenLayout&SCREENLAYOUT_SIZE_MASK)) { 695 case SCREENLAYOUT_SIZE_UNDEFINED: sb.append(" ?lsize"); break; 696 case SCREENLAYOUT_SIZE_SMALL: sb.append(" smll"); break; 697 case SCREENLAYOUT_SIZE_NORMAL: sb.append(" nrml"); break; 698 case SCREENLAYOUT_SIZE_LARGE: sb.append(" lrg"); break; 699 case SCREENLAYOUT_SIZE_XLARGE: sb.append(" xlrg"); break; 700 default: sb.append(" layoutSize="); 701 sb.append(screenLayout&SCREENLAYOUT_SIZE_MASK); break; 702 } 703 switch ((screenLayout&SCREENLAYOUT_LONG_MASK)) { 704 case SCREENLAYOUT_LONG_UNDEFINED: sb.append(" ?long"); break; 705 case SCREENLAYOUT_LONG_NO: /* not-long is not interesting to print */ break; 706 case SCREENLAYOUT_LONG_YES: sb.append(" long"); break; 707 default: sb.append(" layoutLong="); 708 sb.append(screenLayout&SCREENLAYOUT_LONG_MASK); break; 709 } 710 switch (orientation) { 711 case ORIENTATION_UNDEFINED: sb.append(" ?orien"); break; 712 case ORIENTATION_LANDSCAPE: sb.append(" land"); break; 713 case ORIENTATION_PORTRAIT: sb.append(" port"); break; 714 default: sb.append(" orien="); sb.append(orientation); break; 715 } 716 switch ((uiMode&UI_MODE_TYPE_MASK)) { 717 case UI_MODE_TYPE_UNDEFINED: sb.append(" ?uimode"); break; 718 case UI_MODE_TYPE_NORMAL: /* normal is not interesting to print */ break; 719 case UI_MODE_TYPE_DESK: sb.append(" desk"); break; 720 case UI_MODE_TYPE_CAR: sb.append(" car"); break; 721 case UI_MODE_TYPE_TELEVISION: sb.append(" television"); break; 722 case UI_MODE_TYPE_APPLIANCE: sb.append(" appliance"); break; 723 case UI_MODE_TYPE_WATCH: sb.append(" watch"); break; 724 default: sb.append(" uimode="); sb.append(uiMode&UI_MODE_TYPE_MASK); break; 725 } 726 switch ((uiMode&UI_MODE_NIGHT_MASK)) { 727 case UI_MODE_NIGHT_UNDEFINED: sb.append(" ?night"); break; 728 case UI_MODE_NIGHT_NO: /* not-night is not interesting to print */ break; 729 case UI_MODE_NIGHT_YES: sb.append(" night"); break; 730 default: sb.append(" night="); sb.append(uiMode&UI_MODE_NIGHT_MASK); break; 731 } 732 switch (touchscreen) { 733 case TOUCHSCREEN_UNDEFINED: sb.append(" ?touch"); break; 734 case TOUCHSCREEN_NOTOUCH: sb.append(" -touch"); break; 735 case TOUCHSCREEN_STYLUS: sb.append(" stylus"); break; 736 case TOUCHSCREEN_FINGER: sb.append(" finger"); break; 737 default: sb.append(" touch="); sb.append(touchscreen); break; 738 } 739 switch (keyboard) { 740 case KEYBOARD_UNDEFINED: sb.append(" ?keyb"); break; 741 case KEYBOARD_NOKEYS: sb.append(" -keyb"); break; 742 case KEYBOARD_QWERTY: sb.append(" qwerty"); break; 743 case KEYBOARD_12KEY: sb.append(" 12key"); break; 744 default: sb.append(" keys="); sb.append(keyboard); break; 745 } 746 switch (keyboardHidden) { 747 case KEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break; 748 case KEYBOARDHIDDEN_NO: sb.append("/v"); break; 749 case KEYBOARDHIDDEN_YES: sb.append("/h"); break; 750 case KEYBOARDHIDDEN_SOFT: sb.append("/s"); break; 751 default: sb.append("/"); sb.append(keyboardHidden); break; 752 } 753 switch (hardKeyboardHidden) { 754 case HARDKEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break; 755 case HARDKEYBOARDHIDDEN_NO: sb.append("/v"); break; 756 case HARDKEYBOARDHIDDEN_YES: sb.append("/h"); break; 757 default: sb.append("/"); sb.append(hardKeyboardHidden); break; 758 } 759 switch (navigation) { 760 case NAVIGATION_UNDEFINED: sb.append(" ?nav"); break; 761 case NAVIGATION_NONAV: sb.append(" -nav"); break; 762 case NAVIGATION_DPAD: sb.append(" dpad"); break; 763 case NAVIGATION_TRACKBALL: sb.append(" tball"); break; 764 case NAVIGATION_WHEEL: sb.append(" wheel"); break; 765 default: sb.append(" nav="); sb.append(navigation); break; 766 } 767 switch (navigationHidden) { 768 case NAVIGATIONHIDDEN_UNDEFINED: sb.append("/?"); break; 769 case NAVIGATIONHIDDEN_NO: sb.append("/v"); break; 770 case NAVIGATIONHIDDEN_YES: sb.append("/h"); break; 771 default: sb.append("/"); sb.append(navigationHidden); break; 772 } 773 if (seq != 0) { 774 sb.append(" s."); 775 sb.append(seq); 776 } 777 sb.append('}'); 778 return sb.toString(); 779 } 780 781 /** 782 * Set this object to the system defaults. 783 */ 784 public void setToDefaults() { 785 fontScale = 1; 786 mcc = mnc = 0; 787 locale = null; 788 userSetLocale = false; 789 touchscreen = TOUCHSCREEN_UNDEFINED; 790 keyboard = KEYBOARD_UNDEFINED; 791 keyboardHidden = KEYBOARDHIDDEN_UNDEFINED; 792 hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED; 793 navigation = NAVIGATION_UNDEFINED; 794 navigationHidden = NAVIGATIONHIDDEN_UNDEFINED; 795 orientation = ORIENTATION_UNDEFINED; 796 screenLayout = SCREENLAYOUT_UNDEFINED; 797 uiMode = UI_MODE_TYPE_UNDEFINED; 798 screenWidthDp = compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED; 799 screenHeightDp = compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED; 800 smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; 801 densityDpi = DENSITY_DPI_UNDEFINED; 802 seq = 0; 803 } 804 805 /** {@hide} */ 806 @Deprecated public void makeDefault() { 807 setToDefaults(); 808 } 809 810 /** 811 * Copy the fields from delta into this Configuration object, keeping 812 * track of which ones have changed. Any undefined fields in 813 * <var>delta</var> are ignored and not copied in to the current 814 * Configuration. 815 * @return Returns a bit mask of the changed fields, as per 816 * {@link #diff}. 817 */ 818 public int updateFrom(Configuration delta) { 819 int changed = 0; 820 if (delta.fontScale > 0 && fontScale != delta.fontScale) { 821 changed |= ActivityInfo.CONFIG_FONT_SCALE; 822 fontScale = delta.fontScale; 823 } 824 if (delta.mcc != 0 && mcc != delta.mcc) { 825 changed |= ActivityInfo.CONFIG_MCC; 826 mcc = delta.mcc; 827 } 828 if (delta.mnc != 0 && mnc != delta.mnc) { 829 changed |= ActivityInfo.CONFIG_MNC; 830 mnc = delta.mnc; 831 } 832 if (delta.locale != null 833 && (locale == null || !locale.equals(delta.locale))) { 834 changed |= ActivityInfo.CONFIG_LOCALE; 835 locale = delta.locale != null 836 ? (Locale) delta.locale.clone() : null; 837 // If locale has changed, then layout direction is also changed ... 838 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; 839 // ... and we need to update the layout direction (represented by the first 840 // 2 most significant bits in screenLayout). 841 setLayoutDirection(locale); 842 } 843 final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK; 844 if (deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED && 845 deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) { 846 screenLayout = (screenLayout & ~SCREENLAYOUT_LAYOUTDIR_MASK) | deltaScreenLayoutDir; 847 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; 848 } 849 if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0))) 850 { 851 changed |= ActivityInfo.CONFIG_LOCALE; 852 userSetLocale = true; 853 } 854 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED 855 && touchscreen != delta.touchscreen) { 856 changed |= ActivityInfo.CONFIG_TOUCHSCREEN; 857 touchscreen = delta.touchscreen; 858 } 859 if (delta.keyboard != KEYBOARD_UNDEFINED 860 && keyboard != delta.keyboard) { 861 changed |= ActivityInfo.CONFIG_KEYBOARD; 862 keyboard = delta.keyboard; 863 } 864 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED 865 && keyboardHidden != delta.keyboardHidden) { 866 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 867 keyboardHidden = delta.keyboardHidden; 868 } 869 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED 870 && hardKeyboardHidden != delta.hardKeyboardHidden) { 871 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 872 hardKeyboardHidden = delta.hardKeyboardHidden; 873 } 874 if (delta.navigation != NAVIGATION_UNDEFINED 875 && navigation != delta.navigation) { 876 changed |= ActivityInfo.CONFIG_NAVIGATION; 877 navigation = delta.navigation; 878 } 879 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED 880 && navigationHidden != delta.navigationHidden) { 881 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 882 navigationHidden = delta.navigationHidden; 883 } 884 if (delta.orientation != ORIENTATION_UNDEFINED 885 && orientation != delta.orientation) { 886 changed |= ActivityInfo.CONFIG_ORIENTATION; 887 orientation = delta.orientation; 888 } 889 if (getScreenLayoutNoDirection(delta.screenLayout) != 890 (SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED) 891 && (getScreenLayoutNoDirection(screenLayout) != 892 getScreenLayoutNoDirection(delta.screenLayout))) { 893 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; 894 // We need to preserve the previous layout dir bits if they were defined 895 if ((delta.screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == 0) { 896 screenLayout = (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK)|delta.screenLayout; 897 } else { 898 screenLayout = delta.screenLayout; 899 } 900 } 901 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED) 902 && uiMode != delta.uiMode) { 903 changed |= ActivityInfo.CONFIG_UI_MODE; 904 if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) { 905 uiMode = (uiMode&~UI_MODE_TYPE_MASK) 906 | (delta.uiMode&UI_MODE_TYPE_MASK); 907 } 908 if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) { 909 uiMode = (uiMode&~UI_MODE_NIGHT_MASK) 910 | (delta.uiMode&UI_MODE_NIGHT_MASK); 911 } 912 } 913 if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED 914 && screenWidthDp != delta.screenWidthDp) { 915 changed |= ActivityInfo.CONFIG_SCREEN_SIZE; 916 screenWidthDp = delta.screenWidthDp; 917 } 918 if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED 919 && screenHeightDp != delta.screenHeightDp) { 920 changed |= ActivityInfo.CONFIG_SCREEN_SIZE; 921 screenHeightDp = delta.screenHeightDp; 922 } 923 if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED 924 && smallestScreenWidthDp != delta.smallestScreenWidthDp) { 925 changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; 926 smallestScreenWidthDp = delta.smallestScreenWidthDp; 927 } 928 if (delta.densityDpi != DENSITY_DPI_UNDEFINED && 929 densityDpi != delta.densityDpi) { 930 changed |= ActivityInfo.CONFIG_DENSITY; 931 densityDpi = delta.densityDpi; 932 } 933 if (delta.compatScreenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) { 934 compatScreenWidthDp = delta.compatScreenWidthDp; 935 } 936 if (delta.compatScreenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) { 937 compatScreenHeightDp = delta.compatScreenHeightDp; 938 } 939 if (delta.compatSmallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { 940 compatSmallestScreenWidthDp = delta.compatSmallestScreenWidthDp; 941 } 942 if (delta.seq != 0) { 943 seq = delta.seq; 944 } 945 946 return changed; 947 } 948 949 /** 950 * Return a bit mask of the differences between this Configuration 951 * object and the given one. Does not change the values of either. Any 952 * undefined fields in <var>delta</var> are ignored. 953 * @return Returns a bit mask indicating which configuration 954 * values has changed, containing any combination of 955 * {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE 956 * PackageManager.ActivityInfo.CONFIG_FONT_SCALE}, 957 * {@link android.content.pm.ActivityInfo#CONFIG_MCC 958 * PackageManager.ActivityInfo.CONFIG_MCC}, 959 * {@link android.content.pm.ActivityInfo#CONFIG_MNC 960 * PackageManager.ActivityInfo.CONFIG_MNC}, 961 * {@link android.content.pm.ActivityInfo#CONFIG_LOCALE 962 * PackageManager.ActivityInfo.CONFIG_LOCALE}, 963 * {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN 964 * PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN}, 965 * {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD 966 * PackageManager.ActivityInfo.CONFIG_KEYBOARD}, 967 * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION 968 * PackageManager.ActivityInfo.CONFIG_NAVIGATION}, 969 * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION 970 * PackageManager.ActivityInfo.CONFIG_ORIENTATION}, 971 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT 972 * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}, or 973 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE 974 * PackageManager.ActivityInfo.CONFIG_SCREEN_SIZE}, or 975 * {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE 976 * PackageManager.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE}. 977 * {@link android.content.pm.ActivityInfo#CONFIG_LAYOUT_DIRECTION 978 * PackageManager.ActivityInfo.CONFIG_LAYOUT_DIRECTION}. 979 */ 980 public int diff(Configuration delta) { 981 int changed = 0; 982 if (delta.fontScale > 0 && fontScale != delta.fontScale) { 983 changed |= ActivityInfo.CONFIG_FONT_SCALE; 984 } 985 if (delta.mcc != 0 && mcc != delta.mcc) { 986 changed |= ActivityInfo.CONFIG_MCC; 987 } 988 if (delta.mnc != 0 && mnc != delta.mnc) { 989 changed |= ActivityInfo.CONFIG_MNC; 990 } 991 if (delta.locale != null 992 && (locale == null || !locale.equals(delta.locale))) { 993 changed |= ActivityInfo.CONFIG_LOCALE; 994 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; 995 } 996 final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK; 997 if (deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED && 998 deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) { 999 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; 1000 } 1001 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED 1002 && touchscreen != delta.touchscreen) { 1003 changed |= ActivityInfo.CONFIG_TOUCHSCREEN; 1004 } 1005 if (delta.keyboard != KEYBOARD_UNDEFINED 1006 && keyboard != delta.keyboard) { 1007 changed |= ActivityInfo.CONFIG_KEYBOARD; 1008 } 1009 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED 1010 && keyboardHidden != delta.keyboardHidden) { 1011 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 1012 } 1013 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED 1014 && hardKeyboardHidden != delta.hardKeyboardHidden) { 1015 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 1016 } 1017 if (delta.navigation != NAVIGATION_UNDEFINED 1018 && navigation != delta.navigation) { 1019 changed |= ActivityInfo.CONFIG_NAVIGATION; 1020 } 1021 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED 1022 && navigationHidden != delta.navigationHidden) { 1023 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 1024 } 1025 if (delta.orientation != ORIENTATION_UNDEFINED 1026 && orientation != delta.orientation) { 1027 changed |= ActivityInfo.CONFIG_ORIENTATION; 1028 } 1029 if (getScreenLayoutNoDirection(delta.screenLayout) != 1030 (SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED) 1031 && getScreenLayoutNoDirection(screenLayout) != 1032 getScreenLayoutNoDirection(delta.screenLayout)) { 1033 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; 1034 } 1035 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED) 1036 && uiMode != delta.uiMode) { 1037 changed |= ActivityInfo.CONFIG_UI_MODE; 1038 } 1039 if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED 1040 && screenWidthDp != delta.screenWidthDp) { 1041 changed |= ActivityInfo.CONFIG_SCREEN_SIZE; 1042 } 1043 if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED 1044 && screenHeightDp != delta.screenHeightDp) { 1045 changed |= ActivityInfo.CONFIG_SCREEN_SIZE; 1046 } 1047 if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED 1048 && smallestScreenWidthDp != delta.smallestScreenWidthDp) { 1049 changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; 1050 } 1051 if (delta.densityDpi != DENSITY_DPI_UNDEFINED 1052 && densityDpi != delta.densityDpi) { 1053 changed |= ActivityInfo.CONFIG_DENSITY; 1054 } 1055 1056 return changed; 1057 } 1058 1059 /** 1060 * Determine if a new resource needs to be loaded from the bit set of 1061 * configuration changes returned by {@link #updateFrom(Configuration)}. 1062 * 1063 * @param configChanges The mask of changes configurations as returned by 1064 * {@link #updateFrom(Configuration)}. 1065 * @param interestingChanges The configuration changes that the resource 1066 * can handled, as given in {@link android.util.TypedValue#changingConfigurations}. 1067 * 1068 * @return Return true if the resource needs to be loaded, else false. 1069 */ 1070 public static boolean needNewResources(int configChanges, int interestingChanges) { 1071 return (configChanges & (interestingChanges|ActivityInfo.CONFIG_FONT_SCALE)) != 0; 1072 } 1073 1074 /** 1075 * @hide Return true if the sequence of 'other' is better than this. Assumes 1076 * that 'this' is your current sequence and 'other' is a new one you have 1077 * received some how and want to compare with what you have. 1078 */ 1079 public boolean isOtherSeqNewer(Configuration other) { 1080 if (other == null) { 1081 // Sanity check. 1082 return false; 1083 } 1084 if (other.seq == 0) { 1085 // If the other sequence is not specified, then we must assume 1086 // it is newer since we don't know any better. 1087 return true; 1088 } 1089 if (seq == 0) { 1090 // If this sequence is not specified, then we also consider the 1091 // other is better. Yes we have a preference for other. Sue us. 1092 return true; 1093 } 1094 int diff = other.seq - seq; 1095 if (diff > 0x10000) { 1096 // If there has been a sufficiently large jump, assume the 1097 // sequence has wrapped around. 1098 return false; 1099 } 1100 return diff > 0; 1101 } 1102 1103 /** 1104 * Parcelable methods 1105 */ 1106 public int describeContents() { 1107 return 0; 1108 } 1109 1110 public void writeToParcel(Parcel dest, int flags) { 1111 dest.writeFloat(fontScale); 1112 dest.writeInt(mcc); 1113 dest.writeInt(mnc); 1114 if (locale == null) { 1115 dest.writeInt(0); 1116 } else { 1117 dest.writeInt(1); 1118 dest.writeString(locale.getLanguage()); 1119 dest.writeString(locale.getCountry()); 1120 dest.writeString(locale.getVariant()); 1121 } 1122 if(userSetLocale) { 1123 dest.writeInt(1); 1124 } else { 1125 dest.writeInt(0); 1126 } 1127 dest.writeInt(touchscreen); 1128 dest.writeInt(keyboard); 1129 dest.writeInt(keyboardHidden); 1130 dest.writeInt(hardKeyboardHidden); 1131 dest.writeInt(navigation); 1132 dest.writeInt(navigationHidden); 1133 dest.writeInt(orientation); 1134 dest.writeInt(screenLayout); 1135 dest.writeInt(uiMode); 1136 dest.writeInt(screenWidthDp); 1137 dest.writeInt(screenHeightDp); 1138 dest.writeInt(smallestScreenWidthDp); 1139 dest.writeInt(densityDpi); 1140 dest.writeInt(compatScreenWidthDp); 1141 dest.writeInt(compatScreenHeightDp); 1142 dest.writeInt(compatSmallestScreenWidthDp); 1143 dest.writeInt(seq); 1144 } 1145 1146 public void readFromParcel(Parcel source) { 1147 fontScale = source.readFloat(); 1148 mcc = source.readInt(); 1149 mnc = source.readInt(); 1150 if (source.readInt() != 0) { 1151 locale = new Locale(source.readString(), source.readString(), 1152 source.readString()); 1153 } 1154 userSetLocale = (source.readInt()==1); 1155 touchscreen = source.readInt(); 1156 keyboard = source.readInt(); 1157 keyboardHidden = source.readInt(); 1158 hardKeyboardHidden = source.readInt(); 1159 navigation = source.readInt(); 1160 navigationHidden = source.readInt(); 1161 orientation = source.readInt(); 1162 screenLayout = source.readInt(); 1163 uiMode = source.readInt(); 1164 screenWidthDp = source.readInt(); 1165 screenHeightDp = source.readInt(); 1166 smallestScreenWidthDp = source.readInt(); 1167 densityDpi = source.readInt(); 1168 compatScreenWidthDp = source.readInt(); 1169 compatScreenHeightDp = source.readInt(); 1170 compatSmallestScreenWidthDp = source.readInt(); 1171 seq = source.readInt(); 1172 } 1173 1174 public static final Parcelable.Creator<Configuration> CREATOR 1175 = new Parcelable.Creator<Configuration>() { 1176 public Configuration createFromParcel(Parcel source) { 1177 return new Configuration(source); 1178 } 1179 1180 public Configuration[] newArray(int size) { 1181 return new Configuration[size]; 1182 } 1183 }; 1184 1185 /** 1186 * Construct this Configuration object, reading from the Parcel. 1187 */ 1188 private Configuration(Parcel source) { 1189 readFromParcel(source); 1190 } 1191 1192 public int compareTo(Configuration that) { 1193 int n; 1194 float a = this.fontScale; 1195 float b = that.fontScale; 1196 if (a < b) return -1; 1197 if (a > b) return 1; 1198 n = this.mcc - that.mcc; 1199 if (n != 0) return n; 1200 n = this.mnc - that.mnc; 1201 if (n != 0) return n; 1202 if (this.locale == null) { 1203 if (that.locale != null) return 1; 1204 } else if (that.locale == null) { 1205 return -1; 1206 } else { 1207 n = this.locale.getLanguage().compareTo(that.locale.getLanguage()); 1208 if (n != 0) return n; 1209 n = this.locale.getCountry().compareTo(that.locale.getCountry()); 1210 if (n != 0) return n; 1211 n = this.locale.getVariant().compareTo(that.locale.getVariant()); 1212 if (n != 0) return n; 1213 } 1214 n = this.touchscreen - that.touchscreen; 1215 if (n != 0) return n; 1216 n = this.keyboard - that.keyboard; 1217 if (n != 0) return n; 1218 n = this.keyboardHidden - that.keyboardHidden; 1219 if (n != 0) return n; 1220 n = this.hardKeyboardHidden - that.hardKeyboardHidden; 1221 if (n != 0) return n; 1222 n = this.navigation - that.navigation; 1223 if (n != 0) return n; 1224 n = this.navigationHidden - that.navigationHidden; 1225 if (n != 0) return n; 1226 n = this.orientation - that.orientation; 1227 if (n != 0) return n; 1228 n = this.screenLayout - that.screenLayout; 1229 if (n != 0) return n; 1230 n = this.uiMode - that.uiMode; 1231 if (n != 0) return n; 1232 n = this.screenWidthDp - that.screenWidthDp; 1233 if (n != 0) return n; 1234 n = this.screenHeightDp - that.screenHeightDp; 1235 if (n != 0) return n; 1236 n = this.smallestScreenWidthDp - that.smallestScreenWidthDp; 1237 if (n != 0) return n; 1238 n = this.densityDpi - that.densityDpi; 1239 //if (n != 0) return n; 1240 return n; 1241 } 1242 1243 public boolean equals(Configuration that) { 1244 if (that == null) return false; 1245 if (that == this) return true; 1246 return this.compareTo(that) == 0; 1247 } 1248 1249 public boolean equals(Object that) { 1250 try { 1251 return equals((Configuration)that); 1252 } catch (ClassCastException e) { 1253 } 1254 return false; 1255 } 1256 1257 public int hashCode() { 1258 int result = 17; 1259 result = 31 * result + Float.floatToIntBits(fontScale); 1260 result = 31 * result + mcc; 1261 result = 31 * result + mnc; 1262 result = 31 * result + (locale != null ? locale.hashCode() : 0); 1263 result = 31 * result + touchscreen; 1264 result = 31 * result + keyboard; 1265 result = 31 * result + keyboardHidden; 1266 result = 31 * result + hardKeyboardHidden; 1267 result = 31 * result + navigation; 1268 result = 31 * result + navigationHidden; 1269 result = 31 * result + orientation; 1270 result = 31 * result + screenLayout; 1271 result = 31 * result + uiMode; 1272 result = 31 * result + screenWidthDp; 1273 result = 31 * result + screenHeightDp; 1274 result = 31 * result + smallestScreenWidthDp; 1275 result = 31 * result + densityDpi; 1276 return result; 1277 } 1278 1279 /** 1280 * Set the locale. This is the preferred way for setting up the locale (instead of using the 1281 * direct accessor). This will also set the userLocale and layout direction according to 1282 * the locale. 1283 * 1284 * @param loc The locale. Can be null. 1285 */ 1286 public void setLocale(Locale loc) { 1287 locale = loc; 1288 userSetLocale = true; 1289 setLayoutDirection(locale); 1290 } 1291 1292 /** 1293 * Return the layout direction. Will be either {@link View#LAYOUT_DIRECTION_LTR} or 1294 * {@link View#LAYOUT_DIRECTION_RTL}. 1295 * 1296 * @return Returns {@link View#LAYOUT_DIRECTION_RTL} if the configuration 1297 * is {@link #SCREENLAYOUT_LAYOUTDIR_RTL}, otherwise {@link View#LAYOUT_DIRECTION_LTR}. 1298 */ 1299 public int getLayoutDirection() { 1300 return (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == SCREENLAYOUT_LAYOUTDIR_RTL 1301 ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR; 1302 } 1303 1304 /** 1305 * Set the layout direction from the Locale. 1306 * 1307 * @param locale The Locale. If null will set the layout direction to 1308 * {@link View#LAYOUT_DIRECTION_LTR}. If not null will set it to the layout direction 1309 * corresponding to the Locale. 1310 * 1311 * @see {@link View#LAYOUT_DIRECTION_LTR} and {@link View#LAYOUT_DIRECTION_RTL} 1312 */ 1313 public void setLayoutDirection(Locale locale) { 1314 // There is a "1" difference between the configuration values for 1315 // layout direction and View constants for layout direction, just add "1". 1316 final int layoutDirection = 1 + TextUtils.getLayoutDirectionFromLocale(locale); 1317 screenLayout = (screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK)| 1318 (layoutDirection << SCREENLAYOUT_LAYOUTDIR_SHIFT); 1319 } 1320 1321 private static int getScreenLayoutNoDirection(int screenLayout) { 1322 return screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK; 1323 } 1324 1325 /** 1326 * 1327 * @hide 1328 */ 1329 public static String localeToResourceQualifier(Locale locale) { 1330 StringBuilder sb = new StringBuilder(); 1331 boolean l = (locale.getLanguage().length() != 0); 1332 boolean c = (locale.getCountry().length() != 0); 1333 boolean s = (locale.getScript().length() != 0); 1334 boolean v = (locale.getVariant().length() != 0); 1335 1336 if (l) { 1337 sb.append(locale.getLanguage()); 1338 if (c) { 1339 sb.append("-r").append(locale.getCountry()); 1340 if (s) { 1341 sb.append("-s").append(locale.getScript()); 1342 if (v) { 1343 sb.append("-v").append(locale.getVariant()); 1344 } 1345 } 1346 } 1347 } 1348 return sb.toString(); 1349 } 1350 1351 1352 /** 1353 * Returns a string representation of the configuration that can be parsed 1354 * by build tools (like AAPT). 1355 * 1356 * 1357 * 1358 * @hide 1359 */ 1360 public static String resourceQualifierString(Configuration config) { 1361 ArrayList<String> parts = new ArrayList<String>(); 1362 1363 if (config.mcc != 0) { 1364 parts.add(config.mcc + "mcc"); 1365 if (config.mnc != 0) { 1366 parts.add(config.mnc + "mnc"); 1367 } 1368 } 1369 1370 if (!config.locale.getLanguage().isEmpty()) { 1371 parts.add(localeToResourceQualifier(config.locale)); 1372 } 1373 1374 switch (config.screenLayout & Configuration.SCREENLAYOUT_LAYOUTDIR_MASK) { 1375 case Configuration.SCREENLAYOUT_LAYOUTDIR_LTR: 1376 parts.add("ldltr"); 1377 break; 1378 case Configuration.SCREENLAYOUT_LAYOUTDIR_RTL: 1379 parts.add("ldrtl"); 1380 break; 1381 default: 1382 break; 1383 } 1384 1385 if (config.smallestScreenWidthDp != 0) { 1386 parts.add("sw" + config.smallestScreenWidthDp + "dp"); 1387 } 1388 1389 if (config.screenWidthDp != 0) { 1390 parts.add("w" + config.screenWidthDp + "dp"); 1391 } 1392 1393 if (config.screenHeightDp != 0) { 1394 parts.add("h" + config.screenHeightDp + "dp"); 1395 } 1396 1397 switch (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) { 1398 case Configuration.SCREENLAYOUT_SIZE_SMALL: 1399 parts.add("small"); 1400 break; 1401 case Configuration.SCREENLAYOUT_SIZE_NORMAL: 1402 parts.add("normal"); 1403 break; 1404 case Configuration.SCREENLAYOUT_SIZE_LARGE: 1405 parts.add("large"); 1406 break; 1407 case Configuration.SCREENLAYOUT_SIZE_XLARGE: 1408 parts.add("xlarge"); 1409 break; 1410 default: 1411 break; 1412 } 1413 1414 switch (config.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK) { 1415 case Configuration.SCREENLAYOUT_LONG_YES: 1416 parts.add("long"); 1417 break; 1418 case Configuration.SCREENLAYOUT_LONG_NO: 1419 parts.add("notlong"); 1420 break; 1421 default: 1422 break; 1423 } 1424 1425 switch (config.orientation) { 1426 case Configuration.ORIENTATION_LANDSCAPE: 1427 parts.add("land"); 1428 break; 1429 case Configuration.ORIENTATION_PORTRAIT: 1430 parts.add("port"); 1431 break; 1432 default: 1433 break; 1434 } 1435 1436 switch (config.uiMode & Configuration.UI_MODE_TYPE_MASK) { 1437 case Configuration.UI_MODE_TYPE_APPLIANCE: 1438 parts.add("appliance"); 1439 break; 1440 case Configuration.UI_MODE_TYPE_DESK: 1441 parts.add("desk"); 1442 break; 1443 case Configuration.UI_MODE_TYPE_TELEVISION: 1444 parts.add("television"); 1445 break; 1446 case Configuration.UI_MODE_TYPE_CAR: 1447 parts.add("car"); 1448 break; 1449 case Configuration.UI_MODE_TYPE_WATCH: 1450 parts.add("watch"); 1451 break; 1452 default: 1453 break; 1454 } 1455 1456 switch (config.uiMode & Configuration.UI_MODE_NIGHT_MASK) { 1457 case Configuration.UI_MODE_NIGHT_YES: 1458 parts.add("night"); 1459 break; 1460 case Configuration.UI_MODE_NIGHT_NO: 1461 parts.add("notnight"); 1462 break; 1463 default: 1464 break; 1465 } 1466 1467 switch (config.densityDpi) { 1468 case DENSITY_DPI_UNDEFINED: 1469 break; 1470 case 120: 1471 parts.add("ldpi"); 1472 break; 1473 case 160: 1474 parts.add("mdpi"); 1475 break; 1476 case 213: 1477 parts.add("tvdpi"); 1478 break; 1479 case 240: 1480 parts.add("hdpi"); 1481 break; 1482 case 320: 1483 parts.add("xhdpi"); 1484 break; 1485 case 480: 1486 parts.add("xxhdpi"); 1487 break; 1488 case 640: 1489 parts.add("xxxhdpi"); 1490 break; 1491 case DENSITY_DPI_ANY: 1492 parts.add("anydpi"); 1493 break; 1494 case DENSITY_DPI_NONE: 1495 parts.add("nodpi"); 1496 default: 1497 parts.add(config.densityDpi + "dpi"); 1498 break; 1499 } 1500 1501 switch (config.touchscreen) { 1502 case Configuration.TOUCHSCREEN_NOTOUCH: 1503 parts.add("notouch"); 1504 break; 1505 case Configuration.TOUCHSCREEN_FINGER: 1506 parts.add("finger"); 1507 break; 1508 default: 1509 break; 1510 } 1511 1512 switch (config.keyboardHidden) { 1513 case Configuration.KEYBOARDHIDDEN_NO: 1514 parts.add("keysexposed"); 1515 break; 1516 case Configuration.KEYBOARDHIDDEN_YES: 1517 parts.add("keyshidden"); 1518 break; 1519 case Configuration.KEYBOARDHIDDEN_SOFT: 1520 parts.add("keyssoft"); 1521 break; 1522 default: 1523 break; 1524 } 1525 1526 switch (config.keyboard) { 1527 case Configuration.KEYBOARD_NOKEYS: 1528 parts.add("nokeys"); 1529 break; 1530 case Configuration.KEYBOARD_QWERTY: 1531 parts.add("qwerty"); 1532 break; 1533 case Configuration.KEYBOARD_12KEY: 1534 parts.add("12key"); 1535 break; 1536 default: 1537 break; 1538 } 1539 1540 switch (config.navigationHidden) { 1541 case Configuration.NAVIGATIONHIDDEN_NO: 1542 parts.add("navexposed"); 1543 break; 1544 case Configuration.NAVIGATIONHIDDEN_YES: 1545 parts.add("navhidden"); 1546 break; 1547 default: 1548 break; 1549 } 1550 1551 switch (config.navigation) { 1552 case Configuration.NAVIGATION_NONAV: 1553 parts.add("nonav"); 1554 break; 1555 case Configuration.NAVIGATION_DPAD: 1556 parts.add("dpad"); 1557 break; 1558 case Configuration.NAVIGATION_TRACKBALL: 1559 parts.add("trackball"); 1560 break; 1561 case Configuration.NAVIGATION_WHEEL: 1562 parts.add("wheel"); 1563 break; 1564 default: 1565 break; 1566 } 1567 1568 parts.add("v" + Build.VERSION.RESOURCES_SDK_INT); 1569 return TextUtils.join("-", parts); 1570 } 1571} 1572