Search in sources :

Example 1 with VersionQualifier

use of com.android.ide.common.resources.configuration.VersionQualifier in project platform_frameworks_base by android.

the class ConfigGenerator method getFolderConfig.

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());
    return config;
}
Also used : VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) NavigationMethodQualifier(com.android.ide.common.resources.configuration.NavigationMethodQualifier) ScreenSizeQualifier(com.android.ide.common.resources.configuration.ScreenSizeQualifier) KeyboardStateQualifier(com.android.ide.common.resources.configuration.KeyboardStateQualifier) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) NightModeQualifier(com.android.ide.common.resources.configuration.NightModeQualifier) ScreenOrientationQualifier(com.android.ide.common.resources.configuration.ScreenOrientationQualifier) UiModeQualifier(com.android.ide.common.resources.configuration.UiModeQualifier) TouchScreenQualifier(com.android.ide.common.resources.configuration.TouchScreenQualifier) LayoutDirectionQualifier(com.android.ide.common.resources.configuration.LayoutDirectionQualifier) ScreenDimensionQualifier(com.android.ide.common.resources.configuration.ScreenDimensionQualifier) ScreenRatioQualifier(com.android.ide.common.resources.configuration.ScreenRatioQualifier) TextInputMethodQualifier(com.android.ide.common.resources.configuration.TextInputMethodQualifier) DensityQualifier(com.android.ide.common.resources.configuration.DensityQualifier) NetworkCodeQualifier(com.android.ide.common.resources.configuration.NetworkCodeQualifier) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) CountryCodeQualifier(com.android.ide.common.resources.configuration.CountryCodeQualifier)

Example 2 with VersionQualifier

use of com.android.ide.common.resources.configuration.VersionQualifier in project android_frameworks_base by ResurrectionRemix.

the class ConfigGenerator method getFolderConfig.

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());
    return config;
}
Also used : VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) NavigationMethodQualifier(com.android.ide.common.resources.configuration.NavigationMethodQualifier) ScreenSizeQualifier(com.android.ide.common.resources.configuration.ScreenSizeQualifier) KeyboardStateQualifier(com.android.ide.common.resources.configuration.KeyboardStateQualifier) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) NightModeQualifier(com.android.ide.common.resources.configuration.NightModeQualifier) ScreenOrientationQualifier(com.android.ide.common.resources.configuration.ScreenOrientationQualifier) UiModeQualifier(com.android.ide.common.resources.configuration.UiModeQualifier) TouchScreenQualifier(com.android.ide.common.resources.configuration.TouchScreenQualifier) LayoutDirectionQualifier(com.android.ide.common.resources.configuration.LayoutDirectionQualifier) ScreenDimensionQualifier(com.android.ide.common.resources.configuration.ScreenDimensionQualifier) ScreenRatioQualifier(com.android.ide.common.resources.configuration.ScreenRatioQualifier) TextInputMethodQualifier(com.android.ide.common.resources.configuration.TextInputMethodQualifier) DensityQualifier(com.android.ide.common.resources.configuration.DensityQualifier) NetworkCodeQualifier(com.android.ide.common.resources.configuration.NetworkCodeQualifier) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) CountryCodeQualifier(com.android.ide.common.resources.configuration.CountryCodeQualifier)

Example 3 with VersionQualifier

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

the class ThemeEditorUtils method showCreateNewStyleDialog.

/**
   * Creates a new style by displaying the dialog of the {@link NewStyleDialog}.
   * @param defaultParentStyle is used in NewStyleDialog, will be preselected in the parent text field and name will be suggested based on it
   * @param themeEditorContext  current theme editor context
   * @param isTheme whether theme or style will be created
   * @param message is used in NewStyleDialog to display message to user
   * @return the new style name or null if the style wasn't created
   */
