Configuration.java revision 5383f502e4479d117c89666fb2ee1ca53f3d27cf
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.res;
18
19import android.content.pm.ActivityInfo;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23import java.util.Locale;
24
25/**
26 * This class describes all device configuration information that can
27 * impact the resources the application retrieves.  This includes both
28 * user-specified configuration options (locale and scaling) as well
29 * as dynamic device configuration (various types of input devices).
30 */
31public final class Configuration implements Parcelable, Comparable<Configuration> {
32    /**
33     * Current user preference for the scaling factor for fonts, relative
34     * to the base density scaling.
35     */
36    public float fontScale;
37
38    /**
39     * IMSI MCC (Mobile Country Code).  0 if undefined.
40     */
41    public int mcc;
42
43    /**
44     * IMSI MNC (Mobile Network Code).  0 if undefined.
45     */
46    public int mnc;
47
48    /**
49     * Current user preference for the locale.
50     */
51    public Locale locale;
52
53    /**
54     * Locale should persist on setting.  This is hidden because it is really
55     * questionable whether this is the right way to expose the functionality.
56     * @hide
57     */
58    public boolean userSetLocale;
59
60    public static final int SCREENLAYOUT_SIZE_MASK = 0x0f;
61    public static final int SCREENLAYOUT_SIZE_UNDEFINED = 0x00;
62    public static final int SCREENLAYOUT_SIZE_SMALL = 0x01;
63    public static final int SCREENLAYOUT_SIZE_NORMAL = 0x02;
64    public static final int SCREENLAYOUT_SIZE_LARGE = 0x03;
65    public static final int SCREENLAYOUT_SIZE_XLARGE = 0x04;
66
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},
86     * {@link #SCREENLAYOUT_SIZE_LARGE}.
87     *
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
94    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.
113     * One of: {@link #KEYBOARD_NOKEYS}, {@link #KEYBOARD_QWERTY},
114     * {@link #KEYBOARD_12KEY}.
115     */
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.
153     * One of: {@link #NAVIGATION_NONAV}, {@link #NAVIGATION_DPAD},
154     * {@link #NAVIGATION_TRACKBALL}, {@link #NAVIGATION_WHEEL}.
155     */
156    public int navigation;
157
158    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
170    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;
181
182    public static final int UI_MODE_TYPE_MASK = 0x0f;
183    public static final int UI_MODE_TYPE_UNDEFINED = 0x00;
184    public static final int UI_MODE_TYPE_NORMAL = 0x01;
185    public static final int UI_MODE_TYPE_DESK = 0x02;
186    public static final int UI_MODE_TYPE_CAR = 0x03;
187
188    public static final int UI_MODE_NIGHT_MASK = 0x30;
189    public static final int UI_MODE_NIGHT_UNDEFINED = 0x00;
190    public static final int UI_MODE_NIGHT_NO = 0x10;
191    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
196     * 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}.
199     *
200     * <p>The {@link #UI_MODE_NIGHT_MASK} defines whether the screen
201     * is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED},
202     * {@link #UI_MODE_NIGHT_NO} or {@link #UI_MODE_NIGHT_YES}.
203     */
204    public int uiMode;
205
206    /**
207     * @hide Internal book-keeping.
208     */
209    public int seq;
210
211    /**
212     * 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) {
223        setTo(o);
224    }
225
226    public void setTo(Configuration o) {
227        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;
239        navigationHidden = o.navigationHidden;
240        orientation = o.orientation;
241        screenLayout = o.screenLayout;
242        uiMode = o.uiMode;
243        seq = o.seq;
244    }
245
246    public String toString() {
247        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);
266        sb.append("/");
267        sb.append(navigationHidden);
268        sb.append(" orien=");
269        sb.append(orientation);
270        sb.append(" layout=");
271        sb.append(screenLayout);
272        sb.append(" uiMode=");
273        sb.append(uiMode);
274        if (seq != 0) {
275            sb.append(" seq=");
276            sb.append(seq);
277        }
278        sb.append('}');
279        return sb.toString();
280    }
281
282    /**
283     * Set this object to the system defaults.
284     */
285    public void setToDefaults() {
286        fontScale = 1;
287        mcc = mnc = 0;
288        locale = null;
289        userSetLocale = false;
290        touchscreen = TOUCHSCREEN_UNDEFINED;
291        keyboard = KEYBOARD_UNDEFINED;
292        keyboardHidden = KEYBOARDHIDDEN_UNDEFINED;
293        hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED;
294        navigation = NAVIGATION_UNDEFINED;
295        navigationHidden = NAVIGATIONHIDDEN_UNDEFINED;
296        orientation = ORIENTATION_UNDEFINED;
297        screenLayout = SCREENLAYOUT_SIZE_UNDEFINED;
298        uiMode = UI_MODE_TYPE_UNDEFINED;
299        seq = 0;
300    }
301
302    /** {@hide} */
303    @Deprecated public void makeDefault() {
304        setToDefaults();
305    }
306
307    /**
308     * Copy the fields from delta into this Configuration object, keeping
309     * track of which ones have changed.  Any undefined fields in
310     * <var>delta</var> are ignored and not copied in to the current
311     * Configuration.
312     * @return Returns a bit mask of the changed fields, as per
313     * {@link #diff}.
314     */
315    public int updateFrom(Configuration delta) {
316        int changed = 0;
317        if (delta.fontScale > 0 && fontScale != delta.fontScale) {
318            changed |= ActivityInfo.CONFIG_FONT_SCALE;
319            fontScale = delta.fontScale;
320        }
321        if (delta.mcc != 0 && mcc != delta.mcc) {
322            changed |= ActivityInfo.CONFIG_MCC;
323            mcc = delta.mcc;
324        }
325        if (delta.mnc != 0 && mnc != delta.mnc) {
326            changed |= ActivityInfo.CONFIG_MNC;
327            mnc = delta.mnc;
328        }
329        if (delta.locale != null
330                && (locale == null || !locale.equals(delta.locale))) {
331            changed |= ActivityInfo.CONFIG_LOCALE;
332            locale = delta.locale != null
333                    ? (Locale) delta.locale.clone() : null;
334        }
335        if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0)))
336        {
337            userSetLocale = true;
338            changed |= ActivityInfo.CONFIG_LOCALE;
339        }
340        if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
341                && touchscreen != delta.touchscreen) {
342            changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
343            touchscreen = delta.touchscreen;
344        }
345        if (delta.keyboard != KEYBOARD_UNDEFINED
346                && keyboard != delta.keyboard) {
347            changed |= ActivityInfo.CONFIG_KEYBOARD;
348            keyboard = delta.keyboard;
349        }
350        if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED
351                && keyboardHidden != delta.keyboardHidden) {
352            changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
353            keyboardHidden = delta.keyboardHidden;
354        }
355        if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED
356                && hardKeyboardHidden != delta.hardKeyboardHidden) {
357            changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
358            hardKeyboardHidden = delta.hardKeyboardHidden;
359        }
360        if (delta.navigation != NAVIGATION_UNDEFINED
361                && navigation != delta.navigation) {
362            changed |= ActivityInfo.CONFIG_NAVIGATION;
363            navigation = delta.navigation;
364        }
365        if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
366                && navigationHidden != delta.navigationHidden) {
367            changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
368            navigationHidden = delta.navigationHidden;
369        }
370        if (delta.orientation != ORIENTATION_UNDEFINED
371                && orientation != delta.orientation) {
372            changed |= ActivityInfo.CONFIG_ORIENTATION;
373            orientation = delta.orientation;
374        }
375        if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED
376                && screenLayout != delta.screenLayout) {
377            changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
378            screenLayout = delta.screenLayout;
379        }
380        if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)
381                && uiMode != delta.uiMode) {
382            changed |= ActivityInfo.CONFIG_UI_MODE;
383            if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) {
384                uiMode = (uiMode&~UI_MODE_TYPE_MASK)
385                        | (delta.uiMode&UI_MODE_TYPE_MASK);
386            }
387            if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) {
388                uiMode = (uiMode&~UI_MODE_NIGHT_MASK)
389                        | (delta.uiMode&UI_MODE_NIGHT_MASK);
390            }
391        }
392
393        if (delta.seq != 0) {
394            seq = delta.seq;
395        }
396
397        return changed;
398    }
399
400    /**
401     * Return a bit mask of the differences between this Configuration
402     * object and the given one.  Does not change the values of either.  Any
403     * undefined fields in <var>delta</var> are ignored.
404     * @return Returns a bit mask indicating which configuration
405     * values has changed, containing any combination of
406     * {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE
407     * PackageManager.ActivityInfo.CONFIG_FONT_SCALE},
408     * {@link android.content.pm.ActivityInfo#CONFIG_MCC
409     * PackageManager.ActivityInfo.CONFIG_MCC},
410     * {@link android.content.pm.ActivityInfo#CONFIG_MNC
411     * PackageManager.ActivityInfo.CONFIG_MNC},
412     * {@link android.content.pm.ActivityInfo#CONFIG_LOCALE
413     * PackageManager.ActivityInfo.CONFIG_LOCALE},
414     * {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN
415     * PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN},
416     * {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD
417     * PackageManager.ActivityInfo.CONFIG_KEYBOARD},
418     * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION
419     * PackageManager.ActivityInfo.CONFIG_NAVIGATION},
420     * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION
421     * PackageManager.ActivityInfo.CONFIG_ORIENTATION}, or
422     * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT
423     * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}.
424     */
425    public int diff(Configuration delta) {
426        int changed = 0;
427        if (delta.fontScale > 0 && fontScale != delta.fontScale) {
428            changed |= ActivityInfo.CONFIG_FONT_SCALE;
429        }
430        if (delta.mcc != 0 && mcc != delta.mcc) {
431            changed |= ActivityInfo.CONFIG_MCC;
432        }
433        if (delta.mnc != 0 && mnc != delta.mnc) {
434            changed |= ActivityInfo.CONFIG_MNC;
435        }
436        if (delta.locale != null
437                && (locale == null || !locale.equals(delta.locale))) {
438            changed |= ActivityInfo.CONFIG_LOCALE;
439        }
440        if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
441                && touchscreen != delta.touchscreen) {
442            changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
443        }
444        if (delta.keyboard != KEYBOARD_UNDEFINED
445                && keyboard != delta.keyboard) {
446            changed |= ActivityInfo.CONFIG_KEYBOARD;
447        }
448        if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED
449                && keyboardHidden != delta.keyboardHidden) {
450            changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
451        }
452        if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED
453                && hardKeyboardHidden != delta.hardKeyboardHidden) {
454            changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
455        }
456        if (delta.navigation != NAVIGATION_UNDEFINED
457                && navigation != delta.navigation) {
458            changed |= ActivityInfo.CONFIG_NAVIGATION;
459        }
460        if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
461                && navigationHidden != delta.navigationHidden) {
462            changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
463        }
464        if (delta.orientation != ORIENTATION_UNDEFINED
465                && orientation != delta.orientation) {
466            changed |= ActivityInfo.CONFIG_ORIENTATION;
467        }
468        if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED
469                && screenLayout != delta.screenLayout) {
470            changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
471        }
472        if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)
473                && uiMode != delta.uiMode) {
474            changed |= ActivityInfo.CONFIG_UI_MODE;
475        }
476
477        return changed;
478    }
479
480    /**
481     * Determine if a new resource needs to be loaded from the bit set of
482     * configuration changes returned by {@link #updateFrom(Configuration)}.
483     *
484     * @param configChanges The mask of changes configurations as returned by
485     * {@link #updateFrom(Configuration)}.
486     * @param interestingChanges The configuration changes that the resource
487     * can handled, as given in {@link android.util.TypedValue#changingConfigurations}.
488     *
489     * @return Return true if the resource needs to be loaded, else false.
490     */
491    public static boolean needNewResources(int configChanges, int interestingChanges) {
492        return (configChanges & (interestingChanges|ActivityInfo.CONFIG_FONT_SCALE)) != 0;
493    }
494
495    /**
496     * @hide Return true if the sequence of 'other' is better than this.  Assumes
497     * that 'this' is your current sequence and 'other' is a new one you have
498     * received some how and want to compare with what you have.
499     */
500    public boolean isOtherSeqNewer(Configuration other) {
501        if (other == null) {
502            // Sanity check.
503            return false;
504        }
505        if (other.seq == 0) {
506            // If the other sequence is not specified, then we must assume
507            // it is newer since we don't know any better.
508            return true;
509        }
510        if (seq == 0) {
511            // If this sequence is not specified, then we also consider the
512            // other is better.  Yes we have a preference for other.  Sue us.
513            return true;
514        }
515        int diff = other.seq - seq;
516        if (diff > 0x10000) {
517            // If there has been a sufficiently large jump, assume the
518            // sequence has wrapped around.
519            return false;
520        }
521        return diff > 0;
522    }
523
524    /**
525     * Parcelable methods
526     */
527    public int describeContents() {
528        return 0;
529    }
530
531    public void writeToParcel(Parcel dest, int flags) {
532        dest.writeFloat(fontScale);
533        dest.writeInt(mcc);
534        dest.writeInt(mnc);
535        if (locale == null) {
536            dest.writeInt(0);
537        } else {
538            dest.writeInt(1);
539            dest.writeString(locale.getLanguage());
540            dest.writeString(locale.getCountry());
541            dest.writeString(locale.getVariant());
542        }
543        if(userSetLocale) {
544            dest.writeInt(1);
545        } else {
546            dest.writeInt(0);
547        }
548        dest.writeInt(touchscreen);
549        dest.writeInt(keyboard);
550        dest.writeInt(keyboardHidden);
551        dest.writeInt(hardKeyboardHidden);
552        dest.writeInt(navigation);
553        dest.writeInt(navigationHidden);
554        dest.writeInt(orientation);
555        dest.writeInt(screenLayout);
556        dest.writeInt(uiMode);
557        dest.writeInt(seq);
558    }
559
560    public void readFromParcel(Parcel source) {
561        fontScale = source.readFloat();
562        mcc = source.readInt();
563        mnc = source.readInt();
564        if (source.readInt() != 0) {
565            locale = new Locale(source.readString(), source.readString(),
566                    source.readString());
567        }
568        userSetLocale = (source.readInt()==1);
569        touchscreen = source.readInt();
570        keyboard = source.readInt();
571        keyboardHidden = source.readInt();
572        hardKeyboardHidden = source.readInt();
573        navigation = source.readInt();
574        navigationHidden = source.readInt();
575        orientation = source.readInt();
576        screenLayout = source.readInt();
577        uiMode = source.readInt();
578        seq = source.readInt();
579    }
580
581    public static final Parcelable.Creator<Configuration> CREATOR
582            = new Parcelable.Creator<Configuration>() {
583        public Configuration createFromParcel(Parcel source) {
584            return new Configuration(source);
585        }
586
587        public Configuration[] newArray(int size) {
588            return new Configuration[size];
589        }
590    };
591
592    /**
593     * Construct this Configuration object, reading from the Parcel.
594     */
595    private Configuration(Parcel source) {
596        readFromParcel(source);
597    }
598
599    public int compareTo(Configuration that) {
600        int n;
601        float a = this.fontScale;
602        float b = that.fontScale;
603        if (a < b) return -1;
604        if (a > b) return 1;
605        n = this.mcc - that.mcc;
606        if (n != 0) return n;
607        n = this.mnc - that.mnc;
608        if (n != 0) return n;
609        if (this.locale == null) {
610            if (that.locale != null) return 1;
611        } else if (that.locale == null) {
612            return -1;
613        } else {
614            n = this.locale.getLanguage().compareTo(that.locale.getLanguage());
615            if (n != 0) return n;
616            n = this.locale.getCountry().compareTo(that.locale.getCountry());
617            if (n != 0) return n;
618            n = this.locale.getVariant().compareTo(that.locale.getVariant());
619            if (n != 0) return n;
620        }
621        n = this.touchscreen - that.touchscreen;
622        if (n != 0) return n;
623        n = this.keyboard - that.keyboard;
624        if (n != 0) return n;
625        n = this.keyboardHidden - that.keyboardHidden;
626        if (n != 0) return n;
627        n = this.hardKeyboardHidden - that.hardKeyboardHidden;
628        if (n != 0) return n;
629        n = this.navigation - that.navigation;
630        if (n != 0) return n;
631        n = this.navigationHidden - that.navigationHidden;
632        if (n != 0) return n;
633        n = this.orientation - that.orientation;
634        if (n != 0) return n;
635        n = this.screenLayout - that.screenLayout;
636        if (n != 0) return n;
637        n = this.uiMode - that.uiMode;
638        //if (n != 0) return n;
639        return n;
640    }
641
642    public boolean equals(Configuration that) {
643        if (that == null) return false;
644        if (that == this) return true;
645        return this.compareTo(that) == 0;
646    }
647
648    public boolean equals(Object that) {
649        try {
650            return equals((Configuration)that);
651        } catch (ClassCastException e) {
652        }
653        return false;
654    }
655
656    public int hashCode() {
657        return ((int)this.fontScale) + this.mcc + this.mnc
658                + (this.locale != null ? this.locale.hashCode() : 0)
659                + this.touchscreen
660                + this.keyboard + this.keyboardHidden + this.hardKeyboardHidden
661                + this.navigation + this.navigationHidden
662                + this.orientation + this.screenLayout + this.uiMode;
663    }
664}
665