LayoutReloadMonitorpublic final class LayoutReloadMonitor extends Object implements com.android.ide.eclipse.editors.resources.manager.ResourceMonitor.IFileListener, com.android.ide.eclipse.editors.resources.manager.ResourceMonitor.IResourceEventListenerMonitor for file changes triggering a layout redraw. |
Fields Summary |
---|
private static final LayoutReloadMonitor | sThis | private final Map | mListenerMapMap of listeners by IProject. | private static final int | CHANGE_CODE | private static final int | CHANGE_RESOURCES | private static final int | CHANGE_R | private static final int | CHANGE_COUNT | private final Map | mChangedProjectsList of projects having received a file change. the boolean[] contains 3 values:
- CHANGE_CODE: code change flag.
- CHANGE_RESOURCES: resource change flag.
- CHANGE_R: R clas change flag
|
Constructors Summary |
---|
private LayoutReloadMonitor()
ResourceMonitor monitor = ResourceMonitor.getMonitor();
monitor.addFileListener(this, IResourceDelta.ADDED | IResourceDelta.CHANGED);
monitor.addResourceEventListener(this);
|
Methods Summary |
---|
public void | addListener(org.eclipse.core.resources.IProject project, com.android.ide.eclipse.editors.layout.LayoutReloadMonitor$ILayoutReloadListener listener)Adds a listener for a given {@link IProject}.
synchronized (mListenerMap) {
List<ILayoutReloadListener> list = mListenerMap.get(project);
if (list == null) {
list = new ArrayList<ILayoutReloadListener>();
mListenerMap.put(project, list);
}
list.add(listener);
}
| public void | fileChanged(org.eclipse.core.resources.IFile file, org.eclipse.core.resources.IMarkerDelta[] markerDeltas, int kind)
// get the file project
IProject project = file.getProject();
// if this project has already been marked as modified, we do nothing.
boolean[] changeFlags = mChangedProjects.get(project);
if (changeFlags != null && changeFlags[CHANGE_CODE] && changeFlags[CHANGE_RESOURCES] &&
changeFlags[CHANGE_R]) {
return;
}
// now check that the file is *NOT* a layout file (those automatically trigger a layout
// reload and we don't want to do it twice.
ResourceFolder resFolder = ResourceManager.getInstance().getResourceFolder(file);
if (resFolder != null) {
if (resFolder.getType() != ResourceFolderType.LAYOUT) {
// this is a resource change!
if (changeFlags == null) {
changeFlags = new boolean[CHANGE_COUNT];
mChangedProjects.put(project, changeFlags);
}
changeFlags[CHANGE_RESOURCES] = true;
}
} else if (AndroidConstants.EXT_CLASS.equals(file.getFileExtension())) {
if (file.getName().matches("R[\\$\\.](.*)")) {
// this is a R change!
if (changeFlags == null) {
changeFlags = new boolean[CHANGE_COUNT];
mChangedProjects.put(project, changeFlags);
}
changeFlags[CHANGE_R] = true;
} else {
// this is a code change!
if (changeFlags == null) {
changeFlags = new boolean[CHANGE_COUNT];
mChangedProjects.put(project, changeFlags);
}
changeFlags[CHANGE_CODE] = true;
}
}
| public static com.android.ide.eclipse.editors.layout.LayoutReloadMonitor | getMonitor()Returns the single instance of {@link LayoutReloadMonitor}.
return sThis;
| public void | removeListener(org.eclipse.core.resources.IProject project, com.android.ide.eclipse.editors.layout.LayoutReloadMonitor$ILayoutReloadListener listener)Removes a listener for a given {@link IProject}.
synchronized (mListenerMap) {
List<ILayoutReloadListener> list = mListenerMap.get(project);
if (list != null) {
list.remove(listener);
}
}
| public void | resourceChangeEventEnd()
// for each IProject that was changed, we notify all the listeners.
synchronized (mListenerMap) {
for (Entry<IProject, boolean[]> project : mChangedProjects.entrySet()) {
List<ILayoutReloadListener> listeners = mListenerMap.get(project.getKey());
boolean[] flags = project.getValue();
if (listeners != null) {
for (ILayoutReloadListener listener : listeners) {
listener.reloadLayout(flags[CHANGE_CODE], flags[CHANGE_R],
flags[CHANGE_RESOURCES]);
}
}
}
}
// empty the list.
mChangedProjects.clear();
| public void | resourceChangeEventStart()
// nothing to be done here, it all happens in the resourceChangeEventEnd
|
|