use of com.android.tools.idea.configurations.ConfigurationListener in project android by JetBrains.
the class Scene method add.
/**
* Add the NlComponents contained in the given NlModel to the Scene
*
* @param model the NlModel to use
*/
public void add(@NotNull NlModel model) {
ConfigurationListener listener = (flags) -> {
if ((flags & CFG_DEVICE) != 0 && !isManualDpiFactor) {
float newDpiFactor = model.getConfiguration().getDensity().getDpiValue() / 160f;
if (myDpiFactor != newDpiFactor) {
// Update from the model to update the dpi
updateFrom(model);
}
}
return true;
};
model.getConfiguration().addListener(listener);
Disposer.register(model, () -> model.getConfiguration().removeListener(listener));
List<NlComponent> components = model.getComponents();
if (components.size() != 0) {
NlComponent rootComponent = components.get(0).getRoot();
myAnimate = false;
myRoot = updateFromComponent(rootComponent);
myAnimate = true;
addTargets(myRoot);
}
model.addListener(this);
myModel = model;
// let's make sure the selection is correct
if (myScreenView != null) {
selectionChanged(myScreenView.getSelectionModel(), myScreenView.getSelectionModel().getSelection());
}
}
use of com.android.tools.idea.configurations.ConfigurationListener in project android by JetBrains.
the class Configuration method updated.
/** Called when one or more attributes of the configuration has changed */
public void updated(int flags) {
myNotifyDirty |= flags;
myFolderConfigDirty |= flags;
myModificationCount++;
if (myManager.getStateVersion() != myProjectStateVersion) {
myNotifyDirty |= MASK_PROJECT_STATE;
myFolderConfigDirty |= MASK_PROJECT_STATE;
myDevice = null;
myState = null;
}
if (myBulkEditingCount == 0) {
int changed = myNotifyDirty;
if (myListeners != null) {
for (ConfigurationListener listener : myListeners) {
listener.changed(changed);
}
}
myNotifyDirty = 0;
}
}
use of com.android.tools.idea.configurations.ConfigurationListener 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);
}
use of com.android.tools.idea.configurations.ConfigurationListener in project android by JetBrains.
the class NestedConfigurationTest 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 parent = Configuration.create(manager, null, new FolderConfiguration());
assertNotNull(parent);
NestedConfiguration configuration = NestedConfiguration.create(parent);
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.setOverrideLocale(true);
configuration.setLocale(Locale.create("en-rUS"));
assertEquals(1, myChangeCount);
assertEquals(CFG_LOCALE, myFlags);
// No firing when only seeing overridden changes
myFlags = 0;
parent.setLocale(Locale.create("es"));
assertEquals(1, myChangeCount);
assertEquals(0, myFlags);
myFlags = 0;
parent.setLocale(Locale.create("de"));
parent.setUiMode(UiMode.APPLIANCE);
assertEquals(2, myChangeCount);
assertEquals(CFG_UI_MODE, myFlags);
}
Aggregations