use of com.android.tools.idea.res.ResourceNotificationManager in project android by JetBrains.
the class NlModel method inflate.
/**
* Synchronously inflates the model and updates the view hierarchy
*
* @param force forces the model to be re-inflated even if a previous version was already inflated
* @returns whether the model was inflated in this call or not
*/
private boolean inflate(boolean force) {
Configuration configuration = myConfiguration;
if (configuration == null) {
return false;
}
ResourceNotificationManager resourceNotificationManager = ResourceNotificationManager.getInstance(myFile.getProject());
// Some types of files must be saved to disk first, because layoutlib doesn't
// delegate XML parsers for non-layout files (meaning layoutlib will read the
// disk contents, so we have to push any edits to disk before rendering)
LayoutPullParserFactory.saveFileIfNecessary(myFile);
RenderResult result = null;
synchronized (RENDERING_LOCK) {
if (myRenderTask != null && !force) {
// No need to inflate
return false;
}
// Record the current version we're rendering from; we'll use that in #activate to make sure we're picking up any
// external changes
myRenderedVersion = resourceNotificationManager.getCurrentVersion(myFacet, myFile, myConfiguration);
RenderService renderService = RenderService.get(myFacet);
RenderLogger logger = renderService.createLogger();
if (myRenderTask != null) {
myRenderTask.dispose();
}
myRenderTask = renderService.createTask(myFile, configuration, logger, mySurface);
setupRenderTask(myRenderTask);
if (myRenderTask != null) {
if (!isRenderViewPort()) {
myRenderTask.useDesignMode(myFile);
}
result = myRenderTask.inflate();
if (result == null || !result.getRenderResult().isSuccess()) {
myRenderTask.dispose();
myRenderTask = null;
if (result == null) {
result = RenderResult.createBlank(myFile);
}
}
}
updateHierarchy(result);
myRenderResultLock.writeLock().lock();
try {
myRenderResult = result;
} finally {
myRenderResultLock.writeLock().unlock();
}
return myRenderTask != null;
}
}
use of com.android.tools.idea.res.ResourceNotificationManager in project android by JetBrains.
the class NlModel method activate.
/**
* Notify model that it's active. A model is active by default.
*/
public void activate() {
if (!myActive) {
myActive = true;
myConfiguration.addListener(myConfigurationListener);
ResourceNotificationManager manager = ResourceNotificationManager.getInstance(myFile.getProject());
ResourceVersion version = manager.addListener(this, myFacet, myFile, myConfiguration);
// If the resources have changed or the configuration has been modified, request a model update
if (!version.equals(myRenderedVersion) || (myConfiguration.getModificationCount() != myConfigurationModificationCount)) {
String theme = myConfiguration.getTheme();
if (theme != null && !theme.startsWith(ANDROID_STYLE_RESOURCE_PREFIX) && !myProjectResourceRepository.hasResourceItem(theme)) {
myConfiguration.setTheme(myConfiguration.getConfigurationManager().computePreferredTheme(myConfiguration));
}
requestModelUpdate();
myModelVersion.myResourceVersion.incrementAndGet();
}
}
}
Aggregations