import com.android.ide.eclipse.adt.internal.editors.layout.gle2.CanvasViewInfo;
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.DomUtilities;
import com.android.ide.eclipse.adt.internal.editors.layout.uimodel.UiViewElementNode;
-import com.android.ide.eclipse.adt.internal.wizards.newxmlfile.ResourceNameValidator;
+import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator;
import com.android.util.Pair;
import org.eclipse.core.resources.IContainer;
package com.android.ide.eclipse.adt.internal.editors.layout.refactoring;
-import com.android.ide.eclipse.adt.internal.wizards.newxmlfile.ResourceNameValidator;
+import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator;
import com.android.resources.ResourceType;
import org.eclipse.core.resources.IProject;
import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.ViewElementDescriptor;
import com.android.ide.eclipse.adt.internal.editors.layout.gre.ViewMetadataRepository;
+import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
-import com.android.ide.eclipse.adt.internal.wizards.newxmlfile.ResourceNameValidator;
import com.android.resources.ResourceType;
import com.android.sdklib.IAndroidTarget;
import com.android.util.Pair;
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart;
import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestEditor;
import com.android.ide.eclipse.adt.internal.editors.resources.descriptors.ResourcesDescriptors;
+import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator;
import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;
-import com.android.ide.eclipse.adt.internal.resources.manager.FolderTypeRelationship;
import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFile;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolder;
}
/**
- * Is this a resource that can be defined in any file within the "values" folder?
- *
- * @param type the resource type to check
- * @return true if the given resource type can be represented as a value under the
- * values/ folder
- */
- public static boolean isValueResource(ResourceType type) {
- ResourceFolderType[] folderTypes = FolderTypeRelationship.getRelatedFolders(type);
- for (ResourceFolderType folderType : folderTypes) {
- if (folderType == ResourceFolderType.VALUES) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
* Returns the XML tag containing an element description for value items of the given
* resource type
*
});
// Is this something found in a values/ folder?
- boolean valueResource = isValueResource(type);
- //boolean fileResource = isFileResource(type);
+ boolean valueResource = ResourceNameValidator.isValueBasedResourceType(type);
for (ResourceFile file : matches) {
String folderName = file.getFolder().getFolder().getName();
* limitations under the License.
*/
-package com.android.ide.eclipse.adt.internal.wizards.newxmlfile;
+package com.android.ide.eclipse.adt.internal.resources;
import static com.android.ide.eclipse.adt.AndroidConstants.DOT_XML;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.AndroidConstants;
-import com.android.ide.eclipse.adt.internal.editors.xml.Hyperlinks;
+import com.android.ide.eclipse.adt.internal.resources.manager.FolderTypeRelationship;
import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResourceItem;
import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;
// "%s: Invalid file name: must contain only [a-z0-9_.]","
for (int i = 0, n = newText.length(); i < n; i++) {
char c = newText.charAt(i);
- if (!(c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_') {
+ if (!((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_')) {
return String.format(
"File-based resource names must contain only lowercase a-z, 0-9, or _.");
}
*/
public static ResourceNameValidator create(boolean allowXmlExtension, Set<String> existing,
ResourceType type) {
- boolean isFileType = !Hyperlinks.isValueResource(type);
+ boolean isFileType = isFileBasedResourceType(type);
return new ResourceNameValidator(allowXmlExtension, existing, isFileType);
}
existing.add(resource.getName());
}
- boolean isFileType = !Hyperlinks.isValueResource(type);
+ boolean isFileType = isFileBasedResourceType(type);
return new ResourceNameValidator(allowXmlExtension, existing, isFileType);
}
+
+ /**
+ * Is this a resource that is defined in a file named by the resource plus the XML
+ * extension?
+ * <p>
+ * Some resource types can be defined <b>both</b> as a separate XML file as well as
+ * defined within a value XML file along with other properties. This method will
+ * return true for these resource types as well. In other words, a ResourceType can
+ * return true for both {@link #isValueBasedResourceType} and
+ * {@link #isFileBasedResourceType}.
+ *
+ * @param type the resource type to check
+ * @return true if the given resource type is stored in a file named by the resource
+ */
+ public static boolean isFileBasedResourceType(ResourceType type) {
+ ResourceFolderType[] folderTypes = FolderTypeRelationship.getRelatedFolders(type);
+ for (ResourceFolderType folderType : folderTypes) {
+ if (folderType != ResourceFolderType.VALUES) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Is this a resource that can be defined in any file within the "values" folder?
+ * <p>
+ * Some resource types can be defined <b>both</b> as a separate XML file as well
+ * as defined within a value XML file. This method will return true for these types
+ * as well. In other words, a ResourceType can return true for both
+ * {@link #isValueBasedResourceType} and {@link #isFileBasedResourceType}.
+ *
+ * @param type the resource type to check
+ * @return true if the given resource type can be represented as a value under the
+ * values/ folder
+ */
+ public static boolean isValueBasedResourceType(ResourceType type) {
+ ResourceFolderType[] folderTypes = FolderTypeRelationship.getRelatedFolders(type);
+ for (ResourceFolderType folderType : folderTypes) {
+ if (folderType == ResourceFolderType.VALUES) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
import com.android.ide.eclipse.adt.internal.resources.IResourceRepository;
import com.android.ide.eclipse.adt.internal.resources.ResourceHelper;
import com.android.ide.eclipse.adt.internal.resources.ResourceItem;
+import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
-import com.android.ide.eclipse.adt.internal.wizards.newxmlfile.ResourceNameValidator;
import com.android.resources.ResourceType;
import org.eclipse.core.resources.IFile;
String title = String.format("New %1$s...", mResourceType.getDisplayName());
mNewButton.setText(title);
- // We only support adding new strings right now
- mNewButton.setEnabled(Hyperlinks.isValueResource(mResourceType));
+ // We only support adding new values right now
+ mNewButton.setEnabled(ResourceNameValidator.isValueBasedResourceType(mResourceType));
mNewButton.addSelectionListener(new SelectionAdapter() {
@Override
if (mResourceType == ResourceType.STRING) {
createNewString();
} else {
- assert Hyperlinks.isValueResource(mResourceType);
+ assert ResourceNameValidator.isValueBasedResourceType(mResourceType);
String newName = createNewValue(mResourceType);
if (newName != null) {
// Recompute the "current resource" to select the new id
import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
import com.android.ide.eclipse.adt.internal.project.ProjectChooserHelper;
import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper.IProjectFilter;
+import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator;
import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;
import com.android.ide.eclipse.adt.internal.resources.configurations.ResourceQualifier;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;
* limitations under the License.
*/
-package com.android.ide.eclipse.adt.internal.wizards.newxmlfile;
+package com.android.ide.eclipse.adt.internal.resources;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType;
import com.android.resources.ResourceType;
// Only lowercase chars allowed in file-based resource names
assertTrue(ResourceNameValidator.create(true, ResourceFolderType.LAYOUT)
.isValid("Foo123_$") != null);
+ assertTrue(ResourceNameValidator.create(true, ResourceFolderType.LAYOUT)
+ .isValid("foo123_") == null);
+ }
+
+ public void testIsFileBasedResourceType() throws Exception {
+ assertTrue(ResourceNameValidator.isFileBasedResourceType(ResourceType.ANIMATOR));
+ assertTrue(ResourceNameValidator.isFileBasedResourceType(ResourceType.LAYOUT));
+
+ assertFalse(ResourceNameValidator.isFileBasedResourceType(ResourceType.STRING));
+ assertFalse(ResourceNameValidator.isFileBasedResourceType(ResourceType.DIMEN));
+ assertFalse(ResourceNameValidator.isFileBasedResourceType(ResourceType.ID));
+
+ // Both:
+ assertTrue(ResourceNameValidator.isFileBasedResourceType(ResourceType.DRAWABLE));
+ assertTrue(ResourceNameValidator.isFileBasedResourceType(ResourceType.COLOR));
+ }
+
+ public void testIsValueBasedResourceType() throws Exception {
+ assertTrue(ResourceNameValidator.isValueBasedResourceType(ResourceType.STRING));
+ assertTrue(ResourceNameValidator.isValueBasedResourceType(ResourceType.DIMEN));
+ assertTrue(ResourceNameValidator.isValueBasedResourceType(ResourceType.ID));
+
+ assertFalse(ResourceNameValidator.isValueBasedResourceType(ResourceType.LAYOUT));
+ // These can be both:
+ assertTrue(ResourceNameValidator.isValueBasedResourceType(ResourceType.DRAWABLE));
+ assertTrue(ResourceNameValidator.isValueBasedResourceType(ResourceType.COLOR));
}
}