Search in sources :

Example 46 with FolderConfiguration

use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.

the class ConfigurationTest method testListener.

public void testListener() throws Exception {
    final AndroidFacet facet = AndroidFacet.getInstance(myModule);
    assertNotNull(facet);
    ConfigurationManager manager = facet.getConfigurationManager();
    assertNotNull(manager);
    assertSame(manager, facet.getConfigurationManager());
    Configuration configuration = Configuration.create(manager, null, new FolderConfiguration());
    assertNotNull(configuration);
    ConfigurationListener listener = new ConfigurationListener() {

        @Override
        public boolean changed(int flags) {
            myFlags = flags;
            myChangeCount++;
            return true;
        }
    };
    configuration.addListener(listener);
    myChangeCount = 0;
    myFlags = 0;
    configuration.setTheme("@style/MyTheme");
    assertEquals(1, myChangeCount);
    assertEquals(CFG_THEME, myFlags);
    // No firing when no change:
    configuration.setTheme("@style/MyTheme");
    assertEquals(1, myChangeCount);
    assertEquals(CFG_THEME, myFlags);
    myChangeCount = 0;
    myFlags = 0;
    configuration.startBulkEditing();
    configuration.setTheme("@style/MyTheme2");
    assertEquals(0, myChangeCount);
    assertEquals(0, myFlags);
    configuration.setActivity("foo.bar.MyActivity");
    assertEquals(0, myChangeCount);
    assertEquals(0, myFlags);
    configuration.finishBulkEditing();
    assertEquals(1, myChangeCount);
    assertEquals(CFG_THEME | CFG_ACTIVITY, myFlags);
    myChangeCount = 0;
    myFlags = 0;
    configuration.startBulkEditing();
    configuration.setTheme("@style/MyTheme3");
    configuration.setActivity("foo.bar.MyActivity3");
    configuration.setNightMode(NightMode.NIGHT);
    configuration.finishBulkEditing();
    assertEquals(1, myChangeCount);
    assertEquals(CFG_THEME | CFG_ACTIVITY | CFG_NIGHT_MODE, myFlags);
}
Also used : ConfigurationListener(com.android.tools.idea.configurations.ConfigurationListener) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 47 with FolderConfiguration

use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.

the class OrientationMenuAction method getOrientation.

@NotNull
public static ScreenOrientation getOrientation(@NotNull State state) {
    FolderConfiguration config = DeviceConfigHelper.getFolderConfig(state);
    ScreenOrientation orientation = null;
    if (config != null && config.getScreenOrientationQualifier() != null) {
        orientation = config.getScreenOrientationQualifier().getValue();
    }
    if (orientation == null) {
        orientation = ScreenOrientation.PORTRAIT;
    }
    return orientation;
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) NotNull(org.jetbrains.annotations.NotNull)

Example 48 with FolderConfiguration

use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.

the class LocaleMenuAction method getRelevantLocales.

/**
   * Like {@link ConfigurationManager#getLocales} but filters out locales not compatible
   * with language and region qualifiers in the current configuration's folder config
   *
   * @return the list of relevant locales in the project
   */
@NotNull
private List<Locale> getRelevantLocales() {
    List<Locale> locales = new ArrayList<Locale>();
    Configuration configuration = myRenderContext.getConfiguration();
    if (configuration == null) {
        return Collections.emptyList();
    }
    Module module = configuration.getConfigurationManager().getModule();
    LocaleQualifier specificLocale = configuration.getEditedConfig().getLocaleQualifier();
    // locale.
    if (specificLocale != null) {
        List<VirtualFile> variations = ResourceHelper.getResourceVariations(configuration.getFile(), false);
        for (VirtualFile variation : variations) {
            FolderConfiguration config = FolderConfiguration.getConfigForFolder(variation.getParent().getName());
            if (config != null && config.getLocaleQualifier() == null) {
                specificLocale = null;
                break;
            }
        }
    }
    LocalResourceRepository projectResources = ProjectResourceRepository.getProjectResources(module, true);
    Set<LocaleQualifier> languages = projectResources != null ? projectResources.getLocales() : Collections.<LocaleQualifier>emptySet();
    for (LocaleQualifier l : languages) {
        if (specificLocale != null && !specificLocale.isMatchFor(l)) {
            continue;
        }
        locales.add(Locale.create(l));
    }
    return locales;
}
Also used : Locale(com.android.tools.idea.rendering.Locale) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) LocalResourceRepository(com.android.tools.idea.res.LocalResourceRepository) ArrayList(java.util.ArrayList) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Module(com.intellij.openapi.module.Module) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) NotNull(org.jetbrains.annotations.NotNull)

Example 49 with FolderConfiguration

use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.

the class GraphicalResourceRendererEditor method updateComponentInternal.

/**
   * Sets the UI state of the passed {@link ResourceComponent} based on the given {@link EditedStyleItem}
   */
