aboutsummaryrefslogtreecommitdiffstats
path: root/ide_common/src/com/android/ide/common
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2011-04-01 14:11:47 -0700
committerXavier Ducrohet <xav@android.com>2011-06-23 14:17:59 -0700
commita84d8ef38565d59c5c71f7e5bbc1afcc6691c8f7 (patch)
tree4d8cd0d34bdb6c583ea8263a040878802b13692d /ide_common/src/com/android/ide/common
parent4833b2a443f9c101e21649389bec3992a48b9e66 (diff)
downloadsdk-a84d8ef38565d59c5c71f7e5bbc1afcc6691c8f7.zip
sdk-a84d8ef38565d59c5c71f7e5bbc1afcc6691c8f7.tar.gz
sdk-a84d8ef38565d59c5c71f7e5bbc1afcc6691c8f7.tar.bz2
Sample code to use the layout rendering library.
This is very basic sample code showing how to render a layout. This explains how to load the resources, create Folderconfig, ResourceResolver, and how to call the LayoutLibrary to do an actual render. There are some big limitations: - can't render custom views because there's nothing compiling them and generating the compiled R.class file. - not all features of ADT are present because there are things that don't make sense outside of an editor (render in context, expand empty layouts, etc...) Change-Id: I0c8676ebfbff27f0e9412bb4b13193ce64082372
Diffstat (limited to 'ide_common/src/com/android/ide/common')
-rw-r--r--ide_common/src/com/android/ide/common/resources/ResourceRepository.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/ide_common/src/com/android/ide/common/resources/ResourceRepository.java b/ide_common/src/com/android/ide/common/resources/ResourceRepository.java
index f72ebd2..0acc016 100644
--- a/ide_common/src/com/android/ide/common/resources/ResourceRepository.java
+++ b/ide_common/src/com/android/ide/common/resources/ResourceRepository.java
@@ -22,11 +22,14 @@ import com.android.ide.common.resources.configuration.Configurable;
import com.android.ide.common.resources.configuration.FolderConfiguration;
import com.android.ide.common.resources.configuration.LanguageQualifier;
import com.android.ide.common.resources.configuration.RegionQualifier;
+import com.android.io.IAbstractFile;
import com.android.io.IAbstractFolder;
+import com.android.io.IAbstractResource;
import com.android.resources.FolderTypeRelationship;
import com.android.resources.ResourceFolderType;
import com.android.resources.ResourceType;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -459,6 +462,38 @@ public abstract class ResourceRepository {
return set;
}
+ /**
+ * Loads the resources from a resource folder.
+ * <p/>
+ *
+ * @param rootFolder The folder to read the resources from. This is the top level
+ * resource folder (res/)
+ * @throws IOException
+ */
+ public void loadResources(IAbstractFolder rootFolder)
+ throws IOException {
+ IAbstractResource[] files = rootFolder.listMembers();
+ for (IAbstractResource file : files) {
+ if (file instanceof IAbstractFolder) {
+ IAbstractFolder folder = (IAbstractFolder) file;
+ ResourceFolder resFolder = processFolder(folder);
+
+ if (resFolder != null) {
+ // now we process the content of the folder
+ IAbstractResource[] children = folder.listMembers();
+
+ for (IAbstractResource childRes : children) {
+ if (childRes instanceof IAbstractFile) {
+ resFolder.processFile((IAbstractFile) childRes,
+ ResourceDeltaKind.ADDED);
+ }
+ }
+ }
+ }
+ }
+ }
+
+
protected void removeFile(Collection<ResourceType> types, ResourceFile file) {
for (ResourceType type : types) {
removeFile(type, file);