Merge change Ie905f9b5 into eclair

* changes:
  Add support for xdpi and ydpi in the device config for the GLE.
This commit is contained in:
Android (Google) Code Review
2009-09-30 16:17:34 -04:00
5 changed files with 121 additions and 45 deletions

View File

@@ -24,8 +24,6 @@ import com.android.ide.eclipse.adt.internal.editors.layout.parts.ElementCreateCo
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;
import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier.Density;
import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFile;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;
@@ -849,22 +847,14 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
Rectangle rect = getBounds();
boolean isProjectTheme = mConfigComposite.isProjectTheme();
// FIXME pass the density/dpi from somewhere (resource config or skin).
// For now, get it from the config
int density = Density.MEDIUM.getDpiValue();
PixelDensityQualifier qual =
mConfigComposite.getCurrentConfig().getPixelDensityQualifier();
if (qual != null) {
int d = qual.getValue().getDpiValue();
if (d > 0) {
density = d;
}
}
int density = mConfigComposite.getDensity().getDpiValue();
float xdpi = mConfigComposite.getXDpi();
float ydpi = mConfigComposite.getYDpi();
ILayoutResult result = computeLayout(bridge, parser,
iProject /* projectKey */,
rect.width, rect.height, !mConfigComposite.getClipping(),
density, density, density,
density, xdpi, ydpi,
theme, isProjectTheme,
configuredProjectRes, frameworkResources, mProjectCallback,
mLogger);

View File

@@ -31,8 +31,6 @@ import com.android.ide.eclipse.adt.internal.editors.ui.tree.PasteAction;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;
import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier.Density;
import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFile;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;
@@ -949,22 +947,14 @@ public class GraphicalLayoutEditor extends GraphicalEditorWithPalette
Rectangle rect = getBounds();
boolean isProjectTheme = mConfigComposite.isProjectTheme();
// FIXME pass the density/dpi from somewhere (resource config or skin).
// For now, get it from the config
int density = Density.MEDIUM.getDpiValue();
PixelDensityQualifier qual =
mConfigComposite.getCurrentConfig().getPixelDensityQualifier();
if (qual != null) {
int d = qual.getValue().getDpiValue();
if (d > 0) {
density = d;
}
}
int density = mConfigComposite.getDensity().getDpiValue();
float xdpi = mConfigComposite.getXDpi();
float ydpi = mConfigComposite.getYDpi();
ILayoutResult result = computeLayout(bridge, parser,
iProject /* projectKey */,
rect.width, rect.height, !mConfigComposite.getClipping(),
density, density, density,
density, xdpi, ydpi,
theme, isProjectTheme,
configuredProjectRes, frameworkResources, mProjectCallback,
mLogger);

View File

