Java Code Examples for com.android.resources.ResourceFolderType#getTypeByName()

The following examples show how to use com.android.resources.ResourceFolderType#getTypeByName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: ResourceSet.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: ResourceSet.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a FolderData for the given folder.
 *
 * @param folder the folder.
 * @return the FolderData object, or null if we can't determine the {#link ResourceFolderType}
 * of the folder.
 */
@Nullable
private FolderData getFolderData(File folder) throws MergingException {
    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) {
            throw MergingException.withMessage("Invalid resource directory name")
                    .withFile(folder).build();
        }

        if (mNormalizeResources) {
            // 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;
}
 
Example 6
Source File: FullyQualifiedName.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static Qualifiers getQualifiers(Iterable<String> dirNameAndQualifiers) {
  PeekingIterator<String> rawQualifiers =
      Iterators.peekingIterator(dirNameAndQualifiers.iterator());
  // Remove directory name
  final ResourceFolderType folderType = ResourceFolderType.getTypeByName(rawQualifiers.next());

  // If there is no folder type, there are no qualifiers to parse.
  if (folderType == null) {
    return EMPTY_QUALIFIERS;
  }

  List<String> handledQualifiers = new ArrayList<>();
  // Do some substitution of language/region qualifiers.
  while (rawQualifiers.hasNext()) {
    handledQualifiers.add(rawQualifiers.next());
  }
  // Create a configuration
  FolderConfiguration config = FolderConfiguration.getConfigFromQualifiers(handledQualifiers);
  // FolderConfiguration returns an unhelpful null when it considers the qualifiers to be
  // invalid.
  if (config == null) {
    throw new IllegalArgumentException(
        String.format(INVALID_QUALIFIERS, DASH_JOINER.join(dirNameAndQualifiers)));
  }
  config.normalize();

  ImmutableList.Builder<String> builder = ImmutableList.<String>builder();
  // index 3 is past the country code, network code, and locale indices.
  for (int i = 0; i < FolderConfiguration.getQualifierCount(); ++i) {
    addIfNotNull(config.getQualifier(i), builder);
  }
  return new Qualifiers(folderType, builder.build(), config.getLocaleQualifier() == null);
}