public final class

Configuration

extends Object
implements Parcelable Comparable<T>
java.lang.Object
   ↳android.content.res.Configuration

Class Overview

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 dynamic device configuration (various types of input devices).

Summary

Constants
Creator<Configuration>CREATOR
intHARDKEYBOARDHIDDEN_NO
intHARDKEYBOARDHIDDEN_UNDEFINED
intHARDKEYBOARDHIDDEN_YES
intKEYBOARDHIDDEN_NO
intKEYBOARDHIDDEN_UNDEFINED
intKEYBOARDHIDDEN_YES
intKEYBOARD_12KEY
intKEYBOARD_NOKEYS
intKEYBOARD_QWERTY
intKEYBOARD_UNDEFINED
intNAVIGATIONHIDDEN_NO
intNAVIGATIONHIDDEN_UNDEFINED
intNAVIGATIONHIDDEN_YES
intNAVIGATION_DPAD
intNAVIGATION_NONAV
intNAVIGATION_TRACKBALL
intNAVIGATION_UNDEFINED
intNAVIGATION_WHEEL
intORIENTATION_LANDSCAPE
intORIENTATION_PORTRAIT
intORIENTATION_SQUARE
intORIENTATION_UNDEFINED
intSCREENLAYOUT_LONG_MASK
intSCREENLAYOUT_LONG_NO
intSCREENLAYOUT_LONG_UNDEFINED
intSCREENLAYOUT_LONG_YES
intSCREENLAYOUT_SIZE_LARGE
intSCREENLAYOUT_SIZE_MASK
intSCREENLAYOUT_SIZE_NORMAL
intSCREENLAYOUT_SIZE_SMALL
intSCREENLAYOUT_SIZE_UNDEFINED
intSCREENLAYOUT_SIZE_XLARGE
intTOUCHSCREEN_FINGER
intTOUCHSCREEN_NOTOUCH
intTOUCHSCREEN_STYLUS
intTOUCHSCREEN_UNDEFINED
intUI_MODE_NIGHT_MASK
intUI_MODE_NIGHT_NO
intUI_MODE_NIGHT_UNDEFINED
intUI_MODE_NIGHT_YES
intUI_MODE_TYPE_CAR
intUI_MODE_TYPE_DESK
intUI_MODE_TYPE_MASK
intUI_MODE_TYPE_NORMAL
intUI_MODE_TYPE_UNDEFINED
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public floatfontScaleCurrent user preference for the scaling factor for fonts, relative to the base density scaling.
public inthardKeyboardHiddenA flag indicating whether the hard keyboard has been hidden.
public intkeyboardThe kind of keyboard attached to the device.
public intkeyboardHiddenA flag indicating whether any keyboard is available.
public LocalelocaleCurrent user preference for the locale.
public intmccIMSI MCC (Mobile Country Code).
public intmncIMSI MNC (Mobile Network Code).
public intnavigationThe kind of navigation method available on the device.
public intnavigationHiddenA flag indicating whether any 5-way or DPAD navigation available.
public intorientationOverall orientation of the screen.
public intscreenLayoutBit mask of overall layout of the screen.
public inttouchscreenThe kind of touch screen attached to the device.
public intuiModeBit mask of the ui mode.
Public Constructors
Configuration()
Construct an invalid Configuration. You must call setToDefaults() for this object to be valid.
Configuration(Configuration o)
Makes a deep copy suitable for modification.
Public Methods
int compareTo(Configuration that)
int describeContents()
Parcelable methods
int diff(Configuration delta)
Return a bit mask of the differences between this Configuration object and the given one.
boolean equals(Configuration that)
boolean equals(Object that)
Compares this instance with the specified object and indicates if they are equal.
int hashCode()
Returns an integer hash code for this object.
static boolean needNewResources(int configChanges, int interestingChanges)
Determine if a new resource needs to be loaded from the bit set of configuration changes returned by updateFrom(Configuration).
void readFromParcel(Parcel source)
void setTo(Configuration o)
void setToDefaults()
Set this object to the system defaults.
String toString()
Returns a string containing a concise, human-readable description of this object.
int updateFrom(Configuration delta)
Copy the fields from delta into this Configuration object, keeping track of which ones have changed.
void writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable
From interface java.lang.Comparable

Constants

public static final Creator<Configuration> CREATOR

Since: API Level 1

public static final int HARDKEYBOARDHIDDEN_NO

Since: API Level 3

Constant Value: 1 (0x00000001)

public static final int HARDKEYBOARDHIDDEN_UNDEFINED

Since: API Level 3

Constant Value: 0 (0x00000000)

public static final int HARDKEYBOARDHIDDEN_YES

Since: API Level 3

Constant Value: 2 (0x00000002)

public static final int KEYBOARDHIDDEN_NO

Since: API Level 1

Constant Value: 1 (0x00000001)

public static final int KEYBOARDHIDDEN_UNDEFINED

