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

@@ -4,7 +4,7 @@
* Licensed under the Eclipse Public License, Version 1.0 (the "License"); * Licensed under the Eclipse Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.eclipse.org/org/documents/epl-v10.php * http://www.eclipse.org/org/documents/epl-v10.php
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
@@ -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;
@@ -143,7 +143,7 @@ import java.util.Set;
*/ */
public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
implements ILayoutReloadListener { implements ILayoutReloadListener {
private final static String THEME_SEPARATOR = "----------"; //$NON-NLS-1$ private final static String THEME_SEPARATOR = "----------"; //$NON-NLS-1$
/** Reference to the layout editor */ /** Reference to the layout editor */
@@ -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;
@@ -216,7 +216,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
public void onTargetsLoaded() { public void onTargetsLoaded() {
// because the SDK changed we must reset the configured framework resource. // because the SDK changed we must reset the configured framework resource.
mConfiguredFrameworkRes = null; mConfiguredFrameworkRes = null;
updateUIFromResources(); updateUIFromResources();
mThemeCombo.getParent().layout(); mThemeCombo.getParent().layout();
@@ -383,19 +383,19 @@ 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(); onDensityChange();
}
});
mDensity.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
onDensityChange();
} }
}); });
@@ -468,7 +468,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
onNavigationChange(); onNavigationChange();
} }
}); });
Composite labelParent = new Composite(topParent, SWT.NONE); Composite labelParent = new Composite(topParent, SWT.NONE);
@@ -512,7 +512,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
mSize1.addSelectionListener(sl); mSize1.addSelectionListener(sl);
mSize2.addSelectionListener(sl); mSize2.addSelectionListener(sl);
ModifyListener sizeModifyListener = new ModifyListener() { ModifyListener sizeModifyListener = new ModifyListener() {
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
onSizeChange(); onSizeChange();
@@ -551,11 +551,12 @@ 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);
createAlternateLayout(config); createAlternateLayout(config);
} }
} }
@@ -591,7 +592,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
@Override @Override
protected PaletteRoot getPaletteRoot() { protected PaletteRoot getPaletteRoot() {
mPaletteRoot = PaletteFactory.createPaletteRoot(mPaletteRoot, mPaletteRoot = PaletteFactory.createPaletteRoot(mPaletteRoot,
mLayoutEditor.getTargetData()); mLayoutEditor.getTargetData());
return mPaletteRoot; return mPaletteRoot;
} }
@@ -618,7 +619,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
getCommandStack().markSaveLocation(); getCommandStack().markSaveLocation();
firePropertyChange(PROP_DIRTY); firePropertyChange(PROP_DIRTY);
} }
@Override @Override
protected void configurePaletteViewer() { protected void configurePaletteViewer() {
super.configurePaletteViewer(); super.configurePaletteViewer();
@@ -628,7 +629,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// the PaletteTemplateEntry held in the PaletteRoot. // the PaletteTemplateEntry held in the PaletteRoot.
TemplateTransferDragSourceListener dragSource = TemplateTransferDragSourceListener dragSource =
new TemplateTransferDragSourceListener(getPaletteViewer()); new TemplateTransferDragSourceListener(getPaletteViewer());
// Create a drag source on the palette viewer. // Create a drag source on the palette viewer.
// See the drag target associated with the GraphicalViewer in configureGraphicalViewer. // See the drag target associated with the GraphicalViewer in configureGraphicalViewer.
getPaletteViewer().addDragSourceListener(dragSource); getPaletteViewer().addDragSourceListener(dragSource);
@@ -645,12 +646,12 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
viewer.setEditPartFactory(new UiElementsEditPartFactory(mParent.getDisplay())); viewer.setEditPartFactory(new UiElementsEditPartFactory(mParent.getDisplay()));
viewer.setRootEditPart(new ScalableFreeformRootEditPart()); viewer.setRootEditPart(new ScalableFreeformRootEditPart());
// Disable the following -- we don't drag *from* the GraphicalViewer yet: // Disable the following -- we don't drag *from* the GraphicalViewer yet:
// viewer.addDragSourceListener(new TemplateTransferDragSourceListener(viewer)); // viewer.addDragSourceListener(new TemplateTransferDragSourceListener(viewer));
viewer.addDropTargetListener(new DropListener(viewer)); viewer.addDropTargetListener(new DropListener(viewer));
} }
class DropListener extends TemplateTransferDropTargetListener { class DropListener extends TemplateTransferDropTargetListener {
public DropListener(EditPartViewer viewer) { public DropListener(EditPartViewer viewer) {
super(viewer); super(viewer);
@@ -670,7 +671,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
public Object getObjectType() { public Object getObjectType() {
return template; return template;
} }
}; };
} }
} }
@@ -698,7 +699,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
input.toString()); input.toString());
} }
} }
/* (non-javadoc) /* (non-javadoc)
* Sets the graphicalViewer for this EditorPart. * Sets the graphicalViewer for this EditorPart.
* @param viewer the graphical viewer * @param viewer the graphical viewer
@@ -714,18 +715,18 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
/** /**
* Used by LayoutEditor.UiEditorActions.selectUiNode to select a new UI Node * Used by LayoutEditor.UiEditorActions.selectUiNode to select a new UI Node
* created by {@link ElementCreateCommand#execute()}. * created by {@link ElementCreateCommand#execute()}.
* *
* @param uiNodeModel The {@link UiElementNode} to select. * @param uiNodeModel The {@link UiElementNode} to select.
*/ */
@Override @Override
void selectModel(UiElementNode uiNodeModel) { void selectModel(UiElementNode uiNodeModel) {
GraphicalViewer viewer = getGraphicalViewer(); GraphicalViewer viewer = getGraphicalViewer();
// Give focus to the graphical viewer (in case the outline has it) // Give focus to the graphical viewer (in case the outline has it)
viewer.getControl().forceFocus(); viewer.getControl().forceFocus();
Object editPart = viewer.getEditPartRegistry().get(uiNodeModel); Object editPart = viewer.getEditPartRegistry().get(uiNodeModel);
if (editPart instanceof EditPart) { if (editPart instanceof EditPart) {
viewer.select((EditPart)editPart); viewer.select((EditPart)editPart);
} }
@@ -745,7 +746,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
MenuManager menuManager = new MenuManager(); MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true); menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(new ActionMenuListener(viewer)); menuManager.addMenuListener(new ActionMenuListener(viewer));
return menuManager; return menuManager;
} }
@@ -775,13 +776,13 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
} }
} }
} }
if (selected.size() > 0) { if (selected.size() > 0) {
doCreateMenuAction(manager, mViewer, selected); doCreateMenuAction(manager, mViewer, selected);
} }
} }
} }
private void doCreateMenuAction(IMenuManager manager, private void doCreateMenuAction(IMenuManager manager,
final GraphicalViewer viewer, final GraphicalViewer viewer,
final ArrayList<UiElementNode> selected) { final ArrayList<UiElementNode> selected) {
@@ -820,7 +821,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// Append "add" and "remove" actions. They do the same thing as the add/remove // Append "add" and "remove" actions. They do the same thing as the add/remove
// buttons on the side. // buttons on the side.
IconFactory factory = IconFactory.getInstance(); IconFactory factory = IconFactory.getInstance();
final UiEditorActions uiActions = mLayoutEditor.getUiEditorActions(); final UiEditorActions uiActions = mLayoutEditor.getUiEditorActions();
// "Add" makes sense only if there's 0 or 1 item selected since the // "Add" makes sense only if there's 0 or 1 item selected since the
@@ -845,7 +846,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
}); });
manager.add(new Separator()); manager.add(new Separator());
manager.add(new Action("Up", factory.getImageDescriptor("up")) { //$NON-NLS-2$ manager.add(new Action("Up", factory.getImageDescriptor("up")) { //$NON-NLS-2$
@Override @Override
public void run() { public void run() {
@@ -859,8 +860,8 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
} }
}); });
} }
} }
/** /**
* Sets the UI for the edition of a new file. * Sets the UI for the edition of a new file.
@@ -870,11 +871,11 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
void editNewFile(FolderConfiguration configuration) { void editNewFile(FolderConfiguration configuration) {
// update the configuration UI // update the configuration UI
setConfiguration(configuration, true /*force*/); setConfiguration(configuration, true /*force*/);
// enable the create button if the current and edited config are not equals // enable the create button if the current and edited config are not equals
mCreateButton.setEnabled(mEditedConfig.equals(mCurrentConfig) == false); mCreateButton.setEnabled(mEditedConfig.equals(mCurrentConfig) == false);
} }
public Rectangle getBounds() { public Rectangle getBounds() {
ScreenOrientation orientation = null; ScreenOrientation orientation = null;
if (mOrientation.getSelectionIndex() == 0) { if (mOrientation.getSelectionIndex() == 0) {
@@ -916,7 +917,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
return new Rectangle(0, 0, s1, s1); return new Rectangle(0, 0, s1, s1);
} }
} }
/** /**
* Renders an Android View described by a {@link ViewElementDescriptor}. * Renders an Android View described by a {@link ViewElementDescriptor}.
* <p/>This uses the <code>wrap_content</code> mode for both <code>layout_width</code> and * <p/>This uses the <code>wrap_content</code> mode for both <code>layout_width</code> and
@@ -928,17 +929,17 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
if (mEditedFile == null) { if (mEditedFile == null) {
return null; return null;
} }
IAndroidTarget target = Sdk.getCurrent().getTarget(mEditedFile.getProject()); IAndroidTarget target = Sdk.getCurrent().getTarget(mEditedFile.getProject());
if (target == null) { if (target == null) {
return null; return null;
} }
AndroidTargetData data = Sdk.getCurrent().getTargetData(target); AndroidTargetData data = Sdk.getCurrent().getTargetData(target);
if (data == null) { if (data == null) {
return null; return null;
} }
LayoutBridge bridge = data.getLayoutBridge(); LayoutBridge bridge = data.getLayoutBridge();
if (bridge.bridge != null) { // bridge can never be null. if (bridge.bridge != null) { // bridge can never be null.
@@ -961,7 +962,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// get the project resource values based on the current config // get the project resource values based on the current config
mConfiguredProjectRes = projectRes.getConfiguredResources(mCurrentConfig); mConfiguredProjectRes = projectRes.getConfiguredResources(mCurrentConfig);
} }
configuredProjectResources = mConfiguredProjectRes; configuredProjectResources = mConfiguredProjectRes;
} else { } else {
// we absolutely need a Map of configured project resources. // we absolutely need a Map of configured project resources.
@@ -998,12 +999,12 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
int height = result.getRootView().getBottom(); int height = result.getRootView().getBottom();
Raster raster = largeImage.getData(new java.awt.Rectangle(width, height)); Raster raster = largeImage.getData(new java.awt.Rectangle(width, height));
int[] imageDataBuffer = ((DataBufferInt)raster.getDataBuffer()).getData(); int[] imageDataBuffer = ((DataBufferInt)raster.getDataBuffer()).getData();
ImageData imageData = new ImageData(width, height, 32, ImageData imageData = new ImageData(width, height, 32,
new PaletteData(0x00FF0000, 0x0000FF00, 0x000000FF)); new PaletteData(0x00FF0000, 0x0000FF00, 0x000000FF));
imageData.setPixels(0, 0, imageDataBuffer.length, imageDataBuffer, 0); imageData.setPixels(0, 0, imageDataBuffer.length, imageDataBuffer, 0);
return imageData; return imageData;
} }
} }
@@ -1046,7 +1047,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
mNeedsXmlReload = true; mNeedsXmlReload = true;
} }
} }
/** /**
* Actually performs the XML reload * Actually performs the XML reload
* @see #onXmlModelChanged() * @see #onXmlModelChanged()
@@ -1054,17 +1055,17 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
private void doXmlReload(boolean force) { private void doXmlReload(boolean force) {
if (force || mNeedsXmlReload) { if (force || mNeedsXmlReload) {
GraphicalViewer viewer = getGraphicalViewer(); GraphicalViewer viewer = getGraphicalViewer();
// try to preserve the selection before changing the content // try to preserve the selection before changing the content
SelectionManager selMan = viewer.getSelectionManager(); SelectionManager selMan = viewer.getSelectionManager();
ISelection selection = selMan.getSelection(); ISelection selection = selMan.getSelection();
try { try {
viewer.setContents(getModel()); viewer.setContents(getModel());
} finally { } finally {
selMan.setSelection(selection); selMan.setSelection(selection);
} }
mNeedsXmlReload = false; mNeedsXmlReload = false;
} }
} }
@@ -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);
} }
@@ -1223,10 +1225,10 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// update the string showing the folder name // update the string showing the folder name
String current = config.toDisplayString(); String current = config.toDisplayString();
mCurrentLayoutLabel.setText(current != null ? current : "(Default)"); mCurrentLayoutLabel.setText(current != null ? current : "(Default)");
mDisableUpdates = false; mDisableUpdates = false;
} }
/** /**
* Displays an error icon in front of all the non-null qualifiers. * Displays an error icon in front of all the non-null qualifiers.
*/ */
@@ -1236,44 +1238,44 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
if (countryQualifier != null) { if (countryQualifier != null) {
mCountryIcon.setImage(mErrorImage); mCountryIcon.setImage(mErrorImage);
} }
mNetworkIcon.setImage(mMatchImage); mNetworkIcon.setImage(mMatchImage);
NetworkCodeQualifier networkQualifier = mCurrentConfig.getNetworkCodeQualifier(); NetworkCodeQualifier networkQualifier = mCurrentConfig.getNetworkCodeQualifier();
if (networkQualifier != null) { if (networkQualifier != null) {
mNetworkIcon.setImage(mErrorImage); mNetworkIcon.setImage(mErrorImage);
} }
mLanguageIcon.setImage(mMatchImage); mLanguageIcon.setImage(mMatchImage);
LanguageQualifier languageQualifier = mCurrentConfig.getLanguageQualifier(); LanguageQualifier languageQualifier = mCurrentConfig.getLanguageQualifier();
if (languageQualifier != null) { if (languageQualifier != null) {
mLanguageIcon.setImage(mErrorImage); mLanguageIcon.setImage(mErrorImage);
} }
mRegionIcon.setImage(mMatchImage); mRegionIcon.setImage(mMatchImage);
RegionQualifier regionQualifier = mCurrentConfig.getRegionQualifier(); RegionQualifier regionQualifier = mCurrentConfig.getRegionQualifier();
if (regionQualifier != null) { if (regionQualifier != null) {
mRegionIcon.setImage(mErrorImage); mRegionIcon.setImage(mErrorImage);
} }
mOrientationIcon.setImage(mMatchImage); mOrientationIcon.setImage(mMatchImage);
ScreenOrientationQualifier orientationQualifier = ScreenOrientationQualifier orientationQualifier =
mCurrentConfig.getScreenOrientationQualifier(); mCurrentConfig.getScreenOrientationQualifier();
if (orientationQualifier != null) { if (orientationQualifier != null) {
mOrientationIcon.setImage(mErrorImage); mOrientationIcon.setImage(mErrorImage);
} }
mDensityIcon.setImage(mMatchImage); mDensityIcon.setImage(mMatchImage);
PixelDensityQualifier densityQualifier = mCurrentConfig.getPixelDensityQualifier(); PixelDensityQualifier densityQualifier = mCurrentConfig.getPixelDensityQualifier();
if (densityQualifier != null) { if (densityQualifier != null) {
mDensityIcon.setImage(mErrorImage); mDensityIcon.setImage(mErrorImage);
} }
mTouchIcon.setImage(mMatchImage); mTouchIcon.setImage(mMatchImage);
TouchScreenQualifier touchQualifier = mCurrentConfig.getTouchTypeQualifier(); TouchScreenQualifier touchQualifier = mCurrentConfig.getTouchTypeQualifier();
if (touchQualifier != null) { if (touchQualifier != null) {
mTouchIcon.setImage(mErrorImage); mTouchIcon.setImage(mErrorImage);
} }
mKeyboardIcon.setImage(mMatchImage); mKeyboardIcon.setImage(mMatchImage);
KeyboardStateQualifier keyboardQualifier = mCurrentConfig.getKeyboardStateQualifier(); KeyboardStateQualifier keyboardQualifier = mCurrentConfig.getKeyboardStateQualifier();
if (keyboardQualifier != null) { if (keyboardQualifier != null) {
@@ -1285,20 +1287,20 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
if (inputQualifier != null) { if (inputQualifier != null) {
mTextInputIcon.setImage(mErrorImage); mTextInputIcon.setImage(mErrorImage);
} }
mNavigationIcon.setImage(mMatchImage); mNavigationIcon.setImage(mMatchImage);
NavigationMethodQualifier navigationQualifiter = NavigationMethodQualifier navigationQualifiter =
mCurrentConfig.getNavigationMethodQualifier(); mCurrentConfig.getNavigationMethodQualifier();
if (navigationQualifiter != null) { if (navigationQualifiter != null) {
mNavigationIcon.setImage(mErrorImage); mNavigationIcon.setImage(mErrorImage);
} }
mSizeIcon.setImage(mMatchImage); mSizeIcon.setImage(mMatchImage);
ScreenDimensionQualifier sizeQualifier = mCurrentConfig.getScreenDimensionQualifier(); ScreenDimensionQualifier sizeQualifier = mCurrentConfig.getScreenDimensionQualifier();
if (sizeQualifier != null) { if (sizeQualifier != null) {
mSizeIcon.setImage(mErrorImage); mSizeIcon.setImage(mErrorImage);
} }
// update the string showing the folder name // update the string showing the folder name
String current = mCurrentConfig.toDisplayString(); String current = mCurrentConfig.toDisplayString();
mCurrentLayoutLabel.setText(current != null ? current : "(Default)"); mCurrentLayoutLabel.setText(current != null ? current : "(Default)");
@@ -1308,7 +1310,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
UiDocumentNode getModel() { UiDocumentNode getModel() {
return mLayoutEditor.getUiRootNode(); return mLayoutEditor.getUiRootNode();
} }
@Override @Override
void reloadPalette() { void reloadPalette() {
PaletteFactory.createPaletteRoot(mPaletteRoot, mLayoutEditor.getTargetData()); PaletteFactory.createPaletteRoot(mPaletteRoot, mLayoutEditor.getTargetData());
@@ -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))));
}
// update the current config
String value = mDensity.getText();
// empty string, means no qualifier.
if (value.length() == 0) {
mCurrentConfig.setPixelDensityQualifier(null);
} else { } else {
try { mCurrentConfig.setPixelDensityQualifier(null);
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
@@ -1612,11 +1590,11 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
if (mEditedFile == null || mEditedConfig == null) { if (mEditedFile == null || mEditedConfig == null) {
return; return;
} }
// get the resources of the file's project. // get the resources of the file's project.
ProjectResources resources = ResourceManager.getInstance().getProjectResources( ProjectResources resources = ResourceManager.getInstance().getProjectResources(
mEditedFile.getProject()); mEditedFile.getProject());
// from the resources, look for a matching file // from the resources, look for a matching file
ResourceFile match = null; ResourceFile match = null;
if (resources != null) { if (resources != null) {
@@ -1643,7 +1621,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// update the configuration icons with the new edited config. // update the configuration icons with the new edited config.
setConfiguration(mEditedConfig, false /*force*/); setConfiguration(mEditedConfig, false /*force*/);
// enable the create button if the current and edited config are not equals // enable the create button if the current and edited config are not equals
mCreateButton.setEnabled(mEditedConfig.equals(mCurrentConfig) == false); mCreateButton.setEnabled(mEditedConfig.equals(mCurrentConfig) == false);
@@ -1653,7 +1631,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
} else { } else {
// update the configuration icons with the new edited config. // update the configuration icons with the new edited config.
displayConfigError(); displayConfigError();
// enable the Create button // enable the Create button
mCreateButton.setEnabled(true); mCreateButton.setEnabled(true);
@@ -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);
} }
@@ -1671,7 +1650,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
int themeIndex = mThemeCombo.getSelectionIndex(); int themeIndex = mThemeCombo.getSelectionIndex();
if (themeIndex != -1) { if (themeIndex != -1) {
String theme = mThemeCombo.getItem(themeIndex); String theme = mThemeCombo.getItem(themeIndex);
if (theme.equals(THEME_SEPARATOR)) { if (theme.equals(THEME_SEPARATOR)) {
mThemeCombo.select(0); mThemeCombo.select(0);
} }
@@ -1745,7 +1724,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
showErrorInEditor("The project target is not set."); showErrorInEditor("The project target is not set.");
return; return;
} }
AndroidTargetData data = currentSdk.getTargetData(target); AndroidTargetData data = currentSdk.getTargetData(target);
if (data == null) { if (data == null) {
// It can happen that the workspace refreshes while the SDK is loading its // It can happen that the workspace refreshes while the SDK is loading its
@@ -1774,67 +1753,77 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
if (bridge.bridge != null) { // bridge can never be null. if (bridge.bridge != null) { // bridge can never be null.
ResourceManager resManager = ResourceManager.getInstance(); ResourceManager resManager = ResourceManager.getInstance();
ProjectResources projectRes = resManager.getProjectResources(iProject); ProjectResources projectRes = resManager.getProjectResources(iProject);
if (projectRes == null) { if (projectRes == null) {
return; return;
} }
// get the resources of the file's project. // get the resources of the file's project.
if (mConfiguredProjectRes == null) { if (mConfiguredProjectRes == null) {
// make sure they are loaded // make sure they are loaded
projectRes.loadAll(); projectRes.loadAll();
// get the project resource values based on the current config // get the project resource values based on the current config
mConfiguredProjectRes = projectRes.getConfiguredResources(mCurrentConfig); mConfiguredProjectRes = projectRes.getConfiguredResources(mCurrentConfig);
} }
// get the framework resources // get the framework resources
Map<String, Map<String, IResourceValue>> frameworkResources = Map<String, Map<String, IResourceValue>> frameworkResources =
getConfiguredFrameworkResources(); getConfiguredFrameworkResources();
if (mConfiguredProjectRes != null && frameworkResources != null) { if (mConfiguredProjectRes != null && frameworkResources != null) {
if (mProjectCallback == null) { if (mProjectCallback == null) {
mProjectCallback = new ProjectCallback( mProjectCallback = new ProjectCallback(
bridge.classLoader, projectRes, iProject); bridge.classLoader, projectRes, iProject);
} }
if (mLogger == null) { if (mLogger == null) {
mLogger = new ILayoutLog() { mLogger = new ILayoutLog() {
public void error(String message) { public void error(String message) {
AdtPlugin.printErrorToConsole(mEditedFile.getName(), message); AdtPlugin.printErrorToConsole(mEditedFile.getName(), message);
} }
public void error(Throwable error) { public void error(Throwable error) {
String message = error.getMessage(); String message = error.getMessage();
if (message == null) { if (message == null) {
message = error.getClass().getName(); message = error.getClass().getName();
} }
PrintStream ps = new PrintStream(AdtPlugin.getErrorStream()); PrintStream ps = new PrintStream(AdtPlugin.getErrorStream());
error.printStackTrace(ps); error.printStackTrace(ps);
} }
public void warning(String message) { public void warning(String message) {
AdtPlugin.printToConsole(mEditedFile.getName(), message); AdtPlugin.printToConsole(mEditedFile.getName(), message);
} }
}; };
} }
// get the selected theme // get the selected theme
int themeIndex = mThemeCombo.getSelectionIndex(); int themeIndex = mThemeCombo.getSelectionIndex();
if (themeIndex != -1) { if (themeIndex != -1) {
String theme = mThemeCombo.getItem(themeIndex); String theme = mThemeCombo.getItem(themeIndex);
// Compute the layout // Compute the layout
UiElementPullParser parser = new UiElementPullParser(getModel()); UiElementPullParser parser = new UiElementPullParser(getModel());
Rectangle rect = getBounds(); Rectangle rect = getBounds();
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);
@@ -1842,20 +1831,20 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// update the UiElementNode with the layout info. // update the UiElementNode with the layout info.
if (result.getSuccess() == ILayoutResult.SUCCESS) { if (result.getSuccess() == ILayoutResult.SUCCESS) {
model.setEditData(result.getImage()); model.setEditData(result.getImage());
updateNodeWithBounds(result.getRootView()); updateNodeWithBounds(result.getRootView());
} else { } else {
String message = result.getErrorMessage(); String message = result.getErrorMessage();
// Reset the edit data for all the nodes. // Reset the edit data for all the nodes.
resetNodeBounds(model); resetNodeBounds(model);
if (message != null) { if (message != null) {
// set the error in the top element. // set the error in the top element.
model.setEditData(message); model.setEditData(message);
} }
} }
model.refreshUi(); model.refreshUi();
} }
} }
@@ -1951,11 +1940,11 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// clear the cache in the bridge in case a bitmap/9-patch changed. // clear the cache in the bridge in case a bitmap/9-patch changed.
IAndroidTarget target = Sdk.getCurrent().getTarget(mEditedFile.getProject()); IAndroidTarget target = Sdk.getCurrent().getTarget(mEditedFile.getProject());
if (target != null) { if (target != null) {
AndroidTargetData data = Sdk.getCurrent().getTargetData(target); AndroidTargetData data = Sdk.getCurrent().getTargetData(target);
if (data != null) { if (data != null) {
LayoutBridge bridge = data.getLayoutBridge(); LayoutBridge bridge = data.getLayoutBridge();
if (bridge.bridge != null) { if (bridge.bridge != null) {
bridge.bridge.clearCaches(mEditedFile.getProject()); bridge.bridge.clearCaches(mEditedFile.getProject());
} }
@@ -2007,28 +1996,28 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
ProjectResources frameworkProject = getFrameworkResources(); ProjectResources frameworkProject = getFrameworkResources();
mDisableUpdates = true; mDisableUpdates = true;
// Reset stuff // Reset stuff
int selection = mThemeCombo.getSelectionIndex(); int selection = mThemeCombo.getSelectionIndex();
mThemeCombo.removeAll(); mThemeCombo.removeAll();
mPlatformThemeCount = 0; mPlatformThemeCount = 0;
mLanguage.removeAll(); mLanguage.removeAll();
Set<String> languages = new HashSet<String>(); Set<String> languages = new HashSet<String>();
ArrayList<String> themes = new ArrayList<String>(); ArrayList<String> themes = new ArrayList<String>();
// get the themes, and languages from the Framework. // get the themes, and languages from the Framework.
if (frameworkProject != null) { if (frameworkProject != null) {
// get the configured resources for the framework // get the configured resources for the framework
Map<String, Map<String, IResourceValue>> frameworResources = Map<String, Map<String, IResourceValue>> frameworResources =
getConfiguredFrameworkResources(); getConfiguredFrameworkResources();
if (frameworResources != null) { if (frameworResources != null) {
// get the styles. // get the styles.
Map<String, IResourceValue> styles = frameworResources.get( Map<String, IResourceValue> styles = frameworResources.get(
ResourceType.STYLE.getName()); ResourceType.STYLE.getName());
// collect the themes out of all the styles. // collect the themes out of all the styles.
for (IResourceValue value : styles.values()) { for (IResourceValue value : styles.values()) {
String name = value.getName(); String name = value.getName();
@@ -2040,11 +2029,11 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// sort them and add them to the combo // sort them and add them to the combo
Collections.sort(themes); Collections.sort(themes);
for (String theme : themes) { for (String theme : themes) {
mThemeCombo.add(theme); mThemeCombo.add(theme);
} }
mPlatformThemeCount = themes.size(); mPlatformThemeCount = themes.size();
themes.clear(); themes.clear();
} }
@@ -2054,7 +2043,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
languages.addAll(frameworkLanguages); languages.addAll(frameworkLanguages);
} }
} }
// now get the themes and languages from the project. // now get the themes and languages from the project.
ProjectResources project = null; ProjectResources project = null;
if (mEditedFile != null) { if (mEditedFile != null) {
@@ -2062,7 +2051,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// in cases where the opened file is not linked to a project, this could be null. // in cases where the opened file is not linked to a project, this could be null.
if (project != null) { if (project != null) {
// get the configured resources for the project // get the configured resources for the project
if (mConfiguredProjectRes == null) { if (mConfiguredProjectRes == null) {
// make sure they are loaded // make sure they are loaded
project.loadAll(); project.loadAll();
@@ -2070,12 +2059,12 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// get the project resource values based on the current config // get the project resource values based on the current config
mConfiguredProjectRes = project.getConfiguredResources(mCurrentConfig); mConfiguredProjectRes = project.getConfiguredResources(mCurrentConfig);
} }
if (mConfiguredProjectRes != null) { if (mConfiguredProjectRes != null) {
// get the styles. // get the styles.
Map<String, IResourceValue> styleMap = mConfiguredProjectRes.get( Map<String, IResourceValue> styleMap = mConfiguredProjectRes.get(
ResourceType.STYLE.getName()); ResourceType.STYLE.getName());
if (styleMap != null) { if (styleMap != null) {
// collect the themes out of all the styles, ie styles that extend, // collect the themes out of all the styles, ie styles that extend,
// directly or indirectly a platform theme. // directly or indirectly a platform theme.
@@ -2089,9 +2078,9 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
if (mPlatformThemeCount > 0 && themes.size() > 0) { if (mPlatformThemeCount > 0 && themes.size() > 0) {
mThemeCombo.add(THEME_SEPARATOR); mThemeCombo.add(THEME_SEPARATOR);
} }
Collections.sort(themes); Collections.sort(themes);
for (String theme : themes) { for (String theme : themes) {
mThemeCombo.add(theme); mThemeCombo.add(theme);
} }
@@ -2110,7 +2099,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
for (String language : languages) { for (String language : languages) {
mLanguage.add(language); mLanguage.add(language);
} }
mDisableUpdates = false; mDisableUpdates = false;
// and update the Region UI based on the current language // and update the Region UI based on the current language
@@ -2143,7 +2132,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
private boolean isTheme(IResourceValue value, Map<String, IResourceValue> styleMap) { private boolean isTheme(IResourceValue value, Map<String, IResourceValue> styleMap) {
if (value instanceof IStyleResourceValue) { if (value instanceof IStyleResourceValue) {
IStyleResourceValue style = (IStyleResourceValue)value; IStyleResourceValue style = (IStyleResourceValue)value;
boolean frameworkStyle = false; boolean frameworkStyle = false;
String parentStyle = style.getParentStyle(); String parentStyle = style.getParentStyle();
if (parentStyle == null) { if (parentStyle == null) {
@@ -2160,13 +2149,13 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
if (parentStyle.startsWith("@")) { if (parentStyle.startsWith("@")) {
parentStyle = parentStyle.substring(1); parentStyle = parentStyle.substring(1);
} }
// check for framework identifier. // check for framework identifier.
if (parentStyle.startsWith("android:")) { if (parentStyle.startsWith("android:")) {
frameworkStyle = true; frameworkStyle = true;
parentStyle = parentStyle.substring("android:".length()); parentStyle = parentStyle.substring("android:".length());
} }
// at this point we could have the format style/<name>. we want only the name // at this point we could have the format style/<name>. we want only the name
if (parentStyle.startsWith("style/")) { if (parentStyle.startsWith("style/")) {
parentStyle = parentStyle.substring("style/".length()); parentStyle = parentStyle.substring("style/".length());
@@ -2232,7 +2221,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
mDisableUpdates = false; mDisableUpdates = false;
} }
} }
private Map<String, Map<String, IResourceValue>> getConfiguredFrameworkResources() { private Map<String, Map<String, IResourceValue>> getConfiguredFrameworkResources() {
if (mConfiguredFrameworkRes == null) { if (mConfiguredFrameworkRes == null) {
ProjectResources frameworkRes = getFrameworkResources(); ProjectResources frameworkRes = getFrameworkResources();
@@ -2244,7 +2233,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// get the framework resource values based on the current config // get the framework resource values based on the current config
mConfiguredFrameworkRes = frameworkRes.getConfiguredResources(mCurrentConfig); mConfiguredFrameworkRes = frameworkRes.getConfiguredResources(mCurrentConfig);
} }
return mConfiguredFrameworkRes; return mConfiguredFrameworkRes;
} }
@@ -2256,14 +2245,15 @@ 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.
// get the res folder // get the res folder
IFolder res = (IFolder)mEditedFile.getParent().getParent(); IFolder res = (IFolder)mEditedFile.getParent().getParent();
String path = res.getLocation().toOSString(); String path = res.getLocation().toOSString();
File newLayoutFolder = new File(path + File.separator + folderName); File newLayoutFolder = new File(path + File.separator + folderName);
if (newLayoutFolder.isFile()) { if (newLayoutFolder.isFile()) {
// this should not happen since aapt would have complained // this should not happen since aapt would have complained
@@ -2271,34 +2261,34 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// happen. // happen.
String message = String.format("File 'res/%1$s' is in the way!", String message = String.format("File 'res/%1$s' is in the way!",
folderName); folderName);
AdtPlugin.displayError("Layout Creation", message); AdtPlugin.displayError("Layout Creation", message);
return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, message); return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, message);
} else if (newLayoutFolder.exists() == false) { } else if (newLayoutFolder.exists() == false) {
// create it. // create it.
newLayoutFolder.mkdir(); newLayoutFolder.mkdir();
} }
// now create the file // now create the file
File newLayoutFile = new File(newLayoutFolder.getAbsolutePath() + File newLayoutFile = new File(newLayoutFolder.getAbsolutePath() +
File.separator + mEditedFile.getName()); File.separator + mEditedFile.getName());
newLayoutFile.createNewFile(); newLayoutFile.createNewFile();
InputStream input = mEditedFile.getContents(); InputStream input = mEditedFile.getContents();
FileOutputStream fos = new FileOutputStream(newLayoutFile); FileOutputStream fos = new FileOutputStream(newLayoutFile);
byte[] data = new byte[512]; byte[] data = new byte[512];
int count; int count;
while ((count = input.read(data)) != -1) { while ((count = input.read(data)) != -1) {
fos.write(data, 0, count); fos.write(data, 0, count);
} }
input.close(); input.close();
fos.close(); fos.close();
// refreshes the res folder to show up the new // refreshes the res folder to show up the new
// layout folder (if needed) and the file. // layout folder (if needed) and the file.
// We use a progress monitor to catch the end of the refresh // We use a progress monitor to catch the end of the refresh
@@ -2346,27 +2336,27 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
String message = String.format( String message = String.format(
"Failed to create File 'res/%1$s/%2$s' : %3$s", "Failed to create File 'res/%1$s/%2$s' : %3$s",
folderName, mEditedFile.getName(), e2.getMessage()); folderName, mEditedFile.getName(), e2.getMessage());
AdtPlugin.displayError("Layout Creation", message); AdtPlugin.displayError("Layout Creation", message);
return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID,
message, e2); message, e2);
} catch (CoreException e2) { } catch (CoreException e2) {
String message = String.format( String message = String.format(
"Failed to create File 'res/%1$s/%2$s' : %3$s", "Failed to create File 'res/%1$s/%2$s' : %3$s",
folderName, mEditedFile.getName(), e2.getMessage()); folderName, mEditedFile.getName(), e2.getMessage());
AdtPlugin.displayError("Layout Creation", message); AdtPlugin.displayError("Layout Creation", message);
return e2.getStatus(); return e2.getStatus();
} }
return Status.OK_STATUS; return Status.OK_STATUS;
} }
}.schedule(); }.schedule();
} }
/** /**
* Returns a {@link ProjectResources} for the framework resources. * Returns a {@link ProjectResources} for the framework resources.
* @return the framework resources or null if not found. * @return the framework resources or null if not found.
@@ -2376,10 +2366,10 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
Sdk currentSdk = Sdk.getCurrent(); Sdk currentSdk = Sdk.getCurrent();
if (currentSdk != null) { if (currentSdk != null) {
IAndroidTarget target = currentSdk.getTarget(mEditedFile.getProject()); IAndroidTarget target = currentSdk.getTarget(mEditedFile.getProject());
if (target != null) { if (target != null) {
AndroidTargetData data = currentSdk.getTargetData(target); AndroidTargetData data = currentSdk.getTargetData(target);
if (data != null) { if (data != null) {
return data.getFrameworkResources(); return data.getFrameworkResources();
} }
@@ -2389,7 +2379,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
return null; return null;
} }
/** /**
* Computes a layout by calling the correct computeLayout method of ILayoutBridge based on * Computes a layout by calling the correct computeLayout method of ILayoutBridge based on
* the implementation API level. * the implementation API level.
@@ -2402,12 +2392,12 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
Map<String, Map<String, IResourceValue>> projectResources, Map<String, Map<String, IResourceValue>> projectResources,
Map<String, Map<String, IResourceValue>> frameworkResources, Map<String, Map<String, IResourceValue>> frameworkResources,
IProjectCallback projectCallback, ILayoutLog logger) { IProjectCallback projectCallback, ILayoutLog logger) {
if (bridge.apiLevel >= 3) { if (bridge.apiLevel >= 3) {
// newer api with boolean for separation of project/framework theme, // newer api with boolean for separation of project/framework theme,
// and density support. // and density support.
return bridge.bridge.computeLayout(layoutDescription, return bridge.bridge.computeLayout(layoutDescription,
projectKey, screenWidth, screenHeight, density, xdpi, ydpi, projectKey, screenWidth, screenHeight, density, xdpi, ydpi,
themeName, isProjectTheme, themeName, isProjectTheme,
projectResources, frameworkResources, projectCallback, projectResources, frameworkResources, projectCallback,
logger); logger);

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;
@@ -40,22 +41,26 @@ class LayoutCreatorDialog extends TrayDialog {
private ConfigurationSelector mSelector; private ConfigurationSelector mSelector;
private Composite mStatusComposite; private Composite mStatusComposite;
private Label mStatusLabel; private Label mStatusLabel;
private Label mStatusImage; private Label mStatusImage;
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;
// FIXME: add some data to know what configurations already exist. mTarget = target;
// FIXME: add some data to know what configurations already exist.
mConfig.set(config); mConfig.set(config);
} }
@@ -67,22 +72,22 @@ class LayoutCreatorDialog extends TrayDialog {
new Label(top, SWT.NONE).setText( new Label(top, 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(top); mSelector = new ConfigurationSelector(top);
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.
GridData gd = new GridData(); GridData gd = new GridData();
gd.widthHint = ConfigurationSelector.WIDTH_HINT; gd.widthHint = ConfigurationSelector.WIDTH_HINT;
gd.heightHint = ConfigurationSelector.HEIGHT_HINT; gd.heightHint = ConfigurationSelector.HEIGHT_HINT;
mSelector.setLayoutData(gd); mSelector.setLayoutData(gd);
// add a listener to check on the validity of the FolderConfiguration as // add a listener to check on the validity of the FolderConfiguration as
// they are built. // they are built.
mSelector.setOnChangeListener(new Runnable() { mSelector.setOnChangeListener(new Runnable() {
public void run() { public void run() {
ConfigurationState state = mSelector.getState(); ConfigurationState state = mSelector.getState();
switch (state) { switch (state) {
case OK: case OK:
mSelector.getConfiguration(mConfig); mSelector.getConfiguration(mConfig);
@@ -125,16 +130,16 @@ class LayoutCreatorDialog extends TrayDialog {
return top; return top;
} }
public void getConfiguration(FolderConfiguration config) { public void getConfiguration(FolderConfiguration config) {
config.set(mConfig); config.set(mConfig);
} }
/** /**
* resets the status label to show the file that will be created. * resets the status label to show the file that will be created.
*/ */
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;
@@ -33,9 +34,9 @@ public final class CountryCodeQualifier extends ResourceQualifier {
private final static Pattern sCountryCodePattern = Pattern.compile("^mcc(\\d{3})$");//$NON-NLS-1$ private final static Pattern sCountryCodePattern = Pattern.compile("^mcc(\\d{3})$");//$NON-NLS-1$
private int mCode = DEFAULT_CODE; private int mCode = DEFAULT_CODE;
public static final String NAME = "Mobile Country Code"; public static final String NAME = "Mobile Country Code";
/** /**
* Creates and returns a qualifier from the given folder segment. If the segment is incorrect, * Creates and returns a qualifier from the given folder segment. If the segment is incorrect,
* <code>null</code> is returned. * <code>null</code> is returned.
@@ -54,15 +55,15 @@ public final class CountryCodeQualifier extends ResourceQualifier {
// looks like the string we extracted wasn't a valid number. // looks like the string we extracted wasn't a valid number.
return null; return null;
} }
CountryCodeQualifier qualifier = new CountryCodeQualifier(); CountryCodeQualifier qualifier = new CountryCodeQualifier();
qualifier.mCode = code; qualifier.mCode = code;
return qualifier; return qualifier;
} }
return null; return null;
} }
/** /**
* Returns the folder name segment for the given value. This is equivalent to calling * Returns the folder name segment for the given value. This is equivalent to calling
* {@link #toString()} on a {@link CountryCodeQualifier} object. * {@link #toString()} on a {@link CountryCodeQualifier} object.
@@ -72,29 +73,29 @@ public final class CountryCodeQualifier extends ResourceQualifier {
if (code != DEFAULT_CODE && code >= 100 && code <=999) { // code is 3 digit.) { if (code != DEFAULT_CODE && code >= 100 && code <=999) { // code is 3 digit.) {
return String.format("mcc%1$d", code); //$NON-NLS-1$ return String.format("mcc%1$d", code); //$NON-NLS-1$
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
public int getCode() { public int getCode() {
return mCode; return mCode;
} }
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override @Override
public String getShortName() { public String getShortName() {
return "Country Code"; return "Country Code";
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return IconFactory.getInstance().getIcon("mcc"); //$NON-NLS-1$ return IconFactory.getInstance().getIcon("mcc"); //$NON-NLS-1$
} }
@Override @Override
public boolean isValid() { public boolean isValid() {
return mCode != DEFAULT_CODE; return mCode != DEFAULT_CODE;
@@ -107,29 +108,29 @@ public final class CountryCodeQualifier extends ResourceQualifier {
config.setCountryCodeQualifier(qualifier); config.setCountryCodeQualifier(qualifier);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public boolean equals(Object qualifier) { public boolean equals(Object qualifier) {
if (qualifier instanceof CountryCodeQualifier) { if (qualifier instanceof CountryCodeQualifier) {
return mCode == ((CountryCodeQualifier)qualifier).mCode; return mCode == ((CountryCodeQualifier)qualifier).mCode;
} }
return false; return false;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return mCode; return mCode;
} }
/** /**
* 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);
} }
@@ -138,7 +139,7 @@ public final class CountryCodeQualifier extends ResourceQualifier {
if (mCode != DEFAULT_CODE) { if (mCode != DEFAULT_CODE) {
return String.format("MCC %1$d", mCode); return String.format("MCC %1$d", mCode);
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
} }

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;
/** /**
@@ -27,7 +31,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
public final static String QUALIFIER_SEP = "-"; //$NON-NLS-1$ public final static String QUALIFIER_SEP = "-"; //$NON-NLS-1$
private final ResourceQualifier[] mQualifiers = new ResourceQualifier[INDEX_COUNT]; private final ResourceQualifier[] mQualifiers = new ResourceQualifier[INDEX_COUNT];
private final static int INDEX_COUNTRY_CODE = 0; private final static int INDEX_COUNTRY_CODE = 0;
private final static int INDEX_NETWORK_CODE = 1; private final static int INDEX_NETWORK_CODE = 1;
private final static int INDEX_LANGUAGE = 2; private final static int INDEX_LANGUAGE = 2;
@@ -40,7 +44,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
private final static int INDEX_NAVIGATION_METHOD = 9; private final static int INDEX_NAVIGATION_METHOD = 9;
private final static int INDEX_SCREEN_DIMENSION = 10; private final static int INDEX_SCREEN_DIMENSION = 10;
private final static int INDEX_COUNT = 11; private final static int INDEX_COUNT = 11;
/** /**
* Sets the config from the qualifiers of a given <var>config</var>. * Sets the config from the qualifiers of a given <var>config</var>.
* @param config * @param config
@@ -62,7 +66,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
} }
} }
} }
/** /**
* Returns the first invalid qualifier, or <code>null<code> if they are all valid (or if none * Returns the first invalid qualifier, or <code>null<code> if they are all valid (or if none
* exists). * exists).
@@ -73,11 +77,11 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
return mQualifiers[i]; return mQualifiers[i];
} }
} }
// all allocated qualifiers are valid, we return null. // all allocated qualifiers are valid, we return null.
return null; return null;
} }
/** /**
* Returns whether the Region qualifier is valid. Region qualifier can only be present if a * Returns whether the Region qualifier is valid. Region qualifier can only be present if a
* Language qualifier is present as well. * Language qualifier is present as well.
@@ -90,7 +94,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
return true; return true;
} }
/** /**
* Adds a qualifier to the {@link FolderConfiguration} * Adds a qualifier to the {@link FolderConfiguration}
* @param qualifier the {@link ResourceQualifier} to add. * @param qualifier the {@link ResourceQualifier} to add.
@@ -120,7 +124,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
mQualifiers[INDEX_SCREEN_DIMENSION] = qualifier; mQualifiers[INDEX_SCREEN_DIMENSION] = qualifier;
} }
} }
/** /**
* Removes a given qualifier from the {@link FolderConfiguration}. * Removes a given qualifier from the {@link FolderConfiguration}.
* @param qualifier the {@link ResourceQualifier} to remove. * @param qualifier the {@link ResourceQualifier} to remove.
@@ -133,7 +137,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
} }
} }
} }
public void setCountryCodeQualifier(CountryCodeQualifier qualifier) { public void setCountryCodeQualifier(CountryCodeQualifier qualifier) {
mQualifiers[INDEX_COUNTRY_CODE] = qualifier; mQualifiers[INDEX_COUNTRY_CODE] = qualifier;
} }
@@ -205,7 +209,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
public TextInputMethodQualifier getTextInputMethodQualifier() { public TextInputMethodQualifier getTextInputMethodQualifier() {
return (TextInputMethodQualifier)mQualifiers[INDEX_TEXT_INPUT_METHOD]; return (TextInputMethodQualifier)mQualifiers[INDEX_TEXT_INPUT_METHOD];
} }
public void setNavigationMethodQualifier(NavigationMethodQualifier qualifier) { public void setNavigationMethodQualifier(NavigationMethodQualifier qualifier) {
mQualifiers[INDEX_NAVIGATION_METHOD] = qualifier; mQualifiers[INDEX_NAVIGATION_METHOD] = qualifier;
} }
@@ -213,7 +217,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
public NavigationMethodQualifier getNavigationMethodQualifier() { public NavigationMethodQualifier getNavigationMethodQualifier() {
return (NavigationMethodQualifier)mQualifiers[INDEX_NAVIGATION_METHOD]; return (NavigationMethodQualifier)mQualifiers[INDEX_NAVIGATION_METHOD];
} }
public void setScreenDimensionQualifier(ScreenDimensionQualifier qualifier) { public void setScreenDimensionQualifier(ScreenDimensionQualifier qualifier) {
mQualifiers[INDEX_SCREEN_DIMENSION] = qualifier; mQualifiers[INDEX_SCREEN_DIMENSION] = qualifier;
} }
@@ -230,7 +234,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
if (obj == this) { if (obj == this) {
return true; return true;
} }
if (obj instanceof FolderConfiguration) { if (obj instanceof FolderConfiguration) {
FolderConfiguration fc = (FolderConfiguration)obj; FolderConfiguration fc = (FolderConfiguration)obj;
for (int i = 0 ; i < INDEX_COUNT ; i++) { for (int i = 0 ; i < INDEX_COUNT ; i++) {
@@ -247,7 +251,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
return true; return true;
} }
return false; return false;
} }
@@ -255,7 +259,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
public int hashCode() { public int hashCode() {
return toString().hashCode(); return toString().hashCode();
} }
/** /**
* Returns whether the Configuration has only default values. * Returns whether the Configuration has only default values.
*/ */
@@ -265,52 +269,49 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
return false; return false;
} }
} }
return true; return true;
} }
/** /**
* 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));
} }
} }
return result.toString(); return result.toString();
} }
/** /**
* 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;
}
} }
/** /**
* Returns a string valid for display purpose. * Returns a string valid for display purpose.
*/ */
@@ -322,7 +323,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
StringBuilder result = null; StringBuilder result = null;
int index = 0; int index = 0;
ResourceQualifier qualifier = null; ResourceQualifier qualifier = null;
// pre- language/region qualifiers // pre- language/region qualifiers
while (index < INDEX_LANGUAGE) { while (index < INDEX_LANGUAGE) {
qualifier = mQualifiers[index++]; qualifier = mQualifiers[index++];
@@ -333,10 +334,10 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
result.append(", "); //$NON-NLS-1$ result.append(", "); //$NON-NLS-1$
} }
result.append(qualifier.getStringValue()); result.append(qualifier.getStringValue());
} }
} }
// process the language/region qualifier in a custom way, if there are both non null. // process the language/region qualifier in a custom way, if there are both non null.
if (mQualifiers[INDEX_LANGUAGE] != null && mQualifiers[INDEX_REGION] != null) { if (mQualifiers[INDEX_LANGUAGE] != null && mQualifiers[INDEX_REGION] != null) {
String language = mQualifiers[INDEX_LANGUAGE].getStringValue(); String language = mQualifiers[INDEX_LANGUAGE].getStringValue();
@@ -348,10 +349,10 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
result.append(", "); //$NON-NLS-1$ result.append(", "); //$NON-NLS-1$
} }
result.append(String.format("%s_%s", language, region)); //$NON-NLS-1$ result.append(String.format("%s_%s", language, region)); //$NON-NLS-1$
index += 2; index += 2;
} }
// post language/region qualifiers. // post language/region qualifiers.
while (index < INDEX_COUNT) { while (index < INDEX_COUNT) {
qualifier = mQualifiers[index++]; qualifier = mQualifiers[index++];
@@ -362,7 +363,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
result.append(", "); //$NON-NLS-1$ result.append(", "); //$NON-NLS-1$
} }
result.append(qualifier.getStringValue()); result.append(qualifier.getStringValue());
} }
} }
@@ -377,12 +378,12 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
} }
return -1; return -1;
} }
// now we compare the qualifiers // now we compare the qualifiers
for (int i = 0 ; i < INDEX_COUNT; i++) { for (int i = 0 ; i < INDEX_COUNT; i++) {
ResourceQualifier qualifier1 = mQualifiers[i]; ResourceQualifier qualifier1 = mQualifiers[i];
ResourceQualifier qualifier2 = folderConfig.mQualifiers[i]; ResourceQualifier qualifier2 = folderConfig.mQualifiers[i];
if (qualifier1 == null) { if (qualifier1 == null) {
if (qualifier2 == null) { if (qualifier2 == null) {
continue; continue;
@@ -394,16 +395,16 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
return 1; return 1;
} else { } else {
int result = qualifier1.compareTo(qualifier2); int result = qualifier1.compareTo(qualifier2);
if (result == 0) { if (result == 0) {
continue; continue;
} }
return result; return result;
} }
} }
} }
// if we arrive here, all the qualifier matches // if we arrive here, all the qualifier matches
return 0; return 0;
} }
@@ -421,11 +422,11 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
*/ */
public int match(FolderConfiguration referenceConfig) { public int match(FolderConfiguration referenceConfig) {
int matchCount = 0; int matchCount = 0;
for (int i = 0 ; i < INDEX_COUNT ; i++) { for (int i = 0 ; i < INDEX_COUNT ; i++) {
ResourceQualifier testQualifier = mQualifiers[i]; ResourceQualifier testQualifier = mQualifiers[i];
ResourceQualifier referenceQualifier = referenceConfig.mQualifiers[i]; ResourceQualifier referenceQualifier = referenceConfig.mQualifiers[i];
// we only care if testQualifier is non null. If it's null, it's a match but // we only care if testQualifier is non null. If it's null, it's a match but
// without increasing the matchCount. // without increasing the matchCount.
if (testQualifier != null) { if (testQualifier != null) {
@@ -434,7 +435,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
} else if (testQualifier.equals(referenceQualifier) == false) { } else if (testQualifier.equals(referenceQualifier) == false) {
return -1; return -1;
} }
// the qualifier match, increment the count // the qualifier match, increment the count
matchCount++; matchCount++;
} }
@@ -454,10 +455,10 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
return i; return i;
} }
} }
return -1; return -1;
} }
/** /**
* Create default qualifiers. * Create default qualifiers.
*/ */
@@ -485,7 +486,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
count++; count++;
} }
} }
ResourceQualifier[] array = new ResourceQualifier[count]; ResourceQualifier[] array = new ResourceQualifier[count];
int index = 0; int index = 0;
for (int i = 0 ; i < INDEX_COUNT ; i++) { for (int i = 0 ; i < INDEX_COUNT ; i++) {
@@ -493,7 +494,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
array[index++] = mQualifiers[i]; array[index++] = mQualifiers[i];
} }
} }
return array; return array;
} }
} }

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;
@@ -26,7 +27,7 @@ import org.eclipse.swt.graphics.Image;
* Resource Qualifier for keyboard state. * Resource Qualifier for keyboard state.
*/ */
public final class KeyboardStateQualifier extends ResourceQualifier { public final class KeyboardStateQualifier extends ResourceQualifier {
public static final String NAME = "Keyboard State"; public static final String NAME = "Keyboard State";
private KeyboardState mValue = null; private KeyboardState mValue = null;
@@ -37,15 +38,15 @@ public final class KeyboardStateQualifier extends ResourceQualifier {
public static enum KeyboardState { public static enum KeyboardState {
EXPOSED("keysexposed", "Exposed"), //$NON-NLS-1$ EXPOSED("keysexposed", "Exposed"), //$NON-NLS-1$
HIDDEN("keyshidden", "Hidden"); //$NON-NLS-1$ HIDDEN("keyshidden", "Hidden"); //$NON-NLS-1$
private String mValue; private String mValue;
private String mDisplayValue; private String mDisplayValue;
private KeyboardState(String value, String displayValue) { private KeyboardState(String value, String displayValue) {
mValue = value; mValue = value;
mDisplayValue = displayValue; mDisplayValue = displayValue;
} }
/** /**
* Returns the enum for matching the provided qualifier value. * Returns the enum for matching the provided qualifier value.
* @param value The qualifier value. * @param value The qualifier value.
@@ -57,25 +58,25 @@ public final class KeyboardStateQualifier extends ResourceQualifier {
return orient; return orient;
} }
} }
return null; return null;
} }
public String getValue() { public String getValue() {
return mValue; return mValue;
} }
public String getDisplayValue() { public String getDisplayValue() {
return mDisplayValue; return mDisplayValue;
} }
public static int getIndex(KeyboardState value) { public static int getIndex(KeyboardState value) {
int i = 0; int i = 0;
for (KeyboardState input : values()) { for (KeyboardState input : values()) {
if (value == input) { if (value == input) {
return i; return i;
} }
i++; i++;
} }
@@ -105,27 +106,27 @@ public final class KeyboardStateQualifier extends ResourceQualifier {
public KeyboardState getValue() { public KeyboardState getValue() {
return mValue; return mValue;
} }
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override @Override
public String getShortName() { public String getShortName() {
return "Keyboard"; return "Keyboard";
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return IconFactory.getInstance().getIcon("keyboard"); //$NON-NLS-1$ return IconFactory.getInstance().getIcon("keyboard"); //$NON-NLS-1$
} }
@Override @Override
public boolean isValid() { public boolean isValid() {
return mValue != null; return mValue != null;
} }
@Override @Override
public boolean checkAndSet(String value, FolderConfiguration config) { public boolean checkAndSet(String value, FolderConfiguration config) {
KeyboardState orientation = KeyboardState.getEnum(value); KeyboardState orientation = KeyboardState.getEnum(value);
@@ -135,10 +136,10 @@ public final class KeyboardStateQualifier extends ResourceQualifier {
config.setKeyboardStateQualifier(qualifier); config.setKeyboardStateQualifier(qualifier);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public boolean equals(Object qualifier) { public boolean equals(Object qualifier) {
if (qualifier instanceof KeyboardStateQualifier) { if (qualifier instanceof KeyboardStateQualifier) {
@@ -153,19 +154,19 @@ public final class KeyboardStateQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.hashCode(); return mValue.hashCode();
} }
return 0; 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) {
if (mValue != null) { if (mValue != null) {
return mValue.getValue(); return mValue.getValue();
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
@@ -174,7 +175,7 @@ public final class KeyboardStateQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.getDisplayValue(); 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;
@@ -29,9 +30,9 @@ public final class LanguageQualifier extends ResourceQualifier {
private final static Pattern sLanguagePattern = Pattern.compile("^[a-z]{2}$"); //$NON-NLS-1$ private final static Pattern sLanguagePattern = Pattern.compile("^[a-z]{2}$"); //$NON-NLS-1$
public static final String NAME = "Language"; public static final String NAME = "Language";
private String mValue; private String mValue;
/** /**
* Creates and returns a qualifier from the given folder segment. If the segment is incorrect, * Creates and returns a qualifier from the given folder segment. If the segment is incorrect,
* <code>null</code> is returned. * <code>null</code> is returned.
@@ -42,12 +43,12 @@ public final class LanguageQualifier extends ResourceQualifier {
if (sLanguagePattern.matcher(segment).matches()) { if (sLanguagePattern.matcher(segment).matches()) {
LanguageQualifier qualifier = new LanguageQualifier(); LanguageQualifier qualifier = new LanguageQualifier();
qualifier.mValue = segment; qualifier.mValue = segment;
return qualifier; return qualifier;
} }
return null; return null;
} }
/** /**
* Returns the folder name segment for the given value. This is equivalent to calling * Returns the folder name segment for the given value. This is equivalent to calling
* {@link #toString()} on a {@link LanguageQualifier} object. * {@link #toString()} on a {@link LanguageQualifier} object.
@@ -58,7 +59,7 @@ public final class LanguageQualifier extends ResourceQualifier {
if (sLanguagePattern.matcher(segment).matches()) { if (sLanguagePattern.matcher(segment).matches()) {
return segment; return segment;
} }
return null; return null;
} }
@@ -66,25 +67,25 @@ public final class LanguageQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue; return mValue;
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override @Override
public String getShortName() { public String getShortName() {
return NAME; return NAME;
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return IconFactory.getInstance().getIcon("language"); //$NON-NLS-1$ return IconFactory.getInstance().getIcon("language"); //$NON-NLS-1$
} }
@Override @Override
public boolean isValid() { public boolean isValid() {
return mValue != null; return mValue != null;
@@ -97,10 +98,10 @@ public final class LanguageQualifier extends ResourceQualifier {
config.setLanguageQualifier(qualifier); config.setLanguageQualifier(qualifier);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public boolean equals(Object qualifier) { public boolean equals(Object qualifier) {
if (qualifier instanceof LanguageQualifier) { if (qualifier instanceof LanguageQualifier) {
@@ -109,7 +110,7 @@ public final class LanguageQualifier extends ResourceQualifier {
} }
return mValue.equals(((LanguageQualifier)qualifier).mValue); return mValue.equals(((LanguageQualifier)qualifier).mValue);
} }
return false; return false;
} }
@@ -118,15 +119,15 @@ public final class LanguageQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.hashCode(); return mValue.hashCode();
} }
return 0; 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) {
if (mValue != null) { if (mValue != null) {
return getFolderSegment(mValue); return getFolderSegment(mValue);
} }
@@ -139,7 +140,7 @@ public final class LanguageQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue; return mValue;
} }
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;
@@ -26,7 +27,7 @@ import org.eclipse.swt.graphics.Image;
* Resource Qualifier for Navigation Method. * Resource Qualifier for Navigation Method.
*/ */
public final class NavigationMethodQualifier extends ResourceQualifier { public final class NavigationMethodQualifier extends ResourceQualifier {
public static final String NAME = "Navigation Method"; public static final String NAME = "Navigation Method";
private NavigationMethod mValue; private NavigationMethod mValue;
@@ -39,15 +40,15 @@ public final class NavigationMethodQualifier extends ResourceQualifier {
TRACKBALL("trackball", "Trackball"), //$NON-NLS-1$ TRACKBALL("trackball", "Trackball"), //$NON-NLS-1$
WHEEL("wheel", "Wheel"), //$NON-NLS-1$ WHEEL("wheel", "Wheel"), //$NON-NLS-1$
NONAV("nonav", "No Navigation"); //$NON-NLS-1$ NONAV("nonav", "No Navigation"); //$NON-NLS-1$
private String mValue; private String mValue;
private String mDisplay; private String mDisplay;
private NavigationMethod(String value, String display) { private NavigationMethod(String value, String display) {
mValue = value; mValue = value;
mDisplay = display; mDisplay = display;
} }
/** /**
* Returns the enum for matching the provided qualifier value. * Returns the enum for matching the provided qualifier value.
* @param value The qualifier value. * @param value The qualifier value.
@@ -59,14 +60,14 @@ public final class NavigationMethodQualifier extends ResourceQualifier {
return orient; return orient;
} }
} }
return null; return null;
} }
public String getValue() { public String getValue() {
return mValue; return mValue;
} }
public String getDisplayValue() { public String getDisplayValue() {
return mDisplay; return mDisplay;
} }
@@ -77,7 +78,7 @@ public final class NavigationMethodQualifier extends ResourceQualifier {
if (nav == value) { if (nav == value) {
return i; return i;
} }
i++; i++;
} }
@@ -95,7 +96,7 @@ public final class NavigationMethodQualifier extends ResourceQualifier {
return null; return null;
} }
} }
public NavigationMethodQualifier() { public NavigationMethodQualifier() {
// pass // pass
} }
@@ -107,18 +108,18 @@ public final class NavigationMethodQualifier extends ResourceQualifier {
public NavigationMethod getValue() { public NavigationMethod getValue() {
return mValue; return mValue;
} }
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override @Override
public String getShortName() { public String getShortName() {
return "Navigation"; return "Navigation";
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return IconFactory.getInstance().getIcon("navpad"); //$NON-NLS-1$ return IconFactory.getInstance().getIcon("navpad"); //$NON-NLS-1$
@@ -138,16 +139,16 @@ public final class NavigationMethodQualifier extends ResourceQualifier {
config.setNavigationMethodQualifier(qualifier); config.setNavigationMethodQualifier(qualifier);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public boolean equals(Object qualifier) { public boolean equals(Object qualifier) {
if (qualifier instanceof NavigationMethodQualifier) { if (qualifier instanceof NavigationMethodQualifier) {
return mValue == ((NavigationMethodQualifier)qualifier).mValue; return mValue == ((NavigationMethodQualifier)qualifier).mValue;
} }
return false; return false;
} }
@@ -156,19 +157,19 @@ public final class NavigationMethodQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.hashCode(); return mValue.hashCode();
} }
return 0; 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) {
if (mValue != null) { if (mValue != null) {
return mValue.getValue(); return mValue.getValue();
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
@@ -177,7 +178,7 @@ public final class NavigationMethodQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.getDisplayValue(); 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;
@@ -33,9 +34,9 @@ public final class NetworkCodeQualifier extends ResourceQualifier {
private final static Pattern sNetworkCodePattern = Pattern.compile("^mnc(\\d{1,3})$"); //$NON-NLS-1$ private final static Pattern sNetworkCodePattern = Pattern.compile("^mnc(\\d{1,3})$"); //$NON-NLS-1$
private int mCode = DEFAULT_CODE; private int mCode = DEFAULT_CODE;
public final static String NAME = "Mobile Network Code"; public final static String NAME = "Mobile Network Code";
/** /**
* Creates and returns a qualifier from the given folder segment. If the segment is incorrect, * Creates and returns a qualifier from the given folder segment. If the segment is incorrect,
* <code>null</code> is returned. * <code>null</code> is returned.
@@ -54,7 +55,7 @@ public final class NetworkCodeQualifier extends ResourceQualifier {
// looks like the string we extracted wasn't a valid number. // looks like the string we extracted wasn't a valid number.
return null; return null;
} }
NetworkCodeQualifier qualifier = new NetworkCodeQualifier(); NetworkCodeQualifier qualifier = new NetworkCodeQualifier();
qualifier.mCode = code; qualifier.mCode = code;
return qualifier; return qualifier;
@@ -72,29 +73,29 @@ public final class NetworkCodeQualifier extends ResourceQualifier {
if (code != DEFAULT_CODE && code >= 1 && code <= 999) { // code is 1-3 digit. if (code != DEFAULT_CODE && code >= 1 && code <= 999) { // code is 1-3 digit.
return String.format("mnc%1$d", code); //$NON-NLS-1$ return String.format("mnc%1$d", code); //$NON-NLS-1$
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
public int getCode() { public int getCode() {
return mCode; return mCode;
} }
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override @Override
public String getShortName() { public String getShortName() {
return "Network Code"; return "Network Code";
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return IconFactory.getInstance().getIcon("mnc"); //$NON-NLS-1$ return IconFactory.getInstance().getIcon("mnc"); //$NON-NLS-1$
} }
@Override @Override
public boolean isValid() { public boolean isValid() {
return mCode != DEFAULT_CODE; return mCode != DEFAULT_CODE;
@@ -113,22 +114,22 @@ public final class NetworkCodeQualifier extends ResourceQualifier {
// looks like the string we extracted wasn't a valid number. // looks like the string we extracted wasn't a valid number.
return false; return false;
} }
NetworkCodeQualifier qualifier = new NetworkCodeQualifier(); NetworkCodeQualifier qualifier = new NetworkCodeQualifier();
qualifier.mCode = code; qualifier.mCode = code;
config.setNetworkCodeQualifier(qualifier); config.setNetworkCodeQualifier(qualifier);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public boolean equals(Object qualifier) { public boolean equals(Object qualifier) {
if (qualifier instanceof NetworkCodeQualifier) { if (qualifier instanceof NetworkCodeQualifier) {
return mCode == ((NetworkCodeQualifier)qualifier).mCode; return mCode == ((NetworkCodeQualifier)qualifier).mCode;
} }
return false; return false;
} }
@@ -136,12 +137,12 @@ public final class NetworkCodeQualifier extends ResourceQualifier {
public int hashCode() { public int hashCode() {
return mCode; return mCode;
} }
/** /**
* 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);
} }
@@ -150,7 +151,7 @@ public final class NetworkCodeQualifier extends ResourceQualifier {
if (mCode != DEFAULT_CODE) { if (mCode != DEFAULT_CODE) {
return String.format("MNC %1$d", mCode); return String.format("MNC %1$d", mCode);
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
} }

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,118 +29,202 @@ 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,
* <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) {
Matcher m = sPixelDensityPattern.matcher(folderSegment);
if (m.matches()) {
String v = m.group(1);
int density = -1; /**
try { * Screen Orientation enum.
density = Integer.parseInt(v); */
} catch (NumberFormatException e) { public static enum Density {
// looks like the string we extracted wasn't a valid number. HIGH("hdpi", 240, "High Density"), //$NON-NLS-1$
return null; 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;
}
} }
PixelDensityQualifier qualifier = new PixelDensityQualifier(); return null;
qualifier.mValue = density; }
return qualifier; static Density getLegacyEnum(String value) {
Matcher m = sDensityLegacyPattern.matcher(value);
if (m.matches()) {
String v = m.group(1);
try {
int density = Integer.parseInt(v);
for (Density orient : values()) {
if (orient.mDpiValue == density) {
return orient;
}
}
} catch (NumberFormatException e) {
// looks like the string we extracted wasn't a valid number
// which really shouldn't happen since the regexp would have failed.
}
}
return null;
}
public String getValue() {
return mValue;
}
public int getDpiValue() {
return mDpiValue;
}
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;
} }
return null;
} }
/** public PixelDensityQualifier() {
* Returns the folder name segment for the given value. This is equivalent to calling // pass
* {@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 getValue() { public PixelDensityQualifier(Density value) {
mValue = value;
}
public Density getValue() {
return mValue; return mValue;
} }
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override @Override
public String getShortName() { public String getShortName() {
return NAME; return NAME;
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return IconFactory.getInstance().getIcon("dpi"); //$NON-NLS-1$ return IconFactory.getInstance().getIcon("dpi"); //$NON-NLS-1$
} }
@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;
} }
return false; return false;
} }
@Override @Override
public boolean equals(Object qualifier) { public boolean equals(Object qualifier) {
if (qualifier instanceof PixelDensityQualifier) { if (qualifier instanceof PixelDensityQualifier) {
return mValue == ((PixelDensityQualifier)qualifier).mValue; return mValue == ((PixelDensityQualifier)qualifier).mValue;
} }
return false; return false;
} }
@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;
@@ -30,9 +31,9 @@ public final class RegionQualifier extends ResourceQualifier {
private final static Pattern sRegionPattern = Pattern.compile("^r([A-Z]{2})$"); //$NON-NLS-1$ private final static Pattern sRegionPattern = Pattern.compile("^r([A-Z]{2})$"); //$NON-NLS-1$
public static final String NAME = "Region"; public static final String NAME = "Region";
private String mValue; private String mValue;
/** /**
* Creates and returns a qualifier from the given folder segment. If the segment is incorrect, * Creates and returns a qualifier from the given folder segment. If the segment is incorrect,
* <code>null</code> is returned. * <code>null</code> is returned.
@@ -49,7 +50,7 @@ public final class RegionQualifier extends ResourceQualifier {
} }
return null; return null;
} }
/** /**
* Returns the folder name segment for the given value. This is equivalent to calling * Returns the folder name segment for the given value. This is equivalent to calling
* {@link #toString()} on a {@link RegionQualifier} object. * {@link #toString()} on a {@link RegionQualifier} object.
@@ -62,7 +63,7 @@ public final class RegionQualifier extends ResourceQualifier {
return segment; return segment;
} }
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
@@ -70,20 +71,20 @@ public final class RegionQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue; return mValue;
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override @Override
public String getShortName() { public String getShortName() {
return NAME; return NAME;
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return IconFactory.getInstance().getIcon("region"); //$NON-NLS-1$ return IconFactory.getInstance().getIcon("region"); //$NON-NLS-1$
@@ -101,10 +102,10 @@ public final class RegionQualifier extends ResourceQualifier {
config.setRegionQualifier(qualifier); config.setRegionQualifier(qualifier);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public boolean equals(Object qualifier) { public boolean equals(Object qualifier) {
if (qualifier instanceof RegionQualifier) { if (qualifier instanceof RegionQualifier) {
@@ -113,7 +114,7 @@ public final class RegionQualifier extends ResourceQualifier {
} }
return mValue.equals(((RegionQualifier)qualifier).mValue); return mValue.equals(((RegionQualifier)qualifier).mValue);
} }
return false; return false;
} }
@@ -122,15 +123,15 @@ public final class RegionQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.hashCode(); return mValue.hashCode();
} }
return 0; 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); return getFolderSegment(mValue);
} }
@@ -139,7 +140,7 @@ public final class RegionQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue; return mValue;
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
} }

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;
/** /**
@@ -23,28 +25,28 @@ import org.eclipse.swt.graphics.Image;
* <p/>The resource qualifier classes are designed as immutable. * <p/>The resource qualifier classes are designed as immutable.
*/ */
public abstract class ResourceQualifier implements Comparable<ResourceQualifier> { public abstract class ResourceQualifier implements Comparable<ResourceQualifier> {
/** /**
* Returns the human readable name of the qualifier. * Returns the human readable name of the qualifier.
*/ */
public abstract String getName(); public abstract String getName();
/** /**
* Returns a shorter human readable name for the qualifier. * Returns a shorter human readable name for the qualifier.
* @see #getName() * @see #getName()
*/ */
public abstract String getShortName(); public abstract String getShortName();
/** /**
* Returns the icon for the qualifier. * Returns the icon for the qualifier.
*/ */
public abstract Image getIcon(); public abstract Image getIcon();
/** /**
* Returns whether the qualifier has a valid filter value. * Returns whether the qualifier has a valid filter value.
*/ */
public abstract boolean isValid(); public abstract boolean isValid();
/** /**
* Check if the value is valid for this qualifier, and if so sets the value * Check if the value is valid for this qualifier, and if so sets the value
* into a Folder Configuration. * into a Folder Configuration.
@@ -53,13 +55,17 @@ public abstract class ResourceQualifier implements Comparable<ResourceQualifier>
* @return true if the value was valid and was set. * @return true if the value was valid and was set.
*/ */
public abstract boolean checkAndSet(String value, FolderConfiguration config); public abstract boolean checkAndSet(String value, FolderConfiguration config);
/** /**
* 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.
@@ -72,7 +78,7 @@ public abstract class ResourceQualifier implements Comparable<ResourceQualifier>
*/ */
@Override @Override
public abstract boolean equals(Object object); public abstract boolean equals(Object object);
/** /**
* Returns a hash code value for the object. * Returns a hash code value for the object.
* <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.

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;
@@ -46,7 +47,7 @@ public final class ScreenDimensionQualifier extends ResourceQualifier {
* 200 but that'll be Y in landscape and X in portrait. * 200 but that'll be Y in landscape and X in portrait.
* Default value is <code>DEFAULT_SIZE</code> */ * Default value is <code>DEFAULT_SIZE</code> */
private int mValue2 = DEFAULT_SIZE; private int mValue2 = DEFAULT_SIZE;
public int getValue1() { public int getValue1() {
return mValue1; return mValue1;
} }
@@ -54,17 +55,17 @@ public final class ScreenDimensionQualifier extends ResourceQualifier {
public int getValue2() { public int getValue2() {
return mValue2; return mValue2;
} }
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override @Override
public String getShortName() { public String getShortName() {
return "Dimension"; return "Dimension";
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return IconFactory.getInstance().getIcon("dimension"); //$NON-NLS-1$ return IconFactory.getInstance().getIcon("dimension"); //$NON-NLS-1$
@@ -81,7 +82,7 @@ public final class ScreenDimensionQualifier extends ResourceQualifier {
if (m.matches()) { if (m.matches()) {
String d1 = m.group(1); String d1 = m.group(1);
String d2 = m.group(2); String d2 = m.group(2);
ScreenDimensionQualifier qualifier = getQualifier(d1, d2); ScreenDimensionQualifier qualifier = getQualifier(d1, d2);
if (qualifier != null) { if (qualifier != null) {
config.setScreenDimensionQualifier(qualifier); config.setScreenDimensionQualifier(qualifier);
@@ -90,14 +91,14 @@ public final class ScreenDimensionQualifier extends ResourceQualifier {
} }
return false; return false;
} }
@Override @Override
public boolean equals(Object qualifier) { public boolean equals(Object qualifier) {
if (qualifier instanceof ScreenDimensionQualifier) { if (qualifier instanceof ScreenDimensionQualifier) {
ScreenDimensionQualifier q = (ScreenDimensionQualifier)qualifier; ScreenDimensionQualifier q = (ScreenDimensionQualifier)qualifier;
return (mValue1 == q.mValue1 && mValue2 == q.mValue2); return (mValue1 == q.mValue1 && mValue2 == q.mValue2);
} }
return false; return false;
} }
@@ -105,12 +106,12 @@ public final class ScreenDimensionQualifier extends ResourceQualifier {
public int hashCode() { public int hashCode() {
return toString().hashCode(); return toString().hashCode();
} }
public static ScreenDimensionQualifier getQualifier(String size1, String size2) { public static ScreenDimensionQualifier getQualifier(String size1, String size2) {
try { try {
int s1 = Integer.parseInt(size1); int s1 = Integer.parseInt(size1);
int s2 = Integer.parseInt(size2); int s2 = Integer.parseInt(size2);
ScreenDimensionQualifier qualifier = new ScreenDimensionQualifier(); ScreenDimensionQualifier qualifier = new ScreenDimensionQualifier();
if (s1 > s2) { if (s1 > s2) {
@@ -125,7 +126,7 @@ public final class ScreenDimensionQualifier extends ResourceQualifier {
} 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; return null;
} }
@@ -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$
} }
@@ -142,7 +143,7 @@ public final class ScreenDimensionQualifier extends ResourceQualifier {
if (mValue1 != -1 && mValue2 != -1) { if (mValue1 != -1 && mValue2 != -1) {
return String.format("%1$dx%2$d", mValue1, mValue2); return String.format("%1$dx%2$d", mValue1, mValue2);
} }
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;
@@ -24,7 +25,7 @@ import org.eclipse.swt.graphics.Image;
* Resource Qualifier for Screen Orientation. * Resource Qualifier for Screen Orientation.
*/ */
public final class ScreenOrientationQualifier extends ResourceQualifier { public final class ScreenOrientationQualifier extends ResourceQualifier {
public static final String NAME = "Screen Orientation"; public static final String NAME = "Screen Orientation";
private ScreenOrientation mValue = null; private ScreenOrientation mValue = null;
@@ -36,15 +37,15 @@ public final class ScreenOrientationQualifier extends ResourceQualifier {
PORTRAIT("port", "Portrait"), //$NON-NLS-1$ PORTRAIT("port", "Portrait"), //$NON-NLS-1$
LANDSCAPE("land", "Landscape"), //$NON-NLS-1$ LANDSCAPE("land", "Landscape"), //$NON-NLS-1$
SQUARE("square", "Square"); //$NON-NLS-1$ SQUARE("square", "Square"); //$NON-NLS-1$
private String mValue; private String mValue;
private String mDisplayValue; private String mDisplayValue;
private ScreenOrientation(String value, String displayValue) { private ScreenOrientation(String value, String displayValue) {
mValue = value; mValue = value;
mDisplayValue = displayValue; mDisplayValue = displayValue;
} }
/** /**
* Returns the enum for matching the provided qualifier value. * Returns the enum for matching the provided qualifier value.
* @param value The qualifier value. * @param value The qualifier value.
@@ -63,18 +64,18 @@ public final class ScreenOrientationQualifier extends ResourceQualifier {
public String getValue() { public String getValue() {
return mValue; return mValue;
} }
public String getDisplayValue() { public String getDisplayValue() {
return mDisplayValue; return mDisplayValue;
} }
public static int getIndex(ScreenOrientation orientation) { public static int getIndex(ScreenOrientation orientation) {
int i = 0; int i = 0;
for (ScreenOrientation orient : values()) { for (ScreenOrientation orient : values()) {
if (orient == orientation) { if (orient == orientation) {
return i; return i;
} }
i++; i++;
} }
@@ -104,22 +105,22 @@ public final class ScreenOrientationQualifier extends ResourceQualifier {
public ScreenOrientation getValue() { public ScreenOrientation getValue() {
return mValue; return mValue;
} }
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override @Override
public String getShortName() { public String getShortName() {
return "Orientation"; return "Orientation";
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return IconFactory.getInstance().getIcon("orientation"); //$NON-NLS-1$ return IconFactory.getInstance().getIcon("orientation"); //$NON-NLS-1$
} }
@Override @Override
public boolean isValid() { public boolean isValid() {
return mValue != null; return mValue != null;
@@ -133,10 +134,10 @@ public final class ScreenOrientationQualifier extends ResourceQualifier {
config.setScreenOrientationQualifier(qualifier); config.setScreenOrientationQualifier(qualifier);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public boolean equals(Object qualifier) { public boolean equals(Object qualifier) {
if (qualifier instanceof ScreenOrientationQualifier) { if (qualifier instanceof ScreenOrientationQualifier) {
@@ -151,19 +152,19 @@ public final class ScreenOrientationQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.hashCode(); return mValue.hashCode();
} }
return 0; 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) {
if (mValue != null) { if (mValue != null) {
return mValue.getValue(); return mValue.getValue();
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
@@ -172,7 +173,7 @@ public final class ScreenOrientationQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.getDisplayValue(); 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;
@@ -31,7 +32,7 @@ public final class TextInputMethodQualifier extends ResourceQualifier {
public static final String NAME = "Text Input Method"; public static final String NAME = "Text Input Method";
private TextInputMethod mValue; private TextInputMethod mValue;
/** /**
* Screen Orientation enum. * Screen Orientation enum.
*/ */
@@ -39,15 +40,15 @@ public final class TextInputMethodQualifier extends ResourceQualifier {
NOKEY("nokeys", "No Keys"), //$NON-NLS-1$ NOKEY("nokeys", "No Keys"), //$NON-NLS-1$
QWERTY("qwerty", "Qwerty"), //$NON-NLS-1$ QWERTY("qwerty", "Qwerty"), //$NON-NLS-1$
TWELVEKEYS("12key", "12 Key"); //$NON-NLS-1$ TWELVEKEYS("12key", "12 Key"); //$NON-NLS-1$
private String mValue; private String mValue;
private String mDisplayValue; private String mDisplayValue;
private TextInputMethod(String value, String displayValue) { private TextInputMethod(String value, String displayValue) {
mValue = value; mValue = value;
mDisplayValue = displayValue; mDisplayValue = displayValue;
} }
/** /**
* Returns the enum for matching the provided qualifier value. * Returns the enum for matching the provided qualifier value.
* @param value The qualifier value. * @param value The qualifier value.
@@ -59,14 +60,14 @@ public final class TextInputMethodQualifier extends ResourceQualifier {
return orient; return orient;
} }
} }
return null; return null;
} }
public String getValue() { public String getValue() {
return mValue; return mValue;
} }
public String getDisplayValue() { public String getDisplayValue() {
return mDisplayValue; return mDisplayValue;
} }
@@ -77,7 +78,7 @@ public final class TextInputMethodQualifier extends ResourceQualifier {
if (value == input) { if (value == input) {
return i; return i;
} }
i++; i++;
} }
@@ -95,7 +96,7 @@ public final class TextInputMethodQualifier extends ResourceQualifier {
return null; return null;
} }
} }
public TextInputMethodQualifier() { public TextInputMethodQualifier() {
// pass // pass
} }
@@ -107,17 +108,17 @@ public final class TextInputMethodQualifier extends ResourceQualifier {
public TextInputMethod getValue() { public TextInputMethod getValue() {
return mValue; return mValue;
} }
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override @Override
public String getShortName() { public String getShortName() {
return "Text Input"; return "Text Input";
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return IconFactory.getInstance().getIcon("text_input"); //$NON-NLS-1$ return IconFactory.getInstance().getIcon("text_input"); //$NON-NLS-1$
@@ -137,10 +138,10 @@ public final class TextInputMethodQualifier extends ResourceQualifier {
config.setTextInputMethodQualifier(qualifier); config.setTextInputMethodQualifier(qualifier);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public boolean equals(Object qualifier) { public boolean equals(Object qualifier) {
if (qualifier instanceof TextInputMethodQualifier) { if (qualifier instanceof TextInputMethodQualifier) {
@@ -155,7 +156,7 @@ public final class TextInputMethodQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.hashCode(); return mValue.hashCode();
} }
return 0; return 0;
} }
@@ -163,11 +164,11 @@ 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();
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
@@ -176,7 +177,7 @@ public final class TextInputMethodQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.getDisplayValue(); 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;
@@ -29,7 +30,7 @@ public final class TouchScreenQualifier extends ResourceQualifier {
public static final String NAME = "Touch Screen"; public static final String NAME = "Touch Screen";
private TouchScreenType mValue; private TouchScreenType mValue;
/** /**
* Screen Orientation enum. * Screen Orientation enum.
*/ */
@@ -37,15 +38,15 @@ public final class TouchScreenQualifier extends ResourceQualifier {
NOTOUCH("notouch", "No Touch"), //$NON-NLS-1$ NOTOUCH("notouch", "No Touch"), //$NON-NLS-1$
STYLUS("stylus", "Stylus"), //$NON-NLS-1$ STYLUS("stylus", "Stylus"), //$NON-NLS-1$
FINGER("finger", "Finger"); //$NON-NLS-1$ FINGER("finger", "Finger"); //$NON-NLS-1$
private String mValue; private String mValue;
private String mDisplayValue; private String mDisplayValue;
private TouchScreenType(String value, String displayValue) { private TouchScreenType(String value, String displayValue) {
mValue = value; mValue = value;
mDisplayValue = displayValue; mDisplayValue = displayValue;
} }
/** /**
* Returns the enum for matching the provided qualifier value. * Returns the enum for matching the provided qualifier value.
* @param value The qualifier value. * @param value The qualifier value.
@@ -57,14 +58,14 @@ public final class TouchScreenQualifier extends ResourceQualifier {
return orient; return orient;
} }
} }
return null; return null;
} }
public String getValue() { public String getValue() {
return mValue; return mValue;
} }
public String getDisplayValue() { public String getDisplayValue() {
return mDisplayValue; return mDisplayValue;
} }
@@ -75,7 +76,7 @@ public final class TouchScreenQualifier extends ResourceQualifier {
if (t == touch) { if (t == touch) {
return i; return i;
} }
i++; i++;
} }
@@ -94,7 +95,7 @@ public final class TouchScreenQualifier extends ResourceQualifier {
return null; return null;
} }
} }
public TouchScreenQualifier() { public TouchScreenQualifier() {
// pass // pass
} }
@@ -106,17 +107,17 @@ public final class TouchScreenQualifier extends ResourceQualifier {
public TouchScreenType getValue() { public TouchScreenType getValue() {
return mValue; return mValue;
} }
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override @Override
public String getShortName() { public String getShortName() {
return NAME; return NAME;
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return IconFactory.getInstance().getIcon("touch"); //$NON-NLS-1$ return IconFactory.getInstance().getIcon("touch"); //$NON-NLS-1$
@@ -136,10 +137,10 @@ public final class TouchScreenQualifier extends ResourceQualifier {
config.setTouchTypeQualifier(qualifier); config.setTouchTypeQualifier(qualifier);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public boolean equals(Object qualifier) { public boolean equals(Object qualifier) {
if (qualifier instanceof TouchScreenQualifier) { if (qualifier instanceof TouchScreenQualifier) {
@@ -153,7 +154,7 @@ public final class TouchScreenQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.hashCode(); return mValue.hashCode();
} }
return 0; return 0;
} }
@@ -161,11 +162,11 @@ 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();
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
@@ -174,7 +175,7 @@ public final class TouchScreenQualifier extends ResourceQualifier {
if (mValue != null) { if (mValue != null) {
return mValue.getDisplayValue(); return mValue.getDisplayValue();
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
} }

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;
@@ -80,13 +81,13 @@ import java.util.HashMap;
* <ul> * <ul>
* <li>Use {@link #setConfiguration(String)} or {@link #setConfiguration(FolderConfiguration)}. * <li>Use {@link #setConfiguration(String)} or {@link #setConfiguration(FolderConfiguration)}.
* <li>Retrieve the configuration using {@link #getConfiguration(FolderConfiguration)}. * <li>Retrieve the configuration using {@link #getConfiguration(FolderConfiguration)}.
* </ul> * </ul>
*/ */
public class ConfigurationSelector extends Composite { public class ConfigurationSelector extends Composite {
public static final int WIDTH_HINT = 600; public static final int WIDTH_HINT = 600;
public static final int HEIGHT_HINT = 250; public static final int HEIGHT_HINT = 250;
private Runnable mOnChangeListener; private Runnable mOnChangeListener;
private TableViewer mFullTableViewer; private TableViewer mFullTableViewer;
@@ -94,16 +95,16 @@ public class ConfigurationSelector extends Composite {
private Button mAddButton; private Button mAddButton;
private Button mRemoveButton; private Button mRemoveButton;
private StackLayout mStackLayout; private StackLayout mStackLayout;
private boolean mOnRefresh = false; private boolean mOnRefresh = false;
private final FolderConfiguration mBaseConfiguration = new FolderConfiguration(); private final FolderConfiguration mBaseConfiguration = new FolderConfiguration();
private final FolderConfiguration mSelectedConfiguration = new FolderConfiguration(); private final FolderConfiguration mSelectedConfiguration = new FolderConfiguration();
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 Composite mQualifierEditParent; private Composite mQualifierEditParent;
/** /**
* Basic of {@link VerifyListener} to only accept digits. * Basic of {@link VerifyListener} to only accept digits.
*/ */
@@ -119,7 +120,7 @@ public class ConfigurationSelector extends Composite {
} }
} }
} }
/** /**
* Implementation of {@link VerifyListener} for Country Code qualifiers. * Implementation of {@link VerifyListener} for Country Code qualifiers.
*/ */
@@ -138,7 +139,7 @@ public class ConfigurationSelector extends Composite {
} }
} }
} }
/** /**
* Implementation of {@link VerifyListener} for the Language and Region qualifiers. * Implementation of {@link VerifyListener} for the Language and Region qualifiers.
*/ */
@@ -149,7 +150,7 @@ public class ConfigurationSelector extends Composite {
e.doit = false; e.doit = false;
return; return;
} }
// check for lower case only. // check for lower case only.
for (int i = 0 ; i < e.text.length(); i++) { for (int i = 0 ; i < e.text.length(); i++) {
char letter = e.text.charAt(i); char letter = e.text.charAt(i);
@@ -160,17 +161,17 @@ public class ConfigurationSelector extends Composite {
} }
} }
} }
/** /**
* Implementation of {@link VerifyListener} for the Pixel Density qualifier. * Implementation of {@link VerifyListener} for the Pixel Density qualifier.
*/ */
public static class DensityVerifier extends DigitVerifier { } public static class DensityVerifier extends DigitVerifier { }
/** /**
* Implementation of {@link VerifyListener} for the Screen Dimension qualifier. * Implementation of {@link VerifyListener} for the Screen Dimension qualifier.
*/ */
public static class DimensionVerifier extends DigitVerifier { } public static class DimensionVerifier extends DigitVerifier { }
/** /**
* Enum for the state of the configuration being created. * Enum for the state of the configuration being created.
*/ */
@@ -186,18 +187,18 @@ public class ConfigurationSelector extends Composite {
GridLayout gl = new GridLayout(4, false); GridLayout gl = new GridLayout(4, false);
gl.marginWidth = gl.marginHeight = 0; gl.marginWidth = gl.marginHeight = 0;
setLayout(gl); setLayout(gl);
// first column is the first table // first column is the first table
final Table fullTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); final Table fullTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
fullTable.setLayoutData(new GridData(GridData.FILL_BOTH)); fullTable.setLayoutData(new GridData(GridData.FILL_BOTH));
fullTable.setHeaderVisible(true); fullTable.setHeaderVisible(true);
fullTable.setLinesVisible(true); fullTable.setLinesVisible(true);
// create the column // create the column
final TableColumn fullTableColumn = new TableColumn(fullTable, SWT.LEFT); final TableColumn fullTableColumn = new TableColumn(fullTable, SWT.LEFT);
// set the header // set the header
fullTableColumn.setText("Available Qualifiers"); fullTableColumn.setText("Available Qualifiers");
fullTable.addControlListener(new ControlAdapter() { fullTable.addControlListener(new ControlAdapter() {
@Override @Override
public void controlResized(ControlEvent e) { public void controlResized(ControlEvent e) {
@@ -217,24 +218,24 @@ public class ConfigurationSelector extends Composite {
if (selection instanceof IStructuredSelection) { if (selection instanceof IStructuredSelection) {
IStructuredSelection structSelection = (IStructuredSelection)selection; IStructuredSelection structSelection = (IStructuredSelection)selection;
Object first = structSelection.getFirstElement(); Object first = structSelection.getFirstElement();
if (first instanceof ResourceQualifier) { if (first instanceof ResourceQualifier) {
mAddButton.setEnabled(true); mAddButton.setEnabled(true);
return; return;
} }
} }
mAddButton.setEnabled(false); mAddButton.setEnabled(false);
} }
}); });
// 2nd column is the left/right arrow button // 2nd column is the left/right arrow button
Composite buttonComposite = new Composite(this, SWT.NONE); Composite buttonComposite = new Composite(this, SWT.NONE);
gl = new GridLayout(1, false); gl = new GridLayout(1, false);
gl.marginWidth = gl.marginHeight = 0; gl.marginWidth = gl.marginHeight = 0;
buttonComposite.setLayout(gl); buttonComposite.setLayout(gl);
buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
new Composite(buttonComposite, SWT.NONE); new Composite(buttonComposite, SWT.NONE);
mAddButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH); mAddButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH);
mAddButton.setText("->"); mAddButton.setText("->");
@@ -242,20 +243,20 @@ public class ConfigurationSelector extends Composite {
mAddButton.addSelectionListener(new SelectionAdapter() { mAddButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = IStructuredSelection selection =
(IStructuredSelection)mFullTableViewer.getSelection(); (IStructuredSelection)mFullTableViewer.getSelection();
Object first = selection.getFirstElement(); Object first = selection.getFirstElement();
if (first instanceof ResourceQualifier) { if (first instanceof ResourceQualifier) {
ResourceQualifier qualifier = (ResourceQualifier)first; ResourceQualifier qualifier = (ResourceQualifier)first;
mBaseConfiguration.removeQualifier(qualifier); mBaseConfiguration.removeQualifier(qualifier);
mSelectedConfiguration.addQualifier(qualifier); mSelectedConfiguration.addQualifier(qualifier);
mFullTableViewer.refresh(); mFullTableViewer.refresh();
mSelectionTableViewer.refresh(); mSelectionTableViewer.refresh();
mSelectionTableViewer.setSelection(new StructuredSelection(qualifier), true); mSelectionTableViewer.setSelection(new StructuredSelection(qualifier), true);
onChange(false /* keepSelection */); onChange(false /* keepSelection */);
} }
} }
@@ -267,19 +268,19 @@ public class ConfigurationSelector extends Composite {
mRemoveButton.addSelectionListener(new SelectionAdapter() { mRemoveButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = IStructuredSelection selection =
(IStructuredSelection)mSelectionTableViewer.getSelection(); (IStructuredSelection)mSelectionTableViewer.getSelection();
Object first = selection.getFirstElement(); Object first = selection.getFirstElement();
if (first instanceof ResourceQualifier) { if (first instanceof ResourceQualifier) {
ResourceQualifier qualifier = (ResourceQualifier)first; ResourceQualifier qualifier = (ResourceQualifier)first;
mSelectedConfiguration.removeQualifier(qualifier); mSelectedConfiguration.removeQualifier(qualifier);
mBaseConfiguration.addQualifier(qualifier); mBaseConfiguration.addQualifier(qualifier);
mFullTableViewer.refresh(); mFullTableViewer.refresh();
mSelectionTableViewer.refresh(); mSelectionTableViewer.refresh();
onChange(false /* keepSelection */); onChange(false /* keepSelection */);
} }
} }
@@ -290,12 +291,12 @@ public class ConfigurationSelector extends Composite {
selectionTable.setLayoutData(new GridData(GridData.FILL_BOTH)); selectionTable.setLayoutData(new GridData(GridData.FILL_BOTH));
selectionTable.setHeaderVisible(true); selectionTable.setHeaderVisible(true);
selectionTable.setLinesVisible(true); selectionTable.setLinesVisible(true);
// create the column // create the column
final TableColumn selectionTableColumn = new TableColumn(selectionTable, SWT.LEFT); final TableColumn selectionTableColumn = new TableColumn(selectionTable, SWT.LEFT);
// set the header // set the header
selectionTableColumn.setText("Chosen Qualifiers"); selectionTableColumn.setText("Chosen Qualifiers");
selectionTable.addControlListener(new ControlAdapter() { selectionTable.addControlListener(new ControlAdapter() {
@Override @Override
public void controlResized(ControlEvent e) { public void controlResized(ControlEvent e) {
@@ -318,22 +319,22 @@ public class ConfigurationSelector extends Composite {
ISelection selection = event.getSelection(); ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) { if (selection instanceof IStructuredSelection) {
IStructuredSelection structSelection = (IStructuredSelection)selection; IStructuredSelection structSelection = (IStructuredSelection)selection;
if (structSelection.isEmpty() == false) { if (structSelection.isEmpty() == false) {
Object first = structSelection.getFirstElement(); Object first = structSelection.getFirstElement();
if (first instanceof ResourceQualifier) { if (first instanceof ResourceQualifier) {
mRemoveButton.setEnabled(true); mRemoveButton.setEnabled(true);
QualifierEditBase composite = mUiMap.get(first.getClass()); QualifierEditBase composite = mUiMap.get(first.getClass());
if (composite != null) { if (composite != null) {
composite.setQualifier((ResourceQualifier)first); composite.setQualifier((ResourceQualifier)first);
} }
mStackLayout.topControl = composite; mStackLayout.topControl = composite;
mQualifierEditParent.layout(); mQualifierEditParent.layout();
return; return;
} }
} else { } else {
@@ -341,16 +342,16 @@ public class ConfigurationSelector extends Composite {
mQualifierEditParent.layout(); mQualifierEditParent.layout();
} }
} }
mRemoveButton.setEnabled(false); mRemoveButton.setEnabled(false);
} }
}); });
// 4th column is the detail of the selected qualifier // 4th column is the detail of the selected qualifier
mQualifierEditParent = new Composite(this, SWT.NONE); mQualifierEditParent = new Composite(this, SWT.NONE);
mQualifierEditParent.setLayout(mStackLayout = new StackLayout()); mQualifierEditParent.setLayout(mStackLayout = new StackLayout());
mQualifierEditParent.setLayoutData(new GridData(GridData.FILL_VERTICAL)); mQualifierEditParent.setLayoutData(new GridData(GridData.FILL_VERTICAL));
// create the UI for all the qualifiers, and associate them to the ResourceQualifer class. // create the UI for all the qualifiers, and associate them to the ResourceQualifer class.
mUiMap.put(CountryCodeQualifier.class, new MCCEdit(mQualifierEditParent)); mUiMap.put(CountryCodeQualifier.class, new MCCEdit(mQualifierEditParent));
mUiMap.put(NetworkCodeQualifier.class, new MNCEdit(mQualifierEditParent)); mUiMap.put(NetworkCodeQualifier.class, new MNCEdit(mQualifierEditParent));
@@ -364,7 +365,7 @@ public class ConfigurationSelector extends Composite {
mUiMap.put(NavigationMethodQualifier.class, new NavigationEdit(mQualifierEditParent)); mUiMap.put(NavigationMethodQualifier.class, new NavigationEdit(mQualifierEditParent));
mUiMap.put(ScreenDimensionQualifier.class, new ScreenDimensionEdit(mQualifierEditParent)); mUiMap.put(ScreenDimensionQualifier.class, new ScreenDimensionEdit(mQualifierEditParent));
} }
/** /**
* Sets a listener to be notified when the configuration changes. * Sets a listener to be notified when the configuration changes.
* @param listener A {@link Runnable} whose <code>run()</code> method is called when the * @param listener A {@link Runnable} whose <code>run()</code> method is called when the
@@ -373,7 +374,7 @@ public class ConfigurationSelector extends Composite {
public void setOnChangeListener(Runnable listener) { public void setOnChangeListener(Runnable listener) {
mOnChangeListener = listener; mOnChangeListener = listener;
} }
/** /**
* Initialize the UI with a given {@link FolderConfiguration}. This must * Initialize the UI with a given {@link FolderConfiguration}. This must
* be called from the UI thread. * be called from the UI thread.
@@ -382,24 +383,24 @@ public class ConfigurationSelector extends Composite {
public void setConfiguration(FolderConfiguration config) { public void setConfiguration(FolderConfiguration config) {
mSelectedConfiguration.set(config); mSelectedConfiguration.set(config);
mSelectionTableViewer.refresh(); mSelectionTableViewer.refresh();
// create the base config, which is the default config minus the qualifiers // create the base config, which is the default config minus the qualifiers
// in SelectedConfiguration // in SelectedConfiguration
mBaseConfiguration.substract(mSelectedConfiguration); mBaseConfiguration.substract(mSelectedConfiguration);
mFullTableViewer.refresh(); mFullTableViewer.refresh();
} }
/** /**
* Initialize the UI with the configuration represented by a resource folder name. * Initialize the UI with the configuration represented by a resource folder name.
* This must be called from the UI thread. * This must be called from the UI thread.
* *
* @param folderSegments the segments of the folder name, * @param folderSegments the segments of the folder name,
* split using {@link FolderConfiguration#QUALIFIER_SEP}. * split using {@link FolderConfiguration#QUALIFIER_SEP}.
* @return true if success, or false if the folder name is not a valid name. * @return true if success, or false if the folder name is not a valid name.
*/ */
public boolean setConfiguration(String[] folderSegments) { public boolean setConfiguration(String[] folderSegments) {
FolderConfiguration config = ResourceManager.getInstance().getConfig(folderSegments); FolderConfiguration config = ResourceManager.getInstance().getConfig(folderSegments);
if (config == null) { if (config == null) {
return false; return false;
} }
@@ -408,7 +409,7 @@ public class ConfigurationSelector extends Composite {
return true; return true;
} }
/** /**
* Initialize the UI with the configuration represented by a resource folder name. * Initialize the UI with the configuration represented by a resource folder name.
* This must be called from the UI thread. * This must be called from the UI thread.
@@ -421,7 +422,7 @@ public class ConfigurationSelector extends Composite {
return setConfiguration(folderSegments); return setConfiguration(folderSegments);
} }
/** /**
* Gets the configuration as setup by the widget. * Gets the configuration as setup by the widget.
* @param config the {@link FolderConfiguration} object to be filled with the information * @param config the {@link FolderConfiguration} object to be filled with the information
@@ -430,7 +431,7 @@ public class ConfigurationSelector extends Composite {
public void getConfiguration(FolderConfiguration config) { public void getConfiguration(FolderConfiguration config) {
config.set(mSelectedConfiguration); config.set(mSelectedConfiguration);
} }
/** /**
* Returns the state of the configuration being edited/created. * Returns the state of the configuration being edited/created.
*/ */
@@ -438,14 +439,14 @@ public class ConfigurationSelector extends Composite {
if (mSelectedConfiguration.getInvalidQualifier() != null) { if (mSelectedConfiguration.getInvalidQualifier() != null) {
return ConfigurationState.INVALID_CONFIG; return ConfigurationState.INVALID_CONFIG;
} }
if (mSelectedConfiguration.checkRegion() == false) { if (mSelectedConfiguration.checkRegion() == false) {
return ConfigurationState.REGION_WITHOUT_LANGUAGE; return ConfigurationState.REGION_WITHOUT_LANGUAGE;
} }
return ConfigurationState.OK; return ConfigurationState.OK;
} }
/** /**
* Returns the first invalid qualifier of the configuration being edited/created, * Returns the first invalid qualifier of the configuration being edited/created,
* or <code>null<code> if they are all valid (or if none exists). * or <code>null<code> if they are all valid (or if none exists).
@@ -469,7 +470,7 @@ public class ConfigurationSelector extends Composite {
} }
mSelectionTableViewer.refresh(true); mSelectionTableViewer.refresh(true);
if (keepSelection) { if (keepSelection) {
mSelectionTableViewer.setSelection(selection); mSelectionTableViewer.setSelection(selection);
mOnRefresh = false; mOnRefresh = false;
@@ -479,12 +480,12 @@ public class ConfigurationSelector extends Composite {
mOnChangeListener.run(); mOnChangeListener.run();
} }
} }
/** /**
* Content provider around a {@link FolderConfiguration}. * Content provider around a {@link FolderConfiguration}.
*/ */
private static class QualifierContentProvider implements IStructuredContentProvider { private static class QualifierContentProvider implements IStructuredContentProvider {
private FolderConfiguration mInput; private FolderConfiguration mInput;
public QualifierContentProvider() { public QualifierContentProvider() {
@@ -505,12 +506,12 @@ public class ConfigurationSelector extends Composite {
} }
} }
} }
/** /**
* Label provider for {@link ResourceQualifier} objects. * Label provider for {@link ResourceQualifier} objects.
*/ */
private static class QualifierLabelProvider implements ITableLabelProvider { private static class QualifierLabelProvider implements ITableLabelProvider {
private final boolean mShowQualifierValue; private final boolean mShowQualifierValue;
public QualifierLabelProvider(boolean showQualifierValue) { public QualifierLabelProvider(boolean showQualifierValue) {
@@ -528,7 +529,7 @@ public class ConfigurationSelector extends Composite {
} else { } else {
return value; return value;
} }
} else { } else {
return ((ResourceQualifier)element).getShortName(); return ((ResourceQualifier)element).getShortName();
} }
@@ -536,7 +537,7 @@ public class ConfigurationSelector extends Composite {
return null; return null;
} }
public Image getColumnImage(Object element, int columnIndex) { public Image getColumnImage(Object element, int columnIndex) {
// only one column, so we can ignore columnIndex // only one column, so we can ignore columnIndex
if (element instanceof ResourceQualifier) { if (element instanceof ResourceQualifier) {
@@ -563,7 +564,7 @@ public class ConfigurationSelector extends Composite {
// pass // pass
} }
} }
/** /**
* Base class for Edit widget for {@link ResourceQualifier}. * Base class for Edit widget for {@link ResourceQualifier}.
*/ */
@@ -575,10 +576,10 @@ public class ConfigurationSelector extends Composite {
new Label(this, SWT.NONE).setText(title); new Label(this, SWT.NONE).setText(title);
} }
public abstract void setQualifier(ResourceQualifier qualifier); public abstract void setQualifier(ResourceQualifier qualifier);
} }
/** /**
* Edit widget for {@link CountryCodeQualifier}. * Edit widget for {@link CountryCodeQualifier}.
*/ */
@@ -588,13 +589,13 @@ public class ConfigurationSelector extends Composite {
public MCCEdit(Composite parent) { public MCCEdit(Composite parent) {
super(parent, CountryCodeQualifier.NAME); super(parent, CountryCodeQualifier.NAME);
mText = new Text(this, SWT.BORDER); mText = new Text(this, SWT.BORDER);
mText.addVerifyListener(new MobileCodeVerifier()); mText.addVerifyListener(new MobileCodeVerifier());
mText.addModifyListener(new ModifyListener() { mText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
onTextChange(); onTextChange();
} }
}); });
mText.addFocusListener(new FocusAdapter() { mText.addFocusListener(new FocusAdapter() {
@@ -603,13 +604,13 @@ public class ConfigurationSelector extends Composite {
onTextChange(); onTextChange();
} }
}); });
new Label(this, SWT.NONE).setText("(3 digit code)"); new Label(this, SWT.NONE).setText("(3 digit code)");
} }
private void onTextChange() { private void onTextChange() {
String value = mText.getText(); String value = mText.getText();
if (value.length() == 0) { if (value.length() == 0) {
// empty string, means a qualifier with no value. // empty string, means a qualifier with no value.
// Since the qualifier classes are immutable, and we don't want to // Since the qualifier classes are immutable, and we don't want to
@@ -632,7 +633,7 @@ public class ConfigurationSelector extends Composite {
mSelectedConfiguration.setCountryCodeQualifier(new CountryCodeQualifier()); mSelectedConfiguration.setCountryCodeQualifier(new CountryCodeQualifier());
} }
} }
// notify of change // notify of change
onChange(true /* keepSelection */); onChange(true /* keepSelection */);
} }
@@ -640,7 +641,7 @@ public class ConfigurationSelector extends Composite {
@Override @Override
public void setQualifier(ResourceQualifier qualifier) { public void setQualifier(ResourceQualifier qualifier) {
CountryCodeQualifier q = (CountryCodeQualifier)qualifier; CountryCodeQualifier q = (CountryCodeQualifier)qualifier;
mText.setText(Integer.toString(q.getCode())); mText.setText(Integer.toString(q.getCode()));
} }
} }
@@ -653,7 +654,7 @@ public class ConfigurationSelector extends Composite {
public MNCEdit(Composite parent) { public MNCEdit(Composite parent) {
super(parent, NetworkCodeQualifier.NAME); super(parent, NetworkCodeQualifier.NAME);
mText = new Text(this, SWT.BORDER); mText = new Text(this, SWT.BORDER);
mText.addVerifyListener(new MobileCodeVerifier()); mText.addVerifyListener(new MobileCodeVerifier());
mText.addModifyListener(new ModifyListener() { mText.addModifyListener(new ModifyListener() {
@@ -670,10 +671,10 @@ public class ConfigurationSelector extends Composite {
new Label(this, SWT.NONE).setText("(1-3 digit code)"); new Label(this, SWT.NONE).setText("(1-3 digit code)");
} }
private void onTextChange() { private void onTextChange() {
String value = mText.getText(); String value = mText.getText();
if (value.length() == 0) { if (value.length() == 0) {
// empty string, means a qualifier with no value. // empty string, means a qualifier with no value.
// Since the qualifier classes are immutable, and we don't want to // Since the qualifier classes are immutable, and we don't want to
@@ -696,19 +697,19 @@ public class ConfigurationSelector extends Composite {
mSelectedConfiguration.setNetworkCodeQualifier(new NetworkCodeQualifier()); mSelectedConfiguration.setNetworkCodeQualifier(new NetworkCodeQualifier());
} }
} }
// notify of change // notify of change
onChange(true /* keepSelection */); onChange(true /* keepSelection */);
} }
@Override @Override
public void setQualifier(ResourceQualifier qualifier) { public void setQualifier(ResourceQualifier qualifier) {
NetworkCodeQualifier q = (NetworkCodeQualifier)qualifier; NetworkCodeQualifier q = (NetworkCodeQualifier)qualifier;
mText.setText(Integer.toString(q.getCode())); mText.setText(Integer.toString(q.getCode()));
} }
} }
/** /**
* Edit widget for {@link LanguageQualifier}. * Edit widget for {@link LanguageQualifier}.
*/ */
@@ -741,7 +742,7 @@ public class ConfigurationSelector extends Composite {
private void onLanguageChange() { private void onLanguageChange() {
// update the current config // update the current config
String value = mLanguage.getText(); String value = mLanguage.getText();
if (value.length() == 0) { if (value.length() == 0) {
// empty string, means no qualifier. // empty string, 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
@@ -809,7 +810,7 @@ public class ConfigurationSelector extends Composite {
private void onRegionChange() { private void onRegionChange() {
// update the current config // update the current config
String value = mRegion.getText(); String value = mRegion.getText();
if (value.length() == 0) { if (value.length() == 0) {
// empty string, means no qualifier. // empty string, 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
@@ -844,7 +845,7 @@ public class ConfigurationSelector extends Composite {
} }
} }
} }
/** /**
* Edit widget for {@link ScreenOrientationQualifier}. * Edit widget for {@link ScreenOrientationQualifier}.
*/ */
@@ -908,63 +909,58 @@ 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(); }
}
}); mDensity.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mText.addFocusListener(new FocusAdapter() { mDensity.addSelectionListener(new SelectionListener() {
@Override public void widgetDefaultSelected(SelectionEvent e) {
public void focusLost(FocusEvent e) { onDensityChange();
onTextChange(); }
public void widgetSelected(SelectionEvent e) {
onDensityChange();
} }
}); });
} }
private void onTextChange() { private void onDensityChange() {
String value = mText.getText(); // update the current config
int index = mDensity.getSelectionIndex();
if (value.length() == 0) {
// empty string, means a qualifier with no value. 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
onChange(true /* keepSelection */); onChange(true /* keepSelection */);
} }
@Override @Override
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));
}
} }
} }
@@ -1202,7 +1198,7 @@ public class ConfigurationSelector extends Composite {
} }
} }
} }
/** /**
* Edit widget for {@link ScreenDimensionQualifier}. * Edit widget for {@link ScreenDimensionQualifier}.
*/ */
@@ -1217,9 +1213,9 @@ public class ConfigurationSelector extends Composite {
ModifyListener modifyListener = new ModifyListener() { ModifyListener modifyListener = new ModifyListener() {
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
onSizeChange(); onSizeChange();
} }
}; };
FocusAdapter focusListener = new FocusAdapter() { FocusAdapter focusListener = new FocusAdapter() {
@Override @Override
public void focusLost(FocusEvent e) { public void focusLost(FocusEvent e) {
@@ -1237,12 +1233,12 @@ public class ConfigurationSelector extends Composite {
mSize2.addModifyListener(modifyListener); mSize2.addModifyListener(modifyListener);
mSize2.addFocusListener(focusListener); mSize2.addFocusListener(focusListener);
} }
private void onSizeChange() { private void onSizeChange() {
// update the current config // update the current config
String size1 = mSize1.getText(); String size1 = mSize1.getText();
String size2 = mSize2.getText(); String size2 = mSize2.getText();
if (size1.length() == 0 || size2.length() == 0) { if (size1.length() == 0 || size2.length() == 0) {
// if one of the strings is empty, reset to no qualifier. // if one of the strings is empty, reset to 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
@@ -1262,7 +1258,7 @@ public class ConfigurationSelector extends Composite {
new ScreenDimensionQualifier()); new ScreenDimensionQualifier());
} }
} }
// notify of change // notify of change
onChange(true /* keepSelection */); onChange(true /* keepSelection */);
} }
@@ -1270,7 +1266,7 @@ public class ConfigurationSelector extends Composite {
@Override @Override
public void setQualifier(ResourceQualifier qualifier) { public void setQualifier(ResourceQualifier qualifier) {
ScreenDimensionQualifier q = (ScreenDimensionQualifier)qualifier; ScreenDimensionQualifier q = (ScreenDimensionQualifier)qualifier;
mSize1.setText(Integer.toString(q.getValue1())); mSize1.setText(Integer.toString(q.getValue1()));
mSize2.setText(Integer.toString(q.getValue2())); mSize2.setText(Integer.toString(q.getValue2()));
} }

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;
@@ -44,7 +45,7 @@ public class ConfigMatchTest extends TestCase {
private static final String SEARCHED_FILENAME = "main.xml"; //$NON-NLS-1$ private static final String SEARCHED_FILENAME = "main.xml"; //$NON-NLS-1$
private static final String MISC1_FILENAME = "foo.xml"; //$NON-NLS-1$ private static final String MISC1_FILENAME = "foo.xml"; //$NON-NLS-1$
private static final String MISC2_FILENAME = "bar.xml"; //$NON-NLS-1$ private static final String MISC2_FILENAME = "bar.xml"; //$NON-NLS-1$
private ProjectResources mResources; private ProjectResources mResources;
private ResourceQualifier[] mQualifierList; private ResourceQualifier[] mQualifierList;
private FolderConfiguration config4; private FolderConfiguration config4;
@@ -55,20 +56,20 @@ public class ConfigMatchTest extends TestCase {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
// create a Resource Manager to get a list of qualifier as instantiated by the real code. // create a Resource Manager to get a list of qualifier as instantiated by the real code.
// Thanks for QualifierListTest we know this contains all the qualifiers. // Thanks for QualifierListTest we know this contains all the qualifiers.
ResourceManager manager = ResourceManager.getInstance(); ResourceManager manager = ResourceManager.getInstance();
Field qualifierListField = ResourceManager.class.getDeclaredField("mQualifiers"); Field qualifierListField = ResourceManager.class.getDeclaredField("mQualifiers");
assertNotNull(qualifierListField); assertNotNull(qualifierListField);
qualifierListField.setAccessible(true); qualifierListField.setAccessible(true);
// get the actual list. // get the actual list.
mQualifierList = (ResourceQualifier[])qualifierListField.get(manager); mQualifierList = (ResourceQualifier[])qualifierListField.get(manager);
// create the project resources. // create the project resources.
mResources = new ProjectResources(false /* isFrameworkRepository */); mResources = new ProjectResources(false /* isFrameworkRepository */);
// create 2 arrays of IResource. one with the filename being looked up, and one without. // create 2 arrays of IResource. one with the filename being looked up, and one without.
// Since the required API uses IResource, we can use MockFolder for them. // Since the required API uses IResource, we can use MockFolder for them.
FileMock[] validMemberList = new FileMock[] { FileMock[] validMemberList = new FileMock[] {
@@ -80,7 +81,7 @@ public class ConfigMatchTest extends TestCase {
new FileMock(MISC1_FILENAME), new FileMock(MISC1_FILENAME),
new FileMock(MISC2_FILENAME), new FileMock(MISC2_FILENAME),
}; };
// add multiple ResourceFolder to the project resource. // add multiple ResourceFolder to the project resource.
FolderConfiguration defaultConfig = getConfiguration( FolderConfiguration defaultConfig = getConfiguration(
null, // country code null, // country code
@@ -94,9 +95,9 @@ public class ConfigMatchTest extends TestCase {
null, // text input null, // text input
null, // navigation null, // navigation
null); // screen size null); // screen size
addFolder(mResources, defaultConfig, validMemberList); addFolder(mResources, defaultConfig, validMemberList);
config1 = getConfiguration( config1 = getConfiguration(
null, // country code null, // country code
null, // network code null, // network code
@@ -109,7 +110,7 @@ public class ConfigMatchTest extends TestCase {
null, // text input null, // text input
null, // navigation null, // navigation
null); // screen size null); // screen size
addFolder(mResources, config1, validMemberList); addFolder(mResources, config1, validMemberList);
config2 = getConfiguration( config2 = getConfiguration(
@@ -124,7 +125,7 @@ public class ConfigMatchTest extends TestCase {
null, // text input null, // text input
null, // navigation null, // navigation
null); // screen size null); // screen size
addFolder(mResources, config2, validMemberList); addFolder(mResources, config2, validMemberList);
config3 = getConfiguration( config3 = getConfiguration(
@@ -139,7 +140,7 @@ public class ConfigMatchTest extends TestCase {
null, // text input null, // text input
null, // navigation null, // navigation
null); // screen size null); // screen size
addFolder(mResources, config3, validMemberList); addFolder(mResources, config3, validMemberList);
config4 = getConfiguration( config4 = getConfiguration(
@@ -154,7 +155,7 @@ public class ConfigMatchTest extends TestCase {
TextInputMethod.QWERTY.getValue(), // text input TextInputMethod.QWERTY.getValue(), // text input
NavigationMethod.DPAD.getValue(), // navigation NavigationMethod.DPAD.getValue(), // navigation
"480x320"); // screen size "480x320"); // screen size
addFolder(mResources, config4, invalidMemberList); addFolder(mResources, config4, invalidMemberList);
} }
@@ -177,10 +178,10 @@ public class ConfigMatchTest extends TestCase {
TextInputMethod.QWERTY.getValue(), // text input TextInputMethod.QWERTY.getValue(), // text input
NavigationMethod.DPAD.getValue(), // navigation NavigationMethod.DPAD.getValue(), // navigation
"480x320"); // screen size "480x320"); // screen size
ResourceFile result = mResources.getMatchingFile(SEARCHED_FILENAME, ResourceFile result = mResources.getMatchingFile(SEARCHED_FILENAME,
ResourceFolderType.LAYOUT, testConfig); ResourceFolderType.LAYOUT, testConfig);
boolean bresult = result.getFolder().getConfiguration().equals(config3); boolean bresult = result.getFolder().getConfiguration().equals(config3);
assertEquals(bresult, true); assertEquals(bresult, true);
} }
@@ -193,10 +194,10 @@ public class ConfigMatchTest extends TestCase {
*/ */
private FolderConfiguration getConfiguration(String... qualifierValues) { private FolderConfiguration getConfiguration(String... qualifierValues) {
FolderConfiguration config = new FolderConfiguration(); FolderConfiguration config = new FolderConfiguration();
// those must be of the same length // those must be of the same length
assertEquals(qualifierValues.length, mQualifierList.length); assertEquals(qualifierValues.length, mQualifierList.length);
int index = 0; int index = 0;
for (ResourceQualifier qualifier : mQualifierList) { for (ResourceQualifier qualifier : mQualifierList) {
@@ -208,7 +209,7 @@ public class ConfigMatchTest extends TestCase {
return config; return config;
} }
/** /**
* Adds a folder to the given {@link ProjectResources} with the given * Adds a folder to the given {@link ProjectResources} with the given
* {@link FolderConfiguration}. The folder is filled with files from the provided list. * {@link FolderConfiguration}. The folder is filled with files from the provided list.
@@ -218,13 +219,10 @@ public class ConfigMatchTest extends TestCase {
*/ */
private void addFolder(ProjectResources resources, FolderConfiguration config, private void addFolder(ProjectResources resources, FolderConfiguration config,
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);
@@ -237,15 +235,15 @@ public class ConfigMatchTest extends TestCase {
} }
} }
/** Calls ProjectResource.add method via reflection to circumvent access /** Calls ProjectResource.add method via reflection to circumvent access
* restrictions that are enforced when running in the plug-in environment * restrictions that are enforced when running in the plug-in environment
* ie cannot access package or protected members in a different plug-in, even * ie cannot access package or protected members in a different plug-in, even
* if they are in the same declared package as the accessor * if they are in the same declared package as the accessor
*/ */
private ResourceFolder _addProjectResourceFolder(ProjectResources resources, private ResourceFolder _addProjectResourceFolder(ProjectResources resources,
FolderConfiguration config, FolderMock folder) throws Exception { FolderConfiguration config, FolderMock folder) throws Exception {
Method addMethod = ProjectResources.class.getDeclaredMethod("add", Method addMethod = ProjectResources.class.getDeclaredMethod("add",
ResourceFolderType.class, FolderConfiguration.class, ResourceFolderType.class, FolderConfiguration.class,
IAbstractFolder.class); IAbstractFolder.class);
addMethod.setAccessible(true); addMethod.setAccessible(true);
@@ -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;
} }
} }