Java Code Examples for com.android.ide.common.resources.configuration.FolderConfiguration

The following examples show how to use com.android.ide.common.resources.configuration.FolderConfiguration. These examples are extracted from open source projects. 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
/**
 * Returns the resources values matching a given {@link FolderConfiguration}.
 *
 * @param referenceConfig the configuration that each value must match.
 * @return a map with guaranteed to contain an entry for each {@link ResourceType}
 */
@NonNull
public Map<ResourceType, Map<String, ResourceValue>> getConfiguredResources(
        @NonNull FolderConfiguration referenceConfig) {
    Map<ResourceType, Map<String, ResourceValue>> map = Maps.newEnumMap(ResourceType.class);

    synchronized (ITEM_MAP_LOCK) {
        Map<ResourceType, ListMultimap<String, ResourceItem>> itemMap = getMap();
        for (ResourceType key : ResourceType.values()) {
            // get the local results and put them in the map
            map.put(key, getConfiguredResources(itemMap, key, referenceConfig));
        }
    }

    return map;
}
 
Example 2
Source Project: NBANDROID-V2   Source File: ResourceRepository.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the sorted list of languages used in the resources.
 */
@NonNull
public SortedSet<String> getLanguages() {
    ensureInitialized();

    SortedSet<String> set = new TreeSet<String>();

    Collection<List<ResourceFolder>> folderList = mFolderMap.values();
    for (List<ResourceFolder> folderSubList : folderList) {
        for (ResourceFolder folder : folderSubList) {
            FolderConfiguration config = folder.getConfiguration();
            LocaleQualifier locale = config.getLocaleQualifier();
            if (locale != null && locale.hasLanguage()) {
                set.add(locale.getLanguage());
            }
        }
    }

    return set;
}
 
Example 3
Source Project: java-n-IDE-for-Android   Source File: ResourceRepository.java    License: 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 Project: java-n-IDE-for-Android   Source File: ResourceRepository.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source Project: java-n-IDE-for-Android   Source File: ResourceRepository.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the list of source files for a given resource.
 * Optionally, if a {@link FolderConfiguration} is given, then only the best
 * match for this config is returned.
 *
 * @param type the type of the resource.
 * @param name the name of the resource.
 * @param referenceConfig an optional config for which only the best match will be returned.
 *
 * @return a list of files generating this resource or null if it was not found.
 */
@Nullable
public List<ResourceFile> getSourceFiles(@NonNull ResourceType type, @NonNull String name,
        @Nullable FolderConfiguration referenceConfig) {
    ensureInitialized();

    Collection<ResourceItem> items = getResourceItemsOfType(type);

    for (ResourceItem item : items) {
        if (name.equals(item.getName())) {
            if (referenceConfig != null) {
                Configurable match = referenceConfig.findMatchingConfigurable(
                        item.getSourceFileList());

                if (match instanceof ResourceFile) {
                    return Collections.singletonList((ResourceFile) match);
                }

                return null;
            }
            return item.getSourceFileList();
        }
    }

    return null;
}
 
Example 6
Source Project: java-n-IDE-for-Android   Source File: ResourceRepository.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the resources values matching a given {@link FolderConfiguration} for the current
 * project.
 *
 * @param referenceConfig the configuration that each value must match.
 * @return a map with guaranteed to contain an entry for each {@link ResourceType}
 */
@NonNull
protected final Map<ResourceType, Map<String, ResourceValue>> doGetConfiguredResources(
        @NonNull FolderConfiguration referenceConfig) {
    ensureInitialized();

    Map<ResourceType, Map<String, ResourceValue>> map =
        new EnumMap<ResourceType, Map<String, ResourceValue>>(ResourceType.class);

    for (ResourceType key : ResourceType.values()) {
        // get the local results and put them in the map
        map.put(key, getConfiguredResource(key, referenceConfig));
    }

    return map;
}
 
Example 7
Source Project: java-n-IDE-for-Android   Source File: ResourceRepository.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the sorted list of languages used in the resources.
 */
