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