@Nullable
public static String showCreateNewStyleDialog(@Nullable ConfiguredThemeEditorStyle defaultParentStyle, @NotNull final ThemeEditorContext themeEditorContext, boolean isTheme, boolean enableParentChoice, @Nullable final String message, @Nullable ThemeSelectionPanel.ThemeChangedListener themeChangedListener) {
    // if isTheme is true, defaultParentStyle shouldn't be null
    String defaultParentStyleName = null;
    if (isTheme && defaultParentStyle == null) {
        ImmutableList<String> defaultThemes = getDefaultThemeNames(themeEditorContext.getThemeResolver());
        defaultParentStyleName = !defaultThemes.isEmpty() ? defaultThemes.get(0) : null;
    } else if (defaultParentStyle != null) {
        defaultParentStyleName = defaultParentStyle.getQualifiedName();
    }
    final NewStyleDialog dialog = new NewStyleDialog(isTheme, themeEditorContext, defaultParentStyleName, (defaultParentStyle == null) ? null : defaultParentStyle.getName(), message);
    dialog.enableParentChoice(enableParentChoice);
    if (themeChangedListener != null) {
        dialog.setThemeChangedListener(themeChangedListener);
    }
    boolean createStyle = dialog.showAndGet();
    if (!createStyle) {
        return null;
    }
    int minModuleApi = getMinApiLevel(themeEditorContext.getCurrentContextModule());
    int minAcceptableApi = ResolutionUtils.getOriginalApiLevel(ResolutionUtils.getStyleResourceUrl(dialog.getStyleParentName()), themeEditorContext.getProject());
    final String fileName = AndroidResourceUtil.getDefaultResourceFileName(ResourceType.STYLE);
    FolderConfiguration config = new FolderConfiguration();
    if (minModuleApi < minAcceptableApi) {
        VersionQualifier qualifier = new VersionQualifier(minAcceptableApi);
        config.setVersionQualifier(qualifier);
    }
    if (fileName == null) {
        LOG.error("Couldn't find a default filename for ResourceType.STYLE");
        return null;
    }
    final List<String> dirNames = Collections.singletonList(config.getFolderName(ResourceFolderType.VALUES));
    String parentStyleName = dialog.getStyleParentName();
    Module module = themeEditorContext.getCurrentContextModule();
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        LOG.error("Create new style for non-Android module " + module.getName());
        return null;
    }
    Project project = module.getProject();
    VirtualFile resourceDir = facet.getPrimaryResourceDir();
    if (resourceDir == null) {
        AndroidUtils.reportError(project, AndroidBundle.message("check.resource.dir.error", module.getName()));
        return null;
    }
    boolean isCreated = createNewStyle(project, resourceDir, dialog.getStyleName(), parentStyleName, fileName, dirNames);
    return isCreated ? dialog.getStyleName() : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with VersionQualifier

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

the class ThemeEditorUtils method copyTheme.

/**
   * Copies a theme to a values folder with api version apiLevel,
   * potentially creating the necessary folder or file.
   * @param apiLevel api level of the folder the theme is copied to
   * @param toBeCopied theme to be copied
   */
public static void copyTheme(int apiLevel, @NotNull final XmlTag toBeCopied) {
    ApplicationManager.getApplication().assertWriteAccessAllowed();
    PsiFile file = toBeCopied.getContainingFile();
    assert file instanceof XmlFile : file;
    ResourceFolderType folderType = ResourceHelper.getFolderType(file);
    assert folderType != null : file;
    FolderConfiguration config = ResourceHelper.getFolderConfiguration(file);
    assert config != null : file;
    VersionQualifier qualifier = new VersionQualifier(apiLevel);
    config.setVersionQualifier(qualifier);
    String folder = config.getFolderName(folderType);
    if (folderType != ResourceFolderType.VALUES) {
        OverrideResourceAction.forkResourceFile((XmlFile) file, folder, false);
    } else {
        XmlTag tag = OverrideResourceAction.getValueTag(PsiTreeUtil.getParentOfType(toBeCopied, XmlTag.class, false));
        if (tag != null) {
            PsiDirectory dir = null;
            PsiDirectory resFolder = file.getParent();
            if (resFolder != null) {
                resFolder = resFolder.getParent();
            }
            if (resFolder != null) {
                dir = resFolder.findSubdirectory(folder);
                if (dir == null) {
                    dir = resFolder.createSubdirectory(folder);
                }
            }
            OverrideResourceAction.forkResourceValue(toBeCopied.getProject(), tag, file, dir, false);
        }
    }
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) ResourceFolderType(com.android.resources.ResourceFolderType) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) XmlTag(com.intellij.psi.xml.XmlTag)

Example 5 with VersionQualifier

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

the class ThemeEditorStyle method findToBeCopied.

