use of com.android.tools.idea.res.ResourceNotificationManager in project android by JetBrains.
the class NlPreviewImagePanel method setDesignSurface.
public void setDesignSurface(@Nullable DesignSurface designSurface) {
Module oldModule = null;
Configuration oldConfiguration = myDesignSurface != null ? myDesignSurface.getConfiguration() : null;
if (oldConfiguration != null) {
oldModule = oldConfiguration.getModule();
oldConfiguration.removeListener(myConfigurationListener);
}
if (myDesignSurface != null) {
myDesignSurface.removePanZoomListener(myZoomListener);
}
myDesignSurface = designSurface;
Module newModule = null;
Configuration newConfiguration = myDesignSurface != null ? myDesignSurface.getConfiguration() : null;
if (newConfiguration != null) {
newModule = newConfiguration.getModule();
newConfiguration.addListener(myConfigurationListener);
}
if (myDesignSurface != null) {
myDesignSurface.addPanZoomListener(myZoomListener);
}
if (newModule != oldModule) {
ResourceNotificationManager manager = ResourceNotificationManager.getInstance(myDependencyManager.getProject());
AndroidFacet oldFacet = oldModule != null ? AndroidFacet.getInstance(oldModule) : null;
if (oldFacet != null) {
manager.removeListener(myResourceChangeListener, oldFacet, null, null);
}
AndroidFacet newFacet = newModule != null ? AndroidFacet.getInstance(newModule) : null;
if (newFacet != null) {
manager.addListener(myResourceChangeListener, newFacet, null, null);
}
}
myImage = null;
myPreviewGenerationDone = false;
setTransferHandler(designSurface != null ? new ItemTransferHandler(myDesignSurface, this::getItem, myIconPreviewFactory) : null);
invalidateUI();
}
use of com.android.tools.idea.res.ResourceNotificationManager in project android by JetBrains.
the class NlOldPalettePanel method setToolContext.
@Override
public void setToolContext(@Nullable DesignSurface designSurface) {
Module prevModule = null;
if (myConfiguration != null) {
prevModule = myConfiguration.getModule();
myConfiguration.removeListener(this);
}
Module newModule = null;
myDesignSurface = designSurface != null && designSurface.getLayoutType().isSupportedByDesigner() ? designSurface : null;
if (myDesignSurface != null) {
updateConfiguration();
if (myConfiguration != null) {
newModule = myConfiguration.getModule();
myConfiguration.addListener(this);
}
initItems();
checkForNewMissingDependencies();
repaint();
}
if (prevModule != newModule) {
if (prevModule != null) {
AndroidFacet facet = AndroidFacet.getInstance(prevModule);
if (facet != null) {
ResourceNotificationManager manager = ResourceNotificationManager.getInstance(myProject);
manager.removeListener(this, facet, null, null);
}
}
if (newModule != null) {
AndroidFacet facet = AndroidFacet.getInstance(newModule);
if (facet != null) {
ResourceNotificationManager manager = ResourceNotificationManager.getInstance(myProject);
manager.addListener(this, facet, null, null);
}
myIconFactory.dropCache();
}
}
}
use of com.android.tools.idea.res.ResourceNotificationManager in project android by JetBrains.
the class NlModel method deactivate.
/**
* Notify model that it's not active. This means it can stop watching for events etc. It may be activated again in the future.
*/
public void deactivate() {
if (myActive) {
getRenderingQueue().cancelAllUpdates();
ResourceNotificationManager manager = ResourceNotificationManager.getInstance(myFile.getProject());
manager.removeListener(this, myFacet, myFile, myConfiguration);
myConfigurationModificationCount = myConfiguration.getModificationCount();
myConfiguration.removeListener(myConfigurationListener);
myActive = false;
}
}
use of com.android.tools.idea.res.ResourceNotificationManager in project android by JetBrains.
the class ThemeEditorComponent method unsubscribeResourceNotification.
/**
* Unsubscribe {@link #myResourceChangeListener}] from ResourceNotificationManager with current AndroidFacet.
*/
private void unsubscribeResourceNotification() {
if (myThemeEditorContext.getCurrentContextModule().isDisposed()) {
// The subscription is automatically removed when the module is disposed.
return;
}
ResourceNotificationManager manager = ResourceNotificationManager.getInstance(myThemeEditorContext.getProject());
AndroidFacet facet = AndroidFacet.getInstance(myThemeEditorContext.getCurrentContextModule());
assert facet != null : myThemeEditorContext.getCurrentContextModule().getName() + " module doesn't have an AndroidFacet";
unsubscribeResourceNotification(manager, facet);
}
use of com.android.tools.idea.res.ResourceNotificationManager in project android by JetBrains.
the class ThemeEditorComponent method subscribeResourceNotification.
/**
* Subscribes myResourceChangeListener to ResourceNotificationManager with current AndroidFacet.
* By subscribing, myResourceChangeListener can track all internal and external changes in resources.
*/
private void subscribeResourceNotification() {
// Already subscribed, we check this, because sometimes selectNotify can be called twice
if (myIsSubscribedResourceNotification) {
return;
}
final ResourceNotificationManager manager = ResourceNotificationManager.getInstance(myThemeEditorContext.getProject());
final AndroidFacet facet = AndroidFacet.getInstance(myThemeEditorContext.getCurrentContextModule());
assert facet != null : myThemeEditorContext.getCurrentContextModule().getName() + " module doesn't have an AndroidFacet";
manager.addListener(myResourceChangeListener, facet, null, null);
myIsSubscribedResourceNotification = true;
Disposer.register(facet, new Disposable() {
@Override
public void dispose() {
// If the module is disposed, remove subscription
unsubscribeResourceNotification(manager, facet);
}
});
}
Aggregations