Merge change 20866 into donut

* changes:
  Make the res qualifiers aware of the project target to handle differnt behavior.
This commit is contained in:
Android (Google) Code Review
2009-08-11 18:44:08 -07:00
20 changed files with 757 additions and 640 deletions

View File

@@ -43,6 +43,7 @@ import com.android.ide.eclipse.adt.internal.resources.configurations.TextInputMe
import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier; import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.KeyboardStateQualifier.KeyboardState; import com.android.ide.eclipse.adt.internal.resources.configurations.KeyboardStateQualifier.KeyboardState;
import com.android.ide.eclipse.adt.internal.resources.configurations.NavigationMethodQualifier.NavigationMethod; import com.android.ide.eclipse.adt.internal.resources.configurations.NavigationMethodQualifier.NavigationMethod;
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.configurations.TextInputMethodQualifier.TextInputMethod; import com.android.ide.eclipse.adt.internal.resources.configurations.TextInputMethodQualifier.TextInputMethod;
import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier.TouchScreenType; import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier.TouchScreenType;
@@ -55,7 +56,6 @@ import com.android.ide.eclipse.adt.internal.sdk.LoadStatus;
import com.android.ide.eclipse.adt.internal.sdk.Sdk; import com.android.ide.eclipse.adt.internal.sdk.Sdk;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData.LayoutBridge; import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData.LayoutBridge;
import com.android.ide.eclipse.adt.internal.sdk.Sdk.ITargetChangeListener; import com.android.ide.eclipse.adt.internal.sdk.Sdk.ITargetChangeListener;
import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.DensityVerifier;
import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.DimensionVerifier; import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.DimensionVerifier;
import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.LanguageRegionVerifier; import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.LanguageRegionVerifier;
import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.MobileCodeVerifier; import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.MobileCodeVerifier;
@@ -161,7 +161,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
private Combo mLanguage; private Combo mLanguage;
private Combo mRegion; private Combo mRegion;
private Combo mOrientation; private Combo mOrientation;
private Text mDensity; private Combo mDensity;
private Combo mTouch; private Combo mTouch;
private Combo mKeyboard; private Combo mKeyboard;
private Combo mTextInput; private Combo mTextInput;
@@ -383,18 +383,18 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
new Label(topParent, SWT.NONE).setText("Density"); new Label(topParent, SWT.NONE).setText("Density");
mDensityIcon = createControlComposite(topParent, true /* grab_horizontal */); mDensityIcon = createControlComposite(topParent, true /* grab_horizontal */);
mDensity = new Text(mDensityIcon.getParent(), SWT.BORDER); mDensity = new Combo(mDensityIcon.getParent(), SWT.DROP_DOWN | SWT.READ_ONLY);
Density[] dValues = Density.values();
mDensity.add("(Default)");
for (Density value : dValues) {
mDensity.add(value.getDisplayValue());
}
mDensity.select(0);
mDensity.setLayoutData(new GridData( mDensity.setLayoutData(new GridData(
GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL)); GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
mDensity.addVerifyListener(new DensityVerifier());
mDensity.addSelectionListener(new SelectionAdapter() { mDensity.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetDefaultSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
onDensityChange();
}
});
mDensity.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
onDensityChange(); onDensityChange();
} }
}); });
@@ -551,7 +551,8 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
LayoutCreatorDialog dialog = new LayoutCreatorDialog(mCreateButton.getShell(), LayoutCreatorDialog dialog = new LayoutCreatorDialog(mCreateButton.getShell(),
mEditedFile.getName(), mCurrentConfig); mEditedFile.getName(),
Sdk.getCurrent().getTarget(mEditedFile.getProject()), mCurrentConfig);
if (dialog.open() == Dialog.OK) { if (dialog.open() == Dialog.OK) {
final FolderConfiguration config = new FolderConfiguration(); final FolderConfiguration config = new FolderConfiguration();
dialog.getConfiguration(config); dialog.getConfiguration(config);
@@ -1148,12 +1149,13 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
mDensityIcon.setImage(mMatchImage); mDensityIcon.setImage(mMatchImage);
PixelDensityQualifier densityQualifier = config.getPixelDensityQualifier(); PixelDensityQualifier densityQualifier = config.getPixelDensityQualifier();
if (densityQualifier != null) { if (densityQualifier != null) {
mDensity.setText(String.format("%1$d", densityQualifier.getValue())); mDensity.select(
Density.getIndex(densityQualifier.getValue()) + 1);
mCurrentConfig.setPixelDensityQualifier(densityQualifier); mCurrentConfig.setPixelDensityQualifier(densityQualifier);
} else if (force) { } else if (force) {
mDensity.setText(""); //$NON-NLS-1$ mOrientation.select(0);
mCurrentConfig.setPixelDensityQualifier(null); mCurrentConfig.setPixelDensityQualifier(null);
} else if (mDensity.getText().length() > 0) { } else if (mDensity.getSelectionIndex() != 0) {
mDensityIcon.setImage(mWarningImage); mDensityIcon.setImage(mWarningImage);
} }
@@ -1474,36 +1476,12 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
} }
private void onDensityChange() { private void onDensityChange() {
// because mDensity triggers onDensityChange at each modification, calling setText() int index = mDensity.getSelectionIndex();
// will trigger notifications, and we don't want that. if (index != 0) {
if (mDisableUpdates == true) { mCurrentConfig.setPixelDensityQualifier((new PixelDensityQualifier(
return; Density.getByIndex(index-1))));
} } else {
// update the current config
String value = mDensity.getText();
// empty string, means no qualifier.
if (value.length() == 0) {
mCurrentConfig.setPixelDensityQualifier(null); mCurrentConfig.setPixelDensityQualifier(null);
} else {
try {
PixelDensityQualifier qualifier = PixelDensityQualifier.getQualifier(
PixelDensityQualifier.getFolderSegment(Integer.parseInt(value)));
if (qualifier != null) {
mCurrentConfig.setPixelDensityQualifier(qualifier);
} else {
// Failure! Looks like the value is wrong (for instance a one letter string).
// We do nothing in this case.
return;
}
} catch (NumberFormatException e) {
// Looks like the code is not a number. This should not happen since the text
// field has a VerifyListener that prevents it.
// We do nothing in this case.
mDensityIcon.setImage(mErrorImage);
return;
}
} }
// look for a file to open/create // look for a file to open/create
@@ -1661,7 +1639,8 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
String message = String.format( String message = String.format(
"No resources match the configuration\n \n\t%1$s\n \nChange the configuration or create:\n \n\tres/%2$s/%3$s\n \nYou can also click the 'Create' button above.", "No resources match the configuration\n \n\t%1$s\n \nChange the configuration or create:\n \n\tres/%2$s/%3$s\n \nYou can also click the 'Create' button above.",
mCurrentConfig.toDisplayString(), mCurrentConfig.toDisplayString(),
mCurrentConfig.getFolderName(ResourceFolderType.LAYOUT), mCurrentConfig.getFolderName(ResourceFolderType.LAYOUT,
Sdk.getCurrent().getTarget(mEditedFile.getProject())),
mEditedFile.getName()); mEditedFile.getName());
showErrorInEditor(message); showErrorInEditor(message);
} }
@@ -1832,9 +1811,19 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
boolean isProjectTheme = themeIndex >= mPlatformThemeCount; boolean isProjectTheme = themeIndex >= mPlatformThemeCount;
// FIXME pass the density/dpi from somewhere (resource config or skin). // 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 = mCurrentConfig.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, 160, 160.f, 160.f, rect.width, rect.height, density, density, density,
theme, isProjectTheme, theme, isProjectTheme,
mConfiguredProjectRes, frameworkResources, mProjectCallback, mConfiguredProjectRes, frameworkResources, mProjectCallback,
mLogger); mLogger);
@@ -2256,7 +2245,8 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
@Override @Override
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
// get the folder name // get the folder name
String folderName = config.getFolderName(ResourceFolderType.LAYOUT); String folderName = config.getFolderName(ResourceFolderType.LAYOUT,
Sdk.getCurrent().getTarget(mEditedFile.getProject()));
try { try {
// look to see if it exists. // look to see if it exists.

View File

@@ -22,6 +22,7 @@ import com.android.ide.eclipse.adt.internal.resources.configurations.ResourceQua
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType; import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;
import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector; import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector;
import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.ConfigurationState; import com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.ConfigurationState;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TrayDialog; import org.eclipse.jface.dialogs.TrayDialog;
@@ -45,16 +46,20 @@ class LayoutCreatorDialog extends TrayDialog {
private final FolderConfiguration mConfig = new FolderConfiguration(); private final FolderConfiguration mConfig = new FolderConfiguration();
private final String mFileName; private final String mFileName;
private final IAndroidTarget mTarget;
/** /**
* Creates a dialog, and init the UI from a {@link FolderConfiguration}. * Creates a dialog, and init the UI from a {@link FolderConfiguration}.
* @param parentShell the parent {@link Shell}. * @param parentShell the parent {@link Shell}.
* @param config The starting configuration. * @param config The starting configuration.
*/ */
LayoutCreatorDialog(Shell parentShell, String fileName, FolderConfiguration config) { LayoutCreatorDialog(Shell parentShell, String fileName, IAndroidTarget target,
FolderConfiguration config) {
super(parentShell); super(parentShell);
mFileName = fileName; mFileName = fileName;
mTarget = target;
// FIXME: add some data to know what configurations already exist. // FIXME: add some data to know what configurations already exist.
mConfig.set(config); mConfig.set(config);
} }
@@ -135,6 +140,6 @@ class LayoutCreatorDialog extends TrayDialog {
*/ */
private void resetStatus() { private void resetStatus() {
mStatusLabel.setText(String.format("New File: res/%1$s/%2$s", mStatusLabel.setText(String.format("New File: res/%1$s/%2$s",
mConfig.getFolderName(ResourceFolderType.LAYOUT), mFileName)); mConfig.getFolderName(ResourceFolderType.LAYOUT, mTarget), mFileName));
} }
} }

View File

@@ -420,7 +420,7 @@ class ExtractStringInputPage extends UserInputWizardPage implements IWizardPage
// recreate the res path from the current configuration // recreate the res path from the current configuration
mConfigSelector.getConfiguration(mTempConfig); mConfigSelector.getConfiguration(mTempConfig);
StringBuffer sb = new StringBuffer(RES_FOLDER_ABS); StringBuffer sb = new StringBuffer(RES_FOLDER_ABS);
sb.append(mTempConfig.getFolderName(ResourceFolderType.VALUES)); sb.append(mTempConfig.getFolderName(ResourceFolderType.VALUES, mProject));
sb.append('/'); sb.append('/');
String newPath = sb.toString(); String newPath = sb.toString();

View File

@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -129,7 +130,7 @@ public final class CountryCodeQualifier extends ResourceQualifier {
* Returns the string used to represent this qualifier in the folder name. * Returns the string used to represent this qualifier in the folder name.
*/ */
@Override @Override
public String toString() { public String getFolderSegment(IAndroidTarget target) {
return getFolderSegment(mCode); return getFolderSegment(mCode);
} }

View File

@@ -17,6 +17,10 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType; import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.core.resources.IProject;
/** /**
@@ -272,13 +276,13 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
/** /**
* Returns the name of a folder with the configuration. * Returns the name of a folder with the configuration.
*/ */
public String getFolderName(ResourceFolderType folder) { public String getFolderName(ResourceFolderType folder, IAndroidTarget target) {
StringBuilder result = new StringBuilder(folder.getName()); StringBuilder result = new StringBuilder(folder.getName());
for (ResourceQualifier qualifier : mQualifiers) { for (ResourceQualifier qualifier : mQualifiers) {
if (qualifier != null) { if (qualifier != null) {
result.append(QUALIFIER_SEP); result.append(QUALIFIER_SEP);
result.append(qualifier.toString()); result.append(qualifier.getFolderSegment(target));
} }
} }
@@ -286,29 +290,26 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
} }
/** /**
* Returns a string valid for usage in a folder name, or <code>null</code> if the configuration * Returns the name of a folder with the configuration.
* is default. */
public String getFolderName(ResourceFolderType folder, IProject project) {
IAndroidTarget target = null;
if (project != null) {
Sdk currentSdk = Sdk.getCurrent();
if (currentSdk != null) {
target = currentSdk.getTarget(project);
}
}
return getFolderName(folder, target);
}
/**
* Returns {@link #toDisplayString()}.
*/ */
@Override @Override
public String toString() { public String toString() {
StringBuilder result = null; return toDisplayString();
for (ResourceQualifier irq : mQualifiers) {
if (irq != null) {
if (result == null) {
result = new StringBuilder();
} else {
result.append(QUALIFIER_SEP);
}
result.append(irq.toString());
}
}
if (result != null) {
return result.toString();
} else {
return null;
}
} }
/** /**

View File

@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -161,7 +162,7 @@ public final class KeyboardStateQualifier extends ResourceQualifier {
* Returns the string used to represent this qualifier in the folder name. * Returns the string used to represent this qualifier in the folder name.
*/ */
@Override @Override
public String toString() { public String getFolderSegment(IAndroidTarget target) {
if (mValue != null) { if (mValue != null) {
return mValue.getValue(); return mValue.getValue();
} }

View File

@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -126,7 +127,7 @@ public final class LanguageQualifier extends ResourceQualifier {
* Returns the string used to represent this qualifier in the folder name. * Returns the string used to represent this qualifier in the folder name.
*/ */
@Override @Override
public String toString() { public String getFolderSegment(IAndroidTarget target) {
if (mValue != null) { if (mValue != null) {
return getFolderSegment(mValue); return getFolderSegment(mValue);
} }

View File

@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -164,7 +165,7 @@ public final class NavigationMethodQualifier extends ResourceQualifier {
* Returns the string used to represent this qualifier in the folder name. * Returns the string used to represent this qualifier in the folder name.
*/ */
@Override @Override
public String toString() { public String getFolderSegment(IAndroidTarget target) {
if (mValue != null) { if (mValue != null) {
return mValue.getValue(); return mValue.getValue();
} }

View File

@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -141,7 +142,7 @@ public final class NetworkCodeQualifier extends ResourceQualifier {
* Returns the string used to represent this qualifier in the folder name. * Returns the string used to represent this qualifier in the folder name.
*/ */
@Override @Override
public String toString() { public String getFolderSegment(IAndroidTarget target) {
return getFolderSegment(mCode); return getFolderSegment(mCode);
} }

View File

@@ -17,6 +17,8 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.sdklib.AndroidVersion;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -27,56 +29,120 @@ import java.util.regex.Pattern;
* Resource Qualifier for Screen Pixel Density. * Resource Qualifier for Screen Pixel Density.
*/ */
public final class PixelDensityQualifier extends ResourceQualifier { public final class PixelDensityQualifier extends ResourceQualifier {
/** Default pixel density value. This means the property is not set. */ private final static Pattern sDensityLegacyPattern = Pattern.compile("^(\\d+)dpi$");//$NON-NLS-1$
private final static int DEFAULT_DENSITY = -1;
private final static Pattern sPixelDensityPattern = Pattern.compile("^(\\d+)dpi$");//$NON-NLS-1$
public static final String NAME = "Pixel Density"; public static final String NAME = "Pixel Density";
private int mValue = DEFAULT_DENSITY; private Density mValue = Density.MEDIUM;
/** /**
* Creates and returns a qualifier from the given folder segment. If the segment is incorrect, * Screen Orientation enum.
* <code>null</code> is returned.
* @param folderSegment the folder segment from which to create a qualifier.
* @return a new {@link CountryCodeQualifier} object or <code>null</code>
*/ */
public static PixelDensityQualifier getQualifier(String folderSegment) { public static enum Density {
Matcher m = sPixelDensityPattern.matcher(folderSegment); HIGH("hdpi", 240, "High Density"), //$NON-NLS-1$
MEDIUM("mdpi", 160, "Medium Density"), //$NON-NLS-1$
LOW("ldpi", 120, "Low Density"), //$NON-NLS-1$
NODPI("nodpi", -1, "No Density"); //$NON-NLS-1$
private final String mValue;
private final String mDisplayValue;
private final int mDpiValue;
private Density(String value, int dpiValue, String displayValue) {
mValue = value;
mDpiValue = dpiValue;
mDisplayValue = displayValue;
}
/**
* Returns the enum for matching the provided qualifier value.
* @param value The qualifier value.
* @return the enum for the qualifier value or null if no matching was found.
*/
static Density getEnum(String value) {
for (Density orient : values()) {
if (orient.mValue.equals(value)) {
return orient;
}
}
return null;
}
static Density getLegacyEnum(String value) {
Matcher m = sDensityLegacyPattern.matcher(value);
if (m.matches()) { if (m.matches()) {
String v = m.group(1); String v = m.group(1);
int density = -1;
try { try {
density = Integer.parseInt(v); int density = Integer.parseInt(v);
for (Density orient : values()) {
if (orient.mDpiValue == density) {
return orient;
}
}
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// looks like the string we extracted wasn't a valid number. // looks like the string we extracted wasn't a valid number
return null; // which really shouldn't happen since the regexp would have failed.
} }
PixelDensityQualifier qualifier = new PixelDensityQualifier();
qualifier.mValue = density;
return qualifier;
} }
return null; return null;
} }
/** public String getValue() {
* Returns the folder name segment for the given value. This is equivalent to calling return mValue;
* {@link #toString()} on a {@link NetworkCodeQualifier} object.
* @param value the value of the qualifier, as returned by {@link #getValue()}.
*/
public static String getFolderSegment(int value) {
if (value != DEFAULT_DENSITY) {
return String.format("%1$ddpi", value); //$NON-NLS-1$
} }
return ""; //$NON-NLS-1$ public int getDpiValue() {
return mDpiValue;
} }
public int getValue() { public String getLegacyValue() {
if (this != NODPI) {
return String.format("%1$ddpi", mDpiValue);
}
return "";
}
public String getDisplayValue() {
return mDisplayValue;
}
public static int getIndex(Density value) {
int i = 0;
for (Density input : values()) {
if (value == input) {
return i;
}
i++;
}
return -1;
}
public static Density getByIndex(int index) {
int i = 0;
for (Density value : values()) {
if (i == index) {
return value;
}
i++;
}
return null;
}
}
public PixelDensityQualifier() {
// pass
}
public PixelDensityQualifier(Density value) {
mValue = value;
}
public Density getValue() {
return mValue; return mValue;
} }
@@ -97,13 +163,19 @@ public final class PixelDensityQualifier extends ResourceQualifier {
@Override @Override
public boolean isValid() { public boolean isValid() {
return mValue != DEFAULT_DENSITY; return mValue != null;
} }
@Override @Override
public boolean checkAndSet(String value, FolderConfiguration config) { public boolean checkAndSet(String value, FolderConfiguration config) {
PixelDensityQualifier qualifier = getQualifier(value); Density density = Density.getEnum(value);
if (qualifier != null) { if (density == null) {
density = Density.getLegacyEnum(value);
}
if (density != null) {
PixelDensityQualifier qualifier = new PixelDensityQualifier();
qualifier.mValue = density;
config.setPixelDensityQualifier(qualifier); config.setPixelDensityQualifier(qualifier);
return true; return true;
} }
@@ -122,21 +194,35 @@ public final class PixelDensityQualifier extends ResourceQualifier {
@Override @Override
public int hashCode() { public int hashCode() {
return mValue; if (mValue != null) {
return mValue.hashCode();
}
return 0;
} }
/** /**
* Returns the string used to represent this qualifier in the folder name. * Returns the string used to represent this qualifier in the folder name.
*/ */
@Override @Override
public String toString() { public String getFolderSegment(IAndroidTarget target) {
return getFolderSegment(mValue); if (mValue != null) {
if (target != null) {
AndroidVersion version = target.getVersion();
if (version.getApiLevel() <= 3 && version.getCodename() == null) {
return mValue.getLegacyValue();
}
}
return mValue.getValue();
}
return ""; //$NON-NLS-1$
} }
@Override @Override
public String getStringValue() { public String getStringValue() {
if (mValue != DEFAULT_DENSITY) { if (mValue != null) {
return String.format("%1$d dpi", mValue); return mValue.getDisplayValue();
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$

View File

@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -130,7 +131,7 @@ public final class RegionQualifier extends ResourceQualifier {
* Returns the string used to represent this qualifier in the folder name. * Returns the string used to represent this qualifier in the folder name.
*/ */
@Override @Override
public String toString() { public String getFolderSegment(IAndroidTarget target) {
return getFolderSegment(mValue); return getFolderSegment(mValue);
} }

View File

@@ -16,6 +16,8 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
/** /**
@@ -58,8 +60,12 @@ public abstract class ResourceQualifier implements Comparable<ResourceQualifier>
* Returns a string formated to be used in a folder name. * Returns a string formated to be used in a folder name.
* <p/>This is declared as abstract to force children classes to implement it. * <p/>This is declared as abstract to force children classes to implement it.
*/ */
public abstract String getFolderSegment(IAndroidTarget target);
@Override @Override
public abstract String toString(); public String toString() {
return getFolderSegment(null);
}
/** /**
* Returns a string formatted for display purpose. * Returns a string formatted for display purpose.

View File

@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -133,7 +134,7 @@ public final class ScreenDimensionQualifier extends ResourceQualifier {
* Returns the string used to represent this qualifier in the folder name. * Returns the string used to represent this qualifier in the folder name.
*/ */
@Override @Override
public String toString() { public String getFolderSegment(IAndroidTarget target) {
return String.format("%1$dx%2$d", mValue1, mValue2); //$NON-NLS-1$ return String.format("%1$dx%2$d", mValue1, mValue2); //$NON-NLS-1$
} }

View File

@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -159,7 +160,7 @@ public final class ScreenOrientationQualifier extends ResourceQualifier {
* Returns the string used to represent this qualifier in the folder name. * Returns the string used to represent this qualifier in the folder name.
*/ */
@Override @Override
public String toString() { public String getFolderSegment(IAndroidTarget target) {
if (mValue != null) { if (mValue != null) {
return mValue.getValue(); return mValue.getValue();
} }

View File

@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -163,7 +164,7 @@ public final class TextInputMethodQualifier extends ResourceQualifier {
* Returns the string used to represent this qualifier in the folder name. * Returns the string used to represent this qualifier in the folder name.
*/ */
@Override @Override
public String toString() { public String getFolderSegment(IAndroidTarget target) {
if (mValue != null) { if (mValue != null) {
return mValue.getValue(); return mValue.getValue();
} }

View File

@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt.internal.resources.configurations; package com.android.ide.eclipse.adt.internal.resources.configurations;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -161,7 +162,7 @@ public final class TouchScreenQualifier extends ResourceQualifier {
* Returns the string used to represent this qualifier in the folder name. * Returns the string used to represent this qualifier in the folder name.
*/ */
@Override @Override
public String toString() { public String getFolderSegment(IAndroidTarget target) {
if (mValue != null) { if (mValue != null) {
return mValue.getValue(); return mValue.getValue();
} }

View File

@@ -377,6 +377,20 @@ public class Sdk implements IProjectListener {
} }
} }
/**
* Return the {@link AndroidTargetData} for a given {@link IProject}.
*/
public AndroidTargetData getTargetData(IProject project) {
synchronized (AdtPlugin.getDefault().getSdkLockObject()) {
IAndroidTarget target = getTarget(project);
if (target != null) {
return getTargetData(target);
}
}
return null;
}
/** /**
* Returns the configuration map for a given project. * Returns the configuration map for a given project.
* <p/>The Map key are name to be used in the apk filename, while the values are comma separated * <p/>The Map key are name to be used in the apk filename, while the values are comma separated

View File

@@ -31,6 +31,7 @@ import com.android.ide.eclipse.adt.internal.resources.configurations.TextInputMe
import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier; import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier;
import com.android.ide.eclipse.adt.internal.resources.configurations.KeyboardStateQualifier.KeyboardState; import com.android.ide.eclipse.adt.internal.resources.configurations.KeyboardStateQualifier.KeyboardState;
import com.android.ide.eclipse.adt.internal.resources.configurations.NavigationMethodQualifier.NavigationMethod; import com.android.ide.eclipse.adt.internal.resources.configurations.NavigationMethodQualifier.NavigationMethod;
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.configurations.TextInputMethodQualifier.TextInputMethod; import com.android.ide.eclipse.adt.internal.resources.configurations.TextInputMethodQualifier.TextInputMethod;
import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier.TouchScreenType; import com.android.ide.eclipse.adt.internal.resources.configurations.TouchScreenQualifier.TouchScreenType;
@@ -908,52 +909,42 @@ public class ConfigurationSelector extends Composite {
* Edit widget for {@link PixelDensityQualifier}. * Edit widget for {@link PixelDensityQualifier}.
*/ */
private class PixelDensityEdit extends QualifierEditBase { private class PixelDensityEdit extends QualifierEditBase {
private Text mText; private Combo mDensity;
public PixelDensityEdit(Composite parent) { public PixelDensityEdit(Composite parent) {
super(parent, PixelDensityQualifier.NAME); super(parent, PixelDensityQualifier.NAME);
mText = new Text(this, SWT.BORDER); mDensity = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
mText.addVerifyListener(new DensityVerifier()); Density[] soValues = Density.values();
mText.addModifyListener(new ModifyListener() { for (Density value : soValues) {
public void modifyText(ModifyEvent e) { mDensity.add(value.getDisplayValue());
onTextChange();
}
});
mText.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
onTextChange();
}
});
} }
private void onTextChange() { mDensity.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
String value = mText.getText(); mDensity.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
onDensityChange();
}
public void widgetSelected(SelectionEvent e) {
onDensityChange();
}
});
if (value.length() == 0) { }
// empty string, means a qualifier with no value.
private void onDensityChange() {
// update the current config
int index = mDensity.getSelectionIndex();
if (index != -1) {
mSelectedConfiguration.setPixelDensityQualifier(new PixelDensityQualifier(
Density.getByIndex(index)));
} else {
// empty selection, means no qualifier.
// Since the qualifier classes are immutable, and we don't want to // Since the qualifier classes are immutable, and we don't want to
// remove the qualifier from the configuration, we create a new default one. // remove the qualifier from the configuration, we create a new default one.
mSelectedConfiguration.setPixelDensityQualifier(new PixelDensityQualifier()); mSelectedConfiguration.setPixelDensityQualifier(
} else { new PixelDensityQualifier());
try {
PixelDensityQualifier qualifier = PixelDensityQualifier.getQualifier(
PixelDensityQualifier.getFolderSegment(Integer.parseInt(value)));
if (qualifier != null) {
mSelectedConfiguration.setPixelDensityQualifier(qualifier);
} else {
// Failure! Looks like the value is wrong
// (for instance a one letter string).
// We do nothing in this case.
return;
}
} catch (NumberFormatException nfe) {
// Looks like the code is not a number. This should not happen since the text
// field has a VerifyListener that prevents it.
// We do nothing in this case.
return;
}
} }
// notify of change // notify of change
@@ -964,7 +955,12 @@ public class ConfigurationSelector extends Composite {
public void setQualifier(ResourceQualifier qualifier) { public void setQualifier(ResourceQualifier qualifier) {
PixelDensityQualifier q = (PixelDensityQualifier)qualifier; PixelDensityQualifier q = (PixelDensityQualifier)qualifier;
mText.setText(Integer.toString(q.getValue())); Density value = q.getValue();
if (value == null) {
mDensity.clearSelection();
} else {
mDensity.select(Density.getIndex(value));
}
} }
} }

View File

@@ -897,6 +897,9 @@ class NewXmlFileCreationPage extends WizardPage {
// enable types based on new API level // enable types based on new API level
enableTypesBasedOnApi(); enableTypesBasedOnApi();
// update the folder name based on API level
resetFolderPath(false /*validate*/);
// update the Type with the new descriptors. // update the Type with the new descriptors.
initializeRootValues(); initializeRootValues();
@@ -1023,7 +1026,7 @@ class NewXmlFileCreationPage extends WizardPage {
// The configuration is valid. Reformat the folder path using the canonical // The configuration is valid. Reformat the folder path using the canonical
// value from the configuration. // value from the configuration.
newPath = RES_FOLDER_ABS + mTempConfig.getFolderName(type.getResFolderType()); newPath = RES_FOLDER_ABS + mTempConfig.getFolderName(type.getResFolderType(), mProject);
} else { } else {
// The configuration is invalid. We still update the path but this time // The configuration is invalid. We still update the path but this time
// do it manually on the string. // do it manually on the string.
@@ -1032,7 +1035,8 @@ class NewXmlFileCreationPage extends WizardPage {
"^(" + RES_FOLDER_ABS +")[^-]*(.*)", //$NON-NLS-1$ //$NON-NLS-2$ "^(" + RES_FOLDER_ABS +")[^-]*(.*)", //$NON-NLS-1$ //$NON-NLS-2$
"\\1" + type.getResFolderName() + "\\2"); //$NON-NLS-1$ //$NON-NLS-2$ "\\1" + type.getResFolderName() + "\\2"); //$NON-NLS-1$ //$NON-NLS-2$
} else { } else {
newPath = RES_FOLDER_ABS + mTempConfig.getFolderName(type.getResFolderType()); newPath = RES_FOLDER_ABS + mTempConfig.getFolderName(type.getResFolderType(),
mProject);
} }
} }
@@ -1085,19 +1089,7 @@ class NewXmlFileCreationPage extends WizardPage {
return; return;
} }
TypeInfo type = getSelectedType(); resetFolderPath(true /*validate*/);
if (type != null) {
mConfigSelector.getConfiguration(mTempConfig);
StringBuffer sb = new StringBuffer(RES_FOLDER_ABS);
sb.append(mTempConfig.getFolderName(type.getResFolderType()));
mInternalWsFolderPathUpdate = true;
mWsFolderPathTextField.setText(sb.toString());
mInternalWsFolderPathUpdate = false;
validatePage();
}
} }
} }
@@ -1138,6 +1130,28 @@ class NewXmlFileCreationPage extends WizardPage {
} }
} }
/**
* Reset the current Folder path based on the UI selection
* @param validate if true, force a call to {@link #validatePage()}.
*/
private void resetFolderPath(boolean validate) {
TypeInfo type = getSelectedType();
if (type != null) {
mConfigSelector.getConfiguration(mTempConfig);
StringBuffer sb = new StringBuffer(RES_FOLDER_ABS);
sb.append(mTempConfig.getFolderName(type.getResFolderType(), mProject));
mInternalWsFolderPathUpdate = true;
mWsFolderPathTextField.setText(sb.toString());
mInternalWsFolderPathUpdate = false;
if (validate) {
validatePage();
}
}
}
/** /**
* Validates the fields, displays errors and warnings. * Validates the fields, displays errors and warnings.
* Enables the finish button if there are no errors. * Enables the finish button if there are no errors.

View File

@@ -34,6 +34,7 @@ import com.android.ide.eclipse.adt.internal.resources.manager.files.IFileWrapper
import com.android.ide.eclipse.adt.internal.resources.manager.files.IFolderWrapper; import com.android.ide.eclipse.adt.internal.resources.manager.files.IFolderWrapper;
import com.android.ide.eclipse.mock.FileMock; import com.android.ide.eclipse.mock.FileMock;
import com.android.ide.eclipse.mock.FolderMock; import com.android.ide.eclipse.mock.FolderMock;
import com.android.sdklib.SdkConstants;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@@ -220,10 +221,7 @@ public class ConfigMatchTest extends TestCase {
FileMock[] memberList) throws Exception { FileMock[] memberList) throws Exception {
// figure out the folder name based on the configuration // figure out the folder name based on the configuration
String folderName = "layout"; String folderName = config.getFolderName(ResourceFolderType.LAYOUT);
if (config.isDefault() == false) {
folderName += "-" + config.toString();
}
// create the folder mock // create the folder mock
FolderMock folder = new FolderMock(folderName, memberList); FolderMock folder = new FolderMock(folderName, memberList);
@@ -253,7 +251,4 @@ public class ConfigMatchTest extends TestCase {
ResourceFolderType.LAYOUT, config, new IFolderWrapper(folder)); ResourceFolderType.LAYOUT, config, new IFolderWrapper(folder));
return resFolder; return resFolder;
} }
} }