aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/PixelDensityQualifier.java22
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/MultiResourceFile.java26
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/SingleResourceFile.java40
-rw-r--r--layoutlib_utils/src/com/android/layoutlib/utils/DensityBasedResourceValue.java34
4 files changed, 89 insertions, 33 deletions
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 d67d4ae..0ba2aac 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
@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory;
+import com.android.layoutlib.api.IDensityBasedResourceValue;
import com.android.sdklib.AndroidVersion;
import com.android.sdklib.IAndroidTarget;
@@ -39,19 +40,22 @@ public final class PixelDensityQualifier extends ResourceQualifier {
* Screen Orientation enum.
*/
public static enum Density {
- HIGH("hdpi", 240, "High Density"), //$NON-NLS-1$
- MEDIUM("mdpi", 160, "Medium Density"), //$NON-NLS-1$
- LOW("ldpi", 120, "Low Density"), //$NON-NLS-1$
- NODPI("nodpi", -1, "No Density"); //$NON-NLS-1$
+ HIGH("hdpi", 240, "High Density", IDensityBasedResourceValue.Density.HIGH), //$NON-NLS-1$
+ MEDIUM("mdpi", 160, "Medium Density", IDensityBasedResourceValue.Density.MEDIUM), //$NON-NLS-1$
+ LOW("ldpi", 120, "Low Density", IDensityBasedResourceValue.Density.LOW), //$NON-NLS-1$
+ NODPI("nodpi", -1, "No Density", IDensityBasedResourceValue.Density.NODPI); //$NON-NLS-1$
private final String mValue;
private final String mDisplayValue;
private final int mDpiValue;
+ private final IDensityBasedResourceValue.Density mDensity;
- private Density(String value, int dpiValue, String displayValue) {
+ private Density(String value, int dpiValue, String displayValue,
+ IDensityBasedResourceValue.Density density) {
mValue = value;
mDpiValue = dpiValue;
mDisplayValue = displayValue;
+ mDensity = density;
}
/**
@@ -109,6 +113,14 @@ public final class PixelDensityQualifier extends ResourceQualifier {
return mDisplayValue;
}
+ /**
+ * Returns the {@link com.android.layoutlib.api.IDensityBasedResourceValue.Density} value
+ * associated to this {@link Density}.
+ */
+ public IDensityBasedResourceValue.Density getDensity() {
+ return mDensity;
+ }
+
public static int getIndex(Density value) {
int i = 0;
for (Density input : values()) {
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/MultiResourceFile.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/MultiResourceFile.java
index 7528441..2d2749d 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/MultiResourceFile.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/MultiResourceFile.java
@@ -45,7 +45,7 @@ import javax.xml.parsers.SAXParserFactory;
public final class MultiResourceFile extends ResourceFile implements IValueResourceRepository {
private final static SAXParserFactory sParserFactory = SAXParserFactory.newInstance();
-
+
private final HashMap<ResourceType, HashMap<String, ResourceValue>> mResourceItems =
new HashMap<ResourceType, HashMap<String, ResourceValue>>();
@@ -58,7 +58,7 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou
update();
Set<ResourceType> keys = mResourceItems.keySet();
-
+
return keys.toArray(new ResourceType[keys.size()]);
}
@@ -69,21 +69,21 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou
HashMap<String, ResourceValue> list = mResourceItems.get(type);
return (list != null && list.size() > 0);
}
-
+
@Override
public Collection<ProjectResourceItem> getResources(ResourceType type,
ProjectResources projectResources) {
update();
HashMap<String, ResourceValue> list = mResourceItems.get(type);
-
+
ArrayList<ProjectResourceItem> items = new ArrayList<ProjectResourceItem>();
-
+
if (list != null) {
Collection<ResourceValue> values = list.values();
for (ResourceValue res : values) {
ProjectResourceItem item = projectResources.findResourceItem(type, res.getName());
-
+
if (item == null) {
if (type == ResourceType.ID) {
item = new IdResourceItem(res.getName(), false /* isDeclaredInline */);
@@ -99,7 +99,7 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou
return items;
}
-
+
/**
* Updates the Resource items if necessary.
*/
@@ -110,7 +110,7 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou
// need to parse the file and find the content.
parseFile();
-
+
resetTouch();
}
}
@@ -128,7 +128,7 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou
} catch (CoreException e) {
}
}
-
+
/**
* Adds a resource item to the list
* @param resType The type of the resource
@@ -138,7 +138,7 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou
ResourceType type = ResourceType.getEnum(resType);
if (type != null) {
HashMap<String, ResourceValue> list = mResourceItems.get(type);
-
+
// if the list does not exist, create it.
if (list == null) {
list = new HashMap<String, ResourceValue>();
@@ -146,13 +146,13 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou
} else {
// look for a possible value already existing.
ResourceValue oldValue = list.get(value.getName());
-
+
if (oldValue != null) {
oldValue.replaceWith(value);
return;
}
}
-
+
// empty list or no match found? add the given resource
list.put(value.getName(), value);
}
@@ -168,7 +168,7 @@ public final class MultiResourceFile extends ResourceFile implements IValueResou
if (list != null) {
return list.get(name);
}
-
+
return null;
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/SingleResourceFile.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/SingleResourceFile.java
index 51bd793..8900500 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/SingleResourceFile.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/SingleResourceFile.java
@@ -17,8 +17,10 @@
package com.android.ide.eclipse.adt.internal.resources.manager;
import com.android.ide.eclipse.adt.internal.resources.ResourceType;
+import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier;
import com.android.ide.eclipse.adt.internal.resources.manager.files.IAbstractFile;
import com.android.layoutlib.api.IResourceValue;
+import com.android.layoutlib.utils.DensityBasedResourceValue;
import com.android.layoutlib.utils.ResourceValue;
import java.util.ArrayList;
@@ -40,24 +42,24 @@ public class SingleResourceFile extends ResourceFile {
static {
sParserFactory.setNamespaceAware(true);
}
-
+
private final static Pattern sXmlPattern = Pattern.compile("^(.+)\\.xml", //$NON-NLS-1$
Pattern.CASE_INSENSITIVE);
-
+
private final static Pattern[] sDrawablePattern = new Pattern[] {
Pattern.compile("^(.+)\\.9\\.png", Pattern.CASE_INSENSITIVE), //$NON-NLS-1$
Pattern.compile("^(.+)\\.png", Pattern.CASE_INSENSITIVE), //$NON-NLS-1$
Pattern.compile("^(.+)\\.jpg", Pattern.CASE_INSENSITIVE), //$NON-NLS-1$
Pattern.compile("^(.+)\\.gif", Pattern.CASE_INSENSITIVE), //$NON-NLS-1$
};
-
+
private String mResourceName;
private ResourceType mType;
private IResourceValue mValue;
public SingleResourceFile(IAbstractFile file, ResourceFolder folder) {
super(file, folder);
-
+
// we need to infer the type of the resource from the folder type.
// This is easy since this is a single Resource file.
ResourceType[] types = FolderTypeRelationship.getRelatedResourceTypes(folder.getType());
@@ -65,9 +67,17 @@ public class SingleResourceFile extends ResourceFile {
// compute the resource name
mResourceName = getResourceName(mType);
-
- mValue = new ResourceValue(mType.getName(), getResourceName(mType), file.getOsLocation(),
- isFramework());
+
+ // test if there's a density qualifier associated with the resource
+ PixelDensityQualifier qualifier = folder.getConfiguration().getPixelDensityQualifier();
+
+ if (qualifier == null) {
+ mValue = new ResourceValue(mType.getName(), getResourceName(mType),
+ file.getOsLocation(), isFramework());
+ } else {
+ mValue = new DensityBasedResourceValue(mType.getName(), getResourceName(mType),
+ file.getOsLocation(), qualifier.getValue().getDensity(), isFramework());
+ }
}
@Override
@@ -83,27 +93,27 @@ public class SingleResourceFile extends ResourceFile {
@Override
public Collection<ProjectResourceItem> getResources(ResourceType type,
ProjectResources projectResources) {
-
+
// looking for an existing ResourceItem with this name and type
ProjectResourceItem item = projectResources.findResourceItem(type, mResourceName);
-
+
ArrayList<ProjectResourceItem> items = new ArrayList<ProjectResourceItem>();
if (item == null) {
item = new ConfigurableResourceItem(mResourceName);
items.add(item);
}
-
+
// add this ResourceFile to the ResourceItem
item.add(this);
-
+
return items;
}
/*
* (non-Javadoc)
* @see com.android.ide.eclipse.editors.resources.manager.ResourceFile#getValue(com.android.ide.eclipse.common.resources.ResourceType, java.lang.String)
- *
+ *
* This particular implementation does not care about the type or name since a
* SingleResourceFile represents a file generating only one resource.
* The value returned is the full absolute path of the file in OS form.
@@ -112,14 +122,14 @@ public class SingleResourceFile extends ResourceFile {
public IResourceValue getValue(ResourceType type, String name) {
return mValue;
}
-
+
/**
* Returns the name of the resources.
*/
private String getResourceName(ResourceType type) {
// get the name from the filename.
String name = getFile().getName();
-
+
if (type == ResourceType.ANIM || type == ResourceType.LAYOUT || type == ResourceType.MENU ||
type == ResourceType.COLOR || type == ResourceType.XML) {
Matcher m = sXmlPattern.matcher(name);
@@ -133,7 +143,7 @@ public class SingleResourceFile extends ResourceFile {
return m.group(1);
}
}
-
+
// also try the Xml pattern for selector/shape based drawable.
Matcher m = sXmlPattern.matcher(name);
if (m.matches()) {
diff --git a/layoutlib_utils/src/com/android/layoutlib/utils/DensityBasedResourceValue.java b/layoutlib_utils/src/com/android/layoutlib/utils/DensityBasedResourceValue.java
new file mode 100644
index 0000000..59de463
--- /dev/null
+++ b/layoutlib_utils/src/com/android/layoutlib/utils/DensityBasedResourceValue.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2008 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.
+ */
+
+package com.android.layoutlib.utils;
+
+import com.android.layoutlib.api.IDensityBasedResourceValue;
+
+public class DensityBasedResourceValue extends ResourceValue implements IDensityBasedResourceValue {
+
+ private Density mDensity;
+
+ public DensityBasedResourceValue(String type, String name, String value, Density density,
+ boolean isFramework) {
+ super(type, name, value, isFramework);
+ mDensity = density;
+ }
+
+ public Density getDensity() {
+ return mDensity;
+ }
+}