@NonNull
public SortedSet<String> getLanguages() {
    ensureInitialized();

    SortedSet<String> set = new TreeSet<String>();

    Collection<List<ResourceFolder>> folderList = mFolderMap.values();
    for (List<ResourceFolder> folderSubList : folderList) {
        for (ResourceFolder folder : folderSubList) {
            FolderConfiguration config = folder.getConfiguration();
            LanguageQualifier lang = config.getLanguageQualifier();
            if (lang != null) {
                set.add(lang.getShortDisplayValue());
            }
        }
    }

    return set;
}
 
Example 8
Source Project: java-n-IDE-for-Android   Source File: ResourceRepository.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the sorted list of regions used in the resources with the given language.
 * @param currentLanguage the current language the region must be associated with.
 */
@NonNull
public SortedSet<String> getRegions(@NonNull String currentLanguage) {
    ensureInitialized();

    SortedSet<String> set = new TreeSet<String>();

    Collection<List<ResourceFolder>> folderList = mFolderMap.values();
    for (List<ResourceFolder> folderSubList : folderList) {
        for (ResourceFolder folder : folderSubList) {
            FolderConfiguration config = folder.getConfiguration();

            // get the language
            LanguageQualifier lang = config.getLanguageQualifier();
            if (lang != null && lang.getShortDisplayValue().equals(currentLanguage)) {
                RegionQualifier region = config.getRegionQualifier();
                if (region != null) {
                    set.add(region.getShortDisplayValue());
                }
            }
        }
    }

    return set;
}
 
Example 9
Source Project: java-n-IDE-for-Android   Source File: ResourceRepository.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns a map of (resource name, resource value) for the given {@link ResourceType}.
 * <p/>The values returned are taken from the resource files best matching a given
 * {@link FolderConfiguration}.
 * @param type the type of the resources.
 * @param referenceConfig the configuration to best match.
 */
@NonNull
private Map<String, ResourceValue> getConfiguredResource(@NonNull ResourceType type,
        @NonNull FolderConfiguration referenceConfig) {

    // get the resource item for the given type
    Map<String, ResourceItem> items = mResourceMap.get(type);
    if (items == null) {
        return new HashMap<String, ResourceValue>();
    }

    // create the map
    HashMap<String, ResourceValue> map = new HashMap<String, ResourceValue>(items.size());

    for (ResourceItem item : items.values()) {
        ResourceValue value = item.getResourceValue(type, referenceConfig,
                isFrameworkRepository());
        if (value != null) {
            map.put(item.getName(), value);
        }
    }

    return map;
}
 
Example 10
Source Project: javaide   Source File: TranslationDetector.java    License: GNU General Public License v3.0 6 votes vote down vote up
/** Look up the language for the given folder name */
private static String getLanguageTag(String name) {
    if (FD_RES_VALUES.equals(name)) {
        return null;
    }

    FolderConfiguration configuration = FolderConfiguration.getConfigForFolder(name);
    if (configuration != null) {
      LocaleQualifier locale = configuration.getLocaleQualifier();
      if (locale != null && !locale.hasFakeValue()) {
          return locale.getTag();
      }
    }

    return null;
}
 
Example 11
Source Project: intellij   Source File: GeneratedResourceClassifier.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 12
Source Project: javaide   Source File: RenderServiceFactory.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a {@link ResourceResolver} for a given config and project resource.
 *
 * @param config
 * @param projectResources
 * @param themeName
 * @param isProjectTheme
 * @return
 */
public ResourceResolver createResourceResolver(
        FolderConfiguration config,
        ResourceRepository projectResources,
        String themeName,
        boolean isProjectTheme) {

    Map<ResourceType, Map<String, ResourceValue>> configedProjectRes =
            projectResources.getConfiguredResources(config);

    Map<ResourceType, Map<String, ResourceValue>> configedFrameworkRes =
            mResources.getConfiguredResources(config);

    return ResourceResolver.create(configedProjectRes, configedFrameworkRes,
            themeName, isProjectTheme);
}
 
