use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class TargetMenuAction method updatePresentation.
private void updatePresentation(Presentation presentation) {
Configuration configuration = myRenderContext.getConfiguration();
boolean visible = configuration != null;
if (visible) {
IAndroidTarget target = configuration.getTarget();
String brief = getRenderingTargetLabel(target, true);
presentation.setText(brief);
}
if (visible != presentation.isVisible()) {
presentation.setVisible(visible);
}
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class ConfigurationMatcher method findAndSetCompatibleConfig.
/**
* Finds a device/config that can display a configuration.
* <p/>
* Once found the device and config combos are set to the config.
* <p/>
* If there is no compatible configuration, a custom one is created.
*
* @param favorCurrentConfig if true, and no best match is found, don't
* change the current config. This must only be true if the
* current config is compatible.
*/
void findAndSetCompatibleConfig(boolean favorCurrentConfig) {
List<Locale> localeList = getPrioritizedLocales();
List<Device> deviceList = myManager.getDevices();
FolderConfiguration editedConfig = myConfiguration.getEditedConfig();
FolderConfiguration currentConfig = myConfiguration.getFullConfig();
// list of compatible device/state/locale
List<ConfigMatch> anyMatches = new ArrayList<ConfigMatch>();
// list of actual best match (ie the file is a best match for the
// device/state)
List<ConfigMatch> bestMatches = new ArrayList<ConfigMatch>();
// get a locale that matches the host locale roughly (may not be exact match on the region.)
int localeHostMatch = getLocaleMatch();
// build a list of combinations of non standard qualifiers to add to each device's
// qualifier set when testing for a match.
// These qualifiers are: locale, night-mode, car dock.
List<ConfigBundle> configBundles = new ArrayList<ConfigBundle>(200);
// If the edited file has locales, then we have to select a matching locale from
// the list.
// However, if it doesn't, we don't randomly take the first locale, we take one
// matching the current host locale (making sure it actually exist in the project)
int start, max;
if (editedConfig.getLocaleQualifier() != null || localeHostMatch == -1) {
// add all the locales
start = 0;
max = localeList.size();
} else {
// only add the locale host match
start = localeHostMatch;
// test is <
max = localeHostMatch + 1;
}
for (int i = start; i < max; i++) {
Locale l = localeList.get(i);
ConfigBundle bundle = new ConfigBundle();
bundle.config.setLocaleQualifier(l.qualifier);
bundle.localeIndex = i;
configBundles.add(bundle);
}
// add the dock mode to the bundle combinations.
addDockModeToBundles(configBundles);
// add the night mode to the bundle combinations.
addNightModeToBundles(configBundles);
addRenderTargetToBundles(configBundles);
Locale currentLocale = myConfiguration.getLocale();
IAndroidTarget currentTarget = myConfiguration.getTarget();
Module module = myConfiguration.getModule();
for (Device device : deviceList) {
for (State state : device.getAllStates()) {
// loop on the list of config bundles to create full
// configurations.
FolderConfiguration stateConfig = Configuration.getFolderConfig(module, state, currentLocale, currentTarget);
for (ConfigBundle bundle : configBundles) {
// create a new config with device config
FolderConfiguration testConfig = new FolderConfiguration();
testConfig.set(stateConfig);
// add on top of it, the extra qualifiers from the bundle
testConfig.add(bundle.config);
if (editedConfig.isMatchFor(testConfig)) {
// this is a basic match. record it in case we don't
// find a match
// where the edited file is a best config.
anyMatches.add(new ConfigMatch(testConfig, device, state, bundle));
if (isCurrentFileBestMatchFor(testConfig)) {
// this is what we want.
bestMatches.add(new ConfigMatch(testConfig, device, state, bundle));
}
}
}
}
}
if (bestMatches.size() == 0) {
if (favorCurrentConfig) {
// quick check
if (!editedConfig.isMatchFor(currentConfig)) {
LOG.warn("favorCurrentConfig can only be true if the current config is compatible");
}
// just display the warning
LOG.warn(String.format("'%1$s' is not a best match for any device/locale combination for %2$s.\n" + "Displaying it with '%3$s'.", editedConfig.toDisplayString(), myConfiguration.getFile(), currentConfig.toDisplayString()));
} else if (anyMatches.size() > 0) {
// select the best device anyway.
ConfigMatch match = selectConfigMatch(anyMatches);
myConfiguration.startBulkEditing();
myConfiguration.setEffectiveDevice(match.device, match.state);
myConfiguration.setUiMode(UiMode.getByIndex(match.bundle.dockModeIndex));
myConfiguration.setNightMode(NightMode.getByIndex(match.bundle.nightModeIndex));
myConfiguration.finishBulkEditing();
// TODO: display a better warning!
LOG.warn(String.format("'%1$s' is not a best match for any device/locale combination for %2$s.\n" + "Displaying it with\n" + " %3$s\n" + "which is compatible, but will actually be displayed with " + "another more specific version of the layout.", editedConfig.toDisplayString(), myConfiguration.getFile(), currentConfig.toDisplayString()));
} else {
// TODO: there is no device/config able to display the layout, create one.
// For the base config values, we'll take the first device and state,
// and replace whatever qualifier required by the layout file.
}
} else {
ConfigMatch match = selectConfigMatch(bestMatches);
myConfiguration.startBulkEditing();
myConfiguration.setEffectiveDevice(match.device, match.state);
myConfiguration.setUiMode(UiMode.getByIndex(match.bundle.dockModeIndex));
myConfiguration.setNightMode(NightMode.getByIndex(match.bundle.nightModeIndex));
myConfiguration.finishBulkEditing();
}
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class TargetMenuAction method addCompatibilityTargets.
private void addCompatibilityTargets(@NotNull DefaultActionGroup group) {
Configuration configuration = myRenderContext.getConfiguration();
assert configuration != null;
IAndroidTarget currentTarget = configuration.getTarget();
IAndroidTarget highestTarget = configuration.getConfigurationManager().getHighestApiTarget();
assert highestTarget != null;
int highestApiLevel = highestTarget.getVersion().getFeatureLevel();
int minApi = Math.max(getMinSdkVersion(), SHOW_FROM_API_LEVEL);
for (int apiLevel = highestApiLevel; apiLevel >= minApi; apiLevel--) {
IAndroidTarget target = new CompatibilityRenderTarget(highestTarget, apiLevel, null);
boolean isSelected = target.getVersion().equals(currentTarget.getVersion());
group.add(new SetTargetAction(myRenderContext, target.getVersionName(), target, isSelected));
}
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class EditedStyleItem method isPublicAttribute.
public boolean isPublicAttribute() {
if (!getSelectedValue().isFrameworkAttr()) {
return true;
}
Configuration configuration = mySourceTheme.getConfiguration();
IAndroidTarget target = configuration.getRealTarget();
if (target == null) {
LOG.error("Unable to get IAndroidTarget.");
return false;
}
AndroidTargetData androidTargetData = AndroidTargetData.getTargetData(target, configuration.getModule());
if (androidTargetData == null) {
LOG.error("Unable to get AndroidTargetData.");
return false;
}
return androidTargetData.isResourcePublic(ResourceType.ATTR.getName(), getName());
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class ThemeEditorStyle method getParentName.
/**
* @param configuration FolderConfiguration of the style to lookup
* @return parent this style with a FolderConfiguration configuration
*/
@Nullable
public /*if there is no of this style*/
String getParentName(@NotNull FolderConfiguration configuration) {
if (isFramework()) {
IAndroidTarget target = myManager.getHighestApiTarget();
assert target != null;
com.android.ide.common.resources.ResourceItem styleItem = myManager.getResolverCache().getFrameworkResources(new FolderConfiguration(), target).getResourceItem(ResourceType.STYLE, getName());
for (ResourceFile file : styleItem.getSourceFileList()) {
if (file.getConfiguration().equals(configuration)) {
StyleResourceValue style = (StyleResourceValue) file.getValue(ResourceType.STYLE, getName());
return ResolutionUtils.getParentQualifiedName(style);
}
}
throw new IllegalArgumentException("bad folder config " + configuration);
}
for (final ResourceItem styleItem : getStyleResourceItems()) {
if (configuration.equals(styleItem.getConfiguration())) {
StyleResourceValue style = (StyleResourceValue) styleItem.getResourceValue(false);
assert style != null;
return ResolutionUtils.getParentQualifiedName(style);
}
}
throw new IllegalArgumentException("bad folder config " + configuration);
}
Aggregations