1 /* 2 * Copyright (C) 2009 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 17 package android.content.res.cts; 18 19 import java.util.Locale; 20 21 import android.content.res.AssetManager; 22 import android.content.res.Configuration; 23 import android.content.res.Resources; 24 import android.content.res.TypedArray; 25 import android.content.res.Resources.NotFoundException; 26 import android.test.AndroidTestCase; 27 import android.test.suitebuilder.annotation.MediumTest; 28 import android.test.suitebuilder.annotation.SmallTest; 29 import android.util.DisplayMetrics; 30 import android.util.Log; 31 32 import com.android.cts.stub.R; 33 34 public class ConfigTest extends AndroidTestCase { 35 enum Properties { 36 LANGUAGE, 37 COUNTRY, 38 MCC, 39 MNC, 40 TOUCHSCREEN, 41 KEYBOARD, 42 KEYBOARDHIDDEN, 43 NAVIGATION, 44 ORIENTATION, 45 WIDTH, 46 HEIGHT, 47 DENSITY, 48 SCREENLAYOUT, 49 SWIDTH_DP, 50 WIDTH_DP, 51 HEIGHT_DP 52 } 53 54 private static void checkValue(final Resources res, final int resId, 55 final String expectedValue) { 56 try { 57 final String actual = res.getString(resId); 58 assertNotNull("Returned wrong configuration-based simple value: expected <nothing>, " 59 + "got '" + actual + "' from resource 0x" + Integer.toHexString(resId), 60 expectedValue); 61 assertEquals("Returned wrong configuration-based simple value: expected '" 62 + expectedValue + "', got '" + actual + "' from resource 0x" 63 + Integer.toHexString(resId), expectedValue, actual); 64 } catch (NotFoundException e) { 65 assertNull("Resource not found for configuration-based simple value: expecting \"" 66 + expectedValue + "\"", expectedValue); 67 } 68 } 69 70 private static void checkValue(final Resources res, final int resId, 71 final int[] styleable, final String[] expectedValues) { 72 final Resources.Theme theme = res.newTheme(); 73 final TypedArray sa = theme.obtainStyledAttributes(resId, styleable); 74 for (int i = 0; i < styleable.length; i++) { 75 final String actual = sa.getString(i); 76 assertEquals("Returned wrong configuration-based style value: expected '" 77 + expectedValues[i] + "', got '" + actual + "' from attr " 78 + i + " of resource 0x" + Integer.toHexString(resId), 79 actual, expectedValues[i]); 80 } 81 sa.recycle(); 82 } 83 84 private class TotalConfig { 85 final Configuration mConfig; 86 final DisplayMetrics mMetrics; 87 88 public TotalConfig() { 89 mConfig = new Configuration(); 90 mMetrics = new DisplayMetrics(); 91 mConfig.locale = new Locale("++", "++"); 92 } 93 94 public void setProperty(final Properties p, final int value) { 95 switch(p) { 96 case MCC: 97 mConfig.mcc = value; 98 break; 99 case MNC: 100 mConfig.mnc = value; 101 break; 102 case TOUCHSCREEN: 103 mConfig.touchscreen = value; 104 break; 105 case KEYBOARD: 106 mConfig.keyboard = value; 107 break; 108 case KEYBOARDHIDDEN: 109 mConfig.keyboardHidden = value; 110 break; 111 case NAVIGATION: 112 mConfig.navigation = value; 113 break; 114 case ORIENTATION: 115 mConfig.orientation = value; 116 break; 117 case WIDTH: 118 mMetrics.widthPixels = value; 119 mMetrics.noncompatWidthPixels = value; 120 break; 121 case HEIGHT: 122 mMetrics.heightPixels = value; 123 mMetrics.noncompatHeightPixels = value; 124 break; 125 case DENSITY: 126 // this is the ratio from the standard 127 mMetrics.density = (((float)value)/((float)DisplayMetrics.DENSITY_DEFAULT)); 128 mMetrics.noncompatDensity = mMetrics.density; 129 mConfig.densityDpi = value; 130 break; 131 case SCREENLAYOUT: 132 mConfig.screenLayout = value; 133 break; 134 case SWIDTH_DP: 135 mConfig.smallestScreenWidthDp = value; 136 break; 137 case WIDTH_DP: 138 mConfig.screenWidthDp = value; 139 break; 140 case HEIGHT_DP: 141 mConfig.screenHeightDp = value; 142 break; 143 default: 144 assert(false); 145 break; 146 } 147 } 148 149 public void setProperty(final Properties p, final String value) { 150 switch(p) { 151 case LANGUAGE: 152 final String oldCountry = mConfig.locale.getCountry(); 153 mConfig.locale = new Locale(value, oldCountry); 154 break; 155 case COUNTRY: 156 final String oldLanguage = mConfig.locale.getLanguage(); 157 mConfig.locale = new Locale(oldLanguage, value); 158 break; 159 default: 160 assert(false); 161 break; 162 } 163 } 164 165 public Resources getResources() { 166 final AssetManager assmgr = new AssetManager(); 167 assmgr.addAssetPath(mContext.getPackageResourcePath()); 168 return new Resources(assmgr, mMetrics, mConfig); 169 } 170 } 171 172 public TotalConfig makeEmptyConfig() { 173 return new TotalConfig(); 174 } 175 176 public TotalConfig makeClassicConfig() { 177 TotalConfig config = new TotalConfig(); 178 config.setProperty(Properties.LANGUAGE, "en"); 179 config.setProperty(Properties.COUNTRY, "US"); 180 config.setProperty(Properties.MCC, 310); 181 config.setProperty(Properties.MNC, 001); // unused 182 config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_FINGER); 183 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_QWERTY); 184 config.setProperty(Properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_YES); 185 config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_TRACKBALL); 186 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_PORTRAIT); 187 config.setProperty(Properties.SWIDTH_DP, 320); 188 config.setProperty(Properties.WIDTH_DP, 320); 189 config.setProperty(Properties.HEIGHT_DP, 480); 190 config.setProperty(Properties.DENSITY, 160); 191 config.setProperty(Properties.WIDTH, 200); 192 config.setProperty(Properties.HEIGHT, 320); 193 return config; 194 } 195 196 private static void checkPair(Resources res, int[] notResIds, 197 int simpleRes, String simpleString, 198 int bagRes, String bagString) { 199 boolean willHave = true; 200 if (notResIds != null) { 201 for (int i : notResIds) { 202 if (i == simpleRes) { 203 willHave = false; 204 break; 205 } 206 } 207 } 208 checkValue(res, simpleRes, willHave ? simpleString : null); 209 checkValue(res, bagRes, R.styleable.TestConfig, 210 new String[]{willHave ? bagString : null}); 211 } 212 213 @SmallTest 214 public void testAllEmptyConfigs() { 215 /** 216 * Test a resource that contains a value for each possible single 217 * configuration value. 218 */ 219 TotalConfig config = makeEmptyConfig(); 220 Resources res = config.getResources(); 221 checkValue(res, R.configVarying.simple, "simple default"); 222 checkValue(res, R.configVarying.bag, 223 R.styleable.TestConfig, new String[]{"bag default"}); 224 225 config = makeEmptyConfig(); 226 config.setProperty(Properties.LANGUAGE, "xx"); 227 res = config.getResources(); 228 checkValue(res, R.configVarying.simple, "simple xx"); 229 checkValue(res, R.configVarying.bag, 230 R.styleable.TestConfig, new String[]{"bag xx"}); 231 232 config = makeEmptyConfig(); 233 config.setProperty(Properties.LANGUAGE, "xx"); 234 config.setProperty(Properties.COUNTRY, "YY"); 235 res = config.getResources(); 236 checkValue(res, R.configVarying.simple, "simple xx-rYY"); 237 checkValue(res, R.configVarying.bag, 238 R.styleable.TestConfig, new String[]{"bag xx-rYY"}); 239 240 config = makeEmptyConfig(); 241 config.setProperty(Properties.MCC, 111); 242 res = config.getResources(); 243 checkValue(res, R.configVarying.simple, "simple mcc111"); 244 checkValue(res, R.configVarying.bag, 245 R.styleable.TestConfig, new String[]{"bag mcc111"}); 246 247 config = makeEmptyConfig(); 248 config.setProperty(Properties.MNC, 222); 249 res = config.getResources(); 250 checkValue(res, R.configVarying.simple, "simple mnc222"); 251 checkValue(res, R.configVarying.bag, 252 R.styleable.TestConfig, new String[]{"bag mnc222"}); 253 254 config = makeEmptyConfig(); 255 config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_NOTOUCH); 256 res = config.getResources(); 257 checkValue(res, R.configVarying.simple, "simple notouch"); 258 checkValue(res, R.configVarying.bag, 259 R.styleable.TestConfig, new String[]{"bag notouch"}); 260 261 config = makeEmptyConfig(); 262 config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_STYLUS); 263 res = config.getResources(); 264 checkValue(res, R.configVarying.simple, "simple stylus"); 265 checkValue(res, R.configVarying.bag, 266 R.styleable.TestConfig, new String[]{"bag stylus"}); 267 268 config = makeEmptyConfig(); 269 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_NOKEYS); 270 res = config.getResources(); 271 checkValue(res, R.configVarying.simple, "simple nokeys"); 272 checkValue(res, R.configVarying.bag, 273 R.styleable.TestConfig, new String[]{"bag nokeys"}); 274 275 config = makeEmptyConfig(); 276 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY); 277 res = config.getResources(); 278 checkValue(res, R.configVarying.simple, "simple 12key"); 279 checkValue(res, R.configVarying.bag, 280 R.styleable.TestConfig, new String[]{"bag 12key"}); 281 282 config = makeEmptyConfig(); 283 config.setProperty(Properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_NO); 284 res = config.getResources(); 285 checkValue(res, R.configVarying.simple, "simple keysexposed"); 286 checkValue(res, R.configVarying.bag, 287 R.styleable.TestConfig, new String[]{"bag keysexposed"}); 288 289 config = makeEmptyConfig(); 290 config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_NONAV); 291 res = config.getResources(); 292 checkValue(res, R.configVarying.simple, "simple nonav"); 293 checkValue(res, R.configVarying.bag, 294 R.styleable.TestConfig, new String[]{"bag nonav"}); 295 296 config = makeEmptyConfig(); 297 config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_DPAD); 298 res = config.getResources(); 299 checkValue(res, R.configVarying.simple, "simple dpad"); 300 checkValue(res, R.configVarying.bag, 301 R.styleable.TestConfig, new String[]{"bag dpad"}); 302 303 config = makeEmptyConfig(); 304 config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_WHEEL); 305 res = config.getResources(); 306 checkValue(res, R.configVarying.simple, "simple wheel"); 307 checkValue(res, R.configVarying.bag, 308 R.styleable.TestConfig, new String[]{"bag wheel"}); 309 310 config = makeEmptyConfig(); 311 config.setProperty(Properties.HEIGHT, 480); 312 config.setProperty(Properties.WIDTH, 320); 313 res = config.getResources(); 314 checkValue(res, R.configVarying.simple, "simple 480x320"); 315 checkValue(res, R.configVarying.bag, 316 R.styleable.TestConfig, new String[]{"bag 480x320"}); 317 318 config = makeEmptyConfig(); 319 config.setProperty(Properties.DENSITY, 240); 320 res = config.getResources(); 321 checkValue(res, R.configVarying.simple, "simple 240dpi"); 322 checkValue(res, R.configVarying.bag, 323 R.styleable.TestConfig, new String[]{"bag 240dpi"}); 324 325 config = makeEmptyConfig(); 326 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE); 327 res = config.getResources(); 328 checkValue(res, R.configVarying.simple, "simple landscape"); 329 checkValue(res, R.configVarying.bag, 330 R.styleable.TestConfig, new String[]{"bag landscape"}); 331 332 config = makeEmptyConfig(); 333 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_SQUARE); 334 res = config.getResources(); 335 checkValue(res, R.configVarying.simple, "simple square"); 336 checkValue(res, R.configVarying.bag, 337 R.styleable.TestConfig, new String[]{"bag square"}); 338 339 config = makeEmptyConfig(); 340 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_SMALL); 341 res = config.getResources(); 342 checkValue(res, R.configVarying.simple, "simple small"); 343 checkValue(res, R.configVarying.bag, 344 R.styleable.TestConfig, new String[]{"bag small"}); 345 346 config = makeEmptyConfig(); 347 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_NORMAL); 348 res = config.getResources(); 349 checkValue(res, R.configVarying.simple, "simple normal"); 350 checkValue(res, R.configVarying.bag, 351 R.styleable.TestConfig, new String[]{"bag normal"}); 352 353 config = makeEmptyConfig(); 354 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE); 355 res = config.getResources(); 356 checkValue(res, R.configVarying.simple, "simple large"); 357 checkValue(res, R.configVarying.bag, 358 R.styleable.TestConfig, new String[]{"bag large"}); 359 360 config = makeEmptyConfig(); 361 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE); 362 res = config.getResources(); 363 checkValue(res, R.configVarying.simple, "simple xlarge"); 364 checkValue(res, R.configVarying.bag, 365 R.styleable.TestConfig, new String[]{"bag xlarge"}); 366 367 config = makeEmptyConfig(); 368 config.setProperty(Properties.SWIDTH_DP, 600); 369 res = config.getResources(); 370 checkValue(res, R.configVarying.simple, "simple sw600"); 371 checkValue(res, R.configVarying.bag, 372 R.styleable.TestConfig, new String[]{"bag sw600"}); 373 374 config = makeEmptyConfig(); 375 config.setProperty(Properties.SWIDTH_DP, 600); 376 res = config.getResources(); 377 checkValue(res, R.configVarying.simple, "simple sw600"); 378 checkValue(res, R.configVarying.bag, 379 R.styleable.TestConfig, new String[]{"bag sw600"}); 380 381 config = makeEmptyConfig(); 382 config.setProperty(Properties.SWIDTH_DP, 720); 383 res = config.getResources(); 384 checkValue(res, R.configVarying.simple, "simple sw720"); 385 checkValue(res, R.configVarying.bag, 386 R.styleable.TestConfig, new String[]{"bag sw720"}); 387 388 config = makeEmptyConfig(); 389 config.setProperty(Properties.WIDTH_DP, 600); 390 res = config.getResources(); 391 checkValue(res, R.configVarying.simple, "simple w600"); 392 checkValue(res, R.configVarying.bag, 393 R.styleable.TestConfig, new String[]{"bag w600"}); 394 395 config = makeEmptyConfig(); 396 config.setProperty(Properties.WIDTH_DP, 720); 397 res = config.getResources(); 398 checkValue(res, R.configVarying.simple, "simple w720"); 399 checkValue(res, R.configVarying.bag, 400 R.styleable.TestConfig, new String[]{"bag w720"}); 401 402 config = makeEmptyConfig(); 403 config.setProperty(Properties.HEIGHT_DP, 550); 404 res = config.getResources(); 405 checkValue(res, R.configVarying.simple, "simple h550"); 406 checkValue(res, R.configVarying.bag, 407 R.styleable.TestConfig, new String[]{"bag h550"}); 408 409 config = makeEmptyConfig(); 410 config.setProperty(Properties.HEIGHT_DP, 670); 411 res = config.getResources(); 412 checkValue(res, R.configVarying.simple, "simple h670"); 413 checkValue(res, R.configVarying.bag, 414 R.styleable.TestConfig, new String[]{"bag h670"}); 415 } 416 417 @SmallTest 418 public void testAllClassicConfigs() { 419 /** 420 * Test a resource that contains a value for each possible single 421 * configuration value. 422 */ 423 TotalConfig config = makeClassicConfig(); 424 Resources res = config.getResources(); 425 checkValue(res, R.configVarying.simple, "simple default"); 426 checkValue(res, R.configVarying.bag, 427 R.styleable.TestConfig, new String[]{"bag default"}); 428 429 config = makeClassicConfig(); 430 config.setProperty(Properties.LANGUAGE, "xx"); 431 res = config.getResources(); 432 checkValue(res, R.configVarying.simple, "simple xx"); 433 checkValue(res, R.configVarying.bag, 434 R.styleable.TestConfig, new String[]{"bag xx"}); 435 436 config = makeClassicConfig(); 437 config.setProperty(Properties.LANGUAGE, "xx"); 438 config.setProperty(Properties.COUNTRY, "YY"); 439 res = config.getResources(); 440 checkValue(res, R.configVarying.simple, "simple xx-rYY"); 441 checkValue(res, R.configVarying.bag, 442 R.styleable.TestConfig, new String[]{"bag xx-rYY"}); 443 444 config = makeClassicConfig(); 445 config.setProperty(Properties.MCC, 111); 446 res = config.getResources(); 447 checkValue(res, R.configVarying.simple, "simple mcc111"); 448 checkValue(res, R.configVarying.bag, 449 R.styleable.TestConfig, new String[]{"bag mcc111"}); 450 451 config = makeClassicConfig(); 452 config.setProperty(Properties.MNC, 222); 453 res = config.getResources(); 454 checkValue(res, R.configVarying.simple, "simple mnc222"); 455 checkValue(res, R.configVarying.bag, 456 R.styleable.TestConfig, new String[]{"bag mnc222"}); 457 458 config = makeClassicConfig(); 459 config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_NOTOUCH); 460 res = config.getResources(); 461 checkValue(res, R.configVarying.simple, "simple notouch"); 462 checkValue(res, R.configVarying.bag, 463 R.styleable.TestConfig, new String[]{"bag notouch"}); 464 465 config = makeClassicConfig(); 466 config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_STYLUS); 467 res = config.getResources(); 468 checkValue(res, R.configVarying.simple, "simple stylus"); 469 checkValue(res, R.configVarying.bag, 470 R.styleable.TestConfig, new String[]{"bag stylus"}); 471 472 config = makeClassicConfig(); 473 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_NOKEYS); 474 res = config.getResources(); 475 checkValue(res, R.configVarying.simple, "simple nokeys"); 476 checkValue(res, R.configVarying.bag, 477 R.styleable.TestConfig, new String[]{"bag nokeys"}); 478 479 config = makeClassicConfig(); 480 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY); 481 res = config.getResources(); 482 checkValue(res, R.configVarying.simple, "simple 12key 63x57"); 483 checkValue(res, R.configVarying.bag, 484 R.styleable.TestConfig, new String[]{"bag 12key 63x57"}); 485 486 config = makeClassicConfig(); 487 config.setProperty(Properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_NO); 488 res = config.getResources(); 489 checkValue(res, R.configVarying.simple, "simple keysexposed"); 490 checkValue(res, R.configVarying.bag, 491 R.styleable.TestConfig, new String[]{"bag keysexposed"}); 492 493 config = makeClassicConfig(); 494 config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_NONAV); 495 res = config.getResources(); 496 checkValue(res, R.configVarying.simple, "simple nonav"); 497 checkValue(res, R.configVarying.bag, 498 R.styleable.TestConfig, new String[]{"bag nonav"}); 499 500 config = makeClassicConfig(); 501 config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_DPAD); 502 res = config.getResources(); 503 checkValue(res, R.configVarying.simple, "simple dpad 63x57"); 504 checkValue(res, R.configVarying.bag, 505 R.styleable.TestConfig, new String[]{"bag dpad 63x57"}); 506 507 config = makeClassicConfig(); 508 config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_WHEEL); 509 res = config.getResources(); 510 checkValue(res, R.configVarying.simple, "simple wheel"); 511 checkValue(res, R.configVarying.bag, 512 R.styleable.TestConfig, new String[]{"bag wheel"}); 513 514 config = makeClassicConfig(); 515 config.setProperty(Properties.HEIGHT, 480); 516 config.setProperty(Properties.WIDTH, 320); 517 res = config.getResources(); 518 checkValue(res, R.configVarying.simple, "simple 480x320"); 519 checkValue(res, R.configVarying.bag, 520 R.styleable.TestConfig, new String[]{"bag 480x320"}); 521 522 config = makeClassicConfig(); 523 config.setProperty(Properties.DENSITY, 240); 524 res = config.getResources(); 525 checkValue(res, R.configVarying.simple, "simple 240dpi"); 526 checkValue(res, R.configVarying.bag, 527 R.styleable.TestConfig, new String[]{"bag 240dpi"}); 528 529 config = makeClassicConfig(); 530 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE); 531 res = config.getResources(); 532 checkValue(res, R.configVarying.simple, "simple landscape"); 533 checkValue(res, R.configVarying.bag, 534 R.styleable.TestConfig, new String[]{"bag landscape"}); 535 536 config = makeClassicConfig(); 537 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_SQUARE); 538 res = config.getResources(); 539 checkValue(res, R.configVarying.simple, "simple square"); 540 checkValue(res, R.configVarying.bag, 541 R.styleable.TestConfig, new String[]{"bag square"}); 542 543 config = makeClassicConfig(); 544 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_SMALL); 545 res = config.getResources(); 546 checkValue(res, R.configVarying.simple, "simple small"); 547 checkValue(res, R.configVarying.bag, 548 R.styleable.TestConfig, new String[]{"bag small"}); 549 550 config = makeClassicConfig(); 551 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_NORMAL); 552 res = config.getResources(); 553 checkValue(res, R.configVarying.simple, "simple normal"); 554 checkValue(res, R.configVarying.bag, 555 R.styleable.TestConfig, new String[]{"bag normal"}); 556 557 config = makeClassicConfig(); 558 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE); 559 res = config.getResources(); 560 checkValue(res, R.configVarying.simple, "simple large"); 561 checkValue(res, R.configVarying.bag, 562 R.styleable.TestConfig, new String[]{"bag large"}); 563 564 config = makeClassicConfig(); 565 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE); 566 res = config.getResources(); 567 checkValue(res, R.configVarying.simple, "simple xlarge"); 568 checkValue(res, R.configVarying.bag, 569 R.styleable.TestConfig, new String[]{"bag xlarge"}); 570 571 config = makeClassicConfig(); 572 config.setProperty(Properties.SWIDTH_DP, 600); 573 res = config.getResources(); 574 checkValue(res, R.configVarying.simple, "simple sw600"); 575 checkValue(res, R.configVarying.bag, 576 R.styleable.TestConfig, new String[]{"bag sw600"}); 577 578 config = makeClassicConfig(); 579 config.setProperty(Properties.SWIDTH_DP, 600); 580 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE); 581 res = config.getResources(); 582 checkValue(res, R.configVarying.simple, "simple sw600 land"); 583 checkValue(res, R.configVarying.bag, 584 R.styleable.TestConfig, new String[]{"bag sw600 land"}); 585 586 config = makeClassicConfig(); 587 config.setProperty(Properties.SWIDTH_DP, 720); 588 res = config.getResources(); 589 checkValue(res, R.configVarying.simple, "simple sw720"); 590 checkValue(res, R.configVarying.bag, 591 R.styleable.TestConfig, new String[]{"bag sw720"}); 592 593 config = makeClassicConfig(); 594 config.setProperty(Properties.WIDTH_DP, 600); 595 res = config.getResources(); 596 checkValue(res, R.configVarying.simple, "simple w600"); 597 checkValue(res, R.configVarying.bag, 598 R.styleable.TestConfig, new String[]{"bag w600"}); 599 600 config = makeClassicConfig(); 601 config.setProperty(Properties.WIDTH_DP, 720); 602 res = config.getResources(); 603 checkValue(res, R.configVarying.simple, "simple w720"); 604 checkValue(res, R.configVarying.bag, 605 R.styleable.TestConfig, new String[]{"bag w720"}); 606 607 config = makeClassicConfig(); 608 config.setProperty(Properties.HEIGHT_DP, 550); 609 res = config.getResources(); 610 checkValue(res, R.configVarying.simple, "simple h550"); 611 checkValue(res, R.configVarying.bag, 612 R.styleable.TestConfig, new String[]{"bag h550"}); 613 614 config = makeClassicConfig(); 615 config.setProperty(Properties.HEIGHT_DP, 670); 616 res = config.getResources(); 617 checkValue(res, R.configVarying.simple, "simple h670"); 618 checkValue(res, R.configVarying.bag, 619 R.styleable.TestConfig, new String[]{"bag h670"}); 620 } 621 622 @MediumTest 623 public void testDensity() throws Exception { 624 // have 32, 240 and the default 160 content. 625 // rule is that closest wins, with down scaling (larger content) 626 // being twice as nice as upscaling. 627 // transition at H/2 * (-1 +/- sqrt(1+8L/H)) 628 // SO, X < 49 goes to 32 629 // 49 >= X < 182 goes to 160 630 // X >= 182 goes to 240 631 TotalConfig config = makeClassicConfig(); 632 config.setProperty(Properties.DENSITY, 2); 633 Resources res = config.getResources(); 634 checkValue(res, R.configVarying.simple, "simple 32dpi"); 635 checkValue(res, R.configVarying.bag, 636 R.styleable.TestConfig, new String[]{"bag 32dpi"}); 637 638 config = makeClassicConfig(); 639 config.setProperty(Properties.DENSITY, 32); 640 res = config.getResources(); 641 checkValue(res, R.configVarying.simple, "simple 32dpi"); 642 checkValue(res, R.configVarying.bag, 643 R.styleable.TestConfig, new String[]{"bag 32dpi"}); 644 645 config = makeClassicConfig(); 646 config.setProperty(Properties.DENSITY, 48); 647 res = config.getResources(); 648 checkValue(res, R.configVarying.simple, "simple 32dpi"); 649 checkValue(res, R.configVarying.bag, 650 R.styleable.TestConfig, new String[]{"bag 32dpi"}); 651 652 config = makeClassicConfig(); 653 config.setProperty(Properties.DENSITY, 49); 654 res = config.getResources(); 655 checkValue(res, R.configVarying.simple, "simple default"); 656 checkValue(res, R.configVarying.bag, 657 R.styleable.TestConfig, new String[]{"bag default"}); 658 659 config = makeClassicConfig(); 660 config.setProperty(Properties.DENSITY, 150); 661 res = config.getResources(); 662 checkValue(res, R.configVarying.simple, "simple default"); 663 checkValue(res, R.configVarying.bag, 664 R.styleable.TestConfig, new String[]{"bag default"}); 665 666 config = makeClassicConfig(); 667 config.setProperty(Properties.DENSITY, 181); 668 res = config.getResources(); 669 checkValue(res, R.configVarying.simple, "simple default"); 670 checkValue(res, R.configVarying.bag, 671 R.styleable.TestConfig, new String[]{"bag default"}); 672 673 config = makeClassicConfig(); 674 config.setProperty(Properties.DENSITY, 182); 675 res = config.getResources(); 676 checkValue(res, R.configVarying.simple, "simple 240dpi"); 677 checkValue(res, R.configVarying.bag, 678 R.styleable.TestConfig, new String[]{"bag 240dpi"}); 679 680 config = makeClassicConfig(); 681 config.setProperty(Properties.DENSITY, 239); 682 res = config.getResources(); 683 checkValue(res, R.configVarying.simple, "simple 240dpi"); 684 checkValue(res, R.configVarying.bag, 685 R.styleable.TestConfig, new String[]{"bag 240dpi"}); 686 687 config = makeClassicConfig(); 688 config.setProperty(Properties.DENSITY, 490); 689 res = config.getResources(); 690 checkValue(res, R.configVarying.simple, "simple 240dpi"); 691 checkValue(res, R.configVarying.bag, 692 R.styleable.TestConfig, new String[]{"bag 240dpi"}); 693 } 694 695 @MediumTest 696 public void testScreenSize() throws Exception { 697 // ensure that we fall back to the best available screen size 698 // for a given configuration. 699 TotalConfig config = makeClassicConfig(); 700 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_SMALL); 701 Resources res = config.getResources(); 702 checkValue(res, R.configVarying.simple, "simple small"); 703 checkValue(res, R.configVarying.small, "small"); 704 checkValue(res, R.configVarying.normal, "default"); 705 checkValue(res, R.configVarying.large, "default"); 706 checkValue(res, R.configVarying.xlarge, "default"); 707 708 config = makeClassicConfig(); 709 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_NORMAL); 710 res = config.getResources(); 711 checkValue(res, R.configVarying.simple, "simple normal"); 712 checkValue(res, R.configVarying.small, "default"); 713 checkValue(res, R.configVarying.normal, "normal"); 714 checkValue(res, R.configVarying.large, "default"); 715 checkValue(res, R.configVarying.xlarge, "default"); 716 717 config = makeClassicConfig(); 718 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE); 719 res = config.getResources(); 720 checkValue(res, R.configVarying.simple, "simple large"); 721 checkValue(res, R.configVarying.small, "default"); 722 checkValue(res, R.configVarying.normal, "normal"); 723 checkValue(res, R.configVarying.large, "large"); 724 checkValue(res, R.configVarying.xlarge, "default"); 725 726 config = makeClassicConfig(); 727 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE); 728 res = config.getResources(); 729 checkValue(res, R.configVarying.simple, "simple xlarge"); 730 checkValue(res, R.configVarying.small, "default"); 731 checkValue(res, R.configVarying.normal, "normal"); 732 checkValue(res, R.configVarying.large, "large"); 733 checkValue(res, R.configVarying.xlarge, "xlarge"); 734 } 735 736 @MediumTest 737 public void testNewScreenSize() throws Exception { 738 // ensure that swNNNdp, wNNNdp, and hNNNdp are working correctly 739 // for various common screen configurations. 740 TotalConfig config = makeClassicConfig(); 741 config.setProperty(Properties.SWIDTH_DP, 589); 742 config.setProperty(Properties.WIDTH_DP, 589); 743 config.setProperty(Properties.HEIGHT_DP, 500); 744 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE); 745 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE); 746 Resources res = config.getResources(); 747 checkValue(res, R.configVarying.simple, "simple large"); 748 checkValue(res, R.configVarying.sw, "default"); 749 checkValue(res, R.configVarying.w, "default"); 750 checkValue(res, R.configVarying.h, "default"); 751 checkValue(res, R.configVarying.wh, "default"); 752 753 config = makeClassicConfig(); 754 config.setProperty(Properties.SWIDTH_DP, 590); 755 config.setProperty(Properties.WIDTH_DP, 590); 756 config.setProperty(Properties.HEIGHT_DP, 500); 757 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE); 758 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE); 759 config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_MEDIUM); 760 res = config.getResources(); 761 checkValue(res, R.configVarying.simple, "simple sw590 mdpi"); 762 checkValue(res, R.configVarying.sw, "590 mdpi"); 763 764 config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_HIGH); 765 res = config.getResources(); 766 checkValue(res, R.configVarying.simple, "simple sw590 hdpi"); 767 checkValue(res, R.configVarying.sw, "590 hdpi"); 768 769 config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_XHIGH); 770 res = config.getResources(); 771 checkValue(res, R.configVarying.simple, "simple sw590 xhdpi"); 772 checkValue(res, R.configVarying.sw, "590 xhdpi"); 773 774 config.setProperty(Properties.SWIDTH_DP, 591); 775 config.setProperty(Properties.WIDTH_DP, 591); 776 config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_MEDIUM); 777 res = config.getResources(); 778 checkValue(res, R.configVarying.simple, "simple sw591"); 779 checkValue(res, R.configVarying.sw, "591"); 780 781 config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_HIGH); 782 res = config.getResources(); 783 checkValue(res, R.configVarying.simple, "simple sw591 hdpi"); 784 checkValue(res, R.configVarying.sw, "591 hdpi"); 785 786 config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_XHIGH); 787 res = config.getResources(); 788 checkValue(res, R.configVarying.simple, "simple sw591 hdpi"); 789 checkValue(res, R.configVarying.sw, "591 hdpi"); 790 791 config = makeClassicConfig(); 792 config.setProperty(Properties.SWIDTH_DP, 480); 793 config.setProperty(Properties.WIDTH_DP, 800); 794 config.setProperty(Properties.HEIGHT_DP, 480); 795 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE); 796 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE); 797 res = config.getResources(); 798 checkValue(res, R.configVarying.simple, "simple w720"); 799 checkValue(res, R.configVarying.sw, "default"); 800 checkValue(res, R.configVarying.w, "720"); 801 checkValue(res, R.configVarying.h, "default"); 802 checkValue(res, R.configVarying.wh, "600"); 803 804 config = makeClassicConfig(); 805 config.setProperty(Properties.SWIDTH_DP, 600); 806 config.setProperty(Properties.WIDTH_DP, 1024); 807 config.setProperty(Properties.HEIGHT_DP, 552); 808 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE); 809 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE); 810 res = config.getResources(); 811 checkValue(res, R.configVarying.simple, "simple sw600 land"); 812 checkValue(res, R.configVarying.sw, "600 land"); 813 checkValue(res, R.configVarying.w, "720"); 814 checkValue(res, R.configVarying.h, "550"); 815 checkValue(res, R.configVarying.wh, "600-550"); 816 817 config = makeClassicConfig(); 818 config.setProperty(Properties.SWIDTH_DP, 600); 819 config.setProperty(Properties.WIDTH_DP, 600); 820 config.setProperty(Properties.HEIGHT_DP, 974); 821 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_PORTRAIT); 822 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE); 823 res = config.getResources(); 824 checkValue(res, R.configVarying.simple, "simple sw600"); 825 checkValue(res, R.configVarying.sw, "600"); 826 checkValue(res, R.configVarying.w, "600"); 827 checkValue(res, R.configVarying.h, "670"); 828 checkValue(res, R.configVarying.wh, "600-550"); 829 830 config = makeClassicConfig(); 831 config.setProperty(Properties.SWIDTH_DP, 719); 832 config.setProperty(Properties.WIDTH_DP, 1279); 833 config.setProperty(Properties.HEIGHT_DP, 669); 834 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE); 835 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE); 836 res = config.getResources(); 837 checkValue(res, R.configVarying.simple, "simple sw600 land"); 838 checkValue(res, R.configVarying.sw, "600 land"); 839 checkValue(res, R.configVarying.w, "720"); 840 checkValue(res, R.configVarying.h, "550"); 841 checkValue(res, R.configVarying.wh, "600-550"); 842 843 config = makeClassicConfig(); 844 config.setProperty(Properties.SWIDTH_DP, 800); 845 config.setProperty(Properties.WIDTH_DP, 1280); 846 config.setProperty(Properties.HEIGHT_DP, 672); 847 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE); 848 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE); 849 res = config.getResources(); 850 checkValue(res, R.configVarying.simple, "simple sw720"); 851 checkValue(res, R.configVarying.sw, "720"); 852 checkValue(res, R.configVarying.w, "720"); 853 checkValue(res, R.configVarying.h, "670"); 854 checkValue(res, R.configVarying.wh, "720-670"); 855 856 config = makeClassicConfig(); 857 config.setProperty(Properties.SWIDTH_DP, 800); 858 config.setProperty(Properties.WIDTH_DP, 720); 859 config.setProperty(Properties.HEIGHT_DP, 1230); 860 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_PORTRAIT); 861 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE); 862 res = config.getResources(); 863 checkValue(res, R.configVarying.simple, "simple sw720"); 864 checkValue(res, R.configVarying.sw, "720"); 865 checkValue(res, R.configVarying.w, "720"); 866 checkValue(res, R.configVarying.h, "670"); 867 checkValue(res, R.configVarying.wh, "720-670"); 868 } 869 870 // TODO - add tests for special cases - ie, other key params seem ignored if 871 // nokeys is set 872 873 @MediumTest 874 public void testPrecidence() { 875 /** 876 * Check for precidence of resources selected when there are multiple 877 * options matching the current config. 878 */ 879 TotalConfig config = makeEmptyConfig(); 880 config.setProperty(Properties.HEIGHT, 640); 881 config.setProperty(Properties.WIDTH, 400); 882 Resources res = config.getResources(); 883 checkValue(res, R.configVarying.simple, "simple 640x400"); 884 checkValue(res, R.configVarying.bag, 885 R.styleable.TestConfig, new String[]{"bag 640x400"}); 886 887 config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_NONAV); 888 res = config.getResources(); 889 checkValue(res, R.configVarying.simple, "simple nonav"); 890 checkValue(res, R.configVarying.bag, 891 R.styleable.TestConfig, new String[]{"bag nonav"}); 892 893 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_NOKEYS); 894 res = config.getResources(); 895 checkValue(res, R.configVarying.simple, "simple nokeys"); 896 checkValue(res, R.configVarying.bag, 897 R.styleable.TestConfig, new String[]{"bag nokeys"}); 898 899 config.setProperty(Properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_NO); 900 res = config.getResources(); 901 checkValue(res, R.configVarying.simple, "simple keysexposed"); 902 checkValue(res, R.configVarying.bag, 903 R.styleable.TestConfig, new String[]{"bag keysexposed"}); 904 905 config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_NOTOUCH); 906 res = config.getResources(); 907 checkValue(res, R.configVarying.simple, "simple notouch"); 908 checkValue(res, R.configVarying.bag, 909 R.styleable.TestConfig, new String[]{"bag notouch"}); 910 911 config.setProperty(Properties.DENSITY, 240); 912 res = config.getResources(); 913 checkValue(res, R.configVarying.simple, "simple 240dpi"); 914 checkValue(res, R.configVarying.bag, 915 R.styleable.TestConfig, new String[]{"bag 240dpi"}); 916 917 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE); 918 res = config.getResources(); 919 checkValue(res, R.configVarying.simple, "simple landscape"); 920 checkValue(res, R.configVarying.bag, 921 R.styleable.TestConfig, new String[]{"bag landscape"}); 922 923 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE); 924 res = config.getResources(); 925 checkValue(res, R.configVarying.simple, "simple xlarge"); 926 checkValue(res, R.configVarying.bag, 927 R.styleable.TestConfig, new String[]{"bag xlarge"}); 928 929 config.setProperty(Properties.HEIGHT_DP, 670); 930 res = config.getResources(); 931 checkValue(res, R.configVarying.simple, "simple h670"); 932 checkValue(res, R.configVarying.bag, 933 R.styleable.TestConfig, new String[]{"bag h670"}); 934 935 config.setProperty(Properties.WIDTH_DP, 720); 936 res = config.getResources(); 937 checkValue(res, R.configVarying.simple, "simple 720-670"); 938 checkValue(res, R.configVarying.bag, 939 R.styleable.TestConfig, new String[]{"bag 720-670"}); 940 941 config.setProperty(Properties.SWIDTH_DP, 720); 942 res = config.getResources(); 943 checkValue(res, R.configVarying.simple, "simple sw720"); 944 checkValue(res, R.configVarying.bag, 945 R.styleable.TestConfig, new String[]{"bag sw720"}); 946 947 config.setProperty(Properties.LANGUAGE, "xx"); 948 config.setProperty(Properties.COUNTRY, "YY"); 949 res = config.getResources(); 950 checkValue(res, R.configVarying.simple, "simple xx-rYY"); 951 checkValue(res, R.configVarying.bag, 952 R.styleable.TestConfig, new String[]{"bag xx-rYY"}); 953 954 config.setProperty(Properties.MCC, 111); 955 res = config.getResources(); 956 checkValue(res, R.configVarying.simple, "simple mcc111 xx-rYY"); 957 checkValue(res, R.configVarying.bag, 958 R.styleable.TestConfig, new String[]{"bag mcc111 xx-rYY"}); 959 960 config.setProperty(Properties.MNC, 222); 961 res = config.getResources(); 962 checkValue(res, R.configVarying.simple, "simple mcc111 mnc222"); 963 checkValue(res, R.configVarying.bag, 964 R.styleable.TestConfig, new String[]{"bag mcc111 mnc222"}); 965 } 966 967 @MediumTest 968 public void testCombinations() { 969 /** 970 * Verify that in cases of ties, the specific ordering is followed 971 */ 972 973 /** 974 * Precidence order: mcc, mnc, locale, swdp, wdp, hdp, screenlayout-size, 975 * screenlayout-long, orientation, density, 976 * touchscreen, hidden, keyboard, navigation, width-height 977 */ 978 979 /** 980 * verify mcc trumps mnc. Have 110-xx, 220-xx but no 110-220 981 * so which is selected? Should be mcc110-xx. 982 */ 983 TotalConfig config = makeClassicConfig(); 984 config.setProperty(Properties.MCC, 110); 985 config.setProperty(Properties.MNC, 220); 986 config.setProperty(Properties.LANGUAGE, "xx"); 987 Resources res = config.getResources(); 988 checkValue(res, R.configVarying.simple, "simple mcc110 xx"); 989 checkValue(res, R.configVarying.bag, 990 R.styleable.TestConfig, new String[]{"bag mcc110 xx"}); 991 992 /* full A + B + C doesn't exist. Do we get A + C or B + C? 993 */ 994 config = makeClassicConfig(); 995 config.setProperty(Properties.MCC, 111); 996 config.setProperty(Properties.MNC, 222); 997 config.setProperty(Properties.LANGUAGE, "xx"); 998 res = config.getResources(); 999 checkValue(res, R.configVarying.simple, "simple mcc111 mnc222"); 1000 checkValue(res, R.configVarying.bag, 1001 R.styleable.TestConfig, new String[]{"bag mcc111 mnc222"}); 1002 1003 config = makeClassicConfig(); 1004 config.setProperty(Properties.MNC, 222); 1005 config.setProperty(Properties.LANGUAGE, "xx"); 1006 config.setProperty(Properties.ORIENTATION, 1007 Configuration.ORIENTATION_SQUARE); 1008 res = config.getResources(); 1009 checkValue(res, R.configVarying.simple, "simple mnc222 xx"); 1010 checkValue(res, R.configVarying.bag, 1011 R.styleable.TestConfig, new String[]{"bag mnc222 xx"}); 1012 1013 config = makeClassicConfig(); 1014 config.setProperty(Properties.LANGUAGE, "xx"); 1015 config.setProperty(Properties.ORIENTATION, 1016 Configuration.ORIENTATION_SQUARE); 1017 config.setProperty(Properties.DENSITY, 32); 1018 res = config.getResources(); 1019 checkValue(res, R.configVarying.simple, "simple xx square"); 1020 checkValue(res, R.configVarying.bag, 1021 R.styleable.TestConfig, new String[]{"bag xx square"}); 1022 1023 /** 1024 * Verify that proper strings are found for multiple-selectivity case 1025 * (ie, a string set for locale and mcc is found only when both are 1026 * true). 1027 */ 1028 config = makeClassicConfig(); 1029 config.setProperty(Properties.LANGUAGE, "xx"); 1030 config.setProperty(Properties.COUNTRY, "YY"); 1031 config.setProperty(Properties.MCC, 111); 1032 res = config.getResources(); 1033 checkValue(res, R.configVarying.simple, "simple mcc111 xx-rYY"); 1034 checkValue(res, R.configVarying.bag, R.styleable.TestConfig, 1035 new String[] { "bag mcc111 xx-rYY" }); 1036 1037 config = makeClassicConfig(); 1038 config.setProperty(Properties.LANGUAGE, "xx"); 1039 config.setProperty(Properties.COUNTRY, "YY"); 1040 config.setProperty(Properties.MCC, 333); 1041 res = config.getResources(); 1042 checkValue(res, R.configVarying.simple, "simple xx-rYY"); 1043 checkValue(res, R.configVarying.bag, 1044 R.styleable.TestConfig, new String[] { "bag xx-rYY" }); 1045 1046 config = makeClassicConfig(); 1047 config.setProperty(Properties.MNC, 333); 1048 res = config.getResources(); 1049 checkValue(res, R.configVarying.simple, "simple default"); 1050 checkValue(res, R.configVarying.bag, 1051 R.styleable.TestConfig, new String[]{"bag default"}); 1052 1053 config = makeClassicConfig(); 1054 config.setProperty(Properties.ORIENTATION, 1055 Configuration.ORIENTATION_SQUARE); 1056 config.setProperty(Properties.DENSITY, 32); 1057 config.setProperty(Properties.TOUCHSCREEN, 1058 Configuration.TOUCHSCREEN_STYLUS); 1059 res = config.getResources(); 1060 checkValue(res, R.configVarying.simple, "simple square 32dpi"); 1061 checkValue(res, R.configVarying.bag, 1062 R.styleable.TestConfig, new String[]{"bag square 32dpi"}); 1063 1064 config = makeClassicConfig(); 1065 config.setProperty(Properties.DENSITY, 32); 1066 config.setProperty(Properties.TOUCHSCREEN, 1067 Configuration.TOUCHSCREEN_STYLUS); 1068 config.setProperty(Properties.KEYBOARDHIDDEN, 1069 Configuration.KEYBOARDHIDDEN_NO); 1070 res = config.getResources(); 1071 checkValue(res, R.configVarying.simple, "simple 32dpi stylus"); 1072 checkValue(res, R.configVarying.bag, 1073 R.styleable.TestConfig, new String[]{"bag 32dpi stylus"}); 1074 1075 config = makeClassicConfig(); 1076 config.setProperty(Properties.TOUCHSCREEN, 1077 Configuration.TOUCHSCREEN_STYLUS); 1078 config.setProperty(Properties.KEYBOARDHIDDEN, 1079 Configuration.KEYBOARDHIDDEN_NO); 1080 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY); 1081 res = config.getResources(); 1082 checkValue(res, R.configVarying.simple, "simple stylus keysexposed"); 1083 checkValue(res, R.configVarying.bag, 1084 R.styleable.TestConfig, new String[]{"bag stylus keysexposed"}); 1085 1086 config = makeClassicConfig(); 1087 config.setProperty(Properties.KEYBOARDHIDDEN, 1088 Configuration.KEYBOARDHIDDEN_NO); 1089 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY); 1090 config.setProperty(Properties.NAVIGATION, 1091 Configuration.NAVIGATION_DPAD); 1092 res = config.getResources(); 1093 checkValue(res, R.configVarying.simple, "simple keysexposed 12key"); 1094 checkValue(res, R.configVarying.bag, 1095 R.styleable.TestConfig, new String[]{"bag keysexposed 12key"}); 1096 1097 config = makeClassicConfig(); 1098 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY); 1099 config.setProperty(Properties.NAVIGATION, 1100 Configuration.NAVIGATION_DPAD); 1101 config.setProperty(Properties.HEIGHT, 63); 1102 config.setProperty(Properties.WIDTH, 57); 1103 res = config.getResources(); 1104 checkValue(res, R.configVarying.simple, "simple 12key dpad"); 1105 checkValue(res, R.configVarying.bag, 1106 R.styleable.TestConfig, new String[]{"bag 12key dpad"}); 1107 1108 config = makeClassicConfig(); 1109 config.setProperty(Properties.NAVIGATION, 1110 Configuration.NAVIGATION_DPAD); 1111 config.setProperty(Properties.HEIGHT, 640); 1112 config.setProperty(Properties.WIDTH, 400); 1113 res = config.getResources(); 1114 checkValue(res, R.configVarying.simple, "simple dpad 63x57"); 1115 checkValue(res, R.configVarying.bag, 1116 R.styleable.TestConfig, new String[]{"bag dpad 63x57"}); 1117 } 1118 1119 @MediumTest 1120 public void testVersions() { 1121 // Check that we get the most recent resources that are <= our 1122 // current version. Note the special version adjustment, so that 1123 // during development the resource version is incremented to the 1124 // next one. 1125 int vers = android.os.Build.VERSION.SDK_INT; 1126 if (!"REL".equals(android.os.Build.VERSION.CODENAME)) { 1127 vers++; 1128 } 1129 String expected = "v" + vers + "cur"; 1130 assertEquals(expected, mContext.getResources().getString(R.string.version_cur)); 1131 assertEquals("base", mContext.getResources().getString(R.string.version_old)); 1132 assertEquals("v3", mContext.getResources().getString(R.string.version_v3)); 1133 } 1134 } 1135