Search in sources :

Example 1 with Bridge

use of com.android.layoutlib.bridge.Bridge in project android_frameworks_base by ResurrectionRemix.

the class Main method setUp.

/**
     * Initialize the bridge and the resource maps.
     */
@BeforeClass
public static void setUp() {
    File data_dir = new File(PLATFORM_DIR, "data");
    File res = new File(data_dir, "res");
    sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
    sFrameworkRepo.loadResources();
    sFrameworkRepo.loadPublicResources(getLogger());
    sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {

        @NonNull
        @Override
        protected ResourceItem createResourceItem(@NonNull String name) {
            return new ResourceItem(name);
        }
    };
    sProjectResources.loadResources();
    File fontLocation = new File(data_dir, "fonts");
    File buildProp = new File(PLATFORM_DIR, "build.prop");
    File attrs = new File(res, "values" + File.separator + "attrs.xml");
    sBridge = new Bridge();
    sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
Also used : FrameworkResources(com.android.ide.common.resources.FrameworkResources) NonNull(android.annotation.NonNull) FolderWrapper(com.android.io.FolderWrapper) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) File(java.io.File) Bridge(com.android.layoutlib.bridge.Bridge) BeforeClass(org.junit.BeforeClass)

Example 2 with Bridge

use of com.android.layoutlib.bridge.Bridge in project android_frameworks_base by DirtyUnicorns.

the class Main method setUp.

/**
     * Initialize the bridge and the resource maps.
     */
@BeforeClass
public static void setUp() {
    File data_dir = new File(PLATFORM_DIR, "data");
    File res = new File(data_dir, "res");
    sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
    sFrameworkRepo.loadResources();
    sFrameworkRepo.loadPublicResources(getLogger());
    sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {

        @NonNull
        @Override
        protected ResourceItem createResourceItem(@NonNull String name) {
            return new ResourceItem(name);
        }
    };
    sProjectResources.loadResources();
    File fontLocation = new File(data_dir, "fonts");
    File buildProp = new File(PLATFORM_DIR, "build.prop");
    File attrs = new File(res, "values" + File.separator + "attrs.xml");
    sBridge = new Bridge();
    sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
Also used : FrameworkResources(com.android.ide.common.resources.FrameworkResources) NonNull(android.annotation.NonNull) FolderWrapper(com.android.io.FolderWrapper) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) File(java.io.File) Bridge(com.android.layoutlib.bridge.Bridge) BeforeClass(org.junit.BeforeClass)

Example 3 with Bridge

use of com.android.layoutlib.bridge.Bridge in project android_frameworks_base by AOSPA.

the class Main method setUp.

/**
     * Initialize the bridge and the resource maps.
     */
@BeforeClass
public static void setUp() {
    File data_dir = new File(PLATFORM_DIR, "data");
    File res = new File(data_dir, "res");
    sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
    sFrameworkRepo.loadResources();
    sFrameworkRepo.loadPublicResources(getLogger());
    sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {

        @NonNull
        @Override
        protected ResourceItem createResourceItem(@NonNull String name) {
            return new ResourceItem(name);
        }
    };
    sProjectResources.loadResources();
    File fontLocation = new File(data_dir, "fonts");
    File buildProp = new File(PLATFORM_DIR, "build.prop");
    File attrs = new File(res, "values" + File.separator + "attrs.xml");
    sBridge = new Bridge();
    sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
Also used : FrameworkResources(com.android.ide.common.resources.FrameworkResources) NonNull(android.annotation.NonNull) FolderWrapper(com.android.io.FolderWrapper) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) File(java.io.File) Bridge(com.android.layoutlib.bridge.Bridge) BeforeClass(org.junit.BeforeClass)

Example 4 with Bridge

use of com.android.layoutlib.bridge.Bridge in project android_frameworks_base by crdroidandroid.

the class Main method setUp.

/**
     * Initialize the bridge and the resource maps.
     */
@BeforeClass
public static void setUp() {
    File data_dir = new File(PLATFORM_DIR, "data");
    File res = new File(data_dir, "res");
    sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
    sFrameworkRepo.loadResources();
    sFrameworkRepo.loadPublicResources(getLogger());
    sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {

        @NonNull
        @Override
        protected ResourceItem createResourceItem(@NonNull String name) {
            return new ResourceItem(name);
        }
    };
    sProjectResources.loadResources();
    File fontLocation = new File(data_dir, "fonts");
    File buildProp = new File(PLATFORM_DIR, "build.prop");
    File attrs = new File(res, "values" + File.separator + "attrs.xml");
    sBridge = new Bridge();
    sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
Also used : FrameworkResources(com.android.ide.common.resources.FrameworkResources) NonNull(android.annotation.NonNull) FolderWrapper(com.android.io.FolderWrapper) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) File(java.io.File) Bridge(com.android.layoutlib.bridge.Bridge) BeforeClass(org.junit.BeforeClass)

