Fix device dpi handling in the Layout device parsing/UI.
Change-Id: I74fdf8c62a7b005e40e1817d9f39c59d8f99c070
This commit is contained in:
@@ -50,8 +50,8 @@ public class ConfigEditDialog extends GridDialog {
|
||||
|
||||
private String mDeviceName;
|
||||
private String mConfigName;
|
||||
private float mXDpi = 0f;
|
||||
private float mYDpi = 0f;
|
||||
private float mXDpi = Float.NaN;
|
||||
private float mYDpi = Float.NaN;
|
||||
|
||||
|
||||
public ConfigEditDialog(Shell parentShell, FolderConfiguration config) {
|
||||
@@ -140,13 +140,18 @@ public class ConfigEditDialog extends GridDialog {
|
||||
|
||||
final Text deviceXDpiText = new Text(deviceGroup, SWT.BORDER);
|
||||
deviceXDpiText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
if (mXDpi != 0f) {
|
||||
if (Float.isNaN(mXDpi) == false) {
|
||||
deviceXDpiText.setText(String.format("%.1f", mXDpi)); //$NON-NLS-1$
|
||||
}
|
||||
deviceXDpiText.addVerifyListener(floatVerifier);
|
||||
deviceXDpiText.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
mXDpi = Float.parseFloat(deviceXDpiText.getText());
|
||||
String value = deviceXDpiText.getText();
|
||||
if (value.length() == 0) {
|
||||
mXDpi = Float.NaN;
|
||||
} else {
|
||||
mXDpi = Float.parseFloat(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -155,13 +160,18 @@ public class ConfigEditDialog extends GridDialog {
|
||||
|
||||
final Text deviceYDpiText = new Text(deviceGroup, SWT.BORDER);
|
||||
deviceYDpiText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
if (mYDpi != 0f) {
|
||||
if (Float.isNaN(mYDpi) == false) {
|
||||
deviceYDpiText.setText(String.format("%.1f", mYDpi)); //$NON-NLS-1$
|
||||
}
|
||||
deviceYDpiText.addVerifyListener(floatVerifier);
|
||||
deviceYDpiText.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
mYDpi = Float.parseFloat(deviceYDpiText.getText());
|
||||
String value = deviceYDpiText.getText();
|
||||
if (value.length() == 0) {
|
||||
mYDpi = Float.NaN;
|
||||
} else {
|
||||
mYDpi = Float.parseFloat(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -185,11 +195,10 @@ public class ConfigEditDialog extends GridDialog {
|
||||
}
|
||||
});
|
||||
|
||||
mConfigSelector = new ConfigurationSelector(configGroup);
|
||||
mConfigSelector = new ConfigurationSelector(configGroup, true /*deviceMode*/);
|
||||
// configure the selector to be in "device mode" and not accept language/region/version
|
||||
// since those are selected from a different combo
|
||||
// FIXME: add version combo.
|
||||
mConfigSelector.setDeviceMode(true);
|
||||
mConfigSelector.setQualifierFilter(new IQualifierFilter() {
|
||||
public boolean accept(ResourceQualifier qualifier) {
|
||||
if (qualifier instanceof LanguageQualifier ||
|
||||
|
||||
@@ -335,6 +335,8 @@ public class ConfigManagerDialog extends GridDialog {
|
||||
DeviceSelection selection = getSelection();
|
||||
ConfigEditDialog dlg = new ConfigEditDialog(parent.getShell(), null);
|
||||
dlg.setDeviceName(selection.device.getName());
|
||||
dlg.setXDpi(selection.device.getXDpi());
|
||||
dlg.setYDpi(selection.device.getYDpi());
|
||||
dlg.setConfigName(selection.entry.getKey());
|
||||
dlg.setConfig(selection.entry.getValue());
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public final class LayoutCreatorDialog extends GridDialog {
|
||||
new Label(parent, SWT.NONE).setText(
|
||||
String.format("Configuration for the alternate version of %1$s", mFileName));
|
||||
|
||||
mSelector = new ConfigurationSelector(parent);
|
||||
mSelector = new ConfigurationSelector(parent, false /*deviceMode*/);
|
||||
mSelector.setConfiguration(mConfig);
|
||||
|
||||
// parent's layout is a GridLayout as specified in the javadoc.
|
||||
|
||||
@@ -208,7 +208,7 @@ class ExtractStringInputPage extends UserInputWizardPage implements IWizardPage
|
||||
label = new Label(group, SWT.NONE);
|
||||
label.setText("&Configuration:");
|
||||
|
||||
mConfigSelector = new ConfigurationSelector(group);
|
||||
mConfigSelector = new ConfigurationSelector(group, false /*deviceMode*/);
|
||||
GridData gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
|
||||
gd.horizontalSpan = 2;
|
||||
gd.widthHint = ConfigurationSelector.WIDTH_HINT;
|
||||
|
||||
@@ -97,7 +97,7 @@ public class LayoutConfigsXsd {
|
||||
/** The screen-dimension element has 2 size element children. */
|
||||
public static final String NODE_SIZE = "size"; //$NON-NLS-1$
|
||||
|
||||
public static final String NODE_XPDI = "xdpi"; //$NON-NLS-1$
|
||||
public static final String NODE_XDPI = "xdpi"; //$NON-NLS-1$
|
||||
|
||||
public static final String NODE_YDPI = "ydpi"; //$NON-NLS-1$
|
||||
|
||||
|
||||
@@ -154,6 +154,10 @@ class LayoutDeviceHandler extends DefaultHandler {
|
||||
if (qual != null) {
|
||||
mCurrentConfig.setScreenDimensionQualifier(qual);
|
||||
}
|
||||
} else if (LayoutConfigsXsd.NODE_XDPI.equals(localName)) {
|
||||
mCurrentDevice.setXDpi(Float.parseFloat(mStringAccumulator.toString()));
|
||||
} else if (LayoutConfigsXsd.NODE_YDPI.equals(localName)) {
|
||||
mCurrentDevice.setYDpi(Float.parseFloat(mStringAccumulator.toString()));
|
||||
} else if (LayoutConfigsXsd.NODE_SIZE.equals(localName)) {
|
||||
if (mSize1 == null) {
|
||||
mSize1 = mStringAccumulator.toString();
|
||||
|
||||
@@ -109,8 +109,8 @@ public class ConfigurationSelector extends Composite {
|
||||
|
||||
private final HashMap<Class<? extends ResourceQualifier>, QualifierEditBase> mUiMap =
|
||||
new HashMap<Class<? extends ResourceQualifier>, QualifierEditBase>();
|
||||
private final boolean mDeviceMode;
|
||||
private Composite mQualifierEditParent;
|
||||
private boolean mDeviceMode = false;
|
||||
private IQualifierFilter mQualifierFilter;
|
||||
|
||||
/**
|
||||
@@ -198,8 +198,20 @@ public class ConfigurationSelector extends Composite {
|
||||
boolean accept(ResourceQualifier qualifier);
|
||||
}
|
||||
|
||||
public ConfigurationSelector(Composite parent) {
|
||||
/**
|
||||
* Creates the selector.
|
||||
*
|
||||
* If the device mode is <code>true</code> then the configuration selector only
|
||||
* allows to create configuration that are valid on a device (as opposed to resource
|
||||
* configuration).
|
||||
* For instance {@link Density#NODPI} is a valid qualifier for a resource configuration but
|
||||
* this is not valid on a device.
|
||||
* @param parent the composite parent.
|
||||
* @param deviceMode the device mode.
|
||||
*/
|
||||
public ConfigurationSelector(Composite parent, boolean deviceMode) {
|
||||
super(parent, SWT.NONE);
|
||||
mDeviceMode = deviceMode;
|
||||
|
||||
mBaseConfiguration.createDefault();
|
||||
|
||||
@@ -388,19 +400,6 @@ public class ConfigurationSelector extends Composite {
|
||||
mUiMap.put(VersionQualifier.class, new VersionEdit(mQualifierEditParent));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the device mode. If <code>true</code> then the configuration selector only
|
||||
* allows to create configuration that are valid on a device (as opposed to resource
|
||||
* configuration).
|
||||
* For instance {@link Density#NODPI} is a valid qualifier for a resource configuration but
|
||||
* this is not valid on a device.
|
||||
* Default is false.
|
||||
* @param deviceMode the device mode.
|
||||
*/
|
||||
public void setDeviceMode(boolean deviceMode) {
|
||||
mDeviceMode = deviceMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link IQualifierFilter}. If non null, this will restrict the qualifiers that
|
||||
* can be chosen.
|
||||
|
||||
@@ -620,7 +620,7 @@ class NewXmlFileCreationPage extends WizardPage {
|
||||
|
||||
// configuration selector
|
||||
emptyCell(parent);
|
||||
mConfigSelector = new ConfigurationSelector(parent);
|
||||
mConfigSelector = new ConfigurationSelector(parent, false /* deviceMode*/);
|
||||
GridData gd = newGridData(2, GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
|
||||
gd.widthHint = ConfigurationSelector.WIDTH_HINT;
|
||||
gd.heightHint = ConfigurationSelector.HEIGHT_HINT;
|
||||
|
||||
Reference in New Issue
Block a user