From 7e0cee5506357a5578278516534a9ddda2cfc5f8 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Fri, 27 Jul 2012 19:52:08 +0400 Subject: [PATCH] EA-36735 --- .../AndroidDesignerEditorPanel.java | 31 +++-- .../android/designer/model/ModelParser.java | 30 ++++- .../designer/model/RadIncludeLayout.java | 108 +++++++++++++++++- .../propertyTable/IncludeLayoutProperty.java | 2 + 4 files changed, 156 insertions(+), 15 deletions(-) diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java index b99b0b9d602d..d9e7b0e9e167 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java @@ -83,6 +83,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { private final ExternalPSIChangeListener myPSIChangeListener; private final ProfileAction myProfileAction; private final Alarm mySessionAlarm = new Alarm(); + private FolderConfiguration myLastRenderedConfiguration; private volatile RenderSession mySession; private boolean myParseTime; private int myProfileLastVersion; @@ -181,7 +182,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { public void consume(RenderSession session) throws Throwable { RootView rootView = new RootView(30, 20, session.getImage()); try { - parser.updateRootComponent(session, rootView); + parser.updateRootComponent(myLastRenderedConfiguration, session, rootView); } catch (Throwable e) { myRootComponent = parser.getRootComponent(); @@ -252,17 +253,17 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { throw new RenderingException("Device is not specified"); } - FolderConfiguration config = new FolderConfiguration(); - config.set(deviceConfiguration.getConfiguration()); - config.setUiModeQualifier(new UiModeQualifier(manager.getSelectedDockMode())); - config.setNightModeQualifier(new NightModeQualifier(manager.getSelectedNightMode())); + myLastRenderedConfiguration = new FolderConfiguration(); + myLastRenderedConfiguration.set(deviceConfiguration.getConfiguration()); + myLastRenderedConfiguration.setUiModeQualifier(new UiModeQualifier(manager.getSelectedDockMode())); + myLastRenderedConfiguration.setNightModeQualifier(new NightModeQualifier(manager.getSelectedNightMode())); LocaleData locale = manager.getSelectedLocale(); if (locale == null) { throw new RenderingException("Locale is not specified"); } - config.setLanguageQualifier(new LanguageQualifier(locale.getLanguage())); - config.setRegionQualifier(new RegionQualifier(locale.getRegion())); + myLastRenderedConfiguration.setLanguageQualifier(new LanguageQualifier(locale.getLanguage())); + myLastRenderedConfiguration.setRegionQualifier(new RegionQualifier(locale.getRegion())); float xdpi = deviceConfiguration.getDevice().getXDpi(); float ydpi = deviceConfiguration.getDevice().getYDpi(); @@ -274,8 +275,18 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { throw new RenderingException(); } - RenderingResult result = - RenderUtil.renderLayout(getModule(), layoutXmlText, myFile, null, target, facet, config, xdpi, ydpi, theme, 10000, true); + RenderingResult result = RenderUtil.renderLayout(getModule(), + layoutXmlText, + myFile, + null, + target, + facet, + myLastRenderedConfiguration, + xdpi, + ydpi, + theme, + 10000, + true); if (ApplicationManagerEx.getApplicationEx().isInternal()) { System.out.println("Render time: " + (System.currentTimeMillis() - time)); // XXX @@ -346,7 +357,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { RadViewComponent rootComponent = (RadViewComponent)myRootComponent; RootView rootView = (RootView)rootComponent.getNativeComponent(); rootView.setImage(session.getImage()); - ModelParser.updateRootComponent(rootComponent, session, rootView); + ModelParser.updateRootComponent(myLastRenderedConfiguration, rootComponent, session, rootView); myParseTime = false; diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java b/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java index 2d4815aac428..ca3e1378d1ef 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java @@ -17,6 +17,7 @@ package com.intellij.android.designer.model; import com.android.ide.common.rendering.api.RenderSession; import com.android.ide.common.rendering.api.ViewInfo; +import com.android.ide.common.resources.configuration.FolderConfiguration; import com.android.sdklib.SdkConstants; import com.intellij.android.designer.designSurface.AndroidPasteFactory; import com.intellij.android.designer.designSurface.RootView; @@ -41,6 +42,7 @@ import org.jdom.Attribute; import org.jdom.Element; import org.jetbrains.annotations.Nullable; +import java.awt.*; import java.util.List; /** @@ -52,6 +54,7 @@ public class ModelParser extends XmlRecursiveElementVisitor { public static final String XML_FILE_KEY = "XML_FILE"; public static final String MODULE_KEY = "MODULE"; + public static final String FOLDER_CONFIG_KEY = "FOLDER_CONFIG"; private static final int EMPTY_COMPONENT_SIZE = 5; @@ -379,7 +382,7 @@ public class ModelParser extends XmlRecursiveElementVisitor { return myLayoutXmlText; } - public void updateRootComponent(RenderSession session, RootView nativeComponent) throws Exception { + public void updateRootComponent(FolderConfiguration configuration, RenderSession session, RootView nativeComponent) throws Exception { if (myRootComponent == null) { myRootComponent = createComponent(myXmlFile.getRootTag(), myMetaManager.getModelByTag("")); } @@ -389,13 +392,16 @@ public class ModelParser extends XmlRecursiveElementVisitor { myRootComponent.add(rootComponent, null); } - updateRootComponent(myRootComponent, session, nativeComponent); + updateRootComponent(configuration, myRootComponent, session, nativeComponent); myRootComponent.setClientProperty(IdManager.KEY, myIdManager); } - public static void updateRootComponent(RadViewComponent rootComponent, + public static void updateRootComponent(FolderConfiguration configuration, + RadViewComponent rootComponent, RenderSession session, RootView nativeComponent) { + rootComponent.setClientProperty(FOLDER_CONFIG_KEY, configuration); + updateChildren(rootComponent, session.getRootViews(), nativeComponent, 0, 0); rootComponent.setNativeComponent(nativeComponent); @@ -442,7 +448,23 @@ public class ModelParser extends XmlRecursiveElementVisitor { updateComponent(childComponent, views.get(viewIndex), nativeComponent, left, top); } else { - // XXX + Rectangle bounds = null; + for (int subViewIndex = 0; subViewIndex < childViewCount; subViewIndex++) { + ViewInfo view = views.get(viewIndex + subViewIndex); + Rectangle viewBounds = + new Rectangle(view.getLeft(), view.getTop(), view.getRight() - view.getLeft(), view.getBottom() - view.getTop()); + if (bounds == null) { + bounds = viewBounds; + } + else { + bounds = bounds.union(viewBounds); + } + } + + updateComponent(childComponent, + new ViewInfo(childComponent.getMetaModel().getTarget(), null, bounds.x, bounds.y, bounds.x + bounds.width, + bounds.y + bounds.height), + nativeComponent, left, top); } viewIndex += childViewCount; diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadIncludeLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadIncludeLayout.java index d26ccaf8ebd3..70a7b97b2225 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadIncludeLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadIncludeLayout.java @@ -15,6 +15,9 @@ */ package com.intellij.android.designer.model; +import com.android.AndroidConstants; +import com.android.ide.common.resources.configuration.Configurable; +import com.android.ide.common.resources.configuration.FolderConfiguration; import com.intellij.android.designer.propertyTable.IdProperty; import com.intellij.android.designer.propertyTable.IncludeLayoutProperty; import com.intellij.android.designer.propertyTable.editors.ResourceDialog; @@ -22,6 +25,15 @@ import com.intellij.designer.ModuleProvider; import com.intellij.designer.model.RadComponent; import com.intellij.designer.propertyTable.Property; import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiReference; +import com.intellij.psi.xml.XmlAttribute; +import com.intellij.psi.xml.XmlAttributeValue; +import com.intellij.psi.xml.XmlFile; +import com.intellij.psi.xml.XmlTag; +import org.jetbrains.android.dom.converters.AndroidResourceReference; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -30,6 +42,9 @@ import java.util.List; * @author Alexander Lobas */ public class RadIncludeLayout extends RadViewComponent implements IConfigurableComponent { + private int myViewInfoCount = -1; + private FolderConfiguration myConfiguration; + @Override public String getCreationXml() { return " configurables = new ArrayList(); + for (PsiElement element : elements) { + XmlFile xmlFile = (XmlFile)element; + + VirtualFile file = xmlFile.getVirtualFile(); + if (file == null) { + continue; + } + VirtualFile folder = file.getParent(); + if (folder == null) { + continue; + } + + FolderConfiguration includeConfig = FolderConfiguration.getConfig(folder.getName().split(AndroidConstants.RES_QUALIFIER_SEP)); + configurables.add(new MyConfigurable(xmlFile, includeConfig)); + } + + MyConfigurable configurable = (MyConfigurable)configuration.findMatchingConfigurable(configurables); + return configurable == null ? null : configurable.getFile(); + } + + private static class MyConfigurable implements Configurable { + private final XmlFile myFile; + private final FolderConfiguration myConfig; + + private MyConfigurable(XmlFile file, FolderConfiguration config) { + myFile = file; + myConfig = config; + } + + @Override + public FolderConfiguration getConfiguration() { + return myConfig; + } + + public XmlFile getFile() { + return myFile; + } } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/IncludeLayoutProperty.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/IncludeLayoutProperty.java index 0bd4342663ae..ffc393233dcb 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/IncludeLayoutProperty.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/IncludeLayoutProperty.java @@ -16,6 +16,7 @@ package com.intellij.android.designer.propertyTable; import com.android.resources.ResourceType; +import com.intellij.android.designer.model.RadIncludeLayout; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.propertyTable.editors.ResourceEditor; import com.intellij.android.designer.propertyTable.renderers.ResourceRenderer; @@ -69,6 +70,7 @@ public class IncludeLayoutProperty extends Property implements ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { + ((RadIncludeLayout)component).clearViewInfoCount(); component.getTag().setAttribute("layout", (String)value); } });