Example 13
/**
 * Returns the resources values matching a given {@link FolderConfiguration}.
 *
 * @param referenceConfig the configuration that each value must match.
 * @return a map with guaranteed to contain an entry for each {@link ResourceType}
 */
@NonNull
public Map<ResourceType, Map<String, ResourceValue>> getConfiguredResources(
        @NonNull FolderConfiguration referenceConfig) {
    Map<ResourceType, Map<String, ResourceValue>> map = Maps.newEnumMap(ResourceType.class);

    synchronized (ITEM_MAP_LOCK) {
        Map<ResourceType, ListMultimap<String, ResourceItem>> itemMap = getMap();
        for (ResourceType key : ResourceType.values()) {
            // get the local results and put them in the map
            map.put(key, getConfiguredResources(itemMap, key, referenceConfig));
        }
    }

    return map;
}
 
Example 14
@Nullable
public ResourceValue getConfiguredValue(
        @NonNull ResourceType type,
        @NonNull String name,
        @NonNull FolderConfiguration referenceConfig) {
    // get the resource item for the given type
    ListMultimap<String, ResourceItem> items = getMap(type, false);
    if (items == null) {
        return null;
    }

    List<ResourceItem> keyItems = items.get(name);
    if (keyItems == null) {
        return null;
    }

    // look for the best match for the given configuration
    // the match has to be of type ResourceFile since that's what the input list contains
    ResourceItem match = (ResourceItem) referenceConfig.findMatchingConfigurable(keyItems);
    return match != null ? match.getResourceValue(mFramework) : null;
}
 
Example 15
Source Project: NBANDROID-V2   Source File: ResourceRepository.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the resources values matching a given {@link FolderConfiguration} for the current
 * project.
 *
 * @param referenceConfig the configuration that each value must match.
 * @return a map with guaranteed to contain an entry for each {@link ResourceType}
 */
@NonNull
protected final Map<ResourceType, ResourceValueMap> doGetConfiguredResources(
        @NonNull FolderConfiguration referenceConfig) {
    ensureInitialized();

    Map<ResourceType, ResourceValueMap> map =
        new EnumMap<ResourceType, ResourceValueMap>(ResourceType.class);

    for (ResourceType key : ResourceType.values()) {
        // get the local results and put them in the map
        map.put(key, getConfiguredResource(key, referenceConfig));
    }

    return map;
}
 
Example 16
Source Project: javaide   Source File: ResourceRepository.java    License: 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 17
Source Project: javaide   Source File: ResourceRepository.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source Project: javaide   Source File: ResourceRepository.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the list of source files for a given resource.
 * Optionally, if a {@link FolderConfiguration} is given, then only the best
 * match for this config is returned.
 *
 * @param type the type of the resource.
 * @param name the name of the resource.
 * @param referenceConfig an optional config for which only the best match will be returned.
 *
 * @return a list of files generating this resource or null if it was not found.
 */
@Nullable
public List<ResourceFile> getSourceFiles(@NonNull ResourceType type, @NonNull String name,
        @Nullable FolderConfiguration referenceConfig) {
    ensureInitialized();

    Collection<ResourceItem> items = getResourceItemsOfType(type);

    for (ResourceItem item : items) {
        if (name.equals(item.getName())) {
            if (referenceConfig != null) {
                Configurable match = referenceConfig.findMatchingConfigurable(
                        item.getSourceFileList());

                if (match instanceof ResourceFile) {
                    return Collections.singletonList((ResourceFile) match);
                }

                return null;
            }
            return item.getSourceFileList();
        }
    }

    return null;
}
 
Example 19
Source Project: intellij   Source File: BlazeNewResourceCreationHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CreateResourceFileDialogBase createNewResourceFileDialog(
    AndroidFacet facet,
    Collection<CreateTypedResourceFileAction> actions,
    @Nullable ResourceFolderType folderType,
    @Nullable String filename,
    @Nullable String rootElement,
    @Nullable FolderConfiguration folderConfiguration,
    boolean chooseFileName,
    boolean chooseModule,
    @Nullable PsiDirectory resDirectory,
    @Nullable DataContext dataContext,
    CreateResourceFileDialogBase.ValidatorFactory validatorFactory) {
  return new BlazeCreateResourceFileDialog(
      facet,
      actions,
      folderType,
      filename,
      rootElement,
      folderConfiguration,
      chooseFileName,
      chooseModule,
      resDirectory,
      dataContext,
      validatorFactory);
}
 