Example 5 with Bridge

use of com.android.layoutlib.bridge.Bridge in project android by JetBrains.

the class LayoutLibraryLoader method load.

@Nullable
public static LayoutLibrary load(@NotNull IAndroidTarget target, @NotNull Map<String, Map<String, Integer>> enumMap) throws RenderingException, IOException {
    final String fontFolderPath = FileUtil.toSystemIndependentName((target.getPath(IAndroidTarget.FONTS)));
    final VirtualFile fontFolder = LocalFileSystem.getInstance().findFileByPath(fontFolderPath);
    if (fontFolder == null || !fontFolder.isDirectory()) {
        throw new RenderingException(LayoutlibBundle.message("android.directory.cannot.be.found.error", FileUtil.toSystemDependentName(fontFolderPath)));
    }
    final String platformFolderPath = target.isPlatform() ? target.getLocation() : target.getParent().getLocation();
    final File platformFolder = new File(platformFolderPath);
    if (!platformFolder.isDirectory()) {
        throw new RenderingException(LayoutlibBundle.message("android.directory.cannot.be.found.error", FileUtil.toSystemDependentName(platformFolderPath)));
    }
    final File buildProp = new File(platformFolder, SdkConstants.FN_BUILD_PROP);
    if (!buildProp.isFile()) {
        throw new RenderingException(LayoutlibBundle.message("android.file.not.exist.error", FileUtil.toSystemDependentName(buildProp.getPath())));
    }
    if (!SystemInfo.isJavaVersionAtLeast("1.8") && target.getVersion().getFeatureLevel() >= 24) {
        // From N, we require to be running in Java 8
        throw new UnsupportedJavaRuntimeException(LayoutlibBundle.message("android.layout.preview.unsupported.jdk", SdkVersionInfo.getCodeName(target.getVersion().getFeatureLevel())));
    }
    LayoutLibrary library;
    final ILogger logger = new LogWrapper(LOG);
    if (USE_SDK_LAYOUTLIB) {
        final String resFolderPath = FileUtil.toSystemIndependentName((target.getPath(IAndroidTarget.RESOURCES)));
        final VirtualFile resFolder = LocalFileSystem.getInstance().findFileByPath(resFolderPath);
        if (resFolder == null || !resFolder.isDirectory()) {
            throw new RenderingException(LayoutlibBundle.message("android.directory.cannot.be.found.error", FileUtil.toSystemDependentName(resFolderPath)));
        }
        final String layoutLibJarPath = FileUtil.toSystemIndependentName((target.getPath(IAndroidTarget.LAYOUT_LIB)));
        final VirtualFile layoutLibJar = LocalFileSystem.getInstance().findFileByPath(layoutLibJarPath);
        if (layoutLibJar == null || layoutLibJar.isDirectory()) {
            throw new RenderingException(LayoutlibBundle.message("android.file.not.exist.error", FileUtil.toSystemDependentName(layoutLibJarPath)));
        }
        library = LayoutLibrary.load(layoutLibJar.getPath(), logger, ApplicationNamesInfo.getInstance().getFullProductName());
    } else {
        // We instantiate the local Bridge implementation and pass it to the LayoutLibrary instance
        library = LayoutLibrary.load(new Bridge(), LayoutLibraryLoader.class.getClassLoader());
    }
    if (library.getStatus() != LoadStatus.LOADED) {
        throw new RenderingException(library.getLoadMessage());
    }
    final Map<String, String> buildPropMap = ProjectProperties.parsePropertyFile(new BufferingFileWrapper(buildProp), logger);
    final LayoutLog layoutLog = new LayoutLogWrapper(LOG);
    if (library.init(buildPropMap, new File(fontFolder.getPath()), enumMap, layoutLog)) {
        return library;
    } else {
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BufferingFileWrapper(org.jetbrains.android.util.BufferingFileWrapper) LayoutLibrary(com.android.ide.common.rendering.LayoutLibrary) ILogger(com.android.utils.ILogger) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Bridge(com.android.layoutlib.bridge.Bridge) LayoutLog(com.android.ide.common.rendering.api.LayoutLog) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Bridge (com.android.layoutlib.bridge.Bridge)6 File (java.io.File)6 NonNull (android.annotation.NonNull)5 FrameworkResources (com.android.ide.common.resources.FrameworkResources)5 ResourceItem (com.android.ide.common.resources.ResourceItem)5 ResourceRepository (com.android.ide.common.resources.ResourceRepository)5 FolderWrapper (com.android.io.FolderWrapper)5 BeforeClass (org.junit.BeforeClass)5 LayoutLibrary (com.android.ide.common.rendering.LayoutLibrary)1 LayoutLog (com.android.ide.common.rendering.api.LayoutLog)1 ILogger (com.android.utils.ILogger)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 BufferingFileWrapper (org.jetbrains.android.util.BufferingFileWrapper)1 Nullable (org.jetbrains.annotations.Nullable)1