Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.content.res; |
| 18 | |
| 19 | import android.content.pm.ActivityInfo; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
Fabrice Di Meglio | a47f45e | 2011-06-15 14:22:12 -0700 | [diff] [blame] | 22 | import android.util.LocaleUtil; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | |
| 24 | import java.util.Locale; |
| 25 | |
| 26 | /** |
| 27 | * This class describes all device configuration information that can |
| 28 | * impact the resources the application retrieves. This includes both |
| 29 | * user-specified configuration options (locale and scaling) as well |
Scott Main | 63848e3 | 2011-04-20 22:20:46 -0700 | [diff] [blame] | 30 | * as device configurations (such as input modes, screen size and screen orientation). |
| 31 | * <p>You can acquire this object from {@link Resources}, using {@link |
| 32 | * Resources#getConfiguration}. Thus, from an activity, you can get it by chaining the request |
| 33 | * with {@link android.app.Activity#getResources}:</p> |
| 34 | * <pre>Configuration config = getResources().getConfiguration();</pre> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | */ |
| 36 | public final class Configuration implements Parcelable, Comparable<Configuration> { |
| 37 | /** |
| 38 | * Current user preference for the scaling factor for fonts, relative |
| 39 | * to the base density scaling. |
| 40 | */ |
| 41 | public float fontScale; |
| 42 | |
| 43 | /** |
| 44 | * IMSI MCC (Mobile Country Code). 0 if undefined. |
| 45 | */ |
| 46 | public int mcc; |
| 47 | |
| 48 | /** |
| 49 | * IMSI MNC (Mobile Network Code). 0 if undefined. |
| 50 | */ |
| 51 | public int mnc; |
| 52 | |
| 53 | /** |
| 54 | * Current user preference for the locale. |
| 55 | */ |
| 56 | public Locale locale; |
| 57 | |
| 58 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 59 | * Locale should persist on setting. This is hidden because it is really |
| 60 | * questionable whether this is the right way to expose the functionality. |
| 61 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | */ |
| 63 | public boolean userSetLocale; |
| 64 | |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 65 | /** Constant for {@link #screenLayout}: bits that encode the size. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 66 | public static final int SCREENLAYOUT_SIZE_MASK = 0x0f; |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 67 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} |
| 68 | * value indicating that no size has been set. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 69 | public static final int SCREENLAYOUT_SIZE_UNDEFINED = 0x00; |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 70 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} |
| 71 | * value indicating the screen is at least approximately 320x426 dp units. |
| 72 | * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting |
| 73 | * Multiple Screens</a> for more information. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 74 | public static final int SCREENLAYOUT_SIZE_SMALL = 0x01; |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 75 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} |
| 76 | * value indicating the screen is at least approximately 320x470 dp units. |
| 77 | * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting |
| 78 | * Multiple Screens</a> for more information. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 79 | public static final int SCREENLAYOUT_SIZE_NORMAL = 0x02; |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 80 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} |
| 81 | * value indicating the screen is at least approximately 480x640 dp units. |
| 82 | * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting |
| 83 | * Multiple Screens</a> for more information. */ |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 84 | public static final int SCREENLAYOUT_SIZE_LARGE = 0x03; |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 85 | /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK} |
| 86 | * value indicating the screen is at least approximately 720x960 dp units. |
| 87 | * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting |
| 88 | * Multiple Screens</a> for more information.*/ |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 89 | public static final int SCREENLAYOUT_SIZE_XLARGE = 0x04; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 90 | |
| 91 | public static final int SCREENLAYOUT_LONG_MASK = 0x30; |
| 92 | public static final int SCREENLAYOUT_LONG_UNDEFINED = 0x00; |
| 93 | public static final int SCREENLAYOUT_LONG_NO = 0x10; |
| 94 | public static final int SCREENLAYOUT_LONG_YES = 0x20; |
| 95 | |
| 96 | /** |
| 97 | * Special flag we generate to indicate that the screen layout requires |
| 98 | * us to use a compatibility mode for apps that are not modern layout |
| 99 | * aware. |
| 100 | * @hide |
| 101 | */ |
| 102 | public static final int SCREENLAYOUT_COMPAT_NEEDED = 0x10000000; |
| 103 | |
| 104 | /** |
| 105 | * Bit mask of overall layout of the screen. Currently there are two |
| 106 | * fields: |
| 107 | * <p>The {@link #SCREENLAYOUT_SIZE_MASK} bits define the overall size |
| 108 | * of the screen. They may be one of |
| 109 | * {@link #SCREENLAYOUT_SIZE_SMALL}, {@link #SCREENLAYOUT_SIZE_NORMAL}, |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 110 | * {@link #SCREENLAYOUT_SIZE_LARGE}, or {@link #SCREENLAYOUT_SIZE_XLARGE}. |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 111 | * |
| 112 | * <p>The {@link #SCREENLAYOUT_LONG_MASK} defines whether the screen |
| 113 | * is wider/taller than normal. They may be one of |
| 114 | * {@link #SCREENLAYOUT_LONG_NO} or {@link #SCREENLAYOUT_LONG_YES}. |
Dianne Hackborn | 2f98f26 | 2011-03-28 18:28:35 -0700 | [diff] [blame] | 115 | * |
| 116 | * <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting |
| 117 | * Multiple Screens</a> for more information. |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 118 | */ |
| 119 | public int screenLayout; |
| 120 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 121 | /** |
| 122 | * Check if the Configuration's current {@link #screenLayout} is at |
| 123 | * least the given size. |
| 124 | * |
| 125 | * @param size The desired size, either {@link #SCREENLAYOUT_SIZE_SMALL}, |
| 126 | * {@link #SCREENLAYOUT_SIZE_NORMAL}, {@link #SCREENLAYOUT_SIZE_LARGE}, or |
| 127 | * {@link #SCREENLAYOUT_SIZE_XLARGE}. |
| 128 | * @return Returns true if the current screen layout size is at least |
| 129 | * the given size. |
| 130 | */ |
| 131 | public boolean isLayoutSizeAtLeast(int size) { |
| 132 | int cur = screenLayout&SCREENLAYOUT_SIZE_MASK; |
| 133 | if (cur == SCREENLAYOUT_SIZE_UNDEFINED) return false; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 134 | return cur >= size; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 135 | } |
| 136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | public static final int TOUCHSCREEN_UNDEFINED = 0; |
| 138 | public static final int TOUCHSCREEN_NOTOUCH = 1; |
| 139 | public static final int TOUCHSCREEN_STYLUS = 2; |
| 140 | public static final int TOUCHSCREEN_FINGER = 3; |
| 141 | |
| 142 | /** |
| 143 | * The kind of touch screen attached to the device. |
| 144 | * One of: {@link #TOUCHSCREEN_NOTOUCH}, {@link #TOUCHSCREEN_STYLUS}, |
| 145 | * {@link #TOUCHSCREEN_FINGER}. |
| 146 | */ |
| 147 | public int touchscreen; |
| 148 | |
| 149 | public static final int KEYBOARD_UNDEFINED = 0; |
| 150 | public static final int KEYBOARD_NOKEYS = 1; |
| 151 | public static final int KEYBOARD_QWERTY = 2; |
| 152 | public static final int KEYBOARD_12KEY = 3; |
| 153 | |
| 154 | /** |
| 155 | * The kind of keyboard attached to the device. |
Kenny Root | 507f8ed | 2009-06-09 11:21:11 -0500 | [diff] [blame] | 156 | * One of: {@link #KEYBOARD_NOKEYS}, {@link #KEYBOARD_QWERTY}, |
| 157 | * {@link #KEYBOARD_12KEY}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | */ |
| 159 | public int keyboard; |
| 160 | |
| 161 | public static final int KEYBOARDHIDDEN_UNDEFINED = 0; |
| 162 | public static final int KEYBOARDHIDDEN_NO = 1; |
| 163 | public static final int KEYBOARDHIDDEN_YES = 2; |
| 164 | /** Constant matching actual resource implementation. {@hide} */ |
| 165 | public static final int KEYBOARDHIDDEN_SOFT = 3; |
| 166 | |
| 167 | /** |
| 168 | * A flag indicating whether any keyboard is available. Unlike |
| 169 | * {@link #hardKeyboardHidden}, this also takes into account a soft |
| 170 | * keyboard, so if the hard keyboard is hidden but there is soft |
| 171 | * keyboard available, it will be set to NO. Value is one of: |
| 172 | * {@link #KEYBOARDHIDDEN_NO}, {@link #KEYBOARDHIDDEN_YES}. |
| 173 | */ |
| 174 | public int keyboardHidden; |
| 175 | |
| 176 | public static final int HARDKEYBOARDHIDDEN_UNDEFINED = 0; |
| 177 | public static final int HARDKEYBOARDHIDDEN_NO = 1; |
| 178 | public static final int HARDKEYBOARDHIDDEN_YES = 2; |
| 179 | |
| 180 | /** |
| 181 | * A flag indicating whether the hard keyboard has been hidden. This will |
| 182 | * be set on a device with a mechanism to hide the keyboard from the |
| 183 | * user, when that mechanism is closed. One of: |
| 184 | * {@link #HARDKEYBOARDHIDDEN_NO}, {@link #HARDKEYBOARDHIDDEN_YES}. |
| 185 | */ |
| 186 | public int hardKeyboardHidden; |
| 187 | |
| 188 | public static final int NAVIGATION_UNDEFINED = 0; |
| 189 | public static final int NAVIGATION_NONAV = 1; |
| 190 | public static final int NAVIGATION_DPAD = 2; |
| 191 | public static final int NAVIGATION_TRACKBALL = 3; |
| 192 | public static final int NAVIGATION_WHEEL = 4; |
| 193 | |
| 194 | /** |
| 195 | * The kind of navigation method available on the device. |
Kenny Root | 507f8ed | 2009-06-09 11:21:11 -0500 | [diff] [blame] | 196 | * One of: {@link #NAVIGATION_NONAV}, {@link #NAVIGATION_DPAD}, |
| 197 | * {@link #NAVIGATION_TRACKBALL}, {@link #NAVIGATION_WHEEL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | */ |
| 199 | public int navigation; |
| 200 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 201 | public static final int NAVIGATIONHIDDEN_UNDEFINED = 0; |
| 202 | public static final int NAVIGATIONHIDDEN_NO = 1; |
| 203 | public static final int NAVIGATIONHIDDEN_YES = 2; |
| 204 | |
| 205 | /** |
| 206 | * A flag indicating whether any 5-way or DPAD navigation available. |
| 207 | * This will be set on a device with a mechanism to hide the navigation |
| 208 | * controls from the user, when that mechanism is closed. One of: |
| 209 | * {@link #NAVIGATIONHIDDEN_NO}, {@link #NAVIGATIONHIDDEN_YES}. |
| 210 | */ |
| 211 | public int navigationHidden; |
| 212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | public static final int ORIENTATION_UNDEFINED = 0; |
| 214 | public static final int ORIENTATION_PORTRAIT = 1; |
| 215 | public static final int ORIENTATION_LANDSCAPE = 2; |
| 216 | public static final int ORIENTATION_SQUARE = 3; |
| 217 | |
| 218 | /** |
| 219 | * Overall orientation of the screen. May be one of |
| 220 | * {@link #ORIENTATION_LANDSCAPE}, {@link #ORIENTATION_PORTRAIT}, |
| 221 | * or {@link #ORIENTATION_SQUARE}. |
| 222 | */ |
| 223 | public int orientation; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 224 | |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 225 | public static final int UI_MODE_TYPE_MASK = 0x0f; |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 226 | public static final int UI_MODE_TYPE_UNDEFINED = 0x00; |
| 227 | public static final int UI_MODE_TYPE_NORMAL = 0x01; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 228 | public static final int UI_MODE_TYPE_DESK = 0x02; |
| 229 | public static final int UI_MODE_TYPE_CAR = 0x03; |
Dianne Hackborn | e360bb6 | 2011-05-20 16:11:04 -0700 | [diff] [blame] | 230 | public static final int UI_MODE_TYPE_TELEVISION = 0x04; |
Joe Onorato | 44fcb83 | 2011-12-14 20:59:30 -0800 | [diff] [blame] | 231 | public static final int UI_MODE_TYPE_APPLIANCE = 0x05; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 232 | |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 233 | public static final int UI_MODE_NIGHT_MASK = 0x30; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 234 | public static final int UI_MODE_NIGHT_UNDEFINED = 0x00; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 235 | public static final int UI_MODE_NIGHT_NO = 0x10; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 236 | public static final int UI_MODE_NIGHT_YES = 0x20; |
| 237 | |
| 238 | /** |
| 239 | * Bit mask of the ui mode. Currently there are two fields: |
| 240 | * <p>The {@link #UI_MODE_TYPE_MASK} bits define the overall ui mode of the |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 241 | * device. They may be one of {@link #UI_MODE_TYPE_UNDEFINED}, |
| 242 | * {@link #UI_MODE_TYPE_NORMAL}, {@link #UI_MODE_TYPE_DESK}, |
Joe Onorato | 44fcb83 | 2011-12-14 20:59:30 -0800 | [diff] [blame] | 243 | * {@link #UI_MODE_TYPE_CAR}, {@link #UI_MODE_TYPE_TELEVISION}, or |
| 244 | * {@link #UI_MODE_TYPE_APPLIANCE}. |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 245 | * |
| 246 | * <p>The {@link #UI_MODE_NIGHT_MASK} defines whether the screen |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 247 | * is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED}, |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 248 | * {@link #UI_MODE_NIGHT_NO} or {@link #UI_MODE_NIGHT_YES}. |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 249 | */ |
| 250 | public int uiMode; |
| 251 | |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 252 | public static final int SCREEN_WIDTH_DP_UNDEFINED = 0; |
| 253 | |
| 254 | /** |
| 255 | * The current width of the available screen space, in dp units. |
| 256 | */ |
| 257 | public int screenWidthDp; |
| 258 | |
| 259 | public static final int SCREEN_HEIGHT_DP_UNDEFINED = 0; |
| 260 | |
| 261 | /** |
| 262 | * The current height of the available screen space, in dp units. |
| 263 | */ |
| 264 | public int screenHeightDp; |
| 265 | |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 266 | public static final int SMALLEST_SCREEN_WIDTH_DP_UNDEFINED = 0; |
| 267 | |
| 268 | /** |
| 269 | * The smallest screen size an application will see in normal operation. |
| 270 | * This is the smallest value of both screenWidthDp and screenHeightDp |
| 271 | * in both portrait and landscape. |
| 272 | */ |
| 273 | public int smallestScreenWidthDp; |
| 274 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 275 | /** @hide Hack to get this information from WM to app running in compat mode. */ |
| 276 | public int compatScreenWidthDp; |
| 277 | /** @hide Hack to get this information from WM to app running in compat mode. */ |
| 278 | public int compatScreenHeightDp; |
| 279 | /** @hide Hack to get this information from WM to app running in compat mode. */ |
| 280 | public int compatSmallestScreenWidthDp; |
| 281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | /** |
Fabrice Di Meglio | 7a736fb | 2011-06-09 20:20:36 -0700 | [diff] [blame] | 283 | * @hide The text layout direction associated to the current Locale |
Fabrice Di Meglio | 7194efd | 2011-06-09 11:05:25 -0700 | [diff] [blame] | 284 | */ |
Fabrice Di Meglio | 7a736fb | 2011-06-09 20:20:36 -0700 | [diff] [blame] | 285 | public int textLayoutDirection; |
Fabrice Di Meglio | 7194efd | 2011-06-09 11:05:25 -0700 | [diff] [blame] | 286 | |
| 287 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 288 | * @hide Internal book-keeping. |
| 289 | */ |
| 290 | public int seq; |
| 291 | |
| 292 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | * Construct an invalid Configuration. You must call {@link #setToDefaults} |
| 294 | * for this object to be valid. {@more} |
| 295 | */ |
| 296 | public Configuration() { |
| 297 | setToDefaults(); |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Makes a deep copy suitable for modification. |
| 302 | */ |
| 303 | public Configuration(Configuration o) { |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 304 | setTo(o); |
| 305 | } |
| 306 | |
| 307 | public void setTo(Configuration o) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | fontScale = o.fontScale; |
| 309 | mcc = o.mcc; |
| 310 | mnc = o.mnc; |
| 311 | if (o.locale != null) { |
| 312 | locale = (Locale) o.locale.clone(); |
Fabrice Di Meglio | 7a736fb | 2011-06-09 20:20:36 -0700 | [diff] [blame] | 313 | textLayoutDirection = o.textLayoutDirection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | } |
| 315 | userSetLocale = o.userSetLocale; |
| 316 | touchscreen = o.touchscreen; |
| 317 | keyboard = o.keyboard; |
| 318 | keyboardHidden = o.keyboardHidden; |
| 319 | hardKeyboardHidden = o.hardKeyboardHidden; |
| 320 | navigation = o.navigation; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 321 | navigationHidden = o.navigationHidden; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | orientation = o.orientation; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 323 | screenLayout = o.screenLayout; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 324 | uiMode = o.uiMode; |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 325 | screenWidthDp = o.screenWidthDp; |
| 326 | screenHeightDp = o.screenHeightDp; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 327 | smallestScreenWidthDp = o.smallestScreenWidthDp; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 328 | compatScreenWidthDp = o.compatScreenWidthDp; |
| 329 | compatScreenHeightDp = o.compatScreenHeightDp; |
| 330 | compatSmallestScreenWidthDp = o.compatSmallestScreenWidthDp; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 331 | seq = o.seq; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 335 | StringBuilder sb = new StringBuilder(128); |
Dianne Hackborn | 2973568 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 336 | sb.append("{"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 337 | sb.append(fontScale); |
Dianne Hackborn | 5be8de3 | 2011-05-24 18:11:57 -0700 | [diff] [blame] | 338 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 339 | sb.append(mcc); |
Dianne Hackborn | 5be8de3 | 2011-05-24 18:11:57 -0700 | [diff] [blame] | 340 | sb.append("mcc"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 341 | sb.append(mnc); |
Dianne Hackborn | 5be8de3 | 2011-05-24 18:11:57 -0700 | [diff] [blame] | 342 | sb.append("mnc"); |
Dianne Hackborn | 9a84983 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 343 | if (locale != null) { |
| 344 | sb.append(" "); |
| 345 | sb.append(locale); |
| 346 | } else { |
| 347 | sb.append(" (no locale)"); |
Daniel Sandler | 7d6bddc | 2010-07-22 16:11:55 -0400 | [diff] [blame] | 348 | } |
Fabrice Di Meglio | 7a736fb | 2011-06-09 20:20:36 -0700 | [diff] [blame] | 349 | switch (textLayoutDirection) { |
Fabrice Di Meglio | a47f45e | 2011-06-15 14:22:12 -0700 | [diff] [blame] | 350 | case LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE: sb.append(" rtl"); break; |
Fabrice Di Meglio | 7a736fb | 2011-06-09 20:20:36 -0700 | [diff] [blame] | 351 | default: sb.append(" layoutdir="); sb.append(textLayoutDirection); break; |
| 352 | } |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 353 | if (smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
| 354 | sb.append(" sw"); sb.append(smallestScreenWidthDp); sb.append("dp"); |
| 355 | } else { |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 356 | sb.append(" ?swdp"); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 357 | } |
| 358 | if (screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) { |
| 359 | sb.append(" w"); sb.append(screenWidthDp); sb.append("dp"); |
| 360 | } else { |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 361 | sb.append(" ?wdp"); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 362 | } |
| 363 | if (screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) { |
| 364 | sb.append(" h"); sb.append(screenHeightDp); sb.append("dp"); |
| 365 | } else { |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 366 | sb.append(" ?hdp"); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 367 | } |
| 368 | switch ((screenLayout&SCREENLAYOUT_SIZE_MASK)) { |
| 369 | case SCREENLAYOUT_SIZE_UNDEFINED: sb.append(" ?lsize"); break; |
| 370 | case SCREENLAYOUT_SIZE_SMALL: sb.append(" smll"); break; |
| 371 | case SCREENLAYOUT_SIZE_NORMAL: sb.append(" nrml"); break; |
| 372 | case SCREENLAYOUT_SIZE_LARGE: sb.append(" lrg"); break; |
| 373 | case SCREENLAYOUT_SIZE_XLARGE: sb.append(" xlrg"); break; |
| 374 | default: sb.append(" layoutSize="); |
| 375 | sb.append(screenLayout&SCREENLAYOUT_SIZE_MASK); break; |
| 376 | } |
| 377 | switch ((screenLayout&SCREENLAYOUT_LONG_MASK)) { |
| 378 | case SCREENLAYOUT_LONG_UNDEFINED: sb.append(" ?long"); break; |
| 379 | case SCREENLAYOUT_LONG_NO: /* not-long is not interesting to print */ break; |
| 380 | case SCREENLAYOUT_LONG_YES: sb.append(" long"); break; |
| 381 | default: sb.append(" layoutLong="); |
| 382 | sb.append(screenLayout&SCREENLAYOUT_LONG_MASK); break; |
| 383 | } |
| 384 | switch (orientation) { |
| 385 | case ORIENTATION_UNDEFINED: sb.append(" ?orien"); break; |
| 386 | case ORIENTATION_LANDSCAPE: sb.append(" land"); break; |
| 387 | case ORIENTATION_PORTRAIT: sb.append(" port"); break; |
| 388 | default: sb.append(" orien="); sb.append(orientation); break; |
| 389 | } |
| 390 | switch ((uiMode&UI_MODE_TYPE_MASK)) { |
| 391 | case UI_MODE_TYPE_UNDEFINED: sb.append(" ?uimode"); break; |
| 392 | case UI_MODE_TYPE_NORMAL: /* normal is not interesting to print */ break; |
| 393 | case UI_MODE_TYPE_DESK: sb.append(" desk"); break; |
| 394 | case UI_MODE_TYPE_CAR: sb.append(" car"); break; |
Dianne Hackborn | e360bb6 | 2011-05-20 16:11:04 -0700 | [diff] [blame] | 395 | case UI_MODE_TYPE_TELEVISION: sb.append(" television"); break; |
Joe Onorato | 44fcb83 | 2011-12-14 20:59:30 -0800 | [diff] [blame] | 396 | case UI_MODE_TYPE_APPLIANCE: sb.append(" appliance"); break; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 397 | default: sb.append(" uimode="); sb.append(uiMode&UI_MODE_TYPE_MASK); break; |
| 398 | } |
| 399 | switch ((uiMode&UI_MODE_NIGHT_MASK)) { |
| 400 | case UI_MODE_NIGHT_UNDEFINED: sb.append(" ?night"); break; |
| 401 | case UI_MODE_NIGHT_NO: /* not-night is not interesting to print */ break; |
| 402 | case UI_MODE_NIGHT_YES: sb.append(" night"); break; |
| 403 | default: sb.append(" night="); sb.append(uiMode&UI_MODE_NIGHT_MASK); break; |
| 404 | } |
Dianne Hackborn | 9a84983 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 405 | switch (touchscreen) { |
| 406 | case TOUCHSCREEN_UNDEFINED: sb.append(" ?touch"); break; |
| 407 | case TOUCHSCREEN_NOTOUCH: sb.append(" -touch"); break; |
| 408 | case TOUCHSCREEN_STYLUS: sb.append(" stylus"); break; |
| 409 | case TOUCHSCREEN_FINGER: sb.append(" finger"); break; |
| 410 | default: sb.append(" touch="); sb.append(touchscreen); break; |
| 411 | } |
| 412 | switch (keyboard) { |
| 413 | case KEYBOARD_UNDEFINED: sb.append(" ?keyb"); break; |
| 414 | case KEYBOARD_NOKEYS: sb.append(" -keyb"); break; |
| 415 | case KEYBOARD_QWERTY: sb.append(" qwerty"); break; |
| 416 | case KEYBOARD_12KEY: sb.append(" 12key"); break; |
| 417 | default: sb.append(" keys="); sb.append(keyboard); break; |
| 418 | } |
| 419 | switch (keyboardHidden) { |
| 420 | case KEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break; |
| 421 | case KEYBOARDHIDDEN_NO: sb.append("/v"); break; |
| 422 | case KEYBOARDHIDDEN_YES: sb.append("/h"); break; |
| 423 | case KEYBOARDHIDDEN_SOFT: sb.append("/s"); break; |
| 424 | default: sb.append("/"); sb.append(keyboardHidden); break; |
| 425 | } |
| 426 | switch (hardKeyboardHidden) { |
| 427 | case HARDKEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break; |
| 428 | case HARDKEYBOARDHIDDEN_NO: sb.append("/v"); break; |
| 429 | case HARDKEYBOARDHIDDEN_YES: sb.append("/h"); break; |
| 430 | default: sb.append("/"); sb.append(hardKeyboardHidden); break; |
| 431 | } |
| 432 | switch (navigation) { |
| 433 | case NAVIGATION_UNDEFINED: sb.append(" ?nav"); break; |
| 434 | case NAVIGATION_NONAV: sb.append(" -nav"); break; |
| 435 | case NAVIGATION_DPAD: sb.append(" dpad"); break; |
| 436 | case NAVIGATION_TRACKBALL: sb.append(" tball"); break; |
| 437 | case NAVIGATION_WHEEL: sb.append(" wheel"); break; |
| 438 | default: sb.append(" nav="); sb.append(navigation); break; |
| 439 | } |
| 440 | switch (navigationHidden) { |
| 441 | case NAVIGATIONHIDDEN_UNDEFINED: sb.append("/?"); break; |
| 442 | case NAVIGATIONHIDDEN_NO: sb.append("/v"); break; |
| 443 | case NAVIGATIONHIDDEN_YES: sb.append("/h"); break; |
| 444 | default: sb.append("/"); sb.append(navigationHidden); break; |
| 445 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 446 | if (seq != 0) { |
Dianne Hackborn | 9a84983 | 2011-04-07 15:11:57 -0700 | [diff] [blame] | 447 | sb.append(" s."); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 448 | sb.append(seq); |
| 449 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 450 | sb.append('}'); |
| 451 | return sb.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /** |
| 455 | * Set this object to the system defaults. |
| 456 | */ |
| 457 | public void setToDefaults() { |
| 458 | fontScale = 1; |
| 459 | mcc = mnc = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 460 | locale = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | userSetLocale = false; |
| 462 | touchscreen = TOUCHSCREEN_UNDEFINED; |
| 463 | keyboard = KEYBOARD_UNDEFINED; |
| 464 | keyboardHidden = KEYBOARDHIDDEN_UNDEFINED; |
| 465 | hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED; |
| 466 | navigation = NAVIGATION_UNDEFINED; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 467 | navigationHidden = NAVIGATIONHIDDEN_UNDEFINED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | orientation = ORIENTATION_UNDEFINED; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 469 | screenLayout = SCREENLAYOUT_SIZE_UNDEFINED; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 470 | uiMode = UI_MODE_TYPE_UNDEFINED; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 471 | screenWidthDp = compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED; |
| 472 | screenHeightDp = compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED; |
| 473 | smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; |
Fabrice Di Meglio | a47f45e | 2011-06-15 14:22:12 -0700 | [diff] [blame] | 474 | textLayoutDirection = LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 475 | seq = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | /** {@hide} */ |
| 479 | @Deprecated public void makeDefault() { |
| 480 | setToDefaults(); |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Copy the fields from delta into this Configuration object, keeping |
| 485 | * track of which ones have changed. Any undefined fields in |
| 486 | * <var>delta</var> are ignored and not copied in to the current |
| 487 | * Configuration. |
| 488 | * @return Returns a bit mask of the changed fields, as per |
| 489 | * {@link #diff}. |
| 490 | */ |
| 491 | public int updateFrom(Configuration delta) { |
| 492 | int changed = 0; |
| 493 | if (delta.fontScale > 0 && fontScale != delta.fontScale) { |
| 494 | changed |= ActivityInfo.CONFIG_FONT_SCALE; |
| 495 | fontScale = delta.fontScale; |
| 496 | } |
| 497 | if (delta.mcc != 0 && mcc != delta.mcc) { |
| 498 | changed |= ActivityInfo.CONFIG_MCC; |
| 499 | mcc = delta.mcc; |
| 500 | } |
| 501 | if (delta.mnc != 0 && mnc != delta.mnc) { |
| 502 | changed |= ActivityInfo.CONFIG_MNC; |
| 503 | mnc = delta.mnc; |
| 504 | } |
| 505 | if (delta.locale != null |
| 506 | && (locale == null || !locale.equals(delta.locale))) { |
| 507 | changed |= ActivityInfo.CONFIG_LOCALE; |
| 508 | locale = delta.locale != null |
| 509 | ? (Locale) delta.locale.clone() : null; |
Fabrice Di Meglio | a47f45e | 2011-06-15 14:22:12 -0700 | [diff] [blame] | 510 | textLayoutDirection = LocaleUtil.getLayoutDirectionFromLocale(locale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | } |
| 512 | if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0))) |
| 513 | { |
| 514 | userSetLocale = true; |
| 515 | changed |= ActivityInfo.CONFIG_LOCALE; |
| 516 | } |
| 517 | if (delta.touchscreen != TOUCHSCREEN_UNDEFINED |
| 518 | && touchscreen != delta.touchscreen) { |
| 519 | changed |= ActivityInfo.CONFIG_TOUCHSCREEN; |
| 520 | touchscreen = delta.touchscreen; |
| 521 | } |
| 522 | if (delta.keyboard != KEYBOARD_UNDEFINED |
| 523 | && keyboard != delta.keyboard) { |
| 524 | changed |= ActivityInfo.CONFIG_KEYBOARD; |
| 525 | keyboard = delta.keyboard; |
| 526 | } |
| 527 | if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED |
| 528 | && keyboardHidden != delta.keyboardHidden) { |
| 529 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 530 | keyboardHidden = delta.keyboardHidden; |
| 531 | } |
| 532 | if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED |
| 533 | && hardKeyboardHidden != delta.hardKeyboardHidden) { |
| 534 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 535 | hardKeyboardHidden = delta.hardKeyboardHidden; |
| 536 | } |
| 537 | if (delta.navigation != NAVIGATION_UNDEFINED |
| 538 | && navigation != delta.navigation) { |
| 539 | changed |= ActivityInfo.CONFIG_NAVIGATION; |
| 540 | navigation = delta.navigation; |
| 541 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 542 | if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED |
| 543 | && navigationHidden != delta.navigationHidden) { |
| 544 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 545 | navigationHidden = delta.navigationHidden; |
| 546 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | if (delta.orientation != ORIENTATION_UNDEFINED |
| 548 | && orientation != delta.orientation) { |
| 549 | changed |= ActivityInfo.CONFIG_ORIENTATION; |
| 550 | orientation = delta.orientation; |
| 551 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 552 | if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 553 | && screenLayout != delta.screenLayout) { |
| 554 | changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 555 | screenLayout = delta.screenLayout; |
| 556 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 557 | if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED) |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 558 | && uiMode != delta.uiMode) { |
| 559 | changed |= ActivityInfo.CONFIG_UI_MODE; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 560 | if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) { |
| 561 | uiMode = (uiMode&~UI_MODE_TYPE_MASK) |
| 562 | | (delta.uiMode&UI_MODE_TYPE_MASK); |
| 563 | } |
| 564 | if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) { |
| 565 | uiMode = (uiMode&~UI_MODE_NIGHT_MASK) |
| 566 | | (delta.uiMode&UI_MODE_NIGHT_MASK); |
| 567 | } |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 568 | } |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 569 | if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED |
| 570 | && screenWidthDp != delta.screenWidthDp) { |
| 571 | changed |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 572 | screenWidthDp = delta.screenWidthDp; |
| 573 | } |
| 574 | if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED |
| 575 | && screenHeightDp != delta.screenHeightDp) { |
| 576 | changed |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 577 | screenHeightDp = delta.screenHeightDp; |
| 578 | } |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 579 | if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 580 | smallestScreenWidthDp = delta.smallestScreenWidthDp; |
| 581 | } |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 582 | if (delta.compatScreenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) { |
| 583 | compatScreenWidthDp = delta.compatScreenWidthDp; |
| 584 | } |
| 585 | if (delta.compatScreenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) { |
| 586 | compatScreenHeightDp = delta.compatScreenHeightDp; |
| 587 | } |
| 588 | if (delta.compatSmallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) { |
| 589 | compatSmallestScreenWidthDp = delta.compatSmallestScreenWidthDp; |
| 590 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 592 | if (delta.seq != 0) { |
| 593 | seq = delta.seq; |
| 594 | } |
| 595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | return changed; |
| 597 | } |
| 598 | |
| 599 | /** |
| 600 | * Return a bit mask of the differences between this Configuration |
| 601 | * object and the given one. Does not change the values of either. Any |
| 602 | * undefined fields in <var>delta</var> are ignored. |
| 603 | * @return Returns a bit mask indicating which configuration |
| 604 | * values has changed, containing any combination of |
| 605 | * {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE |
| 606 | * PackageManager.ActivityInfo.CONFIG_FONT_SCALE}, |
| 607 | * {@link android.content.pm.ActivityInfo#CONFIG_MCC |
| 608 | * PackageManager.ActivityInfo.CONFIG_MCC}, |
| 609 | * {@link android.content.pm.ActivityInfo#CONFIG_MNC |
| 610 | * PackageManager.ActivityInfo.CONFIG_MNC}, |
| 611 | * {@link android.content.pm.ActivityInfo#CONFIG_LOCALE |
| 612 | * PackageManager.ActivityInfo.CONFIG_LOCALE}, |
| 613 | * {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN |
| 614 | * PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN}, |
| 615 | * {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD |
| 616 | * PackageManager.ActivityInfo.CONFIG_KEYBOARD}, |
| 617 | * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 618 | * PackageManager.ActivityInfo.CONFIG_NAVIGATION}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 620 | * PackageManager.ActivityInfo.CONFIG_ORIENTATION}, |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 621 | * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 622 | * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}, or |
| 623 | * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 624 | * PackageManager.ActivityInfo.CONFIG_SCREEN_SIZE}, or |
| 625 | * {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE |
| 626 | * PackageManager.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | */ |
| 628 | public int diff(Configuration delta) { |
| 629 | int changed = 0; |
| 630 | if (delta.fontScale > 0 && fontScale != delta.fontScale) { |
| 631 | changed |= ActivityInfo.CONFIG_FONT_SCALE; |
| 632 | } |
| 633 | if (delta.mcc != 0 && mcc != delta.mcc) { |
| 634 | changed |= ActivityInfo.CONFIG_MCC; |
| 635 | } |
| 636 | if (delta.mnc != 0 && mnc != delta.mnc) { |
| 637 | changed |= ActivityInfo.CONFIG_MNC; |
| 638 | } |
| 639 | if (delta.locale != null |
| 640 | && (locale == null || !locale.equals(delta.locale))) { |
| 641 | changed |= ActivityInfo.CONFIG_LOCALE; |
| 642 | } |
| 643 | if (delta.touchscreen != TOUCHSCREEN_UNDEFINED |
| 644 | && touchscreen != delta.touchscreen) { |
| 645 | changed |= ActivityInfo.CONFIG_TOUCHSCREEN; |
| 646 | } |
| 647 | if (delta.keyboard != KEYBOARD_UNDEFINED |
| 648 | && keyboard != delta.keyboard) { |
| 649 | changed |= ActivityInfo.CONFIG_KEYBOARD; |
| 650 | } |
| 651 | if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED |
| 652 | && keyboardHidden != delta.keyboardHidden) { |
| 653 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 654 | } |
| 655 | if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED |
| 656 | && hardKeyboardHidden != delta.hardKeyboardHidden) { |
| 657 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 658 | } |
| 659 | if (delta.navigation != NAVIGATION_UNDEFINED |
| 660 | && navigation != delta.navigation) { |
| 661 | changed |= ActivityInfo.CONFIG_NAVIGATION; |
| 662 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 663 | if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED |
| 664 | && navigationHidden != delta.navigationHidden) { |
| 665 | changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN; |
| 666 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | if (delta.orientation != ORIENTATION_UNDEFINED |
| 668 | && orientation != delta.orientation) { |
| 669 | changed |= ActivityInfo.CONFIG_ORIENTATION; |
| 670 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 671 | if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 672 | && screenLayout != delta.screenLayout) { |
| 673 | changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 674 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 675 | if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED) |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 676 | && uiMode != delta.uiMode) { |
| 677 | changed |= ActivityInfo.CONFIG_UI_MODE; |
| 678 | } |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 679 | if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED |
| 680 | && screenWidthDp != delta.screenWidthDp) { |
| 681 | changed |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 682 | } |
| 683 | if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED |
| 684 | && screenHeightDp != delta.screenHeightDp) { |
| 685 | changed |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 686 | } |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 687 | if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED |
| 688 | && smallestScreenWidthDp != delta.smallestScreenWidthDp) { |
| 689 | changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
| 690 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | |
| 692 | return changed; |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * Determine if a new resource needs to be loaded from the bit set of |
| 697 | * configuration changes returned by {@link #updateFrom(Configuration)}. |
| 698 | * |
| 699 | * @param configChanges The mask of changes configurations as returned by |
| 700 | * {@link #updateFrom(Configuration)}. |
| 701 | * @param interestingChanges The configuration changes that the resource |
| 702 | * can handled, as given in {@link android.util.TypedValue#changingConfigurations}. |
| 703 | * |
| 704 | * @return Return true if the resource needs to be loaded, else false. |
| 705 | */ |
| 706 | public static boolean needNewResources(int configChanges, int interestingChanges) { |
| 707 | return (configChanges & (interestingChanges|ActivityInfo.CONFIG_FONT_SCALE)) != 0; |
| 708 | } |
| 709 | |
| 710 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 711 | * @hide Return true if the sequence of 'other' is better than this. Assumes |
| 712 | * that 'this' is your current sequence and 'other' is a new one you have |
| 713 | * received some how and want to compare with what you have. |
| 714 | */ |
| 715 | public boolean isOtherSeqNewer(Configuration other) { |
| 716 | if (other == null) { |
| 717 | // Sanity check. |
| 718 | return false; |
| 719 | } |
| 720 | if (other.seq == 0) { |
| 721 | // If the other sequence is not specified, then we must assume |
| 722 | // it is newer since we don't know any better. |
| 723 | return true; |
| 724 | } |
| 725 | if (seq == 0) { |
| 726 | // If this sequence is not specified, then we also consider the |
| 727 | // other is better. Yes we have a preference for other. Sue us. |
| 728 | return true; |
| 729 | } |
| 730 | int diff = other.seq - seq; |
| 731 | if (diff > 0x10000) { |
| 732 | // If there has been a sufficiently large jump, assume the |
| 733 | // sequence has wrapped around. |
| 734 | return false; |
| 735 | } |
| 736 | return diff > 0; |
| 737 | } |
| 738 | |
| 739 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | * Parcelable methods |
| 741 | */ |
| 742 | public int describeContents() { |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | public void writeToParcel(Parcel dest, int flags) { |
| 747 | dest.writeFloat(fontScale); |
| 748 | dest.writeInt(mcc); |
| 749 | dest.writeInt(mnc); |
| 750 | if (locale == null) { |
| 751 | dest.writeInt(0); |
| 752 | } else { |
| 753 | dest.writeInt(1); |
| 754 | dest.writeString(locale.getLanguage()); |
| 755 | dest.writeString(locale.getCountry()); |
| 756 | dest.writeString(locale.getVariant()); |
| 757 | } |
| 758 | if(userSetLocale) { |
| 759 | dest.writeInt(1); |
| 760 | } else { |
| 761 | dest.writeInt(0); |
| 762 | } |
| 763 | dest.writeInt(touchscreen); |
| 764 | dest.writeInt(keyboard); |
| 765 | dest.writeInt(keyboardHidden); |
| 766 | dest.writeInt(hardKeyboardHidden); |
| 767 | dest.writeInt(navigation); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 768 | dest.writeInt(navigationHidden); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | dest.writeInt(orientation); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 770 | dest.writeInt(screenLayout); |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 771 | dest.writeInt(uiMode); |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 772 | dest.writeInt(screenWidthDp); |
| 773 | dest.writeInt(screenHeightDp); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 774 | dest.writeInt(smallestScreenWidthDp); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 775 | dest.writeInt(compatScreenWidthDp); |
| 776 | dest.writeInt(compatScreenHeightDp); |
| 777 | dest.writeInt(compatSmallestScreenWidthDp); |
Fabrice Di Meglio | 7a736fb | 2011-06-09 20:20:36 -0700 | [diff] [blame] | 778 | dest.writeInt(textLayoutDirection); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 779 | dest.writeInt(seq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | } |
| 781 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 782 | public void readFromParcel(Parcel source) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | fontScale = source.readFloat(); |
| 784 | mcc = source.readInt(); |
| 785 | mnc = source.readInt(); |
| 786 | if (source.readInt() != 0) { |
| 787 | locale = new Locale(source.readString(), source.readString(), |
| 788 | source.readString()); |
| 789 | } |
| 790 | userSetLocale = (source.readInt()==1); |
| 791 | touchscreen = source.readInt(); |
| 792 | keyboard = source.readInt(); |
| 793 | keyboardHidden = source.readInt(); |
| 794 | hardKeyboardHidden = source.readInt(); |
| 795 | navigation = source.readInt(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 796 | navigationHidden = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | orientation = source.readInt(); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 798 | screenLayout = source.readInt(); |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 799 | uiMode = source.readInt(); |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 800 | screenWidthDp = source.readInt(); |
| 801 | screenHeightDp = source.readInt(); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 802 | smallestScreenWidthDp = source.readInt(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 803 | compatScreenWidthDp = source.readInt(); |
| 804 | compatScreenHeightDp = source.readInt(); |
| 805 | compatSmallestScreenWidthDp = source.readInt(); |
Fabrice Di Meglio | 7a736fb | 2011-06-09 20:20:36 -0700 | [diff] [blame] | 806 | textLayoutDirection = source.readInt(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 807 | seq = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 809 | |
| 810 | public static final Parcelable.Creator<Configuration> CREATOR |
| 811 | = new Parcelable.Creator<Configuration>() { |
| 812 | public Configuration createFromParcel(Parcel source) { |
| 813 | return new Configuration(source); |
| 814 | } |
| 815 | |
| 816 | public Configuration[] newArray(int size) { |
| 817 | return new Configuration[size]; |
| 818 | } |
| 819 | }; |
| 820 | |
| 821 | /** |
| 822 | * Construct this Configuration object, reading from the Parcel. |
| 823 | */ |
| 824 | private Configuration(Parcel source) { |
| 825 | readFromParcel(source); |
| 826 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | |
| 828 | public int compareTo(Configuration that) { |
| 829 | int n; |
| 830 | float a = this.fontScale; |
| 831 | float b = that.fontScale; |
| 832 | if (a < b) return -1; |
| 833 | if (a > b) return 1; |
| 834 | n = this.mcc - that.mcc; |
| 835 | if (n != 0) return n; |
| 836 | n = this.mnc - that.mnc; |
| 837 | if (n != 0) return n; |
Dianne Hackborn | a839703 | 2010-03-12 10:52:22 -0800 | [diff] [blame] | 838 | if (this.locale == null) { |
| 839 | if (that.locale != null) return 1; |
| 840 | } else if (that.locale == null) { |
| 841 | return -1; |
| 842 | } else { |
| 843 | n = this.locale.getLanguage().compareTo(that.locale.getLanguage()); |
| 844 | if (n != 0) return n; |
| 845 | n = this.locale.getCountry().compareTo(that.locale.getCountry()); |
| 846 | if (n != 0) return n; |
| 847 | n = this.locale.getVariant().compareTo(that.locale.getVariant()); |
| 848 | if (n != 0) return n; |
| 849 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | n = this.touchscreen - that.touchscreen; |
| 851 | if (n != 0) return n; |
| 852 | n = this.keyboard - that.keyboard; |
| 853 | if (n != 0) return n; |
| 854 | n = this.keyboardHidden - that.keyboardHidden; |
| 855 | if (n != 0) return n; |
| 856 | n = this.hardKeyboardHidden - that.hardKeyboardHidden; |
| 857 | if (n != 0) return n; |
| 858 | n = this.navigation - that.navigation; |
| 859 | if (n != 0) return n; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 860 | n = this.navigationHidden - that.navigationHidden; |
| 861 | if (n != 0) return n; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 862 | n = this.orientation - that.orientation; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 863 | if (n != 0) return n; |
| 864 | n = this.screenLayout - that.screenLayout; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 865 | if (n != 0) return n; |
| 866 | n = this.uiMode - that.uiMode; |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 867 | if (n != 0) return n; |
| 868 | n = this.screenWidthDp - that.screenWidthDp; |
| 869 | if (n != 0) return n; |
| 870 | n = this.screenHeightDp - that.screenHeightDp; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 871 | if (n != 0) return n; |
| 872 | n = this.smallestScreenWidthDp - that.smallestScreenWidthDp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 873 | //if (n != 0) return n; |
| 874 | return n; |
| 875 | } |
| 876 | |
| 877 | public boolean equals(Configuration that) { |
| 878 | if (that == null) return false; |
| 879 | if (that == this) return true; |
| 880 | return this.compareTo(that) == 0; |
| 881 | } |
| 882 | |
| 883 | public boolean equals(Object that) { |
| 884 | try { |
| 885 | return equals((Configuration)that); |
| 886 | } catch (ClassCastException e) { |
| 887 | } |
| 888 | return false; |
| 889 | } |
| 890 | |
| 891 | public int hashCode() { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 892 | int result = 17; |
| 893 | result = 31 * result + Float.floatToIntBits(fontScale); |
| 894 | result = 31 * result + mcc; |
| 895 | result = 31 * result + mnc; |
| 896 | result = 31 * result + (locale != null ? locale.hashCode() : 0); |
| 897 | result = 31 * result + touchscreen; |
| 898 | result = 31 * result + keyboard; |
| 899 | result = 31 * result + keyboardHidden; |
| 900 | result = 31 * result + hardKeyboardHidden; |
| 901 | result = 31 * result + navigation; |
| 902 | result = 31 * result + navigationHidden; |
| 903 | result = 31 * result + orientation; |
| 904 | result = 31 * result + screenLayout; |
| 905 | result = 31 * result + uiMode; |
Dianne Hackborn | ebff8f9 | 2011-05-12 18:07:47 -0700 | [diff] [blame] | 906 | result = 31 * result + screenWidthDp; |
| 907 | result = 31 * result + screenHeightDp; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 908 | result = 31 * result + smallestScreenWidthDp; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 909 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | } |
| 911 | } |