Example 20
Source Project: javaide   Source File: ResourceRepository.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the sorted list of languages used in the resources.
 */
@NonNull
public SortedSet<String> getLanguages() {
    ensureInitialized();

    SortedSet<String> set = new TreeSet<String>();

    Collection<List<ResourceFolder>> folderList = mFolderMap.values();
    for (List<ResourceFolder> folderSubList : folderList) {
        for (ResourceFolder folder : folderSubList) {
            FolderConfiguration config = folder.getConfiguration();
            LocaleQualifier locale = config.getLocaleQualifier();
            if (locale != null) {
                set.add(locale.getLanguage());
            }
        }
    }

    return set;
}
 
Example 21
Source Project: javaide   Source File: ResourceRepository.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the sorted list of regions used in the resources with the given language.
 * @param currentLanguage the current language the region must be associated with.
 */
@NonNull
public SortedSet<String> getRegions(@NonNull String currentLanguage) {
    ensureInitialized();

    SortedSet<String> set = new TreeSet<String>();

    Collection<List<ResourceFolder>> folderList = mFolderMap.values();
    for (List<ResourceFolder> folderSubList : folderList) {
        for (ResourceFolder folder : folderSubList) {
            FolderConfiguration config = folder.getConfiguration();

            // get the language
            LocaleQualifier locale = config.getLocaleQualifier();
            if (locale != null && currentLanguage.equals(locale.getLanguage())
                    && locale.getRegion() != null) {
                set.add(locale.getRegion());
            }
        }
    }

    return set;
}
 
Example 22
Source Project: javaide   Source File: ResourceRepository.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a map of (resource name, resource value) for the given {@link ResourceType}.
 * <p/>The values returned are taken from the resource files best matching a given
 * {@link FolderConfiguration}.
 * @param type the type of the resources.
 * @param referenceConfig the configuration to best match.
 */
@NonNull
private Map<String, ResourceValue> getConfiguredResource(@NonNull ResourceType type,
        @NonNull FolderConfiguration referenceConfig) {

    // get the resource item for the given type
    Map<String, ResourceItem> items = mResourceMap.get(type);
    if (items == null) {
        return new HashMap<String, ResourceValue>();
    }

    // create the map
    HashMap<String, ResourceValue> map = new HashMap<String, ResourceValue>(items.size());

    for (ResourceItem item : items.values()) {
        ResourceValue value = item.getResourceValue(type, referenceConfig,
                isFrameworkRepository());
        if (value != null) {
            map.put(item.getName(), value);
        }
    }

    return map;
}
 
Example 23
Source Project: NBANDROID-V2   Source File: ResourceRepository.java    License: 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 24
Source Project: NBANDROID-V2   Source File: ResourceRepository.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 25
Source Project: NBANDROID-V2   Source File: ResourceRepository.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns a map of (resource name, resource value) for the given {@link ResourceType}.
 * <p>The values returned are taken from the resource files best matching a given
 * {@link FolderConfiguration}.
 *
 * @param type the type of the resources.
 * @param referenceConfig the configuration to best match.
 */
@NonNull
private ResourceValueMap getConfiguredResource(@NonNull ResourceType type,
        @NonNull FolderConfiguration referenceConfig) {
    // get the resource item for the given type
    Map<String, ResourceItem> items = mResourceMap.get(type);
    if (items == null) {
        return ResourceValueMap.create();
    }

    // create the map
    ResourceValueMap map = ResourceValueMap.createWithExpectedSize(items.size());

    for (ResourceItem item : items.values()) {
        ResourceValue value = item.getResourceValue(type, referenceConfig,
                isFrameworkRepository());
        if (value != null) {
            map.put(item.getName(), value);
        }
    }

    return map;
}
 
