diff options
author | Raphael <raphael@google.com> | 2010-08-11 19:33:42 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-10-27 15:11:29 -0700 |
commit | f0a7b02920c4998166a2027682a0e81325a73d75 (patch) | |
tree | 17c55c2aca48852d123210dd2cb1788ad0029a45 | |
parent | 26e2ecd83bf05f63786d3495603043c0dd563f02 (diff) | |
download | sdk-f0a7b02920c4998166a2027682a0e81325a73d75.zip sdk-f0a7b02920c4998166a2027682a0e81325a73d75.tar.gz sdk-f0a7b02920c4998166a2027682a0e81325a73d75.tar.bz2 |
Fix resource issues in ADT.
Change-Id: I744833ec03d0d379ea526c193549f99f25f6811a
15 files changed, 174 insertions, 12 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceType.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceType.java index 008e1fa..f09719c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceType.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceType.java @@ -44,7 +44,7 @@ public enum ResourceType { mDisplayName = displayName; mAlternateXmlNames = alternateXmlNames; } - + /** * Returns the resource type name, as used by XML files. */ @@ -58,7 +58,7 @@ public enum ResourceType { public String getDisplayName() { return mDisplayName; } - + /** * Returns the enum by its name as it appears in the XML or the R class. * @param name name of the resource @@ -79,12 +79,12 @@ public enum ResourceType { } return null; } - + /** * Returns a formatted string usable in an XML to use the specified {@link ResourceItem}. * @param resourceItem The resource item. * @param system Whether this is a system resource or a project resource. - * @return a string in the format @[type]/[name] + * @return a string in the format @[type]/[name] */ public String getXmlString(ResourceItem resourceItem, boolean system) { if (this == ID && resourceItem instanceof IIdResourceItem) { @@ -96,7 +96,7 @@ public enum ResourceType { return (system?"@android:":"@") + mName + "/" + resourceItem.getName(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - + /** * Returns an array with all the names defined by this enum. */ @@ -108,4 +108,9 @@ public enum ResourceType { } return names; } + + @Override + public String toString() { + return getName(); + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/DockModeQualifier.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/DockModeQualifier.java index 8b431b1..f92fe55 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/DockModeQualifier.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/DockModeQualifier.java @@ -95,9 +95,13 @@ public final class DockModeQualifier extends EnumBasedResourceQualifier { DockModeQualifier compareQualifier = (DockModeQualifier)compareTo; DockModeQualifier referenceQualifier = (DockModeQualifier)reference; - // if they are a perfect match, the receiver cannot be a better match. + if (compareQualifier.getValue() == referenceQualifier.getValue()) { + // what we have is already the best possible match (exact match) return false; + } else if (mValue == referenceQualifier.mValue) { + // got new exact value, this is the best! + return true; } else if (mValue == DockMode.NONE) { // else "none" can be a match in case there's no exact match return true; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/KeyboardStateQualifier.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/KeyboardStateQualifier.java index 6c6e961..88b8fc8 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/KeyboardStateQualifier.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/KeyboardStateQualifier.java @@ -101,6 +101,7 @@ public final class KeyboardStateQualifier extends EnumBasedResourceQualifier { KeyboardStateQualifier compareQualifier = (KeyboardStateQualifier)compareTo; KeyboardStateQualifier referenceQualifier = (KeyboardStateQualifier)reference; + if (referenceQualifier.mValue == KeyboardState.SOFT) { // only case where there could be a // better qualifier // only return true if it's a better value. diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/PixelDensityQualifier.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/PixelDensityQualifier.java index e4cc1bc..5237ab0 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/PixelDensityQualifier.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/PixelDensityQualifier.java @@ -116,8 +116,11 @@ public final class PixelDensityQualifier extends EnumBasedResourceQualifier { PixelDensityQualifier compareQ = (PixelDensityQualifier)compareTo; PixelDensityQualifier referenceQ = (PixelDensityQualifier)reference; - if (mValue == referenceQ.mValue && compareQ.mValue != referenceQ.mValue) { - // got exact value, this is the best! + if (compareQ.mValue == referenceQ.mValue) { + // what we have is already the best possible match (exact match) + return false; + } else if (mValue == referenceQ.mValue) { + // got new exact value, this is the best! return true; } else { // in all case we're going to prefer the higher dpi. diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/ScreenSizeQualifier.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/ScreenSizeQualifier.java index b36bd09..ed07380 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/ScreenSizeQualifier.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/ScreenSizeQualifier.java @@ -23,7 +23,7 @@ import com.android.sdklib.resources.ScreenSize; import org.eclipse.swt.graphics.Image; /** - * Resource Qualifier for Screen Size. Size can be "small", "normal", and "large" + * Resource Qualifier for Screen Size. Size can be "small", "normal", "large" and "x-large" */ public class ScreenSizeQualifier extends EnumBasedResourceQualifier { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ProjectResources.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ProjectResources.java index d3f1190..ae6e06b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ProjectResources.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ProjectResources.java @@ -347,8 +347,7 @@ public class ProjectResources implements IResourceRepository { // look for folders containing a file with the given name. ArrayList<ResourceFolder> matchingFolders = new ArrayList<ResourceFolder>(); - // remove the folders that do not have a file with the given name, or if their config - // is incompatible. + // remove the folders that do not have a file with the given name. for (int i = 0 ; i < folders.size(); i++) { ResourceFolder folder = folders.get(i); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceFile.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceFile.java index 1543abc..3a349be 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceFile.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceFile.java @@ -96,5 +96,10 @@ public abstract class ResourceFile extends Resource { * @param name the name of the resource. */ public abstract IResourceValue getValue(ResourceType type, String name); + + @Override + public String toString() { + return mFile.toString(); + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceFolder.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceFolder.java index b04000f..f9cc256 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceFolder.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceFolder.java @@ -259,4 +259,9 @@ public final class ResourceFolder extends Resource { } return list; } + + @Override + public String toString() { + return mFolder.toString(); + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/layout-devices.xsd b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/layout-devices.xsd index 340a1bc..74f22a9 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/layout-devices.xsd +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/layout-devices.xsd @@ -133,6 +133,7 @@ <xsd:enumeration value="small" /> <xsd:enumeration value="normal" /> <xsd:enumeration value="large" /> + <xsd:enumeration value="xlarge" /> </xsd:restriction> </xsd:simpleType> </xsd:element> @@ -187,6 +188,7 @@ <xsd:enumeration value="ldpi" /> <xsd:enumeration value="mdpi" /> <xsd:enumeration value="hdpi" /> + <xsd:enumeration value="xhdpi" /> </xsd:restriction> </xsd:simpleType> </xsd:element> diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/DockModeQualifierTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/DockModeQualifierTest.java index 1cdc91b..f760a89 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/DockModeQualifierTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/DockModeQualifierTest.java @@ -49,7 +49,10 @@ public class DockModeQualifierTest extends TestCase { assertTrue(mNoneQualifier.isBetterMatchThan(mDeskQualifier, mCarQualifier)); assertFalse(mNoneQualifier.isBetterMatchThan(mCarQualifier, mCarQualifier)); + assertTrue(mDeskQualifier.isBetterMatchThan(mCarQualifier, mDeskQualifier)); assertFalse(mDeskQualifier.isBetterMatchThan(mCarQualifier, mCarQualifier)); + + assertTrue(mCarQualifier.isBetterMatchThan(mDeskQualifier, mCarQualifier)); assertFalse(mCarQualifier.isBetterMatchThan(mDeskQualifier, mDeskQualifier)); } diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/PixelDensityQualifierTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/PixelDensityQualifierTest.java index bb05adb..f165d7f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/PixelDensityQualifierTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/PixelDensityQualifierTest.java @@ -56,4 +56,65 @@ public class PixelDensityQualifierTest extends TestCase { assertEquals(false, pdq.checkAndSet("sdfdpi", config));//$NON-NLS-1$ } + public void testIsBetterMatchThan() { + PixelDensityQualifier ldpi = new PixelDensityQualifier(Density.LOW); + PixelDensityQualifier mdpi = new PixelDensityQualifier(Density.MEDIUM); + PixelDensityQualifier hdpi = new PixelDensityQualifier(Density.HIGH); + PixelDensityQualifier xhdpi = new PixelDensityQualifier(Density.XHIGH); + + // first test that each Q is a better match than all other Qs when the ref is the same Q. + assertTrue(ldpi.isBetterMatchThan(mdpi, ldpi)); + assertTrue(ldpi.isBetterMatchThan(hdpi, ldpi)); + assertTrue(ldpi.isBetterMatchThan(xhdpi, ldpi)); + + assertTrue(mdpi.isBetterMatchThan(ldpi, mdpi)); + assertTrue(mdpi.isBetterMatchThan(hdpi, mdpi)); + assertTrue(mdpi.isBetterMatchThan(xhdpi, mdpi)); + + assertTrue(hdpi.isBetterMatchThan(ldpi, hdpi)); + assertTrue(hdpi.isBetterMatchThan(mdpi, hdpi)); + assertTrue(hdpi.isBetterMatchThan(xhdpi, hdpi)); + + assertTrue(xhdpi.isBetterMatchThan(ldpi, xhdpi)); + assertTrue(xhdpi.isBetterMatchThan(mdpi, xhdpi)); + assertTrue(xhdpi.isBetterMatchThan(hdpi, xhdpi)); + + // now test that the highest dpi is always preferable if there's no exact match + + // looking for ldpi: + assertTrue(hdpi.isBetterMatchThan(mdpi, ldpi)); + assertTrue(xhdpi.isBetterMatchThan(mdpi, ldpi)); + assertTrue(xhdpi.isBetterMatchThan(hdpi, ldpi)); + // the other way around + assertFalse(mdpi.isBetterMatchThan(hdpi, ldpi)); + assertFalse(mdpi.isBetterMatchThan(xhdpi, ldpi)); + assertFalse(hdpi.isBetterMatchThan(xhdpi, ldpi)); + + // looking for mdpi + assertTrue(hdpi.isBetterMatchThan(ldpi, mdpi)); + assertTrue(xhdpi.isBetterMatchThan(ldpi, mdpi)); + assertTrue(xhdpi.isBetterMatchThan(hdpi, mdpi)); + // the other way around + assertFalse(ldpi.isBetterMatchThan(hdpi, mdpi)); + assertFalse(ldpi.isBetterMatchThan(xhdpi, mdpi)); + assertFalse(hdpi.isBetterMatchThan(xhdpi, mdpi)); + + // looking for hdpi + assertTrue(mdpi.isBetterMatchThan(ldpi, hdpi)); + assertTrue(xhdpi.isBetterMatchThan(ldpi, hdpi)); + assertTrue(xhdpi.isBetterMatchThan(mdpi, hdpi)); + // the other way around + assertFalse(ldpi.isBetterMatchThan(mdpi, hdpi)); + assertFalse(ldpi.isBetterMatchThan(xhdpi, hdpi)); + assertFalse(mdpi.isBetterMatchThan(xhdpi, hdpi)); + + // looking for xhdpi + assertTrue(mdpi.isBetterMatchThan(ldpi, xhdpi)); + assertTrue(hdpi.isBetterMatchThan(ldpi, xhdpi)); + assertTrue(hdpi.isBetterMatchThan(mdpi, xhdpi)); + // the other way around + assertFalse(ldpi.isBetterMatchThan(mdpi, xhdpi)); + assertFalse(ldpi.isBetterMatchThan(hdpi, xhdpi)); + assertFalse(mdpi.isBetterMatchThan(hdpi, xhdpi)); + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/ScreenSizeQualifierTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/ScreenSizeQualifierTest.java new file mode 100644 index 0000000..c605db5 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/ScreenSizeQualifierTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2010 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.editors.resources.configurations; + +import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration; +import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenSizeQualifier; +import com.android.sdklib.resources.ScreenSize; + +import junit.framework.TestCase; + +public class ScreenSizeQualifierTest extends TestCase { + + private ScreenSizeQualifier ssq; + private FolderConfiguration config; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ssq = new ScreenSizeQualifier(); + config = new FolderConfiguration(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + ssq = null; + config = null; + } + + public void testSmall() { + assertEquals(true, ssq.checkAndSet("small", config)); //$NON-NLS-1$ + assertTrue(config.getScreenSizeQualifier() != null); + assertEquals(ScreenSize.SMALL, config.getScreenSizeQualifier().getValue()); + assertEquals("small", config.getScreenSizeQualifier().toString()); //$NON-NLS-1$ + } + + public void testNormal() { + assertEquals(true, ssq.checkAndSet("normal", config)); //$NON-NLS-1$ + assertTrue(config.getScreenSizeQualifier() != null); + assertEquals(ScreenSize.NORMAL, config.getScreenSizeQualifier().getValue()); + assertEquals("normal", config.getScreenSizeQualifier().toString()); //$NON-NLS-1$ + } + + public void testLarge() { + assertEquals(true, ssq.checkAndSet("large", config)); //$NON-NLS-1$ + assertTrue(config.getScreenSizeQualifier() != null); + assertEquals(ScreenSize.LARGE, config.getScreenSizeQualifier().getValue()); + assertEquals("large", config.getScreenSizeQualifier().toString()); //$NON-NLS-1$ + } + + public void testXLarge() { + assertEquals(true, ssq.checkAndSet("xlarge", config)); //$NON-NLS-1$ + assertTrue(config.getScreenSizeQualifier() != null); + assertEquals(ScreenSize.XLARGE, config.getScreenSizeQualifier().getValue()); + assertEquals("xlarge", config.getScreenSizeQualifier().toString()); //$NON-NLS-1$ + } +} diff --git a/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java index c004f2f..e969034 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java +++ b/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java @@ -22,6 +22,7 @@ package com.android.layoutlib.api; public interface IDensityBasedResourceValue extends IResourceValue { public static enum Density { + XHIGH(320), HIGH(240), MEDIUM(160), LOW(120), diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/Density.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/Density.java index ac0fb91..c6f5b2a 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/Density.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/Density.java @@ -23,6 +23,7 @@ package com.android.sdklib.resources; * as well as other places needing to know the density values. */ public enum Density implements ResourceEnum { + XHIGH("xhdpi", "X-High Density", 320), //$NON-NLS-1$ HIGH("hdpi", "High Density", 240), //$NON-NLS-1$ MEDIUM("mdpi", "Medium Density", 160), //$NON-NLS-1$ LOW("ldpi", "Low Density", 120), //$NON-NLS-1$ diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/ScreenSize.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/ScreenSize.java index dc94afb..d6fc99d 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/ScreenSize.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/ScreenSize.java @@ -23,7 +23,8 @@ package com.android.sdklib.resources; public enum ScreenSize implements ResourceEnum { SMALL("small", "Small", "Small Screen"), //$NON-NLS-1$ NORMAL("normal", "Normal", "Normal Screen"), //$NON-NLS-1$ - LARGE("large", "Large", "Large Screen"); //$NON-NLS-1$ + LARGE("large", "Large", "Large Screen"), //$NON-NLS-1$ + XLARGE("xlarge", "X-Large", "Extra Large Screen"); //$NON-NLS-1$ private final String mValue; private final String mShortDisplayValue; |