use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class ConfigurationTest method test.
public void test() 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);
configuration.startBulkEditing();
configuration.setDisplayName("myconfig");
configuration.setTheme("@style/Theme1");
configuration.setNightMode(NightMode.NIGHT);
configuration.setActivity("tes.tpkg.MyActivity1");
configuration.setUiMode(UiMode.TELEVISION);
IAndroidTarget target = configuration.getConfigurationManager().getTarget();
Device device = configuration.getConfigurationManager().getDefaultDevice();
State deviceState = device != null ? device.getState("Portrait") : null;
if (target != null) {
configuration.setTarget(target);
}
if (device != null) {
configuration.setDevice(device, false);
assertNotNull(deviceState);
configuration.setDeviceState(deviceState);
}
configuration.setLocale(Locale.create("en-rUS"));
configuration.finishBulkEditing();
assertEquals("myconfig", configuration.getDisplayName());
assertEquals("@style/Theme1", configuration.getTheme());
assertEquals(NightMode.NIGHT, configuration.getNightMode());
assertEquals("tes.tpkg.MyActivity1", configuration.getActivity());
assertEquals(UiMode.TELEVISION, configuration.getUiMode());
assertEquals(Locale.create("en-rUS"), configuration.getLocale());
if (target != null) {
assertSame(target, configuration.getRealTarget());
}
if (device != null) {
assertSame(device, configuration.getDevice());
assertNotNull(deviceState);
assertSame(deviceState, configuration.getDeviceState());
}
FolderConfiguration fullConfig = configuration.getFullConfig();
LocaleQualifier languageQualifier = fullConfig.getLocaleQualifier();
String configDisplayString = fullConfig.toDisplayString();
assertNotNull(configDisplayString, languageQualifier);
assertEquals("en", languageQualifier.getLanguage());
String region = fullConfig.getLocaleQualifier().getRegion();
assertNotNull(configDisplayString, region);
assertEquals("US", region);
assertEquals(UiMode.TELEVISION, fullConfig.getUiModeQualifier().getValue());
assertEquals(NightMode.NIGHT, fullConfig.getNightModeQualifier().getValue());
assertEquals(ScreenOrientation.PORTRAIT, fullConfig.getScreenOrientationQualifier().getValue());
if (device != null) {
State landscape = device.getState("Landscape");
assertNotNull(landscape);
configuration.setDeviceState(landscape);
assertEquals(ScreenOrientation.LANDSCAPE, configuration.getFullConfig().getScreenOrientationQualifier().getValue());
}
Density density = configuration.getDensity();
assertEquals(Density.XHIGH, density);
DensityQualifier qualifier = new DensityQualifier().getNullQualifier();
configuration.getFullConfig().setDensityQualifier(qualifier);
density = configuration.getDensity();
assertEquals(Density.MEDIUM, density);
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class ConfigurationMenuAction method hasCapability.
private static boolean hasCapability(EditorDesignSurface context, int capability) {
Configuration configuration = context.getConfiguration();
if (configuration == null) {
return false;
}
boolean enabled = false;
Module module = configuration.getModule();
if (module != null) {
IAndroidTarget target = configuration.getTarget();
if (target != null) {
LayoutLibrary library = RenderService.getLayoutLibrary(module, target);
enabled = library != null && library.supports(capability);
}
}
return enabled;
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class ResourceResolverCache method getResourceResolver.
@NotNull
public ResourceResolver getResourceResolver(@Nullable IAndroidTarget target, @NotNull String themeStyle, @NotNull final FolderConfiguration fullConfiguration) {
// Are caches up to date?
final LocalResourceRepository resources = AppResourceRepository.getAppResources(myManager.getModule(), true);
assert resources != null;
if (myCachedGeneration != resources.getModificationCount()) {
myResolverMap.clear();
myAppResourceMap.clear();
}
// Store the modification count as soon as possible. This ensures that if there is any modification of resources while the
// resolver is being created, it will be cleared subsequently.
myCachedGeneration = resources.getModificationCount();
// When looking up the configured project and framework resources, the theme doesn't matter, so we look up only
// by the configuration qualifiers; for example, here's a sample key:
// -ldltr-sw384dp-w384dp-h640dp-normal-notlong-port-notnight-xhdpi-finger-keyssoft-nokeys-navhidden-nonav-1280x768-v17
// Note that the target version is already baked in via the -v qualifier.
//
// However, the resource resolver also depends on the theme, so we use a more specific key for the resolver map than
// for the configured resource maps, by prepending the theme name:
// @style/MyTheme-ldltr-sw384dp-w384dp-h640dp-normal-notlong-port-notnight-xhdpi-finger-keyssoft-nokeys-navhidden-nonav-1280x768-v17
String configurationKey = fullConfiguration.getUniqueKey();
String resolverKey = themeStyle + configurationKey;
ResourceResolver resolver = myResolverMap.get(resolverKey);
if (resolver == null) {
Map<ResourceType, ResourceValueMap> configuredAppRes;
Map<ResourceType, ResourceValueMap> frameworkResources;
// Framework resources
if (target == null) {
target = myManager.getTarget();
}
if (target == null) {
frameworkResources = Collections.emptyMap();
} else {
ResourceRepository frameworkRes = getFrameworkResources(fullConfiguration, target);
if (frameworkRes == null) {
frameworkResources = Collections.emptyMap();
} else {
// get the framework resource values based on the current config
frameworkResources = myFrameworkResourceMap.get(configurationKey);
if (frameworkResources == null) {
frameworkResources = frameworkRes.getConfiguredResources(fullConfiguration);
// assets replaced the look for the same theme; that doesn't happen to the same extend for Holo)
if (target instanceof CompatibilityRenderTarget && target.getVersion().getApiLevel() == 8) {
IAndroidTarget realTarget = ((CompatibilityRenderTarget) target).getRealTarget();
if (realTarget != null) {
replaceDrawableBitmaps(frameworkResources, target, realTarget);
}
}
myFrameworkResourceMap.put(configurationKey, frameworkResources);
}
}
}
// App resources
configuredAppRes = myAppResourceMap.get(configurationKey);
if (configuredAppRes == null) {
// get the project resource values based on the current config
Application application = ApplicationManager.getApplication();
configuredAppRes = application.runReadAction(new Computable<Map<ResourceType, ResourceValueMap>>() {
@Override
public Map<ResourceType, ResourceValueMap> compute() {
return resources.getConfiguredResources(fullConfiguration);
}
});
myAppResourceMap.put(configurationKey, configuredAppRes);
}
// Resource Resolver
assert themeStyle.startsWith(PREFIX_RESOURCE_REF) : themeStyle;
boolean isProjectTheme = ResourceHelper.isProjectStyle(themeStyle);
String themeName = ResourceHelper.styleToTheme(themeStyle);
resolver = ResourceResolver.create(configuredAppRes, frameworkResources, themeName, isProjectTheme);
if (target instanceof CompatibilityRenderTarget) {
int apiLevel = target.getVersion().getFeatureLevel();
if (apiLevel >= 21) {
resolver.setDeviceDefaults("Material");
} else if (apiLevel >= 14) {
resolver.setDeviceDefaults("Holo");
} else {
resolver.setDeviceDefaults(ResourceResolver.LEGACY_THEME);
}
}
myResolverMap.put(resolverKey, resolver);
}
return resolver;
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class TargetMenuAction method addRealTargets.
private void addRealTargets(@NotNull DefaultActionGroup group) {
Configuration configuration = myRenderContext.getConfiguration();
assert configuration != null;
IAndroidTarget current = configuration.getTarget();
IAndroidTarget[] targets = configuration.getConfigurationManager().getTargets();
boolean haveRecent = false;
int minSdk = getMinSdkVersion();
for (int i = targets.length - 1; i >= 0; i--) {
IAndroidTarget target = targets[i];
if (!ConfigurationManager.isLayoutLibTarget(target)) {
continue;
}
if (!switchToTargetAllowed(configuration, target)) {
continue;
}
AndroidVersion version = target.getVersion();
if (version.getFeatureLevel() < minSdk) {
continue;
}
if (version.getApiLevel() >= SHOW_FROM_API_LEVEL) {
haveRecent = true;
} else if (haveRecent) {
// (unless of course all you have are ancient targets)
break;
}
String title = getRenderingTargetLabel(target, false);
boolean select = current == target;
group.add(new SetTargetAction(myRenderContext, title, target, select));
}
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class NestedConfiguration method initFrom.
/**
* Initializes a new {@linkplain NestedConfiguration} with the overriding
* attributes as the given other {@linkplain NestedConfiguration}, and gets
* its values from the given {@linkplain Configuration}.
*
* @param configuration the configuration to initialize
* @param other the configuration to copy overrides from
* @param values the configuration to copy values from
*/
protected static void initFrom(NestedConfiguration configuration, NestedConfiguration other, Configuration values) {
// TODO: Rewrite to use the clone method!
configuration.startBulkEditing();
configuration.myOverride = other.myOverride;
configuration.setDisplayName(values.getDisplayName());
String activity = values.getActivity();
if (activity != null) {
configuration.setActivity(activity);
}
if (configuration.isOverridingLocale()) {
configuration.setLocale(values.getLocale());
}
if (configuration.isOverridingTarget()) {
IAndroidTarget target = values.getTarget();
if (target != null) {
configuration.setTarget(target);
}
}
if (configuration.isOverridingDevice()) {
Device device = values.getDevice();
if (device != null) {
configuration.setDevice(device, true);
}
}
if (configuration.isOverridingDeviceState()) {
State deviceState = values.getDeviceState();
if (deviceState != null) {
configuration.setDeviceState(deviceState);
}
}
if (configuration.isOverridingNightMode()) {
configuration.setNightMode(values.getNightMode());
}
if (configuration.isOverridingUiMode()) {
configuration.setUiMode(values.getUiMode());
}
configuration.finishBulkEditing();
}
Aggregations