Since: API Level 1

Constant Value: 0 (0x00000000)

public static final int KEYBOARDHIDDEN_YES

Since: API Level 1

Constant Value: 2 (0x00000002)

public static final int KEYBOARD_12KEY

Since: API Level 1

Constant Value: 3 (0x00000003)

public static final int KEYBOARD_NOKEYS

Since: API Level 1

Constant Value: 1 (0x00000001)

public static final int KEYBOARD_QWERTY

Since: API Level 1

Constant Value: 2 (0x00000002)

public static final int KEYBOARD_UNDEFINED

Since: API Level 1

Constant Value: 0 (0x00000000)

public static final int NAVIGATIONHIDDEN_NO

Since: API Level 5

Constant Value: 1 (0x00000001)

public static final int NAVIGATIONHIDDEN_UNDEFINED

Since: API Level 5

Constant Value: 0 (0x00000000)

public static final int NAVIGATIONHIDDEN_YES

Since: API Level 5

Constant Value: 2 (0x00000002)

public static final int NAVIGATION_DPAD

Since: API Level 1

Constant Value: 2 (0x00000002)

public static final int NAVIGATION_NONAV

Since: API Level 1

Constant Value: 1 (0x00000001)

public static final int NAVIGATION_TRACKBALL

Since: API Level 1

Constant Value: 3 (0x00000003)

public static final int NAVIGATION_UNDEFINED

Since: API Level 1

Constant Value: 0 (0x00000000)

public static final int NAVIGATION_WHEEL

Since: API Level 1

Constant Value: 4 (0x00000004)

public static final int ORIENTATION_LANDSCAPE

Since: API Level 1

Constant Value: 2 (0x00000002)

public static final int ORIENTATION_PORTRAIT

Since: API Level 1

Constant Value: 1 (0x00000001)

public static final int ORIENTATION_SQUARE

Since: API Level 1

Constant Value: 3 (0x00000003)

public static final int ORIENTATION_UNDEFINED

Since: API Level 1

Constant Value: 0 (0x00000000)

public static final int SCREENLAYOUT_LONG_MASK

Since: API Level 4

Constant Value: 48 (0x00000030)

public static final int SCREENLAYOUT_LONG_NO

Since: API Level 4

Constant Value: 16 (0x00000010)

public static final int SCREENLAYOUT_LONG_UNDEFINED

Since: API Level 4

Constant Value: 0 (0x00000000)

public static final int SCREENLAYOUT_LONG_YES

Since: API Level 4

Constant Value: 32 (0x00000020)

public static final int SCREENLAYOUT_SIZE_LARGE

Since: API Level 4

Constant Value: 3 (0x00000003)

public static final int SCREENLAYOUT_SIZE_MASK

Since: API Level 4

Constant Value: 15 (0x0000000f)

public static final int SCREENLAYOUT_SIZE_NORMAL

Since: API Level 4

Constant Value: 2 (0x00000002)

public static final int SCREENLAYOUT_SIZE_SMALL

Since: API Level 4

Constant Value: 1 (0x00000001)

public static final int SCREENLAYOUT_SIZE_UNDEFINED

Since: API Level 4

Constant Value: 0 (0x00000000)

public static final int SCREENLAYOUT_SIZE_XLARGE

Since: API Level 9

Constant Value: 4 (0x00000004)

public static final int TOUCHSCREEN_FINGER

Since: API Level 1

Constant Value: 3 (0x00000003)

public static final int TOUCHSCREEN_NOTOUCH

Since: API Level 1

Constant Value: 1 (0x00000001)

public static final int TOUCHSCREEN_STYLUS

Since: API Level 1

Constant Value: 2 (0x00000002)

public static final int TOUCHSCREEN_UNDEFINED

Since: API Level 1

Constant Value: 0 (0x00000000)

public static final int UI_MODE_NIGHT_MASK

Since: API Level 8

Constant Value: 48 (0x00000030)

public static final int UI_MODE_NIGHT_NO

Since: API Level 8

Constant Value: 16 (0x00000010)

public static final int UI_MODE_NIGHT_UNDEFINED

Since: API Level 8

Constant Value: 0 (0x00000000)

public static final int UI_MODE_NIGHT_YES

Since: API Level 8

Constant Value: 32 (0x00000020)

public static final int UI_MODE_TYPE_CAR

Since: API Level 8

Constant Value: 3 (0x00000003)

public static final int UI_MODE_TYPE_DESK

Since: API Level 8

Constant Value: 2 (0x00000002)

public static final int UI_MODE_TYPE_MASK

Since: API Level 8

Constant Value: 15 (0x0000000f)

public static final int UI_MODE_TYPE_NORMAL

Since: API Level 8

Constant Value: 1 (0x00000001)

public static final int UI_MODE_TYPE_UNDEFINED

Since: API Level 8

Constant Value: 0 (0x00000000)

Fields

public float fontScale

