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