private static void updateComponentInternal(@NotNull ResourceComponent component, @NotNull final EditedStyleItem item) {
    final String currentVariantColor = ColorUtil.toHex(ThemeEditorConstants.CURRENT_VARIANT_COLOR);
    final String notSelectedVariantColor = ColorUtil.toHex(ThemeEditorConstants.NOT_SELECTED_VARIANT_COLOR);
    FolderConfiguration restrictedConfig = RestrictedConfiguration.restrict(item.getSelectedItemResourceValue(), item.getAllConfiguredItems());
    String description = String.format(ThemeEditorConstants.CURRENT_VARIANT_TEMPLATE, currentVariantColor, item.getSelectedValueConfiguration().toShortDisplayString());
    VariantsComboItem selectedItem = new VariantsComboItem(description, restrictedConfig != null ? restrictedConfig : item.getSelectedValueConfiguration(), item.getSelectedValueConfiguration());
    // All the not selected elements are sorted alphabetically
    TreeSet<VariantsComboItem> notSelectedItems = Sets.newTreeSet(VARIANTS_COMBO_ITEM_COMPARATOR);
    for (ConfiguredElement<ItemResourceValue> configuredItem : item.getNonSelectedItemResourceValues()) {
        restrictedConfig = RestrictedConfiguration.restrict(configuredItem, item.getAllConfiguredItems());
        if (restrictedConfig == null) {
            // This type is not visible
            LOG.warn(String.format("For item '%1$s': Folder configuration '%2$s' can never be selected. There are no qualifiers combination that would allow selecting it.", item.getName(), configuredItem.getConfiguration()));
            continue;
        }
        description = String.format(ThemeEditorConstants.NOT_SELECTED_VARIANT_TEMPLATE, notSelectedVariantColor, configuredItem.getConfiguration().toShortDisplayString(), " - " + configuredItem.getElement().getValue());
        notSelectedItems.add(new VariantsComboItem(description, restrictedConfig, configuredItem.getConfiguration()));
    }
    ImmutableList<VariantsComboItem> variantList = ImmutableList.<VariantsComboItem>builder().add(selectedItem).addAll(notSelectedItems).build();
    component.setVariantsModel(new CollectionComboBoxModel<VariantsComboItem>(variantList, selectedItem));
}
Also used : ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) VariantsComboItem(com.android.tools.idea.editors.theme.attributes.variants.VariantsComboItem)

Example 50 with FolderConfiguration

use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.

the class ThemeAttributeResolver method resolveAll.

@NotNull
private List<EditedStyleItem> resolveAll() {
    ThemeEditorStyle theme = new ThemeEditorStyle(myManager, myStyle.getQualifiedName());
    for (FolderConfiguration folder : theme.getFolders()) {
        resolveFromInheritance(myStyle, folder, new RestrictedConfiguration(), new HashSet<String>());
    }
    List<EditedStyleItem> result = Lists.newArrayList();
    FolderConfiguration configuration = myStyle.getConfiguration().getFullConfig();
    for (String key : myItemValueMap.keySet()) {
        Collection<ConfiguredElement<ItemResourceValue>> itemValues = myItemValueMap.get(key);
        final ConfiguredElement<ItemResourceValue> selectedValue = (ConfiguredElement<ItemResourceValue>) configuration.findMatchingConfigurable(Lists.<Configurable>newArrayList(itemValues));
        if (selectedValue == null) {
            // TODO: there is NO value for this attribute in the current config,so instead we need to show "no value for current device"
            result.add(new EditedStyleItem(itemValues.iterator().next(), itemValues, myStyle));
        } else {
            itemValues.remove(selectedValue);
            assert !itemValues.contains(selectedValue);
            result.add(new EditedStyleItem(selectedValue, itemValues, myStyle));
        }
    }
    return result;
}
Also used : ConfiguredElement(com.android.tools.idea.editors.theme.datamodels.ConfiguredElement) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configurable(com.android.ide.common.resources.configuration.Configurable) RestrictedConfiguration(com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)69 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 NotNull (org.jetbrains.annotations.NotNull)14 VersionQualifier (com.android.ide.common.resources.configuration.VersionQualifier)12 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)12 Nullable (org.jetbrains.annotations.Nullable)12 ResourceItem (com.android.ide.common.res2.ResourceItem)10 LocaleQualifier (com.android.ide.common.resources.configuration.LocaleQualifier)10 DensityQualifier (com.android.ide.common.resources.configuration.DensityQualifier)9 ResourceFolderType (com.android.resources.ResourceFolderType)9 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)7 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 Project (com.intellij.openapi.project.Project)7 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)6 ResourceResolver (com.android.ide.common.resources.ResourceResolver)6 LayoutDirectionQualifier (com.android.ide.common.resources.configuration.LayoutDirectionQualifier)6 ScreenOrientationQualifier (com.android.ide.common.resources.configuration.ScreenOrientationQualifier)6 ScreenSizeQualifier (com.android.ide.common.resources.configuration.ScreenSizeQualifier)6 SessionParams (com.android.ide.common.rendering.api.SessionParams)5 CountryCodeQualifier (com.android.ide.common.resources.configuration.CountryCodeQualifier)5