blob: 2f110f020e7a4ee34ad3c5d57a0a757a803b58fd [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package 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 /**
Andy Stadlerf8a7cea2009-04-10 16:24:47 -070054 * 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 */
58 public boolean userSetLocale;
59
Dianne Hackbornc4db95c2009-07-21 17:46:02 -070060 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;
Dianne Hackborn14cee9f2010-04-23 17:51:26 -070065 public static final int SCREENLAYOUT_SIZE_XLARGE = 0x04;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -070066
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},
Dianne Hackborn14cee9f2010-04-23 17:51:26 -070086 * {@link #SCREENLAYOUT_SIZE_LARGE}, or {@link #SCREENLAYOUT_SIZE_XLARGE}.
Dianne Hackbornc4db95c2009-07-21 17:46:02 -070087 *
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 public static final int TOUCHSCREEN_UNDEFINED = 0;
95 public static final int TOUCHSCREEN_NOTOUCH = 1;
96 public static final int TOUCHSCREEN_STYLUS = 2;
97 public static final int TOUCHSCREEN_FINGER = 3;
98
99 /**
100 * The kind of touch screen attached to the device.
101 * One of: {@link #TOUCHSCREEN_NOTOUCH}, {@link #TOUCHSCREEN_STYLUS},
102 * {@link #TOUCHSCREEN_FINGER}.
103 */
104 public int touchscreen;
105
106 public static final int KEYBOARD_UNDEFINED = 0;
107 public static final int KEYBOARD_NOKEYS = 1;
108 public static final int KEYBOARD_QWERTY = 2;
109 public static final int KEYBOARD_12KEY = 3;
110
111 /**
112 * The kind of keyboard attached to the device.
Kenny Root507f8ed2009-06-09 11:21:11 -0500113 * One of: {@link #KEYBOARD_NOKEYS}, {@link #KEYBOARD_QWERTY},
114 * {@link #KEYBOARD_12KEY}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 */
116 public int keyboard;
117
118 public static final int KEYBOARDHIDDEN_UNDEFINED = 0;
119 public static final int KEYBOARDHIDDEN_NO = 1;
120 public static final int KEYBOARDHIDDEN_YES = 2;
121 /** Constant matching actual resource implementation. {@hide} */
122 public static final int KEYBOARDHIDDEN_SOFT = 3;
123
124 /**
125 * A flag indicating whether any keyboard is available. Unlike
126 * {@link #hardKeyboardHidden}, this also takes into account a soft
127 * keyboard, so if the hard keyboard is hidden but there is soft
128 * keyboard available, it will be set to NO. Value is one of:
129 * {@link #KEYBOARDHIDDEN_NO}, {@link #KEYBOARDHIDDEN_YES}.
130 */
131 public int keyboardHidden;
132
133 public static final int HARDKEYBOARDHIDDEN_UNDEFINED = 0;
134 public static final int HARDKEYBOARDHIDDEN_NO = 1;
135 public static final int HARDKEYBOARDHIDDEN_YES = 2;
136
137 /**
138 * A flag indicating whether the hard keyboard has been hidden. This will
139 * be set on a device with a mechanism to hide the keyboard from the
140 * user, when that mechanism is closed. One of:
141 * {@link #HARDKEYBOARDHIDDEN_NO}, {@link #HARDKEYBOARDHIDDEN_YES}.
142 */
143 public int hardKeyboardHidden;
144
145 public static final int NAVIGATION_UNDEFINED = 0;
146 public static final int NAVIGATION_NONAV = 1;
147 public static final int NAVIGATION_DPAD = 2;
148 public static final int NAVIGATION_TRACKBALL = 3;
149 public static final int NAVIGATION_WHEEL = 4;
150
151 /**
152 * The kind of navigation method available on the device.
Kenny Root507f8ed2009-06-09 11:21:11 -0500153 * One of: {@link #NAVIGATION_NONAV}, {@link #NAVIGATION_DPAD},
154 * {@link #NAVIGATION_TRACKBALL}, {@link #NAVIGATION_WHEEL}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 */
156 public int navigation;
157
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700158 public static final int NAVIGATIONHIDDEN_UNDEFINED = 0;
159 public static final int NAVIGATIONHIDDEN_NO = 1;
160 public static final int NAVIGATIONHIDDEN_YES = 2;
161
162 /**
163 * A flag indicating whether any 5-way or DPAD navigation available.
164 * This will be set on a device with a mechanism to hide the navigation
165 * controls from the user, when that mechanism is closed. One of:
166 * {@link #NAVIGATIONHIDDEN_NO}, {@link #NAVIGATIONHIDDEN_YES}.
167 */
168 public int navigationHidden;
169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 public static final int ORIENTATION_UNDEFINED = 0;
171 public static final int ORIENTATION_PORTRAIT = 1;
172 public static final int ORIENTATION_LANDSCAPE = 2;
173 public static final int ORIENTATION_SQUARE = 3;
174
175 /**
176 * Overall orientation of the screen. May be one of
177 * {@link #ORIENTATION_LANDSCAPE}, {@link #ORIENTATION_PORTRAIT},
178 * or {@link #ORIENTATION_SQUARE}.
179 */
180 public int orientation;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100181
Tobias Haamel27b28b32010-02-09 23:09:17 +0100182 public static final int UI_MODE_TYPE_MASK = 0x0f;
Dianne Hackbornef05e072010-03-01 17:43:39 -0800183 public static final int UI_MODE_TYPE_UNDEFINED = 0x00;
184 public static final int UI_MODE_TYPE_NORMAL = 0x01;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800185 public static final int UI_MODE_TYPE_DESK = 0x02;
186 public static final int UI_MODE_TYPE_CAR = 0x03;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100187
Tobias Haamel27b28b32010-02-09 23:09:17 +0100188 public static final int UI_MODE_NIGHT_MASK = 0x30;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100189 public static final int UI_MODE_NIGHT_UNDEFINED = 0x00;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100190 public static final int UI_MODE_NIGHT_NO = 0x10;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100191 public static final int UI_MODE_NIGHT_YES = 0x20;
192
193 /**
194 * Bit mask of the ui mode. Currently there are two fields:
195 * <p>The {@link #UI_MODE_TYPE_MASK} bits define the overall ui mode of the
Dianne Hackborn7299c412010-03-04 18:41:49 -0800196 * device. They may be one of {@link #UI_MODE_TYPE_UNDEFINED},
197 * {@link #UI_MODE_TYPE_NORMAL}, {@link #UI_MODE_TYPE_DESK},
198 * or {@link #UI_MODE_TYPE_CAR}.
Tobias Haamel27b28b32010-02-09 23:09:17 +0100199 *
200 * <p>The {@link #UI_MODE_NIGHT_MASK} defines whether the screen
Dianne Hackborn7299c412010-03-04 18:41:49 -0800201 * is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED},
Tobias Haamel27b28b32010-02-09 23:09:17 +0100202 * {@link #UI_MODE_NIGHT_NO} or {@link #UI_MODE_NIGHT_YES}.
Tobias Haamel27b28b32010-02-09 23:09:17 +0100203 */
204 public int uiMode;
205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 /**
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800207 * @hide Internal book-keeping.
208 */
209 public int seq;
210
211 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 * Construct an invalid Configuration. You must call {@link #setToDefaults}
213 * for this object to be valid. {@more}
214 */
215 public Configuration() {
216 setToDefaults();
217 }
218
219 /**
220 * Makes a deep copy suitable for modification.
221 */
222 public Configuration(Configuration o) {
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700223 setTo(o);
224 }
225
226 public void setTo(Configuration o) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 fontScale = o.fontScale;
228 mcc = o.mcc;
229 mnc = o.mnc;
230 if (o.locale != null) {
231 locale = (Locale) o.locale.clone();
232 }
233 userSetLocale = o.userSetLocale;
234 touchscreen = o.touchscreen;
235 keyboard = o.keyboard;
236 keyboardHidden = o.keyboardHidden;
237 hardKeyboardHidden = o.hardKeyboardHidden;
238 navigation = o.navigation;
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700239 navigationHidden = o.navigationHidden;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 orientation = o.orientation;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700241 screenLayout = o.screenLayout;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100242 uiMode = o.uiMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800243 seq = o.seq;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700247 StringBuilder sb = new StringBuilder(128);
248 sb.append("{ scale=");
249 sb.append(fontScale);
250 sb.append(" imsi=");
251 sb.append(mcc);
252 sb.append("/");
253 sb.append(mnc);
254 sb.append(" loc=");
255 sb.append(locale);
256 sb.append(" touch=");
257 sb.append(touchscreen);
258 sb.append(" keys=");
259 sb.append(keyboard);
260 sb.append("/");
261 sb.append(keyboardHidden);
262 sb.append("/");
263 sb.append(hardKeyboardHidden);
264 sb.append(" nav=");
265 sb.append(navigation);
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700266 sb.append("/");
267 sb.append(navigationHidden);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700268 sb.append(" orien=");
Daniel Sandler7d6bddc2010-07-22 16:11:55 -0400269 switch(orientation) {
270 case ORIENTATION_LANDSCAPE:
271 sb.append("L"); break;
272 case ORIENTATION_PORTRAIT:
273 sb.append("P"); break;
274 default:
275 sb.append(orientation);
276 }
277 sb.append(" layout=0x");
278 sb.append(java.lang.Integer.toHexString(screenLayout));
279 sb.append(" uiMode=0x");
280 sb.append(java.lang.Integer.toHexString(uiMode));
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800281 if (seq != 0) {
282 sb.append(" seq=");
283 sb.append(seq);
284 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700285 sb.append('}');
286 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 }
288
289 /**
290 * Set this object to the system defaults.
291 */
292 public void setToDefaults() {
293 fontScale = 1;
294 mcc = mnc = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800295 locale = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 userSetLocale = false;
297 touchscreen = TOUCHSCREEN_UNDEFINED;
298 keyboard = KEYBOARD_UNDEFINED;
299 keyboardHidden = KEYBOARDHIDDEN_UNDEFINED;
300 hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED;
301 navigation = NAVIGATION_UNDEFINED;
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700302 navigationHidden = NAVIGATIONHIDDEN_UNDEFINED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 orientation = ORIENTATION_UNDEFINED;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700304 screenLayout = SCREENLAYOUT_SIZE_UNDEFINED;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800305 uiMode = UI_MODE_TYPE_UNDEFINED;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800306 seq = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 }
308
309 /** {@hide} */
310 @Deprecated public void makeDefault() {
311 setToDefaults();
312 }
313
314 /**
315 * Copy the fields from delta into this Configuration object, keeping
316 * track of which ones have changed. Any undefined fields in
317 * <var>delta</var> are ignored and not copied in to the current
318 * Configuration.
319 * @return Returns a bit mask of the changed fields, as per
320 * {@link #diff}.
321 */
322 public int updateFrom(Configuration delta) {
323 int changed = 0;
324 if (delta.fontScale > 0 && fontScale != delta.fontScale) {
325 changed |= ActivityInfo.CONFIG_FONT_SCALE;
326 fontScale = delta.fontScale;
327 }
328 if (delta.mcc != 0 && mcc != delta.mcc) {
329 changed |= ActivityInfo.CONFIG_MCC;
330 mcc = delta.mcc;
331 }
332 if (delta.mnc != 0 && mnc != delta.mnc) {
333 changed |= ActivityInfo.CONFIG_MNC;
334 mnc = delta.mnc;
335 }
336 if (delta.locale != null
337 && (locale == null || !locale.equals(delta.locale))) {
338 changed |= ActivityInfo.CONFIG_LOCALE;
339 locale = delta.locale != null
340 ? (Locale) delta.locale.clone() : null;
341 }
342 if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0)))
343 {
344 userSetLocale = true;
345 changed |= ActivityInfo.CONFIG_LOCALE;
346 }
347 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
348 && touchscreen != delta.touchscreen) {
349 changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
350 touchscreen = delta.touchscreen;
351 }
352 if (delta.keyboard != KEYBOARD_UNDEFINED
353 && keyboard != delta.keyboard) {
354 changed |= ActivityInfo.CONFIG_KEYBOARD;
355 keyboard = delta.keyboard;
356 }
357 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED
358 && keyboardHidden != delta.keyboardHidden) {
359 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
360 keyboardHidden = delta.keyboardHidden;
361 }
362 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED
363 && hardKeyboardHidden != delta.hardKeyboardHidden) {
364 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
365 hardKeyboardHidden = delta.hardKeyboardHidden;
366 }
367 if (delta.navigation != NAVIGATION_UNDEFINED
368 && navigation != delta.navigation) {
369 changed |= ActivityInfo.CONFIG_NAVIGATION;
370 navigation = delta.navigation;
371 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700372 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
373 && navigationHidden != delta.navigationHidden) {
374 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
375 navigationHidden = delta.navigationHidden;
376 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 if (delta.orientation != ORIENTATION_UNDEFINED
378 && orientation != delta.orientation) {
379 changed |= ActivityInfo.CONFIG_ORIENTATION;
380 orientation = delta.orientation;
381 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700382 if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED
Dianne Hackborn723738c2009-06-25 19:48:04 -0700383 && screenLayout != delta.screenLayout) {
384 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
385 screenLayout = delta.screenLayout;
386 }
Dianne Hackborn7299c412010-03-04 18:41:49 -0800387 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)
Tobias Haamel27b28b32010-02-09 23:09:17 +0100388 && uiMode != delta.uiMode) {
389 changed |= ActivityInfo.CONFIG_UI_MODE;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800390 if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) {
391 uiMode = (uiMode&~UI_MODE_TYPE_MASK)
392 | (delta.uiMode&UI_MODE_TYPE_MASK);
393 }
394 if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) {
395 uiMode = (uiMode&~UI_MODE_NIGHT_MASK)
396 | (delta.uiMode&UI_MODE_NIGHT_MASK);
397 }
Tobias Haamel27b28b32010-02-09 23:09:17 +0100398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800400 if (delta.seq != 0) {
401 seq = delta.seq;
402 }
403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 return changed;
405 }
406
407 /**
408 * Return a bit mask of the differences between this Configuration
409 * object and the given one. Does not change the values of either. Any
410 * undefined fields in <var>delta</var> are ignored.
411 * @return Returns a bit mask indicating which configuration
412 * values has changed, containing any combination of
413 * {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE
414 * PackageManager.ActivityInfo.CONFIG_FONT_SCALE},
415 * {@link android.content.pm.ActivityInfo#CONFIG_MCC
416 * PackageManager.ActivityInfo.CONFIG_MCC},
417 * {@link android.content.pm.ActivityInfo#CONFIG_MNC
418 * PackageManager.ActivityInfo.CONFIG_MNC},
419 * {@link android.content.pm.ActivityInfo#CONFIG_LOCALE
420 * PackageManager.ActivityInfo.CONFIG_LOCALE},
421 * {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN
422 * PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN},
423 * {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD
424 * PackageManager.ActivityInfo.CONFIG_KEYBOARD},
425 * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION
Dianne Hackborn723738c2009-06-25 19:48:04 -0700426 * PackageManager.ActivityInfo.CONFIG_NAVIGATION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION
Dianne Hackborn723738c2009-06-25 19:48:04 -0700428 * PackageManager.ActivityInfo.CONFIG_ORIENTATION}, or
429 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT
430 * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 */
432 public int diff(Configuration delta) {
433 int changed = 0;
434 if (delta.fontScale > 0 && fontScale != delta.fontScale) {
435 changed |= ActivityInfo.CONFIG_FONT_SCALE;
436 }
437 if (delta.mcc != 0 && mcc != delta.mcc) {
438 changed |= ActivityInfo.CONFIG_MCC;
439 }
440 if (delta.mnc != 0 && mnc != delta.mnc) {
441 changed |= ActivityInfo.CONFIG_MNC;
442 }
443 if (delta.locale != null
444 && (locale == null || !locale.equals(delta.locale))) {
445 changed |= ActivityInfo.CONFIG_LOCALE;
446 }
447 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
448 && touchscreen != delta.touchscreen) {
449 changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
450 }
451 if (delta.keyboard != KEYBOARD_UNDEFINED
452 && keyboard != delta.keyboard) {
453 changed |= ActivityInfo.CONFIG_KEYBOARD;
454 }
455 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED
456 && keyboardHidden != delta.keyboardHidden) {
457 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
458 }
459 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED
460 && hardKeyboardHidden != delta.hardKeyboardHidden) {
461 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
462 }
463 if (delta.navigation != NAVIGATION_UNDEFINED
464 && navigation != delta.navigation) {
465 changed |= ActivityInfo.CONFIG_NAVIGATION;
466 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700467 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
468 && navigationHidden != delta.navigationHidden) {
469 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
470 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 if (delta.orientation != ORIENTATION_UNDEFINED
472 && orientation != delta.orientation) {
473 changed |= ActivityInfo.CONFIG_ORIENTATION;
474 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700475 if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED
Dianne Hackborn723738c2009-06-25 19:48:04 -0700476 && screenLayout != delta.screenLayout) {
477 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
478 }
Dianne Hackborn7299c412010-03-04 18:41:49 -0800479 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)
Tobias Haamel27b28b32010-02-09 23:09:17 +0100480 && uiMode != delta.uiMode) {
481 changed |= ActivityInfo.CONFIG_UI_MODE;
482 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483
484 return changed;
485 }
486
487 /**
488 * Determine if a new resource needs to be loaded from the bit set of
489 * configuration changes returned by {@link #updateFrom(Configuration)}.
490 *
491 * @param configChanges The mask of changes configurations as returned by
492 * {@link #updateFrom(Configuration)}.
493 * @param interestingChanges The configuration changes that the resource
494 * can handled, as given in {@link android.util.TypedValue#changingConfigurations}.
495 *
496 * @return Return true if the resource needs to be loaded, else false.
497 */
498 public static boolean needNewResources(int configChanges, int interestingChanges) {
499 return (configChanges & (interestingChanges|ActivityInfo.CONFIG_FONT_SCALE)) != 0;
500 }
501
502 /**
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800503 * @hide Return true if the sequence of 'other' is better than this. Assumes
504 * that 'this' is your current sequence and 'other' is a new one you have
505 * received some how and want to compare with what you have.
506 */
507 public boolean isOtherSeqNewer(Configuration other) {
508 if (other == null) {
509 // Sanity check.
510 return false;
511 }
512 if (other.seq == 0) {
513 // If the other sequence is not specified, then we must assume
514 // it is newer since we don't know any better.
515 return true;
516 }
517 if (seq == 0) {
518 // If this sequence is not specified, then we also consider the
519 // other is better. Yes we have a preference for other. Sue us.
520 return true;
521 }
522 int diff = other.seq - seq;
523 if (diff > 0x10000) {
524 // If there has been a sufficiently large jump, assume the
525 // sequence has wrapped around.
526 return false;
527 }
528 return diff > 0;
529 }
530
531 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 * Parcelable methods
533 */
534 public int describeContents() {
535 return 0;
536 }
537
538 public void writeToParcel(Parcel dest, int flags) {
539 dest.writeFloat(fontScale);
540 dest.writeInt(mcc);
541 dest.writeInt(mnc);
542 if (locale == null) {
543 dest.writeInt(0);
544 } else {
545 dest.writeInt(1);
546 dest.writeString(locale.getLanguage());
547 dest.writeString(locale.getCountry());
548 dest.writeString(locale.getVariant());
549 }
550 if(userSetLocale) {
551 dest.writeInt(1);
552 } else {
553 dest.writeInt(0);
554 }
555 dest.writeInt(touchscreen);
556 dest.writeInt(keyboard);
557 dest.writeInt(keyboardHidden);
558 dest.writeInt(hardKeyboardHidden);
559 dest.writeInt(navigation);
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700560 dest.writeInt(navigationHidden);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 dest.writeInt(orientation);
Dianne Hackborn723738c2009-06-25 19:48:04 -0700562 dest.writeInt(screenLayout);
Tobias Haamel27b28b32010-02-09 23:09:17 +0100563 dest.writeInt(uiMode);
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800564 dest.writeInt(seq);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 }
566
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700567 public void readFromParcel(Parcel source) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 fontScale = source.readFloat();
569 mcc = source.readInt();
570 mnc = source.readInt();
571 if (source.readInt() != 0) {
572 locale = new Locale(source.readString(), source.readString(),
573 source.readString());
574 }
575 userSetLocale = (source.readInt()==1);
576 touchscreen = source.readInt();
577 keyboard = source.readInt();
578 keyboardHidden = source.readInt();
579 hardKeyboardHidden = source.readInt();
580 navigation = source.readInt();
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700581 navigationHidden = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 orientation = source.readInt();
Dianne Hackborn723738c2009-06-25 19:48:04 -0700583 screenLayout = source.readInt();
Tobias Haamel27b28b32010-02-09 23:09:17 +0100584 uiMode = source.readInt();
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800585 seq = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700587
588 public static final Parcelable.Creator<Configuration> CREATOR
589 = new Parcelable.Creator<Configuration>() {
590 public Configuration createFromParcel(Parcel source) {
591 return new Configuration(source);
592 }
593
594 public Configuration[] newArray(int size) {
595 return new Configuration[size];
596 }
597 };
598
599 /**
600 * Construct this Configuration object, reading from the Parcel.
601 */
602 private Configuration(Parcel source) {
603 readFromParcel(source);
604 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605
606 public int compareTo(Configuration that) {
607 int n;
608 float a = this.fontScale;
609 float b = that.fontScale;
610 if (a < b) return -1;
611 if (a > b) return 1;
612 n = this.mcc - that.mcc;
613 if (n != 0) return n;
614 n = this.mnc - that.mnc;
615 if (n != 0) return n;
Dianne Hackborna8397032010-03-12 10:52:22 -0800616 if (this.locale == null) {
617 if (that.locale != null) return 1;
618 } else if (that.locale == null) {
619 return -1;
620 } else {
621 n = this.locale.getLanguage().compareTo(that.locale.getLanguage());
622 if (n != 0) return n;
623 n = this.locale.getCountry().compareTo(that.locale.getCountry());
624 if (n != 0) return n;
625 n = this.locale.getVariant().compareTo(that.locale.getVariant());
626 if (n != 0) return n;
627 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 n = this.touchscreen - that.touchscreen;
629 if (n != 0) return n;
630 n = this.keyboard - that.keyboard;
631 if (n != 0) return n;
632 n = this.keyboardHidden - that.keyboardHidden;
633 if (n != 0) return n;
634 n = this.hardKeyboardHidden - that.hardKeyboardHidden;
635 if (n != 0) return n;
636 n = this.navigation - that.navigation;
637 if (n != 0) return n;
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700638 n = this.navigationHidden - that.navigationHidden;
639 if (n != 0) return n;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 n = this.orientation - that.orientation;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700641 if (n != 0) return n;
642 n = this.screenLayout - that.screenLayout;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100643 if (n != 0) return n;
644 n = this.uiMode - that.uiMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 //if (n != 0) return n;
646 return n;
647 }
648
649 public boolean equals(Configuration that) {
650 if (that == null) return false;
651 if (that == this) return true;
652 return this.compareTo(that) == 0;
653 }
654
655 public boolean equals(Object that) {
656 try {
657 return equals((Configuration)that);
658 } catch (ClassCastException e) {
659 }
660 return false;
661 }
662
663 public int hashCode() {
664 return ((int)this.fontScale) + this.mcc + this.mnc
Dianne Hackborna8397032010-03-12 10:52:22 -0800665 + (this.locale != null ? this.locale.hashCode() : 0)
666 + this.touchscreen
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 + this.keyboard + this.keyboardHidden + this.hardKeyboardHidden
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700668 + this.navigation + this.navigationHidden
Tobias Haamel27b28b32010-02-09 23:09:17 +0100669 + this.orientation + this.screenLayout + this.uiMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 }
671}