import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode;\r
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;\r
import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;\r
-import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier;\r
-import com.android.ide.eclipse.adt.internal.resources.configurations.PixelDensityQualifier.Density;\r
import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources;\r
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFile;\r
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;\r
Rectangle rect = getBounds();\r
boolean isProjectTheme = mConfigComposite.isProjectTheme();\r
\r
- // FIXME pass the density/dpi from somewhere (resource config or skin).\r
- // For now, get it from the config\r
- int density = Density.MEDIUM.getDpiValue();\r
- PixelDensityQualifier qual =\r
- mConfigComposite.getCurrentConfig().getPixelDensityQualifier();\r
- if (qual != null) {\r
- int d = qual.getValue().getDpiValue();\r
- if (d > 0) {\r
- density = d;\r
- }\r
- }\r
+ int density = mConfigComposite.getDensity().getDpiValue();\r
+ float xdpi = mConfigComposite.getXDpi();\r
+ float ydpi = mConfigComposite.getYDpi();\r
\r
ILayoutResult result = computeLayout(bridge, parser,\r
iProject /* projectKey */,\r
rect.width, rect.height, !mConfigComposite.getClipping(),\r
- density, density, density,\r
+ density, xdpi, ydpi,\r
theme, isProjectTheme,\r
configuredProjectRes, frameworkResources, mProjectCallback,\r
mLogger);\r
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;
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);
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;
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.
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:
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();
- for (String name : configNames) {
- mDeviceConfigs.add(name);
- }
+ if (mCurrentDevice != null) {
+ Set<String> configNames = mCurrentDevice.getConfigs().keySet();
+ for (String name : configNames) {
+ mDeviceConfigs.add(name);
+ }
- mDeviceConfigs.select(0);
- if (configNames.size() == 1) {
- mDeviceConfigs.setEnabled(false);
- }
+ mDeviceConfigs.select(0);
+ if (configNames.size() == 1) {
+ 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();
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;
mMap = Collections.unmodifiableMap(mMap);
}
+ void setXDpi(float xdpi) {
+ mXDpi = xdpi;
+ }
+
+ void setYDpi(float ydpi) {
+ mYDpi = ydpi;
+ }
+
public String getName() {
return mName;
}
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;
+ }
}