diff options
7 files changed, 0 insertions, 1582 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/OrientationMenuAction.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/OrientationMenuAction.java index 27446b2..0898cdf 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/OrientationMenuAction.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/OrientationMenuAction.java @@ -17,16 +17,12 @@ package com.android.ide.eclipse.adt.internal.editors.layout.configuration; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.SubmenuAction; -import com.android.ide.eclipse.adt.internal.sdk.LayoutDevice; -import com.android.ide.eclipse.adt.internal.sdk.LayoutDevice.DeviceConfig; import com.android.resources.NightMode; import com.android.resources.ScreenOrientation; import com.android.resources.UiMode; import com.android.sdklib.devices.Device; -import com.android.sdklib.devices.DeviceManager; import com.android.sdklib.devices.State; - import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IAction; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDevice.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDevice.java deleted file mode 100644 index ad0e03f..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDevice.java +++ /dev/null @@ -1,389 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php - * - * 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. - */ - -package com.android.ide.eclipse.adt.internal.sdk; - -import com.android.ide.common.resources.configuration.CountryCodeQualifier; -import com.android.ide.common.resources.configuration.DensityQualifier; -import com.android.ide.common.resources.configuration.FolderConfiguration; -import com.android.ide.common.resources.configuration.KeyboardStateQualifier; -import com.android.ide.common.resources.configuration.NavigationMethodQualifier; -import com.android.ide.common.resources.configuration.NavigationStateQualifier; -import com.android.ide.common.resources.configuration.NetworkCodeQualifier; -import com.android.ide.common.resources.configuration.ScreenDimensionQualifier; -import com.android.ide.common.resources.configuration.ScreenOrientationQualifier; -import com.android.ide.common.resources.configuration.ScreenRatioQualifier; -import com.android.ide.common.resources.configuration.ScreenSizeQualifier; -import com.android.ide.common.resources.configuration.TextInputMethodQualifier; -import com.android.ide.common.resources.configuration.TouchScreenQualifier; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Class representing a layout device. - * - * A Layout device is a collection of {@link FolderConfiguration} that can be used to render Android - * layout files. - * - * It also contains a single xdpi/ydpi that is independent of the {@link FolderConfiguration}. - * - * If the device is meant to represent a true device, then most of the FolderConfigurations' content - * should be identical, with only a few qualifiers (orientation, keyboard state) that would differ. - * However it is simpler to reuse the FolderConfiguration class (with the non changing qualifiers - * duplicated in each configuration) as it's what's being used by the rendering library. - * - * To create, edit and delete LayoutDevice objects, see {@link LayoutDeviceManager}. - * The class is not technically immutable but behaves as such outside of its package. - */ -public class LayoutDevice { - - private final String mName; - - /** - * Wrapper around a {@link FolderConfiguration}. - * <p/>This adds a name, accessible through {@link #getName()}. - * <p/>The folder config can be accessed through {@link #getConfig()}. - * - */ - public final static class DeviceConfig { - private final String mName; - private final FolderConfiguration mConfig; - - DeviceConfig(String name, FolderConfiguration config) { - mName = name; - mConfig = config; - } - - public String getName() { - return mName; - } - - public FolderConfiguration getConfig() { - return mConfig; - } - } - - /** editable list of the config */ - private final ArrayList<DeviceConfig> mConfigs = new ArrayList<DeviceConfig>(); - /** Read-only list */ - private List<DeviceConfig> mROList; - - private float mXDpi = Float.NaN; - private float mYDpi = Float.NaN; - - LayoutDevice(String name) { - mName = name; - } - - /** - * Saves the Layout Device into a document under a given node - * @param doc the document. - * @param parentNode the parent node. - */ - void saveTo(Document doc, Element parentNode) { - // create the device node - Element deviceNode = createNode(doc, parentNode, LayoutDevicesXsd.NODE_DEVICE); - - // create the name attribute (no namespace on this one). - deviceNode.setAttribute(LayoutDevicesXsd.ATTR_NAME, mName); - - // create a default with the x/y dpi - Element defaultNode = createNode(doc, deviceNode, LayoutDevicesXsd.NODE_DEFAULT); - if (Float.isNaN(mXDpi) == false) { - Element xdpiNode = createNode(doc, defaultNode, LayoutDevicesXsd.NODE_XDPI); - xdpiNode.setTextContent(Float.toString(mXDpi)); - } - if (Float.isNaN(mYDpi) == false) { - Element xdpiNode = createNode(doc, defaultNode, LayoutDevicesXsd.NODE_YDPI); - xdpiNode.setTextContent(Float.toString(mYDpi)); - } - - // then save all the configs. - synchronized (mConfigs) { - for (DeviceConfig config : mConfigs) { - saveConfigTo(doc, deviceNode, config.getName(), config.getConfig()); - } - } - } - - /** - * Creates and returns a new NS-enabled node. - * @param doc the {@link Document} - * @param parentNode the parent node. The new node is appended to this one as a child. - * @param name the name of the node. - * @return the newly created node. - */ - private Element createNode(Document doc, Element parentNode, String name) { - Element newNode = doc.createElementNS( - LayoutDevicesXsd.NS_LAYOUT_DEVICE_XSD, name); - newNode.setPrefix(doc.lookupPrefix(LayoutDevicesXsd.NS_LAYOUT_DEVICE_XSD)); - parentNode.appendChild(newNode); - - return newNode; - } - - /** - * Saves a {@link FolderConfiguration} in a {@link Document}. - * @param doc the Document in which to save - * @param parent the parent node - * @param configName the name of the config - * @param config the config to save - */ - private void saveConfigTo(Document doc, Element parent, String configName, - FolderConfiguration config) { - Element configNode = createNode(doc, parent, LayoutDevicesXsd.NODE_CONFIG); - - // create the name attribute (no namespace on this one). - configNode.setAttribute(LayoutDevicesXsd.ATTR_NAME, configName); - - // now do the qualifiers - CountryCodeQualifier ccq = config.getCountryCodeQualifier(); - if (ccq != null) { - Element node = createNode(doc, configNode, LayoutDevicesXsd.NODE_COUNTRY_CODE); - node.setTextContent(Integer.toString(ccq.getCode())); - } - - NetworkCodeQualifier ncq = config.getNetworkCodeQualifier(); - if (ncq != null) { - Element node = createNode(doc, configNode, LayoutDevicesXsd.NODE_NETWORK_CODE); - node.setTextContent(Integer.toString(ncq.getCode())); - } - - ScreenSizeQualifier slsq = config.getScreenSizeQualifier(); - if (slsq != null) { - Element node = createNode(doc, configNode, LayoutDevicesXsd.NODE_SCREEN_SIZE); - node.setTextContent(slsq.getFolderSegment()); - } - - ScreenRatioQualifier srq = config.getScreenRatioQualifier(); - if (srq != null) { - Element node = createNode(doc, configNode, LayoutDevicesXsd.NODE_SCREEN_RATIO); - node.setTextContent(srq.getFolderSegment()); - } - - ScreenOrientationQualifier soq = config.getScreenOrientationQualifier(); - if (soq != null) { - Element node = createNode(doc, configNode, LayoutDevicesXsd.NODE_SCREEN_ORIENTATION); - node.setTextContent(soq.getFolderSegment()); - } - - DensityQualifier dq = config.getDensityQualifier(); - if (dq != null) { - Element node = createNode(doc, configNode, LayoutDevicesXsd.NODE_PIXEL_DENSITY); - node.setTextContent(dq.getFolderSegment()); - } - - TouchScreenQualifier ttq = config.getTouchTypeQualifier(); - if (ttq != null) { - Element node = createNode(doc, configNode, LayoutDevicesXsd.NODE_TOUCH_TYPE); - node.setTextContent(ttq.getFolderSegment()); - } - - KeyboardStateQualifier ksq = config.getKeyboardStateQualifier(); - if (ksq != null) { - Element node = createNode(doc, configNode, LayoutDevicesXsd.NODE_KEYBOARD_STATE); - node.setTextContent(ksq.getFolderSegment()); - } - - TextInputMethodQualifier timq = config.getTextInputMethodQualifier(); - if (timq != null) { - Element node = createNode(doc, configNode, LayoutDevicesXsd.NODE_TEXT_INPUT_METHOD); - node.setTextContent(timq.getFolderSegment()); - } - - NavigationStateQualifier nsq = config.getNavigationStateQualifier(); - if (nsq != null) { - Element node = createNode(doc, configNode, LayoutDevicesXsd.NODE_NAV_STATE); - node.setTextContent(nsq.getFolderSegment()); - } - - NavigationMethodQualifier nmq = config.getNavigationMethodQualifier(); - if (nmq != null) { - Element node = createNode(doc, configNode, LayoutDevicesXsd.NODE_NAV_METHOD); - node.setTextContent(nmq.getFolderSegment()); - } - - ScreenDimensionQualifier sdq = config.getScreenDimensionQualifier(); - if (sdq != null) { - Element sizeNode = createNode(doc, configNode, LayoutDevicesXsd.NODE_SCREEN_DIMENSION); - - Element node = createNode(doc, sizeNode, LayoutDevicesXsd.NODE_SIZE); - node.setTextContent(Integer.toString(sdq.getValue1())); - - node = createNode(doc, sizeNode, LayoutDevicesXsd.NODE_SIZE); - node.setTextContent(Integer.toString(sdq.getValue2())); - } - } - - /** - * Adds config to the LayoutDevice. - * <p/>This ensures that no two configurations have the same. If a config already exists - * with the same name, the new config replaces it. - * - * @param name the name of the config. - * @param config the config. - */ - void addConfig(String name, FolderConfiguration config) { - synchronized (mConfigs) { - doAddConfig(name, config); - seal(); - } - } - - /** - * Adds a list of config to the LayoutDevice - * <p/>This ensures that no two configurations have the same. If a config already exists - * with the same name, the new config replaces it. - - * @param configs the configs to add. - */ - void addConfigs(List<DeviceConfig> configs) { - synchronized (mConfigs) { - // add the configs manually one by one, to check for no duplicate. - for (DeviceConfig config : configs) { - String name = config.getName(); - - for (DeviceConfig c : mConfigs) { - if (c.getName().equals(name)) { - mConfigs.remove(c); - break; - } - } - - mConfigs.add(config); - } - - seal(); - } - } - - /** - * Removes a config by its name. - * @param name the name of the config to remove. - */ - void removeConfig(String name) { - synchronized (mConfigs) { - for (DeviceConfig config : mConfigs) { - if (config.getName().equals(name)) { - mConfigs.remove(config); - seal(); - return; - } - } - } - } - - /** - * Adds config to the LayoutDevice. This is to be used to add plenty of - * configurations. It must be followed by {@link #_seal()}. - * <p/>This ensures that no two configurations have the same. If a config already exists - * with the same name, the new config replaces it. - * <p/><strong>This must be called inside a <code>synchronized(mConfigs)</code> block.</strong> - * - * @param name the name of the config - * @param config the config. - */ - private void doAddConfig(String name, FolderConfiguration config) { - // remove config that would have the same name to ensure no duplicate - for (DeviceConfig c : mConfigs) { - if (c.getName().equals(name)) { - mConfigs.remove(c); - break; - } - } - mConfigs.add(new DeviceConfig(name, config)); - } - - /** - * Seals the layout device by setting up {@link #mROList}. - * <p/><strong>This must be called inside a <code>synchronized(mConfigs)</code> block.</strong> - */ - private void seal() { - mROList = Collections.unmodifiableList(mConfigs); - } - - void setXDpi(float xdpi) { - mXDpi = xdpi; - } - - void setYDpi(float ydpi) { - mYDpi = ydpi; - } - - public String getName() { - return mName; - } - - /** - * Returns an unmodifiable list of all the {@link DeviceConfig}. - */ - public List<DeviceConfig> getConfigs() { - synchronized (mConfigs) { - return mROList; - } - } - - /** - * Returns a {@link DeviceConfig} by its name. - */ - public DeviceConfig getDeviceConfigByName(String name) { - synchronized (mConfigs) { - for (DeviceConfig config : mConfigs) { - if (config.getName().equals(name)) { - return config; - } - } - } - - return null; - } - - /** - * Returns a {@link FolderConfiguration} by its name. - */ - public FolderConfiguration getFolderConfigByName(String name) { - synchronized (mConfigs) { - for (DeviceConfig config : mConfigs) { - if (config.getName().equals(name)) { - return config.getConfig(); - } - } - } - - return null; - } - - /** - * Returns the dpi of the Device screen in X. - * @return the dpi of screen or {@link Float#NaN} if it's not set. - */ - public float getXDpi() { - return mXDpi; - } - - /** - * Returns the dpi of the Device screen in Y. - * @return the dpi of screen or {@link Float#NaN} if it's not set. - */ - public float getYDpi() { - return mYDpi; - } - } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDeviceHandler.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDeviceHandler.java deleted file mode 100644 index 5e19209..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDeviceHandler.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php - * - * 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. - */ - -package com.android.ide.eclipse.adt.internal.sdk; - -import com.android.ide.common.resources.configuration.CountryCodeQualifier; -import com.android.ide.common.resources.configuration.DensityQualifier; -import com.android.ide.common.resources.configuration.FolderConfiguration; -import com.android.ide.common.resources.configuration.KeyboardStateQualifier; -import com.android.ide.common.resources.configuration.NavigationMethodQualifier; -import com.android.ide.common.resources.configuration.NavigationStateQualifier; -import com.android.ide.common.resources.configuration.NetworkCodeQualifier; -import com.android.ide.common.resources.configuration.ScreenDimensionQualifier; -import com.android.ide.common.resources.configuration.ScreenOrientationQualifier; -import com.android.ide.common.resources.configuration.ScreenRatioQualifier; -import com.android.ide.common.resources.configuration.ScreenSizeQualifier; -import com.android.ide.common.resources.configuration.TextInputMethodQualifier; -import com.android.ide.common.resources.configuration.TouchScreenQualifier; -import com.android.resources.Density; -import com.android.resources.Keyboard; -import com.android.resources.KeyboardState; -import com.android.resources.Navigation; -import com.android.resources.NavigationState; -import com.android.resources.ScreenOrientation; -import com.android.resources.ScreenRatio; -import com.android.resources.ScreenSize; -import com.android.resources.TouchScreen; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -import java.util.ArrayList; -import java.util.List; - -/** - * {@link DefaultHandler} implementation to parse Layout Device XML file. - * @see LayoutDevicesXsd - * @see Layout-configs.xsd - */ -class LayoutDeviceHandler extends DefaultHandler { - /* - * The handler does most of the work in startElement and endElement. - * In startElement, it'll create DeviceConfiguration on <device>, as well as - * FolderConfiguration instances on <default> and <config>. - * Those objects are then filled as new nodes are discovered. - * - * For the qualifier values, the qualifier is created and added to the current config - * on the endElement, by using the content found in characters(). - */ - - private List<LayoutDevice> mDevices = new ArrayList<LayoutDevice>(); - - private LayoutDevice mCurrentDevice; - private FolderConfiguration mDefaultConfig; - private FolderConfiguration mCurrentConfig; - private final StringBuilder mStringAccumulator = new StringBuilder(); - - private String mSize1, mSize2; - - public List<LayoutDevice> getDevices() { - return mDevices; - } - - @Override - public void startElement(String uri, String localName, String name, Attributes attributes) - throws SAXException { - if (LayoutDevicesXsd.NODE_DEVICE.equals(localName)) { - // get the deviceName, will not be null since we validated the XML. - String deviceName = attributes.getValue("", LayoutDevicesXsd.ATTR_NAME); - - // create a device and add it to the list - mCurrentDevice = new LayoutDevice(deviceName); - mDevices.add(mCurrentDevice); - } else if (LayoutDevicesXsd.NODE_DEFAULT.equals(localName)) { - // create a new default config - mDefaultConfig = mCurrentConfig = new FolderConfiguration(); - } else if (LayoutDevicesXsd.NODE_CONFIG.equals(localName)) { - // create a new config - mCurrentConfig = new FolderConfiguration(); - - // init with default config if applicable - if (mDefaultConfig != null) { - mCurrentConfig.set(mDefaultConfig); - } - - // get the name of the config - String deviceName = attributes.getValue("", LayoutDevicesXsd.ATTR_NAME); - - // give it to the current device. - mCurrentDevice.addConfig(deviceName, mCurrentConfig); - } else if (LayoutDevicesXsd.NODE_SCREEN_DIMENSION.equals(localName)) { - mSize1 = mSize2 = null; - } - - mStringAccumulator.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) throws SAXException { - mStringAccumulator.append(ch, start, length); - } - - @Override - public void endElement(String uri, String localName, String name) throws SAXException { - if (LayoutDevicesXsd.NODE_DEVICE.equals(localName)) { - mCurrentDevice = null; - mDefaultConfig = null; - } else if (LayoutDevicesXsd.NODE_CONFIG.equals(localName)) { - mCurrentConfig.updateScreenWidthAndHeight(); - mCurrentConfig = null; - } else if (LayoutDevicesXsd.NODE_COUNTRY_CODE.equals(localName)) { - CountryCodeQualifier ccq = new CountryCodeQualifier( - Integer.parseInt(mStringAccumulator.toString())); - mCurrentConfig.setCountryCodeQualifier(ccq); - } else if (LayoutDevicesXsd.NODE_NETWORK_CODE.equals(localName)) { - NetworkCodeQualifier ncq = new NetworkCodeQualifier( - Integer.parseInt(mStringAccumulator.toString())); - mCurrentConfig.setNetworkCodeQualifier(ncq); - } else if (LayoutDevicesXsd.NODE_SCREEN_SIZE.equals(localName)) { - ScreenSizeQualifier ssq = new ScreenSizeQualifier( - ScreenSize.getEnum(mStringAccumulator.toString())); - mCurrentConfig.setScreenSizeQualifier(ssq); - } else if (LayoutDevicesXsd.NODE_SCREEN_RATIO.equals(localName)) { - ScreenRatioQualifier srq = new ScreenRatioQualifier( - ScreenRatio.getEnum(mStringAccumulator.toString())); - mCurrentConfig.setScreenRatioQualifier(srq); - } else if (LayoutDevicesXsd.NODE_SCREEN_ORIENTATION.equals(localName)) { - ScreenOrientationQualifier soq = new ScreenOrientationQualifier( - ScreenOrientation.getEnum(mStringAccumulator.toString())); - mCurrentConfig.setScreenOrientationQualifier(soq); - } else if (LayoutDevicesXsd.NODE_PIXEL_DENSITY.equals(localName)) { - DensityQualifier dq = new DensityQualifier( - Density.getEnum(mStringAccumulator.toString())); - mCurrentConfig.setDensityQualifier(dq); - } else if (LayoutDevicesXsd.NODE_TOUCH_TYPE.equals(localName)) { - TouchScreenQualifier tsq = new TouchScreenQualifier( - TouchScreen.getEnum(mStringAccumulator.toString())); - mCurrentConfig.setTouchTypeQualifier(tsq); - } else if (LayoutDevicesXsd.NODE_KEYBOARD_STATE.equals(localName)) { - KeyboardStateQualifier ksq = new KeyboardStateQualifier( - KeyboardState.getEnum(mStringAccumulator.toString())); - mCurrentConfig.setKeyboardStateQualifier(ksq); - } else if (LayoutDevicesXsd.NODE_TEXT_INPUT_METHOD.equals(localName)) { - TextInputMethodQualifier timq = new TextInputMethodQualifier( - Keyboard.getEnum(mStringAccumulator.toString())); - mCurrentConfig.setTextInputMethodQualifier(timq); - } else if (LayoutDevicesXsd.NODE_NAV_STATE.equals(localName)) { - NavigationStateQualifier nsq = new NavigationStateQualifier( - NavigationState.getEnum(mStringAccumulator.toString())); - mCurrentConfig.setNavigationStateQualifier(nsq); - } else if (LayoutDevicesXsd.NODE_NAV_METHOD.equals(localName)) { - NavigationMethodQualifier nmq = new NavigationMethodQualifier( - Navigation.getEnum(mStringAccumulator.toString())); - mCurrentConfig.setNavigationMethodQualifier(nmq); - } else if (LayoutDevicesXsd.NODE_SCREEN_DIMENSION.equals(localName)) { - ScreenDimensionQualifier qual = ScreenDimensionQualifier.getQualifier(mSize1, mSize2); - if (qual != null) { - mCurrentConfig.setScreenDimensionQualifier(qual); - } - } else if (LayoutDevicesXsd.NODE_XDPI.equals(localName)) { - mCurrentDevice.setXDpi(Float.parseFloat(mStringAccumulator.toString())); - } else if (LayoutDevicesXsd.NODE_YDPI.equals(localName)) { - mCurrentDevice.setYDpi(Float.parseFloat(mStringAccumulator.toString())); - } else if (LayoutDevicesXsd.NODE_SIZE.equals(localName)) { - if (mSize1 == null) { - mSize1 = mStringAccumulator.toString(); - } else if (mSize2 == null) { - mSize2 = mStringAccumulator.toString(); - } - } - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDeviceManager.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDeviceManager.java deleted file mode 100644 index 988c2f4..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDeviceManager.java +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php - * - * 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. - */ - -package com.android.ide.eclipse.adt.internal.sdk; - -import com.android.ide.common.resources.configuration.FolderConfiguration; -import com.android.ide.eclipse.adt.AdtPlugin; -import com.android.ide.eclipse.adt.internal.sdk.LayoutDevice.DeviceConfig; -import com.android.prefs.AndroidLocation; -import com.android.prefs.AndroidLocation.AndroidLocationException; -import com.android.sdklib.SdkConstants; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Validator; - -/** - * Manages the layout devices. - * They can come from 3 sources: built-in, add-ons, user. - */ -public class LayoutDeviceManager { - - /** - * A SAX error handler that captures the errors and warnings. - * This allows us to capture *all* errors and just not get an exception on the first one. - */ - private static class CaptureErrorHandler implements ErrorHandler { - - private final String mSourceLocation; - - private boolean mFoundError = false; - - CaptureErrorHandler(String sourceLocation) { - mSourceLocation = sourceLocation; - } - - public boolean foundError() { - return mFoundError; - } - - /** - * @throws SAXException - */ - @Override - public void error(SAXParseException ex) throws SAXException { - mFoundError = true; - AdtPlugin.log(ex, "Error validating %1$s", mSourceLocation); - } - - /** - * @throws SAXException - */ - @Override - public void fatalError(SAXParseException ex) throws SAXException { - mFoundError = true; - AdtPlugin.log(ex, "Error validating %1$s", mSourceLocation); - } - - /** - * @throws SAXException - */ - @Override - public void warning(SAXParseException ex) throws SAXException { - // ignore those for now. - } - } - - private final SAXParserFactory mParserFactory; - - private List<LayoutDevice> mDefaultLayoutDevices = - new ArrayList<LayoutDevice>(); - private List<LayoutDevice> mAddOnLayoutDevices = - new ArrayList<LayoutDevice>(); - private final List<LayoutDevice> mUserLayoutDevices = - new ArrayList<LayoutDevice>(); - private List<LayoutDevice> mLayoutDevices; - - LayoutDeviceManager() { - mParserFactory = SAXParserFactory.newInstance(); - mParserFactory.setNamespaceAware(true); - } - - public List<LayoutDevice> getCombinedList() { - return mLayoutDevices; - } - - public List<LayoutDevice> getDefaultLayoutDevices() { - return mDefaultLayoutDevices; - } - - public List<LayoutDevice> getAddOnLayoutDevice() { - return mAddOnLayoutDevices; - } - - public List<LayoutDevice> getUserLayoutDevices() { - return mUserLayoutDevices; - } - - public LayoutDevice getUserLayoutDevice(String name) { - for (LayoutDevice d : mUserLayoutDevices) { - if (d.getName().equals(name)) { - return d; - } - } - - return null; - } - - public LayoutDevice addUserDevice(String name, float xdpi, float ydpi) { - LayoutDevice d = new LayoutDevice(name); - d.setXDpi(xdpi); - d.setYDpi(ydpi); - mUserLayoutDevices.add(d); - combineLayoutDevices(); - - return d; - } - - public void removeUserDevice(LayoutDevice device) { - if (mUserLayoutDevices.remove(device)) { - combineLayoutDevices(); - } - } - - /** - * Replaces a device with a new one with new name and/or x/y dpi, and return the new device. - * If the name and dpi values are identical the given device is returned an nothing is done - * @param device the {@link LayoutDevice} to replace - * @param newName the new name. - * @param newXDpi the new X dpi value - * @param newYDpi the new Y dpi value. - * @return the new LayoutDevice - */ - public LayoutDevice replaceUserDevice(LayoutDevice device, String newName, - float newXDpi, float newYDpi) { - if (device.getName().equals(newName) && device.getXDpi() == newXDpi && - device.getYDpi() == newYDpi) { - return device; - } - - // else create a new device - LayoutDevice newDevice = new LayoutDevice(newName); - newDevice.setXDpi(newXDpi); - newDevice.setYDpi(newYDpi); - - // and get the Folderconfiguration - List<DeviceConfig> configs = device.getConfigs(); - newDevice.addConfigs(configs); - - // replace the old device with the new - mUserLayoutDevices.remove(device); - mUserLayoutDevices.add(newDevice); - combineLayoutDevices(); - - return newDevice; - } - - /** - * Adds or replaces a configuration in a given {@link LayoutDevice}. - * @param device the device to modify - * @param configName the configuration name to add or replace - * @param config the configuration to set - */ - public void addUserConfiguration(LayoutDevice device, String configName, - FolderConfiguration config) { - // check that the device does belong to the user list. - // the main goal is to make sure that this does not belong to the default/addon list. - if (mUserLayoutDevices.contains(device)) { - device.addConfig(configName, config); - } - } - - /** - * Replaces a configuration in a given {@link LayoutDevice}. - * @param device the device to modify - * @param oldConfigName the name of the config to replace. If null, the new config is simply - * added. - * @param newConfigName the configuration name to add or replace - * @param config the configuration to set - */ - public void replaceUserConfiguration(LayoutDevice device, String oldConfigName, - String newConfigName, FolderConfiguration config) { - // check that the device does belong to the user list. - // the main goal is to make sure that this does not belong to the default/addon list. - if (mUserLayoutDevices.contains(device)) { - // if the old and new config name are different, remove the old one - if (oldConfigName != null && oldConfigName.equals(newConfigName) == false) { - device.removeConfig(oldConfigName); - } - - // and then add the new one - device.addConfig(newConfigName, config); - } - } - - /** - * Removes a configuration from a given user {@link LayoutDevice} - * @param device the device to modify - * @param configName the name of the config to remove - */ - public void removeUserConfiguration(LayoutDevice device, String configName) { - // check that the device does belong to the user list. - // the main goal is to make sure that this does not belong to the default/addon list. - if (mUserLayoutDevices.contains(device)) { - device.removeConfig(configName); - } - } - - /** - * Saves the user-made {@link LayoutDevice}s to disk. - */ - public void save() { - try { - String userFolder = AndroidLocation.getFolder(); - File deviceXml = new File(userFolder, SdkConstants.FN_DEVICES_XML); - if (deviceXml.isDirectory() == false) { - write(deviceXml, mUserLayoutDevices); - } - } catch (AndroidLocationException e) { - // no user folder? simply don't save the user layout device. - // we could display the error, but it's likely something else did before, as - // nothing will work w/o it. - AdtPlugin.log(e, "Unable to find user directory"); - } - } - - /** - * Loads the default built-in and user created Layout Devices. - * @param sdkOsLocation location of the SDK. - */ - void loadDefaultAndUserDevices(String sdkOsLocation) { - // load the default devices - loadDefaultLayoutDevices(sdkOsLocation); - - // load the user devices; - try { - String userFolder = AndroidLocation.getFolder(); - File deviceXml = new File(userFolder, SdkConstants.FN_DEVICES_XML); - if (deviceXml.isFile()) { - parseLayoutDevices(deviceXml, mUserLayoutDevices); - } - } catch (AndroidLocationException e) { - // no user folder? simply don't load the user layout device - AdtPlugin.log(e, "Unable to find user directory"); - } - } - - void parseAddOnLayoutDevice(File deviceXml) { - parseLayoutDevices(deviceXml, mAddOnLayoutDevices); - } - - void sealAddonLayoutDevices() { - mAddOnLayoutDevices = Collections.unmodifiableList(mAddOnLayoutDevices); - - combineLayoutDevices(); - } - - /** - * Does the actual parsing of a devices.xml file. - * @param deviceXml the {@link File} to load/parse. This must be an existing file. - * @param list the list in which to write the parsed {@link LayoutDevice}. - */ - private void parseLayoutDevices(File deviceXml, List<LayoutDevice> list) { - // first we validate the XML - try { - Source source = new StreamSource(new FileReader(deviceXml)); - - CaptureErrorHandler errorHandler = new CaptureErrorHandler(deviceXml.getAbsolutePath()); - - Validator validator = LayoutDevicesXsd.getValidator(errorHandler); - validator.validate(source); - - if (errorHandler.foundError() == false) { - // do the actual parsing - LayoutDeviceHandler handler = new LayoutDeviceHandler(); - - SAXParser parser = mParserFactory.newSAXParser(); - parser.parse(new InputSource(new FileInputStream(deviceXml)), handler); - - // get the parsed devices - list.addAll(handler.getDevices()); - } - } catch (SAXException e) { - AdtPlugin.log(e, "Error parsing %1$s", deviceXml.getAbsoluteFile()); - } catch (FileNotFoundException e) { - // this shouldn't happen as we check above. - } catch (IOException e) { - AdtPlugin.log(e, "Error reading %1$s", deviceXml.getAbsoluteFile()); - } catch (ParserConfigurationException e) { - AdtPlugin.log(e, "Error parsing %1$s", deviceXml.getAbsoluteFile()); - } - } - - /** - * Creates some built-it layout devices. - */ - private void loadDefaultLayoutDevices(String sdkOsLocation) { - ArrayList<LayoutDevice> list = new ArrayList<LayoutDevice>(); - File toolsFolder = new File(sdkOsLocation, SdkConstants.OS_SDK_TOOLS_LIB_FOLDER); - if (toolsFolder.isDirectory()) { - File deviceXml = new File(toolsFolder, SdkConstants.FN_DEVICES_XML); - if (deviceXml.isFile()) { - parseLayoutDevices(deviceXml, list); - } - } - mDefaultLayoutDevices = Collections.unmodifiableList(list); - } - - private void combineLayoutDevices() { - ArrayList<LayoutDevice> list = new ArrayList<LayoutDevice>(); - list.addAll(mDefaultLayoutDevices); - list.addAll(mAddOnLayoutDevices); - list.addAll(mUserLayoutDevices); - - mLayoutDevices = Collections.unmodifiableList(list); - } - - /** - * Writes the given {@link LayoutDevice}s into the given file. - * @param deviceXml the file to write. - * @param deviceList the LayoutDevice to write into the file. - */ - private void write(File deviceXml, List<LayoutDevice> deviceList) { - try { - // create a new document - DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); - docFactory.setNamespaceAware(true); - DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); - Document doc = docBuilder.newDocument(); - - // create a base node - Element baseNode = doc.createElementNS( - LayoutDevicesXsd.NS_LAYOUT_DEVICE_XSD, - LayoutDevicesXsd.NODE_LAYOUT_DEVICES); - // create the prefix for the namespace - baseNode.setPrefix("d"); - doc.appendChild(baseNode); - - // fill it with the layout devices. - for (LayoutDevice device : deviceList) { - device.saveTo(doc, baseNode); - } - - // save the document to disk - // Prepare the DOM document for writing - Source source = new DOMSource(doc); - - // Prepare the output file - File file = new File(deviceXml.getAbsolutePath()); - Result result = new StreamResult(file); - - // Write the DOM document to the file - Transformer xformer = TransformerFactory.newInstance().newTransformer(); - xformer.transform(source, result); - } catch (Exception e) { - AdtPlugin.log(e, "Failed to write %s", deviceXml.getAbsolutePath()); - } - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDevicesXsd.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDevicesXsd.java deleted file mode 100755 index 1824959..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/LayoutDevicesXsd.java +++ /dev/null @@ -1,136 +0,0 @@ -/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
- *
- * 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.
- */
-
-package com.android.ide.eclipse.adt.internal.sdk;
-
-
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-
-import java.io.InputStream;
-
-import javax.xml.XMLConstants;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-
-/**
- * Public constants for the layout device description XML Schema.
- */
-public class LayoutDevicesXsd {
-
- /** The XML namespace of the layout-configs XML. */
- public static final String NS_LAYOUT_DEVICE_XSD =
- "http://schemas.android.com/sdk/android/layout-devices/1"; //$NON-NLS-1$
-
- /**
- * The "layout-devices" element is the root element of this schema.
- *
- * It must contain one or more "device" elements that each define the configurations
- * available for a given device.
- *
- * These definitions are used in the Graphical Layout Editor in the
- * Android Development Tools (ADT) plugin for Eclipse.
- */
- public static final String NODE_LAYOUT_DEVICES = "layout-devices"; //$NON-NLS-1$
-
- /**
- * A device element must contain at most one "default" element followed
- * by one or more ""config" elements.
- *
- * The "default" element defines all the default parameters inherited
- * by the following "config" elements. Each "config" element can override
- * the default values, if any.
- *
- * A "device" element also has a required "name" attribute that represents
- * the user-interface name of this device.
- */
- public static final String NODE_DEVICE = "device"; //$NON-NLS-1$
-
- /**
- * The "default" element contains zero or more of all the parameter elements
- * listed below. It defines all the parameters that are common to all
- * declared "config" elements.
- */
- public static final String NODE_DEFAULT = "default"; //$NON-NLS-1$
-
- /**
- * The "config" element contains zero or more of all the parameter elements
- * listed below. The parameters from the "default" element (if present) are
- * automatically inherited and can be overridden.
- */
- public static final String NODE_CONFIG = "config"; //$NON-NLS-1$
-
-
- public static final String NODE_COUNTRY_CODE = "country-code"; //$NON-NLS-1$
-
- public static final String NODE_NETWORK_CODE = "network-code"; //$NON-NLS-1$
-
- public static final String NODE_SCREEN_SIZE = "screen-size"; //$NON-NLS-1$
-
- public static final String NODE_SCREEN_RATIO = "screen-ratio"; //$NON-NLS-1$
-
- public static final String NODE_SCREEN_ORIENTATION = "screen-orientation"; //$NON-NLS-1$
-
- public static final String NODE_PIXEL_DENSITY = "pixel-density"; //$NON-NLS-1$
-
- public static final String NODE_TOUCH_TYPE = "touch-type"; //$NON-NLS-1$
-
- public static final String NODE_KEYBOARD_STATE = "keyboard-state"; //$NON-NLS-1$
-
- public static final String NODE_TEXT_INPUT_METHOD = "text-input-method"; //$NON-NLS-1$
-
- public static final String NODE_NAV_STATE = "nav-state"; //$NON-NLS-1$
-
- public static final String NODE_NAV_METHOD = "nav-method"; //$NON-NLS-1$
-
- public static final String NODE_SCREEN_DIMENSION = "screen-dimension"; //$NON-NLS-1$
-
- /** The screen-dimension element has 2 size element children. */
- public static final String NODE_SIZE = "size"; //$NON-NLS-1$
-
- public static final String NODE_XDPI = "xdpi"; //$NON-NLS-1$
-
- public static final String NODE_YDPI = "ydpi"; //$NON-NLS-1$
-
- /**
- * The "name" attribute, used by both the "device" and the "config"
- * elements. It represents the user-interface name of these objects.
- */
- public static final String ATTR_NAME = "name"; //$NON-NLS-1$
-
- /**
- * Helper to get an input stream of the layout config XML schema.
- */
- public static InputStream getXsdStream() {
- return LayoutDevicesXsd.class.getResourceAsStream("layout-devices.xsd"); //$NON-NLS-1$
- }
-
- /** Helper method that returns a {@link Validator} for our XSD */
- public static Validator getValidator(ErrorHandler handler) throws SAXException {
- InputStream xsdStream = 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;
- }
-
-}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/sdk/TestLayoutDevicesXsd.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/sdk/TestLayoutDevicesXsd.java deleted file mode 100755 index 86fb8a6..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/sdk/TestLayoutDevicesXsd.java +++ /dev/null @@ -1,332 +0,0 @@ -/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
- *
- * 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.
- */
-
-package com.android.ide.eclipse.adt.internal.sdk;
-
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import java.io.InputStream;
-import java.io.StringReader;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Validator;
-
-import junit.framework.TestCase;
-
-/**
- * Tests local validation of a Layout-Devices sample XMLs using an XML Schema validator.
- */
-public class TestLayoutDevicesXsd extends TestCase {
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * A SAX error handler that captures the errors and warnings.
- * This allows us to capture *all* errors and just not get an exception on the first one.
- */
- private static class CaptureErrorHandler implements ErrorHandler {
-
- private String mWarnings = "";
- private String mErrors = "";
-
- @SuppressWarnings("unused")
- public String getErrors() {
- return mErrors;
- }
-
- @SuppressWarnings("unused")
- public String getWarnings() {
- return mWarnings;
- }
-
- /**
- * Verifies if the handler captures some errors or warnings.
- * Prints them on stderr.
- * Also fails the unit test if any error was generated.
- */
- public void verify() {
- if (mWarnings.length() > 0) {
- System.err.println(mWarnings);
- }
-
- if (mErrors.length() > 0) {
- System.err.println(mErrors);
- fail(mErrors);
- }
- }
-
- /**
- * @throws SAXException
- */
- @Override
- public void error(SAXParseException ex) throws SAXException {
- mErrors += "Error: " + ex.getMessage() + "\n";
- }
-
- /**
- * @throws SAXException
- */
- @Override
- public void fatalError(SAXParseException ex) throws SAXException {
- mErrors += "Fatal Error: " + ex.getMessage() + "\n";
- }
-
- /**
- * @throws SAXException
- */
- @Override
- public void warning(SAXParseException ex) throws SAXException {
- mWarnings += "Warning: " + ex.getMessage() + "\n";
- }
-
- }
-
- // --- Helpers ------------
-
- /** An helper that validates a string against an expected regexp. */
- private void assertRegex(String expectedRegexp, String actualString) {
- assertNotNull(actualString);
- assertTrue(
- String.format("Regexp Assertion Failed:\nExpected: %s\nActual: %s\n",
- expectedRegexp, actualString),
- actualString.matches(expectedRegexp));
- }
-
- public void checkFailure(String document, String regexp) throws Exception {
- Source source = new StreamSource(new StringReader(document));
-
- // don't capture the validator errors, we want it to fail and catch the exception
- Validator validator = LayoutDevicesXsd.getValidator(null);
- try {
- validator.validate(source);
- } catch (SAXParseException e) {
- // We expect a parse expression referring to this grammar rule
- assertRegex(regexp, e.getMessage());
- return;
- }
- // If we get here, the validator has not failed as we expected it to.
- fail();
- }
-
- public void checkSuccess(String document) throws Exception {
- Source source = new StreamSource(new StringReader(document));
-
- CaptureErrorHandler handler = new CaptureErrorHandler();
- Validator validator = LayoutDevicesXsd.getValidator(null);
- validator.validate(source);
- handler.verify();
- }
-
- // --- Tests ------------
-
- /** Validate a valid sample using an InputStream */
- public void testValidateLocalRepositoryFile() throws Exception {
-
- InputStream xmlStream =
- TestLayoutDevicesXsd.class.getResourceAsStream("config_sample.xml");
- Source source = new StreamSource(xmlStream);
-
- CaptureErrorHandler handler = new CaptureErrorHandler();
- Validator validator = LayoutDevicesXsd.getValidator(handler);
- validator.validate(source);
- handler.verify();
- }
-
- /** A document should at least have a root to be valid */
- public void testEmptyXml() throws Exception {
- checkFailure(
- // document
- "<?xml version=\"1.0\"?>",
-
- // expected failure
- "Premature end of file.*");
- }
-
- /** A document with an unknown element. */
- public void testUnknownContentXml() throws Exception {
- checkFailure(
- // document
- "<?xml version=\"1.0\"?>" +
- "<d:layout-devices xmlns:d=\"http://schemas.android.com/sdk/android/layout-devices/1\" >" +
- "<d:unknown />" +
- "</d:layout-devices>",
-
- // expected failure
- "cvc-complex-type.2.4.a: Invalid content was found.*");
- }
-
- /** A document with an missing attribute in a device element. */
- public void testIncompleteContentXml() throws Exception {
- checkFailure(
- // document
- "<?xml version=\"1.0\"?>" +
- "<d:layout-devices xmlns:d=\"http://schemas.android.com/sdk/android/layout-devices/1\" >" +
- "<d:device />" +
- "</d:layout-devices>",
-
- // expected failure
- "cvc-complex-type.4: Attribute 'name' must appear on element 'd:device'.");
- }
-
- /** A document with a root element containing no device element is valid. */
- public void testEmptyRootXml() throws Exception {
- checkSuccess(
- // document
- "<?xml version=\"1.0\"?>" +
- "<d:layout-devices xmlns:d=\"http://schemas.android.com/sdk/android/layout-devices/1\" />");
- }
-
- /** A document with an empty device element is not valid. */
- public void testEmptyDeviceXml() throws Exception {
- checkFailure(
- // document
- "<?xml version=\"1.0\"?>" +
- "<d:layout-devices xmlns:d=\"http://schemas.android.com/sdk/android/layout-devices/1\" >" +
- "<d:device name=\"foo\"/>" +
- "</d:layout-devices>",
-
- // expected failure
- "cvc-complex-type.2.4.b: The content of element 'd:device' is not complete.*");
- }
-
- /** A document with two default elements in a device element is not valid. */
- public void testTwoDefaultsXml() throws Exception {
- checkFailure(
- // document
- "<?xml version=\"1.0\"?>" +
- "<d:layout-devices xmlns:d=\"http://schemas.android.com/sdk/android/layout-devices/1\" >" +
- "<d:device name=\"foo\">" +
- " <d:default />" +
- " <d:default />" +
- "</d:device>" +
- "</d:layout-devices>",
-
- // expected failure
- "cvc-complex-type.2.4.a: Invalid content was found starting with element 'd:default'.*");
- }
-
- /** The default elements must be defined before the config one. It's invalid if after. */
- public void testDefaultConfigOrderXml() throws Exception {
- checkFailure(
- // document
- "<?xml version=\"1.0\"?>" +
- "<d:layout-devices xmlns:d=\"http://schemas.android.com/sdk/android/layout-devices/1\" >" +
- "<d:device name=\"foo\">" +
- " <d:config name=\"must-be-after-default\" />" +
- " <d:default />" +
- "</d:device>" +
- "</d:layout-devices>",
-
- // expected failure
- "cvc-complex-type.2.4.a: Invalid content was found starting with element 'd:default'.*");
- }
-
- /** Screen dimension cannot be 0. */
- public void testScreenDimZeroXml() throws Exception {
- checkFailure(
- // document
- "<?xml version=\"1.0\"?>" +
- "<d:layout-devices xmlns:d=\"http://schemas.android.com/sdk/android/layout-devices/1\" >" +
- "<d:device name=\"foo\">" +
- " <d:default>" +
- " <d:screen-dimension> <d:size>0</d:size> <d:size>1</d:size> </d:screen-dimension>" +
- " </d:default>" +
- "</d:device>" +
- "</d:layout-devices>",
-
- // expected failure
- "cvc-minInclusive-valid: Value '0' is not facet-valid with respect to minInclusive '1'.*");
- }
-
- /** Screen dimension cannot be negative. */
- public void testScreenDimNegativeXml() throws Exception {
- checkFailure(
- // document
- "<?xml version=\"1.0\"?>" +
- "<d:layout-devices xmlns:d=\"http://schemas.android.com/sdk/android/layout-devices/1\" >" +
- "<d:device name=\"foo\">" +
- " <d:default>" +
- " <d:screen-dimension> <d:size>-5</d:size> <d:size>1</d:size> </d:screen-dimension>" +
- " </d:default>" +
- "</d:device>" +
- "</d:layout-devices>",
-
- // expected failure
- "cvc-minInclusive-valid: Value '-5' is not facet-valid with respect to minInclusive '1'.*");
- }
-
- /** X/Y dpi cannot be 0. */
- public void testXDpiZeroXml() throws Exception {
- checkFailure(
- // document
- "<?xml version=\"1.0\"?>" +
- "<d:layout-devices xmlns:d=\"http://schemas.android.com/sdk/android/layout-devices/1\" >" +
- "<d:device name=\"foo\">" +
- " <d:default>" +
- " <d:xdpi>0</d:xdpi>" +
- " </d:default>" +
- "</d:device>" +
- "</d:layout-devices>",
-
- // expected failure
- "cvc-minExclusive-valid: Value '0' is not facet-valid with respect to minExclusive '0.0E1'.*");
- }
-
-
- /** X/Y dpi cannot be negative. */
- public void testXDpiNegativeXml() throws Exception {
- checkFailure(
- // document
- "<?xml version=\"1.0\"?>" +
- "<d:layout-devices xmlns:d=\"http://schemas.android.com/sdk/android/layout-devices/1\" >" +
- "<d:device name=\"foo\">" +
- " <d:default>" +
- " <d:xdpi>-3.1415926538</d:xdpi>" +
- " </d:default>" +
- "</d:device>" +
- "</d:layout-devices>",
-
- // expected failure
- "cvc-minExclusive-valid: Value '-3.1415926538' is not facet-valid with respect to minExclusive '0.0E1'.*");
- }
-
- /** WHitespace around token is accepted by the schema. */
- public void testTokenWhitespaceXml() throws Exception {
- checkSuccess(
- // document
- "<?xml version=\"1.0\"?>" +
- "<d:layout-devices xmlns:d=\"http://schemas.android.com/sdk/android/layout-devices/1\" >" +
- "<d:device name=\"foo\">" +
- " <d:config name='foo'>" +
- " <d:screen-ratio> \n long \r </d:screen-ratio>" +
- " </d:config>" +
- "</d:device>" +
- "</d:layout-devices>");
- }
-
-}
-
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/sdk/config_sample.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/sdk/config_sample.xml deleted file mode 100755 index 56a753f..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/sdk/config_sample.xml +++ /dev/null @@ -1,137 +0,0 @@ -<?xml version="1.0"?>
-<!--
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
- *
- * 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.
--->
-<d:layout-devices
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:d="http://schemas.android.com/sdk/android/layout-devices/1">
-
- <d:device name="MyDevice"> <!-- 1..n -->
- <d:default> <!-- 0..1 -->
- <d:screen-size>small</d:screen-size>
- <d:screen-ratio>long</d:screen-ratio>
- <d:screen-orientation>port</d:screen-orientation>
- <d:pixel-density>ldpi</d:pixel-density>
- <d:touch-type>notouch</d:touch-type>
- <d:keyboard-state>keysexposed</d:keyboard-state>
- <d:text-input-method>nokeys</d:text-input-method>
- <d:nav-method>dpad</d:nav-method>
- <d:screen-dimension>
- <d:size>240</d:size> <!-- 2 * int>0 -->
- <d:size>480</d:size>
- </d:screen-dimension>
- <d:xdpi>180.81234</d:xdpi>
- <d:ydpi>180.81234</d:ydpi>
- </d:default>
-
- <d:config name="Portrait">
- <d:keyboard-state>keyshidden</d:keyboard-state>
- <d:screen-orientation>port</d:screen-orientation>
- </d:config>
- <d:config name="Landscape, closed">
- <d:keyboard-state>keyshidden</d:keyboard-state>
- <d:screen-orientation>land</d:screen-orientation>
- </d:config>
- <d:config name="Landscape, open">
- <d:keyboard-state>keysexposed</d:keyboard-state>
- <d:screen-orientation>land</d:screen-orientation>
- </d:config>
-
- <d:config name="screen-size-small">
- <d:screen-size>small</d:screen-size>
- </d:config>
- <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>
- </d:config>
-
- <d:config name="screen-ratio-long">
- <d:screen-ratio>long</d:screen-ratio>
- </d:config>
- <d:config name="screen-ratio-notlong">
- <d:screen-ratio>notlong</d:screen-ratio>
- </d:config>
-
- <d:config name="screen-orientation-port">
- <d:screen-orientation>port</d:screen-orientation>
- </d:config>
- <d:config name="screen-orientation-land">
- <d:screen-orientation>land</d:screen-orientation>
- </d:config>
- <d:config name="screen-orientation-square">
- <d:screen-orientation>square</d:screen-orientation>
- </d:config>
-
- <d:config name="pixel-density-ldpi">
- <d:pixel-density>ldpi</d:pixel-density>
- </d:config>
- <d:config name="pixel-density-mdpi">
- <d:pixel-density>mdpi</d:pixel-density>
- </d:config>
- <d:config name="pixel-density-hdpi">
- <d:pixel-density>hdpi</d:pixel-density>
- </d:config>
-
- <d:config name="touch-type-notouch">
- <d:touch-type>notouch</d:touch-type>
- </d:config>
- <d:config name="touch-type-stylus">
- <d:touch-type>stylus</d:touch-type>
- </d:config>
- <d:config name="touch-type-finger">
- <d:touch-type>finger</d:touch-type>
- </d:config>
-
- <d:config name="text-input-method-nokeys">
- <d:text-input-method>nokeys</d:text-input-method>
- </d:config>
- <d:config name="text-input-method-qwerty">
- <d:text-input-method>qwerty</d:text-input-method>
- </d:config>
- <d:config name="text-input-method-12key">
- <d:text-input-method>12key</d:text-input-method>
- </d:config>
-
- <d:config name="nav-method-dpad">
- <d:nav-method>dpad</d:nav-method>
- </d:config>
- <d:config name="nav-method-trackball">
- <d:nav-method>trackball</d:nav-method>
- </d:config>
- <d:config name="nav-method-wheel">
- <d:nav-method>wheel</d:nav-method>
- </d:config>
- <d:config name="nav-method-nonav">
- <d:nav-method>nonav</d:nav-method>
- </d:config>
-
- <d:config name="xdpi">
- <d:xdpi>240</d:xdpi>
- </d:config>
- <d:config name="ydpi">
- <d:ydpi>2800</d:ydpi>
- </d:config>
-
- </d:device>
-
- <d:device name="SomePhone"> <!-- 1..n -->
- <d:config name="screen-size-normal">
- <d:screen-size>normal</d:screen-size>
- </d:config>
- </d:device>
-
-</d:layout-devices>
|