当前位置: 首页>>代码示例>>Java>>正文


Java ResourceFolderType.getFolderType方法代码示例

本文整理汇总了Java中com.android.resources.ResourceFolderType.getFolderType方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceFolderType.getFolderType方法的具体用法?Java ResourceFolderType.getFolderType怎么用?Java ResourceFolderType.getFolderType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.resources.ResourceFolderType的用法示例。


在下文中一共展示了ResourceFolderType.getFolderType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: beforeCheckFile

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
@Override
public void beforeCheckFile(@NonNull Context context) {
    if (endsWith(context.file.getName(), DOT_XML)) {
        // Drawable XML files should not be considered for overdraw, except for <bitmap>'s.
        // The bitmap elements are handled in the scanBitmap() method; it will clear
        // out anything added by this method.
        File parent = context.file.getParentFile();
        ResourceFolderType type = ResourceFolderType.getFolderType(parent.getName());
        if (type == ResourceFolderType.DRAWABLE) {
            if (mValidDrawables == null) {
                mValidDrawables = new ArrayList<String>();
            }
            String resource = getDrawableResource(context.file);
            mValidDrawables.add(resource);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:OverdrawDetector.java

示例2: isOutsideResourceTypeFolder

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
/** Returns true if the context points to an Android module, but outside of a specific resource type folder */
static boolean isOutsideResourceTypeFolder(@NotNull DataContext context) {
  // Avoid listing these actions in folders where we have a more specific action (e.g. "Add Layout File")
  VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context);
  if (file != null) {
    if (!file.isDirectory()) {
      file = file.getParent();
    }
    if (file != null && ResourceFolderType.getFolderType(file.getName()) != null) {
      // TODO: Also check that it's really a resource folder!
      return false;
    }
  }

  // Offer creating resource files from anywhere in the project (as is done for Java Classes) as long as it's within an Android module
  Module module = LangDataKeys.MODULE.getData(context);
  if (module != null) {
    return AndroidFacet.getInstance(module) != null;
  }

  PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
  return element != null && AndroidFacet.getInstance(element) != null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:CreateResourceFileAction.java

示例3: getUniqueFolderType

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
@Nullable
static ResourceFolderType getUniqueFolderType(@Nullable VirtualFile[] files) {
  ResourceFolderType folderType = null;
  if (files != null && files.length > 0) {
    for (VirtualFile file : files) {
      if (!file.isDirectory()) {
        file = file.getParent();
      }
      if (file != null) {
        ResourceFolderType type = ResourceFolderType.getFolderType(file.getName());
        if (type != null) {
          // Ensure that if there are multiple files, they all have the same type
          if (type != folderType && folderType != null) {
            folderType = null;
            break;
          }
          else {
            folderType = type;
          }
        }
      }
    }
  }
  return folderType;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:CreateResourceFileAction.java

示例4: getFolderType

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
@Nullable
public static ResourceFolderType getFolderType(@Nullable final PsiFile file) {
  if (file != null) {
    if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
      return ApplicationManager.getApplication().runReadAction(new Computable<ResourceFolderType>() {
        @Nullable
        @Override
        public ResourceFolderType compute() {
          return getFolderType(file);
        }
      });
    }
    if (!file.isValid()) {
      return getFolderType(file.getVirtualFile());
    }
    PsiDirectory parent = file.getParent();
    if (parent != null) {
      return ResourceFolderType.getFolderType(parent.getName());
    }
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:ResourceHelper.java

示例5: scanResFolder

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
private void scanResFolder(@NotNull PsiDirectory res) {
  for (PsiDirectory dir : res.getSubdirectories()) {
    String name = dir.getName();
    ResourceFolderType folderType = ResourceFolderType.getFolderType(name);
    if (folderType != null) {
      String qualifiers = getQualifiers(name);
      FolderConfiguration folderConfiguration = FolderConfiguration.getConfigForFolder(name);
      if (folderConfiguration == null) {
        continue;
      }
      if (folderType == VALUES) {
        scanValueResFolder(dir, qualifiers, folderConfiguration);
      } else {
        scanFileResourceFolder(dir, folderType, qualifiers, folderConfiguration);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ResourceFolderRepository.java

示例6: getSource

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
@Nullable
@Override
public ResourceFile getSource() {
  ResourceFile source = super.getSource();

  // Temporary safety workaround
  if (source == null && myFile != null && myFile.getParent() != null) {
    PsiDirectory parent = myFile.getParent();
    if (parent != null) {
      String name = parent.getName();
      ResourceFolderType folderType = ResourceFolderType.getFolderType(name);
      FolderConfiguration configuration = FolderConfiguration.getConfigForFolder(name);
      int index = name.indexOf('-');
      String qualifiers = index == -1 ? "" : name.substring(index + 1);
      source = new PsiResourceFile(myFile, Collections.<ResourceItem>singletonList(this), qualifiers, folderType,
                                   configuration);
      setSource(source);
    }
  }

  return source;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:PsiResourceItem.java

示例7: getIcon

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
@Nullable
@Override
public Icon getIcon(@NotNull PsiElement element, @Iconable.IconFlags int flags) {
  if (element instanceof XmlFile) {
    final VirtualFile file = ((XmlFile)element).getVirtualFile();
    if (file != null && !FN_ANDROID_MANIFEST_XML.equals(file.getName())) {
      VirtualFile parent = file.getParent();
      if (parent != null) {
        String parentName = parent.getName();
        int index = parentName.indexOf('-');
        if (index != -1) {
          FolderConfiguration config = FolderConfiguration.getConfigForFolder(parentName);
          if (config != null && config.getLocaleQualifier() != null && ResourceFolderType.getFolderType(parentName) != null) {
            return FlagManager.get().getFlag(config);
          }
        }
      }
    }
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AndroidIconProvider.java

示例8: mayHaveNonStringTranslations

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
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;
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:24,代码来源:GeneratedResourceClassifier.java

示例9: isValidSourceFile

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
@Override
protected boolean isValidSourceFile(@NonNull File sourceFolder, @NonNull File file) {
    if (!super.isValidSourceFile(sourceFolder, file)) {
        return false;
    }

    File resFolder = file.getParentFile();
    // valid files are right under a resource folder under the source folder
    return resFolder.getParentFile().equals(sourceFolder) &&
            !isIgnored(resFolder) &&
            ResourceFolderType.getFolderType(resFolder.getName()) != null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:13,代码来源:ResourceSet.java

示例10: findResourceFile

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
/**
 * Looks up the {@link ResourceFile} for the given {@link File}, if possible
 *
 * @param file the file
 * @return the corresponding {@link ResourceFile}, or null if not a known {@link ResourceFile}
 */
@Nullable
protected ResourceFile findResourceFile(@NonNull File file) {
    // Look up the right resource file for this path
    String parentName = file.getParentFile().getName();
    IAbstractFolder folder = getResFolder().getFolder(parentName);
    if (folder != null) {
        ResourceFolder resourceFolder = getResourceFolder(folder);
        if (resourceFolder == null) {
            FolderConfiguration configForFolder = FolderConfiguration
                    .getConfigForFolder(parentName);
            if (configForFolder != null) {
                ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName);
                if (folderType != null) {
                    resourceFolder = add(folderType, configForFolder, folder);
                }
            }
        }
        if (resourceFolder != null) {
            ResourceFile resourceFile = resourceFolder.getFile(file.getName());
            if (resourceFile != null) {
                return resourceFile;
            }
        }
    }

    return null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:34,代码来源:ResourceRepository.java

示例11: checkResFolder

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
private void checkResFolder(
        @NonNull Project project,
        @Nullable Project main,
        @NonNull File res,
        @NonNull List<ResourceXmlDetector> xmlChecks,
        @Nullable List<Detector> dirChecks,
        @Nullable List<Detector> binaryChecks) {
    File[] resourceDirs = res.listFiles();
    if (resourceDirs == null) {
        return;
    }

    // Sort alphabetically such that we can process related folder types at the
    // same time, and to have a defined behavior such that detectors can rely on
    // predictable ordering, e.g. layouts are seen before menus are seen before
    // values, etc (l < m < v).

    Arrays.sort(resourceDirs);
    for (File dir : resourceDirs) {
        ResourceFolderType type = ResourceFolderType.getFolderType(dir.getName());
        if (type != null) {
            checkResourceFolder(project, main, dir, type, xmlChecks, dirChecks, binaryChecks);
        }

        if (mCanceled) {
            return;
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:LintDriver.java

示例12: beforeCheckFile

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
@Override
public void beforeCheckFile(@NonNull Context context) {
    File file = context.file;
    boolean isXmlFile = LintUtils.isXmlFile(file);
    if (!isXmlFile && !LintUtils.isBitmapFile(file)) {
        return;
    }
    String parentName = file.getParentFile().getName();
    int dash = parentName.indexOf('-');
    if (dash != -1 || FD_RES_VALUES.equals(parentName)) {
        return;
    }
    ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName);
    if (folderType == null) {
        return;
    }
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType);
    if (types.isEmpty()) {
        return;
    }
    ResourceType type = types.get(0);
    String resourceName = getResourceFieldName(getBaseName(file.getName()));
    if (isPrivate(context, type, resourceName)) {
        String message = createOverrideErrorMessage(context, type, resourceName);
        Location location = Location.create(file);
        context.report(ISSUE, location, message);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:PrivateResourceDetector.java

示例13: getNameError

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
@Nullable
private String getNameError(@NotNull String fileName) {
  String typeName = myResourceTypeCombo.getSelectedName();
  if (typeName != null) {
    ResourceFolderType type = ResourceFolderType.getFolderType(typeName);
    if (type != null) {
      ResourceNameValidator validator = ResourceNameValidator.create(true, type);
      return validator.getErrorText(fileName);
    }
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:CreateResourceFileDialog.java

示例14: getNameError

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
@Nullable
private String getNameError(String fileName) {
  String typeName = myResourceTypeCombo.getSelectedName();
  if (typeName != null) {
    ResourceFolderType type = ResourceFolderType.getFolderType(typeName);
    if (type != null) {
      IdeResourceNameValidator validator =
          IdeResourceNameValidator.forFilename(type, SdkConstants.DOT_XML);
      return validator.getErrorText(fileName);
    }
  }

  return null;
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:15,代码来源:BlazeCreateResourceFileDialog.java

示例15: formatFile

import com.android.resources.ResourceFolderType; //导入方法依赖的package包/类
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);
        }
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:56,代码来源:XmlPrettyPrinter.java


注:本文中的com.android.resources.ResourceFolderType.getFolderType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。