Merge change Ie905f9b5 into eclair
* changes: Add support for xdpi and ydpi in the device config for the GLE.
This commit is contained in:
@@ -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.UiDocumentNode;
|
||||||
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
|
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.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.ProjectResources;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFile;
|
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFile;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;
|
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;
|
||||||
@@ -849,22 +847,14 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
|
|||||||
Rectangle rect = getBounds();
|
Rectangle rect = getBounds();
|
||||||
boolean isProjectTheme = mConfigComposite.isProjectTheme();
|
boolean isProjectTheme = mConfigComposite.isProjectTheme();
|
||||||
|
|
||||||
// FIXME pass the density/dpi from somewhere (resource config or skin).
|
int density = mConfigComposite.getDensity().getDpiValue();
|
||||||
// For now, get it from the config
|
float xdpi = mConfigComposite.getXDpi();
|
||||||
int density = Density.MEDIUM.getDpiValue();
|
float ydpi = mConfigComposite.getYDpi();
|
||||||
PixelDensityQualifier qual =
|
|
||||||
mConfigComposite.getCurrentConfig().getPixelDensityQualifier();
|
|
||||||
if (qual != null) {
|
|
||||||
int d = qual.getValue().getDpiValue();
|
|
||||||
if (d > 0) {
|
|
||||||
density = d;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ILayoutResult result = computeLayout(bridge, parser,
|
ILayoutResult result = computeLayout(bridge, parser,
|
||||||
iProject /* projectKey */,
|
iProject /* projectKey */,
|
||||||
rect.width, rect.height, !mConfigComposite.getClipping(),
|
rect.width, rect.height, !mConfigComposite.getClipping(),
|
||||||
density, density, density,
|
density, xdpi, ydpi,
|
||||||
theme, isProjectTheme,
|
theme, isProjectTheme,
|
||||||
configuredProjectRes, frameworkResources, mProjectCallback,
|
configuredProjectRes, frameworkResources, mProjectCallback,
|
||||||
mLogger);
|
mLogger);
|
||||||
|
|||||||
@@ -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.UiDocumentNode;
|
||||||
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
|
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.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.ProjectResources;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFile;
|
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFile;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;
|
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;
|
||||||
@@ -949,22 +947,14 @@ public class GraphicalLayoutEditor extends GraphicalEditorWithPalette
|
|||||||
Rectangle rect = getBounds();
|
Rectangle rect = getBounds();
|
||||||
boolean isProjectTheme = mConfigComposite.isProjectTheme();
|
boolean isProjectTheme = mConfigComposite.isProjectTheme();
|
||||||
|
|
||||||
// FIXME pass the density/dpi from somewhere (resource config or skin).
|
int density = mConfigComposite.getDensity().getDpiValue();
|
||||||
// For now, get it from the config
|
float xdpi = mConfigComposite.getXDpi();
|
||||||
int density = Density.MEDIUM.getDpiValue();
|
float ydpi = mConfigComposite.getYDpi();
|
||||||
PixelDensityQualifier qual =
|
|
||||||
mConfigComposite.getCurrentConfig().getPixelDensityQualifier();
|
|
||||||
if (qual != null) {
|
|
||||||
int d = qual.getValue().getDpiValue();
|
|
||||||
if (d > 0) {
|
|
||||||
density = d;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ILayoutResult result = computeLayout(bridge, parser,
|
ILayoutResult result = computeLayout(bridge, parser,
|
||||||
iProject /* projectKey */,
|
iProject /* projectKey */,
|
||||||
rect.width, rect.height, !mConfigComposite.getClipping(),
|
rect.width, rect.height, !mConfigComposite.getClipping(),
|
||||||
density, density, density,
|
density, xdpi, ydpi,
|
||||||
theme, isProjectTheme,
|
theme, isProjectTheme,
|
||||||
configuredProjectRes, frameworkResources, mProjectCallback,
|
configuredProjectRes, frameworkResources, mProjectCallback,
|
||||||
mLogger);
|
mLogger);
|
||||||
|
|||||||
@@ -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.ResourceType;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;
|
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.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.RegionQualifier;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.configurations.ResourceQualifier;
|
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.ScreenDimensionQualifier;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.configurations.ScreenOrientationQualifier;
|
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.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.configurations.ScreenOrientationQualifier.ScreenOrientation;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources;
|
import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources;
|
||||||
import com.android.ide.eclipse.adt.internal.sdk.DeviceConfiguration;
|
import com.android.ide.eclipse.adt.internal.sdk.DeviceConfiguration;
|
||||||
@@ -84,6 +86,8 @@ public class ConfigurationComposite extends Composite {
|
|||||||
|
|
||||||
private boolean mClipping = true;
|
private boolean mClipping = true;
|
||||||
|
|
||||||
|
private DeviceConfiguration mCurrentDevice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface implemented by the part which owns a {@link ConfigurationComposite}.
|
* Interface implemented by the part which owns a {@link ConfigurationComposite}.
|
||||||
* This notifies the owners when the configuration change.
|
* This notifies the owners when the configuration change.
|
||||||
@@ -227,15 +231,73 @@ public class ConfigurationComposite extends Composite {
|
|||||||
config.set(mCurrentConfig);
|
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() {
|
public Rectangle getScreenBounds() {
|
||||||
// get the orientation from the current device config
|
// get the orientation from the current device config
|
||||||
ScreenOrientationQualifier qual = mCurrentConfig.getScreenOrientationQualifier();
|
ScreenOrientationQualifier qual = mCurrentConfig.getScreenOrientationQualifier();
|
||||||
ScreenOrientation orientation = qual.getValue();
|
ScreenOrientation orientation = ScreenOrientation.PORTRAIT;
|
||||||
|
if (qual != null) {
|
||||||
|
orientation = qual.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
// get the device screen dimension
|
// get the device screen dimension
|
||||||
ScreenDimensionQualifier qual2 = mCurrentConfig.getScreenDimensionQualifier();
|
ScreenDimensionQualifier qual2 = mCurrentConfig.getScreenDimensionQualifier();
|
||||||
int s1 = qual2.getValue1();
|
int s1, s2;
|
||||||
int s2 = qual2.getValue2();
|
if (qual2 != null) {
|
||||||
|
s1 = qual2.getValue1();
|
||||||
|
s2 = qual2.getValue2();
|
||||||
|
} else {
|
||||||
|
s1 = 480;
|
||||||
|
s2 = 320;
|
||||||
|
}
|
||||||
|
|
||||||
switch (orientation) {
|
switch (orientation) {
|
||||||
default:
|
default:
|
||||||
@@ -512,11 +574,16 @@ public class ConfigurationComposite extends Composite {
|
|||||||
private void onDeviceChange(boolean recomputeLayout) {
|
private void onDeviceChange(boolean recomputeLayout) {
|
||||||
|
|
||||||
int deviceIndex = mDeviceList.getSelectionIndex();
|
int deviceIndex = mDeviceList.getSelectionIndex();
|
||||||
DeviceConfiguration device = mDevices.get(deviceIndex);
|
if (deviceIndex != -1) {
|
||||||
|
mCurrentDevice = mDevices.get(deviceIndex);
|
||||||
|
} else {
|
||||||
|
mCurrentDevice = null;
|
||||||
|
}
|
||||||
|
|
||||||
mDeviceConfigs.removeAll();
|
mDeviceConfigs.removeAll();
|
||||||
|
|
||||||
Set<String> configNames = device.getConfigs().keySet();
|
if (mCurrentDevice != null) {
|
||||||
|
Set<String> configNames = mCurrentDevice.getConfigs().keySet();
|
||||||
for (String name : configNames) {
|
for (String name : configNames) {
|
||||||
mDeviceConfigs.add(name);
|
mDeviceConfigs.add(name);
|
||||||
}
|
}
|
||||||
@@ -526,19 +593,17 @@ public class ConfigurationComposite extends Composite {
|
|||||||
mDeviceConfigs.setEnabled(false);
|
mDeviceConfigs.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
if (recomputeLayout) {
|
if (recomputeLayout) {
|
||||||
onDeviceConfigChange();
|
onDeviceConfigChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onDeviceConfigChange() {
|
private void onDeviceConfigChange() {
|
||||||
if (mDevices != null) {
|
if (mCurrentDevice != null) {
|
||||||
int deviceIndex = mDeviceList.getSelectionIndex();
|
|
||||||
DeviceConfiguration device = mDevices.get(deviceIndex);
|
|
||||||
|
|
||||||
int configIndex = mDeviceConfigs.getSelectionIndex();
|
int configIndex = mDeviceConfigs.getSelectionIndex();
|
||||||
String name = mDeviceConfigs.getItem(configIndex);
|
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
|
// get the current qualifiers from the current config
|
||||||
LanguageQualifier lang = mCurrentConfig.getLanguageQualifier();
|
LanguageQualifier lang = mCurrentConfig.getLanguageQualifier();
|
||||||
|
|||||||
@@ -25,8 +25,11 @@ import java.util.Map;
|
|||||||
public class DeviceConfiguration {
|
public class DeviceConfiguration {
|
||||||
|
|
||||||
private final String mName;
|
private final String mName;
|
||||||
|
|
||||||
private Map<String, FolderConfiguration> mMap =
|
private Map<String, FolderConfiguration> mMap =
|
||||||
new HashMap<String, FolderConfiguration>();
|
new HashMap<String, FolderConfiguration>();
|
||||||
|
private float mXDpi = Float.NaN;
|
||||||
|
private float mYDpi = Float.NaN;
|
||||||
|
|
||||||
DeviceConfiguration(String name) {
|
DeviceConfiguration(String name) {
|
||||||
mName = name;
|
mName = name;
|
||||||
@@ -40,6 +43,14 @@ public class DeviceConfiguration {
|
|||||||
mMap = Collections.unmodifiableMap(mMap);
|
mMap = Collections.unmodifiableMap(mMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setXDpi(float xdpi) {
|
||||||
|
mXDpi = xdpi;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setYDpi(float ydpi) {
|
||||||
|
mYDpi = ydpi;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return mName;
|
return mName;
|
||||||
}
|
}
|
||||||
@@ -47,4 +58,20 @@ public class DeviceConfiguration {
|
|||||||
public Map<String, FolderConfiguration> getConfigs() {
|
public Map<String, FolderConfiguration> getConfigs() {
|
||||||
return mMap;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -670,6 +670,8 @@ public class Sdk implements IProjectListener {
|
|||||||
*/
|
*/
|
||||||
private void createDefaultLayoutDevices() {
|
private void createDefaultLayoutDevices() {
|
||||||
DeviceConfiguration adp1 = new DeviceConfiguration("ADP1");
|
DeviceConfiguration adp1 = new DeviceConfiguration("ADP1");
|
||||||
|
adp1.setXDpi(180.6f);
|
||||||
|
adp1.setYDpi(182.f);
|
||||||
mLayoutDevices.add(adp1);
|
mLayoutDevices.add(adp1);
|
||||||
// default config
|
// default config
|
||||||
FolderConfiguration defConfig = new FolderConfiguration();
|
FolderConfiguration defConfig = new FolderConfiguration();
|
||||||
@@ -700,6 +702,8 @@ public class Sdk implements IProjectListener {
|
|||||||
adp1.addConfig("Landscape, opened", opened);
|
adp1.addConfig("Landscape, opened", opened);
|
||||||
|
|
||||||
DeviceConfiguration ion = new DeviceConfiguration("Ion");
|
DeviceConfiguration ion = new DeviceConfiguration("Ion");
|
||||||
|
ion.setXDpi(180.6f);
|
||||||
|
ion.setYDpi(182.f);
|
||||||
mLayoutDevices.add(ion);
|
mLayoutDevices.add(ion);
|
||||||
// default config
|
// default config
|
||||||
defConfig = new FolderConfiguration();
|
defConfig = new FolderConfiguration();
|
||||||
|
|||||||
Reference in New Issue
Block a user