Since: API Level 1

Current user preference for the scaling factor for fonts, relative to the base density scaling.

public int hardKeyboardHidden

Since: API Level 3

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: HARDKEYBOARDHIDDEN_NO, HARDKEYBOARDHIDDEN_YES.

public int keyboard

Since: API Level 1

The kind of keyboard attached to the device. One of: KEYBOARD_NOKEYS, KEYBOARD_QWERTY, KEYBOARD_12KEY.

public int keyboardHidden

Since: API Level 1

A flag indicating whether any keyboard is available. Unlike 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: KEYBOARDHIDDEN_NO, KEYBOARDHIDDEN_YES.

public Locale locale

Since: API Level 1

Current user preference for the locale.

public int mcc

Since: API Level 1

IMSI MCC (Mobile Country Code). 0 if undefined.

public int mnc

Since: API Level 1

IMSI MNC (Mobile Network Code). 0 if undefined.

public int navigation

Since: API Level 1

The kind of navigation method available on the device. One of: NAVIGATION_NONAV, NAVIGATION_DPAD, NAVIGATION_TRACKBALL, NAVIGATION_WHEEL.

public int navigationHidden

Since: API Level 5

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: NAVIGATIONHIDDEN_NO, NAVIGATIONHIDDEN_YES.

public int orientation

Since: API Level 1

Overall orientation of the screen. May be one of ORIENTATION_LANDSCAPE, ORIENTATION_PORTRAIT, or ORIENTATION_SQUARE.

public int screenLayout

Since: API Level 4

Bit mask of overall layout of the screen. Currently there are two fields:

The SCREENLAYOUT_SIZE_MASK bits define the overall size of the screen. They may be one of SCREENLAYOUT_SIZE_SMALL, SCREENLAYOUT_SIZE_NORMAL, SCREENLAYOUT_SIZE_LARGE.

The SCREENLAYOUT_LONG_MASK defines whether the screen is wider/taller than normal. They may be one of SCREENLAYOUT_LONG_NO or SCREENLAYOUT_LONG_YES.

public int touchscreen

Since: API Level 1

The kind of touch screen attached to the device. One of: TOUCHSCREEN_NOTOUCH, TOUCHSCREEN_STYLUS, TOUCHSCREEN_FINGER.

public int uiMode

Since: API Level 8

Bit mask of the ui mode. Currently there are two fields:

The UI_MODE_TYPE_MASK bits define the overall ui mode of the device. They may be one of UI_MODE_TYPE_UNDEFINED, UI_MODE_TYPE_NORMAL, UI_MODE_TYPE_DESK, or UI_MODE_TYPE_CAR.

The UI_MODE_NIGHT_MASK defines whether the screen is in a special mode. They may be one of UI_MODE_NIGHT_UNDEFINED, UI_MODE_NIGHT_NO or UI_MODE_NIGHT_YES.

Public Constructors

public Configuration ()

Since: API Level 1

Construct an invalid Configuration. You must call setToDefaults() for this object to be valid.

public Configuration (Configuration o)

Since: API Level 1

Makes a deep copy suitable for modification.

Public Methods

public int compareTo (Configuration that)

Since: API Level 1

public int describeContents ()

Since: API Level 1

Parcelable methods

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public int diff (Configuration delta)

Since: API Level 1

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.

public boolean equals (Configuration that)

Since: API Level 1

public boolean equals (Object that)

Since: API Level 1

Compares this instance with the specified object and indicates if they are equal. In order to be equal, o must represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be reflexive, symmetric, and transitive. Also, no object reference other than null is equal to null.

The default implementation returns true only if this == o. See Writing a correct equals method if you intend implementing your own equals method.

The general contract for the equals and hashCode() methods is that if equals returns true for any two objects, then hashCode() must return the same value for these objects. This means that subclasses of Object usually override either both methods or neither of them.

Parameters
that the object to compare this instance with.
Returns
  • true if the specified object is equal to this Object; false otherwise.

public int hashCode ()

Since: API Level 1

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
  • this object's hash code.

public static boolean needNewResources (int configChanges, int interestingChanges)

Since: API Level 1

Determine if a new resource needs to be loaded from the bit set of configuration changes returned by updateFrom(Configuration).

Parameters
configChanges The mask of changes configurations as returned by updateFrom(Configuration).
interestingChanges The configuration changes that the resource can handled, as given in changingConfigurations.
Returns
  • Return true if the resource needs to be loaded, else false.

public void readFromParcel (Parcel source)

Since: API Level 8

public void setTo (Configuration o)

Since: API Level 8

public void setToDefaults ()

Since: API Level 1

Set this object to the system defaults.

public String toString ()

Since: API Level 1

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public int updateFrom (Configuration delta)

Since: API Level 1

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.

Returns

public void writeToParcel (Parcel dest, int flags)

Since: API Level 1

Flatten this object in to a Parcel.

Parameters
dest The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.