Parse add-on supplied layout devices.
Add-ons are expected to provide a file called devices.xml in their root
folder. The XML schema for this file is
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/layout-configs.xsd
I slightly fixed the schema so that normal screen size use the token
"normal" instead of "medium" to match the resource qualifier.
To round up the feature, the following changes are included:
- getEnum in the resource qualifier enum has been made public. There's no
sense in keeping it private and it'll help with people possibly using
valueOf which behaves differently (case sensitive so
ScreenSize.valueOf("normal") fails, while getEnum on the same string succeed.
- Updated the device configuration UI to deal with missing list of
devices while the SDK loads.
Change-Id: Ib1b01007d2ae7fd6398172c3549b2686c33d48be
This commit is contained in:
@@ -23,11 +23,8 @@ import org.xml.sax.SAXParseException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import javax.xml.validation.Validator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
@@ -107,19 +104,6 @@ public class TestLayoutConfisXsd extends TestCase {
|
||||
|
||||
// --- Helpers ------------
|
||||
|
||||
/** Helper method that returns a validator for our XSD */
|
||||
private Validator getValidator(CaptureErrorHandler handler) throws SAXException {
|
||||
InputStream xsdStream = LayoutConfigsXsd.getXsdStream();
|
||||
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
Schema schema = factory.newSchema(new StreamSource(xsdStream));
|
||||
Validator validator = schema.newValidator();
|
||||
if (handler != null) {
|
||||
validator.setErrorHandler(handler);
|
||||
}
|
||||
|
||||
return validator;
|
||||
}
|
||||
|
||||
/** Validate a valid sample using an InputStream */
|
||||
public void testValidateLocalRepositoryFile() throws Exception {
|
||||
|
||||
@@ -128,7 +112,7 @@ public class TestLayoutConfisXsd extends TestCase {
|
||||
Source source = new StreamSource(xmlStream);
|
||||
|
||||
CaptureErrorHandler handler = new CaptureErrorHandler();
|
||||
Validator validator = getValidator(handler);
|
||||
Validator validator = LayoutConfigsXsd.getValidator(handler);
|
||||
validator.validate(source);
|
||||
handler.verify();
|
||||
}
|
||||
@@ -151,7 +135,7 @@ public class TestLayoutConfisXsd extends TestCase {
|
||||
Source source = new StreamSource(new StringReader(document));
|
||||
|
||||
CaptureErrorHandler handler = new CaptureErrorHandler();
|
||||
Validator validator = getValidator(handler);
|
||||
Validator validator = LayoutConfigsXsd.getValidator(handler);
|
||||
|
||||
try {
|
||||
validator.validate(source);
|
||||
@@ -175,7 +159,7 @@ public class TestLayoutConfisXsd extends TestCase {
|
||||
Source source = new StreamSource(new StringReader(document));
|
||||
|
||||
// don't capture the validator errors, we want it to fail and catch the exception
|
||||
Validator validator = getValidator(null);
|
||||
Validator validator = LayoutConfigsXsd.getValidator(null);
|
||||
try {
|
||||
validator.validate(source);
|
||||
} catch (SAXParseException e) {
|
||||
@@ -197,7 +181,7 @@ public class TestLayoutConfisXsd extends TestCase {
|
||||
Source source = new StreamSource(new StringReader(document));
|
||||
|
||||
// don't capture the validator errors, we want it to fail and catch the exception
|
||||
Validator validator = getValidator(null);
|
||||
Validator validator = LayoutConfigsXsd.getValidator(null);
|
||||
try {
|
||||
validator.validate(source);
|
||||
} catch (SAXParseException e) {
|
||||
@@ -217,7 +201,7 @@ public class TestLayoutConfisXsd extends TestCase {
|
||||
Source source = new StreamSource(new StringReader(document));
|
||||
|
||||
// don't capture the validator errors, we want it to fail and catch the exception
|
||||
Validator validator = getValidator(null);
|
||||
Validator validator = LayoutConfigsXsd.getValidator(null);
|
||||
try {
|
||||
validator.validate(source);
|
||||
} catch (SAXParseException e) {
|
||||
@@ -239,7 +223,7 @@ public class TestLayoutConfisXsd extends TestCase {
|
||||
Source source = new StreamSource(new StringReader(document));
|
||||
|
||||
// don't capture the validator errors, we want it to fail and catch the exception
|
||||
Validator validator = getValidator(null);
|
||||
Validator validator = LayoutConfigsXsd.getValidator(null);
|
||||
try {
|
||||
validator.validate(source);
|
||||
} catch (SAXParseException e) {
|
||||
@@ -264,7 +248,7 @@ public class TestLayoutConfisXsd extends TestCase {
|
||||
Source source = new StreamSource(new StringReader(document));
|
||||
|
||||
// don't capture the validator errors, we want it to fail and catch the exception
|
||||
Validator validator = getValidator(null);
|
||||
Validator validator = LayoutConfigsXsd.getValidator(null);
|
||||
try {
|
||||
validator.validate(source);
|
||||
} catch (SAXParseException e) {
|
||||
@@ -289,7 +273,7 @@ public class TestLayoutConfisXsd extends TestCase {
|
||||
Source source = new StreamSource(new StringReader(document));
|
||||
|
||||
// don't capture the validator errors, we want it to fail and catch the exception
|
||||
Validator validator = getValidator(null);
|
||||
Validator validator = LayoutConfigsXsd.getValidator(null);
|
||||
try {
|
||||
validator.validate(source);
|
||||
} catch (SAXParseException e) {
|
||||
|
||||
@@ -50,8 +50,8 @@
|
||||
<d:config name="screen-size-small">
|
||||
<d:screen-size>small</d:screen-size>
|
||||
</d:config>
|
||||
<d:config name="screen-size-medium">
|
||||
<d:screen-size>medium</d:screen-size>
|
||||
<d:config name="screen-size-normal">
|
||||
<d:screen-size>normal</d:screen-size>
|
||||
</d:config>
|
||||
<d:config name="screen-size-large">
|
||||
<d:screen-size>large</d:screen-size>
|
||||
@@ -121,8 +121,8 @@
|
||||
|
||||
|
||||
<d:device name="SomePhone"> <!-- 1..n -->
|
||||
<d:config name="screen-size-medium">
|
||||
<d:screen-size>medium</d:screen-size>
|
||||
<d:config name="screen-size-normal">
|
||||
<d:screen-size>normal</d:screen-size>
|
||||
</d:config>
|
||||
</d:device>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user