Configuration.java revision 2c749d242759ea36c0229ea933f22b6363337b19
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 * The target screen density being rendered to, 537 * corresponding to 538 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#DensityQualifier">density</a> 539 * resource qualifier. Set to 540 * {@link #DENSITY_DPI_UNDEFINED} if no density is specified. 541 */ 542 public int densityDpi; 543 544 /** @hide Hack to get this information from WM to app running in compat mode. */ 545 public int compatScreenWidthDp; 546 /** @hide Hack to get this information from WM to app running in compat mode. */ 547 public int compatScreenHeightDp; 548 /** @hide Hack to get this information from WM to app running in compat mode. */ 549 public int compatSmallestScreenWidthDp; 550 551 /** 552 * @hide Internal book-keeping. 553 */ 554 public int seq; 555 556 /** @hide Native-specific bit mask for MCC config; DO NOT USE UNLESS YOU ARE SURE. */ 557 public static final int NATIVE_CONFIG_MCC = 0x0001; 558 /** @hide Native-specific bit mask for MNC config; DO NOT USE UNLESS YOU ARE SURE. */ 559 public static final int NATIVE_CONFIG_MNC = 0x0002; 560 /** @hide Native-specific bit mask for LOCALE config; DO NOT USE UNLESS YOU ARE SURE. */ 561 public static final int NATIVE_CONFIG_LOCALE = 0x0004; 562 /** @hide Native-specific bit mask for TOUCHSCREEN config; DO NOT USE UNLESS YOU ARE SURE. */ 563 public static final int NATIVE_CONFIG_TOUCHSCREEN = 0x0008; 564 /** @hide Native-specific bit mask for KEYBOARD config; DO NOT USE UNLESS YOU ARE SURE. */ 565 public static final int NATIVE_CONFIG_KEYBOARD = 0x0010; 566 /** @hide Native-specific bit mask for KEYBOARD_HIDDEN config; DO NOT USE UNLESS YOU 567 * ARE SURE. */ 568 public static final int NATIVE_CONFIG_KEYBOARD_HIDDEN = 0x0020; 569 /** @hide Native-specific bit mask for NAVIGATION config; DO NOT USE UNLESS YOU ARE SURE. */ 570 public static final int NATIVE_CONFIG_NAVIGATION = 0x0040; 571 /** @hide Native-specific bit mask for ORIENTATION config; DO NOT USE UNLESS YOU ARE SURE. */ 572 public static final int NATIVE_CONFIG_ORIENTATION = 0x0080; 573 /** @hide Native-specific bit mask for DENSITY config; DO NOT USE UNLESS YOU ARE SURE. */ 574 public static final int NATIVE_CONFIG_DENSITY = 0x0100; 575 /** @hide Native-specific bit mask for SCREEN_SIZE config; DO NOT USE UNLESS YOU ARE SURE. */ 576 public static final int NATIVE_CONFIG_SCREEN_SIZE = 0x0200; 577 /** @hide Native-specific bit mask for VERSION config; DO NOT USE UNLESS YOU ARE SURE. */ 578 public static final int NATIVE_CONFIG_VERSION = 0x0400; 579 /** @hide Native-specific bit mask for SCREEN_LAYOUT config; DO NOT USE UNLESS YOU ARE SURE. */ 580 public static final int NATIVE_CONFIG_SCREEN_LAYOUT = 0x0800; 581 /** @hide Native-specific bit mask for UI_MODE config; DO NOT USE UNLESS YOU ARE SURE. */ 582 public static final int NATIVE_CONFIG_UI_MODE = 0x1000; 583 /** @hide Native-specific bit mask for SMALLEST_SCREEN_SIZE config; DO NOT USE UNLESS YOU 584 * ARE SURE. */ 585 public static final int NATIVE_CONFIG_SMALLEST_SCREEN_SIZE = 0x2000; 586 /** @hide Native-specific bit mask for LAYOUTDIR config ; DO NOT USE UNLESS YOU ARE SURE.*/ 587 public static final int NATIVE_CONFIG_LAYOUTDIR = 0x4000; 588 589 /** 590 * Construct an invalid Configuration. You must call {@link #setToDefaults} 591 * for this object to be valid. {@more} 592 */ 593 public Configuration() { 594 setToDefaults(); 595 } 596 597 /** 598 * Makes a deep copy suitable for modification. 599 */ 600 public Configuration(Configuration o) { 601 setTo(o); 602 } 603 604 public void setTo(Configuration o) { 605 fontScale = o.fontScale; 606 mcc = o.mcc; 607 mnc = o.mnc; 608 if (o.locale != null) { 609 locale = (Locale) o.locale.clone(); 610 } 611 userSetLocale = o.userSetLocale; 612 touchscreen = o.touchscreen; 613 keyboard = o.keyboard; 614 keyboardHidden = o.keyboardHidden; 615 hardKeyboardHidden = o.hardKeyboardHidden; 616 navigation = o.navigation; 617 navigationHidden = o.navigationHidden; 618 orientation = o.orientation; 619 screenLayout = o.screenLayout; 620 uiMode = o.uiMode; 621 screenWidthDp = o.screenWidthDp; 622 screenHeightDp = o.screenHeightDp; 623 smallestScreenWidthDp = o.smallestScreenWidthDp; 624 densityDpi = o.densityDpi; 625 compatScreenWidthDp = o.compatScreenWidthDp; 626 compatScreenHeightDp = o.compatScreenHeightDp; 627 compatSmallestScreenWidthDp = o.compatSmallestScreenWidthDp; 628 seq = o.seq; 629 } 630 631 public String toString() { 632 StringBuilder sb = new StringBuilder(128); 633 sb.append("{"); 634 sb.append(fontScale); 635 sb.append(" "); 636 if (mcc != 0) { 637 sb.append(mcc); 638 sb.append("mcc"); 639 } else { 640 sb.append("?mcc"); 641 } 642 if (mnc != 0) { 643 sb.append(mnc); 644 sb.append("mnc"); 645 } else { 646 sb.append("?mnc"); 647 } 648 if (locale != null) { 649 sb.append(" "); 650 sb.append(locale); 651 } else { 652 sb.append(" ?locale"); 653 } 654 int layoutDir = (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK); 655 switch (layoutDir) { 656 case SCREENLAYOUT_LAYOUTDIR_UNDEFINED: sb.append(" ?layoutDir"); break; 657 case SCREENLAYOUT_LAYOUTDIR_LTR: sb.append(" ldltr"); break; 658 case SCREENLAYOUT_LAYOUTDIR_RTL: sb.append(" ldrtl"); break; 659 default: sb.append(" layoutDir="); 660 sb.append(layoutDir >> SCREENLAYOUT_LAYOUTDIR_SHIFT); break; 661 } 662 if (smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { 663 sb.append(" sw"); sb.append(smallestScreenWidthDp); sb.append("dp"); 664 } else { 665 sb.append(" ?swdp"); 666 } 667 if (screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) { 668 sb.append(" w"); sb.append(screenWidthDp); sb.append("dp"); 669 } else { 670 sb.append(" ?wdp"); 671 } 672 if (screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) { 673 sb.append(" h"); sb.append(screenHeightDp); sb.append("dp"); 674 } else { 675 sb.append(" ?hdp"); 676 } 677 if (densityDpi != DENSITY_DPI_UNDEFINED) { 678 sb.append(" "); sb.append(densityDpi); sb.append("dpi"); 679 } else { 680 sb.append(" ?density"); 681 } 682 switch ((screenLayout&SCREENLAYOUT_SIZE_MASK)) { 683 case SCREENLAYOUT_SIZE_UNDEFINED: sb.append(" ?lsize"); break; 684 case SCREENLAYOUT_SIZE_SMALL: sb.append(" smll"); break; 685 case SCREENLAYOUT_SIZE_NORMAL: sb.append(" nrml"); break; 686 case SCREENLAYOUT_SIZE_LARGE: sb.append(" lrg"); break; 687 case SCREENLAYOUT_SIZE_XLARGE: sb.append(" xlrg"); break; 688 default: sb.append(" layoutSize="); 689 sb.append(screenLayout&SCREENLAYOUT_SIZE_MASK); break; 690 } 691 switch ((screenLayout&SCREENLAYOUT_LONG_MASK)) { 692 case SCREENLAYOUT_LONG_UNDEFINED: sb.append(" ?long"); break; 693 case SCREENLAYOUT_LONG_NO: /* not-long is not interesting to print */ break; 694 case SCREENLAYOUT_LONG_YES: sb.append(" long"); break; 695 default: sb.append(" layoutLong="); 696 sb.append(screenLayout&SCREENLAYOUT_LONG_MASK); break; 697 } 698 switch (orientation) { 699 case ORIENTATION_UNDEFINED: sb.append(" ?orien"); break; 700 case ORIENTATION_LANDSCAPE: sb.append(" land"); break; 701 case ORIENTATION_PORTRAIT: sb.append(" port"); break; 702 default: sb.append(" orien="); sb.append(orientation); break; 703 } 704 switch ((uiMode&UI_MODE_TYPE_MASK)) { 705 case UI_MODE_TYPE_UNDEFINED: sb.append(" ?uimode"); break; 706 case UI_MODE_TYPE_NORMAL: /* normal is not interesting to print */ break; 707 case UI_MODE_TYPE_DESK: sb.append(" desk"); break; 708 case UI_MODE_TYPE_CAR: sb.append(" car"); break; 709 case UI_MODE_TYPE_TELEVISION: sb.append(" television"); break; 710 case UI_MODE_TYPE_APPLIANCE: sb.append(" appliance"); break; 711 case UI_MODE_TYPE_WATCH: sb.append(" watch"); break; 712 default: sb.append(" uimode="); sb.append(uiMode&UI_MODE_TYPE_MASK); break; 713 } 714 switch ((uiMode&UI_MODE_NIGHT_MASK)) { 715 case UI_MODE_NIGHT_UNDEFINED: sb.append(" ?night"); break; 716 case UI_MODE_NIGHT_NO: /* not-night is not interesting to print */ break; 717 case UI_MODE_NIGHT_YES: sb.append(" night"); break; 718 default: sb.append(" night="); sb.append(uiMode&UI_MODE_NIGHT_MASK); break; 719 } 720 switch (touchscreen) { 721 case TOUCHSCREEN_UNDEFINED: sb.append(" ?touch"); break; 722 case TOUCHSCREEN_NOTOUCH: sb.append(" -touch"); break; 723 case TOUCHSCREEN_STYLUS: sb.append(" stylus"); break; 724 case TOUCHSCREEN_FINGER: sb.append(" finger"); break; 725 default: sb.append(" touch="); sb.append(touchscreen); break; 726 } 727 switch (keyboard) { 728 case KEYBOARD_UNDEFINED: sb.append(" ?keyb"); break; 729 case KEYBOARD_NOKEYS: sb.append(" -keyb"); break; 730 case KEYBOARD_QWERTY: sb.append(" qwerty"); break; 731 case KEYBOARD_12KEY: sb.append(" 12key"); break; 732 default: sb.append(" keys="); sb.append(keyboard); break; 733 } 734 switch (keyboardHidden) { 735 case KEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break; 736 case KEYBOARDHIDDEN_NO: sb.append("/v"); break; 737 case KEYBOARDHIDDEN_YES: sb.append("/h"); break; 738 case KEYBOARDHIDDEN_SOFT: sb.append("/s"); break; 739 default: sb.append("/"); sb.append(keyboardHidden); break; 740 } 741 switch (hardKeyboardHidden) { 742 case HARDKEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break; 743 case HARDKEYBOARDHIDDEN_NO: sb.append("/v"); break; 744 case HARDKEYBOARDHIDDEN_YES: sb.append("/h"); break; 745 default: sb.append("/"); sb.append(hardKeyboardHidden); break; 746 } 747 switch (navigation) { 748 case NAVIGATION_UNDEFINED: sb.append(" ?nav"); break; 749 case NAVIGATION_NONAV: sb.append(" -nav"); break; 750 case NAVIGATION_DPAD: sb.append(" dpad"); break; 751 case NAVIGATION_TRACKBALL: sb.append(" tball"); break; 752 case NAVIGATION_WHEEL: sb.append(" wheel"); break; 753 default: sb.append(" nav="); sb.append(navigation); break; 754 } 755 switch (navigationHidden) { 756 case NAVIGATIONHIDDEN_UNDEFINED: sb.append("/?"); break; 757 case NAVIGATIONHIDDEN_NO: sb.append("/v"); break; 758 case NAVIGATIONHIDDEN_YES: sb.append("/h"); break; 759 default: sb.append("/"); sb.append(navigationHidden); break; 760 } 761 if (seq != 0) { 762 sb.append(" s."); 763 sb.append(seq); 764 } 765 sb.append('}'); 766 return sb.toString(); 767 } 768 769 /** 770 * Set this object to the system defaults. 771 */ 772 public void setToDefaults() { 773 fontScale = 1; 774 mcc = mnc = 0; 775 locale = null; 776 userSetLocale = false; 777 touchscreen = TOUCHSCREEN_UNDEFINED; 778 keyboard = KEYBOARD_UNDEFINED; 779 keyboardHidden = KEYBOARDHIDDEN_UNDEFINED; 780 hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED; 781 navigation = NAVIGATION_UNDEFINED; 782 navigationHidden = NAVIGATIONHIDDEN_UNDEFINED; 783 orientation = ORIENTATION_UNDEFINED; 784 screenLayout = SCREENLAYOUT_UNDEFINED; 785 uiMode = UI_MODE_TYPE_UNDEFINED; 786 screenWidthDp = compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED; 787 screenHeightDp = compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED; 788 smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; 789 densityDpi = DENSITY_DPI_UNDEFINED; 790 seq = 0; 791 } 792 793 /** {@hide} */ 794 @Deprecated public void makeDefault() { 795 setToDefaults(); 796 } 797 798 /** 799 * Copy the fields from delta into this Configuration object, keeping 800 * track of which ones have changed. Any undefined fields in 801 * <var>delta</var> are ignored and not copied in to the current 802 * Configuration. 803 * @return Returns a bit mask of the changed fields, as per 804 * {@link #diff}. 805 */ 806 public int updateFrom(Configuration delta) { 807 int changed = 0; 808 if (delta.fontScale > 0 && fontScale != delta.fontScale) { 809 changed |= ActivityInfo.CONFIG_FONT_SCALE; 810 fontScale = delta.fontScale; 811 } 812 if (delta.mcc != 0 && mcc != delta.mcc) { 813 changed |= ActivityInfo.CONFIG_MCC; 814 mcc = delta.mcc; 815 } 816 if (delta.mnc != 0 && mnc != delta.mnc) { 817 changed |= ActivityInfo.CONFIG_MNC; 818 mnc = delta.mnc; 819 } 820 if (delta.locale != null 821 && (locale == null || !locale.equals(delta.locale))) { 822 changed |= ActivityInfo.CONFIG_LOCALE; 823 locale = delta.locale != null 824 ? (Locale) delta.locale.clone() : null; 825 // If locale has changed, then layout direction is also changed ... 826 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; 827 // ... and we need to update the layout direction (represented by the first 828 // 2 most significant bits in screenLayout). 829 setLayoutDirection(locale); 830 } 831 final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK; 832 if (deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED && 833 deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) { 834 screenLayout = (screenLayout & ~SCREENLAYOUT_LAYOUTDIR_MASK) | deltaScreenLayoutDir; 835 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; 836 } 837 if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0))) 838 { 839 changed |= ActivityInfo.CONFIG_LOCALE; 840 userSetLocale = true; 841 } 842 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED 843 && touchscreen != delta.touchscreen) { 844 changed |= ActivityInfo.CONFIG_TOUCHSCREEN; 845 touchscreen = delta.touchscreen; 846 } 847 if (delta.keyboard != KEYBOARD_UNDEFINED 848 && keyboard != delta.keyboard) { 849 changed |= ActivityInfo.CONFIG_KEYBOARD; 850 keyboard = delta.keyboard; 851 } 852 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED 853 && keyboardHidden != delta.keyboardHidden) { 854 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 855 keyboardHidden = delta.keyboardHidden; 856 } 857 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED 858 && hardKeyboardHidden != delta.hardKeyboardHidden) { 859 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 860 hardKeyboardHidden = delta.hardKeyboardHidden; 861 } 862 if (delta.navigation != NAVIGATION_UNDEFINED 863 && navigation != delta.navigation) { 864 changed |= ActivityInfo.CONFIG_NAVIGATION; 865 navigation = delta.navigation; 866 } 867 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED 868 && navigationHidden != delta.navigationHidden) { 869 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 870 navigationHidden = delta.navigationHidden; 871 } 872 if (delta.orientation != ORIENTATION_UNDEFINED 873 && orientation != delta.orientation) { 874 changed |= ActivityInfo.CONFIG_ORIENTATION; 875 orientation = delta.orientation; 876 } 877 if (getScreenLayoutNoDirection(delta.screenLayout) != 878 (SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED) 879 && (getScreenLayoutNoDirection(screenLayout) != 880 getScreenLayoutNoDirection(delta.screenLayout))) { 881 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; 882 // We need to preserve the previous layout dir bits if they were defined 883 if ((delta.screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == 0) { 884 screenLayout = (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK)|delta.screenLayout; 885 } else { 886 screenLayout = delta.screenLayout; 887 } 888 } 889 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED) 890 && uiMode != delta.uiMode) { 891 changed |= ActivityInfo.CONFIG_UI_MODE; 892 if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) { 893 uiMode = (uiMode&~UI_MODE_TYPE_MASK) 894 | (delta.uiMode&UI_MODE_TYPE_MASK); 895 } 896 if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) { 897 uiMode = (uiMode&~UI_MODE_NIGHT_MASK) 898 | (delta.uiMode&UI_MODE_NIGHT_MASK); 899 } 900 } 901 if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED 902 && screenWidthDp != delta.screenWidthDp) { 903 changed |= ActivityInfo.CONFIG_SCREEN_SIZE; 904 screenWidthDp = delta.screenWidthDp; 905 } 906 if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED 907 && screenHeightDp != delta.screenHeightDp) { 908 changed |= ActivityInfo.CONFIG_SCREEN_SIZE; 909 screenHeightDp = delta.screenHeightDp; 910 } 911 if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED 912 && smallestScreenWidthDp != delta.smallestScreenWidthDp) { 913 changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; 914 smallestScreenWidthDp = delta.smallestScreenWidthDp; 915 } 916 if (delta.densityDpi != DENSITY_DPI_UNDEFINED && 917 densityDpi != delta.densityDpi) { 918 changed |= ActivityInfo.CONFIG_DENSITY; 919 densityDpi = delta.densityDpi; 920 } 921 if (delta.compatScreenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) { 922 compatScreenWidthDp = delta.compatScreenWidthDp; 923 } 924 if (delta.compatScreenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) { 925 compatScreenHeightDp = delta.compatScreenHeightDp; 926 } 927 if (delta.compatSmallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { 928 compatSmallestScreenWidthDp = delta.compatSmallestScreenWidthDp; 929 } 930 if (delta.seq != 0) { 931 seq = delta.seq; 932 } 933 934 return changed; 935 } 936 937 /** 938 * Return a bit mask of the differences between this Configuration 939 * object and the given one. Does not change the values of either. Any 940 * undefined fields in <var>delta</var> are ignored. 941 * @return Returns a bit mask indicating which configuration 942 * values has changed, containing any combination of 943 * {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE 944 * PackageManager.ActivityInfo.CONFIG_FONT_SCALE}, 945 * {@link android.content.pm.ActivityInfo#CONFIG_MCC 946 * PackageManager.ActivityInfo.CONFIG_MCC}, 947 * {@link android.content.pm.ActivityInfo#CONFIG_MNC 948 * PackageManager.ActivityInfo.CONFIG_MNC}, 949 * {@link android.content.pm.ActivityInfo#CONFIG_LOCALE 950 * PackageManager.ActivityInfo.CONFIG_LOCALE}, 951 * {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN 952 * PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN}, 953 * {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD 954 * PackageManager.ActivityInfo.CONFIG_KEYBOARD}, 955 * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION 956 * PackageManager.ActivityInfo.CONFIG_NAVIGATION}, 957 * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION 958 * PackageManager.ActivityInfo.CONFIG_ORIENTATION}, 959 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT 960 * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}, or 961 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE 962 * PackageManager.ActivityInfo.CONFIG_SCREEN_SIZE}, or 963 * {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE 964 * PackageManager.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE}. 965 * {@link android.content.pm.ActivityInfo#CONFIG_LAYOUT_DIRECTION 966 * PackageManager.ActivityInfo.CONFIG_LAYOUT_DIRECTION}. 967 */ 968 public int diff(Configuration delta) { 969 int changed = 0; 970 if (delta.fontScale > 0 && fontScale != delta.fontScale) { 971 changed |= ActivityInfo.CONFIG_FONT_SCALE; 972 } 973 if (delta.mcc != 0 && mcc != delta.mcc) { 974 changed |= ActivityInfo.CONFIG_MCC; 975 } 976 if (delta.mnc != 0 && mnc != delta.mnc) { 977 changed |= ActivityInfo.CONFIG_MNC; 978 } 979 if (delta.locale != null 980 && (locale == null || !locale.equals(delta.locale))) { 981 changed |= ActivityInfo.CONFIG_LOCALE; 982 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; 983 } 984 final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK; 985 if (deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED && 986 deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) { 987 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION; 988 } 989 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED 990 && touchscreen != delta.touchscreen) { 991 changed |= ActivityInfo.CONFIG_TOUCHSCREEN; 992 } 993 if (delta.keyboard != KEYBOARD_UNDEFINED 994 && keyboard != delta.keyboard) { 995 changed |= ActivityInfo.CONFIG_KEYBOARD; 996 } 997 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED 998 && keyboardHidden != delta.keyboardHidden) { 999 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 1000 } 1001 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED 1002 && hardKeyboardHidden != delta.hardKeyboardHidden) { 1003 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 1004 } 1005 if (delta.navigation != NAVIGATION_UNDEFINED 1006 && navigation != delta.navigation) { 1007 changed |= ActivityInfo.CONFIG_NAVIGATION; 1008 } 1009 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED 1010 && navigationHidden != delta.navigationHidden) { 1011 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 1012 } 1013 if (delta.orientation != ORIENTATION_UNDEFINED 1014 && orientation != delta.orientation) { 1015 changed |= ActivityInfo.CONFIG_ORIENTATION; 1016 } 1017 if (getScreenLayoutNoDirection(delta.screenLayout) != 1018 (SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED) 1019 && getScreenLayoutNoDirection(screenLayout) != 1020 getScreenLayoutNoDirection(delta.screenLayout)) { 1021 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; 1022 } 1023 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED) 1024 && uiMode != delta.uiMode) { 1025 changed |= ActivityInfo.CONFIG_UI_MODE; 1026 } 1027 if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED 1028 && screenWidthDp != delta.screenWidthDp) { 1029 changed |= ActivityInfo.CONFIG_SCREEN_SIZE; 1030 } 1031 if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED 1032 && screenHeightDp != delta.screenHeightDp) { 1033 changed |= ActivityInfo.CONFIG_SCREEN_SIZE; 1034 } 1035 if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED 1036 && smallestScreenWidthDp != delta.smallestScreenWidthDp) { 1037 changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; 1038 } 1039 if (delta.densityDpi != DENSITY_DPI_UNDEFINED 1040 && densityDpi != delta.densityDpi) { 1041 changed |= ActivityInfo.CONFIG_DENSITY; 1042 } 1043 1044 return changed; 1045 } 1046 1047 /** 1048 * Determine if a new resource needs to be loaded from the bit set of 1049 * configuration changes returned by {@link #updateFrom(Configuration)}. 1050 * 1051 * @param configChanges The mask of changes configurations as returned by 1052 * {@link #updateFrom(Configuration)}. 1053 * @param interestingChanges The configuration changes that the resource 1054 * can handled, as given in {@link android.util.TypedValue#changingConfigurations}. 1055 * 1056 * @return Return true if the resource needs to be loaded, else false. 1057 */ 1058 public static boolean needNewResources(int configChanges, int interestingChanges) { 1059 return (configChanges & (interestingChanges|ActivityInfo.CONFIG_FONT_SCALE)) != 0; 1060 } 1061 1062 /** 1063 * @hide Return true if the sequence of 'other' is better than this. Assumes 1064 * that 'this' is your current sequence and 'other' is a new one you have 1065 * received some how and want to compare with what you have. 1066 */ 1067 public boolean isOtherSeqNewer(Configuration other) { 1068 if (other == null) { 1069 // Sanity check. 1070 return false; 1071 } 1072 if (other.seq == 0) { 1073 // If the other sequence is not specified, then we must assume 1074 // it is newer since we don't know any better. 1075 return true; 1076 } 1077 if (seq == 0) { 1078 // If this sequence is not specified, then we also consider the 1079 // other is better. Yes we have a preference for other. Sue us. 1080 return true; 1081 } 1082 int diff = other.seq - seq; 1083 if (diff > 0x10000) { 1084 // If there has been a sufficiently large jump, assume the 1085 // sequence has wrapped around. 1086 return false; 1087 } 1088 return diff > 0; 1089 } 1090 1091 /** 1092 * Parcelable methods 1093 */ 1094 public int describeContents() { 1095 return 0; 1096 } 1097 1098 public void writeToParcel(Parcel dest, int flags) { 1099 dest.writeFloat(fontScale); 1100 dest.writeInt(mcc); 1101 dest.writeInt(mnc); 1102 if (locale == null) { 1103 dest.writeInt(0); 1104 } else { 1105 dest.writeInt(1); 1106 dest.writeString(locale.getLanguage()); 1107 dest.writeString(locale.getCountry()); 1108 dest.writeString(locale.getVariant()); 1109 } 1110 if(userSetLocale) { 1111 dest.writeInt(1); 1112 } else { 1113 dest.writeInt(0); 1114 } 1115 dest.writeInt(touchscreen); 1116 dest.writeInt(keyboard); 1117 dest.writeInt(keyboardHidden); 1118 dest.writeInt(hardKeyboardHidden); 1119 dest.writeInt(navigation); 1120 dest.writeInt(navigationHidden); 1121 dest.writeInt(orientation); 1122 dest.writeInt(screenLayout); 1123 dest.writeInt(uiMode); 1124 dest.writeInt(screenWidthDp); 1125 dest.writeInt(screenHeightDp); 1126 dest.writeInt(smallestScreenWidthDp); 1127 dest.writeInt(densityDpi); 1128 dest.writeInt(compatScreenWidthDp); 1129 dest.writeInt(compatScreenHeightDp); 1130 dest.writeInt(compatSmallestScreenWidthDp); 1131 dest.writeInt(seq); 1132 } 1133 1134 public void readFromParcel(Parcel source) { 1135 fontScale = source.readFloat(); 1136 mcc = source.readInt(); 1137 mnc = source.readInt(); 1138 if (source.readInt() != 0) { 1139 locale = new Locale(source.readString(), source.readString(), 1140 source.readString()); 1141 } 1142 userSetLocale = (source.readInt()==1); 1143 touchscreen = source.readInt(); 1144 keyboard = source.readInt(); 1145 keyboardHidden = source.readInt(); 1146 hardKeyboardHidden = source.readInt(); 1147 navigation = source.readInt(); 1148 navigationHidden = source.readInt(); 1149 orientation = source.readInt(); 1150 screenLayout = source.readInt(); 1151 uiMode = source.readInt(); 1152 screenWidthDp = source.readInt(); 1153 screenHeightDp = source.readInt(); 1154 smallestScreenWidthDp = source.readInt(); 1155 densityDpi = source.readInt(); 1156 compatScreenWidthDp = source.readInt(); 1157 compatScreenHeightDp = source.readInt(); 1158 compatSmallestScreenWidthDp = source.readInt(); 1159 seq = source.readInt(); 1160 } 1161 1162 public static final Parcelable.Creator<Configuration> CREATOR 1163 = new Parcelable.Creator<Configuration>() { 1164 public Configuration createFromParcel(Parcel source) { 1165 return new Configuration(source); 1166 } 1167 1168 public Configuration[] newArray(int size) { 1169 return new Configuration[size]; 1170 } 1171 }; 1172 1173 /** 1174 * Construct this Configuration object, reading from the Parcel. 1175 */ 1176 private Configuration(Parcel source) { 1177 readFromParcel(source); 1178 } 1179 1180 public int compareTo(Configuration that) { 1181 int n; 1182 float a = this.fontScale; 1183 float b = that.fontScale; 1184 if (a < b) return -1; 1185 if (a > b) return 1; 1186 n = this.mcc - that.mcc; 1187 if (n != 0) return n; 1188 n = this.mnc - that.mnc; 1189 if (n != 0) return n; 1190 if (this.locale == null) { 1191 if (that.locale != null) return 1; 1192 } else if (that.locale == null) { 1193 return -1; 1194 } else { 1195 n = this.locale.getLanguage().compareTo(that.locale.getLanguage()); 1196 if (n != 0) return n; 1197 n = this.locale.getCountry().compareTo(that.locale.getCountry()); 1198 if (n != 0) return n; 1199 n = this.locale.getVariant().compareTo(that.locale.getVariant()); 1200 if (n != 0) return n; 1201 } 1202 n = this.touchscreen - that.touchscreen; 1203 if (n != 0) return n; 1204 n = this.keyboard - that.keyboard; 1205 if (n != 0) return n; 1206 n = this.keyboardHidden - that.keyboardHidden; 1207 if (n != 0) return n; 1208 n = this.hardKeyboardHidden - that.hardKeyboardHidden; 1209 if (n != 0) return n; 1210 n = this.navigation - that.navigation; 1211 if (n != 0) return n; 1212 n = this.navigationHidden - that.navigationHidden; 1213 if (n != 0) return n; 1214 n = this.orientation - that.orientation; 1215 if (n != 0) return n; 1216 n = this.screenLayout - that.screenLayout; 1217 if (n != 0) return n; 1218 n = this.uiMode - that.uiMode; 1219 if (n != 0) return n; 1220 n = this.screenWidthDp - that.screenWidthDp; 1221 if (n != 0) return n; 1222 n = this.screenHeightDp - that.screenHeightDp; 1223 if (n != 0) return n; 1224 n = this.smallestScreenWidthDp - that.smallestScreenWidthDp; 1225 if (n != 0) return n; 1226 n = this.densityDpi - that.densityDpi; 1227 //if (n != 0) return n; 1228 return n; 1229 } 1230 1231 public boolean equals(Configuration that) { 1232 if (that == null) return false; 1233 if (that == this) return true; 1234 return this.compareTo(that) == 0; 1235 } 1236 1237 public boolean equals(Object that) { 1238 try { 1239 return equals((Configuration)that); 1240 } catch (ClassCastException e) { 1241 } 1242 return false; 1243 } 1244 1245 public int hashCode() { 1246 int result = 17; 1247 result = 31 * result + Float.floatToIntBits(fontScale); 1248 result = 31 * result + mcc; 1249 result = 31 * result + mnc; 1250 result = 31 * result + (locale != null ? locale.hashCode() : 0); 1251 result = 31 * result + touchscreen; 1252 result = 31 * result + keyboard; 1253 result = 31 * result + keyboardHidden; 1254 result = 31 * result + hardKeyboardHidden; 1255 result = 31 * result + navigation; 1256 result = 31 * result + navigationHidden; 1257 result = 31 * result + orientation; 1258 result = 31 * result + screenLayout; 1259 result = 31 * result + uiMode; 1260 result = 31 * result + screenWidthDp; 1261 result = 31 * result + screenHeightDp; 1262 result = 31 * result + smallestScreenWidthDp; 1263 result = 31 * result + densityDpi; 1264 return result; 1265 } 1266 1267 /** 1268 * Set the locale. This is the preferred way for setting up the locale (instead of using the 1269 * direct accessor). This will also set the userLocale and layout direction according to 1270 * the locale. 1271 * 1272 * @param loc The locale. Can be null. 1273 */ 1274 public void setLocale(Locale loc) { 1275 locale = loc; 1276 userSetLocale = true; 1277 setLayoutDirection(locale); 1278 } 1279 1280 /** 1281 * Return the layout direction. Will be either {@link View#LAYOUT_DIRECTION_LTR} or 1282 * {@link View#LAYOUT_DIRECTION_RTL}. 1283 * 1284 * @return Returns {@link View#LAYOUT_DIRECTION_RTL} if the configuration 1285 * is {@link #SCREENLAYOUT_LAYOUTDIR_RTL}, otherwise {@link View#LAYOUT_DIRECTION_LTR}. 1286 */ 1287 public int getLayoutDirection() { 1288 return (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == SCREENLAYOUT_LAYOUTDIR_RTL 1289 ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR; 1290 } 1291 1292 /** 1293 * Set the layout direction from the Locale. 1294 * 1295 * @param locale The Locale. If null will set the layout direction to 1296 * {@link View#LAYOUT_DIRECTION_LTR}. If not null will set it to the layout direction 1297 * corresponding to the Locale. 1298 * 1299 * @see {@link View#LAYOUT_DIRECTION_LTR} and {@link View#LAYOUT_DIRECTION_RTL} 1300 */ 1301 public void setLayoutDirection(Locale locale) { 1302 // There is a "1" difference between the configuration values for 1303 // layout direction and View constants for layout direction, just add "1". 1304 final int layoutDirection = 1 + TextUtils.getLayoutDirectionFromLocale(locale); 1305 screenLayout = (screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK)| 1306 (layoutDirection << SCREENLAYOUT_LAYOUTDIR_SHIFT); 1307 } 1308 1309 private static int getScreenLayoutNoDirection(int screenLayout) { 1310 return screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK; 1311 } 1312 1313 /** 1314 * 1315 * @hide 1316 */ 1317 public static String localeToResourceQualifier(Locale locale) { 1318 StringBuilder sb = new StringBuilder(); 1319 boolean l = (locale.getLanguage().length() != 0); 1320 boolean c = (locale.getCountry().length() != 0); 1321 boolean s = (locale.getScript().length() != 0); 1322 boolean v = (locale.getVariant().length() != 0); 1323 1324 if (l) { 1325 sb.append(locale.getLanguage()); 1326 if (c) { 1327 sb.append("-r").append(locale.getCountry()); 1328 if (s) { 1329 sb.append("-s").append(locale.getScript()); 1330 if (v) { 1331 sb.append("-v").append(locale.getVariant()); 1332 } 1333 } 1334 } 1335 } 1336 return sb.toString(); 1337 } 1338 1339 1340 /** 1341 * Returns a string representation of the configuration that can be parsed 1342 * by build tools (like AAPT). 1343 * 1344 * 1345 * 1346 * @hide 1347 */ 1348 public static String resourceQualifierString(Configuration config) { 1349 ArrayList<String> parts = new ArrayList<String>(); 1350 1351 if (config.mcc != 0) { 1352 parts.add(config.mcc + "mcc"); 1353 if (config.mnc != 0) { 1354 parts.add(config.mnc + "mnc"); 1355 } 1356 } 1357 1358 if (!config.locale.getLanguage().isEmpty()) { 1359 parts.add(localeToResourceQualifier(config.locale)); 1360 } 1361 1362 switch (config.screenLayout & Configuration.SCREENLAYOUT_LAYOUTDIR_MASK) { 1363 case Configuration.SCREENLAYOUT_LAYOUTDIR_LTR: 1364 parts.add("ldltr"); 1365 break; 1366 case Configuration.SCREENLAYOUT_LAYOUTDIR_RTL: 1367 parts.add("ldrtl"); 1368 break; 1369 default: 1370 break; 1371 } 1372 1373 if (config.smallestScreenWidthDp != 0) { 1374 parts.add("sw" + config.smallestScreenWidthDp + "dp"); 1375 } 1376 1377 if (config.screenWidthDp != 0) { 1378 parts.add("w" + config.screenWidthDp + "dp"); 1379 } 1380 1381 if (config.screenHeightDp != 0) { 1382 parts.add("h" + config.screenHeightDp + "dp"); 1383 } 1384 1385 switch (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) { 1386 case Configuration.SCREENLAYOUT_SIZE_SMALL: 1387 parts.add("small"); 1388 break; 1389 case Configuration.SCREENLAYOUT_SIZE_NORMAL: 1390 parts.add("normal"); 1391 break; 1392 case Configuration.SCREENLAYOUT_SIZE_LARGE: 1393 parts.add("large"); 1394 break; 1395 case Configuration.SCREENLAYOUT_SIZE_XLARGE: 1396 parts.add("xlarge"); 1397 break; 1398 default: 1399 break; 1400 } 1401 1402 switch (config.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK) { 1403 case Configuration.SCREENLAYOUT_LONG_YES: 1404 parts.add("long"); 1405 break; 1406 case Configuration.SCREENLAYOUT_LONG_NO: 1407 parts.add("notlong"); 1408 break; 1409 default: 1410 break; 1411 } 1412 1413 switch (config.orientation) { 1414 case Configuration.ORIENTATION_LANDSCAPE: 1415 parts.add("land"); 1416 break; 1417 case Configuration.ORIENTATION_PORTRAIT: 1418 parts.add("port"); 1419 break; 1420 default: 1421 break; 1422 } 1423 1424 switch (config.uiMode & Configuration.UI_MODE_TYPE_MASK) { 1425 case Configuration.UI_MODE_TYPE_APPLIANCE: 1426 parts.add("appliance"); 1427 break; 1428 case Configuration.UI_MODE_TYPE_DESK: 1429 parts.add("desk"); 1430 break; 1431 case Configuration.UI_MODE_TYPE_TELEVISION: 1432 parts.add("television"); 1433 break; 1434 case Configuration.UI_MODE_TYPE_CAR: 1435 parts.add("car"); 1436 break; 1437 case Configuration.UI_MODE_TYPE_WATCH: 1438 parts.add("watch"); 1439 break; 1440 default: 1441 break; 1442 } 1443 1444 switch (config.uiMode & Configuration.UI_MODE_NIGHT_MASK) { 1445 case Configuration.UI_MODE_NIGHT_YES: 1446 parts.add("night"); 1447 break; 1448 case Configuration.UI_MODE_NIGHT_NO: 1449 parts.add("notnight"); 1450 break; 1451 default: 1452 break; 1453 } 1454 1455 switch (config.densityDpi) { 1456 case 0: 1457 break; 1458 case 120: 1459 parts.add("ldpi"); 1460 break; 1461 case 160: 1462 parts.add("mdpi"); 1463 break; 1464 case 213: 1465 parts.add("tvdpi"); 1466 break; 1467 case 240: 1468 parts.add("hdpi"); 1469 break; 1470 case 320: 1471 parts.add("xhdpi"); 1472 break; 1473 default: 1474 parts.add(config.densityDpi + "dpi"); 1475 break; 1476 } 1477 1478 switch (config.touchscreen) { 1479 case Configuration.TOUCHSCREEN_NOTOUCH: 1480 parts.add("notouch"); 1481 break; 1482 case Configuration.TOUCHSCREEN_FINGER: 1483 parts.add("finger"); 1484 break; 1485 default: 1486 break; 1487 } 1488 1489 switch (config.keyboardHidden) { 1490 case Configuration.KEYBOARDHIDDEN_NO: 1491 parts.add("keysexposed"); 1492 break; 1493 case Configuration.KEYBOARDHIDDEN_YES: 1494 parts.add("keyshidden"); 1495 break; 1496 case Configuration.KEYBOARDHIDDEN_SOFT: 1497 parts.add("keyssoft"); 1498 break; 1499 default: 1500 break; 1501 } 1502 1503 switch (config.keyboard) { 1504 case Configuration.KEYBOARD_NOKEYS: 1505 parts.add("nokeys"); 1506 break; 1507 case Configuration.KEYBOARD_QWERTY: 1508 parts.add("qwerty"); 1509 break; 1510 case Configuration.KEYBOARD_12KEY: 1511 parts.add("12key"); 1512 break; 1513 default: 1514 break; 1515 } 1516 1517 switch (config.navigationHidden) { 1518 case Configuration.NAVIGATIONHIDDEN_NO: 1519 parts.add("navexposed"); 1520 break; 1521 case Configuration.NAVIGATIONHIDDEN_YES: 1522 parts.add("navhidden"); 1523 break; 1524 default: 1525 break; 1526 } 1527 1528 switch (config.navigation) { 1529 case Configuration.NAVIGATION_NONAV: 1530 parts.add("nonav"); 1531 break; 1532 case Configuration.NAVIGATION_DPAD: 1533 parts.add("dpad"); 1534 break; 1535 case Configuration.NAVIGATION_TRACKBALL: 1536 parts.add("trackball"); 1537 break; 1538 case Configuration.NAVIGATION_WHEEL: 1539 parts.add("wheel"); 1540 break; 1541 default: 1542 break; 1543 } 1544 1545 parts.add("v" + Build.VERSION.SDK_INT); 1546 return TextUtils.join("-", parts); 1547 } 1548} 1549