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