Create Density based resource values when needed.

This will let the layoutlib know when to scale bitmaps
that are not in the native density of the rendering.

Change-Id: I08c99666460b5b5a3ed8d0aac7fa1b7c0136fd6b
This commit is contained in:
Xavier Ducrohet
2009-09-22 18:32:17 -07:00
parent 038300d95f
commit 350187ab93
4 changed files with 89 additions and 33 deletions

View File

@@ -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()) {

View File

@@ -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;
@@ -66,8 +68,16 @@ 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

View File

@@ -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;
}
}