// Resource names must be valid Java identifiers, since they will
// be represented as Java identifiers in the R file:
if (!Character.isJavaIdentifierStart(newText.charAt(0))) {
- return "The layout name must begin with a character";
+ return "The resource name must begin with a character";
}
for (int i = 1, n = newText.length(); i < n; i++) {
char c = newText.charAt(i);
}
if (mIsFileType) {
+ char first = newText.charAt(0);
+ if (!(first >= 'a' && first <= 'z')) {
+ return String.format(
+ "File-based resource names must start with a lowercase letter.");
+ }
+
// AAPT only allows lowercase+digits+_:
// "%s: Invalid file name: must contain only [a-z0-9_.]","
for (int i = 0, n = newText.length(); i < n; i++) {
import junit.framework.TestCase;
+@SuppressWarnings("javadoc")
public class ResourceNameValidatorTest extends TestCase {
public void testValidator() throws Exception {
// Valid
.isValid("Foo123_$") != null);
assertTrue(ResourceNameValidator.create(true, ResourceFolderType.LAYOUT)
.isValid("foo123_") == null);
+
+ // Can't start with _ in file-based resource names, is okay for value based resources
+ assertTrue(ResourceNameValidator.create(true, ResourceFolderType.VALUES)
+ .isValid("_foo") == null);
+ assertTrue(ResourceNameValidator.create(true, ResourceFolderType.LAYOUT)
+ .isValid("_foo") != null);
+ assertTrue(ResourceNameValidator.create(true, ResourceFolderType.DRAWABLE)
+ .isValid("_foo") != null);
}
}