Merge change 165 into donut

* changes:
  Squashed commit of the following:
This commit is contained in:
Android (Google) Code Review
2009-04-23 12:23:46 -07:00
12 changed files with 463 additions and 252 deletions

View File

@@ -988,119 +988,225 @@ struct ResTable_config
return diffs;
}
// Return true if 'this' is more specific than 'o'. Optionally, if
// 'requested' is null, then they will also be compared against the
// requested configuration and true will only be returned if 'this'
// is a better candidate than 'o' for the configuration. This assumes that
// match() has already been used to remove any configurations that don't
// match the requested configuration at all; if they are not first filtered,
// non-matching results can be considered better than matching ones.
// Return true if 'this' is more specific than 'o'.
inline bool
isBetterThan(const ResTable_config& o, const ResTable_config* requested = NULL) const {
isMoreSpecificThan(const ResTable_config& o) const {
// The order of the following tests defines the importance of one
// configuration parameter over another. Those tests first are more
// important, trumping any values in those following them.
if (imsi != 0 && (!requested || requested->imsi != 0)) {
if (mcc != 0 && (!requested || requested->mcc != 0)) {
if (o.mcc == 0) {
return true;
}
if (imsi || o.imsi) {
if (mcc != o.mcc) {
if (!mcc) return false;
if (!o.mcc) return true;
}
if (mnc != 0 && (!requested || requested->mnc != 0)) {
if (o.mnc == 0) {
return true;
}
if (mnc != o.mnc) {
if (!mnc) return false;
if (!o.mnc) return true;
}
}
if (locale != 0 && (!requested || requested->locale != 0)) {
if (language[0] != 0 && (!requested || requested->language[0] != 0)) {
if (o.language[0] == 0) {
return true;
}
if (locale || o.locale) {
if (language[0] != o.language[0]) {
if (!language[0]) return false;
if (!o.language[0]) return true;
}
if (country[0] != 0 && (!requested || requested->country[0] != 0)) {
if (o.country[0] == 0) {
return true;
}
if (country[0] != o.country[0]) {
if (!country[0]) return false;
if (!o.country[0]) return true;
}
}
if (screenType != 0 && (!requested || requested->screenType != 0)) {
if (orientation != 0 && (!requested || requested->orientation != 0)) {
if (o.orientation == 0) {
return true;
}
if (screenType || o.screenType) {
if (orientation != o.orientation) {
if (!orientation) return false;
if (!o.orientation) return true;
}
if (density != 0 && (!requested || requested->density != 0)) {
if (o.density == 0) {
return true;
}
}
if (touchscreen != 0 && (!requested || requested->touchscreen != 0)) {
if (o.touchscreen == 0) {
return true;
}
// density is never 'more specific'
// as the default just equals 160
if (touchscreen != o.touchscreen) {
if (!touchscreen) return false;
if (!o.touchscreen) return true;
}
}
if (input != 0 && (!requested || requested->input != 0)) {
const int keysHidden = inputFlags&MASK_KEYSHIDDEN;
const int reqKeysHidden = requested
? requested->inputFlags&MASK_KEYSHIDDEN : 0;
if (keysHidden != 0 && reqKeysHidden != 0) {
const int oKeysHidden = o.inputFlags&MASK_KEYSHIDDEN;
//LOGI("isBetterThan keysHidden: cur=%d, given=%d, config=%d\n",
// keysHidden, oKeysHidden, reqKeysHidden);
if (oKeysHidden == 0) {
//LOGI("Better because 0!");
return true;
}
// For compatibility, we count KEYSHIDDEN_NO as being
// the same as KEYSHIDDEN_SOFT. Here we disambiguate these
// may making an exact match more specific.
if (keysHidden == reqKeysHidden && oKeysHidden != reqKeysHidden) {
// The current configuration is an exact match, and
// the given one is not, so the current one is better.
//LOGI("Better because other not same!");
return true;
}
if (input || o.input) {
if (inputFlags != o.inputFlags) {
if (!(inputFlags & MASK_KEYSHIDDEN)) return false;
if (!(o.inputFlags & MASK_KEYSHIDDEN)) return true;
}
if (keyboard != 0 && (!requested || requested->keyboard != 0)) {
if (o.keyboard == 0) {
return true;
}
if (keyboard != o.keyboard) {
if (!keyboard) return false;
if (!o.keyboard) return true;
}
if (navigation != 0 && (!requested || requested->navigation != 0)) {
if (o.navigation == 0) {
return true;
}
if (navigation != o.navigation) {
if (!navigation) return false;
if (!o.navigation) return true;
}
}
if (screenSize != 0 && (!requested || requested->screenSize != 0)) {
if (screenWidth != 0 && (!requested || requested->screenWidth != 0)) {
if (o.screenWidth == 0) {
return true;
}
if (screenSize || o.screenSize) {
if (screenWidth != o.screenWidth) {
if (!screenWidth) return false;
if (!o.screenWidth) return true;
}
if (screenHeight != 0 && (!requested || requested->screenHeight != 0)) {
if (o.screenHeight == 0) {
return true;
}
if (screenHeight != o.screenHeight) {
if (!screenHeight) return false;
if (!o.screenHeight) return true;
}
}
if (version != 0 && (!requested || requested->version != 0)) {
if (sdkVersion != 0 && (!requested || requested->sdkVersion != 0)) {
if (o.sdkVersion == 0) {
return true;
}
if (version || o.version) {
if (sdkVersion != o.sdkVersion) {
if (!sdkVersion) return false;
if (!o.sdkVersion) return true;
}
if (minorVersion != 0 && (!requested || requested->minorVersion != 0)) {
if (o.minorVersion == 0) {
return true;
}
if (minorVersion != o.minorVersion) {
if (!minorVersion) return false;
if (!o.minorVersion) return true;
}
}
return false;
}
// Return true if 'this' is a better match than 'o' for the 'requested'
// configuration. This assumes that match() has already been used to
// remove any configurations that don't match the requested configuration
// at all; if they are not first filtered, non-matching results can be
// considered better than matching ones.
// The general rule per attribute: if the request cares about an attribute
// (it normally does), if the two (this and o) are equal it's a tie. If
// they are not equal then one must be generic because only generic and
// '==requested' will pass the match() call. So if this is not generic,
// it wins. If this IS generic, o wins (return false).
inline bool
isBetterThan(const ResTable_config& o,
const ResTable_config* requested) const {
if (requested) {
if (imsi || o.imsi) {
if ((mcc != o.mcc) && requested->mcc) {
return (mcc);
}
if ((mnc != o.mnc) && requested->mnc) {
return (mnc);
}
}
if (locale || o.locale) {
if ((language[0] != o.language[0]) && requested->language[0]) {
return (language[0]);
}
if ((country[0] != o.country[0]) && requested->country[0]) {
return (country[0]);
}
}
if (screenType || o.screenType) {
if ((orientation != o.orientation) && requested->orientation) {
return (orientation);
}
if (density != o.density) {
// density is tough. Any density is potentially useful
// because the system will scale it. Scaling down
// is generally better than scaling up.
// Default density counts as 160dpi (the system default)
// TODO - remove 160 constants
int h = (density?density:160);
int l = (o.density?o.density:160);
bool bImBigger = true;
if (l > h) {
int t = h;
h = l;
l = t;
bImBigger = false;
}
int reqValue = (requested->density?requested->density:160);
if (reqValue >= h) {
// requested value higher than both l and h, give h
return bImBigger;
}
if (l >= reqValue) {
// requested value lower than both l and h, give l
return !bImBigger;
}
// saying that scaling down is 2x better than up
if (((2 * l) - reqValue) * h > reqValue * reqValue) {
return !bImBigger;
} else {
return bImBigger;
}
}
if ((touchscreen != o.touchscreen) && requested->touchscreen) {
return (touchscreen);
}
}
if (input || o.input) {
const int keysHidden = inputFlags & MASK_KEYSHIDDEN;
const int oKeysHidden = o.inputFlags & MASK_KEYSHIDDEN;
if (keysHidden != oKeysHidden) {
const int reqKeysHidden =
requested->inputFlags & MASK_KEYSHIDDEN;
if (reqKeysHidden) {
if (!keysHidden) return false;
if (!oKeysHidden) return true;
// For compatibility, we count KEYSHIDDEN_NO as being
// the same as KEYSHIDDEN_SOFT. Here we disambiguate
// these by making an exact match more specific.
if (reqKeysHidden == keysHidden) return true;
if (reqKeysHidden == oKeysHidden) return false;
}
}
if ((keyboard != o.keyboard) && requested->keyboard) {
return (keyboard);
}
if ((navigation != o.navigation) && requested->navigation) {
return (navigation);
}
}
if (screenSize || o.screenSize) {
if ((screenWidth != o.screenWidth) && requested->screenWidth) {
return (screenWidth);
}
if ((screenHeight != o.screenHeight) &&
requested->screenHeight) {
return (screenHeight);
}
}
if (version || o.version) {
if ((sdkVersion != o.sdkVersion) && requested->sdkVersion) {
return (sdkVersion);
}
if ((minorVersion != o.minorVersion) &&
requested->minorVersion) {
return (minorVersion);
}
}
return false;
}
return isMoreSpecificThan(o);
}
// Return true if 'this' can be considered a match for the parameters in
// 'settings'.
// Note this is asymetric. A default piece of data will match every request
@@ -1137,8 +1243,7 @@ struct ResTable_config
&& orientation != settings.orientation) {
return false;
}
// Density not taken into account, always match, no matter what
// density is specified for the resource
// density always matches - we can scale it. See isBetterThan
if (settings.touchscreen != 0 && touchscreen != 0
&& touchscreen != settings.touchscreen) {
return false;

View File

@@ -1820,7 +1820,7 @@ ssize_t ResTable::getResource(uint32_t resID, Res_value* outValue, bool mayBeBag
}
}
if (bestPackage != NULL && bestItem.isBetterThan(thisConfig)) {
if (bestPackage != NULL && bestItem.isMoreSpecificThan(thisConfig)) {
continue;
}

View File

@@ -15,8 +15,8 @@
-->
<resources>
<item type="configVarying" name="simple">simple portrait</item>
<item type="configVarying" name="simple">simple 32dpi</item>
<bag type="configVarying" name="bag">
<item name="testString">bag portrait</item>
<item name="testString">bag 32dpi</item>
</bag>
</resources>

View File

@@ -15,8 +15,8 @@
-->
<resources>
<item type="configVarying" name="simple">simple 320x200</item>
<item type="configVarying" name="simple">simple 640x400</item>
<bag type="configVarying" name="bag">
<item name="testString">bag 320x200</item>
<item name="testString">bag 640x400</item>
</bag>
</resources>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<item type="configVarying" name="simple">simple fr FR</item>
<bag type="configVarying" name="bag">
<item name="testString">bag fr FR</item>
</bag>
</resources>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<item type="configVarying" name="simple">simple fr</item>
<bag type="configVarying" name="bag">
<item name="testString">bag fr</item>
</bag>
</resources>

View File

@@ -15,8 +15,8 @@
-->
<resources>
<item type="configVarying" name="simple">simple trackball</item>
<item type="configVarying" name="simple">simple mcc110 xx</item>
<bag type="configVarying" name="bag">
<item name="testString">bag trackball</item>
<item name="testString">bag mcc110 xx</item>
</bag>
</resources>

View File

@@ -15,8 +15,8 @@
-->
<resources>
<item type="configVarying" name="simple">simple finger</item>
<item type="configVarying" name="simple">simple mcc112</item>
<bag type="configVarying" name="bag">
<item name="testString">bag finger</item>
<item name="testString">bag mcc112</item>
</bag>
</resources>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<item type="configVarying" name="simple">simple mnc220 xx</item>
<bag type="configVarying" name="bag">
<item name="testString">bag mnc220 xx</item>
</bag>
</resources>

View File

@@ -15,8 +15,8 @@
-->
<resources>
<item type="configVarying" name="simple">simple keyshidden</item>
<item type="configVarying" name="simple">simple mnc222 32dpi</item>
<bag type="configVarying" name="bag">
<item name="testString">bag keyshidden</item>
<item name="testString">bag mnc222 32dpi</item>
</bag>
</resources>

View File

@@ -15,8 +15,8 @@
-->
<resources>
<item type="configVarying" name="simple">simple qwerty</item>
<item type="configVarying" name="simple">simple mnc223</item>
<bag type="configVarying" name="bag">
<item name="testString">bag qwerty</item>
<item name="testString">bag mnc223</item>
</bag>
</resources>

View File

@@ -98,7 +98,7 @@ public class ConfigTest extends AndroidTestCase {
mMetrics = new DisplayMetrics();
mMetrics.widthPixels = 200;
mMetrics.heightPixels = 320;
mMetrics.density = 120;
mMetrics.density = 1;
}
void setProperty(properties p, int value) {
@@ -131,7 +131,9 @@ public class ConfigTest extends AndroidTestCase {
mMetrics.heightPixels = value;
break;
case DENSITY:
mMetrics.density = value;
// this is the ratio from the standard
mMetrics.density = (((float)value)/((float)DisplayMetrics.DEFAULT_DENSITY));
break;
default:
assert(false);
@@ -187,18 +189,16 @@ public class ConfigTest extends AndroidTestCase {
*/
TotalConfig config = new TotalConfig();
Resources res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple default");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag default"});
checkValue(res, R.configVarying.simple, "simple default");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag default"});
config = new TotalConfig();
config.setProperty(properties.LANGUAGE, "xx");
res = config.getResources();
// got simple xx 32dpi
// checkValue(res, R.configVarying.simple, "simple xx");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag xx"});
checkValue(res, R.configVarying.simple, "simple xx");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag xx"});
config = new TotalConfig();
config.setProperty(properties.LANGUAGE, "xx");
@@ -225,116 +225,66 @@ public class ConfigTest extends AndroidTestCase {
config = new TotalConfig();
config.setProperty(properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_NOTOUCH);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple notouch");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag notouch"});
config = new TotalConfig();
config.setProperty(properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_FINGER);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple finger");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag finger"});
checkValue(res, R.configVarying.simple, "simple notouch");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag notouch"});
config = new TotalConfig();
config.setProperty(properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_STYLUS);
res = config.getResources();
// got simple 32dpi stylus
// checkValue(res, R.configVarying.simple, "simple stylus");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag stylus"});
checkValue(res, R.configVarying.simple, "simple stylus");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag stylus"});
config = new TotalConfig();
config.setProperty(properties.KEYBOARD, Configuration.KEYBOARD_NOKEYS);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple nokeys");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag nokeys"});
config = new TotalConfig();
config.setProperty(properties.KEYBOARD, Configuration.KEYBOARD_QWERTY);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple qwerty");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag qwerty"});
checkValue(res, R.configVarying.simple, "simple nokeys");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag nokeys"});
config = new TotalConfig();
config.setProperty(properties.KEYBOARD, Configuration.KEYBOARD_12KEY);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple 12key");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag 12key"});
config = new TotalConfig();
config.setProperty(properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_YES);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple keyshidden");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag keyshidden"});
checkValue(res, R.configVarying.simple, "simple 12key");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 12key"});
config = new TotalConfig();
config.setProperty(properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_NO);
res = config.getResources();
// got simple 32dpi keysexposed
// checkValue(res, R.configVarying.simple, "simple keysexposed");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag keysexposed"});
checkValue(res, R.configVarying.simple, "simple keysexposed");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag keysexposed"});
config = new TotalConfig();
config.setProperty(properties.NAVIGATION, Configuration.NAVIGATION_NONAV);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple nonav");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag nonav"});
checkValue(res, R.configVarying.simple, "simple nonav");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag nonav"});
config = new TotalConfig();
config.setProperty(properties.NAVIGATION, Configuration.NAVIGATION_DPAD);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple dpad");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag dpad"});
config = new TotalConfig();
config.setProperty(properties.NAVIGATION, Configuration.NAVIGATION_TRACKBALL);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple trackball");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag trackball"});
checkValue(res, R.configVarying.simple, "simple dpad");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag dpad"});
config = new TotalConfig();
config.setProperty(properties.NAVIGATION, Configuration.NAVIGATION_WHEEL);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple wheel");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag wheel"});
config = new TotalConfig();
config.setProperty(properties.HEIGHT, 320);
config.setProperty(properties.WIDTH, 200);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple 320x200");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag 320x200"});
checkValue(res, R.configVarying.simple, "simple wheel");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag wheel"});
config = new TotalConfig();
config.setProperty(properties.HEIGHT, 480);
config.setProperty(properties.WIDTH, 320);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple 480x320");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag 480x320"});
checkValue(res, R.configVarying.simple, "simple 480x320");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 480x320"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 240);
@@ -343,37 +293,92 @@ public class ConfigTest extends AndroidTestCase {
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 240dpi"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 120);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple 120dpi");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag 120dpi"});
config = new TotalConfig();
config.setProperty(properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple landscape");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag landscape"});
config = new TotalConfig();
config.setProperty(properties.ORIENTATION, Configuration.ORIENTATION_PORTRAIT);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple portrait");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag portrait"});
checkValue(res, R.configVarying.simple, "simple landscape");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag landscape"});
config = new TotalConfig();
config.setProperty(properties.ORIENTATION, Configuration.ORIENTATION_SQUARE);
res = config.getResources();
// got simple square 32dpi
// checkValue(res, R.configVarying.simple, "simple square");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag square"});
checkValue(res, R.configVarying.simple, "simple square");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag square"});
}
@MediumTest
public void testDensity() throws Exception {
// have 32, 240 and the default 160 content.
// rule is that closest wins, with down scaling (larger content)
// being twice as nice as upscaling.
// transition at H/2 * (-1 +/- sqrt(1+8L/H))
// SO, X < 49 goes to 32
// 49 >= X < 182 goes to 160
// X >= 182 goes to 240
TotalConfig config = new TotalConfig();
config.setProperty(properties.DENSITY, 2);
Resources res = config.getResources();
checkValue(res, R.configVarying.simple, "simple 32dpi");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 32dpi"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 32);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple 32dpi");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 32dpi"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 48);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple 32dpi");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 32dpi"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 49);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple default");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag default"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 150);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple default");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag default"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 181);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple default");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag default"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 182);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple 240dpi");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 240dpi"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 239);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple 240dpi");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 240dpi"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 490);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple 240dpi");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 240dpi"});
}
// TODO - add tests for special cases - ie, other key params seem ignored if
@@ -407,10 +412,9 @@ public class ConfigTest extends AndroidTestCase {
config = new TotalConfig();
config.setProperty(properties.MNC, 333);
res = config.getResources();
// got simple 24dpi
// checkValue(res, R.configVarying.simple, "simple default");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag default"});
checkValue(res, R.configVarying.simple, "simple default");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag default"});
}
@MediumTest
@@ -419,13 +423,31 @@ public class ConfigTest extends AndroidTestCase {
* Verify that in cases of ties, the specific ordering is followed
*/
/* full A + B + C doesn't exist. Do we get A + C or B + C?
/**
* Precidence order: mcc, mnc, locale, orientation, density,
* touchscreen, hidden, keyboard, navigation, width-height
*/
/**
* verify mcc trumps mnc. Have 110-xx, 220-xx but no 110-220
* so with is selected? Should be mcc110-xx.
*/
TotalConfig config = new TotalConfig();
config.setProperty(properties.MCC, 110);
config.setProperty(properties.MNC, 220);
config.setProperty(properties.LANGUAGE, "xx");
Resources res = config.getResources();
checkValue(res, R.configVarying.simple, "simple mcc110 xx");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag mcc110 xx"});
/* full A + B + C doesn't exist. Do we get A + C or B + C?
*/
config = new TotalConfig();
config.setProperty(properties.MCC, 111);
config.setProperty(properties.MNC, 222);
config.setProperty(properties.LANGUAGE, "xx");
Resources res = config.getResources();
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple mcc111 mnc222");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag mcc111 mnc222"});
@@ -433,7 +455,8 @@ public class ConfigTest extends AndroidTestCase {
config = new TotalConfig();
config.setProperty(properties.MNC, 222);
config.setProperty(properties.LANGUAGE, "xx");
config.setProperty(properties.ORIENTATION, Configuration.ORIENTATION_SQUARE);
config.setProperty(properties.ORIENTATION,
Configuration.ORIENTATION_SQUARE);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple mnc222 xx");
checkValue(res, R.configVarying.bag,
@@ -441,60 +464,77 @@ public class ConfigTest extends AndroidTestCase {
config = new TotalConfig();
config.setProperty(properties.LANGUAGE, "xx");
config.setProperty(properties.ORIENTATION, Configuration.ORIENTATION_SQUARE);
config.setProperty(properties.ORIENTATION,
Configuration.ORIENTATION_SQUARE);
config.setProperty(properties.DENSITY, 32);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple xx 32dpi");
checkValue(res, R.configVarying.simple, "simple xx square");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag xx 32dpi"});
R.styleable.TestConfig, new String[]{"bag xx square"});
config = new TotalConfig();
config.setProperty(properties.ORIENTATION, Configuration.ORIENTATION_SQUARE);
config.setProperty(properties.ORIENTATION,
Configuration.ORIENTATION_SQUARE);
config.setProperty(properties.DENSITY, 32);
config.setProperty(properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_STYLUS);
config.setProperty(properties.TOUCHSCREEN,
Configuration.TOUCHSCREEN_STYLUS);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple square 32dpi");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag square 32dpi"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 32);
config.setProperty(properties.TOUCHSCREEN,
Configuration.TOUCHSCREEN_STYLUS);
config.setProperty(properties.KEYBOARDHIDDEN,
Configuration.KEYBOARDHIDDEN_NO);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple 32dpi stylus");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 32dpi stylus"});
config = new TotalConfig();
config.setProperty(properties.DENSITY, 32);
config.setProperty(properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_STYLUS);
config.setProperty(properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_NO);
config.setProperty(properties.TOUCHSCREEN,
Configuration.TOUCHSCREEN_STYLUS);
config.setProperty(properties.KEYBOARDHIDDEN,
Configuration.KEYBOARDHIDDEN_NO);
config.setProperty(properties.KEYBOARD, Configuration.KEYBOARD_12KEY);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple 32dpi stylus");
checkValue(res, R.configVarying.simple, "simple stylus keysexposed");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 32dpi stylus"});
R.styleable.TestConfig, new String[]{"bag stylus keysexposed"});
config = new TotalConfig();
config.setProperty(properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_STYLUS);
config.setProperty(properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_NO);
config.setProperty(properties.KEYBOARDHIDDEN,
Configuration.KEYBOARDHIDDEN_NO);
config.setProperty(properties.KEYBOARD, Configuration.KEYBOARD_12KEY);
config.setProperty(properties.NAVIGATION,
Configuration.NAVIGATION_DPAD);
res = config.getResources();
// got simple 32dpi stylus
// checkValue(res, R.configVarying.simple, "simple stylus 12key");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag stylus 12key"});
config = new TotalConfig();
config.setProperty(properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_NO);
config.setProperty(properties.KEYBOARD, Configuration.KEYBOARD_12KEY);
config.setProperty(properties.NAVIGATION, Configuration.NAVIGATION_DPAD);
res = config.getResources();
// got simple 32dpi exposed
// checkValue(res, R.configVarying.simple, "simple stylus keysexposed");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag stylus keysexposed"});
checkValue(res, R.configVarying.simple, "simple keysexposed 12key");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag keysexposed 12key"});
config = new TotalConfig();
config.setProperty(properties.KEYBOARD, Configuration.KEYBOARD_12KEY);
config.setProperty(properties.NAVIGATION, Configuration.NAVIGATION_DPAD);
config.setProperty(properties.NAVIGATION,
Configuration.NAVIGATION_DPAD);
config.setProperty(properties.HEIGHT, 63);
config.setProperty(properties.WIDTH, 57);
res = config.getResources();
// got simple 240dpi
// checkValue(res, R.configVarying.simple, "simple 12key dpad");
// checkValue(res, R.configVarying.bag,
// R.styleable.TestConfig, new String[]{"bag 12key dpad"});
checkValue(res, R.configVarying.simple, "simple 12key dpad");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag 12key dpad"});
config = new TotalConfig();
config.setProperty(properties.NAVIGATION,
Configuration.NAVIGATION_DPAD);
config.setProperty(properties.HEIGHT, 640);
config.setProperty(properties.WIDTH, 400);
res = config.getResources();
checkValue(res, R.configVarying.simple, "simple dpad");
checkValue(res, R.configVarying.bag,
R.styleable.TestConfig, new String[]{"bag dpad"});
}
}