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