/**
   * Finds best to be copied {@link FolderConfiguration}s
   * e.g if style is defined in "port-v8", "port-v18", "port-v22", "night-v20" and desiredApi = 21,
   * then result is {"port-v18", "night-v20"}
   *
   * @param desiredApi new api level of {@link FolderConfiguration}s after being copied
   * @return Collection of FolderConfigurations which are going to be copied to version desiredApi
   */
@NotNull
private ImmutableCollection<FolderConfiguration> findToBeCopied(int desiredApi) {
    // Keeps closest VersionQualifier to 'desiredApi'
    // e.g. desiredApi = 21, "en-port", "en-port-v18", "en-port-v19", "en-port-v22" then
    // bestVersionCopyFrom will contain {"en-port" -> v19}, as it is closest one to v21
    final HashMap<FolderConfiguration, VersionQualifier> bestVersionCopyFrom = Maps.newHashMap();
    for (ResourceItem styleItem : getStyleResourceItems()) {
        FolderConfiguration configuration = FolderConfiguration.copyOf(styleItem.getConfiguration());
        int styleItemVersion = ThemeEditorUtils.getVersionFromConfiguration(configuration);
        // We want to get the best from port-v19 port-v20 port-v23. so we need to remove the version qualifier to compare them
        configuration.setVersionQualifier(null);
        if (styleItemVersion > desiredApi) {
            // Thus, we don't need to copy it, we are going to just modify it.
            continue;
        }
        // If 'version' is closer to 'desiredApi' than we have found
        if (!bestVersionCopyFrom.containsKey(configuration) || bestVersionCopyFrom.get(configuration).getVersion() < styleItemVersion) {
            bestVersionCopyFrom.put(configuration, new VersionQualifier(styleItemVersion));
        }
    }
    ImmutableList.Builder<FolderConfiguration> toBeCopied = ImmutableList.builder();
    for (FolderConfiguration key : bestVersionCopyFrom.keySet()) {
        FolderConfiguration configuration = FolderConfiguration.copyOf(key);
        VersionQualifier version = bestVersionCopyFrom.get(key);
        if (version.getVersion() != -1) {
            configuration.setVersionQualifier(version);
        }
        // Version can't be bigger as we have filtered above
        if (version.getVersion() < desiredApi) {
            toBeCopied.add(configuration);
        }
    }
    return toBeCopied.build();
}
Also used : VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) ImmutableList(com.google.common.collect.ImmutableList) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) ResourceItem(com.android.ide.common.res2.ResourceItem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VersionQualifier (com.android.ide.common.resources.configuration.VersionQualifier)13 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)12 LocaleQualifier (com.android.ide.common.resources.configuration.LocaleQualifier)6 CountryCodeQualifier (com.android.ide.common.resources.configuration.CountryCodeQualifier)5 DensityQualifier (com.android.ide.common.resources.configuration.DensityQualifier)5 KeyboardStateQualifier (com.android.ide.common.resources.configuration.KeyboardStateQualifier)5 LayoutDirectionQualifier (com.android.ide.common.resources.configuration.LayoutDirectionQualifier)5 NavigationMethodQualifier (com.android.ide.common.resources.configuration.NavigationMethodQualifier)5 NetworkCodeQualifier (com.android.ide.common.resources.configuration.NetworkCodeQualifier)5 NightModeQualifier (com.android.ide.common.resources.configuration.NightModeQualifier)5 ScreenDimensionQualifier (com.android.ide.common.resources.configuration.ScreenDimensionQualifier)5 ScreenOrientationQualifier (com.android.ide.common.resources.configuration.ScreenOrientationQualifier)5 ScreenRatioQualifier (com.android.ide.common.resources.configuration.ScreenRatioQualifier)5 ScreenSizeQualifier (com.android.ide.common.resources.configuration.ScreenSizeQualifier)5 TextInputMethodQualifier (com.android.ide.common.resources.configuration.TextInputMethodQualifier)5 TouchScreenQualifier (com.android.ide.common.resources.configuration.TouchScreenQualifier)5 UiModeQualifier (com.android.ide.common.resources.configuration.UiModeQualifier)5 IAndroidTarget (com.android.sdklib.IAndroidTarget)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 ResourceFolderType (com.android.resources.ResourceFolderType)2