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


Java ResourceFolderType类代码示例

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


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

示例1: getFolderName

import com.android.resources.ResourceFolderType; //导入依赖的package包/类
/**
 * Returns the name of a folder with the configuration.
 */
@NonNull
public String getFolderName(@NonNull ResourceFolderType folder) {
    StringBuilder result = new StringBuilder(folder.getName());

    for (ResourceQualifier qualifier : mQualifiers) {
        if (qualifier != null) {
            String segment = qualifier.getFolderSegment();
            if (segment != null && !segment.isEmpty()) {
                result.append(SdkConstants.RES_QUALIFIER_SEP);
                result.append(segment);
            }
        }
    }

    return result.toString();
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:20,代码来源:FolderConfiguration.java

示例2: hasResources

import com.android.resources.ResourceFolderType; //导入依赖的package包/类
/**
 * Returns whether a file in the folder is generating a resource of a specified type.
 * @param type The {@link ResourceType} being looked up.
 */
public boolean hasResources(ResourceType type) {
    // Check if the folder type is able to generate resource of the type that was asked.
    // this is a first check to avoid going through the files.
    List<ResourceFolderType> folderTypes = FolderTypeRelationship.getRelatedFolders(type);

    boolean valid = false;
    for (ResourceFolderType rft : folderTypes) {
        if (rft == mType) {
            valid = true;
            break;
        }
    }

    if (valid) {
        if (mFiles != null) {
            for (ResourceFile f : mFiles) {
                if (f.hasResources(type)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:29,代码来源:ResourceFolder.java

示例3: processFolder

import com.android.resources.ResourceFolderType; //导入依赖的package包/类
/**
 * Processes a folder and adds it to the list of existing folders.
 * @param folder the folder to process
 * @return the ResourceFolder created from this folder, or null if the process failed.
 */
@Nullable
public ResourceFolder processFolder(@NonNull IAbstractFolder folder) {
    ensureInitialized();

    // split the name of the folder in segments.
    String[] folderSegments = folder.getName().split(SdkConstants.RES_QUALIFIER_SEP);

    // get the enum for the resource type.
    ResourceFolderType type = ResourceFolderType.getTypeByName(folderSegments[0]);

    if (type != null) {
        // get the folder configuration.
        FolderConfiguration config = FolderConfiguration.getConfig(folderSegments);

        if (config != null) {
            return add(type, config, folder);
        }
    }

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

示例4: getMatchingFile

import com.android.resources.ResourceFolderType; //导入依赖的package包/类
/**
 * Returns the {@link ResourceFile} matching the given name,
 * {@link ResourceFolderType} and configuration.
 * <p/>
 * This only works with files generating one resource named after the file
 * (for instance, layouts, bitmap based drawable, xml, anims).
 *
 * @param name the resource name or file name
 * @param type the folder type search for
 * @param config the folder configuration to match for
 * @return the matching file or <code>null</code> if no match was found.
 */
@Nullable
public ResourceFile getMatchingFile(
        @NonNull String name,
        @NonNull ResourceFolderType type,
        @NonNull FolderConfiguration config) {
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(type);
    for (ResourceType t : types) {
        if (t == ResourceType.ID) {
            continue;
        }
        ResourceFile match = getMatchingFile(name, t, config);
        if (match != null) {
            return match;
        }
    }

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

示例5: isFileBasedResourceType

import com.android.resources.ResourceFolderType; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:ResourceHelper.java

示例6: shouldScheduleUpdate

import com.android.resources.ResourceFolderType; //导入依赖的package包/类
private static boolean shouldScheduleUpdate(@NotNull VirtualFile file) {
  final FileType fileType = file.getFileType();

  if (fileType == AndroidIdlFileType.ourFileType ||
      fileType == AndroidRenderscriptFileType.INSTANCE ||
      SdkConstants.FN_ANDROID_MANIFEST_XML.equals(file.getName())) {
    return true;
  }
  else if (fileType == StdFileTypes.XML) {
    final VirtualFile parent = file.getParent();

    if (parent != null && parent.isDirectory()) {
      final String resType = AndroidCommonUtils.getResourceTypeByDirName(parent.getName());
      return ResourceFolderType.VALUES.getName().equals(resType);
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:AndroidResourceFilesListener.java

示例7: 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

示例8: changeColor

import com.android.resources.ResourceFolderType; //导入依赖的package包/类
public static boolean changeColor(@NotNull final Module module, @NotNull final String colorName, @NotNull final String colorValue) {
  AndroidFacet facet = AndroidFacet.getInstance(module);
  if (facet == null) {
    return false;
  }

  final String fileName = AndroidResourceUtil.getDefaultResourceFileName(ResourceType.COLOR);
  if (fileName == null) {
    return false;
  }
  final List<String> dirNames = Collections.singletonList(ResourceFolderType.VALUES.getName());

  try {
    if (!AndroidResourceUtil.changeColorResource(facet, colorName, colorValue, fileName, dirNames)) {
      // Changing color resource has failed, one possible reason is that color isn't defined in the project.
      // Trying to create the color instead.
      return AndroidResourceUtil.createValueResource(module, colorName, ResourceType.COLOR, fileName, dirNames, colorValue);
    }

    return true;
  }
  catch (Exception e) {
    return false;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:ThemeEditorUtils.java

示例9: 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

示例10: collectQualifiers

import com.android.resources.ResourceFolderType; //导入依赖的package包/类
private static BidirectionalMap<String, VirtualFile> collectQualifiers(VirtualFile resDirectory, VirtualFile file) {
  BidirectionalMap<String, VirtualFile> result = new BidirectionalMap<String, VirtualFile>();
  ResourceFolderType type = ResourceHelper.getFolderType(file);
  for (VirtualFile dir : resDirectory.getChildren()) {
    ResourceFolderType otherType = ResourceFolderType.getFolderType(dir.getName());
    if (otherType == type) {
      VirtualFile fileWithQualifier = dir.findChild(file.getName());
      if (fileWithQualifier != null) {
        String childName = dir.getName();
        int dashPos = childName.indexOf('-');
        String qualifier = dashPos > 0 ? childName.substring(dashPos+1) : "<default>";
        result.put(qualifier, fileWithQualifier);
      }
    }
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ResourceQualifierSwitcher.java

示例11: isAlreadyWarnedDrawableFile

import com.android.resources.ResourceFolderType; //导入依赖的package包/类
/**
 * Returns true if this attribute is in a drawable document with one of the
 * root tags that require API 21
 */
private static boolean isAlreadyWarnedDrawableFile(@NonNull XmlContext context,
        @NonNull Attr attribute, int attributeApiLevel) {
    // Don't complain if it's in a drawable file where we've already
    // flagged the root drawable type as being unsupported
    if (context.getResourceFolderType() == ResourceFolderType.DRAWABLE
            && attributeApiLevel == 21) {
        String root = attribute.getOwnerDocument().getDocumentElement().getTagName();
        if (TAG_RIPPLE.equals(root)
                || TAG_VECTOR.equals(root)
                || TAG_ANIMATED_VECTOR.equals(root)
                || TAG_ANIMATED_SELECTOR.equals(root)) {
            return true;
        }
    }

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

示例12: 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

示例13: findResourceFile

import com.android.resources.ResourceFolderType; //导入依赖的package包/类
@Nullable
private PsiResourceFile findResourceFile(String dirName, String fileName) {
  int index = dirName.indexOf('-');
  String qualifiers;
  String folderTypeName;
  if (index == -1) {
    qualifiers = "";
    folderTypeName = dirName;
  } else {
    qualifiers = dirName.substring(index + 1);
    folderTypeName = dirName.substring(0, index);
  }
  ResourceFolderType folderType = ResourceFolderType.getTypeByName(folderTypeName);

  for (PsiResourceFile file : myResourceFiles.values()) {
    String name = file.getName();
    if (folderType == file.getFolderType() && fileName.equals(name) && qualifiers.equals(file.getQualifiers())) {
      return file;
    }
  }

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

示例14: isAvailable

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

示例15: forkResourceValue

import com.android.resources.ResourceFolderType; //导入依赖的package包/类
protected static void forkResourceValue(@NotNull Project project, @NotNull XmlTag tag, @NotNull PsiFile file,
                                        @NotNull AndroidFacet facet, @Nullable PsiDirectory dir) {

  PsiDirectory resFolder = findRes(file);
  if (resFolder == null) {
    return; // shouldn't happen; we checked in isAvailable
  }
  String name = tag.getAttributeValue(ATTR_NAME);
  ResourceType type = AndroidResourceUtil.getResourceForResourceTag(tag);
  if (name == null || type == null) {
    return; // shouldn't happen; we checked in isAvailable
  }
  if (dir == null) {
    dir = selectFolderDir(project, resFolder.getVirtualFile(), ResourceFolderType.VALUES);
  }
  if (dir != null) {
    String value = PsiResourceItem.getTextContent(tag).trim();
    createValueResource(file, facet, dir, name, value, type, tag.getText());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:OverrideResourceAction.java


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