/* * 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 com.android.internal.util.XmlUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlSerializer; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo.Config; import android.os.Build; import android.os.LocaleList; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; import android.view.View; import java.io.IOException; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; 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 list 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
getLocales().get(0)
is now the preferred accessor.
*/
@Deprecated public Locale locale;
private LocaleList mLocaleList;
/**
* Locale should persist on setting. This is hidden because it is really
* questionable whether this is the right way to expose the functionality.
* @hide
*/
public boolean userSetLocale;
/** Constant for {@link #screenLayout}: bits that encode the size. */
public static final int SCREENLAYOUT_SIZE_MASK = 0x0f;
/** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
* value indicating that no size has been set. */
public static final int SCREENLAYOUT_SIZE_UNDEFINED = 0x00;
/** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
* value indicating the screen is at least approximately 320x426 dp units,
* corresponds to the
* small
* resource qualifier.
* See Supporting
* Multiple Screens for more information. */
public static final int SCREENLAYOUT_SIZE_SMALL = 0x01;
/** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
* value indicating the screen is at least approximately 320x470 dp units,
* corresponds to the
* normal
* resource qualifier.
* See Supporting
* Multiple Screens for more information. */
public static final int SCREENLAYOUT_SIZE_NORMAL = 0x02;
/** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
* value indicating the screen is at least approximately 480x640 dp units,
* corresponds to the
* large
* resource qualifier.
* See Supporting
* Multiple Screens for more information. */
public static final int SCREENLAYOUT_SIZE_LARGE = 0x03;
/** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
* value indicating the screen is at least approximately 720x960 dp units,
* corresponds to the
* xlarge
* resource qualifier.
* See Supporting
* Multiple Screens for more information.*/
public static final int SCREENLAYOUT_SIZE_XLARGE = 0x04;
/** Constant for {@link #screenLayout}: bits that encode the aspect ratio. */
public static final int SCREENLAYOUT_LONG_MASK = 0x30;
/** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK}
* value indicating that no size has been set. */
public static final int SCREENLAYOUT_LONG_UNDEFINED = 0x00;
/** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK}
* value that corresponds to the
* notlong
* resource qualifier. */
public static final int SCREENLAYOUT_LONG_NO = 0x10;
/** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK}
* value that corresponds to the
* long
* resource qualifier. */
public static final int SCREENLAYOUT_LONG_YES = 0x20;
/** Constant for {@link #screenLayout}: bits that encode the layout direction. */
public static final int SCREENLAYOUT_LAYOUTDIR_MASK = 0xC0;
/** Constant for {@link #screenLayout}: bits shift to get the layout direction. */
public static final int SCREENLAYOUT_LAYOUTDIR_SHIFT = 6;
/** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK}
* value indicating that no layout dir has been set. */
public static final int SCREENLAYOUT_LAYOUTDIR_UNDEFINED = 0x00;
/** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK}
* value indicating that a layout dir has been set to LTR. */
public static final int SCREENLAYOUT_LAYOUTDIR_LTR = 0x01 << SCREENLAYOUT_LAYOUTDIR_SHIFT;
/** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK}
* value indicating that a layout dir has been set to RTL. */
public static final int SCREENLAYOUT_LAYOUTDIR_RTL = 0x02 << SCREENLAYOUT_LAYOUTDIR_SHIFT;
/** Constant for {@link #screenLayout}: bits that encode roundness of the screen. */
public static final int SCREENLAYOUT_ROUND_MASK = 0x300;
/** @hide Constant for {@link #screenLayout}: bit shift to get to screen roundness bits */
public static final int SCREENLAYOUT_ROUND_SHIFT = 8;
/**
* Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating
* that it is unknown whether or not the screen has a round shape.
*/
public static final int SCREENLAYOUT_ROUND_UNDEFINED = 0x00;
/**
* Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating
* that the screen does not have a rounded shape.
*/
public static final int SCREENLAYOUT_ROUND_NO = 0x1 << SCREENLAYOUT_ROUND_SHIFT;
/**
* Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating
* that the screen has a rounded shape. Corners may not be visible to the user;
* developers should pay special attention to the {@link android.view.WindowInsets} delivered
* to views for more information about ensuring content is not obscured.
*
* Corresponds to the -round
resource qualifier.
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}.
* *The {@link #SCREENLAYOUT_LAYOUTDIR_MASK} defines whether the screen layout * is either LTR or RTL. They may be one of * {@link #SCREENLAYOUT_LAYOUTDIR_LTR} or {@link #SCREENLAYOUT_LAYOUTDIR_RTL}.
* *The {@link #SCREENLAYOUT_ROUND_MASK} defines whether the screen has a rounded * shape. They may be one of {@link #SCREENLAYOUT_ROUND_NO} or {@link #SCREENLAYOUT_ROUND_YES}. *
* *See Supporting * Multiple Screens for more information.
*/ public int screenLayout; /** @hide */ static public int resetScreenLayout(int curLayout) { return (curLayout&~(SCREENLAYOUT_LONG_MASK | SCREENLAYOUT_SIZE_MASK | SCREENLAYOUT_COMPAT_NEEDED)) | (SCREENLAYOUT_LONG_YES | SCREENLAYOUT_SIZE_XLARGE); } /** @hide */ static public int reduceScreenLayout(int curLayout, int longSizeDp, int shortSizeDp) { int screenLayoutSize; boolean screenLayoutLong; boolean screenLayoutCompatNeeded; // These semi-magic numbers define our compatibility modes for // applications with different screens. These are guarantees to // app developers about the space they can expect for a particular // configuration. DO NOT CHANGE! if (longSizeDp < 470) { // This is shorter than an HVGA normal density screen (which // is 480 pixels on its long side). screenLayoutSize = SCREENLAYOUT_SIZE_SMALL; screenLayoutLong = false; screenLayoutCompatNeeded = false; } else { // What size is this screen screen? if (longSizeDp >= 960 && shortSizeDp >= 720) { // 1.5xVGA or larger screens at medium density are the point // at which we consider it to be an extra large screen. screenLayoutSize = SCREENLAYOUT_SIZE_XLARGE; } else if (longSizeDp >= 640 && shortSizeDp >= 480) { // VGA or larger screens at medium density are the point // at which we consider it to be a large screen. screenLayoutSize = SCREENLAYOUT_SIZE_LARGE; } else { screenLayoutSize = SCREENLAYOUT_SIZE_NORMAL; } // If this screen is wider than normal HVGA, or taller // than FWVGA, then for old apps we want to run in size // compatibility mode. if (shortSizeDp > 321 || longSizeDp > 570) { screenLayoutCompatNeeded = true; } else { screenLayoutCompatNeeded = false; } // Is this a long screen? if (((longSizeDp*3)/5) >= (shortSizeDp-1)) { // Anything wider than WVGA (5:3) is considering to be long. screenLayoutLong = true; } else { screenLayoutLong = false; } } // Now reduce the last screenLayout to not be better than what we // have found. if (!screenLayoutLong) { curLayout = (curLayout&~SCREENLAYOUT_LONG_MASK) | SCREENLAYOUT_LONG_NO; } if (screenLayoutCompatNeeded) { curLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; } int curSize = curLayout&SCREENLAYOUT_SIZE_MASK; if (screenLayoutSize < curSize) { curLayout = (curLayout&~SCREENLAYOUT_SIZE_MASK) | screenLayoutSize; } return curLayout; } /** @hide */ public static String configurationDiffToString(int diff) { ArrayListThe {@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}, * {@link #UI_MODE_TYPE_CAR}, {@link #UI_MODE_TYPE_TELEVISION}, * {@link #UI_MODE_TYPE_APPLIANCE}, or {@link #UI_MODE_TYPE_WATCH}. * *
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;
/**
* Default value for {@link #screenWidthDp} indicating that no width
* has been specified.
*/
public static final int SCREEN_WIDTH_DP_UNDEFINED = 0;
/**
* The current width of the available screen space, in dp units,
* corresponding to
* screen
* width resource qualifier. Set to
* {@link #SCREEN_WIDTH_DP_UNDEFINED} if no width is specified.
*/
public int screenWidthDp;
/**
* Default value for {@link #screenHeightDp} indicating that no width
* has been specified.
*/
public static final int SCREEN_HEIGHT_DP_UNDEFINED = 0;
/**
* The current height of the available screen space, in dp units,
* corresponding to
* screen
* height resource qualifier. Set to
* {@link #SCREEN_HEIGHT_DP_UNDEFINED} if no height is specified.
*/
public int screenHeightDp;
/**
* Default value for {@link #smallestScreenWidthDp} indicating that no width
* has been specified.
*/
public static final int SMALLEST_SCREEN_WIDTH_DP_UNDEFINED = 0;
/**
* The smallest screen size an application will see in normal operation,
* corresponding to
* smallest
* screen width resource qualifier.
* This is the smallest value of both screenWidthDp and screenHeightDp
* in both portrait and landscape. Set to
* {@link #SMALLEST_SCREEN_WIDTH_DP_UNDEFINED} if no width is specified.
*/
public int smallestScreenWidthDp;
/**
* Default value for {@link #densityDpi} indicating that no width
* has been specified.
*/
public static final int DENSITY_DPI_UNDEFINED = 0;
/**
* Value for {@link #densityDpi} for resources that scale to any density (vector drawables).
* {@hide}
*/
public static final int DENSITY_DPI_ANY = 0xfffe;
/**
* Value for {@link #densityDpi} for resources that are not meant to be scaled.
* {@hide}
*/
public static final int DENSITY_DPI_NONE = 0xffff;
/**
* The target screen density being rendered to,
* corresponding to
* density
* resource qualifier. Set to
* {@link #DENSITY_DPI_UNDEFINED} if no density is specified.
*/
public int densityDpi;
/** @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 Internal book-keeping.
*/
public int seq;
/** @hide */
@IntDef(flag = true,
value = {
NATIVE_CONFIG_MCC,
NATIVE_CONFIG_MNC,
NATIVE_CONFIG_LOCALE,
NATIVE_CONFIG_TOUCHSCREEN,
NATIVE_CONFIG_KEYBOARD,
NATIVE_CONFIG_KEYBOARD_HIDDEN,
NATIVE_CONFIG_NAVIGATION,
NATIVE_CONFIG_ORIENTATION,
NATIVE_CONFIG_DENSITY,
NATIVE_CONFIG_SCREEN_SIZE,
NATIVE_CONFIG_VERSION,
NATIVE_CONFIG_SCREEN_LAYOUT,
NATIVE_CONFIG_UI_MODE,
NATIVE_CONFIG_SMALLEST_SCREEN_SIZE,
NATIVE_CONFIG_LAYOUTDIR,
})
@Retention(RetentionPolicy.SOURCE)
public @interface NativeConfig {}
/** @hide Native-specific bit mask for MCC config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_MCC = 0x0001;
/** @hide Native-specific bit mask for MNC config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_MNC = 0x0002;
/** @hide Native-specific bit mask for LOCALE config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_LOCALE = 0x0004;
/** @hide Native-specific bit mask for TOUCHSCREEN config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_TOUCHSCREEN = 0x0008;
/** @hide Native-specific bit mask for KEYBOARD config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_KEYBOARD = 0x0010;
/** @hide Native-specific bit mask for KEYBOARD_HIDDEN config; DO NOT USE UNLESS YOU
* ARE SURE. */
public static final int NATIVE_CONFIG_KEYBOARD_HIDDEN = 0x0020;
/** @hide Native-specific bit mask for NAVIGATION config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_NAVIGATION = 0x0040;
/** @hide Native-specific bit mask for ORIENTATION config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_ORIENTATION = 0x0080;
/** @hide Native-specific bit mask for DENSITY config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_DENSITY = 0x0100;
/** @hide Native-specific bit mask for SCREEN_SIZE config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_SCREEN_SIZE = 0x0200;
/** @hide Native-specific bit mask for VERSION config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_VERSION = 0x0400;
/** @hide Native-specific bit mask for SCREEN_LAYOUT config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_SCREEN_LAYOUT = 0x0800;
/** @hide Native-specific bit mask for UI_MODE config; DO NOT USE UNLESS YOU ARE SURE. */
public static final int NATIVE_CONFIG_UI_MODE = 0x1000;
/** @hide Native-specific bit mask for SMALLEST_SCREEN_SIZE config; DO NOT USE UNLESS YOU
* ARE SURE. */
public static final int NATIVE_CONFIG_SMALLEST_SCREEN_SIZE = 0x2000;
/** @hide Native-specific bit mask for LAYOUTDIR config ; DO NOT USE UNLESS YOU ARE SURE.*/
public static final int NATIVE_CONFIG_LAYOUTDIR = 0x4000;
/**
* 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);
}
/* This brings mLocaleList in sync with locale in case a user of the older API who doesn't know
* about setLocales() has changed locale directly. */
private void fixUpLocaleList() {
if ((locale == null && !mLocaleList.isEmpty()) ||
(locale != null && !locale.equals(mLocaleList.get(0)))) {
mLocaleList = locale == null ? LocaleList.getEmptyLocaleList() : new LocaleList(locale);
}
}
public void setTo(Configuration o) {
fontScale = o.fontScale;
mcc = o.mcc;
mnc = o.mnc;
locale = o.locale == null ? null : (Locale) o.locale.clone();
o.fixUpLocaleList();
mLocaleList = o.mLocaleList;
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;
densityDpi = o.densityDpi;
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(" ");
if (mcc != 0) {
sb.append(mcc);
sb.append("mcc");
} else {
sb.append("?mcc");
}
if (mnc != 0) {
sb.append(mnc);
sb.append("mnc");
} else {
sb.append("?mnc");
}
fixUpLocaleList();
if (!mLocaleList.isEmpty()) {
sb.append(" ");
sb.append(mLocaleList);
} else {
sb.append(" ?localeList");
}
int layoutDir = (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK);
switch (layoutDir) {
case SCREENLAYOUT_LAYOUTDIR_UNDEFINED: sb.append(" ?layoutDir"); break;
case SCREENLAYOUT_LAYOUTDIR_LTR: sb.append(" ldltr"); break;
case SCREENLAYOUT_LAYOUTDIR_RTL: sb.append(" ldrtl"); break;
default: sb.append(" layoutDir=");
sb.append(layoutDir >> SCREENLAYOUT_LAYOUTDIR_SHIFT); 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");
}
if (densityDpi != DENSITY_DPI_UNDEFINED) {
sb.append(" "); sb.append(densityDpi); sb.append("dpi");
} else {
sb.append(" ?density");
}
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;
case UI_MODE_TYPE_APPLIANCE: sb.append(" appliance"); break;
case UI_MODE_TYPE_WATCH: sb.append(" watch"); 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;
mLocaleList = LocaleList.getEmptyLocaleList();
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_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;
densityDpi = DENSITY_DPI_UNDEFINED;
seq = 0;
}
/** {@hide} */
@Deprecated public void makeDefault() {
setToDefaults();
}
/**
* Copies the fields from delta into this Configuration object, keeping
* track of which ones have changed. Any undefined fields in {@code delta}
* are ignored and not copied in to the current Configuration.
*
* @return a bit mask of the changed fields, as per {@link #diff}
*/
public @Config int updateFrom(@NonNull 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;
}
fixUpLocaleList();
delta.fixUpLocaleList();
if (!delta.mLocaleList.isEmpty() && !mLocaleList.equals(delta.mLocaleList)) {
changed |= ActivityInfo.CONFIG_LOCALE;
mLocaleList = delta.mLocaleList;
// delta.locale can't be null, since delta.mLocaleList is not empty.
if (!delta.locale.equals(locale)) {
locale = (Locale) delta.locale.clone();
// If locale has changed, then layout direction is also changed ...
changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
// ... and we need to update the layout direction (represented by the first
// 2 most significant bits in screenLayout).
setLayoutDirection(locale);
}
}
final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK;
if (deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED &&
deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) {
screenLayout = (screenLayout & ~SCREENLAYOUT_LAYOUTDIR_MASK) | deltaScreenLayoutDir;
changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
}
if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0)))
{
changed |= ActivityInfo.CONFIG_LOCALE;
userSetLocale = true;
}
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 (getScreenLayoutNoDirection(delta.screenLayout) !=
(SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED)
&& (getScreenLayoutNoDirection(screenLayout) !=
getScreenLayoutNoDirection(delta.screenLayout))) {
changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
// We need to preserve the previous layout dir bits if they were defined
if ((delta.screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == 0) {
screenLayout = (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK)|delta.screenLayout;
} else {
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) {
changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
smallestScreenWidthDp = delta.smallestScreenWidthDp;
}
if (delta.densityDpi != DENSITY_DPI_UNDEFINED &&
densityDpi != delta.densityDpi) {
changed |= ActivityInfo.CONFIG_DENSITY;
densityDpi = delta.densityDpi;
}
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}.
* {@link android.content.pm.ActivityInfo#CONFIG_LAYOUT_DIRECTION
* PackageManager.ActivityInfo.CONFIG_LAYOUT_DIRECTION}.
*/
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;
}
fixUpLocaleList();
delta.fixUpLocaleList();
if (!delta.mLocaleList.isEmpty() && !mLocaleList.equals(delta.mLocaleList)) {
changed |= ActivityInfo.CONFIG_LOCALE;
changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
}
final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK;
if (deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED &&
deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) {
changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
}
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 (getScreenLayoutNoDirection(delta.screenLayout) !=
(SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED)
&& getScreenLayoutNoDirection(screenLayout) !=
getScreenLayoutNoDirection(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;
}
if (delta.densityDpi != DENSITY_DPI_UNDEFINED
&& densityDpi != delta.densityDpi) {
changed |= ActivityInfo.CONFIG_DENSITY;
}
return changed;
}
/**
* Determines 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 handle as given in
* {@link android.util.TypedValue#changingConfigurations}
* @return {@code true} if the resource needs to be loaded, {@code false}
* otherwise
*/
public static boolean needNewResources(@Config int configChanges,
@Config 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);
fixUpLocaleList();
final int localeListSize = mLocaleList.size();
dest.writeInt(localeListSize);
for (int i = 0; i < localeListSize; ++i) {
final Locale l = mLocaleList.get(i);
dest.writeString(l.toLanguageTag());
}
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(densityDpi);
dest.writeInt(compatScreenWidthDp);
dest.writeInt(compatScreenHeightDp);
dest.writeInt(compatSmallestScreenWidthDp);
dest.writeInt(seq);
}
public void readFromParcel(Parcel source) {
fontScale = source.readFloat();
mcc = source.readInt();
mnc = source.readInt();
final int localeListSize = source.readInt();
final Locale[] localeArray = new Locale[localeListSize];
for (int i = 0; i < localeListSize; ++i) {
localeArray[i] = Locale.forLanguageTag(source.readString());
}
mLocaleList = new LocaleList(localeArray);
locale = mLocaleList.get(0);
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();
densityDpi = source.readInt();
compatScreenWidthDp = source.readInt();
compatScreenHeightDp = source.readInt();
compatSmallestScreenWidthDp = source.readInt();
seq = source.readInt();
}
public static final Parcelable.Creator.equals()
on the input locale and the
* {@link #locale} attribute would return true
if they are not null, but there is
* no guarantee that they would be the same object.
*
* See also the note about layout direction in {@link #setLocales(LocaleList)}.
*
* @param loc The locale. Can be null.
*/
public void setLocale(@Nullable Locale loc) {
setLocales(loc == null ? LocaleList.getEmptyLocaleList() : new LocaleList(loc));
}
/**
* @hide
*
* Clears the locale without changing layout direction.
*/
public void clearLocales() {
mLocaleList = LocaleList.getEmptyLocaleList();
locale = null;
}
/**
* Return the layout direction. Will be either {@link View#LAYOUT_DIRECTION_LTR} or
* {@link View#LAYOUT_DIRECTION_RTL}.
*
* @return Returns {@link View#LAYOUT_DIRECTION_RTL} if the configuration
* is {@link #SCREENLAYOUT_LAYOUTDIR_RTL}, otherwise {@link View#LAYOUT_DIRECTION_LTR}.
*/
public int getLayoutDirection() {
return (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == SCREENLAYOUT_LAYOUTDIR_RTL
? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
}
/**
* Set the layout direction from a Locale.
*
* @param loc The Locale. If null will set the layout direction to
* {@link View#LAYOUT_DIRECTION_LTR}. If not null will set it to the layout direction
* corresponding to the Locale.
*
* @see View#LAYOUT_DIRECTION_LTR
* @see View#LAYOUT_DIRECTION_RTL
*/
public void setLayoutDirection(Locale loc) {
// There is a "1" difference between the configuration values for
// layout direction and View constants for layout direction, just add "1".
final int layoutDirection = 1 + TextUtils.getLayoutDirectionFromLocale(loc);
screenLayout = (screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK)|
(layoutDirection << SCREENLAYOUT_LAYOUTDIR_SHIFT);
}
private static int getScreenLayoutNoDirection(int screenLayout) {
return screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK;
}
/**
* Return whether the screen has a round shape. Apps may choose to change styling based
* on this property, such as the alignment or layout of text or informational icons.
*
* @return true if the screen is rounded, false otherwise
*/
public boolean isScreenRound() {
return (screenLayout & SCREENLAYOUT_ROUND_MASK) == SCREENLAYOUT_ROUND_YES;
}
/**
*
* @hide
*/
public static String localesToResourceQualifier(LocaleList locs) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < locs.size(); i++) {
Locale loc = locs.get(i);
boolean l = (loc.getLanguage().length() != 0);
boolean c = (loc.getCountry().length() != 0);
boolean s = (loc.getScript().length() != 0);
boolean v = (loc.getVariant().length() != 0);
// TODO: take script and extensions into account
if (l) {
if (sb.length() != 0) {
sb.append(",");
}
sb.append(loc.getLanguage());
if (c) {
sb.append("-r").append(loc.getCountry());
if (s) {
sb.append("-s").append(loc.getScript());
if (v) {
sb.append("-v").append(loc.getVariant());
}
}
}
}
}
return sb.toString();
}
/**
* Returns a string representation of the configuration that can be parsed
* by build tools (like AAPT).
*
* @hide
*/
public static String resourceQualifierString(Configuration config) {
ArrayListbase
and change
. The
* resulting delta can be used with {@link #updateFrom(Configuration)}.
*
* Caveat: If the any of the Configuration's members becomes undefined, then
* {@link #updateFrom(Configuration)} will treat it as a no-op and not update that member.
*
* This is fine for device configurations as no member is ever undefined.
* {@hide}
*/
public static Configuration generateDelta(Configuration base, Configuration change) {
final Configuration delta = new Configuration();
if (base.fontScale != change.fontScale) {
delta.fontScale = change.fontScale;
}
if (base.mcc != change.mcc) {
delta.mcc = change.mcc;
}
if (base.mnc != change.mnc) {
delta.mnc = change.mnc;
}
base.fixUpLocaleList();
change.fixUpLocaleList();
if (!base.mLocaleList.equals(change.mLocaleList)) {
delta.mLocaleList = change.mLocaleList;
delta.locale = change.locale;
}
if (base.touchscreen != change.touchscreen) {
delta.touchscreen = change.touchscreen;
}
if (base.keyboard != change.keyboard) {
delta.keyboard = change.keyboard;
}
if (base.keyboardHidden != change.keyboardHidden) {
delta.keyboardHidden = change.keyboardHidden;
}
if (base.navigation != change.navigation) {
delta.navigation = change.navigation;
}
if (base.navigationHidden != change.navigationHidden) {
delta.navigationHidden = change.navigationHidden;
}
if (base.orientation != change.orientation) {
delta.orientation = change.orientation;
}
if ((base.screenLayout & SCREENLAYOUT_SIZE_MASK) !=
(change.screenLayout & SCREENLAYOUT_SIZE_MASK)) {
delta.screenLayout |= change.screenLayout & SCREENLAYOUT_SIZE_MASK;
}
if ((base.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK) !=
(change.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) {
delta.screenLayout |= change.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK;
}
if ((base.screenLayout & SCREENLAYOUT_LONG_MASK) !=
(change.screenLayout & SCREENLAYOUT_LONG_MASK)) {
delta.screenLayout |= change.screenLayout & SCREENLAYOUT_LONG_MASK;
}
if ((base.screenLayout & SCREENLAYOUT_ROUND_MASK) !=
(change.screenLayout & SCREENLAYOUT_ROUND_MASK)) {
delta.screenLayout |= change.screenLayout & SCREENLAYOUT_ROUND_MASK;
}
if ((base.uiMode & UI_MODE_TYPE_MASK) != (change.uiMode & UI_MODE_TYPE_MASK)) {
delta.uiMode |= change.uiMode & UI_MODE_TYPE_MASK;
}
if ((base.uiMode & UI_MODE_NIGHT_MASK) != (change.uiMode & UI_MODE_NIGHT_MASK)) {
delta.uiMode |= change.uiMode & UI_MODE_NIGHT_MASK;
}
if (base.screenWidthDp != change.screenWidthDp) {
delta.screenWidthDp = change.screenWidthDp;
}
if (base.screenHeightDp != change.screenHeightDp) {
delta.screenHeightDp = change.screenHeightDp;
}
if (base.smallestScreenWidthDp != change.smallestScreenWidthDp) {
delta.smallestScreenWidthDp = change.smallestScreenWidthDp;
}
if (base.densityDpi != change.densityDpi) {
delta.densityDpi = change.densityDpi;
}
return delta;
}
private static final String XML_ATTR_FONT_SCALE = "fs";
private static final String XML_ATTR_MCC = "mcc";
private static final String XML_ATTR_MNC = "mnc";
private static final String XML_ATTR_LOCALES = "locales";
private static final String XML_ATTR_TOUCHSCREEN = "touch";
private static final String XML_ATTR_KEYBOARD = "key";
private static final String XML_ATTR_KEYBOARD_HIDDEN = "keyHid";
private static final String XML_ATTR_HARD_KEYBOARD_HIDDEN = "hardKeyHid";
private static final String XML_ATTR_NAVIGATION = "nav";
private static final String XML_ATTR_NAVIGATION_HIDDEN = "navHid";
private static final String XML_ATTR_ORIENTATION = "ori";
private static final String XML_ATTR_SCREEN_LAYOUT = "scrLay";
private static final String XML_ATTR_UI_MODE = "ui";
private static final String XML_ATTR_SCREEN_WIDTH = "width";
private static final String XML_ATTR_SCREEN_HEIGHT = "height";
private static final String XML_ATTR_SMALLEST_WIDTH = "sw";
private static final String XML_ATTR_DENSITY = "density";
/**
* Reads the attributes corresponding to Configuration member fields from the Xml parser.
* The parser is expected to be on a tag which has Configuration attributes.
*
* @param parser The Xml parser from which to read attributes.
* @param configOut The Configuration to populate from the Xml attributes.
* {@hide}
*/
public static void readXmlAttrs(XmlPullParser parser, Configuration configOut)
throws XmlPullParserException, IOException {
configOut.fontScale = Float.intBitsToFloat(
XmlUtils.readIntAttribute(parser, XML_ATTR_FONT_SCALE, 0));
configOut.mcc = XmlUtils.readIntAttribute(parser, XML_ATTR_MCC, 0);
configOut.mnc = XmlUtils.readIntAttribute(parser, XML_ATTR_MNC, 0);
final String localesStr = XmlUtils.readStringAttribute(parser, XML_ATTR_LOCALES);
configOut.mLocaleList = LocaleList.forLanguageTags(localesStr);
configOut.locale = configOut.mLocaleList.get(0);
configOut.touchscreen = XmlUtils.readIntAttribute(parser, XML_ATTR_TOUCHSCREEN,
TOUCHSCREEN_UNDEFINED);
configOut.keyboard = XmlUtils.readIntAttribute(parser, XML_ATTR_KEYBOARD,
KEYBOARD_UNDEFINED);
configOut.keyboardHidden = XmlUtils.readIntAttribute(parser, XML_ATTR_KEYBOARD_HIDDEN,
KEYBOARDHIDDEN_UNDEFINED);
configOut.hardKeyboardHidden =
XmlUtils.readIntAttribute(parser, XML_ATTR_HARD_KEYBOARD_HIDDEN,
HARDKEYBOARDHIDDEN_UNDEFINED);
configOut.navigation = XmlUtils.readIntAttribute(parser, XML_ATTR_NAVIGATION,
NAVIGATION_UNDEFINED);
configOut.navigationHidden = XmlUtils.readIntAttribute(parser, XML_ATTR_NAVIGATION_HIDDEN,
NAVIGATIONHIDDEN_UNDEFINED);
configOut.orientation = XmlUtils.readIntAttribute(parser, XML_ATTR_ORIENTATION,
ORIENTATION_UNDEFINED);
configOut.screenLayout = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_LAYOUT,
SCREENLAYOUT_UNDEFINED);
configOut.uiMode = XmlUtils.readIntAttribute(parser, XML_ATTR_UI_MODE, 0);
configOut.screenWidthDp = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_WIDTH,
SCREEN_WIDTH_DP_UNDEFINED);
configOut.screenHeightDp = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_HEIGHT,
SCREEN_HEIGHT_DP_UNDEFINED);
configOut.smallestScreenWidthDp =
XmlUtils.readIntAttribute(parser, XML_ATTR_SMALLEST_WIDTH,
SMALLEST_SCREEN_WIDTH_DP_UNDEFINED);
configOut.densityDpi = XmlUtils.readIntAttribute(parser, XML_ATTR_DENSITY,
DENSITY_DPI_UNDEFINED);
}
/**
* Writes the Configuration's member fields as attributes into the XmlSerializer.
* The serializer is expected to have already started a tag so that attributes can be
* immediately written.
*
* @param xml The serializer to which to write the attributes.
* @param config The Configuration whose member fields to write.
* {@hide}
*/
public static void writeXmlAttrs(XmlSerializer xml, Configuration config) throws IOException {
XmlUtils.writeIntAttribute(xml, XML_ATTR_FONT_SCALE,
Float.floatToIntBits(config.fontScale));
if (config.mcc != 0) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_MCC, config.mcc);
}
if (config.mnc != 0) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_MNC, config.mnc);
}
config.fixUpLocaleList();
if (!config.mLocaleList.isEmpty()) {
XmlUtils.writeStringAttribute(xml, XML_ATTR_LOCALES, config.mLocaleList.toLanguageTags());
}
if (config.touchscreen != TOUCHSCREEN_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_TOUCHSCREEN, config.touchscreen);
}
if (config.keyboard != KEYBOARD_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_KEYBOARD, config.keyboard);
}
if (config.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_KEYBOARD_HIDDEN, config.keyboardHidden);
}
if (config.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_HARD_KEYBOARD_HIDDEN,
config.hardKeyboardHidden);
}
if (config.navigation != NAVIGATION_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_NAVIGATION, config.navigation);
}
if (config.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_NAVIGATION_HIDDEN, config.navigationHidden);
}
if (config.orientation != ORIENTATION_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_ORIENTATION, config.orientation);
}
if (config.screenLayout != SCREENLAYOUT_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_SCREEN_LAYOUT, config.screenLayout);
}
if (config.uiMode != 0) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_UI_MODE, config.uiMode);
}
if (config.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_SCREEN_WIDTH, config.screenWidthDp);
}
if (config.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_SCREEN_HEIGHT, config.screenHeightDp);
}
if (config.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_SMALLEST_WIDTH, config.smallestScreenWidthDp);
}
if (config.densityDpi != DENSITY_DPI_UNDEFINED) {
XmlUtils.writeIntAttribute(xml, XML_ATTR_DENSITY, config.densityDpi);
}
}
}