blob: 61e3004c327e45f0901ff770637b3e5b3e71428e [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001package android.content.res;
2
3import android.content.pm.ActivityInfo;
4import android.os.Parcel;
5import android.os.Parcelable;
6
7import java.util.Locale;
8
9/**
10 * This class describes all device configuration information that can
11 * impact the resources the application retrieves. This includes both
12 * user-specified configuration options (locale and scaling) as well
13 * as dynamic device configuration (various types of input devices).
14 */
15public final class Configuration implements Parcelable, Comparable<Configuration> {
16 /**
17 * Current user preference for the scaling factor for fonts, relative
18 * to the base density scaling.
19 */
20 public float fontScale;
21
22 /**
23 * IMSI MCC (Mobile Country Code). 0 if undefined.
24 */
25 public int mcc;
26
27 /**
28 * IMSI MNC (Mobile Network Code). 0 if undefined.
29 */
30 public int mnc;
31
32 /**
33 * Current user preference for the locale.
34 */
35 public Locale locale;
36
37 /**
Andy Stadlerf8a7cea2009-04-10 16:24:47 -070038 * Locale should persist on setting. This is hidden because it is really
39 * questionable whether this is the right way to expose the functionality.
40 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041 */
42 public boolean userSetLocale;
43
Dianne Hackbornc4db95c2009-07-21 17:46:02 -070044 public static final int SCREENLAYOUT_SIZE_MASK = 0x0f;
45 public static final int SCREENLAYOUT_SIZE_UNDEFINED = 0x00;
46 public static final int SCREENLAYOUT_SIZE_SMALL = 0x01;
47 public static final int SCREENLAYOUT_SIZE_NORMAL = 0x02;
48 public static final int SCREENLAYOUT_SIZE_LARGE = 0x03;
49
50 public static final int SCREENLAYOUT_LONG_MASK = 0x30;
51 public static final int SCREENLAYOUT_LONG_UNDEFINED = 0x00;
52 public static final int SCREENLAYOUT_LONG_NO = 0x10;
53 public static final int SCREENLAYOUT_LONG_YES = 0x20;
54
55 /**
56 * Special flag we generate to indicate that the screen layout requires
57 * us to use a compatibility mode for apps that are not modern layout
58 * aware.
59 * @hide
60 */
61 public static final int SCREENLAYOUT_COMPAT_NEEDED = 0x10000000;
62
63 /**
64 * Bit mask of overall layout of the screen. Currently there are two
65 * fields:
66 * <p>The {@link #SCREENLAYOUT_SIZE_MASK} bits define the overall size
67 * of the screen. They may be one of
68 * {@link #SCREENLAYOUT_SIZE_SMALL}, {@link #SCREENLAYOUT_SIZE_NORMAL},
69 * or {@link #SCREENLAYOUT_SIZE_LARGE}.
70 *
71 * <p>The {@link #SCREENLAYOUT_LONG_MASK} defines whether the screen
72 * is wider/taller than normal. They may be one of
73 * {@link #SCREENLAYOUT_LONG_NO} or {@link #SCREENLAYOUT_LONG_YES}.
74 */
75 public int screenLayout;
76
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 public static final int TOUCHSCREEN_UNDEFINED = 0;
78 public static final int TOUCHSCREEN_NOTOUCH = 1;
79 public static final int TOUCHSCREEN_STYLUS = 2;
80 public static final int TOUCHSCREEN_FINGER = 3;
81
82 /**
83 * The kind of touch screen attached to the device.
84 * One of: {@link #TOUCHSCREEN_NOTOUCH}, {@link #TOUCHSCREEN_STYLUS},
85 * {@link #TOUCHSCREEN_FINGER}.
86 */
87 public int touchscreen;
88
89 public static final int KEYBOARD_UNDEFINED = 0;
90 public static final int KEYBOARD_NOKEYS = 1;
91 public static final int KEYBOARD_QWERTY = 2;
92 public static final int KEYBOARD_12KEY = 3;
93
94 /**
95 * The kind of keyboard attached to the device.
Kenny Root507f8ed2009-06-09 11:21:11 -050096 * One of: {@link #KEYBOARD_NOKEYS}, {@link #KEYBOARD_QWERTY},
97 * {@link #KEYBOARD_12KEY}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 */
99 public int keyboard;
100
101 public static final int KEYBOARDHIDDEN_UNDEFINED = 0;
102 public static final int KEYBOARDHIDDEN_NO = 1;
103 public static final int KEYBOARDHIDDEN_YES = 2;
104 /** Constant matching actual resource implementation. {@hide} */
105 public static final int KEYBOARDHIDDEN_SOFT = 3;
106
107 /**
108 * A flag indicating whether any keyboard is available. Unlike
109 * {@link #hardKeyboardHidden}, this also takes into account a soft
110 * keyboard, so if the hard keyboard is hidden but there is soft
111 * keyboard available, it will be set to NO. Value is one of:
112 * {@link #KEYBOARDHIDDEN_NO}, {@link #KEYBOARDHIDDEN_YES}.
113 */
114 public int keyboardHidden;
115
116 public static final int HARDKEYBOARDHIDDEN_UNDEFINED = 0;
117 public static final int HARDKEYBOARDHIDDEN_NO = 1;
118 public static final int HARDKEYBOARDHIDDEN_YES = 2;
119
120 /**
121 * A flag indicating whether the hard keyboard has been hidden. This will
122 * be set on a device with a mechanism to hide the keyboard from the
123 * user, when that mechanism is closed. One of:
124 * {@link #HARDKEYBOARDHIDDEN_NO}, {@link #HARDKEYBOARDHIDDEN_YES}.
125 */
126 public int hardKeyboardHidden;
127
128 public static final int NAVIGATION_UNDEFINED = 0;
129 public static final int NAVIGATION_NONAV = 1;
130 public static final int NAVIGATION_DPAD = 2;
131 public static final int NAVIGATION_TRACKBALL = 3;
132 public static final int NAVIGATION_WHEEL = 4;
133
134 /**
135 * The kind of navigation method available on the device.
Kenny Root507f8ed2009-06-09 11:21:11 -0500136 * One of: {@link #NAVIGATION_NONAV}, {@link #NAVIGATION_DPAD},
137 * {@link #NAVIGATION_TRACKBALL}, {@link #NAVIGATION_WHEEL}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 */
139 public int navigation;
140
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700141 public static final int NAVIGATIONHIDDEN_UNDEFINED = 0;
142 public static final int NAVIGATIONHIDDEN_NO = 1;
143 public static final int NAVIGATIONHIDDEN_YES = 2;
144
145 /**
146 * A flag indicating whether any 5-way or DPAD navigation available.
147 * This will be set on a device with a mechanism to hide the navigation
148 * controls from the user, when that mechanism is closed. One of:
149 * {@link #NAVIGATIONHIDDEN_NO}, {@link #NAVIGATIONHIDDEN_YES}.
150 */
151 public int navigationHidden;
152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 public static final int ORIENTATION_UNDEFINED = 0;
154 public static final int ORIENTATION_PORTRAIT = 1;
155 public static final int ORIENTATION_LANDSCAPE = 2;
156 public static final int ORIENTATION_SQUARE = 3;
157
158 /**
159 * Overall orientation of the screen. May be one of
160 * {@link #ORIENTATION_LANDSCAPE}, {@link #ORIENTATION_PORTRAIT},
161 * or {@link #ORIENTATION_SQUARE}.
162 */
163 public int orientation;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100164
Tobias Haamel27b28b32010-02-09 23:09:17 +0100165 public static final int UI_MODE_TYPE_MASK = 0x0f;
Dianne Hackbornef05e072010-03-01 17:43:39 -0800166 public static final int UI_MODE_TYPE_UNDEFINED = 0x00;
167 public static final int UI_MODE_TYPE_NORMAL = 0x01;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800168 public static final int UI_MODE_TYPE_DESK = 0x02;
169 public static final int UI_MODE_TYPE_CAR = 0x03;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100170
Tobias Haamel27b28b32010-02-09 23:09:17 +0100171 public static final int UI_MODE_NIGHT_MASK = 0x30;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100172 public static final int UI_MODE_NIGHT_UNDEFINED = 0x00;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100173 public static final int UI_MODE_NIGHT_NO = 0x10;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100174 public static final int UI_MODE_NIGHT_YES = 0x20;
175
176 /**
177 * Bit mask of the ui mode. Currently there are two fields:
178 * <p>The {@link #UI_MODE_TYPE_MASK} bits define the overall ui mode of the
Dianne Hackborn7299c412010-03-04 18:41:49 -0800179 * device. They may be one of {@link #UI_MODE_TYPE_UNDEFINED},
180 * {@link #UI_MODE_TYPE_NORMAL}, {@link #UI_MODE_TYPE_DESK},
181 * or {@link #UI_MODE_TYPE_CAR}.
Tobias Haamel27b28b32010-02-09 23:09:17 +0100182 *
183 * <p>The {@link #UI_MODE_NIGHT_MASK} defines whether the screen
Dianne Hackborn7299c412010-03-04 18:41:49 -0800184 * is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED},
Tobias Haamel27b28b32010-02-09 23:09:17 +0100185 * {@link #UI_MODE_NIGHT_NO} or {@link #UI_MODE_NIGHT_YES}.
Tobias Haamel27b28b32010-02-09 23:09:17 +0100186 */
187 public int uiMode;
188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 /**
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800190 * @hide Internal book-keeping.
191 */
192 public int seq;
193
194 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 * Construct an invalid Configuration. You must call {@link #setToDefaults}
196 * for this object to be valid. {@more}
197 */
198 public Configuration() {
199 setToDefaults();
200 }
201
202 /**
203 * Makes a deep copy suitable for modification.
204 */
205 public Configuration(Configuration o) {
206 fontScale = o.fontScale;
207 mcc = o.mcc;
208 mnc = o.mnc;
209 if (o.locale != null) {
210 locale = (Locale) o.locale.clone();
211 }
212 userSetLocale = o.userSetLocale;
213 touchscreen = o.touchscreen;
214 keyboard = o.keyboard;
215 keyboardHidden = o.keyboardHidden;
216 hardKeyboardHidden = o.hardKeyboardHidden;
217 navigation = o.navigation;
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700218 navigationHidden = o.navigationHidden;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 orientation = o.orientation;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700220 screenLayout = o.screenLayout;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100221 uiMode = o.uiMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800222 seq = o.seq;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 }
224
225 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700226 StringBuilder sb = new StringBuilder(128);
227 sb.append("{ scale=");
228 sb.append(fontScale);
229 sb.append(" imsi=");
230 sb.append(mcc);
231 sb.append("/");
232 sb.append(mnc);
233 sb.append(" loc=");
234 sb.append(locale);
235 sb.append(" touch=");
236 sb.append(touchscreen);
237 sb.append(" keys=");
238 sb.append(keyboard);
239 sb.append("/");
240 sb.append(keyboardHidden);
241 sb.append("/");
242 sb.append(hardKeyboardHidden);
243 sb.append(" nav=");
244 sb.append(navigation);
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700245 sb.append("/");
246 sb.append(navigationHidden);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700247 sb.append(" orien=");
248 sb.append(orientation);
Dianne Hackborn723738c2009-06-25 19:48:04 -0700249 sb.append(" layout=");
250 sb.append(screenLayout);
Tobias Haamel27b28b32010-02-09 23:09:17 +0100251 sb.append(" uiMode=");
252 sb.append(uiMode);
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800253 if (seq != 0) {
254 sb.append(" seq=");
255 sb.append(seq);
256 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700257 sb.append('}');
258 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 }
260
261 /**
262 * Set this object to the system defaults.
263 */
264 public void setToDefaults() {
265 fontScale = 1;
266 mcc = mnc = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800267 locale = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 userSetLocale = false;
269 touchscreen = TOUCHSCREEN_UNDEFINED;
270 keyboard = KEYBOARD_UNDEFINED;
271 keyboardHidden = KEYBOARDHIDDEN_UNDEFINED;
272 hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED;
273 navigation = NAVIGATION_UNDEFINED;
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700274 navigationHidden = NAVIGATIONHIDDEN_UNDEFINED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 orientation = ORIENTATION_UNDEFINED;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700276 screenLayout = SCREENLAYOUT_SIZE_UNDEFINED;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800277 uiMode = UI_MODE_TYPE_UNDEFINED;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800278 seq = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 }
280
281 /** {@hide} */
282 @Deprecated public void makeDefault() {
283 setToDefaults();
284 }
285
286 /**
287 * Copy the fields from delta into this Configuration object, keeping
288 * track of which ones have changed. Any undefined fields in
289 * <var>delta</var> are ignored and not copied in to the current
290 * Configuration.
291 * @return Returns a bit mask of the changed fields, as per
292 * {@link #diff}.
293 */
294 public int updateFrom(Configuration delta) {
295 int changed = 0;
296 if (delta.fontScale > 0 && fontScale != delta.fontScale) {
297 changed |= ActivityInfo.CONFIG_FONT_SCALE;
298 fontScale = delta.fontScale;
299 }
300 if (delta.mcc != 0 && mcc != delta.mcc) {
301 changed |= ActivityInfo.CONFIG_MCC;
302 mcc = delta.mcc;
303 }
304 if (delta.mnc != 0 && mnc != delta.mnc) {
305 changed |= ActivityInfo.CONFIG_MNC;
306 mnc = delta.mnc;
307 }
308 if (delta.locale != null
309 && (locale == null || !locale.equals(delta.locale))) {
310 changed |= ActivityInfo.CONFIG_LOCALE;
311 locale = delta.locale != null
312 ? (Locale) delta.locale.clone() : null;
313 }
314 if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0)))
315 {
316 userSetLocale = true;
317 changed |= ActivityInfo.CONFIG_LOCALE;
318 }
319 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
320 && touchscreen != delta.touchscreen) {
321 changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
322 touchscreen = delta.touchscreen;
323 }
324 if (delta.keyboard != KEYBOARD_UNDEFINED
325 && keyboard != delta.keyboard) {
326 changed |= ActivityInfo.CONFIG_KEYBOARD;
327 keyboard = delta.keyboard;
328 }
329 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED
330 && keyboardHidden != delta.keyboardHidden) {
331 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
332 keyboardHidden = delta.keyboardHidden;
333 }
334 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED
335 && hardKeyboardHidden != delta.hardKeyboardHidden) {
336 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
337 hardKeyboardHidden = delta.hardKeyboardHidden;
338 }
339 if (delta.navigation != NAVIGATION_UNDEFINED
340 && navigation != delta.navigation) {
341 changed |= ActivityInfo.CONFIG_NAVIGATION;
342 navigation = delta.navigation;
343 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700344 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
345 && navigationHidden != delta.navigationHidden) {
346 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
347 navigationHidden = delta.navigationHidden;
348 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 if (delta.orientation != ORIENTATION_UNDEFINED
350 && orientation != delta.orientation) {
351 changed |= ActivityInfo.CONFIG_ORIENTATION;
352 orientation = delta.orientation;
353 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700354 if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED
Dianne Hackborn723738c2009-06-25 19:48:04 -0700355 && screenLayout != delta.screenLayout) {
356 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
357 screenLayout = delta.screenLayout;
358 }
Dianne Hackborn7299c412010-03-04 18:41:49 -0800359 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)
Tobias Haamel27b28b32010-02-09 23:09:17 +0100360 && uiMode != delta.uiMode) {
361 changed |= ActivityInfo.CONFIG_UI_MODE;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800362 if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) {
363 uiMode = (uiMode&~UI_MODE_TYPE_MASK)
364 | (delta.uiMode&UI_MODE_TYPE_MASK);
365 }
366 if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) {
367 uiMode = (uiMode&~UI_MODE_NIGHT_MASK)
368 | (delta.uiMode&UI_MODE_NIGHT_MASK);
369 }
Tobias Haamel27b28b32010-02-09 23:09:17 +0100370 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800372 if (delta.seq != 0) {
373 seq = delta.seq;
374 }
375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 return changed;
377 }
378
379 /**
380 * Return a bit mask of the differences between this Configuration
381 * object and the given one. Does not change the values of either. Any
382 * undefined fields in <var>delta</var> are ignored.
383 * @return Returns a bit mask indicating which configuration
384 * values has changed, containing any combination of
385 * {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE
386 * PackageManager.ActivityInfo.CONFIG_FONT_SCALE},
387 * {@link android.content.pm.ActivityInfo#CONFIG_MCC
388 * PackageManager.ActivityInfo.CONFIG_MCC},
389 * {@link android.content.pm.ActivityInfo#CONFIG_MNC
390 * PackageManager.ActivityInfo.CONFIG_MNC},
391 * {@link android.content.pm.ActivityInfo#CONFIG_LOCALE
392 * PackageManager.ActivityInfo.CONFIG_LOCALE},
393 * {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN
394 * PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN},
395 * {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD
396 * PackageManager.ActivityInfo.CONFIG_KEYBOARD},
397 * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION
Dianne Hackborn723738c2009-06-25 19:48:04 -0700398 * PackageManager.ActivityInfo.CONFIG_NAVIGATION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION
Dianne Hackborn723738c2009-06-25 19:48:04 -0700400 * PackageManager.ActivityInfo.CONFIG_ORIENTATION}, or
401 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT
402 * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 */
404 public int diff(Configuration delta) {
405 int changed = 0;
406 if (delta.fontScale > 0 && fontScale != delta.fontScale) {
407 changed |= ActivityInfo.CONFIG_FONT_SCALE;
408 }
409 if (delta.mcc != 0 && mcc != delta.mcc) {
410 changed |= ActivityInfo.CONFIG_MCC;
411 }
412 if (delta.mnc != 0 && mnc != delta.mnc) {
413 changed |= ActivityInfo.CONFIG_MNC;
414 }
415 if (delta.locale != null
416 && (locale == null || !locale.equals(delta.locale))) {
417 changed |= ActivityInfo.CONFIG_LOCALE;
418 }
419 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
420 && touchscreen != delta.touchscreen) {
421 changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
422 }
423 if (delta.keyboard != KEYBOARD_UNDEFINED
424 && keyboard != delta.keyboard) {
425 changed |= ActivityInfo.CONFIG_KEYBOARD;
426 }
427 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED
428 && keyboardHidden != delta.keyboardHidden) {
429 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
430 }
431 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED
432 && hardKeyboardHidden != delta.hardKeyboardHidden) {
433 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
434 }
435 if (delta.navigation != NAVIGATION_UNDEFINED
436 && navigation != delta.navigation) {
437 changed |= ActivityInfo.CONFIG_NAVIGATION;
438 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700439 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
440 && navigationHidden != delta.navigationHidden) {
441 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
442 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 if (delta.orientation != ORIENTATION_UNDEFINED
444 && orientation != delta.orientation) {
445 changed |= ActivityInfo.CONFIG_ORIENTATION;
446 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700447 if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED
Dianne Hackborn723738c2009-06-25 19:48:04 -0700448 && screenLayout != delta.screenLayout) {
449 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
450 }
Dianne Hackborn7299c412010-03-04 18:41:49 -0800451 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)
Tobias Haamel27b28b32010-02-09 23:09:17 +0100452 && uiMode != delta.uiMode) {
453 changed |= ActivityInfo.CONFIG_UI_MODE;
454 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455
456 return changed;
457 }
458
459 /**
460 * Determine if a new resource needs to be loaded from the bit set of
461 * configuration changes returned by {@link #updateFrom(Configuration)}.
462 *
463 * @param configChanges The mask of changes configurations as returned by
464 * {@link #updateFrom(Configuration)}.
465 * @param interestingChanges The configuration changes that the resource
466 * can handled, as given in {@link android.util.TypedValue#changingConfigurations}.
467 *
468 * @return Return true if the resource needs to be loaded, else false.
469 */
470 public static boolean needNewResources(int configChanges, int interestingChanges) {
471 return (configChanges & (interestingChanges|ActivityInfo.CONFIG_FONT_SCALE)) != 0;
472 }
473
474 /**
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800475 * @hide Return true if the sequence of 'other' is better than this. Assumes
476 * that 'this' is your current sequence and 'other' is a new one you have
477 * received some how and want to compare with what you have.
478 */
479 public boolean isOtherSeqNewer(Configuration other) {
480 if (other == null) {
481 // Sanity check.
482 return false;
483 }
484 if (other.seq == 0) {
485 // If the other sequence is not specified, then we must assume
486 // it is newer since we don't know any better.
487 return true;
488 }
489 if (seq == 0) {
490 // If this sequence is not specified, then we also consider the
491 // other is better. Yes we have a preference for other. Sue us.
492 return true;
493 }
494 int diff = other.seq - seq;
495 if (diff > 0x10000) {
496 // If there has been a sufficiently large jump, assume the
497 // sequence has wrapped around.
498 return false;
499 }
500 return diff > 0;
501 }
502
503 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 * Parcelable methods
505 */
506 public int describeContents() {
507 return 0;
508 }
509
510 public void writeToParcel(Parcel dest, int flags) {
511 dest.writeFloat(fontScale);
512 dest.writeInt(mcc);
513 dest.writeInt(mnc);
514 if (locale == null) {
515 dest.writeInt(0);
516 } else {
517 dest.writeInt(1);
518 dest.writeString(locale.getLanguage());
519 dest.writeString(locale.getCountry());
520 dest.writeString(locale.getVariant());
521 }
522 if(userSetLocale) {
523 dest.writeInt(1);
524 } else {
525 dest.writeInt(0);
526 }
527 dest.writeInt(touchscreen);
528 dest.writeInt(keyboard);
529 dest.writeInt(keyboardHidden);
530 dest.writeInt(hardKeyboardHidden);
531 dest.writeInt(navigation);
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700532 dest.writeInt(navigationHidden);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 dest.writeInt(orientation);
Dianne Hackborn723738c2009-06-25 19:48:04 -0700534 dest.writeInt(screenLayout);
Tobias Haamel27b28b32010-02-09 23:09:17 +0100535 dest.writeInt(uiMode);
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800536 dest.writeInt(seq);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 }
538
539 public static final Parcelable.Creator<Configuration> CREATOR
540 = new Parcelable.Creator<Configuration>() {
541 public Configuration createFromParcel(Parcel source) {
542 return new Configuration(source);
543 }
544
545 public Configuration[] newArray(int size) {
546 return new Configuration[size];
547 }
548 };
549
550 /**
551 * Construct this Configuration object, reading from the Parcel.
552 */
553 private Configuration(Parcel source) {
554 fontScale = source.readFloat();
555 mcc = source.readInt();
556 mnc = source.readInt();
557 if (source.readInt() != 0) {
558 locale = new Locale(source.readString(), source.readString(),
559 source.readString());
560 }
561 userSetLocale = (source.readInt()==1);
562 touchscreen = source.readInt();
563 keyboard = source.readInt();
564 keyboardHidden = source.readInt();
565 hardKeyboardHidden = source.readInt();
566 navigation = source.readInt();
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700567 navigationHidden = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 orientation = source.readInt();
Dianne Hackborn723738c2009-06-25 19:48:04 -0700569 screenLayout = source.readInt();
Tobias Haamel27b28b32010-02-09 23:09:17 +0100570 uiMode = source.readInt();
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800571 seq = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 }
573
574 public int compareTo(Configuration that) {
575 int n;
576 float a = this.fontScale;
577 float b = that.fontScale;
578 if (a < b) return -1;
579 if (a > b) return 1;
580 n = this.mcc - that.mcc;
581 if (n != 0) return n;
582 n = this.mnc - that.mnc;
583 if (n != 0) return n;
584 n = this.locale.getLanguage().compareTo(that.locale.getLanguage());
585 if (n != 0) return n;
586 n = this.locale.getCountry().compareTo(that.locale.getCountry());
587 if (n != 0) return n;
588 n = this.locale.getVariant().compareTo(that.locale.getVariant());
589 if (n != 0) return n;
590 n = this.touchscreen - that.touchscreen;
591 if (n != 0) return n;
592 n = this.keyboard - that.keyboard;
593 if (n != 0) return n;
594 n = this.keyboardHidden - that.keyboardHidden;
595 if (n != 0) return n;
596 n = this.hardKeyboardHidden - that.hardKeyboardHidden;
597 if (n != 0) return n;
598 n = this.navigation - that.navigation;
599 if (n != 0) return n;
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700600 n = this.navigationHidden - that.navigationHidden;
601 if (n != 0) return n;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 n = this.orientation - that.orientation;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700603 if (n != 0) return n;
604 n = this.screenLayout - that.screenLayout;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100605 if (n != 0) return n;
606 n = this.uiMode - that.uiMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 //if (n != 0) return n;
608 return n;
609 }
610
611 public boolean equals(Configuration that) {
612 if (that == null) return false;
613 if (that == this) return true;
614 return this.compareTo(that) == 0;
615 }
616
617 public boolean equals(Object that) {
618 try {
619 return equals((Configuration)that);
620 } catch (ClassCastException e) {
621 }
622 return false;
623 }
624
625 public int hashCode() {
626 return ((int)this.fontScale) + this.mcc + this.mnc
627 + this.locale.hashCode() + this.touchscreen
628 + this.keyboard + this.keyboardHidden + this.hardKeyboardHidden
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700629 + this.navigation + this.navigationHidden
Tobias Haamel27b28b32010-02-09 23:09:17 +0100630 + this.orientation + this.screenLayout + this.uiMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 }
632}