Example 26
Source Project: java-n-IDE-for-Android   Source File: ResourceSet.java    License: 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 27
Source Project: java-n-IDE-for-Android   Source File: ResourceItem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FolderConfiguration getConfiguration() {
    String qualifier = getQualifiers();
    if (qualifier.isEmpty()) {
        return new FolderConfiguration();
    }

    return FolderConfiguration.getConfigFromQualifiers(Splitter.on('-').split(qualifier));
}
 
Example 28
Source Project: java-n-IDE-for-Android   Source File: ResourceItem.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private Density getFolderDensity() {
    String qualifiers = getQualifiers();
    if (!qualifiers.isEmpty() && qualifiers.contains("dpi")) {
        Iterable<String> segments = Splitter.on('-').split(qualifiers);
        FolderConfiguration config = FolderConfiguration.getConfigFromQualifiers(segments);
        if (config != null) {
            DensityQualifier densityQualifier = config.getDensityQualifier();
            if (densityQualifier != null) {
                return densityQualifier.getValue();
            }
        }
    }
    return null;
}
 
Example 29
@NonNull
public Map<String, ResourceValue> getConfiguredResources(
        @NonNull Map<ResourceType, ListMultimap<String, ResourceItem>> itemMap,
        @NonNull ResourceType type,
        @NonNull FolderConfiguration referenceConfig) {
    // get the resource item for the given type
    ListMultimap<String, ResourceItem> items = itemMap.get(type);
    if (items == null) {
        return Maps.newHashMap();
    }

    Set<String> keys = items.keySet();

    // create the map
    Map<String, ResourceValue> map = Maps.newHashMapWithExpectedSize(keys.size());

    for (String key : keys) {
        List<ResourceItem> keyItems = items.get(key);

        // look for the best match for the given configuration
        // the match has to be of type ResourceFile since that's what the input list contains
        ResourceItem match = (ResourceItem) referenceConfig.findMatchingConfigurable(keyItems);
        if (match != null) {
            ResourceValue value = match.getResourceValue(mFramework);
            if (value != null) {
                map.put(match.getName(), value);
            }
        }
    }

    return map;
}
 
Example 30
Source Project: NBANDROID-V2   Source File: ConfigGenerator.java    License: Apache License 2.0 5 votes vote down vote up
public FolderConfiguration getFolderConfig() {
    FolderConfiguration config = new FolderConfiguration();
    // config.createDefault();
    config.setDensityQualifier(new DensityQualifier(mDensity));
    config.setNavigationMethodQualifier(new NavigationMethodQualifier(mNavigation));
    if (mScreenWidth > mScreenHeight) {
        config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenWidth,
                mScreenHeight));
    } else {
        config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenHeight,
                mScreenWidth));
    }
    config.setScreenRatioQualifier(new ScreenRatioQualifier(mRatio));
    config.setScreenSizeQualifier(new ScreenSizeQualifier(mSize));
    config.setTextInputMethodQualifier(new TextInputMethodQualifier(mKeyboard));
    config.setTouchTypeQualifier(new TouchScreenQualifier(mTouchScreen));
    config.setKeyboardStateQualifier(new KeyboardStateQualifier(mKeyboardState));
    config.setScreenOrientationQualifier(new ScreenOrientationQualifier(mOrientation));

    config.updateScreenWidthAndHeight();

    // some default qualifiers.
    config.setUiModeQualifier(new UiModeQualifier(UiMode.NORMAL));
    config.setNightModeQualifier(new NightModeQualifier(NightMode.NOTNIGHT));
    config.setCountryCodeQualifier(new CountryCodeQualifier());
    config.setLayoutDirectionQualifier(new LayoutDirectionQualifier());
    config.setNetworkCodeQualifier(new NetworkCodeQualifier());
    config.setLocaleQualifier(new LocaleQualifier());
    config.setVersionQualifier(new VersionQualifier(28));
    return config;
}