@@ -20,11 +20,13 @@ import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.ide.eclipse.adt.internal.resources.ResourceType;
import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;
import com.android.ide.eclipse.adt.internal.resources.configurations.LanguageQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.RegionQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.ResourceQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenDimensionQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenOrientationQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.VersionQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier.Density;
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenOrientationQualifier.ScreenOrientation;
import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources;
import com.android.ide.eclipse.adt.internal.sdk.DeviceConfiguration;
@@ -84,6 +86,8 @@ public class ConfigurationComposite extends Composite {
private boolean mClipping = true;
private DeviceConfiguration mCurrentDevice;
/**
* Interface implemented by the part which owns a {@link ConfigurationComposite}.
* This notifies the owners when the configuration change.
@@ -227,15 +231,73 @@ public class ConfigurationComposite extends Composite {
config.set(mCurrentConfig);
}
/**
* Returns the currently selected {@link Density}. This is guaranteed to be non null.
*/
public Density getDensity() {
if (mCurrentConfig != null) {
PixelDensityQualifier qual = mCurrentConfig.getPixelDensityQualifier();
if (qual != null) {
// just a sanity check
Density d = qual.getValue();
if (d != Density.NODPI) {
return d;
}
}
}
// no config? return medium as the default density.
return Density.MEDIUM;
}
/**
* Returns the current device xdpi.
*/
public float getXDpi() {
if (mCurrentDevice != null) {
float dpi = mCurrentDevice.getXDpi();
if (Float.isNaN(dpi) == false) {
return dpi;
}
}
// get the pixel density as the density.
return getDensity().getDpiValue();
}
/**
* Returns the current device ydpi.
*/
public float getYDpi() {
if (mCurrentDevice != null) {
float dpi = mCurrentDevice.getYDpi();
if (Float.isNaN(dpi) == false) {
return dpi;
}
}
// get the pixel density as the density.
return getDensity().getDpiValue();
}
public Rectangle getScreenBounds() {
// get the orientation from the current device config
ScreenOrientationQualifier qual = mCurrentConfig.getScreenOrientationQualifier();
ScreenOrientation orientation = qual.getValue();
ScreenOrientation orientation = ScreenOrientation.PORTRAIT;
if (qual != null) {
orientation = qual.getValue();
}
// get the device screen dimension
ScreenDimensionQualifier qual2 = mCurrentConfig.getScreenDimensionQualifier();
int s1 = qual2.getValue1();
int s2 = qual2.getValue2();
int s1, s2;
if (qual2 != null) {
s1 = qual2.getValue1();
s2 = qual2.getValue2();
} else {
s1 = 480;
s2 = 320;
}
switch (orientation) {
default:
@@ -512,11 +574,16 @@ public class ConfigurationComposite extends Composite {
private void onDeviceChange(boolean recomputeLayout) {
int deviceIndex = mDeviceList.getSelectionIndex();
DeviceConfiguration device = mDevices.get(deviceIndex);
if (deviceIndex != -1) {
mCurrentDevice = mDevices.get(deviceIndex);
} else {
mCurrentDevice = null;
}
mDeviceConfigs.removeAll();
Set<String> configNames = device.getConfigs().keySet();
if (mCurrentDevice != null) {
Set<String> configNames = mCurrentDevice.getConfigs().keySet();
for (String name : configNames) {
mDeviceConfigs.add(name);
}
@@ -526,19 +593,17 @@ public class ConfigurationComposite extends Composite {
mDeviceConfigs.setEnabled(false);
}
}
if (recomputeLayout) {
onDeviceConfigChange();
}
}
private void onDeviceConfigChange() {
if (mDevices != null) {
int deviceIndex = mDeviceList.getSelectionIndex();
DeviceConfiguration device = mDevices.get(deviceIndex);
if (mCurrentDevice != null) {
int configIndex = mDeviceConfigs.getSelectionIndex();
String name = mDeviceConfigs.getItem(configIndex);
FolderConfiguration config = device.getConfigs().get(name);
FolderConfiguration config = mCurrentDevice.getConfigs().get(name);
// get the current qualifiers from the current config
LanguageQualifier lang = mCurrentConfig.getLanguageQualifier();

View File

@@ -25,8 +25,11 @@ import java.util.Map;
public class DeviceConfiguration {
private final String mName;
private Map<String, FolderConfiguration> mMap =
new HashMap<String, FolderConfiguration>();
private float mXDpi = Float.NaN;
private float mYDpi = Float.NaN;
DeviceConfiguration(String name) {
mName = name;
@@ -40,6 +43,14 @@ public class DeviceConfiguration {
mMap = Collections.unmodifiableMap(mMap);
}
void setXDpi(float xdpi) {
mXDpi = xdpi;
}
void setYDpi(float ydpi) {
mYDpi = ydpi;
}
public String getName() {
return mName;
}
@@ -47,4 +58,20 @@ public class DeviceConfiguration {
public Map<String, FolderConfiguration> getConfigs() {
return mMap;
}
/**
* 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;
}
}

View File

@@ -670,6 +670,8 @@ public class Sdk implements IProjectListener {
*/
private void createDefaultLayoutDevices() {
DeviceConfiguration adp1 = new DeviceConfiguration("ADP1");
adp1.setXDpi(180.6f);
adp1.setYDpi(182.f);
mLayoutDevices.add(adp1);
// default config
FolderConfiguration defConfig = new FolderConfiguration();
@@ -700,6 +702,8 @@ public class Sdk implements IProjectListener {
adp1.addConfig("Landscape, opened", opened);
DeviceConfiguration ion = new DeviceConfiguration("Ion");
ion.setXDpi(180.6f);
ion.setYDpi(182.f);
mLayoutDevices.add(ion);
// default config
defConfig = new FolderConfiguration();