本文整理汇总了Java中com.android.resources.ResourceFolderType.VALUES属性的典型用法代码示例。如果您正苦于以下问题:Java ResourceFolderType.VALUES属性的具体用法?Java ResourceFolderType.VALUES怎么用?Java ResourceFolderType.VALUES使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.android.resources.ResourceFolderType
的用法示例。
在下文中一共展示了ResourceFolderType.VALUES属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAvailable
public boolean isAvailable(@Nullable XmlTag tag, PsiFile file) {
if (file instanceof XmlFile && file.isValid() && AndroidFacet.getInstance(file) != null) {
ResourceFolderType folderType = ResourceHelper.getFolderType(file);
if (folderType == null) {
return false;
} else if (folderType != ResourceFolderType.VALUES) {
return true;
} else {
// In value files, you can invoke this action if the caret is on or inside an element (other than the
// root <resources> tag). Only accept the element if it has a known type with a known name.
if (tag != null && tag.getAttributeValue(ATTR_NAME) != null) {
return AndroidResourceUtil.getResourceForResourceTag(tag) != null;
}
}
}
return false;
}
示例2: beforeCheckFile
@Override
public void beforeCheckFile(@NonNull Context context) {
if (mPrefix != null && context instanceof XmlContext) {
XmlContext xmlContext = (XmlContext) context;
ResourceFolderType folderType = xmlContext.getResourceFolderType();
if (folderType != null && folderType != ResourceFolderType.VALUES) {
String name = LintUtils.getBaseName(context.file.getName());
if (!name.startsWith(mPrefix)) {
// Attempt to report the error on the root tag of the associated
// document to make suppressing the error with a tools:suppress
// attribute etc possible
if (xmlContext.document != null) {
Element root = xmlContext.document.getDocumentElement();
if (root != null) {
xmlContext.report(ISSUE, root, xmlContext.getLocation(root),
getErrorMessage(name));
return;
}
}
context.report(ISSUE, Location.create(context.file),
getErrorMessage(name));
}
}
}
}
示例3: visitElement
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
if (mPrefix == null || context.getResourceFolderType() != ResourceFolderType.VALUES) {
return;
}
for (Element item : LintUtils.getChildren(element)) {
Attr nameAttribute = item.getAttributeNode(ATTR_NAME);
if (nameAttribute != null) {
String name = nameAttribute.getValue();
if (!name.startsWith(mPrefix)) {
String message = getErrorMessage(name);
context.report(ISSUE, nameAttribute, context.getLocation(nameAttribute),
message);
}
}
}
}
示例4: mayHaveNonStringTranslations
private static boolean mayHaveNonStringTranslations(String dirName) {
// String translations only sit in the values-xx-rYY directories, so we can rule out other
// directories quickly.
if (!dirName.contains(SdkConstants.RES_QUALIFIER_SEP)) {
return true;
}
if (ResourceFolderType.getFolderType(dirName) != ResourceFolderType.VALUES) {
return true;
}
FolderConfiguration config = FolderConfiguration.getConfigForFolder(dirName);
// Conservatively say it's interesting if there is an unrecognized configuration.
if (config == null) {
return true;
}
// If this is a translation mixed with something else, consider it a translation directory.
boolean hasTranslation = false;
for (ResourceQualifier qualifier : config.getQualifiers()) {
if (qualifier instanceof LocaleQualifier) {
hasTranslation = true;
}
}
return !hasTranslation;
}
示例5: isIgnorable
private boolean isIgnorable(PsiTreeChangeEvent event) {
// We can ignore edits in whitespace, and in XML error nodes, and in comments
// (Note that editing text in an attribute value, including whitespace characters,
// is not a PsiWhiteSpace element; it's an XmlToken of token type XML_ATTRIBUTE_VALUE_TOKEN
PsiElement child = event.getChild();
PsiElement parent = event.getParent();
if (child instanceof PsiErrorElement ||
child instanceof XmlComment ||
parent instanceof XmlComment) {
return true;
}
if ((child instanceof PsiWhiteSpace || child instanceof XmlText || parent instanceof XmlText)
&& ResourceHelper.getFolderType(event.getFile()) != ResourceFolderType.VALUES) {
// Editing text or whitespace has no effect outside of values files
return true;
}
return false;
}
示例6: isFileBasedResourceType
/**
* 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(@NotNull ResourceType type) {
List<ResourceFolderType> folderTypes = FolderTypeRelationship.getRelatedFolders(type);
for (ResourceFolderType folderType : folderTypes) {
if (folderType != ResourceFolderType.VALUES) {
if (type == ResourceType.ID) {
// The folder types for ID is not only VALUES but also
// LAYOUT and MENU. However, unlike resources, they are only defined
// inline there so for the purposes of isFileBasedResourceType
// (where the intent is to figure out files that are uniquely identified
// by a resource's name) this method should return false anyway.
return false;
}
return true;
}
}
return false;
}
示例7: getFolderData
/**
* Returns a FolderData for the given folder
* @param folder the folder.
* @return the FolderData object.
*/
@Nullable
private static FolderData getFolderData(File folder) {
FolderData fd = new FolderData();
String folderName = folder.getName();
int pos = folderName.indexOf(ResourceConstants.RES_QUALIFIER_SEP);
if (pos != -1) {
fd.folderType = ResourceFolderType.getTypeByName(folderName.substring(0, pos));
if (fd.folderType == null) {
return null;
}
FolderConfiguration folderConfiguration = FolderConfiguration.getConfigForFolder(folderName);
if (folderConfiguration == null) {
return null;
}
// normalize it
folderConfiguration.normalize();
// get the qualifier portion from the folder config.
// the returned string starts with "-" so we remove that.
fd.qualifiers = folderConfiguration.getUniqueKey().substring(1);
} else {
fd.folderType = ResourceFolderType.getTypeByName(folderName);
}
if (fd.folderType != null && fd.folderType != ResourceFolderType.VALUES) {
fd.type = FolderTypeRelationship.getRelatedResourceTypes(fd.folderType).get(0);
}
return fd;
}
示例8: isFileBasedResourceType
/**
* Determine if the given type corresponds to a resource that has a unique
* file
*
* @param type the resource type to check
* @return true if the given type corresponds to a file-type resource
*/
public static boolean isFileBasedResourceType(@NonNull ResourceType type) {
List<ResourceFolderType> folderTypes = FolderTypeRelationship.getRelatedFolders(type);
for (ResourceFolderType folderType : folderTypes) {
if (folderType != ResourceFolderType.VALUES) {
return type != ResourceType.ID;
}
}
return false;
}
示例9: invoke
@Override
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
AndroidFacet facet = AndroidFacet.getInstance(file);
ResourceFolderType folderType = ResourceHelper.getFolderType(file);
if (facet == null || folderType == null) {
// shouldn't happen; we checked in isAvailable
return;
}
if (folderType != ResourceFolderType.VALUES) {
forkResourceFile((XmlFile)file, null, true);
} else if (editor != null) {
forkResourceValue(project, editor, file, facet, null);
}
}
示例10: apply
@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
PsiFile file = startElement.getContainingFile();
if (file instanceof XmlFile) {
ResourceFolderType folderType = ResourceHelper.getFolderType(file);
if (folderType != null) {
if (folderType != ResourceFolderType.VALUES) {
forkResourceFile((XmlFile)file, myFolder, true);
} else {
XmlTag tag = getValueTag(PsiTreeUtil.getParentOfType(startElement, XmlTag.class, false));
if (tag != null) {
AndroidFacet facet = AndroidFacet.getInstance(startElement);
if (facet != null) {
PsiDirectory dir = null;
if (myFolder != null) {
PsiDirectory resFolder = findRes(file);
if (resFolder != null) {
dir = resFolder.findSubdirectory(myFolder);
if (dir == null) {
dir = resFolder.createSubdirectory(myFolder);
}
}
}
forkResourceValue(startElement.getProject(), tag, file, facet, dir);
}
}
}
}
}
}
示例11: forkResourceFile
/**
* Create a variation (copy) of a given resource file (of a given type).
*
* @param xmlFile the XML resource file to fork
* @param myNewFolder the resource folder to create, or null to ask the user
* @param open if true, open the file after creating it
*/
public static void forkResourceFile(@NotNull final XmlFile xmlFile, @Nullable String myNewFolder, boolean open) {
VirtualFile file = xmlFile.getVirtualFile();
if (file == null) {
return;
}
Module module = AndroidPsiUtils.getModuleSafely(xmlFile);
if (module == null) {
return;
}
ResourceFolderType folderType = ResourceHelper.getFolderType(xmlFile);
if (folderType == null || folderType == ResourceFolderType.VALUES) {
return;
}
Configuration configuration = null;
if (folderType == ResourceFolderType.LAYOUT) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
configuration = facet.getConfigurationManager().getConfiguration(file);
}
}
// Suppress: IntelliJ claims folderType can be null here, but it can't (and inserting assert folderType != null is correctly
// identified as redundant)
//noinspection ConstantConditions
forkResourceFile(module, folderType, file, xmlFile, myNewFolder, configuration, open);
}
示例12: MyValidator
public MyValidator(Project project, PsiDirectory directory) {
super(project, directory);
// No validator for value files -- you can call them anything you want (e.g. "public.xml" is a valid
// name even though public is a Java keyword, etc.)
myNameValidator = myResourceType == ResourceFolderType.VALUES ? null : ResourceNameValidator.create(true, myResourceType);
}
示例13: formatFile
private static void formatFile(@NonNull XmlFormatPreferences prefs, File file,
boolean stdout) {
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null) {
for (File child : files) {
formatFile(prefs, child, stdout);
}
}
} else if (file.isFile() && SdkUtils.endsWithIgnoreCase(file.getName(), DOT_XML)) {
XmlFormatStyle style = null;
if (file.getName().equals(SdkConstants.ANDROID_MANIFEST_XML)) {
style = XmlFormatStyle.MANIFEST;
} else {
File parent = file.getParentFile();
if (parent != null) {
String parentName = parent.getName();
ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName);
if (folderType == ResourceFolderType.LAYOUT) {
style = XmlFormatStyle.LAYOUT;
} else if (folderType == ResourceFolderType.VALUES) {
style = XmlFormatStyle.RESOURCE;
}
}
}
try {
String xml = Files.toString(file, Charsets.UTF_8);
Document document = XmlUtils.parseDocumentSilently(xml, true);
if (document == null) {
System.err.println("Could not parse " + file);
System.exit(1);
return;
}
if (style == null) {
style = XmlFormatStyle.get(document);
}
boolean endWithNewline = xml.endsWith("\n");
int firstNewLine = xml.indexOf('\n');
String lineSeparator = firstNewLine > 0 && xml.charAt(firstNewLine - 1) == '\r' ?
"\r\n" : "\n";
String formatted = XmlPrettyPrinter.prettyPrint(document, prefs, style,
lineSeparator, endWithNewline);
if (stdout) {
System.out.println(formatted);
} else {
Files.write(formatted, file, Charsets.UTF_8);
}
} catch (IOException e) {
System.err.println("Could not read " + file);
System.exit(1);
}
}
}
示例14: appliesTo
@Override
public boolean appliesTo(@NonNull ResourceFolderType folderType) {
return folderType == ResourceFolderType.LAYOUT || folderType == ResourceFolderType.VALUES;
}
示例15: appliesTo
@Override
public boolean appliesTo(@NonNull ResourceFolderType folderType) {
return folderType == ResourceFolderType.VALUES;
}