Configuration.java revision 7d3a5bcf300aea7bffb1d46f28e244ca807f5e82
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.Parcel; 21import android.os.Parcelable; 22 23import java.util.Locale; 24 25/** 26 * This class describes all device configuration information that can 27 * impact the resources the application retrieves. This includes both 28 * user-specified configuration options (locale and scaling) as well 29 * as dynamic device configuration (various types of input devices). 30 */ 31public final class Configuration implements Parcelable, Comparable<Configuration> { 32 /** 33 * Current user preference for the scaling factor for fonts, relative 34 * to the base density scaling. 35 */ 36 public float fontScale; 37 38 /** 39 * IMSI MCC (Mobile Country Code). 0 if undefined. 40 */ 41 public int mcc; 42 43 /** 44 * IMSI MNC (Mobile Network Code). 0 if undefined. 45 */ 46 public int mnc; 47 48 /** 49 * Current user preference for the locale. 50 */ 51 public Locale locale; 52 53 /** 54 * Locale should persist on setting. This is hidden because it is really 55 * questionable whether this is the right way to expose the functionality. 56 * @hide 57 */ 58 public boolean userSetLocale; 59 60 public static final int SCREENLAYOUT_SIZE_MASK = 0x0f; 61 public static final int SCREENLAYOUT_SIZE_UNDEFINED = 0x00; 62 public static final int SCREENLAYOUT_SIZE_SMALL = 0x01; 63 public static final int SCREENLAYOUT_SIZE_NORMAL = 0x02; 64 public static final int SCREENLAYOUT_SIZE_LARGE = 0x03; 65 public static final int SCREENLAYOUT_SIZE_XLARGE = 0x04; 66 67 public static final int SCREENLAYOUT_LONG_MASK = 0x30; 68 public static final int SCREENLAYOUT_LONG_UNDEFINED = 0x00; 69 public static final int SCREENLAYOUT_LONG_NO = 0x10; 70 public static final int SCREENLAYOUT_LONG_YES = 0x20; 71 72 /** 73 * Special flag we generate to indicate that the screen layout requires 74 * us to use a compatibility mode for apps that are not modern layout 75 * aware. 76 * @hide 77 */ 78 public static final int SCREENLAYOUT_COMPAT_NEEDED = 0x10000000; 79 80 /** 81 * Bit mask of overall layout of the screen. Currently there are two 82 * fields: 83 * <p>The {@link #SCREENLAYOUT_SIZE_MASK} bits define the overall size 84 * of the screen. They may be one of 85 * {@link #SCREENLAYOUT_SIZE_SMALL}, {@link #SCREENLAYOUT_SIZE_NORMAL}, 86 * {@link #SCREENLAYOUT_SIZE_LARGE}, or {@link #SCREENLAYOUT_SIZE_XLARGE}. 87 * 88 * <p>The {@link #SCREENLAYOUT_LONG_MASK} defines whether the screen 89 * is wider/taller than normal. They may be one of 90 * {@link #SCREENLAYOUT_LONG_NO} or {@link #SCREENLAYOUT_LONG_YES}. 91 */ 92 public int screenLayout; 93 94 /** 95 * Check if the Configuration's current {@link #screenLayout} is at 96 * least the given size. 97 * 98 * @param size The desired size, either {@link #SCREENLAYOUT_SIZE_SMALL}, 99 * {@link #SCREENLAYOUT_SIZE_NORMAL}, {@link #SCREENLAYOUT_SIZE_LARGE}, or 100 * {@link #SCREENLAYOUT_SIZE_XLARGE}. 101 * @return Returns true if the current screen layout size is at least 102 * the given size. 103 */ 104 public boolean isLayoutSizeAtLeast(int size) { 105 int cur = screenLayout&SCREENLAYOUT_SIZE_MASK; 106 if (cur == SCREENLAYOUT_SIZE_UNDEFINED) return false; 107 return cur >= size; 108 } 109 110 public static final int TOUCHSCREEN_UNDEFINED = 0; 111 public static final int TOUCHSCREEN_NOTOUCH = 1; 112 public static final int TOUCHSCREEN_STYLUS = 2; 113 public static final int TOUCHSCREEN_FINGER = 3; 114 115 /** 116 * The kind of touch screen attached to the device. 117 * One of: {@link #TOUCHSCREEN_NOTOUCH}, {@link #TOUCHSCREEN_STYLUS}, 118 * {@link #TOUCHSCREEN_FINGER}. 119 */ 120 public int touchscreen; 121 122 public static final int KEYBOARD_UNDEFINED = 0; 123 public static final int KEYBOARD_NOKEYS = 1; 124 public static final int KEYBOARD_QWERTY = 2; 125 public static final int KEYBOARD_12KEY = 3; 126 127 /** 128 * The kind of keyboard attached to the device. 129 * One of: {@link #KEYBOARD_NOKEYS}, {@link #KEYBOARD_QWERTY}, 130 * {@link #KEYBOARD_12KEY}. 131 */ 132 public int keyboard; 133 134 public static final int KEYBOARDHIDDEN_UNDEFINED = 0; 135 public static final int KEYBOARDHIDDEN_NO = 1; 136 public static final int KEYBOARDHIDDEN_YES = 2; 137 /** Constant matching actual resource implementation. {@hide} */ 138 public static final int KEYBOARDHIDDEN_SOFT = 3; 139 140 /** 141 * A flag indicating whether any keyboard is available. Unlike 142 * {@link #hardKeyboardHidden}, this also takes into account a soft 143 * keyboard, so if the hard keyboard is hidden but there is soft 144 * keyboard available, it will be set to NO. Value is one of: 145 * {@link #KEYBOARDHIDDEN_NO}, {@link #KEYBOARDHIDDEN_YES}. 146 */ 147 public int keyboardHidden; 148 149 public static final int HARDKEYBOARDHIDDEN_UNDEFINED = 0; 150 public static final int HARDKEYBOARDHIDDEN_NO = 1; 151 public static final int HARDKEYBOARDHIDDEN_YES = 2; 152 153 /** 154 * A flag indicating whether the hard keyboard has been hidden. This will 155 * be set on a device with a mechanism to hide the keyboard from the 156 * user, when that mechanism is closed. One of: 157 * {@link #HARDKEYBOARDHIDDEN_NO}, {@link #HARDKEYBOARDHIDDEN_YES}. 158 */ 159 public int hardKeyboardHidden; 160 161 public static final int NAVIGATION_UNDEFINED = 0; 162 public static final int NAVIGATION_NONAV = 1; 163 public static final int NAVIGATION_DPAD = 2; 164 public static final int NAVIGATION_TRACKBALL = 3; 165 public static final int NAVIGATION_WHEEL = 4; 166 167 /** 168 * The kind of navigation method available on the device. 169 * One of: {@link #NAVIGATION_NONAV}, {@link #NAVIGATION_DPAD}, 170 * {@link #NAVIGATION_TRACKBALL}, {@link #NAVIGATION_WHEEL}. 171 */ 172 public int navigation; 173 174 public static final int NAVIGATIONHIDDEN_UNDEFINED = 0; 175 public static final int NAVIGATIONHIDDEN_NO = 1; 176 public static final int NAVIGATIONHIDDEN_YES = 2; 177 178 /** 179 * A flag indicating whether any 5-way or DPAD navigation available. 180 * This will be set on a device with a mechanism to hide the navigation 181 * controls from the user, when that mechanism is closed. One of: 182 * {@link #NAVIGATIONHIDDEN_NO}, {@link #NAVIGATIONHIDDEN_YES}. 183 */ 184 public int navigationHidden; 185 186 public static final int ORIENTATION_UNDEFINED = 0; 187 public static final int ORIENTATION_PORTRAIT = 1; 188 public static final int ORIENTATION_LANDSCAPE = 2; 189 public static final int ORIENTATION_SQUARE = 3; 190 191 /** 192 * Overall orientation of the screen. May be one of 193 * {@link #ORIENTATION_LANDSCAPE}, {@link #ORIENTATION_PORTRAIT}, 194 * or {@link #ORIENTATION_SQUARE}. 195 */ 196 public int orientation; 197 198 public static final int UI_MODE_TYPE_MASK = 0x0f; 199 public static final int UI_MODE_TYPE_UNDEFINED = 0x00; 200 public static final int UI_MODE_TYPE_NORMAL = 0x01; 201 public static final int UI_MODE_TYPE_DESK = 0x02; 202 public static final int UI_MODE_TYPE_CAR = 0x03; 203 204 public static final int UI_MODE_NIGHT_MASK = 0x30; 205 public static final int UI_MODE_NIGHT_UNDEFINED = 0x00; 206 public static final int UI_MODE_NIGHT_NO = 0x10; 207 public static final int UI_MODE_NIGHT_YES = 0x20; 208 209 /** 210 * Bit mask of the ui mode. Currently there are two fields: 211 * <p>The {@link #UI_MODE_TYPE_MASK} bits define the overall ui mode of the 212 * device. They may be one of {@link #UI_MODE_TYPE_UNDEFINED}, 213 * {@link #UI_MODE_TYPE_NORMAL}, {@link #UI_MODE_TYPE_DESK}, 214 * or {@link #UI_MODE_TYPE_CAR}. 215 * 216 * <p>The {@link #UI_MODE_NIGHT_MASK} defines whether the screen 217 * is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED}, 218 * {@link #UI_MODE_NIGHT_NO} or {@link #UI_MODE_NIGHT_YES}. 219 */ 220 public int uiMode; 221 222 /** 223 * @hide Internal book-keeping. 224 */ 225 public int seq; 226 227 /** 228 * Construct an invalid Configuration. You must call {@link #setToDefaults} 229 * for this object to be valid. {@more} 230 */ 231 public Configuration() { 232 setToDefaults(); 233 } 234 235 /** 236 * Makes a deep copy suitable for modification. 237 */ 238 public Configuration(Configuration o) { 239 setTo(o); 240 } 241 242 public void setTo(Configuration o) { 243 fontScale = o.fontScale; 244 mcc = o.mcc; 245 mnc = o.mnc; 246 if (o.locale != null) { 247 locale = (Locale) o.locale.clone(); 248 } 249 userSetLocale = o.userSetLocale; 250 touchscreen = o.touchscreen; 251 keyboard = o.keyboard; 252 keyboardHidden = o.keyboardHidden; 253 hardKeyboardHidden = o.hardKeyboardHidden; 254 navigation = o.navigation; 255 navigationHidden = o.navigationHidden; 256 orientation = o.orientation; 257 screenLayout = o.screenLayout; 258 uiMode = o.uiMode; 259 seq = o.seq; 260 } 261 262 public String toString() { 263 StringBuilder sb = new StringBuilder(128); 264 sb.append("{ scale="); 265 sb.append(fontScale); 266 sb.append(" imsi="); 267 sb.append(mcc); 268 sb.append("/"); 269 sb.append(mnc); 270 sb.append(" loc="); 271 sb.append(locale); 272 sb.append(" touch="); 273 sb.append(touchscreen); 274 sb.append(" keys="); 275 sb.append(keyboard); 276 sb.append("/"); 277 sb.append(keyboardHidden); 278 sb.append("/"); 279 sb.append(hardKeyboardHidden); 280 sb.append(" nav="); 281 sb.append(navigation); 282 sb.append("/"); 283 sb.append(navigationHidden); 284 sb.append(" orien="); 285 switch(orientation) { 286 case ORIENTATION_LANDSCAPE: 287 sb.append("L"); break; 288 case ORIENTATION_PORTRAIT: 289 sb.append("P"); break; 290 default: 291 sb.append(orientation); 292 } 293 sb.append(" layout=0x"); 294 sb.append(java.lang.Integer.toHexString(screenLayout)); 295 sb.append(" uiMode=0x"); 296 sb.append(java.lang.Integer.toHexString(uiMode)); 297 if (seq != 0) { 298 sb.append(" seq="); 299 sb.append(seq); 300 } 301 sb.append('}'); 302 return sb.toString(); 303 } 304 305 /** 306 * Set this object to the system defaults. 307 */ 308 public void setToDefaults() { 309 fontScale = 1; 310 mcc = mnc = 0; 311 locale = null; 312 userSetLocale = false; 313 touchscreen = TOUCHSCREEN_UNDEFINED; 314 keyboard = KEYBOARD_UNDEFINED; 315 keyboardHidden = KEYBOARDHIDDEN_UNDEFINED; 316 hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED; 317 navigation = NAVIGATION_UNDEFINED; 318 navigationHidden = NAVIGATIONHIDDEN_UNDEFINED; 319 orientation = ORIENTATION_UNDEFINED; 320 screenLayout = SCREENLAYOUT_SIZE_UNDEFINED; 321 uiMode = UI_MODE_TYPE_UNDEFINED; 322 seq = 0; 323 } 324 325 /** {@hide} */ 326 @Deprecated public void makeDefault() { 327 setToDefaults(); 328 } 329 330 /** 331 * Copy the fields from delta into this Configuration object, keeping 332 * track of which ones have changed. Any undefined fields in 333 * <var>delta</var> are ignored and not copied in to the current 334 * Configuration. 335 * @return Returns a bit mask of the changed fields, as per 336 * {@link #diff}. 337 */ 338 public int updateFrom(Configuration delta) { 339 int changed = 0; 340 if (delta.fontScale > 0 && fontScale != delta.fontScale) { 341 changed |= ActivityInfo.CONFIG_FONT_SCALE; 342 fontScale = delta.fontScale; 343 } 344 if (delta.mcc != 0 && mcc != delta.mcc) { 345 changed |= ActivityInfo.CONFIG_MCC; 346 mcc = delta.mcc; 347 } 348 if (delta.mnc != 0 && mnc != delta.mnc) { 349 changed |= ActivityInfo.CONFIG_MNC; 350 mnc = delta.mnc; 351 } 352 if (delta.locale != null 353 && (locale == null || !locale.equals(delta.locale))) { 354 changed |= ActivityInfo.CONFIG_LOCALE; 355 locale = delta.locale != null 356 ? (Locale) delta.locale.clone() : null; 357 } 358 if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0))) 359 { 360 userSetLocale = true; 361 changed |= ActivityInfo.CONFIG_LOCALE; 362 } 363 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED 364 && touchscreen != delta.touchscreen) { 365 changed |= ActivityInfo.CONFIG_TOUCHSCREEN; 366 touchscreen = delta.touchscreen; 367 } 368 if (delta.keyboard != KEYBOARD_UNDEFINED 369 && keyboard != delta.keyboard) { 370 changed |= ActivityInfo.CONFIG_KEYBOARD; 371 keyboard = delta.keyboard; 372 } 373 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED 374 && keyboardHidden != delta.keyboardHidden) { 375 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 376 keyboardHidden = delta.keyboardHidden; 377 } 378 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED 379 && hardKeyboardHidden != delta.hardKeyboardHidden) { 380 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 381 hardKeyboardHidden = delta.hardKeyboardHidden; 382 } 383 if (delta.navigation != NAVIGATION_UNDEFINED 384 && navigation != delta.navigation) { 385 changed |= ActivityInfo.CONFIG_NAVIGATION; 386 navigation = delta.navigation; 387 } 388 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED 389 && navigationHidden != delta.navigationHidden) { 390 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 391 navigationHidden = delta.navigationHidden; 392 } 393 if (delta.orientation != ORIENTATION_UNDEFINED 394 && orientation != delta.orientation) { 395 changed |= ActivityInfo.CONFIG_ORIENTATION; 396 orientation = delta.orientation; 397 } 398 if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED 399 && screenLayout != delta.screenLayout) { 400 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; 401 screenLayout = delta.screenLayout; 402 } 403 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED) 404 && uiMode != delta.uiMode) { 405 changed |= ActivityInfo.CONFIG_UI_MODE; 406 if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) { 407 uiMode = (uiMode&~UI_MODE_TYPE_MASK) 408 | (delta.uiMode&UI_MODE_TYPE_MASK); 409 } 410 if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) { 411 uiMode = (uiMode&~UI_MODE_NIGHT_MASK) 412 | (delta.uiMode&UI_MODE_NIGHT_MASK); 413 } 414 } 415 416 if (delta.seq != 0) { 417 seq = delta.seq; 418 } 419 420 return changed; 421 } 422 423 /** 424 * Return a bit mask of the differences between this Configuration 425 * object and the given one. Does not change the values of either. Any 426 * undefined fields in <var>delta</var> are ignored. 427 * @return Returns a bit mask indicating which configuration 428 * values has changed, containing any combination of 429 * {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE 430 * PackageManager.ActivityInfo.CONFIG_FONT_SCALE}, 431 * {@link android.content.pm.ActivityInfo#CONFIG_MCC 432 * PackageManager.ActivityInfo.CONFIG_MCC}, 433 * {@link android.content.pm.ActivityInfo#CONFIG_MNC 434 * PackageManager.ActivityInfo.CONFIG_MNC}, 435 * {@link android.content.pm.ActivityInfo#CONFIG_LOCALE 436 * PackageManager.ActivityInfo.CONFIG_LOCALE}, 437 * {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN 438 * PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN}, 439 * {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD 440 * PackageManager.ActivityInfo.CONFIG_KEYBOARD}, 441 * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION 442 * PackageManager.ActivityInfo.CONFIG_NAVIGATION}, 443 * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION 444 * PackageManager.ActivityInfo.CONFIG_ORIENTATION}, or 445 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT 446 * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}. 447 */ 448 public int diff(Configuration delta) { 449 int changed = 0; 450 if (delta.fontScale > 0 && fontScale != delta.fontScale) { 451 changed |= ActivityInfo.CONFIG_FONT_SCALE; 452 } 453 if (delta.mcc != 0 && mcc != delta.mcc) { 454 changed |= ActivityInfo.CONFIG_MCC; 455 } 456 if (delta.mnc != 0 && mnc != delta.mnc) { 457 changed |= ActivityInfo.CONFIG_MNC; 458 } 459 if (delta.locale != null 460 && (locale == null || !locale.equals(delta.locale))) { 461 changed |= ActivityInfo.CONFIG_LOCALE; 462 } 463 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED 464 && touchscreen != delta.touchscreen) { 465 changed |= ActivityInfo.CONFIG_TOUCHSCREEN; 466 } 467 if (delta.keyboard != KEYBOARD_UNDEFINED 468 && keyboard != delta.keyboard) { 469 changed |= ActivityInfo.CONFIG_KEYBOARD; 470 } 471 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED 472 && keyboardHidden != delta.keyboardHidden) { 473 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 474 } 475 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED 476 && hardKeyboardHidden != delta.hardKeyboardHidden) { 477 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 478 } 479 if (delta.navigation != NAVIGATION_UNDEFINED 480 && navigation != delta.navigation) { 481 changed |= ActivityInfo.CONFIG_NAVIGATION; 482 } 483 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED 484 && navigationHidden != delta.navigationHidden) { 485 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; 486 } 487 if (delta.orientation != ORIENTATION_UNDEFINED 488 && orientation != delta.orientation) { 489 changed |= ActivityInfo.CONFIG_ORIENTATION; 490 } 491 if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED 492 && screenLayout != delta.screenLayout) { 493 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; 494 } 495 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED) 496 && uiMode != delta.uiMode) { 497 changed |= ActivityInfo.CONFIG_UI_MODE; 498 } 499 500 return changed; 501 } 502 503 /** 504 * Determine if a new resource needs to be loaded from the bit set of 505 * configuration changes returned by {@link #updateFrom(Configuration)}. 506 * 507 * @param configChanges The mask of changes configurations as returned by 508 * {@link #updateFrom(Configuration)}. 509 * @param interestingChanges The configuration changes that the resource 510 * can handled, as given in {@link android.util.TypedValue#changingConfigurations}. 511 * 512 * @return Return true if the resource needs to be loaded, else false. 513 */ 514 public static boolean needNewResources(int configChanges, int interestingChanges) { 515 return (configChanges & (interestingChanges|ActivityInfo.CONFIG_FONT_SCALE)) != 0; 516 } 517 518 /** 519 * @hide Return true if the sequence of 'other' is better than this. Assumes 520 * that 'this' is your current sequence and 'other' is a new one you have 521 * received some how and want to compare with what you have. 522 */ 523 public boolean isOtherSeqNewer(Configuration other) { 524 if (other == null) { 525 // Sanity check. 526 return false; 527 } 528 if (other.seq == 0) { 529 // If the other sequence is not specified, then we must assume 530 // it is newer since we don't know any better. 531 return true; 532 } 533 if (seq == 0) { 534 // If this sequence is not specified, then we also consider the 535 // other is better. Yes we have a preference for other. Sue us. 536 return true; 537 } 538 int diff = other.seq - seq; 539 if (diff > 0x10000) { 540 // If there has been a sufficiently large jump, assume the 541 // sequence has wrapped around. 542 return false; 543 } 544 return diff > 0; 545 } 546 547 /** 548 * Parcelable methods 549 */ 550 public int describeContents() { 551 return 0; 552 } 553 554 public void writeToParcel(Parcel dest, int flags) { 555 dest.writeFloat(fontScale); 556 dest.writeInt(mcc); 557 dest.writeInt(mnc); 558 if (locale == null) { 559 dest.writeInt(0); 560 } else { 561 dest.writeInt(1); 562 dest.writeString(locale.getLanguage()); 563 dest.writeString(locale.getCountry()); 564 dest.writeString(locale.getVariant()); 565 } 566 if(userSetLocale) { 567 dest.writeInt(1); 568 } else { 569 dest.writeInt(0); 570 } 571 dest.writeInt(touchscreen); 572 dest.writeInt(keyboard); 573 dest.writeInt(keyboardHidden); 574 dest.writeInt(hardKeyboardHidden); 575 dest.writeInt(navigation); 576 dest.writeInt(navigationHidden); 577 dest.writeInt(orientation); 578 dest.writeInt(screenLayout); 579 dest.writeInt(uiMode); 580 dest.writeInt(seq); 581 } 582 583 public void readFromParcel(Parcel source) { 584 fontScale = source.readFloat(); 585 mcc = source.readInt(); 586 mnc = source.readInt(); 587 if (source.readInt() != 0) { 588 locale = new Locale(source.readString(), source.readString(), 589 source.readString()); 590 } 591 userSetLocale = (source.readInt()==1); 592 touchscreen = source.readInt(); 593 keyboard = source.readInt(); 594 keyboardHidden = source.readInt(); 595 hardKeyboardHidden = source.readInt(); 596 navigation = source.readInt(); 597 navigationHidden = source.readInt(); 598 orientation = source.readInt(); 599 screenLayout = source.readInt(); 600 uiMode = source.readInt(); 601 seq = source.readInt(); 602 } 603 604 public static final Parcelable.Creator<Configuration> CREATOR 605 = new Parcelable.Creator<Configuration>() { 606 public Configuration createFromParcel(Parcel source) { 607 return new Configuration(source); 608 } 609 610 public Configuration[] newArray(int size) { 611 return new Configuration[size]; 612 } 613 }; 614 615 /** 616 * Construct this Configuration object, reading from the Parcel. 617 */ 618 private Configuration(Parcel source) { 619 readFromParcel(source); 620 } 621 622 public int compareTo(Configuration that) { 623 int n; 624 float a = this.fontScale; 625 float b = that.fontScale; 626 if (a < b) return -1; 627 if (a > b) return 1; 628 n = this.mcc - that.mcc; 629 if (n != 0) return n; 630 n = this.mnc - that.mnc; 631 if (n != 0) return n; 632 if (this.locale == null) { 633 if (that.locale != null) return 1; 634 } else if (that.locale == null) { 635 return -1; 636 } else { 637 n = this.locale.getLanguage().compareTo(that.locale.getLanguage()); 638 if (n != 0) return n; 639 n = this.locale.getCountry().compareTo(that.locale.getCountry()); 640 if (n != 0) return n; 641 n = this.locale.getVariant().compareTo(that.locale.getVariant()); 642 if (n != 0) return n; 643 } 644 n = this.touchscreen - that.touchscreen; 645 if (n != 0) return n; 646 n = this.keyboard - that.keyboard; 647 if (n != 0) return n; 648 n = this.keyboardHidden - that.keyboardHidden; 649 if (n != 0) return n; 650 n = this.hardKeyboardHidden - that.hardKeyboardHidden; 651 if (n != 0) return n; 652 n = this.navigation - that.navigation; 653 if (n != 0) return n; 654 n = this.navigationHidden - that.navigationHidden; 655 if (n != 0) return n; 656 n = this.orientation - that.orientation; 657 if (n != 0) return n; 658 n = this.screenLayout - that.screenLayout; 659 if (n != 0) return n; 660 n = this.uiMode - that.uiMode; 661 //if (n != 0) return n; 662 return n; 663 } 664 665 public boolean equals(Configuration that) { 666 if (that == null) return false; 667 if (that == this) return true; 668 return this.compareTo(that) == 0; 669 } 670 671 public boolean equals(Object that) { 672 try { 673 return equals((Configuration)that); 674 } catch (ClassCastException e) { 675 } 676 return false; 677 } 678 679 public int hashCode() { 680 return ((int)this.fontScale) + this.mcc + this.mnc 681 + (this.locale != null ? this.locale.hashCode() : 0) 682 + this.touchscreen 683 + this.keyboard + this.keyboardHidden + this.hardKeyboardHidden 684 + this.navigation + this.navigationHidden 685 + this.orientation + this.screenLayout + this.uiMode; 686 } 687} 688