/* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.content.res; import android.content.pm.ActivityInfo; import android.os.Parcel; import android.os.Parcelable; import android.util.LocaleUtil; import java.util.Locale; /** * This class describes all device configuration information that can * impact the resources the application retrieves. This includes both * user-specified configuration options (locale and scaling) as well * as device configurations (such as input modes, screen size and screen orientation). *
You can acquire this object from {@link Resources}, using {@link * Resources#getConfiguration}. Thus, from an activity, you can get it by chaining the request * with {@link android.app.Activity#getResources}:
*Configuration config = getResources().getConfiguration();*/ public final class Configuration implements Parcelable, Comparable
The {@link #SCREENLAYOUT_SIZE_MASK} bits define the overall size * of the screen. They may be one of * {@link #SCREENLAYOUT_SIZE_SMALL}, {@link #SCREENLAYOUT_SIZE_NORMAL}, * {@link #SCREENLAYOUT_SIZE_LARGE}, or {@link #SCREENLAYOUT_SIZE_XLARGE}. * *
The {@link #SCREENLAYOUT_LONG_MASK} defines whether the screen * is wider/taller than normal. They may be one of * {@link #SCREENLAYOUT_LONG_NO} or {@link #SCREENLAYOUT_LONG_YES}. * *
See Supporting * Multiple Screens for more information. */ public int screenLayout; /** * Check if the Configuration's current {@link #screenLayout} is at * least the given size. * * @param size The desired size, either {@link #SCREENLAYOUT_SIZE_SMALL}, * {@link #SCREENLAYOUT_SIZE_NORMAL}, {@link #SCREENLAYOUT_SIZE_LARGE}, or * {@link #SCREENLAYOUT_SIZE_XLARGE}. * @return Returns true if the current screen layout size is at least * the given size. */ public boolean isLayoutSizeAtLeast(int size) { int cur = screenLayout&SCREENLAYOUT_SIZE_MASK; if (cur == SCREENLAYOUT_SIZE_UNDEFINED) return false; return cur >= size; } public static final int TOUCHSCREEN_UNDEFINED = 0; public static final int TOUCHSCREEN_NOTOUCH = 1; public static final int TOUCHSCREEN_STYLUS = 2; public static final int TOUCHSCREEN_FINGER = 3; /** * The kind of touch screen attached to the device. * One of: {@link #TOUCHSCREEN_NOTOUCH}, {@link #TOUCHSCREEN_STYLUS}, * {@link #TOUCHSCREEN_FINGER}. */ public int touchscreen; public static final int KEYBOARD_UNDEFINED = 0; public static final int KEYBOARD_NOKEYS = 1; public static final int KEYBOARD_QWERTY = 2; public static final int KEYBOARD_12KEY = 3; /** * The kind of keyboard attached to the device. * One of: {@link #KEYBOARD_NOKEYS}, {@link #KEYBOARD_QWERTY}, * {@link #KEYBOARD_12KEY}. */ public int keyboard; public static final int KEYBOARDHIDDEN_UNDEFINED = 0; public static final int KEYBOARDHIDDEN_NO = 1; public static final int KEYBOARDHIDDEN_YES = 2; /** Constant matching actual resource implementation. {@hide} */ public static final int KEYBOARDHIDDEN_SOFT = 3; /** * A flag indicating whether any keyboard is available. Unlike * {@link #hardKeyboardHidden}, this also takes into account a soft * keyboard, so if the hard keyboard is hidden but there is soft * keyboard available, it will be set to NO. Value is one of: * {@link #KEYBOARDHIDDEN_NO}, {@link #KEYBOARDHIDDEN_YES}. */ public int keyboardHidden; public static final int HARDKEYBOARDHIDDEN_UNDEFINED = 0; public static final int HARDKEYBOARDHIDDEN_NO = 1; public static final int HARDKEYBOARDHIDDEN_YES = 2; /** * A flag indicating whether the hard keyboard has been hidden. This will * be set on a device with a mechanism to hide the keyboard from the * user, when that mechanism is closed. One of: * {@link #HARDKEYBOARDHIDDEN_NO}, {@link #HARDKEYBOARDHIDDEN_YES}. */ public int hardKeyboardHidden; public static final int NAVIGATION_UNDEFINED = 0; public static final int NAVIGATION_NONAV = 1; public static final int NAVIGATION_DPAD = 2; public static final int NAVIGATION_TRACKBALL = 3; public static final int NAVIGATION_WHEEL = 4; /** * The kind of navigation method available on the device. * One of: {@link #NAVIGATION_NONAV}, {@link #NAVIGATION_DPAD}, * {@link #NAVIGATION_TRACKBALL}, {@link #NAVIGATION_WHEEL}. */ public int navigation; public static final int NAVIGATIONHIDDEN_UNDEFINED = 0; public static final int NAVIGATIONHIDDEN_NO = 1; public static final int NAVIGATIONHIDDEN_YES = 2; /** * A flag indicating whether any 5-way or DPAD navigation available. * This will be set on a device with a mechanism to hide the navigation * controls from the user, when that mechanism is closed. One of: * {@link #NAVIGATIONHIDDEN_NO}, {@link #NAVIGATIONHIDDEN_YES}. */ public int navigationHidden; public static final int ORIENTATION_UNDEFINED = 0; public static final int ORIENTATION_PORTRAIT = 1; public static final int ORIENTATION_LANDSCAPE = 2; public static final int ORIENTATION_SQUARE = 3; /** * Overall orientation of the screen. May be one of * {@link #ORIENTATION_LANDSCAPE}, {@link #ORIENTATION_PORTRAIT}, * or {@link #ORIENTATION_SQUARE}. */ public int orientation; public static final int UI_MODE_TYPE_MASK = 0x0f; public static final int UI_MODE_TYPE_UNDEFINED = 0x00; public static final int UI_MODE_TYPE_NORMAL = 0x01; public static final int UI_MODE_TYPE_DESK = 0x02; public static final int UI_MODE_TYPE_CAR = 0x03; public static final int UI_MODE_TYPE_TELEVISION = 0x04; public static final int UI_MODE_NIGHT_MASK = 0x30; public static final int UI_MODE_NIGHT_UNDEFINED = 0x00; public static final int UI_MODE_NIGHT_NO = 0x10; public static final int UI_MODE_NIGHT_YES = 0x20; /** * Bit mask of the ui mode. Currently there are two fields: *
The {@link #UI_MODE_TYPE_MASK} bits define the overall ui mode of the * device. They may be one of {@link #UI_MODE_TYPE_UNDEFINED}, * {@link #UI_MODE_TYPE_NORMAL}, {@link #UI_MODE_TYPE_DESK}, * or {@link #UI_MODE_TYPE_CAR}. * *
The {@link #UI_MODE_NIGHT_MASK} defines whether the screen
* is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED},
* {@link #UI_MODE_NIGHT_NO} or {@link #UI_MODE_NIGHT_YES}.
*/
public int uiMode;
public static final int SCREEN_WIDTH_DP_UNDEFINED = 0;
/**
* The current width of the available screen space, in dp units.
*/
public int screenWidthDp;
public static final int SCREEN_HEIGHT_DP_UNDEFINED = 0;
/**
* The current height of the available screen space, in dp units.
*/
public int screenHeightDp;
public static final int SMALLEST_SCREEN_WIDTH_DP_UNDEFINED = 0;
/**
* The smallest screen size an application will see in normal operation.
* This is the smallest value of both screenWidthDp and screenHeightDp
* in both portrait and landscape.
*/
public int smallestScreenWidthDp;
/** @hide Hack to get this information from WM to app running in compat mode. */
public int compatScreenWidthDp;
/** @hide Hack to get this information from WM to app running in compat mode. */
public int compatScreenHeightDp;
/** @hide Hack to get this information from WM to app running in compat mode. */
public int compatSmallestScreenWidthDp;
/**
* @hide The text layout direction associated to the current Locale
*/
public int textLayoutDirection;
/**
* @hide Internal book-keeping.
*/
public int seq;
/**
* Construct an invalid Configuration. You must call {@link #setToDefaults}
* for this object to be valid. {@more}
*/
public Configuration() {
setToDefaults();
}
/**
* Makes a deep copy suitable for modification.
*/
public Configuration(Configuration o) {
setTo(o);
}
public void setTo(Configuration o) {
fontScale = o.fontScale;
mcc = o.mcc;
mnc = o.mnc;
if (o.locale != null) {
locale = (Locale) o.locale.clone();
textLayoutDirection = o.textLayoutDirection;
}
userSetLocale = o.userSetLocale;
touchscreen = o.touchscreen;
keyboard = o.keyboard;
keyboardHidden = o.keyboardHidden;
hardKeyboardHidden = o.hardKeyboardHidden;
navigation = o.navigation;
navigationHidden = o.navigationHidden;
orientation = o.orientation;
screenLayout = o.screenLayout;
uiMode = o.uiMode;
screenWidthDp = o.screenWidthDp;
screenHeightDp = o.screenHeightDp;
smallestScreenWidthDp = o.smallestScreenWidthDp;
compatScreenWidthDp = o.compatScreenWidthDp;
compatScreenHeightDp = o.compatScreenHeightDp;
compatSmallestScreenWidthDp = o.compatSmallestScreenWidthDp;
seq = o.seq;
}
public String toString() {
StringBuilder sb = new StringBuilder(128);
sb.append("{");
sb.append(fontScale);
sb.append(" ");
sb.append(mcc);
sb.append("mcc");
sb.append(mnc);
sb.append("mnc");
if (locale != null) {
sb.append(" ");
sb.append(locale);
} else {
sb.append(" (no locale)");
}
switch (textLayoutDirection) {
case LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE: sb.append(" rtl"); break;
default: sb.append(" layoutdir="); sb.append(textLayoutDirection); break;
}
if (smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
sb.append(" sw"); sb.append(smallestScreenWidthDp); sb.append("dp");
} else {
sb.append(" ?swdp");
}
if (screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
sb.append(" w"); sb.append(screenWidthDp); sb.append("dp");
} else {
sb.append(" ?wdp");
}
if (screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
sb.append(" h"); sb.append(screenHeightDp); sb.append("dp");
} else {
sb.append(" ?hdp");
}
switch ((screenLayout&SCREENLAYOUT_SIZE_MASK)) {
case SCREENLAYOUT_SIZE_UNDEFINED: sb.append(" ?lsize"); break;
case SCREENLAYOUT_SIZE_SMALL: sb.append(" smll"); break;
case SCREENLAYOUT_SIZE_NORMAL: sb.append(" nrml"); break;
case SCREENLAYOUT_SIZE_LARGE: sb.append(" lrg"); break;
case SCREENLAYOUT_SIZE_XLARGE: sb.append(" xlrg"); break;
default: sb.append(" layoutSize=");
sb.append(screenLayout&SCREENLAYOUT_SIZE_MASK); break;
}
switch ((screenLayout&SCREENLAYOUT_LONG_MASK)) {
case SCREENLAYOUT_LONG_UNDEFINED: sb.append(" ?long"); break;
case SCREENLAYOUT_LONG_NO: /* not-long is not interesting to print */ break;
case SCREENLAYOUT_LONG_YES: sb.append(" long"); break;
default: sb.append(" layoutLong=");
sb.append(screenLayout&SCREENLAYOUT_LONG_MASK); break;
}
switch (orientation) {
case ORIENTATION_UNDEFINED: sb.append(" ?orien"); break;
case ORIENTATION_LANDSCAPE: sb.append(" land"); break;
case ORIENTATION_PORTRAIT: sb.append(" port"); break;
default: sb.append(" orien="); sb.append(orientation); break;
}
switch ((uiMode&UI_MODE_TYPE_MASK)) {
case UI_MODE_TYPE_UNDEFINED: sb.append(" ?uimode"); break;
case UI_MODE_TYPE_NORMAL: /* normal is not interesting to print */ break;
case UI_MODE_TYPE_DESK: sb.append(" desk"); break;
case UI_MODE_TYPE_CAR: sb.append(" car"); break;
case UI_MODE_TYPE_TELEVISION: sb.append(" television"); break;
default: sb.append(" uimode="); sb.append(uiMode&UI_MODE_TYPE_MASK); break;
}
switch ((uiMode&UI_MODE_NIGHT_MASK)) {
case UI_MODE_NIGHT_UNDEFINED: sb.append(" ?night"); break;
case UI_MODE_NIGHT_NO: /* not-night is not interesting to print */ break;
case UI_MODE_NIGHT_YES: sb.append(" night"); break;
default: sb.append(" night="); sb.append(uiMode&UI_MODE_NIGHT_MASK); break;
}
switch (touchscreen) {
case TOUCHSCREEN_UNDEFINED: sb.append(" ?touch"); break;
case TOUCHSCREEN_NOTOUCH: sb.append(" -touch"); break;
case TOUCHSCREEN_STYLUS: sb.append(" stylus"); break;
case TOUCHSCREEN_FINGER: sb.append(" finger"); break;
default: sb.append(" touch="); sb.append(touchscreen); break;
}
switch (keyboard) {
case KEYBOARD_UNDEFINED: sb.append(" ?keyb"); break;
case KEYBOARD_NOKEYS: sb.append(" -keyb"); break;
case KEYBOARD_QWERTY: sb.append(" qwerty"); break;
case KEYBOARD_12KEY: sb.append(" 12key"); break;
default: sb.append(" keys="); sb.append(keyboard); break;
}
switch (keyboardHidden) {
case KEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break;
case KEYBOARDHIDDEN_NO: sb.append("/v"); break;
case KEYBOARDHIDDEN_YES: sb.append("/h"); break;
case KEYBOARDHIDDEN_SOFT: sb.append("/s"); break;
default: sb.append("/"); sb.append(keyboardHidden); break;
}
switch (hardKeyboardHidden) {
case HARDKEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break;
case HARDKEYBOARDHIDDEN_NO: sb.append("/v"); break;
case HARDKEYBOARDHIDDEN_YES: sb.append("/h"); break;
default: sb.append("/"); sb.append(hardKeyboardHidden); break;
}
switch (navigation) {
case NAVIGATION_UNDEFINED: sb.append(" ?nav"); break;
case NAVIGATION_NONAV: sb.append(" -nav"); break;
case NAVIGATION_DPAD: sb.append(" dpad"); break;
case NAVIGATION_TRACKBALL: sb.append(" tball"); break;
case NAVIGATION_WHEEL: sb.append(" wheel"); break;
default: sb.append(" nav="); sb.append(navigation); break;
}
switch (navigationHidden) {
case NAVIGATIONHIDDEN_UNDEFINED: sb.append("/?"); break;
case NAVIGATIONHIDDEN_NO: sb.append("/v"); break;
case NAVIGATIONHIDDEN_YES: sb.append("/h"); break;
default: sb.append("/"); sb.append(navigationHidden); break;
}
if (seq != 0) {
sb.append(" s.");
sb.append(seq);
}
sb.append('}');
return sb.toString();
}
/**
* Set this object to the system defaults.
*/
public void setToDefaults() {
fontScale = 1;
mcc = mnc = 0;
locale = null;
userSetLocale = false;
touchscreen = TOUCHSCREEN_UNDEFINED;
keyboard = KEYBOARD_UNDEFINED;
keyboardHidden = KEYBOARDHIDDEN_UNDEFINED;
hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED;
navigation = NAVIGATION_UNDEFINED;
navigationHidden = NAVIGATIONHIDDEN_UNDEFINED;
orientation = ORIENTATION_UNDEFINED;
screenLayout = SCREENLAYOUT_SIZE_UNDEFINED;
uiMode = UI_MODE_TYPE_UNDEFINED;
screenWidthDp = compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
screenHeightDp = compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
textLayoutDirection = LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE;
seq = 0;
}
/** {@hide} */
@Deprecated public void makeDefault() {
setToDefaults();
}
/**
* Copy the fields from delta into this Configuration object, keeping
* track of which ones have changed. Any undefined fields in
* delta are ignored and not copied in to the current
* Configuration.
* @return Returns a bit mask of the changed fields, as per
* {@link #diff}.
*/
public int updateFrom(Configuration delta) {
int changed = 0;
if (delta.fontScale > 0 && fontScale != delta.fontScale) {
changed |= ActivityInfo.CONFIG_FONT_SCALE;
fontScale = delta.fontScale;
}
if (delta.mcc != 0 && mcc != delta.mcc) {
changed |= ActivityInfo.CONFIG_MCC;
mcc = delta.mcc;
}
if (delta.mnc != 0 && mnc != delta.mnc) {
changed |= ActivityInfo.CONFIG_MNC;
mnc = delta.mnc;
}
if (delta.locale != null
&& (locale == null || !locale.equals(delta.locale))) {
changed |= ActivityInfo.CONFIG_LOCALE;
locale = delta.locale != null
? (Locale) delta.locale.clone() : null;
textLayoutDirection = LocaleUtil.getLayoutDirectionFromLocale(locale);
}
if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0)))
{
userSetLocale = true;
changed |= ActivityInfo.CONFIG_LOCALE;
}
if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
&& touchscreen != delta.touchscreen) {
changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
touchscreen = delta.touchscreen;
}
if (delta.keyboard != KEYBOARD_UNDEFINED
&& keyboard != delta.keyboard) {
changed |= ActivityInfo.CONFIG_KEYBOARD;
keyboard = delta.keyboard;
}
if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED
&& keyboardHidden != delta.keyboardHidden) {
changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
keyboardHidden = delta.keyboardHidden;
}
if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED
&& hardKeyboardHidden != delta.hardKeyboardHidden) {
changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
hardKeyboardHidden = delta.hardKeyboardHidden;
}
if (delta.navigation != NAVIGATION_UNDEFINED
&& navigation != delta.navigation) {
changed |= ActivityInfo.CONFIG_NAVIGATION;
navigation = delta.navigation;
}
if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
&& navigationHidden != delta.navigationHidden) {
changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
navigationHidden = delta.navigationHidden;
}
if (delta.orientation != ORIENTATION_UNDEFINED
&& orientation != delta.orientation) {
changed |= ActivityInfo.CONFIG_ORIENTATION;
orientation = delta.orientation;
}
if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED
&& screenLayout != delta.screenLayout) {
changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
screenLayout = delta.screenLayout;
}
if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)
&& uiMode != delta.uiMode) {
changed |= ActivityInfo.CONFIG_UI_MODE;
if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) {
uiMode = (uiMode&~UI_MODE_TYPE_MASK)
| (delta.uiMode&UI_MODE_TYPE_MASK);
}
if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) {
uiMode = (uiMode&~UI_MODE_NIGHT_MASK)
| (delta.uiMode&UI_MODE_NIGHT_MASK);
}
}
if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED
&& screenWidthDp != delta.screenWidthDp) {
changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
screenWidthDp = delta.screenWidthDp;
}
if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED
&& screenHeightDp != delta.screenHeightDp) {
changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
screenHeightDp = delta.screenHeightDp;
}
if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
smallestScreenWidthDp = delta.smallestScreenWidthDp;
}
if (delta.compatScreenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
compatScreenWidthDp = delta.compatScreenWidthDp;
}
if (delta.compatScreenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
compatScreenHeightDp = delta.compatScreenHeightDp;
}
if (delta.compatSmallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
compatSmallestScreenWidthDp = delta.compatSmallestScreenWidthDp;
}
if (delta.seq != 0) {
seq = delta.seq;
}
return changed;
}
/**
* Return a bit mask of the differences between this Configuration
* object and the given one. Does not change the values of either. Any
* undefined fields in delta are ignored.
* @return Returns a bit mask indicating which configuration
* values has changed, containing any combination of
* {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE
* PackageManager.ActivityInfo.CONFIG_FONT_SCALE},
* {@link android.content.pm.ActivityInfo#CONFIG_MCC
* PackageManager.ActivityInfo.CONFIG_MCC},
* {@link android.content.pm.ActivityInfo#CONFIG_MNC
* PackageManager.ActivityInfo.CONFIG_MNC},
* {@link android.content.pm.ActivityInfo#CONFIG_LOCALE
* PackageManager.ActivityInfo.CONFIG_LOCALE},
* {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN
* PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN},
* {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD
* PackageManager.ActivityInfo.CONFIG_KEYBOARD},
* {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION
* PackageManager.ActivityInfo.CONFIG_NAVIGATION},
* {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION
* PackageManager.ActivityInfo.CONFIG_ORIENTATION},
* {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT
* PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}, or
* {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE
* PackageManager.ActivityInfo.CONFIG_SCREEN_SIZE}, or
* {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE
* PackageManager.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE}.
*/
public int diff(Configuration delta) {
int changed = 0;
if (delta.fontScale > 0 && fontScale != delta.fontScale) {
changed |= ActivityInfo.CONFIG_FONT_SCALE;
}
if (delta.mcc != 0 && mcc != delta.mcc) {
changed |= ActivityInfo.CONFIG_MCC;
}
if (delta.mnc != 0 && mnc != delta.mnc) {
changed |= ActivityInfo.CONFIG_MNC;
}
if (delta.locale != null
&& (locale == null || !locale.equals(delta.locale))) {
changed |= ActivityInfo.CONFIG_LOCALE;
}
if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
&& touchscreen != delta.touchscreen) {
changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
}
if (delta.keyboard != KEYBOARD_UNDEFINED
&& keyboard != delta.keyboard) {
changed |= ActivityInfo.CONFIG_KEYBOARD;
}
if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED
&& keyboardHidden != delta.keyboardHidden) {
changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
}
if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED
&& hardKeyboardHidden != delta.hardKeyboardHidden) {
changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
}
if (delta.navigation != NAVIGATION_UNDEFINED
&& navigation != delta.navigation) {
changed |= ActivityInfo.CONFIG_NAVIGATION;
}
if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
&& navigationHidden != delta.navigationHidden) {
changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
}
if (delta.orientation != ORIENTATION_UNDEFINED
&& orientation != delta.orientation) {
changed |= ActivityInfo.CONFIG_ORIENTATION;
}
if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED
&& screenLayout != delta.screenLayout) {
changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
}
if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)
&& uiMode != delta.uiMode) {
changed |= ActivityInfo.CONFIG_UI_MODE;
}
if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED
&& screenWidthDp != delta.screenWidthDp) {
changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
}
if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED
&& screenHeightDp != delta.screenHeightDp) {
changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
}
if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED
&& smallestScreenWidthDp != delta.smallestScreenWidthDp) {
changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
}
return changed;
}
/**
* Determine if a new resource needs to be loaded from the bit set of
* configuration changes returned by {@link #updateFrom(Configuration)}.
*
* @param configChanges The mask of changes configurations as returned by
* {@link #updateFrom(Configuration)}.
* @param interestingChanges The configuration changes that the resource
* can handled, as given in {@link android.util.TypedValue#changingConfigurations}.
*
* @return Return true if the resource needs to be loaded, else false.
*/
public static boolean needNewResources(int configChanges, int interestingChanges) {
return (configChanges & (interestingChanges|ActivityInfo.CONFIG_FONT_SCALE)) != 0;
}
/**
* @hide Return true if the sequence of 'other' is better than this. Assumes
* that 'this' is your current sequence and 'other' is a new one you have
* received some how and want to compare with what you have.
*/
public boolean isOtherSeqNewer(Configuration other) {
if (other == null) {
// Sanity check.
return false;
}
if (other.seq == 0) {
// If the other sequence is not specified, then we must assume
// it is newer since we don't know any better.
return true;
}
if (seq == 0) {
// If this sequence is not specified, then we also consider the
// other is better. Yes we have a preference for other. Sue us.
return true;
}
int diff = other.seq - seq;
if (diff > 0x10000) {
// If there has been a sufficiently large jump, assume the
// sequence has wrapped around.
return false;
}
return diff > 0;
}
/**
* Parcelable methods
*/
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeFloat(fontScale);
dest.writeInt(mcc);
dest.writeInt(mnc);
if (locale == null) {
dest.writeInt(0);
} else {
dest.writeInt(1);
dest.writeString(locale.getLanguage());
dest.writeString(locale.getCountry());
dest.writeString(locale.getVariant());
}
if(userSetLocale) {
dest.writeInt(1);
} else {
dest.writeInt(0);
}
dest.writeInt(touchscreen);
dest.writeInt(keyboard);
dest.writeInt(keyboardHidden);
dest.writeInt(hardKeyboardHidden);
dest.writeInt(navigation);
dest.writeInt(navigationHidden);
dest.writeInt(orientation);
dest.writeInt(screenLayout);
dest.writeInt(uiMode);
dest.writeInt(screenWidthDp);
dest.writeInt(screenHeightDp);
dest.writeInt(smallestScreenWidthDp);
dest.writeInt(compatScreenWidthDp);
dest.writeInt(compatScreenHeightDp);
dest.writeInt(compatSmallestScreenWidthDp);
dest.writeInt(textLayoutDirection);
dest.writeInt(seq);
}
public void readFromParcel(Parcel source) {
fontScale = source.readFloat();
mcc = source.readInt();
mnc = source.readInt();
if (source.readInt() != 0) {
locale = new Locale(source.readString(), source.readString(),
source.readString());
}
userSetLocale = (source.readInt()==1);
touchscreen = source.readInt();
keyboard = source.readInt();
keyboardHidden = source.readInt();
hardKeyboardHidden = source.readInt();
navigation = source.readInt();
navigationHidden = source.readInt();
orientation = source.readInt();
screenLayout = source.readInt();
uiMode = source.readInt();
screenWidthDp = source.readInt();
screenHeightDp = source.readInt();
smallestScreenWidthDp = source.readInt();
compatScreenWidthDp = source.readInt();
compatScreenHeightDp = source.readInt();
compatSmallestScreenWidthDp = source.readInt();
textLayoutDirection = source.readInt();
seq = source.readInt();
}
public static final Parcelable.Creator