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;
}
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;
}
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;
}
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);
}
}
}
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();
}
Aggregations